yangan
2024-11-11 4e517dc54e1e3e5e5b543383c321161de351272e
pages/customer-page/addTo-freightForwarder-driver/addTo-freightForwarder-driver.vue
@@ -1,37 +1,44 @@
<template>
   <!-- 添加货代或司机 -->
   <!-- 添加承运商或司机 -->
   <view class="addTo-freightForwarder-drvier">
      <view class="addForm">
         <u--form labelPosition="top"
            ref="form1">
            <u-form-item labelWidth="20%"
               label="姓名"
               ref="item1"><u--input v-model="name"
               :label="role == 1 ?'承运商' : '姓名'"
               ref="item1"
               v-if="role == 1"><u--input v-model="name"
                  :customStyle="{ border: '1px solid #dddddd' }"></u--input></u-form-item>
            <u-form-item labelWidth="25%"
               label="手机号"
               ref="item1"><u--input v-model="phone"
               ref="item1"
               v-if="role == 1"><u--input v-model="phone"
                  :customStyle="{ border: '1px solid #dddddd' }"></u--input></u-form-item>
            <u-form-item labelWidth="25%"
               label="汽车车牌号"
               ref="item1"
               v-if="role == 2">
               <u--input v-model="carNo"
                  :customStyle="{ border: '1px solid #dddddd' }"></u--input>
               <xm-cell special label="车牌号" :value="carNo" @show="showKeyboard('xmKeyboard')"></xm-cell>
               <xm-keyboard-v2 ref="xmKeyboard" @confirm="(v) => carNo = v"></xm-keyboard-v2>
            </u-form-item>
         </u--form>
      </view>
      <view class="else-invite"
         @click="elseInvite">
         +从其他车队选择
      </view>
      <view class="addBtn"><u-button text="邀请"
            type="primary"
            @click="addToHuoDaiOrDriver"></u-button></view>
            @click="addToHuoDaiOrDriver"
            :loading="loading"></u-button></view>
   </view>
</template>
<script>
   import { customerId } from '@/utils/status.js';
   import { mapMutations } from 'vuex';
   export default {
      onLoad(params) {
         console.log(params,'params')
         this.role = params.role;
         if (params.fleetId) {
            this.fleetId = params.fleetId;
@@ -39,16 +46,19 @@
      },
      data() {
         return {
            role: null, // 决定添加货代司机,还是车队司机
            role: null, // 决定添加承运商司机,还是车队司机
            fleetId: null,
            name: '',
            phone: '',
            carNo: '',
            customerId
            customerId,
            loading: false
         };
      },
      methods: {
         ...mapMutations(['lengthchange']),
         showKeyboard(ref){
            this.$refs[ref].toShow(this.carNo)
         },
         init() {},
         addToHuoDaiOrDriver() {
            switch (this.role) {
@@ -64,7 +74,7 @@
                  }
                  break;
               case '2':
                  if (this.name == '' || this.phone == '' || this.carNo == '') {
                  if (this.carNo == '') {
                     uni.showToast({
                        title: '请规范输入!',
                        icon: 'error',
@@ -77,42 +87,60 @@
                  break;
            }
         },
         // 邀请货代
         // 邀请承运商
         bindHuoDai() {
            // this.$reqPost('bindHuoDai', { customerId: this.customerId, name: this.name, phone: this.phone }, 'params').then(res => {
            this.loading = true
            this.$reqPost('bindHuoDai', { name: this.name, phone: this.phone }, 'params').then(res => {
               this.loading = false
               if (res.code == 0) {
                  this.$u.toast('添加成功');
                  setTimeout(() => {
                     uni.navigateBack({
                        delta: 1
                     });
                     uni.navigateBack()
                     uni.$emit('needRefresh')
                     // uni.switchTab({
                     //    url: '/pages/tabbar-page/myPage-tabbar/myPage-tabbar'
                     // });
                  }, 1000);
               } else {
                  this.$u.toast(res.msg ? res.msg : '未成功添加');
               }
            });
            }).catch(e => {
               this.loading = false
            })
         },
         // 邀请司机
         bindUserFleet() {
            this.$reqPost('bindUserFleet', { fleetId: this.fleetId, name: this.name, phone: this.phone, carNo: this
                  .carNo }, 'params').then(res => {
            this.loading = true
            this.$reqPost('bindUserFleet', {
               fleetId: this.fleetId,
               carNo: this
                  .carNo
            }, 'params').then(res => {
               console.log('邀请司机', res);
               this.loading = false
               if (res.code == 0) {
                  this.$u.toast(res.msg ? res.msg : '操作成功');
                  this.$reqGet('GetUserFleet', { fleetId: this.fleetId }).then(response => {
                     this.lengthchange(response.data.length);
                  });
                  uni.navigateBack({
                     delta: 1
                  });
                  setTimeout(() => {
                     uni.navigateBack()
                     uni.$emit('needRefresh')
                     // uni.switchTab({
                     //    url: '/pages/tabbar-page/myPage-tabbar/myPage-tabbar'
                     // });
                  }, 1000)
               } else {
                  uni.showToast({
                     title: res.msg ? res.msg : '操作失败',
                     duration: 2000
                  });
               }
            });
            }).catch(e => {
               this.loading = false
            })
         },
         elseInvite() {
            uni.navigateTo({
               url: `/pages/public-page/selectFleet/selectFleet?fleetId=${this.fleetId}`
            })
         }
      }
   };
@@ -128,6 +156,13 @@
         margin: 0 auto;
      }
      .else-invite {
         width: vww(150);
         margin: 0 auto;
         color: #3c9cff;
         margin-top: vww(40);
      }
      .addBtn {
         width: 90%;
         position: fixed;