modifyPersonInformation.js
6.4 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// pages/my/modifyPersonInformation/modifyPersonInformation.js
const app = getApp();
const qiniuUploader = require("../../../utils/qiniuUploader");
Page({
/**
* 页面的初始数据
*/
data: {
flag: false,
birth: false,
choose: 10,
photoPath: "",
user: {},
mobile: '',
phone: '',
birthday: '',
nick_name: '',
nick_names: '',
sex: '',
nameFlag: false,
key:''
},
//选择上传头像
changePhoto: function () {
var that = this;
// 选择图片
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
const filePath = res.tempFilePaths[0];
that.setData({
photoPath: filePath
});
qiniuUploader.upload(filePath, (res) => {
console.log(res)
let a ='http://qiniu.himrhi.com/'+res.key
that.setData({
key: a
});
}, (error) => {
console.log('error: ' + error);
}, {
region: 'ECN',
domain: 'qiniu.himrhi.com',
uptokenURL: 'http://www.himrhi.com/api/wxapp/public/getQiniuToken',
uptokenFunc: function () { return 'JMgHPK8vEdZfUfxZIW8qIsyucRCZeTZ4aqHLWsjI:9VjchzcKJTa9uqK_0MWELzc4_zg=:eyJzY29wZSI6ImhpLWZyZXNoIiwiZGVhZGxpbmUiOjE1NjA3MzU3ODF9'; }
}, (res) => {
console.log('上传进度', res.progress)
console.log('已经上传的数据长度', res.totalBytesSent)
console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
}, () => {
// 取消上传
}, () => {
// `before` 上传前执行的操作
}, (err) => {
// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
});
}
})
},
//修改性别
//修改男
choose1() {
this.setData({
choose: 1
});
},
//修改女
choose2() {
this.setData({
choose: 2
});
},
//渲染个人信息
fetchPersonal() {
let that = this
let url = '/wxapp/user/getUserInfo'
app.post(url).then(r => {
if (r.code == 1) {
if (r.data.sex == 1) {
r.data.sex = '女'
} else {
r.data.sex = '男'
}
let leixing=typeof(r.data.birthday)
if (leixing == 'number'){
r.data.birthday = app.timeFormate(r.data.birthday, 'YYMMDD')
}
// r.data.birthday = app.timeFormate(r.data.birthday, 'YYMMDD')
that.setData({
user: r.data,
phone: r.data.mobile,
birthday: r.data.birthday,
nick_name: r.data.user_nickname,
sex: r.data.sex,
photoPath:r.data.avatar
})
}
})
},
//选择生日
bindDateChange(e) {
let birthday = e.detail.value;
this.setData({
birthday: birthday
})
},
//确认修改
confirmUpdate() {
let that = this
let url = '/wxapp/user/setUserInfo'
let sex = ''
if (that.data.choose == 2) {
sex =1
} else if (that.data.choose == 1) {
sex =2
} else if (that.data.choose == 10) {
sex = that.data.sex
if(that.data.sex=='女'){
sex=1
}else{
sex=2
}
}
if (sex == '' && !sex) {
wx.showToast({
title: '请确定性别',
icon: 'none'
})
return;
}
if (that.data.birthday == '' && !that.data.birthday) {
wx.showToast({
title: '请确定生日',
icon: 'none'
})
return;
}
if (that.data.nick_names == ''&&that.data.nick_name=='') {
wx.showToast({
title: '请确定昵称',
icon: 'none'
})
return;
}
let nick_names=''
if(that.data.nick_names!=''){
nick_names=that.data.nick_names
}else{
nick_names=that.data.nick_name
}
let avatar = that. data.key
if (that.data.photoPath == '' && avatar == '') {
wx.showToast({
title: '请确定头像',
icon: 'none'
})
return;
}
if(that.data.avatar==''){
avatar=that.data.photoPath
}else{
avatar=that.data.key
}
console.log(avatar+"新的头像信息")
console.log(that.data.birthday+"生日")
let params = {
avatar: avatar,
user_nickname: nick_names,
sex: sex,
birthday: that.data.birthday
}
app.post(url, params).then(r => {
if (r.code == 1) {
wx.showToast({
title: '修改成功',
icon: 'none'
})
this.fetchPersonal();
wx.switchTab({
url: '../../my/my',
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this
that.fetchPersonal();
if (options.mobile) {
that.setData({
mobile: options.mobile
})
}
if (options.value) {
that.setData({
nick_names: options.value,
nameFlag: true
})
}
},
// 返回个人中心
get_my() {
wx.switchTab({
url: '../my',
})
},
// 修改昵称
getamend_nickname() {
wx.navigateTo({
url: '../modifyName/modifyName',
})
},
// 修改手机号
getamend_nickphone() {
wx.navigateTo({
url: '../modifyPhone/modifyPhone',
})
},
//修改性别
changeSex() {
this.setData({
flag: !this.data.flag
});
},
//修改生日
changeBirth() {
this.setData({
birth: !this.data.birth
});
},
//点击修改性别确定
hide() {
this.setData({
flag: !this.data.flag
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})