qingyiay
2023-05-10 29658de29b2eb5292bf0c2fad7427b374b769ebc
pages/public-page/forward/forward.vue
@@ -10,7 +10,14 @@
            </u-form-item>
            <u-form-item label="输入数量" labelWidth="20%" ref="item1">
               <view class="forward-card-amount">
                  <view class="forward-card-amount-input"><u--input v-model="val.carNum" placeholder="请输入转发数量"></u--input></view>
                  <view class="forward-card-amount-input">
                     <u--input
                        v-model="val.carNum"
                        placeholder="请输入转发数量"
                        @input="debouncecarNumInput(index, val.carNum)"
                        @blur="blurInput(index, val.carNum)"
                     ></u--input>
                  </view>
                  <u-checkbox-group v-model="val.checkboxValue1" placement="column" @change="v => checkboxChange(v, index, val)">
                     <u-checkbox :customStyle="{ marginBottom: '8px' }" size="30" labelSize="30" label="全部转发" name="全部转发" :disabled="val.ischecked"></u-checkbox>
                  </u-checkbox-group>
@@ -20,9 +27,11 @@
         </u--form>
      </view>
      <!-- 增加按钮 -->
      <view class="AdddBtn"><u-button text="添加" :hairline="false" type="primary" :customStyle="{ marginBottom: '8px' }" @click="addForm"></u-button></view>
      <view class="AdddBtn">
         <u-button text="添加" :hairline="false" type="primary" :customStyle="{ marginBottom: '8px' }" @click="addForm" :disabled="whetherClick"></u-button>
      </view>
      <!-- 按钮 -->
      <view class="forwardBtn"><u-button text="提交" :hairline="false" type="warning" @click="submitForm"></u-button></view>
      <view class="forwardBtn"><u-button text="提交" :hairline="false" type="warning" @click="submitForm" :disabled="whetherClick1"></u-button></view>
      <!-- 选择货代或车队弹出框 -->
      <view class="selectHuoDaiOrFleet-container">
