reset.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. data: {
  5. },
  6. onLoad: function (options) {
  7. },
  8. onShow: function () {
  9. AUTH.wxaCode().then(code => {
  10. this.data.code = code
  11. })
  12. this.getUserApiInfo()
  13. },
  14. async getUserApiInfo() {
  15. const res = await WXAPI.userDetail(wx.getStorageSync('token'))
  16. if (res.code == 2000) {
  17. AUTH.openLoginDialog()
  18. return
  19. }
  20. if (res.code == 0) {
  21. this.setData({
  22. mobile: res.data.base.mobile
  23. })
  24. }
  25. },
  26. async sendSms() {
  27. const res = await WXAPI.smsValidateCodeByToken(wx.getStorageSync('token'))
  28. if (res.code == 2000) {
  29. AUTH.openLoginDialog()
  30. return
  31. }
  32. if (res.code == 0) {
  33. this.setData({
  34. smsloading: true,
  35. smsloadingSecond: 60
  36. })
  37. wx.showToast({
  38. title: '短信已发送',
  39. })
  40. this.countDown()
  41. } else {
  42. wx.showToast({
  43. title: res.msg,
  44. icon: 'none'
  45. })
  46. }
  47. },
  48. countDown() {
  49. const smsloadingSecond = this.data.smsloadingSecond
  50. if (smsloadingSecond) {
  51. this.setData({
  52. smsloadingSecond: smsloadingSecond-1
  53. })
  54. setTimeout(() => {
  55. this.countDown()
  56. }, 1000);
  57. } else {
  58. this.setData({
  59. smsloading: false
  60. })
  61. }
  62. },
  63. async submit() {
  64. if (!this.data.mobile) {
  65. wx.showToast({
  66. title: '请先绑定手机号码',
  67. icon: 'none'
  68. })
  69. return
  70. }
  71. if (!this.data.code) {
  72. wx.showToast({
  73. title: '请输入短信验证码',
  74. icon: 'none'
  75. })
  76. return
  77. }
  78. if (!this.data.pwd) {
  79. wx.showToast({
  80. title: '请输入交易密码',
  81. icon: 'none'
  82. })
  83. return
  84. }
  85. if (!this.data.pwd2) {
  86. wx.showToast({
  87. title: '请再次输入交易密码',
  88. icon: 'none'
  89. })
  90. return
  91. }
  92. if (this.data.pwd != this.data.pwd2) {
  93. wx.showToast({
  94. title: '两次输入不一致',
  95. icon: 'none'
  96. })
  97. return
  98. }
  99. const res = await WXAPI.resetPayPassword(this.data.mobile, this.data.code, this.data.pwd)
  100. if (res.code == 2000) {
  101. AUTH.openLoginDialog()
  102. return
  103. }
  104. if (res.code != 0) {
  105. wx.showToast({
  106. title: res.msg,
  107. icon: 'none'
  108. })
  109. return
  110. }
  111. wx.showToast({
  112. title: '设置成功'
  113. })
  114. setTimeout(() => {
  115. wx.navigateBack({
  116. delta: 0,
  117. })
  118. }, 1000);
  119. },
  120. processLogin(e) {
  121. if (!e.detail.userInfo) {
  122. wx.showToast({
  123. title: '已取消',
  124. icon: 'none',
  125. })
  126. return;
  127. }
  128. AUTH.register(this);
  129. },
  130. getPhoneNumber: function(e) {
  131. if (!e.detail.errMsg || e.detail.errMsg != "getPhoneNumber:ok") {
  132. wx.showModal({
  133. title: '提示',
  134. content: e.detail.errMsg,
  135. showCancel: false
  136. })
  137. return;
  138. }
  139. WXAPI.bindMobileWxapp(wx.getStorageSync('token'), this.data.code, e.detail.encryptedData, e.detail.iv).then(res => {
  140. AUTH.wxaCode().then(code => {
  141. this.data.code = code
  142. })
  143. if (res.code === 10002) {
  144. AUTH.openLoginDialog()
  145. return
  146. }
  147. if (res.code == 0) {
  148. wx.showToast({
  149. title: '绑定成功',
  150. icon: 'success',
  151. duration: 2000
  152. })
  153. this.getUserApiInfo();
  154. } else {
  155. wx.showModal({
  156. title: '提示',
  157. content: res.msg,
  158. showCancel: false
  159. })
  160. }
  161. })
  162. },
  163. })