checkphonesecruity.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // pages/ucenter/accountsecurity/checkphonesecuirty/checkphonesecruity.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. vcode: '',
  8. scene: '',
  9. userInfo: {},
  10. hidePhone: null,
  11. errorMsg: '',
  12. vcodeFlag: true,
  13. vcodeTimeOut: 0,
  14. vcodeTimeOutDefault: 0,
  15. vcodeLen:6,
  16. vcodeInterval:null,
  17. vcode_button_text:'获取验证码',
  18. reviserPasswordScene: 'MDF_PWD',
  19. unbindPhoneScene: 'UN_PHONE',
  20. showMsg: false,
  21. timeing: true
  22. },
  23. onError(e) {
  24. wx.showModal({
  25. title: '温馨提示',
  26. content: '当前网络环境较差,无法连接服务器,请稍后重试。有问题请联系客服电话4009608068,接听时段08:30-17:00。',
  27. showCancel: false,
  28. confirmColor:'#00AADD',
  29. });
  30. },
  31. inputVerificatrCode(e) {
  32. this.setData({
  33. vcode: e.detail.value,
  34. showMsg: false,
  35. });
  36. if(!this.msgVcode()){
  37. return;
  38. }
  39. this.checkAll();
  40. },
  41. msgVcode(){
  42. if (!this.checkVcode()) {
  43. this.setData({
  44. // errorMsg: '验证码格式不正确'
  45. errorMsg: '验证码格式不正确'
  46. });
  47. this.setData({
  48. checkCode: false
  49. });
  50. return false;
  51. } else {
  52. this.setData({
  53. errorMsg: ''
  54. });
  55. }
  56. return true;
  57. },
  58. checkAll() {
  59. if(!this.msgVcode()){
  60. return;
  61. }
  62. if (this.data.vcode) {
  63. this.setData({
  64. checkCode: true,
  65. // vcodeFlag: false
  66. });
  67. } else {
  68. this.setData({
  69. checkCode: false,
  70. // vcodeFlag: true
  71. });
  72. }
  73. },
  74. checkVcode() {
  75. if (this.data.vcode==undefined || this.data.vcode=="" || this.data.vcode==null) {
  76. return false;
  77. }
  78. if(this.data.vcode.length==this.data.vcodeLen){
  79. return true;
  80. }
  81. return false;
  82. },
  83. getVerificateCode(){
  84. let vcodeFlag = this.data.vcodeFlag;
  85. let phone = this.data.userInfo.phonenumber;
  86. let that = this;
  87. if (!vcodeFlag) {
  88. return;
  89. }
  90. this.setData({
  91. vcodeTimeOut:this.data.vcodeTimeOutDefault
  92. })
  93. wx.request({
  94. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/sendPhoneVcodeNoUnique',
  95. data: {
  96. scene: that.data.scene,
  97. terminal: phone,
  98. },
  99. method: 'POST',
  100. success(res) {
  101. if (res.data.code == 200) {
  102. wx.showToast({
  103. title: '验证码已发送',
  104. icon: 'success',
  105. duration: 1000 //持续的时间
  106. })
  107. let vcodeInterval = setInterval(function () {
  108. if (that.data.vcodeTimeOut <= 0) {
  109. that.setData({
  110. vcodeFlag: true,
  111. vcode_button_text: '获取验证码',
  112. timeing:true
  113. })
  114. clearInterval(vcodeInterval);
  115. }else{
  116. let str = '获取验证码'+'(' + that.data.vcodeTimeOut + 's)'
  117. that.setData({
  118. vcodeTimeOut:that.data.vcodeTimeOut-1,
  119. vcodeFlag: false,
  120. vcode_button_text: str,
  121. timeing:false
  122. })
  123. }
  124. }, 1000);
  125. }else{
  126. if (res.data.code == 1) {
  127. if(res.data.msg!=null && res.data.msg.startsWith("503")){
  128. getApp().showNetworkError();
  129. return;
  130. }
  131. wx.showModal({
  132. title: '提示',
  133. content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
  134. showCancel:false,
  135. confirmText: '去登录',
  136. confirmColor:'#00AADD',
  137. success: function (res1) {
  138. if (res1.confirm) {
  139. let url = '/pages/login/phone_login/phone_login';
  140. wx.redirectTo({
  141. url
  142. })
  143. }
  144. }
  145. });
  146. }else{
  147. wx.showModal({
  148. title: '提示',
  149. content:res.data.msg,
  150. showCancel:false,
  151. confirmColor:'#00AADD',
  152. });
  153. }
  154. }
  155. }
  156. });
  157. },
  158. nextConfirm(e){
  159. let that = this;
  160. this.checkAll();
  161. this.setData({
  162. showMsg:true
  163. })
  164. if(!this.data.checkCode){
  165. return;
  166. }
  167. wx.request({
  168. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/checkPhoneSecruity',
  169. data: {
  170. phonenumber: that.data.userInfo.phonenumber,
  171. scene: that.data.scene,
  172. vcode: that.data.vcode
  173. },
  174. method: 'POST',
  175. success(res) {
  176. if (res.data.code == 1) {
  177. if(res.data.msg!=null && res.data.msg.startsWith("503")){
  178. getApp().showNetworkError();
  179. return;
  180. }
  181. // that.setData({
  182. // vcode: null,
  183. // });
  184. // that.checkAll();
  185. wx.showModal({
  186. title: '提示',
  187. content:res.data.msg,
  188. showCancel:false,
  189. confirmColor:'#00AADD',
  190. });
  191. } else {
  192. if(that.data.scene==that.data.reviserPasswordScene){
  193. let url = `/pages/ucenter/accountsecurity/mdfpassword/mdfpassword`;
  194. wx.redirectTo({
  195. url
  196. });
  197. }else if(that.data.scene==that.data.unbindPhoneScene){
  198. let url = `/pages/ucenter/accountsecurity/unbindphone/unbindphone`;
  199. wx.redirectTo({
  200. url
  201. });
  202. }
  203. }
  204. },
  205. fail(e){
  206. getApp().showNetworkError();
  207. }
  208. });
  209. },
  210. /**
  211. * 生命周期函数--监听页面加载
  212. */
  213. onLoad(options) {
  214. let {
  215. scene
  216. } = options;
  217. this.setData({
  218. scene
  219. });
  220. let userInfo = wx.getStorageSync('userInfo');
  221. let isLogin = wx.getStorageSync('isLogin');
  222. // 页面显示
  223. if (userInfo && isLogin) {
  224. let phonenumber = userInfo.phonenumber;
  225. let hidePhone = phonenumber.substring(0,3)+'****'+phonenumber.substring(7);
  226. this.setData({
  227. userInfo: userInfo,
  228. hidePhone
  229. });
  230. } else {
  231. //未登录信息
  232. this.setData({
  233. userInfo: {}
  234. });
  235. let url = `/pages/login/phone_login/phone_login`;
  236. wx.navigateTo({
  237. url
  238. });
  239. return;
  240. }
  241. let that = this
  242. wx.request({
  243. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/vcodeInfo',
  244. data: {
  245. scene:this.data.scene,
  246. },
  247. method: 'POST',
  248. success(res) {
  249. that.setData({
  250. vcodeInfo:false,
  251. vcodeTimeOut:res.data.result.expire,
  252. vcodeTimeOutDefault:res.data.result.expire,
  253. vcodeLen:res.data.result.len
  254. })
  255. }
  256. });
  257. },
  258. /**
  259. * 生命周期函数--监听页面初次渲染完成
  260. */
  261. onReady() {
  262. },
  263. /**
  264. * 生命周期函数--监听页面显示
  265. */
  266. onShow() {
  267. this.setData({
  268. vcode: null
  269. });
  270. },
  271. /**
  272. * 生命周期函数--监听页面隐藏
  273. */
  274. onHide() {
  275. },
  276. /**
  277. * 生命周期函数--监听页面卸载
  278. */
  279. onUnload() {
  280. },
  281. /**
  282. * 页面相关事件处理函数--监听用户下拉动作
  283. */
  284. onPullDownRefresh() {
  285. },
  286. /**
  287. * 页面上拉触底事件的处理函数
  288. */
  289. onReachBottom() {
  290. },
  291. /**
  292. * 用户点击右上角分享
  293. */
  294. onShareAppMessage() {
  295. }
  296. })