phone.vue 4.4 KB

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