付延余
2023-03-23 1cb780b1762c62751c7f5f26132f3a7aa4ef3e2f
pages/public-page/forward/forward.vue
@@ -1,21 +1,27 @@
<template>
   <!-- 转发 -->
   <view class="forward">
      <view class="forward-card">
      <view><u-notice-bar :text="text" :fontSize="30" mode="link"></u-notice-bar></view>
      <view class="forward-card" v-for="(val, index) in jhOrderPlanForwardList">
         <u--form labelPosition="top" :model="forwardForm" ref="form1">
            <u-form-item label="转发对象" labelWidth="20%" ref="item1" @click="forwardObjectClick"><u--input v-model="name" placeholder="点击选择转发对象"></u--input></u-form-item>
            <u-form-item label="转发对象" labelWidth="20%" ref="item1" @click="forwardObjectClick(index)">
               <u--input v-model="val.name" placeholder="点击选择转发对象"></u--input>
            </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="forwardForm.nums" placeholder="请输入转发数量"></u--input></view>
                  <u-checkbox-group v-model="checkboxValue1" placement="column" @change="checkboxChange">
                  <view class="forward-card-amount-input"><u--input v-model="val.carNum" placeholder="请输入转发数量"></u--input></view>
                  <u-checkbox-group v-model="val.checkboxValue1" placement="column" @change="v => checkboxChange(v, index)">
                     <u-checkbox :customStyle="{ marginBottom: '8px' }" size="30" labelSize="30" label="全部转发" name="全部转发"></u-checkbox>
                  </u-checkbox-group>
               </view>
            </u-form-item>
            <u-form-item><u-button text="删除本组" :hairline="false" type="error" @click="deleteGroup(index, val)"></u-button></u-form-item>
         </u--form>
      </view>
      <!-- 增加按钮 -->
      <view class="AdddBtn"><u-button text="添加" :hairline="false" type="primary" :customStyle="{ marginBottom: '8px' }" @click="addForm"></u-button></view>
      <!-- 按钮 -->
      <view class="forwardBtn"><u-button text="提交" :hairline="false" type="primary" @click="submitForm"></u-button></view>
      <view class="forwardBtn"><u-button text="提交" :hairline="false" type="warning" @click="submitForm"></u-button></view>
      <!-- 选择货代或车队弹出框 -->
      <view class="selectHuoDaiOrFleet-container">
