register.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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({
  88. url: '/pages/callback/index',
  89. query: {
  90. pagestatus: 6
  91. }
  92. })
  93. })
  94. })
  95. },
  96. // 倒计时
  97. beginCountDown() {
  98. this.countDown = 119
  99. this.timer = setInterval(() => {
  100. if (this.countDown === 0) {
  101. clearInterval(this.timer)
  102. this.isSend = 0
  103. return
  104. }
  105. this.countDown -= 1
  106. }, 1000)
  107. },
  108. // 表单验证
  109. formSubmit(e) {
  110. // 表单规则
  111. let rules = [
  112. {
  113. name: 'mobile',
  114. rule: ['required'],
  115. msg: ['请输入手机号']
  116. },
  117. {
  118. name: 'code',
  119. rule: ['required'],
  120. msg: ['请输入验证码']
  121. },
  122. {
  123. name: 'realName',
  124. rule: ['required'],
  125. msg: ['请输入名字']
  126. },
  127. {
  128. name: 'birthday',
  129. rule: ['required'],
  130. msg: ['请选择生日']
  131. }
  132. ]
  133. // 进行表单检查
  134. let formData = e.detail.value
  135. let checkRes = form.validation(formData, rules)
  136. // 验证通过!
  137. if (!checkRes) {
  138. setTimeout(() => {
  139. this.confirmFn()
  140. })
  141. } else {
  142. this.$msg(checkRes)
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. // 公共
  150. .line-cell {
  151. .tui-title {
  152. width: 210px;
  153. color: $fontColor2;
  154. }
  155. .tui-input {
  156. width: calc(100% - 210px);
  157. font-size: 28px;
  158. }
  159. .tui-placeholder {
  160. color: #ccc;
  161. }
  162. .phcolor {
  163. color: #ccc;
  164. }
  165. }
  166. .btn-wrap {
  167. width: 90%;
  168. margin: 60px auto;
  169. .button-com {
  170. width: 100%;
  171. margin: 0 auto;
  172. }
  173. }
  174. .code-wrap {
  175. .tui-input {
  176. width: calc(100% - 410px);
  177. font-size: 28px;
  178. }
  179. .tui-code {
  180. width: 200px;
  181. text-align: center;
  182. border-left: 1px solid $borderColor;
  183. color: $mainColor;
  184. }
  185. }
  186. </style>