Ver código fonte

接口联调完成

htc 3 dias atrás
pai
commit
5b9a1d9e19
1 arquivos alterados com 33 adições e 17 exclusões
  1. 33 17
      pagesMy/userInfo.vue

+ 33 - 17
pagesMy/userInfo.vue

@@ -2,7 +2,7 @@
 	<view class="default_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
 		<cus-header title='用户信息'></cus-header>
 		<view class="info adffcac">
-			<image class="info-avatar" :src="userInfo.avatarPath||defaultAvatar" @click="changeAvatar"></image>
+			<image class="info-avatar" :src="userInfo.headUrl||defaultAvatar" @click="changeAvatar"></image>
 			<view class="info-text">上传头像</view>
 			<view class="info-form">
 				<view class="info-form-item adfac">
@@ -14,13 +14,13 @@
 				<view class="info-form-item adfac">
 					<view class="info-form-item-left">性别</view>
 					<view class="info-form-item-right adfac">
-						<view class="info-form-item-right-pre adfac" @click="changeGender(1)">
-							<image :src="imgBase+'selected.png'" v-if="userInfo.gender==1"></image>
+						<view class="info-form-item-right-pre adfac" @click="changeGender(0)">
+							<image :src="imgBase+'selected.png'" v-if="userInfo.gender==0"></image>
 							<image :src="imgBase+'not_select.png'" v-else></image>
 							<text>男</text>
 						</view>
-						<view class="info-form-item-right-pre adfac" @click="changeGender(2)" style="margin-left: 80rpx;">
-							<image :src="imgBase+'selected.png'" v-if="userInfo.gender==2"></image>
+						<view class="info-form-item-right-pre adfac" @click="changeGender(1)" style="margin-left: 80rpx;">
+							<image :src="imgBase+'selected.png'" v-if="userInfo.gender==1"></image>
 							<image :src="imgBase+'not_select.png'" v-else></image>
 							<text>女</text>
 						</view>
@@ -43,7 +43,8 @@
 			return {
 				defaultAvatar:this.$imgBase+'upload.png',
 				userInfo:{
-					avatarPath:'',
+					id:'',
+					headUrl:'',
 					realName:'',
 					gender:null
 				},
@@ -51,7 +52,14 @@
 			}
 		},
 		onLoad() {
-			this.jmPhone = JSON.parse(uni.getStorageSync('userInfo'))?.mobile?.replace(/(\d{3})\d{4}(\d{4})/, '$1 **** $2');
+			if(uni.getStorageSync('userInfo')){
+				let ui = JSON.parse(uni.getStorageSync('userInfo'));
+				this.jmPhone = ui?.mobile?.replace(/(\d{3})\d{4}(\d{4})/, '$1 **** $2');
+				this.userInfo.id = ui?.id;
+				this.userInfo.headUrl = ui.headUrl;
+				this.userInfo.realName = ui.realName;
+				this.userInfo.gender = ui.gender;
+			}
 		},
 		methods:{
 			changeGender(gender){
@@ -78,7 +86,7 @@
 						try{
 							let data = JSON.parse(res.data);
 							if(data.code!==0) return this.$showToast(data.msg)
-							this.userInfo.avatarPath = data.data||'';
+							this.userInfo.headUrl = data.data||'';
 						}catch(e){
 							//TODO handle the exception
 						}
@@ -115,7 +123,7 @@
 				  console.log('获取微信用户信息成功:', res.userInfo);
 				  if (res.userInfo) {
 					if (getAvatarOnly) { // 只获取头像
-					  this.userInfo.avatarPath = res.userInfo.avatarUrl;
+					  this.userInfo.headUrl = res.userInfo.avatarUrl;
 					}
 				  }
 				},
@@ -125,16 +133,24 @@
 			  });
 			},
 			handleSave(){
-				if(!this.userInfo.avatarPath) return this.$showToast('请上传头像');
+				if(!this.userInfo.headUrl) return this.$showToast('请上传头像');
 				if(!this.userInfo.realName) return this.$showToast('请输入姓名');
-				if(!this.userInfo.gender) return this.$showToast('请选择性别');
+				if(this.userInfo.gender==null) return this.$showToast('请选择性别');
 				
-				this.$showToast('保存成功')
-				setTimeout(()=>{
-					uni.reLaunch({
-						url:'/pages/my'
-					})
-				},1500)
+				this.$api.put('/wx/updateUser',this.userInfo).then(({data:res})=>{
+					if(res.code!==0) return this.$showToast(res.msg)
+					this.$showToast('保存成功')
+					let ui = JSON.parse(uni.getStorageSync('userInfo'));
+					ui.headUrl = this.userInfo.headUrl;
+					ui.realName = this.userInfo.realName;
+					ui.gender = this.userInfo.gender;
+					uni.setStorageSync('userInfo',JSON.stringify(ui));
+					setTimeout(()=>{
+						uni.reLaunch({
+							url:'/pages/my'
+						})
+					},1500)
+				})
 			}
 		}
 	}