user.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="container">
  3. <view class="row b-b">
  4. <text class="tit">手机号</text>
  5. <input class="input" v-model="account" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
  6. </view>
  7. <view>
  8. <!-- <view class="row b-b">
  9. <text class="tit">验证码</text>
  10. <input class="input" v-model="captcha" type="text" placeholder="请填写验证码" placeholder-class="placeholder" />
  11. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  12. </view> -->
  13. <button class="add-btn" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import { mapState, mapMutations } from 'vuex';
  19. import { spread, userinfo } from '@/api/user.js';
  20. export default {
  21. data() {
  22. return {
  23. time: '', //保存倒计时对象
  24. countDown: 0, //倒计时
  25. account: '', //手机号
  26. captcha: '', //验证码
  27. password: '', //新密码
  28. loding: false //是否载入中
  29. };
  30. },
  31. watch: {
  32. // 监听倒计时
  33. countDown(i) {
  34. if (i == 0) {
  35. clearInterval(this.time);
  36. }
  37. }
  38. },
  39. computed: {
  40. ...mapState(['userInfo'])
  41. },
  42. onLoad() {
  43. if (this.userInfo.phone == null) {
  44. this.account = '';
  45. } else {
  46. this.account = this.userInfo.phone;
  47. this.show = false;
  48. }
  49. },
  50. methods: {
  51. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  52. //发送验证码
  53. verification() {
  54. let obj = this;
  55. if (this.account == '') {
  56. this.$api.msg('请输入电话号码');
  57. return;
  58. }
  59. if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(this.account)) {
  60. this.$api.msg('请输入正确的手机号');
  61. return;
  62. }
  63. // 判断是否在倒计时
  64. if (obj.countDown > 0) {
  65. return false;
  66. } else {
  67. obj.countDown = 60;
  68. obj.time = setInterval(() => {
  69. obj.countDown--;
  70. }, 1000);
  71. //调用验证码接口
  72. verify({
  73. phone: obj.account,
  74. type: 'BDING_CODE'
  75. })
  76. .then(({ data }) => {})
  77. .catch(err => {
  78. console.log(err);
  79. });
  80. }
  81. },
  82. confirm(e) {
  83. let obj = this;
  84. obj.loding = true;
  85. spread({
  86. phone: obj.account,
  87. })
  88. .then(({ data }) => {
  89. obj.$api.msg('绑定成功!');
  90. userinfo({})
  91. .then(({ data }) => {
  92. this.setUserInfo(data);
  93. })
  94. .catch(e => {
  95. console.log(e);
  96. });
  97. setTimeout(function() {
  98. obj.loding = false;
  99. uni.navigateBack({
  100. })
  101. }, 1000);
  102. })
  103. .catch(err => {
  104. obj.loding = false;
  105. console.log(err);
  106. });
  107. }
  108. }
  109. };
  110. </script>
  111. <style lang="scss">
  112. page {
  113. background: $page-color-base;
  114. }
  115. .row {
  116. display: flex;
  117. align-items: center;
  118. position: relative;
  119. padding: 0 30rpx;
  120. height: 110rpx;
  121. background: #fff;
  122. .tit {
  123. flex-shrink: 0;
  124. width: 120rpx;
  125. font-size: 30rpx;
  126. color: $font-color-dark;
  127. }
  128. .input {
  129. flex: 1;
  130. font-size: 30rpx;
  131. color: $font-color-dark;
  132. }
  133. .iconlocation {
  134. font-size: 36rpx;
  135. color: $font-color-light;
  136. }
  137. }
  138. .add-btn {
  139. display: flex;
  140. align-items: center;
  141. justify-content: center;
  142. width: 690rpx;
  143. height: 80rpx;
  144. margin: 60rpx auto;
  145. font-size: $font-lg;
  146. color: #fff;
  147. background-color: $base-color;
  148. border-radius: 10rpx;
  149. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  150. }
  151. .bg-gray {
  152. background-color: $color-gray;
  153. }
  154. .code {
  155. color: #5dbc7c;
  156. font-size: 23rpx;
  157. border-left: 1px solid #eeeeee;
  158. width: 150rpx;
  159. flex-shrink: 0;
  160. text-align: center;
  161. }
  162. </style>