oil-station/gasStation-uni/pagesMy/setup/index.vue

275 lines
7.0 KiB
Vue
Raw Normal View History

2024-08-16 18:26:19 +08:00
<template>
<view class="content">
<view class="container">
<view class="my-header">
<view class="my-icons" @click="goBack"> <uni-icons type="left" size="16"></uni-icons> </view>
2024-09-25 15:10:46 +08:00
<view class="my-text">个人资料</view>
2024-08-16 18:26:19 +08:00
<view class="my-icons"></view>
</view>
<!-- 顶部区域 -->
<!-- #ifdef MP-WEIXIN -->
<button class="box-hang" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<view class="">头像</view>
<view class="touxiang">
2024-09-22 14:16:55 +08:00
<image class="touxiang" v-if="user.avatar!='' && user.avatar!=null && user.avatar!=undefined"
:src="baseUrl + user.avatar" mode="aspectFit"></image>
2024-09-25 15:10:46 +08:00
<image class="touxiang" v-else src="@/static/icon/icon/newmy.png" mode="aspectFit"></image>
2024-08-16 18:26:19 +08:00
</view>
</button>
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<button class="box-hang" @click="onChooseAvatar1">
<view class="">头像</view>
<view class="touxiang">
2024-09-22 14:16:55 +08:00
<image class="touxiang" v-if="user.avatar!='' && user.avatar!=null && user.avatar!=undefined"
:src="baseUrl + user.avatar" mode="aspectFit"></image>
2024-09-25 15:10:46 +08:00
<image class="touxiang" v-else src="@/static/icon/icon/newmy.png" mode="aspectFit"></image>
2024-08-16 18:26:19 +08:00
</view>
</button>
<!-- #endif -->
<view class="box-hang" @click="goEdit(0)">
<view class="">昵称</view>
2024-09-22 14:16:55 +08:00
<view class="dis">
<text v-if="!user.name">未填写</text>
<text v-else>{{user.name}}</text>
<uni-icons type="right" size="16"></uni-icons>
2024-08-16 18:26:19 +08:00
</view>
</view>
2024-09-22 14:16:55 +08:00
<view class="box-hang" @click="show1 =!show1">
<view class="">性别</view>
2024-09-25 15:10:46 +08:00
<view class="dis">
<text v-if="user.sex==1"></text>
<text v-else-if="user.sex==0"></text>
<text v-else>不详</text>
<uni-icons type="right" size="16"></uni-icons>
</view>
2024-09-22 14:16:55 +08:00
</view>
<view class="box-hang" @click="show=!show">
<view class="">生日</view>
<view class="dis"> <text>{{user.birthday}}</text> <uni-icons type="right" size="16"></uni-icons> </view>
</view>
<!-- <view class="box-hang">
2024-08-16 18:26:19 +08:00
<view class="">手机号</view>
<view class="dis"> <text>{{user.mobile}}</text> <uni-icons type="right" size="16"></uni-icons> </view>
</view>
<view class="box-hang">
<view class="">会员号</view>
<view class="dis"> <text>{{user.userNo}}</text> <uni-icons type="right" size="16"></uni-icons> </view>
2024-09-22 14:30:12 +08:00
</view> -->
2024-09-25 15:10:46 +08:00
<!-- <view class="box-hang" @click="goEdit(2)">
2024-08-16 18:26:19 +08:00
<view class="">车牌号</view>
<view class="dis">
<text v-if="!user.carNo">未填写</text>
<text v-else>{{user.carNo}}</text> <uni-icons type="right" size="16"></uni-icons>
</view>
2024-09-25 15:10:46 +08:00
</view> -->
2024-08-16 18:26:19 +08:00
<!-- <view class="box-hang" @click="goEdit(3)">
2024-09-22 14:16:55 +08:00
<view class="">会员支付设置</view>
<view class="dis"> <text>已设置</text> <uni-icons type="right" size="16"></uni-icons> </view>
2024-08-16 18:26:19 +08:00
</view> -->
2024-09-22 14:16:55 +08:00
<u-datetime-picker :show="show" v-model="value1" mode="date" @cancel="cancel1"
@confirm="confirm1"></u-datetime-picker>
<u-picker :show="show1" :columns="columns" @cancel="cancel" @confirm="confirm"></u-picker>
2024-08-16 18:26:19 +08:00
</view>
</view>
</template>
<script>
import request from "../../utils/request";
import upload from '@/utils/upload.js'
export default {
data() {
return {
title: '',
// 用户信息
2024-09-22 14:16:55 +08:00
user: {
2024-08-16 18:26:19 +08:00
// 用户头像
2024-09-22 14:16:55 +08:00
avatar: "",
2024-08-16 18:26:19 +08:00
},
// url信息
baseUrl: this.$baseUrl,
2024-09-22 14:16:55 +08:00
columns: [
['全部类型', '消费有礼', '会员充值']
],
show: false,
show1: false,
2024-08-16 18:26:19 +08:00
}
},
onShow() {
this.getUser()
},
components: {
},
methods: {
2024-09-22 14:16:55 +08:00
confirm(e) {
this.show1 = false
},
cancel() {
this.show1 = false
},
timestampToString(timestamp) {
// 将时间戳转换为Date对象
const date = new Date(timestamp);
// 使用toLocaleDateString和toLocaleTimeString可以根据本地格式转换日期和时间
const dateString = date.toLocaleDateString()
const timeString = date.toLocaleTimeString();
// 返回日期和时间的组合
return date.getFullYear() + '-' + (date.getMonth() + 1);
},
confirm1(e) {
this.show = false
},
cancel1() {
this.show = false
},
2024-08-16 18:26:19 +08:00
// 用户选择头像
2024-09-22 14:16:55 +08:00
onChooseAvatar(e) {
2024-08-16 18:26:19 +08:00
let _this = this;
let tempFilePath = e.detail.avatarUrl //上传的图片地址
2024-09-22 14:16:55 +08:00
let maxSizeInBytes = 1024 * 1024 //限制大小
2024-08-16 18:26:19 +08:00
uni.getFileInfo({
2024-09-22 14:16:55 +08:00
filePath: tempFilePath,
2024-08-16 18:26:19 +08:00
success(res) {
let fileSize = res.size
2024-09-22 14:16:55 +08:00
if (fileSize > maxSizeInBytes) {
2024-08-16 18:26:19 +08:00
uni.showToast({
2024-09-22 14:16:55 +08:00
title: "请上传小于1MB的图片",
icon: "error"
2024-08-16 18:26:19 +08:00
})
return
}
console.log(tempFilePath)
// 将图片上传服务器
upload({
url: '/clientApi/file/upload',
filePath: tempFilePath,
}).then((res) => {
console.log('images', res.data.fileName);
_this.user.avatar = res.data.fileName
_this.editUser()
})
},
})
},
// 用户选择头像
2024-09-22 14:16:55 +08:00
onChooseAvatar1(e) {
2024-08-16 18:26:19 +08:00
let _this = this;
//从本地相册选择图片或使用相机拍照
uni.chooseImage({
2024-09-22 14:16:55 +08:00
sourceType: ['album', 'camera'], //选择方式相册或者相机
2024-08-16 18:26:19 +08:00
success: (res) => {
console.log('图片', res)
var tempFilePath = res.tempFilePaths;
var filePath = tempFilePath[0];
2024-09-22 14:16:55 +08:00
console.log(filePath); //输出本地头像路径
//调用上传下载api
2024-08-16 18:26:19 +08:00
// 将图片上传服务器
upload({
url: '/clientApi/file/upload',
filePath: filePath,
}).then((res) => {
console.log('images', res.data.fileName);
_this.user.avatar = res.data.fileName
_this.editUser()
})
}
});
},
// 修改用户信息
2024-09-22 14:16:55 +08:00
editUser() {
2024-08-16 18:26:19 +08:00
request({
url: 'business/userManager/user/edit',
method: 'put',
2024-09-22 14:16:55 +08:00
data: this.user,
2024-08-16 18:26:19 +08:00
}).then(res => {
if (res.code == 200) {
this.getUser()
}
})
},
// 跳转修改页面
2024-09-22 14:16:55 +08:00
goEdit(val) {
2024-08-16 18:26:19 +08:00
uni.navigateTo({
url: '/pagesMy/editUser/index?editType=' + val,
})
},
// 查询当前登录用户信息
2024-09-22 14:16:55 +08:00
getUser() {
2024-08-16 18:26:19 +08:00
request({
url: 'business/userManager/user/getUser',
method: 'get',
}).then(res => {
if (res.data != null && res.data != "" && res.data != undefined) {
this.user = res.data
}
})
},
goBack() {
uni.navigateTo({
2024-09-22 14:16:55 +08:00
url: "/pages/my/my"
2024-08-16 18:26:19 +08:00
})
}
}
}
</script>
<style scoped lang="scss">
.content {
background: #f4f5f6;
}
.container {
width: 100%;
height: 100vh;
box-sizing: border-box;
padding-top: 88px;
}
.my-header {
width: 100%;
height: 88px;
background: #ffffff;
display: flex;
align-items: center;
justify-content: space-between;
color: #000;
box-sizing: border-box;
padding: 0px 15px;
padding-top: 40px;
.my-icons {
width: 20px;
}
position: fixed;
top: 0px;
}
.box-hang {
background-color: white;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
padding: 15px 10px;
border-bottom: 1px solid #f4f5f6;
}
.touxiang {
width: 50px;
height: 50px;
border-radius: 50%;
overflow: hidden;
// background-color: #f4f5f6;
}
.dis {
color: #a69999;
}
</style>