bindPhoneNumber.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="wrap">
  3. <view class="top"></view>
  4. <view class="content">
  5. <view class="title">绑定手机号</view>
  6. <input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" />
  7. <button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button>
  8. <u-message-input v-if="show" :focus="true" :value="messageCode" @change="change" @finish="finish" mode="bottomLine" :maxlength="codelength"></u-message-input>
  9. </view>
  10. <!-- <text v-if="messageError">验证码错误,请重新输入</text> -->
  11. <view class="captcha">
  12. <!-- <text v-if="show&&this.messageDisable==false" @tap="noCaptcha">收不到验证码点这里</text> -->
  13. <text v-if="messageShow">{{ second }}秒后可重新获取验证码</text>
  14. </view>
  15. <view class="buttom">
  16. <view class="hint">
  17. 登录代表同意
  18. <text class="link">隐私政策,</text>
  19. 并授权使用您的账号信息(如昵称、头像、收获地址)以便您统一管理
  20. </view>
  21. </view>
  22. <u-toast ref="uToast" />
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. tel: '',
  30. messageCode:'',
  31. messageShow: false,
  32. messageDisable: false,
  33. codelength: 4,
  34. show: false,
  35. second:10,
  36. toastMsg:'',
  37. toastUrl:'',
  38. toastType:'',
  39. // messageError:false
  40. }
  41. },
  42. onLoad() {
  43. },
  44. computed: {
  45. inputStyle() {
  46. let style = {};
  47. if(this.tel.length==11&&this.messageDisable==false) {
  48. style.color = "#fff";
  49. style.backgroundColor = this.$u.color['warning'];
  50. }
  51. return style;
  52. }
  53. },
  54. methods: {
  55. showToast() {
  56. this.$refs.uToast.show({
  57. title: this.toastMsg,
  58. type: this.toastType,
  59. url: this.toastUrl
  60. })
  61. },
  62. submit() {
  63. if(this.$u.test.mobile(this.tel)&&this.messageDisable==false) {
  64. let that = this;
  65. this.$u.api.getcode(this.tel)
  66. .then(res =>{
  67. this.messageDisable = true;
  68. this.messageShow = true;
  69. this.show = true;
  70. let interval = setInterval(() => {
  71. that.second--;
  72. if (that.second <= 0) {
  73. that.messageDisable=false
  74. that.messageShow = false;
  75. if (that.messageCode.lenth != 4) {
  76. // this.messageError = true;
  77. }
  78. clearInterval(interval);
  79. that.second=10;
  80. }
  81. }, 1000);
  82. console.log('getcode res',res)
  83. }).catch(err=>{
  84. console.log('err',err)
  85. this.toastMsg = err.statusCode + ":" + err.data.message;
  86. this.showToast();
  87. console.log('getcode err',err)
  88. });
  89. }
  90. },
  91. // 收不到验证码选择时的选择
  92. // noCaptcha() {
  93. // uni.showActionSheet({
  94. // itemList: ['重新获取验证码', '接听语音验证码'],
  95. // success: function(res) {
  96. // },
  97. // fail: function(res) {
  98. // }
  99. // });
  100. // },
  101. // change事件侦听
  102. change(value) {
  103. // console.log('change', value);
  104. },
  105. // 输入完验证码最后一位执行
  106. finish(value) {
  107. let params = {
  108. phone:this.tel,
  109. code:value
  110. };
  111. this.$u.api.bindphone(params)
  112. .then(res =>{
  113. if(res.retHead.errCode=='0'){
  114. this.$u.api.getuseinfo().then(res => {
  115. console.log('getuseinfo',res.retBody);
  116. this.$u.vuex('vuex_user', res.retBody);
  117. this.toastMsg = '操作成功';
  118. this.showToast();
  119. setTimeout(() => {
  120. this.$u.route({
  121. url: 'pages/template/wxCenter/index'
  122. })
  123. }, 2000);
  124. });
  125. }else{
  126. console.log('asdf',res)
  127. this.toastMsg = res.retHead.errMsg;
  128. this.showToast();
  129. }
  130. }).catch(err=>{
  131. console.log('finish err',err);
  132. this.toastMsg = err.retHead.errMsg;
  133. this.showToast();
  134. });
  135. console.log('finish', value);
  136. }
  137. }
  138. };
  139. </script>
  140. <style lang="scss" scoped>
  141. .hide{display: none!important;}
  142. .wrap {
  143. font-size: 28rpx;
  144. .content {
  145. width: 600rpx;
  146. margin: 80rpx auto 0;
  147. .title {
  148. text-align: left;
  149. font-size: 60rpx;
  150. font-weight: 500;
  151. margin-bottom: 100rpx;
  152. }
  153. input {
  154. text-align: left;
  155. margin-bottom: 10rpx;
  156. padding-bottom: 20rpx;
  157. border-bottom: 1px solid #ddd;
  158. }
  159. .getCaptcha {
  160. margin: 45rpx auto 130rpx;
  161. background-color: rgb(253, 243, 208);
  162. color: $u-tips-color;
  163. border: none;
  164. font-size: 30rpx;
  165. padding: 12rpx 0;
  166. &::after {
  167. border: none;
  168. }
  169. }
  170. }
  171. .buttom {
  172. .hint {
  173. padding: 20rpx 40rpx;
  174. font-size: 20rpx;
  175. color: $u-tips-color;
  176. .link {
  177. color: $u-type-warning;
  178. }
  179. }
  180. }
  181. .captcha {
  182. color: $u-type-warning;
  183. font-size: 30rpx;
  184. margin-top: 40rpx;
  185. text-align: center;
  186. }
  187. }
  188. </style>