form-club-register.vue 4.7 KB

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