index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. userInfo: app.globalData.userInfo,
  31. phone: updataStorageData("phone"),
  32. hpUser: wx.getStorageSync("hpuser")
  33. })
  34. console.log("ggg", this.data.hpUser)
  35. },
  36. vcode() {
  37. if (this.djs && this.djs.interval) return !1
  38. this.djs = new $wuxCountDown({
  39. date: +(new Date) + 60000,
  40. onEnd() {
  41. this.setData({
  42. djs: '重新获取验证码',
  43. })
  44. },
  45. render(date) {
  46. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  47. date.sec !== 0 && this.setData({
  48. djs: '重新发送(' + sec + ')',
  49. })
  50. },
  51. })
  52. },
  53. inputPhone(e) {
  54. console.log(e.detail.value)
  55. this.setData({
  56. phone: e.detail.value
  57. })
  58. },
  59. inputYzm(e) {
  60. console.log(e.detail.value)
  61. this.setData({
  62. zym: e.detail.value
  63. })
  64. },
  65. sendCode() {
  66. if (String(this.data.phone).length != 11) {
  67. showToast("请输入11位手机号")
  68. return false
  69. }
  70. if (this.data.djs && this.data.djs !== '重新获取验证码') {
  71. return false
  72. }
  73. this.setData({
  74. isShowYzm: true
  75. })
  76. this.vcode()
  77. sendPhoneCode({
  78. phoneNo: this.data.phone
  79. }).then(data => {
  80. showToast('短信已发送,请填写新手机号和验证码', 'none', 2500)
  81. console.log(data)
  82. })
  83. },
  84. showCode() {
  85. this.setData({
  86. isShowCode: true
  87. })
  88. },
  89. save() {
  90. if (!this.data.isShowCode) {
  91. wx.navigateBack()
  92. return
  93. }
  94. let {
  95. phone,
  96. zym
  97. } = this.data
  98. if (String(phone).length != 11) {
  99. showToast("请输入手机号")
  100. return false
  101. }
  102. if (!this.data.isShowYzm) {
  103. showToast("请先获取验证码")
  104. return false
  105. }
  106. if (String(zym).length != 4) {
  107. showToast("请输入验证码")
  108. return false
  109. }
  110. usePhoneBound({
  111. phoneNo: phone,
  112. msgCode: zym
  113. }).then(data => {
  114. console.log(data)
  115. wx.navigateBack()
  116. })
  117. }
  118. })