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