Files
xdd-uniapp-new/pkg_user/views/personalData.vue
T
2024-02-06 12:42:46 +08:00

339 lines
8.8 KiB
Vue
Raw 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 type="text" v-model="userInfo.nickname"/>
</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" @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-->
<!-- class="logOut cart-color acea-row row-center-wrapper"-->
<!-- @click="logout"-->
<!-- v-if="$deviceType=='app'"-->
<!-- >退出登录-->
<!-- </view>-->
</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";
export default {
name: "PersonalData",
components: {
ImageCropper
},
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
avatar: "",
isWeixin: false,
currentAccounts: 0,
switchUserInfo: [],
userIndex: 0,
tempFilePath: '',
cropFilePath: '',
};
},
computed: mapGetters(["userInfo"]),
mounted: function () {
this.avatar = this.userInfo.avatar;
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");
}
},
// switchAccounts: function (index) {
// let that = this;
// this.userIndex = index;
// let userInfo = this.switchUserInfo[this.userIndex];
// if (this.switchUserInfo.length <= 1) return true;
// if (userInfo === undefined) {
// uni.showToast({
// title: "切换的账号不存在",
// icon: "none",
// duration: 2000
// });
// return;
// }
// if (userInfo.user_type === "h5") {
// switchH5Login()
// .then(({data}) => {
// uni.hideLoading();
// const expires_time = dayjs(data.expires_time);
// store.commit("login", data.token, expires_time);
// that.$emit("changeswitch", false);
// location.reload();
// })
// .catch(err => {
// uni.hideLoading();
// uni.showToast({
// title:
// err.msg || err.response.data.msg || err.response.data.message,
// icon: "none",
// duration: 2000
// });
// });
// } else {
// cookie.set("loginType", "wechat", 60);
// uni.hideLoading();
// this.$store.commit("logout");
// this.$emit("changeswitch", false);
// }
// },
chooseImage() {
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: (res) => {
this.tempFilePath = res.tempFilePaths.shift()
}
});
},
submit: function () {
let userInfo = this.userInfo;
let that = this;
postUserEdit({
nickname: trim(this.userInfo.nickname),
avatar: this.avatar
}).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
});
}
);
},
// logout: function () {
// uni.showModal({
// title: "提示",
// content: "确认退出登录?",
// success: function (res) {
// if (res.confirm) {
// getLogout()
// .then(res => {
// this.$store.commit("logout");
// this.$yrouter.replace({
// path: "/pages/user/Login/index",
// query: {}
// });
// })
// .catch(() => {
// })
// }
// }
// });
// }
}
}
</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;
height: 406rpx;
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;
}
.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>