微信

index.vue 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="mainPage" v-if="showPage">
  3. <div class="mask">
  4. <div class="centerLabel" style="width:100%;">
  5. <div class="box" style="margin:0 auto;">
  6. <div class="title">登录</div>
  7. <div class="mobile">
  8. <i class="iconfont icon-dianhua"></i>
  9. <input type="tel" maxlength="11" placeholder="手机号" v-model="postData.phone">
  10. </div>
  11. <div class="sms" style="margin-top:.2rem;">
  12. <i class="iconfont icon-mima"></i>
  13. <input type="tel" maxlength="6" placeholder="验证码" v-model="postData.captcha">
  14. <div class="sand color" v-if="seconds === 61" @click="sandMsg">发送验证码</div>
  15. <div class="sand" v-else>{{seconds}}后可重发</div>
  16. </div>
  17. </div>
  18. <div class="submit" @click="submit">
  19. <div>通过验证</div>
  20. </div>
  21. </div>
  22. <transition name="slide">
  23. <div class="select" v-if="showCase">
  24. <van-picker
  25. show-toolbar
  26. title="请选择"
  27. value-key='CaseName'
  28. :columns="columns"
  29. @cancel="onCancelC"
  30. @confirm="onConfirmC"
  31. />
  32. </div>
  33. </transition>
  34. <transition name="slide">
  35. <div class="select" v-if="showSales">
  36. <van-picker
  37. show-toolbar
  38. title="请选择"
  39. value-key='UserName'
  40. :columns="columnsS"
  41. @cancel="onCancelS"
  42. @confirm="onConfirmS"
  43. />
  44. </div>
  45. </transition>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import { createNamespacedHelpers } from 'vuex'
  51. const { mapActions: actions } = createNamespacedHelpers('userCenter')
  52. const { mapActions: mapLoginActions } = createNamespacedHelpers('login')
  53. const { mapState: mapUserState } = createNamespacedHelpers('userCenter')
  54. let canSubmit
  55. export default {
  56. data () {
  57. return {
  58. showPage: false,
  59. showCase: false,
  60. showSales: false,
  61. seconds: 61,
  62. postData: {
  63. phone: '',
  64. captcha: ''
  65. }
  66. }
  67. },
  68. computed: {
  69. ...mapUserState({
  70. userInfo: x => x.userInfo
  71. }),
  72. },
  73. methods: {
  74. ...actions(['getCaptcha']),
  75. ...mapLoginActions(['submitData']),
  76. sandMsg () {
  77. if (!this.postData.phone) {
  78. this.$toast('请先填写手机号')
  79. return
  80. }
  81. let reg = /^1[0-9]{10}$/
  82. if (!reg.test(this.postData.phone)) {
  83. this.$toast('请填写正确的手机号')
  84. return
  85. }
  86. this.getCaptcha(this.postData.phone)
  87. this.seconds = 60
  88. this.runTime()
  89. },
  90. runTime () {
  91. setTimeout(() => {
  92. this.seconds--
  93. if (this.seconds < 60 && this.seconds >= 1) {
  94. this.runTime()
  95. } else if (this.seconds < 1) {
  96. this.seconds = 61
  97. }
  98. }, 1000)
  99. },
  100. getUrl (val) {
  101. var url = window.location.pathname
  102. return url.replace('sales.html', 'user.html') + '#/' + val + '?hideTabbar=1'
  103. },
  104. submit () {
  105. if (!canSubmit) {
  106. return
  107. }
  108. canSubmit = false
  109. if (!this.postData.captcha) {
  110. this.$toast('请填写验证码')
  111. canSubmit = true
  112. return
  113. }
  114. let reg = /^[0-9]{6}$/
  115. if (!reg.test(this.postData.captcha)) {
  116. this.$toast('验证码格式不正确')
  117. canSubmit = true
  118. return
  119. }
  120. this.submitData(this.postData).then((res) => {
  121. setTimeout(() => {
  122. window.location.replace(this.getUrl('mainPage/coffeeIndex'))
  123. }, 2000)
  124. }).catch(() => {
  125. console.log(111)
  126. canSubmit = true
  127. })
  128. }
  129. },
  130. created () {
  131. canSubmit = true
  132. if (this.userInfo.customer.MapUser) {
  133. // this.showPage = true
  134. window.location.replace(this.getUrl('mainPage/coffeeIndex'))
  135. } else {
  136. this.showPage = true
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. @import 'page.scss';
  143. </style>