form-club-register.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="club-register">
  3. <el-form :model="formData" :rules="rules" ref="form" label-width="0">
  4. <el-form-item prop="mobile">
  5. <el-input
  6. v-model="formData.mobile"
  7. placeholder="手机号"
  8. @blur="onMobileBlur"
  9. maxlength="11"
  10. show-word-limit
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item prop="verifyCode">
  14. <div class="verifyCode flex justify-between">
  15. <el-input
  16. v-model="formData.verifyCode"
  17. placeholder="验证码"
  18. maxlength="6"
  19. show-word-limit
  20. ></el-input>
  21. <div class="send ml-8" @click="onSend">{{ sendCodeBtnText }}</div>
  22. </div>
  23. </el-form-item>
  24. <el-form-item prop="password">
  25. <el-input v-model="formData.password" placeholder="密码"></el-input>
  26. </el-form-item>
  27. <el-form-item prop="confirmPwd">
  28. <el-input
  29. v-model="formData.confirmPwd"
  30. placeholder="再次输入密码"
  31. ></el-input>
  32. </el-form-item>
  33. </el-form>
  34. <SimpleDialog
  35. v-model="active"
  36. @confirm="onConfirm"
  37. @cancel="onCancel"
  38. description="抱歉,该手机号已注册,您可以登录后再来进行正品授权申请!"
  39. :center="true"
  40. />
  41. </div>
  42. </template>
  43. <script>
  44. import { mapGetters } from 'vuex'
  45. import { isMobile } from '@/utils/validator'
  46. export default {
  47. data() {
  48. const confirmPwdValide = (rule, value, callback) => {
  49. if (this.formData.password !== value) {
  50. callback(new Error('两次输入的密码不一致'))
  51. } else {
  52. callback()
  53. }
  54. }
  55. return {
  56. formData: {
  57. mobile: '',
  58. verifyCode: '',
  59. password: '',
  60. confirmPwd: '',
  61. },
  62. sendStatus: 0,
  63. active: false,
  64. rules: {
  65. mobile: [
  66. { required: true, message: '手机号不能为空', trigger: ['blur'] },
  67. ],
  68. verifyCode: [
  69. { required: true, message: '验证码不能为空', trigger: ['blur'] },
  70. ],
  71. password: [
  72. { required: true, message: '密码不能为空', trigger: ['blur'] },
  73. ],
  74. confirmPwd: [
  75. { required: true, message: '请再次输入密码', trigger: ['blur'] },
  76. { validator: confirmPwdValide, trigger: ['blur'] },
  77. ],
  78. },
  79. }
  80. },
  81. computed: {
  82. ...mapGetters(['authUserId', 'routePrefix', 'accessToken']),
  83. sendCodeBtnText() {
  84. return this.sendStatus === 0
  85. ? '获取验证码'
  86. : `再次发送${this.sendStatus}s`
  87. },
  88. },
  89. methods: {
  90. async onSend() {
  91. if (this.sendStatus > 0) return
  92. // 验证手机号是否合法
  93. if (!isMobile(this.formData.mobile)) {
  94. this.$toast('请输入正确的手机号')
  95. return
  96. }
  97. try {
  98. // 发送验证码
  99. await this.$http.api.sendVerifyCode({
  100. mobile: this.formData.mobile,
  101. authUserId: this.authUserId,
  102. type: 1,
  103. })
  104. this.$toast('验证码已发送')
  105. // 开启倒计时
  106. this.countdown()
  107. } catch (error) {
  108. console.log(error)
  109. }
  110. },
  111. countdown() {
  112. this.sendStatus = 30
  113. this.timer = setInterval(() => {
  114. if (this.sendStatus === 0) {
  115. clearInterval(this.timer)
  116. return
  117. }
  118. this.sendStatus--
  119. }, 1000)
  120. },
  121. onConfirm() {
  122. this.$router.push(`${this.routePrefix}`)
  123. },
  124. onCancel() {
  125. this.active = false
  126. },
  127. onMobileBlur() {
  128. this.checkouMobileBindClub()
  129. },
  130. // 判断用户手机号是否绑定机构
  131. async checkouMobileBindClub() {
  132. if (!isMobile(this.formData.mobile)) return
  133. try {
  134. const res = await this.$http.api.fetchClubAuthInfo({
  135. authUserId: this.authUserId,
  136. mobile: this.formData.mobile,
  137. })
  138. if (res.data.clubUser) {
  139. this.active = true
  140. }
  141. } catch (error) {
  142. console.log(error)
  143. }
  144. },
  145. genetageFormData() {
  146. return {
  147. mobile: this.formData.mobile,
  148. verifyCode: this.formData.verifyCode,
  149. password: this.formData.password,
  150. }
  151. },
  152. // 表单验证
  153. validate() {
  154. this.$emit('step', this.genetageFormData())
  155. return this.$refs.form.validate()
  156. },
  157. },
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .verifyCode {
  162. .send {
  163. cursor: pointer;
  164. white-space: nowrap;
  165. @include themify($themes) {
  166. color: themed('color');
  167. }
  168. }
  169. }
  170. </style>