123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <template>
- <div class="club-register">
- <el-form :model="formData" :rules="rules" ref="form" label-width="0">
- <el-form-item prop="mobile">
- <el-input
- type="text"
- v-model="formData.mobile"
- placeholder="手机号"
- @blur="onMobileBlur"
- maxlength="11"
- @input="handleMobileInput"
- ></el-input>
- </el-form-item>
- <el-form-item prop="verifyCode">
- <div class="verifyCode flex justify-between">
- <el-input
- v-model="formData.verifyCode"
- placeholder="验证码"
- maxlength="6"
- @input="handleVerifyCodeInput"
- ></el-input>
- <div class="send ml-8" @click="onSend">{{ sendCodeBtnText }}</div>
- </div>
- </el-form-item>
- <el-form-item prop="password">
- <el-input
- type="password"
- v-model="formData.password"
- placeholder="密码"
- maxlength="12"
- show-word-limit
- show-password
- ></el-input>
- </el-form-item>
- <el-form-item prop="confirmPwd">
- <el-input
- type="password"
- v-model="formData.confirmPwd"
- placeholder="再次输入密码"
- maxlength="12"
- show-word-limit
- show-password
- ></el-input>
- </el-form-item>
- </el-form>
- <SimpleDialog
- v-model="active"
- @confirm="onConfirm"
- @cancel="onCancel"
- confirmText="去登录"
- description="抱歉,该手机号已注册,您可以登录后再来进行正品授权申请!"
- :center="true"
- />
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- import { isMobile } from '@/utils/validator'
- export default {
- data() {
- const confirmPwdValide = (rule, value, callback) => {
- if (this.formData.password !== value) {
- callback(new Error('两次输入的密码不一致'))
- } else {
- callback()
- }
- }
- const mobileValidate = (rule, value, callback) => {
- if (!isMobile(value)) {
- callback(new Error('手机号格式不正确'))
- } else {
- callback()
- }
- }
- return {
- formData: {
- mobile: '',
- verifyCode: '',
- password: '',
- confirmPwd: '',
- },
- registerStatus: true, // 能否注册
- sendStatus: 0,
- active: false,
- rules: {
- mobile: [
- { required: true, message: '手机号不能为空', trigger: ['blur'] },
- { validator: mobileValidate, trigger: ['blur'] },
- ],
- verifyCode: [
- { required: true, message: '验证码不能为空', trigger: ['blur'] },
- ],
- password: [
- { required: true, message: '密码不能为空', trigger: ['blur'] },
- { min: 8, max: 12, message: '请输入8-12位密码', trigger: ['blur'] },
- ],
- confirmPwd: [
- { required: true, message: '请再次输入密码', trigger: ['blur'] },
- { validator: confirmPwdValide, trigger: ['blur'] },
- ],
- },
- }
- },
- computed: {
- ...mapGetters(['authUserId', 'routePrefix', 'accessToken']),
- sendCodeBtnText() {
- return this.sendStatus === 0
- ? '获取验证码'
- : `再次发送${this.sendStatus}s`
- },
- },
- methods: {
- async onSend() {
- if (!this.registerStatus) return (this.active = true)
- if (this.sendStatus > 0) return
- // 验证手机号是否合法
- if (!isMobile(this.formData.mobile)) {
- this.$toast('请输入正确的手机号')
- return
- }
- try {
- // 发送验证码
- await this.$http.api.sendVerifyCode({
- mobile: this.formData.mobile,
- authUserId: this.authUserId,
- type: 1,
- })
- this.$toast('验证码已发送')
- // 开启倒计时
- this.countdown()
- } catch (error) {
- console.log(error)
- }
- },
- // 输入框输入时
- handleMobileInput() {
- this.formData.mobile = this.formData.mobile.replace(/\D/gi, '')
- },
- // 输入框输入时
- handleVerifyCodeInput() {
- this.formData.verifyCode = this.formData.verifyCode.replace(/\D/gi, '')
- },
- countdown() {
- this.sendStatus = 30
- this.timer = setInterval(() => {
- if (this.sendStatus === 0) {
- clearInterval(this.timer)
- return
- }
- this.sendStatus--
- }, 1000)
- },
- onConfirm() {
- this.$router.push(`${this.routePrefix}`)
- },
- onCancel() {
- this.active = false
- },
- onMobileBlur() {
- if (isMobile(this.formData.mobile)) {
- this.checkouMobileBindClub()
- }
- },
- // 判断用户手机号是否绑定机构
- async checkouMobileBindClub() {
- try {
- const res = await this.$http.api.fetchClubAuthInfo({
- authUserId: this.authUserId,
- mobile: this.formData.mobile,
- })
- if (res.data.clubUser) {
- this.active = true
- this.registerStatus = false
- } else {
- this.registerStatus = true
- }
- } catch (error) {
- console.log(error)
- }
- },
- genetageFormData() {
- return {
- mobile: this.formData.mobile,
- verifyCode: this.formData.verifyCode,
- password: this.formData.password,
- }
- },
- // 表单验证
- validate() {
- this.$emit('step', this.genetageFormData())
- return this.$refs.form.validate()
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- .club-register {
- ::v-deep {
- .el-input.is-active .el-input__inner,
- .el-input__inner:focus {
- @include themify($themes) {
- border-color: themed('color');
- }
- }
- }
- }
- .verifyCode {
- .send {
- cursor: pointer;
- white-space: nowrap;
- @include themify($themes) {
- color: themed('color');
- }
- }
- }
- </style>
|