index.js 2.3 KB

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