index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { phoneRegisterReset, registerVerify, 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(e){
  43. let userInfo = e.detail;
  44. let tel = userInfo.phone;
  45. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  46. this.setData({ userInfo: e.detail, phone: phone});
  47. },
  48. /**
  49. * 发送验证码
  50. *
  51. */
  52. code: function () {
  53. let that = this;
  54. if (!this.data.userInfo.phone) return app.Tips({title:'手机号码不存在,无法发送验证码'});
  55. if (that.data.imagesCode){
  56. if (!that.data.captchaimg) {
  57. return app.Tips({ title: '请输入图片验证码' });
  58. }
  59. };
  60. registerVerify(this.data.captchaimg,this.data.key,this.data.userInfo.phone).then(res=>{
  61. if (res.status == 402) {
  62. that.data.imagesCode = true;
  63. that.setData({
  64. imagesCode: that.data.imagesCode
  65. });
  66. if (this.data.captchaimg != '') {
  67. that.runNun();
  68. }
  69. }else{
  70. that.runNun();
  71. }
  72. }).catch(function(err){
  73. return app.Tips({ title: err });
  74. });
  75. },
  76. runNun:function(){
  77. let that = this;
  78. let n = 60;
  79. let run = setInterval(function () {
  80. n--;
  81. if (n < 0) {
  82. clearInterval(run);
  83. that.setData({ disabled: false, active: false, timetext: '重新获取' })
  84. } else {
  85. that.setData({ timetext: "剩余 " + n + "s", disabled: true, active: true })
  86. }
  87. }, 1000);
  88. },
  89. /**
  90. * H5登录 修改密码
  91. *
  92. */
  93. editPwd:function(){
  94. let that = this;
  95. if (!that.data.password) return app.Tips({title:'请输入新密码'});
  96. if (that.data.qr_password != that.data.password) return app.Tips({title:'两次输入的密码不一致!'});
  97. if (!that.data.captcha) return app.Tips({title:'请输入验证码'});
  98. if (that.data.imagesCode){
  99. if (!that.data.captchaimg){
  100. return app.Tips({ title: '请输入图片验证码' });
  101. }
  102. };
  103. phoneRegisterReset({
  104. account:that.data.userInfo.phone,
  105. captcha:that.data.captcha,
  106. password: that.data.password,
  107. code: that.data.captchaimg
  108. }).then(res=>{
  109. return app.Tips({title:res.msg},{tab:3,url:1});
  110. }).catch(err=>{
  111. return app.Tips({title:err});
  112. });
  113. },
  114. // 获取key值;
  115. getVerifyCode:function(){
  116. let that = this;
  117. verifyCode().then(res=>{
  118. that.setData({
  119. key: res.data.key,
  120. httpUrl: app.globalData.url + '/api/sms_captcha?key=' + res.data.key
  121. })
  122. }).catch(err=>{
  123. return app.Tips({ title: err.msg });
  124. })
  125. },
  126. /**
  127. * 生命周期函数--监听页面加载
  128. */
  129. onLoad: function (options) {
  130. this.getVerifyCode();
  131. },
  132. imagesCodeTap:function(){
  133. this.setData({
  134. httpUrl: this.data.httpUrl + '&' + Date.parse(new Date())
  135. })
  136. },
  137. /**
  138. * 生命周期函数--监听页面初次渲染完成
  139. */
  140. onReady: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function () {
  156. }
  157. })