Commit 240a354d0f03efcba3949aaaf6914265247f54c2

Authored by iceling
1 parent aaae60ec

手机验证

pages/user/Change_phone/Change_phone.js
1   -
2 1 var a = getApp(),
  2 + o = a.globalData,
3 3 r = a.globalData.setting,
4 4 t = a.request,
5 5 s = require("../../../utils/common.js"),
... ... @@ -11,68 +11,203 @@ Page({
11 11 */
12 12 data: {
13 13 iurl: r.imghost,
14   - inputxphone:false,
15   - phone:0,
  14 + inputxphone: 0,
  15 + mobile: 17359580658, //旧手机号码
  16 + currentTime: "", //验证码发送倒计时
  17 + getvcode: "获取验证码",
  18 + wxopenid: "2",
  19 + isver: 0, //是否有发送验证码
  20 + code: "", //验证码
  21 + url: "", //确认更换手机号码跳转路径
  22 + change_phone: "", //新手机号码
16 23 },
17 24 /**
18 25 * 生命周期函数--监听页面加载
19 26 */
20   - onLoad: function (options) {
21   - this.setData({
22   - phone: options.mobile
  27 + onLoad: function(options) {
  28 + this.setData({
  29 + // mobile: options.mobile,
  30 + //wxOpneId: options.openid
  31 + })
  32 + },
  33 + //获取手机验证码
  34 + Ver_phone: function() {
  35 + var th = this;
  36 + var mobile = th.data.mobile;
  37 + var wxopenid = th.data.wxopenid;
  38 + var change_phone = th.data.change_phone;
  39 + var isver = th.data.isver;
  40 + console.log("iiiiiiiiiiiiii" + change_phone + mobile);
  41 + var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  42 + if (mobile.length < 11) {
  43 + getApp().my_warnning("请输入11位的手机号码", 0, th);
  44 + } else if (!myreg.test(mobile)) {
  45 + getApp().my_warnning("手机号有误", 0, th);
  46 + return false;
  47 + }
  48 + if (change_phone == mobile) {
  49 + getApp().my_warnning("新手机号码和旧手机号码不能一样", 0, th);
  50 + return false;
  51 + }
  52 + if (change_phone != "") {
  53 + mobile = change_phone;
  54 + }
  55 + if (isver == 0) {
  56 + th.setData({
  57 + isver: 1
  58 + })
  59 + } else {
  60 + return false
  61 + }
  62 + getApp().request.post("/api/weshop/smslog/sendsms", {
  63 + data: {
  64 + store_id: r.stoid,
  65 + scene: 1, //发送类型(1短信 2语音)
  66 + mobile: mobile,
  67 + wxopenid: wxopenid
  68 + },
  69 + success: function(res) {
  70 + if (res.data.code == 0) {
  71 + th.setData({
  72 + isver: 0,
  73 + getvcode: 60,
  74 + currentTime: setInterval(th.gettime, 1000),
  75 + })
  76 + } else {
  77 + getApp().my_warnning(res.data.msg, 0, th);
  78 + th.setData({
  79 + isver: 0,
  80 + getvcode: "重新获取"
  81 + })
  82 + return false;
  83 + }
  84 + }
  85 + })
  86 +
  87 + },
  88 + gettime: function() {
  89 + var that = this;
  90 + if (that.data.getvcode == 1) {
  91 + //清除js定时器  
  92 + clearInterval(that.data.currentTime);
  93 + that.setData({
  94 + getvcode: "重新获取",
  95 + });
  96 + } else {
  97 + that.setData({
  98 + getvcode: --that.data.getvcode,
  99 + });
  100 + }
  101 + },
  102 + change_phone: function() {
  103 + var th = this;
  104 + var code = th.data.code;
  105 + var mobile = th.data.mobile;
  106 + if (th.ver_code() == false) return false;
  107 + getApp().request.put("/api/weshop/users/updateMobile/" + r.stoid + '/' + o.user_id + '/' + code + '/' + mobile, {
  108 + success: function(res) {
  109 + if (res.data.code == 0) {
  110 + getApp().my_warnning("更换成功", 0, th);
  111 + // th.setData({
  112 + // url: "/pages/user/userinfo/userinfo?change_phone" + change_phone
  113 + // })
  114 + } else {
  115 + getApp().my_warnning("更换失败", 0, th);
  116 + return false;
  117 + }
  118 + }
  119 + })
  120 +
  121 + },
  122 + //判断验证码是否正确
  123 + ver_code: function(e) {
  124 + var th = this;
  125 + var code = th.data.code,
  126 + mobile = th.data.mobile,
  127 + wxopenid = th.data.wxopenid,
  128 + getvcode = th.data.getvcode,
  129 + chang_phone = th.data.change_phone;
  130 + if (code.length < 3 && code == "") {
  131 + getApp().my_warnning("请输入正确的验证码", 0, th);
  132 + return false;
  133 + } else if (getvcode.length<3){
  134 + getApp().my_warnning("验证超时", 0, th);
  135 + return false;
  136 + }else {
  137 + getApp().request.put("/api/weshop/users/updateMobileFirst/" + r.stoid + '/' + o.user_id + '/' + code, {
  138 + success: function(res) {
  139 + if (res.data.code == 0) {
  140 + th.setData({
  141 + inputxphone: 1,
  142 + getvcode: "获取验证码",
  143 + code: ""
  144 + })
  145 + clearInterval(th.data.currentTime);
  146 + } else {
  147 + getApp().my_warnning(res.data.msg, 0, th);
  148 + return false;
  149 + }
  150 + }
23 151 })
  152 + }
24 153 },
25   - go: function (e) {
  154 + getCodeValue: function(e) {
26 155 this.setData({
27   - inputxphone: true
  156 + code: e.detail.value
  157 + })
  158 + },
  159 + getphoneValue: function(e) {
  160 + var th = this;
  161 + th.setData({
  162 + change_phone: e.detail.value,
28 163 })
29 164 },
30 165 /**
31 166 * 生命周期函数--监听页面初次渲染完成
32 167 */
33   - onReady: function () {
  168 + onReady: function() {
34 169  
35 170 },
36 171  
37 172 /**
38 173 * 生命周期函数--监听页面显示
39 174 */
40   - onShow: function () {
  175 + onShow: function() {
41 176  
42 177 },
43 178  
44 179 /**
45 180 * 生命周期函数--监听页面隐藏
46 181 */
47   - onHide: function () {
  182 + onHide: function() {
48 183  
49 184 },
50 185  
51 186 /**
52 187 * 生命周期函数--监听页面卸载
53 188 */
54   - onUnload: function () {
  189 + onUnload: function() {
55 190  
56 191 },
57 192  
58 193 /**
59 194 * 页面相关事件处理函数--监听用户下拉动作
60 195 */
61   - onPullDownRefresh: function () {
  196 + onPullDownRefresh: function() {
62 197  
63 198 },
64 199  
65 200 /**
66 201 * 页面上拉触底事件的处理函数
67 202 */
68   - onReachBottom: function () {
  203 + onReachBottom: function() {
69 204  
70 205 },
71 206  
72 207 /**
73 208 * 用户点击右上角分享
74 209 */
75   - onShareAppMessage: function () {
  210 + onShareAppMessage: function() {
76 211  
77 212 }
78 213 })
79 214 \ No newline at end of file
... ...
pages/user/Change_phone/Change_phone.json
1 1 {
2 2 "navigationBarTitleText": "更换手机",
3   - "usingComponents": {}
  3 +"usingComponents": {
  4 + "warn": "/components/long_warn/long_warn"
  5 +}
4 6 }
5 7 \ No newline at end of file
... ...
pages/user/Change_phone/Change_phone.wxml
... ... @@ -8,20 +8,25 @@
8 8 <!-- 手机号码 -->
9 9 <view class="flex-vertical phone">
10 10 <image src="{{iurl}}/miniapp/images/userinfo/phone.png"></image>
11   - <block wx:if="{{inputxphone==false}}">
12   - <view class="inphone">{{phone}}</view>
  11 + <block wx:if="{{inputxphone==0}}">
  12 + <view class="inphone">{{mobile}}</view>
13 13 </block>
14 14 <block wx:else>
15   - <input class="inphone" placeholder="输入新手机号" type="number" maxlength="11"/>
  15 + <input bindblur="getphoneValue" class="inphone" placeholder="输入新手机号" type="number" maxlength="11" value="{{change_phone}}"/>
16 16 </block>
17 17 </view>
18 18  
19 19 <!-- 发送手机验证码 -->
20 20 <view class="flex-vertical code">
21 21 <image src="{{iurl}}/miniapp/images/userinfo/code.png"></image>
22   - <input placeholder="请输入验证码" type="number" maxlength="10" />
  22 + <input placeholder="请输入验证码" bindinput="getCodeValue" type="number" maxlength="6" value="{{code}}" />
23 23 <view class="flex-center Obtain">
24   - <view>获取验证码</view>
  24 + <block wx:if="{{getvcode.length>3}}">
  25 + <view bindtap="Ver_phone">{{getvcode}}</view>
  26 + </block>
  27 + <block wx:else>
  28 + <view>{{getvcode}}s</view>
  29 + </block>
25 30 </view>
26 31 </view>
27 32 </view>
... ... @@ -37,16 +42,19 @@
37 42 </view>
38 43 </view>
39 44  
40   - <view class="flex-center go fs32" bindtap="go">
41   - <view class="flex-center lower">
42   - <block wx:if="{{inputxphone==false}}">
43   - <view>下一步</view>
44   - </block>
45   - <block wx:else>
46   - <view>确定更换</view>
47   - </block>
48   - </view>
  45 + <view class="flex-center go fs32">
  46 + <block wx:if="{{inputxphone==0}}">
  47 + <view class="flex-center lower" bindtap="ver_code">
  48 + <view>下一步</view>
  49 + </view>
  50 + </block>
  51 + <block wx:else>
  52 + <navigator url="{{url}}" class="flex-center lower" bindtap="change_phone">
  53 + <view>确定更换</view>
  54 + </navigator>
  55 + </block>
49 56 </view>
50 57  
51 58  
52   -</view>
53 59 \ No newline at end of file
  60 +</view>
  61 +<warn id="warn"></warn>
54 62 \ No newline at end of file
... ...