index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import {
  2. phoneRegisterReset,
  3. registerVerify,
  4. verifyCode
  5. } from '../../api/api.js';
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. parameter: {
  13. 'navbar': '1',
  14. 'return': '1',
  15. 'title': '登录',
  16. 'color': true,
  17. 'class': '0'
  18. },
  19. disabled: false,
  20. active: false,
  21. timetext: '获取验证码',
  22. userInfo: {},
  23. phone: '',
  24. key: '',
  25. imagesCode: false,
  26. httpUrl: '',
  27. captchaimg: ''
  28. },
  29. inputgetName(e) {
  30. let that = this;
  31. let name = e.currentTarget.dataset.name;
  32. let nameMap = {}
  33. if (name.indexOf('.') != -1) {
  34. let nameList = name.split('.')
  35. if (that.data[nameList[0]]) {
  36. nameMap[nameList[0]] = that.data[nameList[0]]
  37. } else {
  38. nameMap[nameList[0]] = {}
  39. }
  40. nameMap[nameList[0]][nameList[1]] = e.detail.value
  41. } else {
  42. nameMap[name] = e.detail.value
  43. }
  44. that.setData(nameMap);
  45. },
  46. onLoadFun: function (e) {
  47. let userInfo = e.detail;
  48. let tel = userInfo.phone;
  49. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  50. this.setData({
  51. userInfo: e.detail,
  52. phone: phone
  53. });
  54. },
  55. /**
  56. * 发送验证码
  57. */
  58. code: function () {
  59. let that = this;
  60. if (!this.data.userInfo.phone) return app.Tips({
  61. title: '手机号码不存在,无法发送验证码'
  62. });
  63. if (that.data.imagesCode) {
  64. if (!that.data.captchaimg) {
  65. return app.Tips({
  66. title: '请输入图片验证码'
  67. });
  68. }
  69. };
  70. registerVerify(this.data.captchaimg, this.data.key, this.data.userInfo.phone).then(res => {
  71. if (res.status == 402) {
  72. that.data.imagesCode = true;
  73. that.setData({
  74. imagesCode: that.data.imagesCode
  75. });
  76. if (this.data.captchaimg != '') {
  77. that.runNun();
  78. }
  79. } else {
  80. that.runNun();
  81. }
  82. }).catch(function (err) {
  83. return app.Tips({
  84. title: err
  85. });
  86. });
  87. },
  88. runNun: function () {
  89. let that = this;
  90. let n = 60;
  91. let run = setInterval(function () {
  92. n--;
  93. if (n < 0) {
  94. clearInterval(run);
  95. that.setData({
  96. disabled: false,
  97. active: false,
  98. timetext: '重新获取'
  99. })
  100. } else {
  101. that.setData({
  102. timetext: "剩余 " + n + "s",
  103. disabled: true,
  104. active: true
  105. })
  106. }
  107. }, 1000);
  108. },
  109. /**
  110. * H5登录 修改密码
  111. *
  112. */
  113. editPwd: function () {
  114. let that = this;
  115. if (!that.data.password) return app.Tips({
  116. title: '请输入新密码'
  117. });
  118. if (that.data.qr_password != that.data.password) return app.Tips({
  119. title: '两次输入的密码不一致!'
  120. });
  121. if (!that.data.captcha) return app.Tips({
  122. title: '请输入验证码'
  123. });
  124. if (that.data.imagesCode) {
  125. if (!that.data.captchaimg) {
  126. return app.Tips({
  127. title: '请输入图片验证码'
  128. });
  129. }
  130. };
  131. phoneRegisterReset({
  132. account: that.data.userInfo.phone,
  133. captcha: that.data.captcha,
  134. password: that.data.password,
  135. code: that.data.captchaimg
  136. }).then(res => {
  137. return app.Tips({
  138. title: res.msg
  139. }, {
  140. tab: 3,
  141. url: 1
  142. });
  143. }).catch(err => {
  144. return app.Tips({
  145. title: err
  146. });
  147. });
  148. },
  149. // 获取key值;
  150. getVerifyCode: function () {
  151. let that = this;
  152. verifyCode().then(res => {
  153. that.setData({
  154. key: res.data.key,
  155. httpUrl: app.globalData.url + '/api/sms_captcha?key=' + res.data.key
  156. })
  157. }).catch(err => {
  158. return app.Tips({
  159. title: err.msg
  160. });
  161. })
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function (options) {
  167. this.getVerifyCode();
  168. },
  169. imagesCodeTap: function () {
  170. this.setData({
  171. httpUrl: this.data.httpUrl + '&' + Date.parse(new Date())
  172. })
  173. },
  174. /**
  175. * 生命周期函数--监听页面初次渲染完成
  176. */
  177. onReady: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面显示
  181. */
  182. onShow: function () {
  183. },
  184. /**
  185. * 生命周期函数--监听页面隐藏
  186. */
  187. onHide: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面卸载
  191. */
  192. onUnload: function () {
  193. }
  194. })