@@ -47,7 +53,8 @@
export default {
   onLoad(params) {
      console.log('转发的提煤单id', params.orderPlanId, params.carNum);
      this.cars2 = Number(params.cars2);
      this.carNumSurplus1 = Number(params.carNumSurplus1);
      if (params.carNumSurplus1 || params.carNumSurplusHuodai) {
         if (params.carNumSurplus1 != 0) {
            this.forwardSurplus = params.carNumSurplus1;
@@ -55,7 +62,32 @@
            this.forwardSurplus = params.carNumSurplusHuodai;
         }
      }
      this.forwardForm.orderPlanId = params.orderPlanId;
      this.orderPlanId = params.orderPlanId;
      this.$reqGet('forwardList', { OrderPlanId: params.orderPlanId }).then(res => {
         if (res.data) {
            this.jhOrderPlanForwardList = res.data.map(item => {
               return {
                  id: item.id,
                  orderPlanId: item.orderPlanId,
                  name: item.xsUserName === null ? item.fleetName : item.xsUserName,
                  carNum: item.carNum,
                  xsUserId: item.xsUserId === null ? 0 : item.xsUserId,
                  fleetId: item.fleetId === null ? 0 : item.fleetId,
                  checkboxValue1: ''
               };
            });
            console.log(this.jhOrderPlanForwardList, '列表');
         } else {
            this.jhOrderPlanForwardList = this.jhOrderPlanForwardList.map(v => {
               if (!v.orderPlanId) {
                  return {
                     ...v,
                     orderPlanId: params.orderPlanId
                  };
               }
            });
         }
      });
   },
   data() {
      return {
@@ -63,13 +95,20 @@
         paramsName: {},
         huoDaiData: [],
         fleetData: [],
         name: '',
         forwardForm: {
            orderPlanId: null,
            nums: null,
            userId: 0,
            fleetId: 0
         },
         // 日计划id
         orderPlanId: '',
         jhOrderPlanForwardList: [
            {
               orderPlanId: '',
               name: '',
               carNum: null,
               xsUserId: 0,
               fleetId: 0,
               checkboxValue1: ''
            }
         ],
         // 索引,利用索引正确显示
         index: '',
         checkboxValue1: '',
         selectPopupShow: false,
         list1: [
@@ -80,7 +119,10 @@
               name: '货代'
            }
         ],
         tabHuoDai: false
         tabHuoDai: false,
         carNumSurplus1: '',
         cars2: '',
         formNum: 1
      };
   },
   onShow() {
@@ -93,6 +135,9 @@
   computed: {
      roleType() {
         return uni.getStorageSync('roleType');
      },
      text() {
         return `已领取${this.cars2}张日计划单,剩余${this.carNumSurplus1}张日计划单`;
      }
   },
   methods: {
@@ -110,12 +155,12 @@
               break;
         }
      },
      checkboxChange(value) {
         console.log('复选框变化', value);
      checkboxChange(value, index) {
         console.log('复选框变化', value, index);
         if (value.length != 0) {
            this.forwardForm.nums = this.forwardSurplus;
            this.jhOrderPlanForwardList[index].carNum = this.forwardSurplus;
         } else {
            this.forwardForm.nums = null;
            this.jhOrderPlanForwardList[index].carNum = null;
         }
      },
      // 获取货代列表
@@ -133,9 +178,9 @@
         });
      },
      // 转发
      forwardObjectClick() {
         console.log('hahah');
      forwardObjectClick(index) {
         this.selectPopupShow = true;
         this.index = index;
         console.log(this.huoDaiData, this.fleetData, '转发');
      },
      selectPopupClose() {
@@ -147,27 +192,61 @@
      // 转发选择货代
      forwardHuoDaiObjectSelect(item) {
         this.selectPopupShow = false;
         this.forwardForm.userId = item.userId;
         this.name = item.name;
         this.forwardForm.fleetId = 0;
         console.log('货代选择', this.forwardForm);
         this.jhOrderPlanForwardList[this.index].xsUserId = item.userId;
         this.jhOrderPlanForwardList[this.index].name = item.name;
         this.jhOrderPlanForwardList[this.index].fleetId = 0;
         console.log('货代选择', this.jhOrderPlanForwardList[this.index]);
      },
      // 转发选择车队
      forwardFleetObjectSelect(item) {
         this.selectPopupShow = false;
         this.forwardForm.fleetId = item.id;
         this.name = item.name;
         this.forwardForm.userId = 0;
         console.log('车队选择', this.forwardForm);
         this.jhOrderPlanForwardList[this.index].fleetId = item.id;
         this.jhOrderPlanForwardList[this.index].name = item.name;
         this.jhOrderPlanForwardList[this.index].xsUserId = 0;
         console.log('车队选择', this.jhOrderPlanForwardList[this.index]);
      },
      addForm() {
         this.jhOrderPlanForwardList.push({
            orderPlanId: this.orderPlanId,
            name: '',
            carNum: 0,
            xsUserId: 0,
            fleetId: 0,
            checkboxValue1: ''
         });
      },
      // 删除一组表单
      deleteGroup(index, v) {
         if (v.id) {
            this.$reqPost('deleteForward', { id: v.id }, 'params').then(res => {
               if (res.code === 0) {
                  this.jhOrderPlanForwardList.splice(index, 1);
                  this.$u.toast('删除成功');
               }
            });
         } else {
            this.jhOrderPlanForwardList.splice(index, 1);
         }
      },
      // 提交
      submitForm() {
         if (isNaN(Number(this.forwardForm.nums)) || Number(this.forwardForm.nums) <= 0) {
            this.$u.toast('请输入合法数字');
         } else if (Number(this.forwardForm.nums) > Number(this.forwardSurplus)) {
            this.$u.toast('超过最大订单剩余量');
         } else {
            this.$reqPost('forward', this.forwardForm, 'params').then(res => {
         let isPass = false;
         this.jhOrderPlanForwardList.forEach(v => {
            if (isNaN(Number(v.carNum)) || Number(v.carNum) <= 0) {
               this.$u.toast('请输入合法数字');
               isPass = false;
               return isPass;
            } else if (Number(v.carNum) > Number(this.forwardSurplus)) {
               this.$u.toast('超过最大订单剩余量');
               isPass = false;
               return isPass;
            } else {
               isPass = true;
               return isPass;
            }
         });
         if (isPass) {
            this.$reqPost('forward', this.jhOrderPlanForwardList, 'json').then(res => {
               if (res.code == 0) {
                  this.$u.toast('提交成功');
                  setTimeout(() => {
@@ -196,8 +275,11 @@
   // 卡片
   .forward-card {
      margin-top: vww(24);
      margin-top: vww(10);
      .notice-bar {
         width: 100%;
         height: vww(24);
      }
      .u-form {
         .u-form-item {
            .u-form-item__body {
@@ -227,8 +309,8 @@
   }
   .forwardBtn {
      width: 90%;
      position: fixed;
      width: 100%;
      // position: fixed;
      bottom: vww(50);
   }