form-club-register.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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">获取验证码</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. active: false,
  63. rules: {
  64. mobile: [
  65. { required: true, message: '手机号不能为空', trigger: ['blur'] },
  66. ],
  67. verifyCode: [
  68. { required: true, message: '验证码不能为空', trigger: ['blur'] },
  69. ],
  70. password: [
  71. { required: true, message: '密码不能为空', trigger: ['blur'] },
  72. ],
  73. confirmPwd: [
  74. { required: true, message: '请再次输入密码', trigger: ['blur'] },
  75. { validator: confirmPwdValide, trigger: ['blur'] },
  76. ],
  77. },
  78. }
  79. },
  80. computed: {
  81. ...mapGetters(['authUserId', 'routePrefix', 'accessToken']),
  82. },
  83. methods: {
  84. onConfirm() {
  85. this.$router.push(`${this.routePrefix}`)
  86. },
  87. onCancel() {
  88. this.active = false
  89. },
  90. onMobileBlur() {
  91. this.checkouMobileBindClub()
  92. },
  93. // 判断用户手机号是否绑定机构
  94. async checkouMobileBindClub() {
  95. if (!isMobile(this.formData.mobile)) return
  96. try {
  97. const res = await this.$http.api.checkouMobileBindClub({
  98. authUserId: this.authUserId,
  99. mobile: this.formData.mobile,
  100. })
  101. if (res.data.clubUser) {
  102. this.active = true
  103. }
  104. } catch (error) {
  105. console.log(error)
  106. }
  107. },
  108. // 表单验证
  109. validate() {
  110. this.$emit('step', this.formData)
  111. return this.$refs.form.validate()
  112. },
  113. },
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .verifyCode {
  118. .send {
  119. cursor: pointer;
  120. white-space: nowrap;
  121. @include themify($themes) {
  122. color: themed('color');
  123. }
  124. }
  125. }
  126. </style>