checkphonesecruity.js 5.7 KB

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