checkphonesecruity.js 5.7 KB

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