<template>
|
<view class="page_bg">
|
<uv-navbar title="个人资料" :autoBack="true" :placeholder="true" bgColor="rgba(0,0,0,0)" titleStyle="color:#fff" leftIconColor="#fff"></uv-navbar>
|
|
<view class="head_ph">
|
<uv-upload :fileList="fileList1" name="1" :maxCount="1" width="200rpx" height="200rpx" :previewFullImage="false"
|
@afterRead="afterRead" @delete="deletePic">
|
<!-- <image class="ico_head" :src="baseURL+avatar" mode="widthFix"
|
style="width: 200rpx;height: 200rpx;"></image> -->
|
</uv-upload>
|
<!-- <image class="camera" src="/static/img/ico_3.png" mode="widthFix"></image> -->
|
</view>
|
|
<view class="user_info">
|
<view class="item">
|
<view class="name">
|
电话
|
</view>
|
<view class="info">
|
<uv-input placeholder="请输入电话" border="none" v-model="phonenumber" :clearable="true" ></uv-input>
|
</view>
|
</view>
|
<view class="item">
|
<view class="name">
|
密码
|
</view>
|
<view class="info_eye">
|
<uv-input placeholder="请输入密码" :password="isEye" border="none" v-model="password" :clearable="true"></uv-input>
|
<view class="eye" @click="isEye = !isEye">
|
<uv-icon v-if="isEye" name="eye-off" color="#666" size="40rpx"></uv-icon>
|
<uv-icon v-else name="eye" color="#666" size="40rpx"></uv-icon>
|
</view>
|
</view>
|
</view>
|
<view class="item">
|
<view class="name">
|
昵称
|
</view>
|
<view class="info">
|
<uv-input placeholder="请输入昵称" border="none" v-model="nickName" :clearable="true"></uv-input>
|
</view>
|
</view>
|
<view class="item">
|
<view class="name">
|
微信号
|
</view>
|
<view class="info">
|
<uv-input placeholder="请输入微信号" border="none" v-model="wx" :clearable="true"></uv-input>
|
</view>
|
</view>
|
|
</view>
|
|
<view class="footer_btn">
|
<uv-button text="确认修改" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" size="large" @click="postUserProfile()"></uv-button>
|
</view>
|
|
|
|
</view>
|
</template>
|
|
<script>
|
import { userInfo, userProfile } from '@/api/api.js'
|
export default {
|
data() {
|
return {
|
userId: '',
|
userName: '',
|
password: '',
|
nickName: '',
|
wx: '',
|
avatar: '',
|
phonenumber: '',
|
fileList1: [],
|
baseURL: '',
|
agree: 0,
|
isEye: true
|
}
|
},
|
onLoad() {
|
this.baseURL = uni.$uv.http.config.baseURL
|
this.getUserInfo()
|
},
|
methods: {
|
postUserProfile(){
|
if(this.fileList1.length == 0){
|
uni.showToast({
|
title: '请上传头像',
|
duration: 2000,
|
icon: 'none'
|
});
|
return
|
}
|
// if(!this.avatar){
|
// uni.showToast({
|
// title: '请上传头像',
|
// duration: 2000,
|
// icon: 'none'
|
// });
|
// return
|
// }
|
if(!this.phonenumber){
|
uni.showToast({
|
title: '请输入手机号码',
|
duration: 2000,
|
icon: 'none'
|
});
|
return
|
}
|
if (!/^1[3-9]\d{9}$/.test(this.phonenumber)) {
|
uni.showToast({
|
title: '手机号码格式不正确',
|
icon: 'none'
|
});
|
return
|
}
|
if(!this.password){
|
uni.showToast({
|
title: '请输入密码',
|
duration: 2000,
|
icon: 'none'
|
});
|
return
|
}
|
if(!this.nickName){
|
uni.showToast({
|
title: '请输入昵称',
|
duration: 2000,
|
icon: 'none'
|
});
|
return
|
}
|
if(!this.wx){
|
uni.showToast({
|
title: '请输入微信号',
|
duration: 2000,
|
icon: 'none'
|
});
|
return
|
}
|
|
userProfile({
|
userId: this.userId,
|
phonenumber: this.phonenumber,
|
password: this.password,
|
nickName: this.nickName,
|
wx: this.wx,
|
avatar: this.avatar
|
}).then(res=>{
|
console.log('修改用户信息---',res)
|
uni.showToast({
|
title: res.msg,
|
duration: 2000,
|
icon: 'none'
|
});
|
this.getUserInfo()
|
if(res.code == 200){
|
uni.navigateBack({
|
delta: 1
|
});
|
}
|
})
|
},
|
getUserInfo(){
|
userInfo().then(res=>{
|
console.log(res.user)
|
this.fileList1 = []
|
this.userId = res.user.userId
|
this.phonenumber = res.user.phonenumber
|
this.password = res.user.password
|
this.nickName = res.user.nickName
|
this.wx = res.user.wx
|
this.avatar = res.user.avatar
|
this.fileList1.push({url:this.baseURL+res.user.avatar})
|
})
|
},
|
// 删除图片
|
deletePic(event) {
|
this[`fileList${event.name}`].splice(event.index, 1)
|
},
|
// 新增图片
|
async afterRead(event) {
|
console.log('event---',event)
|
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
let lists = [].concat(event.file)
|
let fileListLen = this[`fileList${event.name}`].length
|
lists.map((item) => {
|
this[`fileList${event.name}`].push({
|
...item,
|
status: 'uploading',
|
message: '上传中'
|
})
|
})
|
for (let i = 0; i < lists.length; i++) {
|
const result = await this.uploadFilePromise(lists[i].url)
|
this.avatar = result
|
let item = this[`fileList${event.name}`][fileListLen]
|
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
|
status: 'success',
|
message: '',
|
url: result
|
}))
|
fileListLen++
|
}
|
},
|
uploadFilePromise(url) {
|
return new Promise((resolve, reject) => {
|
let a = uni.uploadFile({
|
url: this.baseURL+'/common/uploadFileByAnny', // 仅为示例,非真实的接口地址
|
filePath: url,
|
name: 'file',
|
success: (res) => {
|
console.log('图片-----',JSON.parse(res.data).fileName)
|
setTimeout(() => {
|
resolve(JSON.parse(res.data).fileName)
|
}, 1000)
|
}
|
});
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
::v-deep .uv-upload__wrap__preview,::v-deep .uv-upload__button{
|
margin: 0 !important;
|
}
|
::v-deep .uv-upload__wrap__preview__image{
|
border-radius: 50%;
|
}
|
.footer_btn{
|
position: fixed;
|
left:0;
|
right: 0;
|
bottom: 0;
|
padding:35rpx;
|
}
|
.user_info{
|
.item{
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
border-bottom: 1rpx solid #ddd;
|
padding:0 35rpx;
|
height: 120rpx;
|
.name{
|
width: 140rpx;
|
flex-shrink: 0;
|
font-size: 28rpx;
|
color: rgba(0,0,0,0.9);
|
line-height: 46rpx;
|
}
|
.info{
|
width: 100%;
|
}
|
.info_eye{
|
width: 100%;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
.eye{
|
flex-shrink: 0;
|
margin-left: 20rpx;
|
}
|
}
|
}
|
}
|
.head_ph {
|
flex-shrink: 0;
|
width: 200rpx;
|
margin: 50rpx auto;
|
position: relative;
|
.camera{
|
position: absolute;
|
right: 0;
|
bottom: 0;
|
width: 50rpx;
|
z-index: 9;
|
}
|
.name{
|
text-align: center;
|
font-size: 28rpx;
|
line-height: 40rpx;
|
margin-top: 20rpx;
|
}
|
.ico_head {
|
width: 200rpx;
|
height: 200rpx;
|
border-radius: 50%;
|
}
|
}
|
.page_bg{
|
width: 100%;
|
min-height: calc(100vh - var(--window-bottom));
|
background:url('/static/img/bg_2.jpg') no-repeat center top;
|
background-size: 100% auto;
|
}
|
</style>
|