set.vue
7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<template>
<view class="set-page">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view @click="upAvatar" class="u-flex set-main">
<view class="main-image"><image class="image" :src="avatar || '../../static/logo.png'"></image></view>
<view class="main-right-image"><image class="image" src="../../static/arrow-right.png"></image></view>
</view>
<view class="u-m-t-20 basic-text"><text class="text">基本资料</text></view>
<view class="basic-main">
<u--form labelPosition="left" :model="myInfoModel">
<u-form-item labelWidth="80px" label="真实姓名" prop="userInfo.realName" borderBottom ref="item1">
<u--input placeholder="请输入真实姓名" v-model="myInfoModel.userInfo.realName" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="手机号码" prop="userInfo.phoneNumber" borderBottom ref="item1">
<u--input placeholder="请输入手机号码" v-model="myInfoModel.userInfo.phoneNumber" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="用户账号 " prop="userInfo.username" borderBottom ref="item1">
<u--input placeholder="请输入用户账号 " v-model="myInfoModel.userInfo.username" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="邮箱地址" prop="userInfo.email" borderBottom ref="item1">
<u--input placeholder="请输入邮箱地址" v-model="myInfoModel.userInfo.email" border="none"></u--input>
</u-form-item>
<u-form-item
@click="
showDate = true;
hideKeyboard();
"
labelWidth="80px"
label="有效期"
prop="userInfo.accountExpireTime"
ref="item1"
>
<u--input v-model="myInfoModel.userInfo.accountExpireTime" placeholder="请选择有效期" border="none"></u--input>
<u-datetime-picker
:formatter="formatter"
:show="showDate"
:value="datetime"
mode="dateTime"
closeOnClickOverlay
@confirm="dateConfirm"
@cancel="dateClose"
@close="dateClose"
></u-datetime-picker>
</u-form-item>
</u--form>
</view>
<view class="basic-bottom u-flex">
<view class="item" v-if="info.data.isThirdLogin">
<button class="submit" size="default" @click="clearAccountFunc" :style="{ background: InfoColor }"><text class="un-bind-text">解绑</text></button>
</view>
<view class="item" style="margin-right: 60rpx;" :style="[{ position: info.data.isThirdLogin ? '' : 'relative' }, { right: info.data.isThirdLogin ? '' : '-158rpx' }]">
<button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }"><text class="un-bind-text">确认</text></button>
</view>
</view>
<!-- #ifdef MP -->
<view class="u-m-t-40"><text style="visibility: hidden;">#</text></view>
<!-- #endif -->
<!-- 解绑账号 -->
<view>
<u-popup bgColor="transparent" :overlay="true" :show="showBind" mode="bottom">
<view class="u-flex logout-main">
<view class="main"><text style="color: #999999">是否需要解除绑定的账号?</text></view>
<view @click="confrimBind(info)" class="main"><text style="color: #f95e5a">是</text></view>
<view @click="showBind = false" class="main1"><text style="color: #3478f7">否</text></view>
</view>
</u-popup>
</view>
<!-- 解绑账号 -->
</view>
</template>
<script>
import { mapMutations } from 'vuex';
export default {
data() {
return {
showBind: false,
PrimaryColor: '#377DFF', //主题色
InfoColor: '#00C9A7', //主题色
myInfoModel: {
userInfo: {
realName: '',
phoneNumber: '',
username: '',
email: '',
accountExpireTime: ''
}
},
showDate: false,
dateTime: Number(new Date()),
avatar: '',
id: '',
info: {},
openIds: '',
isUpdatePersonOrLoginInfo: false
};
},
onLoad(e) {
if (e.data !== null) {
let params = JSON.parse(e.data);
this.info = params;
this.myInfoModel.userInfo.realName = params.data.realName;
this.myInfoModel.userInfo.phoneNumber = params.data.phoneNumber;
this.myInfoModel.userInfo.username = params.data.username;
this.myInfoModel.userInfo.email = params.data.email;
this.myInfoModel.userInfo.accountExpireTime = params.data.accountExpireTime;
this.avatar = params.data.avatar == undefined ? '../../static/logo.png' : params.data.avatar;
this.id = params.data.userId;
}
},
onShow() {
let getOpenId = getApp().globalData.openId;
if (getOpenId) {
this.openIds = getOpenId;
}
},
methods: {
...mapMutations(['setUserInfo']),
confrimBind(e) {
if (e) {
//解绑
let httpData = {
appUserId: e.data?.userId,
thirdUserId: e.third?.thirdUserId == null ? this.openIds : e.third?.thirdUserId
};
uni.$u.http.delete('/yt/third', httpData).then(res => {
if (res) {
uni.showToast({
title: '解绑成功'
});
this.showBind = false;
} else {
uni.showToast({
title: '解绑失败'
});
this.showBind = false;
}
});
}
},
clearAccountFunc() {
this.showBind = true;
},
// 修改头像
upAvatar() {
var that = this;
uni.chooseImage({
count: 1,
sourceType: ['camera', 'album'],
success: res => {
const tempFilePaths = res.tempFilePaths;
//限制上传的图片大小不超过2M
let resSize = res.tempFiles[0].size;
if (resSize > 2097152) {
uni.showToast({
title: '上传的图片大小不能超过2M',
icon: 'none',
duration: 2000,
mask: true
});
return;
}
//获取图片扩展名
const fileTxt = res.tempFilePaths[0].split('.').pop();
const judgeType = fileTxt == 'jpg' || fileTxt == 'jpeg' || fileTxt == 'png';
if (!judgeType) {
uni.showToast({
title: '请上传指定图片类型(jpg、jpeg、png)',
icon: 'none',
duration: 2000,
mask: true
});
return;
}
uni.$u.http
.upload('/yt/oss/upload', {
filePath: tempFilePaths[0],
name: 'file'
})
.then(res => {
if (res) {
that.avatar = res.fileStaticUri;
return uni.$u.toast('头像上传成功');
}
});
}
});
},
onSubmitFunc() {
let httpData = {
avatar: this.avatar,
email: this.myInfoModel.userInfo.email,
id: this.id,
phoneNumber: this.myInfoModel.userInfo.phoneNumber,
realName: this.myInfoModel.userInfo.realName
};
uni.$u.http
.put('/yt/user/center', httpData)
.then(res => {
if (res) {
this.setUserInfo(res);
uni.showToast({
title: '更新个人资料成功~',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 500);
}
})
.catch(e => {
uni.$u.toast(e.data.message);
});
},
dateClose() {
this.showDate = false;
},
dateConfirm(e) {
this.showDate = false;
this.myInfoModel.userInfo.accountExpireTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
},
//格式化日期
formatter(type, value) {
if (type === 'year') {
return `${value}年`;
}
if (type === 'month') {
return `${value}月`;
}
if (type === 'day') {
return `${value}日`;
}
if (type === 'hour') {
return `${value}时`;
}
if (type === 'minute') {
return `${value}分`;
}
return value;
},
//隐藏输入框
hideKeyboard() {
uni.hideKeyboard();
}
}
};
</script>
<style lang="scss" scoped>
@import './static/set.scss';
/deep/ .u-line {
width: 662rpx !important;
}
/deep/ .u-form-item {
height: 100rpx !important;
}
</style>