martial-arts/pagesA/my-data/my-data.vue

169 lines
5.0 KiB
Vue

<template>
<view>
<status-container titlet="基本资料" returnc="#FFFFFF">
<view slot="content" style="margin-top: -20rpx;">
<view class="bacf pad-x50 pad-zy20">
<view class="pad-sx30 pad-zy10 disjbac bbot" @tap="chooseEv('avatar')">
<view class="fon24 col26">头像</view>
<view class="disac">
<image class="radius_100" :src="userInfo.headimgurl" mode="aspectFill" style="width: 92rpx;height: 92rpx;"></image>
<view class="icon icon-next fon24 mar-z10" style="color: #7f7f7f;"></view>
</view>
</view>
<view class="pad-sx30 fon24 pad-zy10 disjbac bbot" @tap="chooseEv('nick_name')">
<view class="col26">昵称</view>
<view class="disac">
<view class="">{{userInfo.nickname || '未填写'}}</view>
<view class="icon icon-next fon24 mar-z10" style="color: #7f7f7f;"></view>
</view>
</view>
<view class="pad-sx30 fon24 pad-zy10 disjbac bbot" @tap="chooseEv(5)">
<view class="col26">真实姓名</view>
<view class="disac">
<view class="">{{realName || '未填写'}}</view>
<view class="icon icon-next fon24 mar-z10" style="color: #7f7f7f;"></view>
</view>
</view>
<view class="pad-sx30 fon24 pad-zy10 disjbac bbot mar-x30" @tap="chooseEv(6)">
<!-- <view class="pad-sx30 fon24 pad-zy10 disjbac bbot mar-x30"> -->
<view class="col26">联系电话</view>
<view class="disac">
<view class="">{{phone || '未填写'}}</view>
<view class="icon icon-next fon24 mar-z10" style="color: #7f7f7f;"></view>
</view>
</view>
</view>
</view>
</status-container>
<dynamic-frame ref="refFrame" :showType="showType" :tipsTitle="tipsTitle" @returnEv="returnEv"></dynamic-frame>
</view>
</template>
<script>
import dynamicFrame from '@/components/dynamic-frame.vue';
export default {
components:{
dynamicFrame
},
data() {
return {
showType:5,
baseHttps:`${getApp().globalData.hostapiQi}`, //接口链接
tipsTitle:'真实姓名',
userInfo:{
headimgurl:'',
nickname:'',
}, //用户信息
realName:'',//真实姓名字段
phone:'',//联系电话
}
},
onLoad() {
this.userInfo = uni.getStorageSync('userInfo');
console.log(this.userInfo)
},
methods: {
// 发起修改
chooseEv(index){
this.showType = index;
if(this.showType==5){
this.tipsTitle = index==5?'真实姓名':'电话号码';
this.$refs.refFrame.ifLogistics = true;
this.$refs.refFrame.ifAnimated = true;
this.$refs.refFrame.dynamicObj.content = this.realName || '';
this.$refs.refFrame.tempText = JSON.parse(JSON.stringify(this.realName || ''));
}
if(this.showType==6){
this.tipsTitle = index==5?'真实姓名':'电话号码';
this.$refs.refFrame.ifLogistics = true;
this.$refs.refFrame.ifAnimated = true;
this.$refs.refFrame.dynamicObj.content = this.phone || '';
this.$refs.refFrame.tempText = JSON.parse(JSON.stringify(this.phone || ''));
}
if(this.showType=='avatar'){
uni.chooseImage({
count: 1, //默认9
sourceType: ['album','camera'], //从相册选择
success: (res)=> {
// 上传图片
this.uploadImg(res.tempFilePaths[0]);
}
})
}
if(this.showType=='nick_name'){
this.tipsTitle = '修改昵称';
this.$refs.refFrame.ifLogistics = true;
this.$refs.refFrame.ifAnimated = true;
this.$refs.refFrame.dynamicObj.content = this.phone || '';
this.$refs.refFrame.tempText = JSON.parse(JSON.stringify(this.phone || ''));
}
},
// 头像上传
uploadImg(url){
uni.showLoading({
title: '上传中'
});
this.$requst.upload('/api/file/upload/image',{path:url}).then(res=>{
if(res.code==0) {
// 确认修改
this.returnEv(res.data.src)
}
uni.hideLoading();
})
},
//确认修改
returnEv(obj){
console.log(obj)
if(this.showType=='avatar'){
if(this.userInfo.avatarUrl!=obj){
// 如果修改后的跟修改前的不一样
this.setData('headimgurl',obj);
}
this.userInfo.headimgurl = this.baseHttps + obj;
}
if(this.showType=='nick_name'){
if(this.userInfo.nickname!=obj.content){
// 如果修改后的跟修改前的不一样
this.setData('nickname',obj.content);
}
this.userInfo.nickname = obj.content;
}
if(this.showType==5){
if(this.realName!=obj.content){
// 如果修改后的跟修改前的不一样
this.setData('real_name',obj.content);
}
this.realName = obj.content;
}
if(this.showType==6){
if(this.phone!=obj.content){
// 如果修改后的跟修改前的不一样
this.setData('mobile',obj.content);
}
this.phone = obj.content;
}
},
// 执行修改事件
setData(field,value){
let params = {
field,
value
}
this.$requst.post('/api/user/update-info',params).then(res=>{
if(res.code==0){
this.$toolAll.tools.showToast('修改成功');
}
})
}
}
}
</script>
<style></style>