Files

330 lines
8.4 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="user-personalData">
<view class="top-box" :style="{'backgroundImage':`url(${webUrl}/20240109234153916906.png)`}">
<view class="flex ai-center">
<image-cropper :src="tempFilePath" @confirm="confirm" @cancel="cancel"></image-cropper>
<view style="position: relative" @tap="chooseImage">
<image class="cover" :src="avatar"/>
<view class="btn-change flex jc-center ai-center">更换头像</view>
</view>
<view>
<view class="name">{{ userInfo.nickname }}</view>
<view class="phone">绑定手机号{{ userInfo.phone || '未绑定' }}</view>
</view>
</view>
</view>
<view class="cell-box">
<view class="cell flex jc-between ai-center">
<view class="flex ai-center">
<view class="title">昵称</view>
<view class="value">
<input
v-model="nickname"
type="text"
maxlength="12"
/>
</view>
</view>
<view class="icon">
<image :src="webUrl+'/20220903145836941399.png'"/>
</view>
</view>
<view class="cell flex jc-between ai-center">
<view class="flex ai-center">
<view class="title">ID号</view>
<view class="value">{{ userInfo.uid }}</view>
</view>
<view class="icon">
<image :src="webUrl+'/20220925102920713727.png'" style="width: 40rpx;height: 40rpx"/>
</view>
</view>
<view class="cell flex jc-between ai-center">
<view class="flex ai-center">
<view class="title">性别</view>
<view class="value">
<u-radio-group
v-model="form.gender"
placement="row"
>
<u-radio
:name="1"
:customStyle="{marginRight: '16px'}"
active-color="#C41617"
label="男"
/>
<u-radio
:name="2"
active-color="#C41617"
label="女"
/>
</u-radio-group>
</view>
</view>
<view class="icon">
<image :src="webUrl+'/20220903145836941399.png'"/>
</view>
</view>
<view class="cell flex jc-between ai-center">
<view class="flex ai-center">
<view class="title">出生日期</view>
<view class="value">
<picker
:value="form.birthday"
mode="date"
class="picker"
@change="birthdayChange"
>
<u--text v-if="form.birthday" :text="form.birthday"></u--text>
<u--text v-else text="请选择" color="#c0c4cc"></u--text>
</picker>
</view>
</view>
<view class="icon">
<image :src="webUrl+'/20220903145836941399.png'"/>
</view>
</view>
<view class="cell flex jc-between ai-center" @click="bindPhone">
<view class="flex ai-center">
<view class="title">手机号</view>
<view class="value">{{ userInfo.phone || '未绑定' }}</view>
</view>
<view class="icon">
<image :src="webUrl+'/20220903145836941399.png'"/>
</view>
</view>
<view class="cell flex jc-between ai-center" @click="payPwdClick">
<view class="flex ai-center">
<view class="title">支付密码</view>
<view class="value"></view>
</view>
<view class="icon">
<image :src="webUrl+'/20220903145836941399.png'"/>
</view>
</view>
</view>
<button class="btn-save" @click="submit">保存修改</button>
</view>
</template>
<script>
import {mapGetters} from 'vuex'
import {isWeixin, trim, uploadImage} from '@/utils'
import {postUserEdit} from '@/api/user'
import ImageCropper from '@/pkg_user/components/invinbg-image-cropper/invinbg-image-cropper.vue'
import { pageListenMixins } from '@/mixins/pageListenMixins'
export default {
name: 'PersonalData',
components: {
ImageCropper
},
mixins: [pageListenMixins],
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
avatar: '',
nickname: '',
isWeixin: false,
currentAccounts: 0,
switchUserInfo: [],
userIndex: 0,
tempFilePath: '',
cropFilePath: '',
pageKeyId: Object.freeze('userConfig'),
form: {
gender: '',
birthday: ''
}
}
},
computed: mapGetters(['userInfo']),
mounted: function () {
this.avatar = this.userInfo.avatar
this.nickname = this.userInfo.nickname
this.form.gender = this.userInfo.gender
this.form.birthday = this.userInfo.birthday || ''
this.isWeixin = isWeixin()
},
onShow: function () {
// 获取用户信息
this.$store.dispatch('getUser', true)
},
methods: {
confirm(e) {
this.tempFilePath = ''
this.cropFilePath = e.detail.tempFilePath
uploadImage(this.cropFilePath, img => {
console.log(img)
this.avatar = img
this.cropFilePath = ''
})
},
cancel() {
console.log('canceled')
},
bindPhone: function () {
this.$yrouter.push('/pkg_user/views/bindPhone')
},
payPwdClick: function () {
// 先判断用户是否绑定过手机
if (this.userInfo.phone) {
// 再判断用户是否设置过支付密码
if (this.userInfo.hasPwdPay) {
// 修改支付密码
this.$yrouter.push('/pkg_user/views/payPassword');
} else {
// 设置支付密码
this.$yrouter.push('/pkg_user/views/payPassword?isSetMode=true');
}
} else {
// 跳转到绑定手机
this.$yrouter.push('/pkg_user/views/bindPhone');
}
},
chooseImage() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: (res) => {
this.tempFilePath = res.tempFilePaths.shift()
}
})
},
birthdayChange(e) {
this.form.birthday = e.detail.value
},
submit: function () {
const that = this
postUserEdit({
nickname: trim(this.nickname),
avatar: this.avatar,
gender: this.form.gender,
birthday: this.form.birthday
}).then(res => {
that.$store.dispatch('userInfo', true)
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
setTimeout(function () {
that.$yrouter.back()
}, 2000)
}, err => {
uni.showToast({
title: err.msg || err.response.data.msg || err.response.data.message,
icon: 'none',
duration: 2000
})
})
}
}
}
</script>
<style scoped lang="less">
.user-personalData {
min-height: 100vh;
background: #F6F6F6;
view {
box-sizing: border-box;
}
.top-box {
width: 100vw;
height: 396.5rpx;
padding: 86rpx 0 0 76rpx;
background-size: 750rpx 396.5rpx;
color: #FFFFFF;
.cover {
width: 112rpx;
height: 112rpx;
border-radius: 50%;
margin-right: 44rpx;
}
.btn-change {
position: absolute;
left: 0;
top: 98rpx;
width: 110rpx;
height: 36rpx;
border-radius: 20rpx;
background: #FFFFFF;
color: #333333;
font-size: 22rpx;
}
.name {
font-size: 36rpx;
line-height: 52rpx;
font-weight: bold;
}
.phone {
margin-top: 18rpx;
font-size: 28rpx;
line-height: 40rpx;
}
}
.cell-box {
width: 686rpx;
margin: -130rpx 32rpx 0;
padding: 0 40rpx 20rpx;
box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.16);
border-radius: 12rpx;
background: #FFFFFF;
.cell:last-child {
border-bottom: none;
}
.cell {
padding: 24rpx 0;
border-bottom: 1rpx solid #ECECEE;
.title {
width: 160rpx;
color: #333333;
font-weight: bold;
font-size: 32rpx;
line-height: 48rpx;
}
.value {
color: #999999;
font-size: 32rpx;
line-height: 48rpx;
.picker {
width: 400rpx;
}
}
.icon {
image {
width: 32rpx;
height: 32rpx;
}
}
}
}
.btn-save {
position: fixed;
left: 32rpx;
bottom: 160rpx;
width: 686rpx;
border-radius: 40rpx;
background: #C41617;
color: #FFFFFF;
font-size: 36rpx;
}
}
</style>