register-for-invite.vue 3.2 KB

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