changetel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view class="changetel">
  3. <z-navbar title="更换手机号" back></z-navbar>
  4. <view class="flex-n fac top_toast">
  5. <view class="top_toast_dot">
  6. *
  7. </view>
  8. <view class="top_toast_text">
  9. 更换手机号后,您所在的店铺要用新的手机号重新登录
  10. </view>
  11. </view>
  12. <z-card>
  13. <view class="mlr-40 card_area">
  14. <view class="flex-n fac card_area_item">
  15. <view class="card_icon iconfont iconyuanjiaojuxing2"></view>
  16. <z-input class="ml-19" type="number" align="left" v-model="phone" placeholder="请输入新的手机号码"></z-input>
  17. </view>
  18. <view class="line"></view>
  19. <view class="flex-n fac card_area_item">
  20. <view class="card_icon iconfont iconjuxing11" style="font-size: 30rpx;"></view>
  21. <z-input class="ml-19 flex-1" align="left" v-model="code" placeholder="请输入短信验证码"></z-input>
  22. <view class="card_send_message" v-if="sendCodeState!=2" type="primary" @click="sendCode(phone)">{{sendCodeState=='0'?'发送验证码':'重新获取'}}
  23. </view>
  24. <view class="card_send_message" v-else disabled type="primary">{{countdown}}s</view>
  25. </view>
  26. </view>
  27. </z-card>
  28. <z-button class="mt-50" @click="submit">保 存</z-button>
  29. <u-toast ref="uToast"></u-toast>
  30. </view>
  31. </template>
  32. <script>
  33. export default{
  34. data(){
  35. return{
  36. phone:'',
  37. code:'',
  38. sendCodeState: 0,//发送验证码 0 重新发送 1 倒计时2
  39. countdown: 60,//倒计时
  40. cleartime: '',//清除定时器
  41. }
  42. },
  43. mounted(){
  44. },
  45. watch:{
  46. countdown(newval, oldval) {
  47. if (newval == 0) {
  48. clearInterval(this.cleartime);
  49. this.countdown = 60;
  50. this.sendCodeState = 1;
  51. }
  52. },
  53. },
  54. methods:{
  55. //发送验证码
  56. sendCode(phone) {
  57. this.$axios.post('sms/sendSms', {
  58. "phone": phone,
  59. "type": "SEND_CODE"
  60. }).then(res => {
  61. this.$refs.uToast.success('验证码发送成功');
  62. this.sendCodeState = 2;
  63. this.cleartime = setInterval(() => {
  64. this.countdown--;
  65. }, 1000)
  66. }).catch(err => {
  67. this.$refs.uToast.error(err.msg);
  68. })
  69. },
  70. submit(){
  71. this.$axios.post('app/user/updatePhone',{
  72. phone:this.phone,
  73. code:this.code
  74. }).then(res => {
  75. this.$refs.uToast.success('手机号修改成功');
  76. uni.reLaunch({
  77. url:'../../login/oldlogin'
  78. })
  79. }).catch(err => {
  80. this.$refs.uToast.error(err.msg);
  81. })
  82. }
  83. },
  84. beforeDestroy() {
  85. clearTimeout(this.cleartime);
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .changetel{
  91. .top_toast{
  92. line-height: 97rpx;
  93. margin-left: 30rpx;
  94. letter-spacing: 1rpx;
  95. .top_toast_dot{
  96. font-size: 24rpx;
  97. color: #FF0000;
  98. }
  99. .top_toast_text{
  100. font-size: 24rpx;
  101. color: #666666;
  102. margin-left: 19rpx;
  103. }
  104. }
  105. .card_area{
  106. .card_area_item{
  107. height: 100rpx;
  108. }
  109. .card_icon {
  110. font-size: 40rpx;
  111. min-width: 40rpx;
  112. color: gray;
  113. }
  114. .card_send_message{
  115. font-size: 28rpx;
  116. color: #2481EE;
  117. }
  118. }
  119. }
  120. </style>