sadjv3_jishi/pages/my/userinfo.vue

456 lines
11 KiB
Vue
Raw Normal View History

2024-06-05 19:14:51 +08:00
<template>
<view>
<view class="usermain">
<view class="usermain-item ">
<view>头像</view>
<!-- #ifdef MP-WEIXIN -->
<view>
<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" style="background: #FFFFFF;">
<image src="../../static/logo.png" v-if="avatar==null" mode=""
style="width: 111rpx;height: 111rpx;border-radius: 50%;"></image>
<image v-else :src="avatar" mode="" style="width: 111rpx;height: 111rpx;border-radius: 50%;">
</image>
</button>
</view>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
2024-08-19 14:42:28 +08:00
<view @click="toggle()">
<jp-cropper-watermark :watermarkType="1" mode="ratio" :width="530" :height="750" :handleWH="false" :maxWidth="1080" :maxHeight="1920" :url="url" @cancel="oncancel" @ok="onok"></jp-cropper-watermark>
2024-06-05 19:14:51 +08:00
<image src="../../static/logo.png" v-if="avatar==null" mode=""
style="width: 111rpx;height: 111rpx;border-radius: 50%;"></image>
<image v-else :src="avatar" mode="" style="width: 111rpx;height: 111rpx;border-radius: 50%;">
</image>
2024-08-19 14:03:40 +08:00
2024-06-05 19:14:51 +08:00
</view>
<!-- #endif -->
</view>
<view class="usermain-item item-padding ">
<view>用户名</view>
<view>
<view class="cu-form-group">
<input type="nickname" v-model="userName" placeholder="请输入用户名" />
</view>
</view>
</view>
<view class="usermain-item item-padding ">
<view>年龄</view>
<view>
<view class="cu-form-group">
<input v-model="age" />
</view>
</view>
</view>
<!-- <view class="usermain-item item-padding">
<view >姓名</view>
<view class="cu-form-group">
<input v-model="realName" placeholder="请填写您的真实姓名" />
</view>
</view> -->
<view class="usermain-item item-padding ">
<view>手机</view>
<view>
<view class="cu-form-group" v-if="phone">
<input v-model="phone" disabled placeholder="请输入联系电话" />
</view>
<!-- #ifdef MP-WEIXIN -->
<view class="cu-form-group" v-if="!phone">
<button style="border: none;font-size: 28rpx;background: #FFFFFF;" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
授权手机号</button>
</view>
<!-- #endif -->
</view>
</view>
<view class="usermain-item item-padding ">
<view>性别</view>
<view>
<view class="cu-form-group">
<u-radio-group v-model="sex">
2024-06-27 11:08:18 +08:00
<u-radio shape="circle" active-color="#019c88" :name="1"></u-radio>
<u-radio shape="circle" active-color="#019c88" :name="2"></u-radio>
2024-06-05 19:14:51 +08:00
</u-radio-group>
</view>
</view>
</view>
</view>
<view class="footer-btn">
<view class="usermain-btn" @click="messagebtn()">保存</view>
</view>
2024-08-19 14:42:28 +08:00
<view>
<!-- 普通弹窗 -->
2024-08-27 10:56:36 +08:00
<uni-popup ref="popup" type="bottom" background-color="#fff">
2024-08-19 14:42:28 +08:00
<view class="popup-content">
<view class="popup-content-top">
<view @click="uploadImg(0)" class="popup-content-top-btn" style="border-bottom: 1px solid #ccc;">
查看头像
</view>
<view @click="uploadImg(1)" class="popup-content-top-btn">
从相册选择图片
</view>
</view>
<view class="popup-content-bottom" @click="quxiao">
取消
</view>
</view>
</uni-popup>
</view>
2024-06-05 19:14:51 +08:00
</view>
</template>
<script>
import * as websocketUtils from 'utils/websocketUtils.js';
export default {
data() {
return {
phone: '',
avatar: '../../static/logo.png',
userName: '',
nickName: '',
userId: '',
realName: '',
weChatId: "",
password: '',
platform: '',
createTime: '',
money: '',
jiFen: '',
status: '',
zhiFuBao: '',
zhiFuBaoName: '',
sex: 1,
2024-08-19 14:03:40 +08:00
age: 0,
2024-08-19 14:42:28 +08:00
url:'',
upUrl:''
2024-06-05 19:14:51 +08:00
};
},
onLoad(e) {
this.getUserInfo()
// this.avatar = uni.getStorageSync('avatar')
},
methods: {
//小程序微信登录后获取手机号
getPhoneNumber: function(e) {
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
console.log('用户拒绝提供手机号');
} else {
console.log('用户同意提供手机号');
console.log(e)
this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
}
},
//小程序微信登录后获取手机号
setPhoneByInsert(decryptData, iv) {
let that = this;
uni.login({
provider: 'weixin',
success: function(loginRes) {
console.log(loginRes, '************')
let data = {
code: loginRes.code,
type: 2
}
that.$Request.get('/app/Login/wxLogin', data).then(res => {
if (res.code == 0) {
uni.setStorageSync('openId', res.data.open_id)
uni.setStorageSync('unionId', res.data.unionId)
// that.sessionkey = res.data.session_key;
let datat = {
decryptData: decryptData,
key: res.data.session_key,
iv: iv
};
that.$Request.postJson('/app/Login/selectPhone', datat).then(res => {
if (res.code == 0) {
that.phone = res.data.phoneNumber;
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
});
}
})
}
})
}
});
},
//微信填写能力获取头像
onChooseAvatar(e) {
console.log(e.detail.avatarUrl)
let that = this;
let token = uni.getStorageSync('token');
uni.showLoading({
title: '上传中...'
});
let userId = uni.getStorageSync('userId');
uni.uploadFile({
2024-10-26 16:43:55 +08:00
url: websocketUtils.uploadAvatarUrl(), //真实的接口地址
2024-06-05 19:14:51 +08:00
filePath: e.detail.avatarUrl,
header: {
token: token
},
name: 'file',
success: uploadFileRes => {
let url = JSON.parse(uploadFileRes.data);
that.avatar = url.data
uni.hideLoading();
}
});
},
goMyAddress() {
uni.navigateTo({
url: '../jifen/myaddress'
});
},
2024-08-19 14:03:40 +08:00
onok(ev) {
var that=this;
this.url = "";
if(ev.path){
uni.showLoading({
title: '上传中...'
});
let token = uni.getStorageSync('token');
let userId = uni.getStorageSync('userId');
2024-10-26 16:43:55 +08:00
that.upUrl = ev.path;
2024-08-19 14:03:40 +08:00
uni.uploadFile({
2024-10-26 16:43:55 +08:00
url: websocketUtils.uploadAvatarUrl(), //真实的接口地址
2024-08-19 14:42:28 +08:00
filePath:that.upUrl,
2024-08-19 14:03:40 +08:00
header: {
token: token
},
name: 'file',
success: uploadFileRes => {
2024-08-27 10:56:36 +08:00
that.avatar = JSON.parse(uploadFileRes.data).data;
2024-08-19 14:42:28 +08:00
that.$refs.popup.close('bottom')
2024-08-19 14:03:40 +08:00
uni.hideLoading();
}
});
}
},
oncancel() {
// url设置为空隐藏控件
this.url = "";
2024-08-19 10:20:19 +08:00
},
2024-08-19 14:42:28 +08:00
quxiao(){
this.$refs.popup.close('bottom')
},
toggle(type) {
this.$refs.popup.open('bottom')
},
uploadImg(index) {
2024-06-05 19:14:51 +08:00
let token = uni.getStorageSync('token')
if (!token) {
this.goLoginInfo();
return;
}
let that = this;
var url = null;
2024-08-19 14:42:28 +08:00
if (index === 0) {
// 用户点击了预览当前图片
// 可以自己实现当前头像链接的读取
let url = that.avatar;
let arr = []
arr.push(url)
uni.previewImage({
// 预览功能图片也必须是数组的
urls: arr
})
} else if (index === 1) {
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
uni.getImageInfo({
src: res.tempFilePaths[0],
success: (info) => {
const size = info.size;
if (size / 1024 / 1024 > 4) {
// 图片大于2MB
uni.showToast({
icon:'error',
title:'图片超出4MB限制,请重新选择'
})
} else {
that.url = res.tempFilePaths[0];
that.upUrl=res.tempFilePaths[0];
}
}
2024-06-05 19:14:51 +08:00
});
}
2024-08-19 14:42:28 +08:00
});
}
2024-06-05 19:14:51 +08:00
},
2024-08-19 10:20:19 +08:00
2024-06-05 19:14:51 +08:00
getUserInfo() {
let userId = uni.getStorageSync('userId')
this.$Request.get("/app/user/selectUserById").then(res => {
if (res.code == 0) {
this.$queue.setData('avatar', res.data.avatar);
this.$queue.setData('userId', res.data.userId);
this.$queue.setData('userName', res.data.userName);
this.$queue.setData('phone', res.data.phone);
this.$queue.setData('age', res.data.age);
this.sex = res.data.sex
this.age = res.data.age
this.phone = res.data.phone;
this.avatar = res.data.avatar;
this.userName = res.data.userName;
if (this.userName == null) {
this.userName = res.data.nickName;
} else {
this.userName = res.data.userName;
}
}
uni.hideLoading();
});
},
// 保存
messagebtn() {
if (!this.userName) {
// this.$queue.showToast('用户名不能为空');
uni.showToast({
title: "用户名不能为空",
icon: "none"
})
} else if (!this.phone) {
// this.$queue.showToast('用户名不能为空');
uni.showToast({
title: "联系电话不能为空",
icon: "none"
})
} else {
uni.showModal({
title: '温馨提示',
content: '确定保存信息',
success: e => {
if (e.confirm) {
this.$Request.postJson("/app/user/updateUser", {
userName: this.userName,
avatar: this.avatar,
phone: this.phone,
sex: this.sex,
age: this.age
}).then(res => {
if (res.code === 0) {
uni.showToast({
title: '保存成功',
icon: "none"
})
setTimeout(function() {
uni.navigateBack()
}, 1000)
} else {
uni.showToast({
title: res.msg,
icon: "none"
})
}
})
}
}
});
}
}
},
// userphone(){
// uni.navigateTo({
// url:'/pages/my/userphone'
// })
// }
};
</script>
2024-08-19 14:42:28 +08:00
<style scoped>
.popup-content-bottom{
width: 100%;
text-align: center;
padding: 15px 0px;
border-radius: 5px;
background-color: #fcfcfd;
margin: 7px 0px;
}
.popup-content-top{
border-radius: 5px;
background-color: #fcfcfd;
}
.popup-content-top-btn{
width: 100%;
text-align: center;
padding: 15px 0px;
}
.popup-content{
padding: 0 36rpx;
}
2024-06-05 19:14:51 +08:00
page {
background: #f7f7f7;
}
button::after {
border: none;
}
.usermain {
background: #ffffff;
2024-08-19 14:42:28 +08:00
padding: 0 20rpx;
2024-06-05 19:14:51 +08:00
}
.usermain-item {
display: flex;
align-items: center;
padding: 10rpx 0;
justify-content: space-between;
border-bottom: 1rpx solid #f7f7f7;
}
.usermain-item.item-padding {
/* padding: 0; */
}
.cu-form-group {
padding: 0;
background: #ffffff;
text-align: right;
}
.cu-form-group input {
background: #ffffff;
font-size: 28rpx;
/* color: #fff; */
}
.footer-btn {
position: fixed;
width: 100%;
padding: 0 30rpx;
bottom: 0rpx;
left: 0;
right: 0;
background: #FFFFFF;
height: 110rpx;
line-height: 110rpx;
z-index: 999;
}
.footer-btn .usermain-btn {
2024-06-27 11:08:18 +08:00
background: linear-gradient(to right, #019c88, #21b590);
2024-06-05 19:14:51 +08:00
color: #FFFFFF;
margin: 16rpx 0;
width: 100%;
border-radius: 50rpx;
height: 78rpx;
line-height: 78rpx;
font-size: 30rpx;
text-align: center;
}
</style>