index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {
  2. getCenterInfo,
  3. sendPhoneCode,
  4. usePhoneBound
  5. } from '../../services/index.js'
  6. import {
  7. imgServerUrl
  8. } from '../../config/config.js'
  9. import {
  10. showToast
  11. } from '../../utils/tips.js'
  12. import $wuxCountDown from '../../utils/coutdown.js'
  13. import {
  14. updataStorageData
  15. } from '../../utils/storage.js'
  16. const app = getApp();
  17. Page({
  18. data: {
  19. imgServerUrl: imgServerUrl,
  20. bornYear: '',
  21. gender: '',
  22. realName: '',
  23. zym: '',
  24. phone: '',
  25. isShowYzm: false,
  26. isShowCode: false,
  27. },
  28. onLoad: function(options) {
  29. this.setData({
  30. phone: updataStorageData("phone"),
  31. hpUser: wx.getStorageSync("hpuser")
  32. })
  33. console.log("ggg", this.data.hpUser)
  34. },
  35. vcode() {
  36. if (this.djs && this.djs.interval) return !1
  37. this.djs = new $wuxCountDown({
  38. date: +(new Date) + 60000,
  39. onEnd() {
  40. this.setData({
  41. djs: '重新获取验证码',
  42. })
  43. },
  44. render(date) {
  45. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  46. date.sec !== 0 && this.setData({
  47. djs: '重新发送(' + sec + ')',
  48. })
  49. },
  50. })
  51. },
  52. inputPhone(e) {
  53. console.log(e.detail.value)
  54. this.setData({
  55. phone: e.detail.value
  56. })
  57. },
  58. inputYzm(e) {
  59. console.log(e.detail.value)
  60. this.setData({
  61. zym: e.detail.value
  62. })
  63. },
  64. sendCode() {
  65. if (String(this.data.phone).length != 11) {
  66. showToast("请输入11位手机号")
  67. return false
  68. }
  69. if (this.data.djs && this.data.djs !== '重新获取验证码') {
  70. return false
  71. }
  72. this.setData({
  73. isShowYzm: true
  74. })
  75. this.vcode()
  76. sendPhoneCode({
  77. phoneNo: this.data.phone
  78. }).then(data => {
  79. showToast('短信已发送,请填写新手机号和验证码', 'none', 2500)
  80. console.log(data)
  81. })
  82. },
  83. showCode() {
  84. this.setData({
  85. isShowCode: true
  86. })
  87. },
  88. save() {
  89. if (!this.data.isShowCode) {
  90. wx.navigateBack()
  91. return
  92. }
  93. let {
  94. phone,
  95. zym
  96. } = this.data
  97. if (String(phone).length != 11) {
  98. showToast("请输入手机号")
  99. return false
  100. }
  101. if (!this.data.isShowYzm) {
  102. showToast("请先获取验证码")
  103. return false
  104. }
  105. if (String(zym).length != 4) {
  106. showToast("请输入验证码")
  107. return false
  108. }
  109. usePhoneBound({
  110. phoneNo: phone,
  111. msgCode: zym
  112. }).then(data => {
  113. console.log(data)
  114. wx.navigateBack()
  115. })
  116. }
  117. })