phone.vue 4.6 KB

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