wjt
2024-06-22 6f44eb561c9a728e3ff4862554047abc31640ca7
policy/changePhone/changePhone.vue
@@ -8,7 +8,7 @@
                  手机号
               </view>
               <view class="form-input">
                  <input type="number"  placeholder="请输入11位手机号"/>
                  <input type="number"  placeholder="请输入11位手机号" v-model="form.phone"/>
               </view>
            </view>
            <view class="form-item">
@@ -16,7 +16,7 @@
                  验证码
               </view>
               <view class="form-input set-flex set-flex-content-between">
                  <input type="number" placeholder="请输入验证码"/>
                  <input type="number" placeholder="请输入验证码" v-model="form.code"/>
                  <view @click="getCode">
                     <text class="driver"></text>
                     <text class="getcode">{{tips}}</text>
@@ -25,15 +25,14 @@
            </view>
         </view>
         <view style="margin-top: 56rpx;">
            <view class="per-button" @click="loging">修改手机号</view>
            <view class="per-button" @click="changeCode">修改手机号</view>
         </view>
      </view>
   </view>
</template>
<script>
   // 00营商办,01执法,02企业 区分不同的登陆页面
   import { getCode, codeLogin, getInfo } from '@/api/auth.js'
   import { getNewVerify, getInfo, checkCode, updatePhone } from '@/api/auth.js'
   export default {
      data() {
         return {
@@ -50,6 +49,7 @@
         }
      },
      onLoad(options) {
         console.log(options)
         if(options.code) {
            this.form.userType = options.code
         }
@@ -81,10 +81,13 @@
               uni.showLoading({
                  title: '正在获取验证码'
               })
               getCode({phone: this.form.phone }).then(val => {
                     this.startCountdown()
                     uni.hideLoading();
                     uni.$u.toast('验证码已发送');
               getNewVerify({phone: this.form.phone }).then(val => {
                     if(val.data.code == 200) {
                        this.startCountdown()
                        uni.hideLoading();
                        this.tips = `${this.countdownTime}s后重新获取`
                        uni.$u.toast('验证码已发送');
                     }
               })
            } else {
               uni.$u.toast('倒计时结束后再发送');
@@ -107,13 +110,54 @@
               this.startCountdown()
            }, 1000)
         },
         loging() {
            codeLogin(this.form).then(val => {
               if(val.data.token) {
                  this.loginToken = val.data.token
                  uni.setStorageSync('sessionToken', this.loginToken)
                  this.getInfo()
         async checkCode() {
            try{
               const { data } = await checkCode(this.form)
               if(data.code == 200 && data.data) {
                  return Promise.resolve()
               } else {
                  uni.showToast({
                     title: '验证码错误',
                     icon: 'none'
                  })
                  throw "验证码错误"
                  return Promise.reject('验证码错误')
               }
            } catch(err) {
               uni.showToast({
                  title: '验证码错误',
                  icon: 'none'
               })
               throw "验证码错误"
            }
         },
         async changeCode() {
            await this.checkCode()
            if(!this.form.phone){
               uni.showToast({
                  title: '请输入手机号',
                  icon: 'none'
               })
               return
            }
            if(!this.$u.test.mobile(this.form.phone)){
               uni.showToast({
                  title: '请输入正确的手机号',
                  icon: 'none'
               })
               return
            }
            updatePhone(this.form).then(val => {
               if(val.data.code == 200) {
                  uni.showToast({
                     title: '修改成功',
                     icon: 'none'
                  })
                  setTimeout(() => {
                     uni.navigateBack()
                  }, 500)
               }
            })
         },
         getInfo() {