SignUpAccount.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="signUpAccount">
  3. <!-- <m-header /> -->
  4. <m-step />
  5. <div class="title">基本信息</div>
  6. <!-- <van-form ref="form" :show-error="false" validate-first @submit="onSubmit" @failed="onFailed"> -->
  7. <van-field v-model="form.phone" type="tel" :maxlength="11" required name="phone" label="手机号" placeholder="请输入手机号" />
  8. <van-field type="number" v-model="form.code" :maxlength="6" required clearable name="code" label="验证码" placeholder="请输入验证码">
  9. <template #button>
  10. <span class="codeText" v-show="countDownStatus" @click="onGetCode">获取验证码</span>
  11. <span class="code-text" v-show="!countDownStatus">
  12. <van-count-down ref="countdown" style="color: #c4c4c4" :auto-start="false" :time="countDownTime" @finish="onCountDownFinished" format="ss秒" />
  13. </span>
  14. </template>
  15. </van-field>
  16. <div class="agreeProtocol">
  17. <van-checkbox v-model="agreeStatus"></van-checkbox>
  18. <i style="font-style: normal; color: #999" @click="agreeStatus = !agreeStatus">已阅读并同意</i> <span @click="onToProtocol">《酷乐秀用户注册服务协议》</span>
  19. </div>
  20. <van-button type="primary" :disabled="!agreeStatus" @click="onSubmit" round block>下一步</van-button>
  21. <!-- </van-form> -->
  22. </div>
  23. </template>
  24. <script>
  25. import MStep from '@/components/MStep'
  26. // import { browser } from '@/common/common'
  27. import {
  28. patternPhone
  29. } from '@/utils/validateRules'
  30. import setLoading from '@/utils/loading'
  31. import {
  32. sendSms,
  33. smsLogin,
  34. queryUserByPhone
  35. } from './SignUpApi'
  36. export default {
  37. name: 'signUpAccount',
  38. components: {
  39. MStep
  40. },
  41. data() {
  42. localStorage.removeItem("Authorization")
  43. let accountInfo = localStorage.getItem('accountInfo')
  44. localStorage.removeItem('accountInfo')
  45. const query = this.$route.query
  46. return {
  47. examId: query.examId,
  48. organId: query.organId,
  49. patternPhone: patternPhone,
  50. agreeStatus: false,
  51. form: accountInfo ? JSON.parse(accountInfo) : {
  52. phone: null,
  53. code: null,
  54. },
  55. countDownStatus: true, // 到计时状态
  56. countDownTime: 1000 * 120 // 倒计时时间
  57. }
  58. },
  59. mounted() {
  60. // 插入token
  61. // let params = this.$route.query
  62. // if(params.Authorization) {
  63. // localStorage.setItem('Authorization', decodeURI(params.Authorization))
  64. // localStorage.setItem('userInfo', decodeURI(params.Authorization))
  65. // }
  66. },
  67. methods: {
  68. async onGetCode() { // 获取验证码
  69. setLoading(true)
  70. if (!this.checkPhone(this.form.phone)) {
  71. return
  72. }
  73. try {
  74. const resultSend = await sendSms({
  75. mobile: this.form.phone
  76. })
  77. const result = resultSend.data
  78. if (result.code === 200) {
  79. this.countDownStatus = false
  80. this.$refs.countdown.start() // 倒计时开始
  81. setLoading(false)
  82. } else {
  83. this.$toast(result.msg)
  84. }
  85. } catch (error) {
  86. //
  87. setLoading(false)
  88. }
  89. },
  90. onCountDownFinished() { // 倒计时结束
  91. this.countDownStatus = true
  92. this.$refs.countdown.reset()
  93. },
  94. async onCheckPhone() { // 检查手机号是否存在
  95. setLoading(true)
  96. try {
  97. let form = this.form
  98. let params = {
  99. mobile: form.phone,
  100. clientId: "student"
  101. }
  102. const code = await queryUserByPhone(params)
  103. const result = code.data
  104. if (result.code === 200) {
  105. // 1 为已注册,0为未注册
  106. this.onLogin(result.data)
  107. } else {
  108. this.$toast(result.msg)
  109. }
  110. } catch (error) {
  111. setLoading(false)
  112. }
  113. },
  114. async onLogin(status) { // 登录
  115. const form = this.form
  116. let params = {
  117. clientId: 'student',
  118. clientSecret: 'student',
  119. phone: form.phone,
  120. smsCode: form.code,
  121. organId: this.organId
  122. }
  123. if (status === 0) { // 不为空是为注册
  124. params.registerFlag = 'true'
  125. }
  126. const login = await smsLogin(params)
  127. const result = login.data
  128. if (result.code === 200) {
  129. let auth = result.data.authentication
  130. localStorage.setItem('Authorization', auth.token_type + ' ' + auth.access_token)
  131. this.$router.push({
  132. path: "/signUpBaseInfo",
  133. query: {
  134. organId: this.organId
  135. }
  136. })
  137. } else {
  138. this.$toast(result.msg)
  139. }
  140. },
  141. onSubmit() {
  142. const form = this.form
  143. if (!this.checkPhone(form.phone)) { // 手机号验证
  144. return
  145. }
  146. if (!form.code) {
  147. this.$toast('请输入验证码')
  148. return
  149. }
  150. if(!this.agreeStatus) {
  151. this.$toast('请先阅读并同意酷乐秀用户注册服务协议')
  152. return
  153. }
  154. // 验证码
  155. this.onCheckPhone()
  156. },
  157. onToProtocol() { // 跳转协议
  158. localStorage.setItem('accountInfo', JSON.stringify(this.form))
  159. this.$router.push({
  160. path: '/smallProtocol'
  161. })
  162. },
  163. checkPhone(phoneNumber) {
  164. let result = true
  165. if (!(this.patternPhone.test(phoneNumber))) {
  166. this.$toast('手机号输入有误')
  167. result = false
  168. }
  169. return result
  170. }
  171. },
  172. destroyed() {
  173. this.$toast.clear()
  174. }
  175. }
  176. </script>
  177. <style lang="less" scoped>
  178. @import url("../../assets/commonLess/variable");
  179. .signUpAccount {
  180. height: 100vh;
  181. overflow-y: auto;
  182. overflow-x: hidden;
  183. background-color: @--main-bg-color;
  184. .title {
  185. font-size: .16rem;
  186. color: @--font-second-color;
  187. padding: .12rem .16rem;
  188. }
  189. /deep/.van-cell {
  190. padding: .13rem .16rem;
  191. }
  192. /deep/.van-field__label {
  193. font-size: .17rem;
  194. color: @--font-main-color;
  195. width: 1.15rem;
  196. }
  197. /deep/.van-field__body {
  198. font-size: .16rem
  199. }
  200. /deep/.van-count-down {
  201. font-size: .16rem;
  202. // color: ;
  203. }
  204. .codeText {
  205. font-size: .16rem;
  206. color: @--main-color;
  207. }
  208. .agreeProtocol {
  209. font-size: .14rem;
  210. display: flex;
  211. align-items: center;
  212. color: @--font-main-color;
  213. padding: .15rem .15rem .05rem;
  214. .van-checkbox {
  215. padding-right: .08rem;
  216. }
  217. /deep/.van-checkbox__icon .van-icon {
  218. // border-color: #14928A;
  219. background: #F4F4F4;
  220. }
  221. /deep/.van-checkbox__icon--checked .van-icon {
  222. color: #FFFFFF;
  223. background-color: @--main-color;
  224. border-color: @--main-color;
  225. }
  226. span {
  227. color: @--main-color;
  228. }
  229. }
  230. .van-button--primary {
  231. margin: .16rem 0 .18rem;
  232. background-color: @--main-color;
  233. border: 1px solid @--main-color;
  234. color: #FFFFFF;
  235. font-size: .18rem;
  236. height: .5rem;
  237. line-height: .52rem;
  238. width: 90%;
  239. margin-left: 5%;
  240. }
  241. .stepBtn {
  242. margin-top: .15rem;
  243. }
  244. }
  245. </style>