index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { registerVerify, bindingPhone, verifyCode} from '../../api/api.js';
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '绑定手机号',
  12. 'color': true,
  13. 'class': '0'
  14. },
  15. disabled: false,
  16. active: false,
  17. timetext: '获取验证码',
  18. userInfo: {},
  19. phone: '',
  20. key: '',
  21. imagesCode: false,
  22. httpUrl: '',
  23. captchaimg: ''
  24. },
  25. inputgetName(e) {
  26. let that = this;
  27. let name = e.currentTarget.dataset.name;
  28. let nameMap = {}
  29. if (name.indexOf('.') != -1) {
  30. let nameList = name.split('.')
  31. if (that.data[nameList[0]]) {
  32. nameMap[nameList[0]] = that.data[nameList[0]]
  33. } else {
  34. nameMap[nameList[0]] = {}
  35. }
  36. nameMap[nameList[0]][nameList[1]] = e.detail.value
  37. } else {
  38. nameMap[name] = e.detail.value
  39. }
  40. that.setData(nameMap);
  41. },
  42. onLoadFun:function(){
  43. },
  44. editPwd:function(){
  45. let that = this;
  46. if (!this.data.phone) return app.Tips({ title: '请填写手机号码!' });
  47. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) return app.Tips({ title: '请输入正确的手机号码!' });
  48. if (!this.data.captcha) return app.Tips({title:'请填写验证码'});
  49. bindingPhone({
  50. phone:this.data.phone,
  51. captcha: this.data.captcha
  52. }).then(res=>{
  53. if (res.data !== undefined && res.data.is_bind){
  54. wx.showModal({
  55. title:'是否绑定账号',
  56. content:res.msg,
  57. confirmText:'绑定',
  58. success(res){
  59. if (res.confirm){
  60. bindingPhone({
  61. phone: that.data.phone,
  62. captcha: that.data.captcha,
  63. step:1
  64. }).then(res=>{
  65. return app.Tips({ title: res.msg, icon: 'success' }, { tab: 5, url: '/pages/user_info/index' });
  66. }).catch(err => { return app.Tips({ title: err }); })
  67. } else if (res.cancel){
  68. return app.Tips({ title: '您已取消绑定!'}, { tab: 5, url: '/pages/user_info/index' });
  69. }
  70. }
  71. });
  72. }else
  73. return app.Tips({title:'绑定成功!',icon:'success'},{tab:5,url:'/pages/user_info/index'});
  74. }).catch(err=>{
  75. return app.Tips({title:err});
  76. })
  77. },
  78. /**
  79. * 发送验证码
  80. *
  81. */
  82. code: function () {
  83. let that = this;
  84. if (!this.data.phone) return app.Tips({ title: '请填写手机号码!' });
  85. if (!(/^1[3456789]\d{9}$/.test(that.data.phone))) return app.Tips({ title: '请输入正确的手机号码!' });
  86. if (that.data.imagesCode) {
  87. if (!that.data.captchaimg) {
  88. return app.Tips({ title: '请输入图片验证码' });
  89. }
  90. };
  91. registerVerify(this.data.captchaimg, this.data.key,this.data.phone).then(res => {
  92. if (res.status == 402) {
  93. that.data.imagesCode = true;
  94. that.setData({
  95. imagesCode: that.data.imagesCode
  96. });
  97. if (this.data.captchaimg != '') {
  98. that.runNun();
  99. }
  100. } else {
  101. that.runNun();
  102. }
  103. return app.Tips({title:'发送成功',icon:'success'});
  104. }).catch(err => {
  105. return app.Tips({ title: err });
  106. });
  107. },
  108. runNun: function () {
  109. let that = this;
  110. let n = 60;
  111. let run = setInterval(function () {
  112. n--;
  113. if (n < 0) {
  114. clearInterval(run);
  115. that.setData({ disabled: false, active: false, timetext: '重新获取' })
  116. } else {
  117. that.setData({ timetext: "剩余 " + n + "s", disabled: true, active: true })
  118. }
  119. }, 1000);
  120. },
  121. // 获取key值;
  122. getVerifyCode: function () {
  123. let that = this;
  124. verifyCode().then(res => {
  125. that.setData({
  126. key: res.data.key,
  127. httpUrl: app.globalData.url + '/api/sms_captcha?key=' + res.data.key
  128. })
  129. }).catch(err => {
  130. return app.Tips({ title: err.msg });
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面加载
  135. */
  136. onLoad: function (options) {
  137. this.getVerifyCode();
  138. },
  139. imagesCodeTap: function () {
  140. this.setData({
  141. httpUrl: this.data.httpUrl + '&' + Date.parse(new Date())
  142. })
  143. },
  144. /**
  145. * 生命周期函数--监听页面初次渲染完成
  146. */
  147. onReady: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. }
  174. })