register-for-invite.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <v-container class="register-for-invite" fluid>
  3. <div class="title">注册</div>
  4. <validation-observer ref="observer" v-slot="{ invalid }" slim>
  5. <v-form @submit.prevent="submit()">
  6. <validation-provider
  7. v-slot="{ errors }"
  8. ref="providerPhome"
  9. name="手机号码"
  10. rules="required|min:11|max:11"
  11. slim
  12. >
  13. <v-text-field
  14. v-model="form.phone"
  15. label="手机号码"
  16. name="phone"
  17. required
  18. :error-messages="errors"
  19. maxlength="11"
  20. type="tel"
  21. />
  22. </validation-provider>
  23. <validation-provider
  24. v-slot="{ errors }"
  25. name="验证码"
  26. rules="required|min:6|max:6"
  27. slim
  28. >
  29. <v-text-field
  30. v-model="form.code"
  31. label="验证码"
  32. :error-messages="errors"
  33. name="code"
  34. maxlength="6"
  35. required
  36. >
  37. <template #append-outer>
  38. <v-btn
  39. :loading="codeSending"
  40. :disabled="codeTime > 0"
  41. small
  42. @click="sendSmsCode()"
  43. >
  44. <template v-if="codeTime > 0">{{ codeTime }}s</template>
  45. <template v-else>发送验证码</template>
  46. </v-btn>
  47. </template>
  48. </v-text-field>
  49. </validation-provider>
  50. <div class="">
  51. <v-btn type="submit" :disabled="invalid" :loading="submitting"
  52. >注册并下载app</v-btn
  53. >
  54. </div>
  55. </v-form>
  56. </validation-observer>
  57. </v-container>
  58. </template>
  59. <script>
  60. import { registerForInvite } from '~/api/user/client.js';
  61. import { sendSmsCode } from '~/api/message/phone.js';
  62. export default {
  63. auth: false,
  64. name: 'RegisterForInvite',
  65. data() {
  66. return {
  67. form: {
  68. phone: '17603013019',
  69. code: '',
  70. invitationUserName: null,
  71. activityId: null,
  72. },
  73. codeSending: false,
  74. codeTime: 0,
  75. submitting: false,
  76. };
  77. },
  78. fetch() {
  79. this.form.invitationUserName = this.$route.query.invitationUserName;
  80. this.form.activityId = this.$route.query.activityId;
  81. },
  82. head: {
  83. title: '注册',
  84. },
  85. watch: {},
  86. methods: {
  87. async submit() {
  88. try {
  89. this.submitting = true;
  90. const valid = await this.$refs.observer.validate();
  91. if (valid) {
  92. this.$tongji.trackEvent('活动', '注册', '', 0);
  93. const res = await registerForInvite(this, this.form);
  94. this.$toast.success(res.msg);
  95. }
  96. } finally {
  97. this.submitting = false;
  98. }
  99. },
  100. async sendSmsCode() {
  101. try {
  102. this.codeSending = true;
  103. const validationResult = await this.$refs.providerPhome.validate();
  104. if (validationResult.valid) {
  105. this.$tongji.trackEvent('活动', '发送短信', '', 0);
  106. const res = await sendSmsCode(this, {
  107. type: 'common',
  108. authorizationType: 4,
  109. phone: this.form.phone,
  110. });
  111. this.codeTime = 60;
  112. this.codeInterval = setInterval(() => {
  113. if (--this.codeTime <= 0) {
  114. clearInterval(this.codeInterval);
  115. }
  116. }, 1000);
  117. this.$toast.success(res.msg);
  118. }
  119. } finally {
  120. this.codeSending = false;
  121. }
  122. },
  123. },
  124. };
  125. </script>