抖音b端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 line
3.8 KiB

  1. const config = require('../../config/config.js')
  2. const Common = require('../../common/common.js')
  3. const app = getApp()
  4. var interval = null //倒计时函数
  5. Page({
  6. data: {
  7. phone: '',
  8. yzm: '',
  9. flag: true,
  10. retry: false,
  11. time: 60,
  12. phones: "",
  13. date: '请选择日期',
  14. fun_id: 2,
  15. time: '获取验证码', //倒计时
  16. currentTime: 61,
  17. disabled:false,
  18. setInter:''
  19. },
  20. getCode: function (options) {
  21. var that = this;
  22. var currentTime = that.data.currentTime
  23. that.data.setInter = setInterval(function () {
  24. currentTime--;
  25. that.setData({
  26. time: currentTime + '秒'
  27. })
  28. if (currentTime <= 0) {
  29. clearInterval(that.data.setInter)
  30. that.setData({
  31. time: '获取验证码',
  32. currentTime: 61,
  33. disabled: false
  34. })
  35. }
  36. console.log(that.data.time)
  37. }, 1000)
  38. },
  39. onHide:function(){
  40. let that = this;
  41. clearInterval(that.data.setInter);
  42. that.setData({
  43. time: '获取验证码',
  44. currentTime: 61,
  45. disabled: false
  46. })
  47. },
  48. onUnload:function(){
  49. let that = this;
  50. clearInterval(that.data.setInter)
  51. that.setData({
  52. time: '获取验证码',
  53. currentTime: 61,
  54. disabled: false
  55. })
  56. },
  57. onLoad:function(options){
  58. console.log(options);
  59. if(tt.getStorageSync("phone")){
  60. this.setData({
  61. phone: tt.getStorageSync("phone"),
  62. })
  63. }
  64. if(options.flags=='reset'){
  65. tt.setNavigationBarTitle({
  66. title: '修改密码'
  67. })
  68. this.setData({
  69. flags: options.flags
  70. })
  71. }else{
  72. tt.setNavigationBarTitle({
  73. title: '忘记密码'
  74. })
  75. }
  76. },
  77. onShow: function () {
  78. let that = this;
  79. that.setData({
  80. phones: tt.getStorageSync("phone"),
  81. disabled:false
  82. });
  83. console.log(that.data.phones)
  84. },
  85. getYZM(e) {
  86. console.log(e);
  87. if (e.detail.value.phone) {
  88. this.setData({
  89. phone: e.detail.value.phone,
  90. yzm: e.detail.value.yzm
  91. })
  92. }else{
  93. this.setData({
  94. phone: tt.getStorageSync("phone"),
  95. yzm: e.detail.value.yzm
  96. })
  97. }
  98. },
  99. next() {
  100. setTimeout(() => {
  101. console.log(this.data)
  102. Common.hasValidationCode(this.data.phone, this.data.yzm)
  103. .then(res => {
  104. console.log(res)
  105. setTimeout(() => {
  106. console.log(res)
  107. if (res.code == 200) {
  108. tt.navigateTo({
  109. url: `/pages/setpwd/setpwd?phone=${this.data.phone}&code=${this.data.yzm}`
  110. })
  111. } else {
  112. tt.showToast({
  113. title: "验证码错误",
  114. icon: "none",
  115. duration: 2000
  116. })
  117. }
  118. }, 500)
  119. })
  120. }, 1000)
  121. },
  122. send(e) {
  123. console.log(this.data.phone);
  124. var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
  125. let that = this;
  126. // setTimeout(() => {
  127. let tel = that.data.phone;
  128. console.log(tel)
  129. if (phoneReg.test(tel)) {
  130. Common.sendValidationCode(tel)
  131. .then(res => {
  132. console.log(res);
  133. if (res.code == 200) {
  134. that.getCode();
  135. that.setData({
  136. disabled: true
  137. })
  138. tt.showToast({
  139. title: res.message,
  140. image: '../../static/images/success.png'
  141. })
  142. } else if (res.code == 12061){
  143. tt.showToast({
  144. title: "短息已发送,稍后重试",
  145. icon: "none",
  146. })
  147. } else {
  148. tt.showToast({
  149. title: res.message,
  150. icon: "none",
  151. })
  152. }
  153. })
  154. } else {
  155. tt.showToast({
  156. title: '手机号有误',
  157. icon: "none",
  158. })
  159. }
  160. // }, 500)
  161. }
  162. })