phone-change.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view style="border-top: 1rpx solid #f8f8f8;">
  3. <view class="mlr-36 mt-30">
  4. 更改手机号码后,下次登录可使用新手机号码登录。当前手机号码:{{userInfo.mobile}}
  5. </view>
  6. <u-field v-model="tel" class="mlr-36 mt-40" :trim="true" label-width="0" placeholder="请输入手机号"></u-field>
  7. <view class="code mlr-36 flex">
  8. <input type="text" v-model="code" placeholder="请输入验证码"/>
  9. <view class="code1 white text-center" @click="getcode">
  10. {{vscode}}
  11. </view>
  12. </view>
  13. <view class="fixed-bottom pb-80">
  14. <u-button type="primary" :disabled="!tel || !code" @click="submit">提交</u-button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {mapState} from 'vuex';
  20. export default {
  21. data() {
  22. return {
  23. tel:'',
  24. code:'',
  25. vscode:'获取验证码',
  26. countNum:60,
  27. countDownTimer:null,
  28. submitbtn:true
  29. }
  30. },
  31. computed:{
  32. ...mapState(['userInfo'])
  33. },
  34. methods: {
  35. // 获取短信验证码
  36. getcode(){
  37. var myreg = /^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$/;
  38. if(!myreg.test(this.tel)){
  39. uni.showToast({
  40. title:'请输入手机号',
  41. icon: 'none'
  42. })
  43. return
  44. }
  45. if(this.vscode != '获取验证码' && this.vscode != '重新发送'){
  46. return
  47. }
  48. this.countNum = 60
  49. this.countDownTimer = setInterval(()=> {
  50. if (this.countNum < 1) {
  51. clearInterval(this.countDownTimer)
  52. this.vscode = "重新发送";
  53. return;
  54. }
  55. this.countNum--;
  56. this.vscode = this.countNum + '秒重发';
  57. }, 1000)
  58. this.$http('/api/sms/send',{
  59. mobile: this.tel,
  60. event: 'changemobile'
  61. },'POST').then(data=>{
  62. uni.showToast({
  63. title:'短信已发送,请注意查收',
  64. icon:'none'
  65. })
  66. })
  67. },
  68. submit(){
  69. if(this.submitbtn == true){
  70. this.submitbtn = false
  71. this.$http('/addons/ddrive/user/changemobile',{
  72. mobile: this.tel,
  73. captcha: this.code
  74. },"POST").then(data=>{
  75. this.$store.dispatch('updateUserInfo')
  76. uni.showToast({
  77. title: '修改手机号成功',
  78. icon: 'none'
  79. })
  80. setTimeout(()=>{
  81. uni.navigateBack({})
  82. },1000)
  83. }).catch(data=>{
  84. this.submitbtn = true
  85. })
  86. }
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. /deep/.u-field{
  93. padding: 13px 0 !important;
  94. }
  95. /deep/.u-btn{
  96. height: 96rpx !important;
  97. }
  98. /deep/.u-primary-hover {
  99. background-color: $blue !important;
  100. }
  101. /deep/.u-btn--primary--disabled {
  102. background-color: $bg-1 !important;
  103. }
  104. .code{
  105. margin-top: 10rpx;
  106. padding-top: 14rpx;
  107. padding-bottom: 15rpx;
  108. border-bottom: 1rpx solid #f5f6f7;
  109. input{
  110. margin-left: 8rpx;
  111. font-size: 26rpx;
  112. }
  113. .code1{
  114. width: 180rpx;
  115. height: 70rpx;
  116. font-size: 26rpx;
  117. line-height: 70rpx;
  118. background: $bg-1;
  119. }
  120. }
  121. </style>