register.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="app-content">
  3. <form @submit="formSubmit">
  4. <div class="module-com input-line-wrap">
  5. <tui-list-cell class="line-cell" :hover="false">
  6. <div class="tui-title">手机号</div>
  7. <input v-model="form.mobile" placeholder-class="phcolor" class="tui-input" name="mobile" placeholder="请输入手机号" type="number" />
  8. </tui-list-cell>
  9. <tui-list-cell class="line-cell code-wrap" :hover="false">
  10. <div class="tui-title">验证码</div>
  11. <input v-model="form.code" placeholder-class="phcolor" class="tui-input" name="code" placeholder="请输入验证码" type="number" />
  12. <div class="tui-code" v-if="isSend">{{ countDown + 's' }}</div>
  13. <div class="tui-code" v-else @click="getCode">获取验证码</div>
  14. </tui-list-cell>
  15. <tui-list-cell class="line-cell" :hover="false">
  16. <div class="tui-title">姓名</div>
  17. <input v-model="form.realName" placeholder-class="phcolor" class="tui-input" name="realName" placeholder="选填" type="text" />
  18. </tui-list-cell>
  19. <tui-list-cell class="line-cell" :hover="false">
  20. <div class="tui-title">生日</div>
  21. <picker mode="date" :value="form.birthday" @change="selTimeFn" class="tui-input">
  22. <input v-model="form.birthday" hidden placeholder-class="phcolor" class="tui-input" name="birthday" />
  23. <div v-if="form.birthday">{{ form.birthday }}</div>
  24. <div class="tui-placeholder" v-else>请选择生日</div>
  25. </picker>
  26. <!-- <input placeholder-class="phcolor" class="tui-input" name="phone" placeholder="选填" maxlength="50" type="number" /> -->
  27. </tui-list-cell>
  28. <div class="btn-wrap">
  29. <button class="button-com red big" formType="submit">确认</button>
  30. </div>
  31. </div>
  32. </form>
  33. </div>
  34. </template>
  35. <script>
  36. import TuiListCell from '@/components/plugin/list-cell'
  37. const form = require('@/utils/formValidation.js')
  38. // api
  39. import { register } from '@/api/login'
  40. import { sendSms } from '@/api/common'
  41. export default {
  42. name: 'register',
  43. components: {
  44. TuiListCell
  45. },
  46. data() {
  47. return {
  48. form: {
  49. mobile: '',
  50. code: '',
  51. realName: '',
  52. birthday: 0
  53. },
  54. isSend: 0,
  55. countDown: 119,
  56. timer: null
  57. }
  58. },
  59. onLoad(option) {},
  60. methods: {
  61. getCode() {
  62. if (!this.form.mobile || !this.$util.checkMobile(this.form.mobile)) {
  63. this.$msg('请输入正确的手机号!')
  64. return false
  65. }
  66. this.isSend = 1
  67. sendSms({
  68. type: 1,
  69. mobile: this.form.mobile
  70. })
  71. .then(res => {
  72. this.beginCountDown()
  73. this.$msg('发送成功!')
  74. })
  75. .catch(() => {
  76. this.isSend = 0
  77. this.$msg('发送失败!')
  78. })
  79. },
  80. selTimeFn(e) {
  81. this.form.birthday = e.detail.value
  82. },
  83. confirmFn() {
  84. register(this.form).then(res => {
  85. this.$msg('注册成功!')
  86. setTimeout(() => {
  87. this.$util.pageTo('/pages/home/user')
  88. })
  89. })
  90. },
  91. // 倒计时
  92. beginCountDown() {
  93. this.countDown = 119
  94. this.timer = setInterval(() => {
  95. if (this.countDown === 0) {
  96. clearInterval(this.timer)
  97. this.isSend = 0
  98. return
  99. }
  100. this.countDown -= 1
  101. }, 1000)
  102. },
  103. // 表单验证
  104. formSubmit(e) {
  105. // 表单规则
  106. let rules = [
  107. {
  108. name: 'mobile',
  109. rule: ['required'],
  110. msg: ['请输入手机号']
  111. },
  112. {
  113. name: 'code',
  114. rule: ['required'],
  115. msg: ['请输入验证码']
  116. },
  117. {
  118. name: 'realName',
  119. rule: ['required'],
  120. msg: ['请输入名字']
  121. },
  122. {
  123. name: 'birthday',
  124. rule: ['required'],
  125. msg: ['请选择生日']
  126. }
  127. ]
  128. // 进行表单检查
  129. let formData = e.detail.value
  130. let checkRes = form.validation(formData, rules)
  131. // 验证通过!
  132. if (!checkRes) {
  133. setTimeout(() => {
  134. this.confirmFn()
  135. })
  136. } else {
  137. this.$msg(checkRes)
  138. }
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. // 公共
  145. .line-cell {
  146. .tui-title {
  147. width: 210px;
  148. color: $fontColor2;
  149. }
  150. .tui-input {
  151. width: calc(100% - 210px);
  152. font-size: 28px;
  153. }
  154. .tui-placeholder {
  155. color: #ccc;
  156. }
  157. .phcolor {
  158. color: #ccc;
  159. }
  160. }
  161. .btn-wrap {
  162. width: 90%;
  163. margin: 60px auto;
  164. .button-com {
  165. width: 100%;
  166. margin: 0 auto;
  167. }
  168. }
  169. .code-wrap {
  170. .tui-input {
  171. width: calc(100% - 410px);
  172. font-size: 28px;
  173. }
  174. .tui-code {
  175. width: 200px;
  176. text-align: center;
  177. border-left: 1px solid $borderColor;
  178. color: $mainColor;
  179. }
  180. }
  181. </style>