index.js 4.3 KB

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