@@ -55,13 +64,14 @@
<script>
import { customerId } from '@/utils/status';
import toast from '../../../uni_modules/uview-ui/libs/config/props/toast';
export default {
   onLoad(params) {
      console.log(params, '转发页面的参数');
      // 客户
      this.cars2 = Number(params.cars2);
      this.carNumSurplus1 = Number(params.carNumSurplus1);
      this.tempcarNumSurplus1 = this.carNumSurplus1 = Number(params.carNumSurplus1);
      // 货代
      this.carNum = Number(params.carNum);
      this.carNumSurplusHuodai = this.forwardSurplus = Number(params.carNumSurplusHuodai);
@@ -128,12 +138,15 @@
         list1: [{ name: '车队' }, { name: '货代' }],
         tabHuoDai: false,
         carNumSurplus1: '',
         tempcarNumSurplus1: '',
         cars2: '',
         carNum: '',
         carNumSurplusHuodai: '',
         formNum: 1,
         // 个人转发数据
         personalForward: {}
         personalForward: {},
         whetherClick: false,
         whetherClick1: false
      };
   },
   onShow() {
@@ -187,8 +200,7 @@
         }
      },
      checkboxChange(value, index, v) {
         uni.setStorageSync('allrelay', this.jhOrderPlanForwardList[index].carNum);
         this.jhOrderPlanForwardList = this.jhOrderPlanForwardList.map((v, i) => {
         this.jhOrderPlanForwardList = this.jhOrderPlanForwardList.map(v => {
            return {
               ...v,
               ischecked: false
@@ -197,35 +209,34 @@
         if (value.length != 0) {
            let tempforwardSurplus = this.forwardSurplus;
            let tempcarNumSurplus1 = this.carNumSurplus1;
            if (v.id) {
               this.$reqGet('jhorderplanforward', { forwardId: v.id }).then(res => {
                  this.personalForward = res.data;
                  // 计算全部转发数
                  // 客户
                  if (this.roleType == 1) {
                     this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempcarNumSurplus1);
                     if (this.jhOrderPlanForwardList[index].carNum == 0) {
                        this.jhOrderPlanForwardList[index].carNum == tempcarNumSurplus1;
                     }
                  }
                  tempcarNumSurplus1 = 0;
                  // 货代
                  if (this.roleType == 2) {
                     this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempforwardSurplus);
                  }
                  tempforwardSurplus = 0;
               });
            } else {
               if (this.roleType == 1) {
                  this.jhOrderPlanForwardList[index].carNum = this.carNumSurplus1;
                  // this.allrelay(this.jhOrderPlanForwardList[index].carNum, this.carNumSurplus1);
               }
               tempcarNumSurplus1 = 0;
               if (this.roleType == 2) {
                  this.jhOrderPlanForwardList[index].carNum = this.forwardSurplus;
                  // this.allrelay(this.jhOrderPlanForwardList[index].carNum, this.forwardSurplus);
               }
               tempforwardSurplus = 0;
            // if (v.id) {
            //    this.$reqGet('jhorderplanforward', { forwardId: v.id }).then(res => {
            //       this.personalForward = res.data;
            //       // 计算全部转发数
            //       // 客户
            //       if (this.roleType == 1) {
            //          this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempcarNumSurplus1);
            //          this.calculate(this.jhOrderPlanForwardList);
            //          if (tempcarNumSurplus1 == 0) {
            //             this.jhOrderPlanForwardList[index].carNum = this.allrelay(0, this.carNumSurplus1);
            //          }
            //       }
            //       tempcarNumSurplus1 = 0;
            //       // 货代
            //       if (this.roleType == 2) {
            //          this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempforwardSurplus);
            //       }
            //       tempforwardSurplus = 0;
            //    });
            // } else { }
            if (this.roleType == 1) {
               this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.carNumSurplus1, this.jhOrderPlanForwardList[index].carNum);
               this.calculate(this.jhOrderPlanForwardList);
            }
            if (this.roleType == 2) {
               this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.forwardSurplus, this.jhOrderPlanForwardList[index].carNum);
               this.calculate(this.jhOrderPlanForwardList);
            }
            // 选择一个后其余禁止复选
            this.jhOrderPlanForwardList.forEach((v, i) => {
@@ -233,23 +244,10 @@
                  v.ischecked = true;
               }
            });
            this.whetherClick = true;
         } else {
            let tempforwardSurplus = this.forwardSurplus;
            let tempcarNumSurplus1 = this.carNumSurplus1;
            // 货代
            if (this.roleType == 2) {
               this.jhOrderPlanForwardList[index].carNum = 0;
               if (this.jhOrderPlanForwardList[index].carNum <= 0) {
                  this.jhOrderPlanForwardList[index].carNum = 0;
               }
            }
            // 客户
            if (this.roleType == 1) {
               this.jhOrderPlanForwardList[index].carNum = 0;
               if (this.jhOrderPlanForwardList[index].carNum <= 0) {
                  this.jhOrderPlanForwardList[index].carNum = 0;
               }
            }
            this.jhOrderPlanForwardList[index].carNum = 0;
            this.calculate(this.jhOrderPlanForwardList);
         }
      },
      // 获取货代列表
@@ -303,6 +301,43 @@
            }
         });
      },
      // 计算提煤单数量,添加或删除时调用
      calculate(arr) {
         let total = arr.reduce((prev, cur) => {
            return cur.carNum + prev;
         }, 0);
         console.log(total, '提煤单一共的数据');
         if (this.roleType == 1) {
            if (this.cars2 >= total) {
               this.carNumSurplus1 = this.cars2 - total;
               this.whetherClick = false;
               this.whetherClick1 = false;
            } else {
               this.carNumSurplus1 = 0;
               this.$u.toast('剩余提煤单数量不足');
               this.whetherClick = true;
               this.whetherClick1 = true;
            }
         }
         return total;
      },
      debouncecarNumInput(index, value) {
         let time;
         let that = this;
         return (function() {
            if (!time) {
               time = setTimeout(() => {
                  that.$set(that.jhOrderPlanForwardList[index], 'carNum', Number(value));
                  that.calculate(that.jhOrderPlanForwardList);
                  time = null;
               }, 800);
            }
         })();
      },
      blurInput(index, value) {
         this.$set(this.jhOrderPlanForwardList[index], 'carNum', Number(value));
         this.calculate(this.jhOrderPlanForwardList);
      },
      // 添加一组表单
      addForm() {
         // 判断是否有一个复选,如果有则禁止新加的复选,没有则不禁止
@@ -311,7 +346,7 @@
            this.jhOrderPlanForwardList.push({
               orderPlanId: this.orderPlanId,
               name: '',
               carNum: 0,
               carNum: null,
               xsUserId: 0,
               fleetId: 0,
               checkboxValue1: '',
@@ -321,13 +356,14 @@
            this.jhOrderPlanForwardList.push({
               orderPlanId: this.orderPlanId,
               name: '',
               carNum: 0,
               carNum: null,
               xsUserId: 0,
               fleetId: 0,
               checkboxValue1: '',
               ischecked: true
            });
         }
         this.calculate(this.jhOrderPlanForwardList);
      },
      // 删除一组表单
      deleteGroup(index, v) {
@@ -336,6 +372,7 @@
            this.$reqPost('deleteForward', { id: v.id }, 'params').then(res => {
               if (res.code === 0) {
                  this.jhOrderPlanForwardList.splice(index, 1);
                  this.calculate(this.jhOrderPlanForwardList);
                  this.$u.toast('删除成功');
               } else if (res.code === 1) {
                  this.$u.toast(res.msg);
@@ -343,6 +380,7 @@
            });
         } else {
            this.jhOrderPlanForwardList.splice(index, 1);
            this.calculate(this.jhOrderPlanForwardList);
            this.$u.toast('删除成功');
         }
      },