deming/pageE/mine/EditUserInfo.vue

247 lines
5.8 KiB
Vue
Raw Normal View History

2020-06-08 15:23:23 +08:00
<template>
<view class="edit-info">
<view class="user-info">
2020-07-07 17:47:00 +08:00
<view class="info-avatar" @click="changeAvatar">
2020-07-06 17:32:29 +08:00
<u-avatar :src="avatar" :size="120"></u-avatar>
<view class="avatar-text">更换头像</view>
2020-06-08 15:23:23 +08:00
</view>
<view class="info-item">
<view class="title">昵称</view>
2020-06-29 08:47:37 +08:00
<view class="value">
<input type="text" v-model="nickname" />
</view>
2020-06-08 15:23:23 +08:00
</view>
<view class="info-item">
<view class="title">性别</view>
2020-06-30 18:06:50 +08:00
<view class="value" @click="selectGender=true">{{ gender == '1' ? '' : '' }}</view>
2020-06-08 15:23:23 +08:00
</view>
2020-06-29 08:47:37 +08:00
<u-select v-model="selectGender" mode="single-column" :list="list" @confirm="setGender"></u-select>
2020-06-08 15:23:23 +08:00
<view class="info-item">
<view class="title">生日</view>
2020-06-29 08:47:37 +08:00
<view class="value" @click="selectBirthday=true">{{ birthday }}</view>
2020-06-08 15:23:23 +08:00
</view>
2020-06-29 08:47:37 +08:00
<u-picker mode="time" v-model="selectBirthday" :params="params" @confirm="setBirthday"></u-picker>
2020-06-08 15:23:23 +08:00
<view class="info-item phone" @click="updatePhone">
<view class="title">手机号</view>
2020-06-29 08:47:37 +08:00
<view class="value">{{ phoneNumber }}</view>
2020-06-08 15:23:23 +08:00
<image src="../static/mine/21.png"></image>
</view>
</view>
2020-07-03 17:44:58 +08:00
<view class="edit-tips">注意修改手机号需要原手机号获取验证码无原手机验证码请联系客服</view>
2020-06-29 08:47:37 +08:00
<view class="edit-btn" @click="updateMemberInfo">完成</view>
2020-06-08 15:23:23 +08:00
</view>
</template>
<script>
2020-07-01 17:32:36 +08:00
import common from '@/static/js/common.js'
2020-06-08 15:23:23 +08:00
export default {
data() {
2020-06-29 08:47:37 +08:00
return {
selectGender: false,
selectBirthday: false,
list: [
{
value: 1,
label: '男'
},
{
value: 2,
label: '女'
}
],
params: {
year: true,
month: true,
day: true,
hour: false,
minute: false,
second: false
},
2020-07-03 17:44:58 +08:00
nickname: '',
2020-06-30 18:06:50 +08:00
gender: '', // 1男 2女
2020-06-29 08:47:37 +08:00
birthday: '',
phoneNumber: '',
2020-06-30 18:06:50 +08:00
avatar: '',
2020-07-14 10:13:27 +08:00
uploadPath: '', // 上传时的路径
2020-06-29 08:47:37 +08:00
}
},
onLoad() {
this.getUserInfo();
2020-06-08 15:23:23 +08:00
},
2020-07-30 20:33:16 +08:00
// 监听头像裁剪
created() {
// uni.$on('uAvatarCropper', path => {
// const url = this.$u.http.config.baseUrl + '/Upload/uploadfile';
// this.avatar = path;
// // 可以在此上传到服务端
// // uni.uploadFile({
// // url: 'http://www.example.com/upload',
// // filePath: path,
// // name: 'file',
// // complete: (res) => {
// // console.log(res);
// // }
// // });
// common.uploadFile({
// url: url,
// name: 'avatar',
// filePath: path
// }).then(result => {
// // console.log(result);
// this.$set(this, 'avatar', result.file_path);
// // this.avatar = result.file_path;
// this.uploadPath = result.file_name;
// }, error => {
// this.$u.toast(error);
// })
// })
},
2020-07-08 18:14:41 +08:00
onNavigationBarButtonTap(e) {
if( e.index == 0 ) uni.navigateBack();
},
2020-06-08 15:23:23 +08:00
methods: {
2020-07-07 17:47:00 +08:00
changeAvatar() {
const url = this.$u.http.config.baseUrl + '/Upload/uploadfile';
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: (res) => {
this.avatar = res.tempFilePaths[0];
common.uploadFile({
url: url,
2020-07-10 09:03:19 +08:00
name: 'avatar',
filePath: res.tempFilePaths[0]
2020-07-07 17:47:00 +08:00
}).then(result => {
2020-07-14 10:13:27 +08:00
// console.log(result);
2020-08-01 16:36:48 +08:00
// this.$set(this, 'avatar', result.file_path);
2020-07-14 10:13:27 +08:00
// this.avatar = result.file_path;
this.uploadPath = result.file_name;
2020-07-07 17:47:00 +08:00
}, error => {
this.$u.toast(error);
})
}
});
},
2020-07-30 20:33:16 +08:00
// 头像裁剪
// chooseAvatar() {
// this.$u.route({
// url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
// params: {
// destWidth: 300,
// rectWidth: 200,
// fileType: 'jpg',
// }
// })
// },
2020-06-29 08:47:37 +08:00
getUserInfo() {
this.$u.api.getMemberInfo().then(res => {
if (res.errCode == 0) {
let userInfo = res.data.MemberArray;
[this.nickname, this.phoneNumber, this.birthday, this.gender, this.avatar] = [
userInfo.member_nickname,
2020-07-03 17:44:58 +08:00
userInfo.member_mobile,
userInfo.member_birthday,
2020-06-29 08:47:37 +08:00
userInfo.member_sex,
2020-08-01 16:36:48 +08:00
userInfo.member_avatar + '?' + new Date().getTime(),
2020-06-29 08:47:37 +08:00
];
}
})
},
2020-06-30 18:06:50 +08:00
updateMemberInfo() {
2020-06-29 08:47:37 +08:00
this.$u.api.updateMemberInfo({
nickname: this.nickname,
2020-06-30 18:06:50 +08:00
gender: this.gender,
2020-07-14 10:13:27 +08:00
avatar: this.uploadPath,
2020-06-29 08:47:37 +08:00
birthday: this.birthday,
}).then(res => {
if (res.errCode == 0) {
2020-06-30 18:06:50 +08:00
this.getUserInfo();
2020-07-25 15:17:52 +08:00
this.$u.toast(res.message);
2020-06-29 08:47:37 +08:00
}
})
},
setGender(value) {
2020-06-30 18:06:50 +08:00
// console.log(value);
this.gender = value[0].value;
2020-06-29 08:47:37 +08:00
},
setBirthday(value) {
// console.log(value);
2020-07-01 17:32:36 +08:00
this.birthday = value.year + '-' + value.month + '-' + value.day;
2020-06-29 08:47:37 +08:00
},
2020-06-08 15:23:23 +08:00
updatePhone() {
uni.navigateTo({
url: '/pageE/mine/UpdatePhone'
});
}
},
};
</script>
<style lang="scss" scoped>
.edit-info {
min-height: calc(100vh - var(--window-top));
background-color: #ECECEC;
padding-top: 1rpx;
.user-info {
.info-avatar {
2020-07-06 17:32:29 +08:00
height: 202rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
2020-06-08 15:23:23 +08:00
background: rgba(255,255,255,1);
2020-07-06 17:32:29 +08:00
.avatar-text {
margin-top: 12rpx;
font-size: 24rpx;
color: rgba(255,120,15,1);
2020-06-08 15:23:23 +08:00
}
}
.info-item {
display: flex;
align-items: center;
padding: 35rpx 30rpx;
border-top: 2rpx solid #ECECEC;
font-size: 30rpx;
height: 98rpx;
background: rgba(255,255,255,1);
.title {
width: 240rpx;
color: rgba(51,51,51,1);
}
.value {
2020-06-29 08:47:37 +08:00
flex: 1;
height: 98rpx;
line-height: 98rpx;
2020-06-08 15:23:23 +08:00
color: rgba(102,102,102,1);
2020-06-29 08:47:37 +08:00
> input {
height: 98rpx;
}
2020-06-08 15:23:23 +08:00
}
}
.phone {
> image {
margin-left: auto;
width: 11rpx;
height: 22rpx;
}
}
}
.edit-tips {
font-size: 24rpx;
color: rgba(102,102,102,1);
line-height: 40rpx;
margin: 20rpx 0 120rpx;
padding: 0 30rpx;
}
.edit-btn {
margin: 0 auto;
width: 690rpx;
height: 98rpx;
background: rgba(255,120,15,1);
border-radius: 49rpx;
font-size: 36rpx;
color: rgba(255,255,255,1);
line-height: 98rpx;
text-align: center;
}
}
</style>