Change_phone.js
6.23 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
var a = getApp(),
o = a.globalData,
r = a.globalData.setting,
t = a.request,
s = require("../../../../utils/common.js"),
util = require("../../../../utils/util.js");
Page({
/**
* 页面的初始数据
*/
data: {
iurl: r.imghost,
inputxphone: 1,
mobile: null, //旧手机号码
currentTime: "", //验证码发送倒计时
getvcode: "获取验证码", //显示文字
time_len: 0, //重新获取时长
wxopenid: null,
isver: 0, //是否有发送验证码
code: "", //验证码
change_phone: "", //新手机号码
send: 1, //发送类型
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var th = this;
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2]; //上一个页面
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
is_zy: 1
})
getApp().getConfig2(function(ee) {
var sms_conf = ee.sms_send_type;
sms_conf = JSON.parse(sms_conf);
th.setData({
mobile: getApp().globalData.userInfo.mobile,
wxopenid: getApp().globalData.userInfo.weapp_openid,
time_len: sms_conf?sms_conf.time_out:60
})
})
},
//获取手机验证码
Ver_phone: function() {
var th = this;
var mobile = th.data.mobile;
var wxopenid = th.data.wxopenid;
var change_phone = th.data.change_phone;
var isver = th.data.isver;
var send = th.data.send;
var myreg = /^(((11[0-9]{1})|(12[0-9]{1})|(13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
if(change_phone){
if (change_phone.length < 11) {
getApp().my_warnning("请输入11位的手机号码", 0, th);
} else if (!myreg.test(change_phone)) {
getApp().my_warnning("手机号有误", 0, th);
return false;
}
}else{
getApp().my_warnning("请输入11位的手机号码", 0, th);
return false;
if (mobile.length < 11) {
getApp().my_warnning("请输入11位的手机号码", 0, th);
} else if (!myreg.test(mobile)) {
getApp().my_warnning("手机号有误", 0, th);
return false;
}
}
if (change_phone == mobile) {
getApp().my_warnning("新手机号码和旧手机号码不能一样", 0, th);
return false;
}
if (change_phone != "") {
mobile = change_phone;
}
if (isver == 0) {
th.setData({
isver: 1
})
} else {
return false
}
getApp().request.post("/api/weshop/smslog/sendsms", {
data: {
store_id: r.stoid,
scene: send, //发送类型(1短信 2语音)
mobile: mobile,
wxopenid: wxopenid
},
success: function(res) {
if (res.data.code == 0) {
th.setData({
isver: 0,
getvcode: th.data.time_len,
currentTime: setInterval(th.gettime, 1000),
send: 2
})
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.setData({
isver: 0,
getvcode: "重新获取",
})
return false;
}
}
})
},
gettime: function() {
var that = this;
if (that.data.getvcode == 1) {
//清除js定时器
clearInterval(that.data.currentTime);
that.setData({
getvcode: "重新获取",
});
} else {
that.setData({
getvcode: --that.data.getvcode,
});
}
},
change_phone: function() {
var th = this;
var code = th.data.code;
var mobile = th.data.mobile;
var change_phone = th.data.change_phone;
if (change_phone.length > 1) {
mobile = change_phone
}
if(!change_phone){
return getApp().my_warnning("请输入手机号", 0, th);
}
if(!code){
return getApp().my_warnning("请输入验证码", 0, th);
}
getApp().request.put("/api/weshop/users/updateMobile/" + r.stoid + '/' + o.user_id + '/' + code + '/' + mobile, {
success: function(res) {
if (res.data.code == 0) {
var url = "/pages/user/userinfo/userinfo?change_phone" + change_phone
getApp().globalData.userInfo.mobile = mobile;
getApp().my_warnning("更换成功", 0, th);
getApp().goto(url);
} else {
getApp().my_warnning(res.data.msg, 0, th);
return false;
}
}
})
},
//判断验证码是否正确
ver_code: function(e) {
var th = this;
var code = th.data.code,
mobile = th.data.mobile,
wxopenid = th.data.wxopenid,
getvcode = th.data.getvcode,
chang_phone = th.data.change_phone;
if (code.length < 3 && code == "") {
getApp().my_warnning("请输入正确的验证码", 0, th);
return false;
} else if (getvcode.length < 3) {
getApp().my_warnning("验证超时", 0, th);
return false;
} else {
getApp().request.put("/api/weshop/users/updateMobileFirst/" + r.stoid + '/' + o.user_id + '/' + code, {
success: function(res) {
if (res.data.code == 0) {
th.setData({
inputxphone: 1,
getvcode: "获取验证码",
code: ""
})
clearInterval(th.data.currentTime);
} else {
getApp().my_warnning(res.data.msg, 0, th);
return false;
}
}
})
}
},
getCodeValue: function(e) {
this.setData({
code: e.detail.value
})
},
getphoneValue: function(e) {
var th = this;
th.setData({
change_phone: e.detail.value,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
getApp().globalData.no_clear=1
}
})