userinfo_edit.js
4.37 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
var e = getApp(), s = e.globalData.setting, a = e.request, i = require("../../../utils/md5.js"), t = require("../../../utils/common.js");
Page({
data: {
url: s.url,
resourceUrl: s.resourceUrl,
user: null,
type: "",
canGetCode: !1
},
onLoad: function(s) {
var a = this;
this.setBarTitle(s.type), e.getUserInfo(function(e) {
a.setData({
user: e,
type: s.type
});
});
},
setBarTitle: function(e) {
var s = "修改个人信息";
"nickname" == e ? s = "修改昵称" : "mobile" == e ? s = "修改手机" : "email" == e ? s = "修改邮箱" : "password" == e ? s = "修改密码" : "paypwd" == e ? s = "修改支付密码" : "sex" == e && (s = "修改性别"),
wx.setNavigationBarTitle({
title: s
});
},
formSubmit: function(s) {
var a = this.data.type;
if (a) {
var i = s.detail.value;
"nickname" == a ? this.submitNickname(i) : "mobile" == a ? this.submitMobile(i) : "email" == a ? this.submitEmail(i) : "password" == a ? this.submitPassword(i) : "paypwd" == a ? this.submitPaypwd(i) : "sex" == a ? this.submitSex(i) : e.confirmBox("处理类型出错:" + a);
}
},
submitNickname: function(s) {
if (!s.nickname) return e.showWarning("请输入昵称"), !1;
this.requestUpdateUser({
nickname: s.nickname
});
},
submitMobile: function(s) {
return s.mobile ? s.mobile_code ? void this.requestUpdateUser({
mobile: s.mobile,
mobile_code: s.mobile_code
}) : (e.showWarning("请输入验证码"), !1) : (e.showWarning("请输入手机号"), !1);
},
submitEmail: function(s) {
return s.email ? s.email.indexOf("@") < 0 ? (e.showWarning("邮箱格式不正确"), !1) : void this.requestUpdateUser({
email: s.email
}) : (e.showWarning("请输入邮箱"), !1);
},
submitPassword: function(s) {
return this.data.user.password && !s.old_password ? (e.showWarning("请输入旧密码"), !1) : s.new_password ? s.confirm_password ? s.new_password.length < 6 || s.new_password.length > 18 ? (e.showWarning("密码长度不合法"),
!1) : s.new_password !== s.confirm_password ? (e.showWarning("两次密码不一致"), !1) : void a.post("/api/user/password", {
data: {
old_password: i("TPSHOP" + s.old_password),
new_password: i("TPSHOP" + s.new_password)
},
success: function(s) {
e.showSuccess("修改成功", function() {
wx.navigateBack();
});
}
}) : (e.showWarning("请输入确认密码"), !1) : (e.showWarning("请输入新密码"), !1);
},
submitPaypwd: function(s) {
return s.paypwd_mobile ? s.paypwd_code ? s.paypwd ? s.paypwd_confirm ? s.paypwd.length < 6 || s.paypwd.length > 18 ? (e.showWarning("密码长度不合法"),
!1) : s.paypwd !== s.paypwd_confirm ? (e.showWarning("两次密码不一致"), !1) : void a.post("/api/user/paypwd", {
data: {
new_password: i("TPSHOP" + s.paypwd),
mobile: s.paypwd_mobile,
paypwd_code: s.paypwd_code
},
success: function(s) {
e.showSuccess("修改成功", function() {
wx.navigateBack();
});
}
}) : (e.showWarning("请输入确认密码"), !1) : (e.showWarning("请输入新密码"), !1) : (e.showWarning("请输入验证码"),
!1) : (e.showWarning("请输入手机号"), !1);
},
submitSex: function(s) {
if (0 == this.data.user.sex) return e.showWarning("请选择性别"), !1;
this.requestUpdateUser({
sex: this.data.user.sex
});
},
changeGender: function(e) {
var s = "boy" == e.currentTarget.dataset.gender ? 1 : 2;
this.setData({
"user.sex": s
});
},
requestUpdateUser: function(e) {
a.post("/api/user/updateUserInfo", {
data: e,
success: function(e) {
wx.navigateBack();
}
});
},
setMobile: function(e) {
this.data.user.mobile = e.detail.value;
},
getCode: function(e) {
t.sendSmsCode(this.data.user.mobile);
}
});