123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <template>
- <view>
- <view class="content">
- <view class="info-item">
- <view class="label">头像</view>
- <view class="right">
- <image class="head" @tap="chooseImage()" :src="headImg" mode=""></image>
- </view>
- </view>
- <view class="info-item">
- <view class="label">姓名</view>
- <view class="right">
- <input type="text" v-model="nickName" placeholder="请输入姓名" class="input" />
- </view>
- </view>
- <view class="info-item">
- <view class="label">性别</view>
- <view class="right x-end" style="width:80%;height: 40px;justify-content: end;">
- <picker style="width: 100%;text-align: right;" @change="pickerSex" :value="sex" :range="sexPicker">
- <view class="picker">
- {{sex>-1?sexPicker[sex]:''}}
- </view>
- </picker>
- </view>
- </view>
- <view class="info-item">
- <view class="label">手机号</view>
- <view class="right">
- <input type="text" v-model="phonenumber" placeholder="请输入手机号" class="input" />
- </view>
- </view>
- </view>
-
- <view class="btn-box">
- <view class="sub-btn" @click="submit()">保存修改</view>
- </view>
- </view>
-
- </template>
- <script>
- import {setPwd,setHeadImg,setUserInfo,getUserInfo} from '@/api/user.js';
- import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
- export default {
- data() {
- return {
- nickName:"",
- deptName:"",
- postNames:"",
- phonenumber:"",
- email:"",
- sexPicker: ['男', '女','未知'],
- sex: 0, // 性别
- headImg: '/static/images/detault_head.jpg', // 头像,
- headImgUrl:'',
- }
- },
- onLoad() {
- this.getUserInfo();
- },
- methods: {
- bindUser(data){
- var that=this;
- that.nickName=data.user.nickName;
- that.posts=data.post;
- that.phonenumber=data.user.phone;
- that.email=data.user.email;
- if(data.user.sex!=undefined){
- that.sex=data.user.sex;
- }
- if(data.post!=null&&data.post.length>0){
- var postNameStr="";
- data.post.forEach( (v,i) => {
- postNameStr+=v+",";
- },this);
- that.postNames=postNameStr.substr(0,postNameStr.length-1);
-
- }
- if(!that.$isEmpty(data.user.avatar)){
- //this.headImg=uni.getStorageSync('requestPath')+data.user.avatar;
- this.headImg=data.user.avatar;
- this.headImgUrl=data.user.avatar;
- }
- },
- getUserInfo(){
- var data = {};
- var that=this;
- getUserInfo(data).then(
- res => {
- that.bindUser(res);
-
- },
- rej => {}
- );
- },
- // 性别选择
- pickerSex(e) {
- this.sex = e.detail.value
- },
- // 选择照片
- async chooseImage() {
- // #ifdef APP-PLUS
- if(!plus.runtime.isAgreePrivacy()) {
- uni.showToast({title: "请同意隐私政策",icon: "none"});
- return;
- }
- let result = await premissionCheck("EXTERNAL_STORAGE");
- if(result == 1) {
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], //从相册选择
- success: (res) => {
- //this.headImg = res.tempFilePaths[0]
- uni.uploadFile({
- url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
- filePath: res.tempFilePaths[0],
- name: 'file',
- formData: {
- 'user': 'test' // 上传附带参数
- },
- success: (uploadFileRes) => {
- console.log(uploadFileRes)
- // 根据接口具体返回格式 赋值具体对应url
- var data=JSON.parse(uploadFileRes.data)
- //this.headImg=uni.getStorageSync('requestPath')+data.fileName;
- this.headImg=data.url;
- this.headImgUrl=data.url;
- }
- });
- }
- });
- }
-
- // #endif
- },
- // 预览头像
- viewImage() {
- uni.previewImage({
- urls: this.headImg,
- current: this.headImg
- });
- },
- submit(){
- if (this.$isEmpty(this.phonenumber)) {
- uni.showToast({
- title: "请输入手机号",
- icon: 'none',
- });
- return
- }
- var data = {phone:this.phonenumber,email:this.email,sex:this.sex.toString(),avatar:this.headImgUrl,nickName:this.nickName};
- console.log(data);
- setUserInfo(data).then(res => {
- if(res.code==200){
- uni.showToast({
- title: '修改成功',
- duration: 2000
- });
- }
- else{
- uni.showToast({
- title: res.msg,
- icon: 'none',
- });
- }
-
- },
- rej => {}
- );
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .content{
- padding-top: 20rpx;
- border-top: 1px solid #F5F6FA;
- }
- .info-item{
- height: 104upx;
- background: #FFFFFF;
- padding: 0 30upx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 1px solid #F5F6FA;
- &:last-child{
- border-bottom: none;
- }
- .label{
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- .right{
- display: flex;
- align-items: center;
- justify-content: center;
- .text{
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- .image{
- margin-left: 10upx;
- width: 30upx;
- height: 30upx;
- }
- .input{
- text-align: right;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- }
- .head{
- border-radius: 50%;
- width: 80upx;
- height: 80upx;
- }
- .arrow{
- width: 30upx;
- height: 30upx;
- }
- .text{
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- .input{
- text-align: right;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- &.password{
- margin-top: 20upx;
- .right{
- display: flex;
- align-items: center;
- .text{
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- margin-right: 15upx;
- }
- }
- }
- }
- .btn-box{
- margin-top: 15rpx;
- height: 120upx;
- padding: 0 30upx;
- display: flex;
- align-items: center;
- justify-content: center;
- .sub-btn{
- width: 100%;
- height: 88upx;
- line-height: 88upx;
- text-align: center;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #FFFFFF;
- background: #FF5C03;
- border-radius: 44upx;
- }
- }
- </style>
|