StepMobile.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>设置密保</p>
  5. <a href="javascript:void(0)" class="back" @click="jump('select')"><i class="el-icon-back"></i></a>
  6. </div>
  7. <div class="f-form">
  8. <div class="page-part">
  9. <span>使用手机号<strong>{{info | hide}}</strong>接收验证码</span>
  10. </div>
  11. <div class="page-part">
  12. <mt-field auto-complete="off"
  13. placeholder="短信验证码"
  14. v-model="code"
  15. :state="state.code"
  16. @blur.native.capture="validateCode">
  17. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  18. </mt-field>
  19. </div>
  20. <div class="page-part">
  21. <mt-button size="large" type="primary" @click="sureAccount">下一步</mt-button>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'step-mobile',
  29. props: ['info'],
  30. data () {
  31. return {
  32. state: {
  33. code: 'error'
  34. },
  35. code: '',
  36. tokenCode: '',
  37. tokenText: '获取验证码',
  38. tokenTime: '60'
  39. }
  40. },
  41. filters: {
  42. hide: function (value) {
  43. let reg = /^(\d{3})\d{6}(\d{2})$/
  44. return value.replace(reg, '$1******$2')
  45. }
  46. },
  47. methods: {
  48. jump (type) {
  49. this.$emit('stepEvent', type)
  50. },
  51. // 警告弹窗
  52. downToast (type) {
  53. this.$toast({
  54. message: type,
  55. iconClass: 'el-icon-warning'
  56. })
  57. },
  58. // 验证码验证
  59. validateCode () {
  60. if (!this.code) {
  61. this.downToast('请填写验证码信息')
  62. this.state.code = 'error'
  63. } else {
  64. let param = new FormData()
  65. param.append('mobile', this.info)
  66. param.append('code', this.code)
  67. param.append('token', this.tokenCode)
  68. let config = {
  69. headers: {'Content-Type': 'multipart/form-data'}
  70. }
  71. this.$http.post(`/update/user/checkCode/mobile`, param, config)
  72. .then(response => {
  73. if (response.data.success) {
  74. this.state.code = 'success'
  75. } else {
  76. this.state.code = 'error'
  77. return Promise.reject(response.data)
  78. }
  79. }).catch(err => {
  80. this.downToast(err.errMsg)
  81. })
  82. }
  83. },
  84. // 获取验证码
  85. getCheckCode () {
  86. if (this.tokenTime > 0 && this.tokenTime < 60) {
  87. this.downToast('请稍后再点击,我在倒计时')
  88. } else {
  89. this.$indicator.open('获取中...')
  90. let _this = this
  91. this.$http.get('/update/user/check/mobile', {params: {mobile: this.info}})
  92. .then(response => {
  93. this.$indicator.close()
  94. if (response.data) {
  95. this.tokenCode = response.data.content.token
  96. this.$toast({
  97. message: '验证码已经发送到您的手机,请注意查收',
  98. iconClass: 'el-icon-success'
  99. })
  100. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  101. let setTime = setInterval(() => {
  102. _this.tokenTime--
  103. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  104. if (this.tokenTime <= 0) {
  105. clearInterval(setTime)
  106. _this.tokenText = '获取验证码'
  107. _this.tokenTime = 60
  108. }
  109. }, 1000)
  110. }
  111. }).catch(() => {
  112. this.$indicator.close()
  113. this.downToast('请检查网络是否正常或联系服务商')
  114. })
  115. }
  116. },
  117. // 验证信息
  118. sureAccount () {
  119. if (this.state.code !== 'success') {
  120. this.downToast('请确认填写是否有误')
  121. } else {
  122. this.$indicator.open('验证过程中...')
  123. let param = new FormData()
  124. param.append('mobile', this.info)
  125. param.append('code', this.code)
  126. param.append('token', this.tokenCode)
  127. let config = {
  128. headers: {'Content-Type': 'multipart/form-data'}
  129. }
  130. this.$http.post('/update/user/check/mobile', param, config)
  131. .then(response => {
  132. this.$indicator.close()
  133. if (response.data.success) {
  134. this.$emit('stepEvent', 'new')
  135. this.$emit('tokenEvent', response.data.content)
  136. } else {
  137. this.downToast(response.data.errMsg)
  138. }
  139. }).catch(() => {
  140. this.$indicator.close()
  141. this.downToast('请检查网络是否正常或联系服务商')
  142. })
  143. }
  144. }
  145. }
  146. }
  147. </script>