Browse Source

feat(purchaseOrder): 新增采购订单单价修改与批量更新功能

liujt 1 tháng trước cách đây
mục cha
commit
ff7ba37a56

+ 168 - 36
src/BIZComponents/paymentCollectionPlan/Index.vue

@@ -11,20 +11,22 @@
       <!-- 表头工具栏 -->
       <template v-slot:toolbar>
         <div class="headbox">
-            <el-button
-            size="small"
-            type="primary"
-            icon="el-icon-plus"
-            class="ele-btn-icon"
-            @click="handlAdd"
-            v-if="type!='view'"
-            >
-            新增
-            </el-button>
+            <div>
+              <el-button
+                size="small"
+                type="primary"
+                icon="el-icon-plus"
+                class="ele-btn-icon"
+                @click="handlAdd"
+                v-if="showAddBtn"
+              >
+                新增
+              </el-button>
+            </div>
 
             <div class="pricebox">
                 <span class="amount">比例合计:{{ allRatio }}%</span>
-                <span class="amount">计划{{ menu === 'purchase' ? '收款' : '付款' }}金额合计:{{ allPrice }}元</span>
+                <span class="amount">计划{{ menu === 'purchase' ? '付款' : '收款' }}金额合计:{{ allPrice }}元</span>
 
                 <!-- <el-form-item
                     style="width: 300px"
@@ -122,7 +124,7 @@
             placeholder="请选择"
             style="width: 100%"
             :disabled="type=='view'"
-
+            @change="(val) => typeChange(val, scope.$index)"
           >
             <el-option
               v-for="item in paymentTypeOp"
@@ -155,7 +157,7 @@
             <el-input
                 type="number"
                 :min="0"
-                :disabled="type=='view'"
+                disabled
                 v-model="scope.row.price"
                 style="width: 100%"
                 placeholder="请输入"
@@ -177,7 +179,7 @@
           <el-date-picker
             style="width: 140px"
             v-model="scope.row.deadLine"
-            :disabled="type=='view'"
+            :disabled="!showAddBtn"
             type="date"
             placeholder="选择日期"
           >
@@ -220,6 +222,7 @@
 <script>
   import { emailReg, phoneReg, numberReg } from 'ele-admin';
   import { paymentTypeOp } from '@/enum/dict';
+  import { formatPrice } from '@/BIZComponents/setProduct.js';
   export default {
     props: {
       delDetailIds: Array,
@@ -231,6 +234,10 @@
       discountTotalPrice: {
         type: [Number, String],
         default: 0
+      },
+      info: {
+        type: Object,
+        default: () => {}
       }
     },
     data() {
@@ -242,6 +249,7 @@
         ratio: null,
         remark: '',
         type: '',
+        typeName: '',
         issueNumber: null
       };
       return {
@@ -254,14 +262,19 @@
           datasource: []
         },
         paymentTypeOp,
-
-        rules: {}
+        rules: {},
+        isLoadingFromApi: false
       };
     },
     computed: {
       canHandl() {
         return this.form.datasource.length;
       },
+      showAddBtn() {
+        // console.log('showAddBtn~~~~', this.type, this.info);
+        // console.log('showAddBtn!!!!',!['1', '2'].includes(this.info.settlementMode) || this.type != 'view');
+        return !(['1', '2'].includes(this.info?.settlementMode)) && this.type != 'view' 
+      },
       columns() {
         return [
           {
@@ -334,42 +347,68 @@
             resizable: false,
             slot: 'action',
             showOverflowTooltip: true,
-            show: this.type != 'view'
+            show: this.showAddBtn
           }
         ];
       },
       allRatio() {
-        return this.form.datasource.reduce((acc, cur) => acc + Number(cur.ratio), 0).toFixed(2);
+        return formatPrice(this.form.datasource.reduce((acc, cur) => acc + Number(cur.ratio), 0));
       },
       allPrice() {
-        return this.form.datasource.reduce((acc, cur) => acc + Number(cur.price), 0).toFixed(2);
+        // 使用分进行计算,避免浮点数精度问题
+        return formatPrice(this.form.datasource.reduce((acc, cur) => acc + Math.round(Number(cur.price) * 100), 0) / 100);
       },
     },
     watch: {
       discountAmount(newval) {
-        if (newval) {
+        if (newval && !this.isLoadingFromApi) {
           this.refreshprice();
         }
+      },
+      info: {
+        handler(newval) {
+          // if (newval && newval.receiptPaymentList) {
+          //   this.isLoadingFromApi = true;
+          //   this.form.datasource = newval.receiptPaymentList;
+          //   if (newval.payAmount) {
+          //     this.discountAmount = newval.payAmount;
+          //   }
+          //   setTimeout(() => {
+          //     this.isLoadingFromApi = false;
+          //   }, 100);
+          // }
+        },
+        deep: true
       }
     },
     methods: {
       setDiscountAmount(val) {
         console.log(val, '000000');
         this.discountAmount = val;
+        // 立即更新价格,无需设置isLoadingFromApi为true
+        this.refreshprice();
+      },
+      typeChange(val, index = null) {
+        // console.log(val, index, '55555');
+        if (val) {
+          this.$set(this.form.datasource[index], 'typeName', this.paymentTypeOp.find(item => item.value === val).label);
+        }
       },
       //输入比例更新金额
       async ratioInput(val, index = null) {
-        console.log(this.discountAmount, '77777');
+        // console.log(this.discountAmount, '77777');
+        // console.log(val, '5555555');
         val = Number(val);
         try {
           if (index != null) {
             await this.checkRatio();
           }
           let newval = (val / 100).toFixed(2);
-          let price = (this.discountAmount * newval).toFixed(2);
-          console.log(newval, price, index, '88888');
+          // console.log('newval~~~', newval)
+          let price = formatPrice(this.discountAmount * newval);
+          // console.log(newval, price, index, '88888');
           if (index != null) {
-            console.log(newval, price, index, '999999');
+            // console.log(newval, price, index, '999999');
             this.$set(this.form.datasource[index], 'price', price);
           } else {
             return price;
@@ -390,7 +429,7 @@
               sum += Number(r.ratio);
             }
           });
-          console.log(sum, '3333333');
+          // console.log(sum, '3333333');
           if (sum > 100) {
             this.$message.error('总共比例不能超过100');
             this.$set(
@@ -403,20 +442,72 @@
               'price',
               0.0
             );
-            reject(false);
+            resolve(true);
           } else {
             resolve(true);
           }
         });
       },
       refreshprice() {
-        let newData = this.form.datasource;
-        newData.forEach(async (r, index) => {
+        // 如果正在从API加载数据,则不执行刷新操作
+        if (this.isLoadingFromApi) {
+          return;
+        }
+        
+        // 创建一个新的数组,避免直接修改原数组
+        let newData = JSON.parse(JSON.stringify(this.form.datasource));
+        console.log('newData after copy:', newData);
+        
+        // 先根据比例计算所有价格
+        for (let i = 0; i < newData.length; i++) {
+          const r = newData[i];
           if (r.ratio) {
-            console.log(this.ratioInput(Number(r.ratio)), '9999888888');
-            r.price = await this.ratioInput(Number(r.ratio));
+            // 直接计算价格,避免使用async/await的forEach
+            let val = Number(r.ratio);
+            let newval = (val / 100).toFixed(2);
+            let price = formatPrice(this.discountAmount * newval);
+            newData[i] = {
+              ...r,
+              price: price
+            };
           }
-        });
+        }
+        
+        // 验证并调整最后一行价格,确保总和等于优惠后的总金额
+        // 使用分进行计算,避免浮点数精度问题
+        const allPriceSum = newData.reduce((acc, cur) => acc + Math.round(Number(cur.price || 0) * 100), 0) / 100;
+        const discountAmount = Number(this.discountAmount);
+        // 直接计算比例总和,避免字符串转换问题
+        const allRatio = newData.reduce((acc, cur) => acc + Number(cur.ratio || 0), 0);
+        
+        console.log('allPriceSum:', allPriceSum, 'discountAmount:', discountAmount, 'allRatio:', allRatio);
+        
+        // 检查是否所有数据都有price且比例合计为100%
+        const allHavePrice = newData.every(item => item.price != null && item.price !== '');
+        
+        console.log('allHavePrice:', allHavePrice);
+        
+        if (allHavePrice && Math.abs(allRatio - 100) < 0.01 && Math.abs(allPriceSum - discountAmount) >= 0.01) {
+          // 调整最后一行的价格
+          if (newData.length > 0) {
+            const lastIndex = newData.length - 1;
+            // 使用分进行计算,避免浮点数精度问题
+            const otherPriceSum = newData.slice(0, lastIndex).reduce((acc, cur) => acc + Math.round(Number(cur.price || 0) * 100), 0) / 100;
+            // 计算最后一行应该有的价格
+            const lastPrice = Math.round((discountAmount - otherPriceSum) * 100) / 100;
+            newData[lastIndex] = {
+              ...newData[lastIndex],
+              price: formatPrice(lastPrice)
+            };
+            console.log('adjusted last item price:', lastPrice);
+          }
+        }
+        
+        console.log('newData before update:', newData);
+        
+        // 确保更新this.form.datasource,触发Vue的响应式更新
+        this.form.datasource = newData;
+        console.log('after update, datasource:', this.form.datasource);
       },
       // 返回列表数据
       getTableValue() {
@@ -424,7 +515,7 @@
       },
       //修改回显
       putTableValue(data) {
-        console.log('data~~~~', data);
+        console.log('data~~~~111', data);
         if (data) {
           this.form.datasource = data.receiptPaymentList;
           this.setDiscountAmount(data.payAmount);
@@ -438,6 +529,7 @@
           if (row.id) {
             this.delDetailIds.push(row.id);
           }
+          this.$emit('getIssueNumber', this.form.datasource.length);
         }
       },
       // 清空表格
@@ -451,7 +543,7 @@
         });
       },
       defaultList(method, issueNumber, dateRange) {
-        console.log('method, issueNumber', method, issueNumber);
+        // console.log('method, issueNumber', method, issueNumber, dateRange);
         const tempList = []
         if(dateRange) {
           this.setDefaultList(dateRange, issueNumber);
@@ -463,6 +555,7 @@
             let item = JSON.parse(JSON.stringify(this.defaultForm));
               item.moneyName = i < params.length ? params[i] : '';
               item.type = i < params.length ? this.paymentTypeOp[i].value : '';
+              item.typeName = i < params.length ? this.paymentTypeOp[i].label : '';
               item.key = i + 1;
               item.issueNumber = i + 1;
               tempList.push(item);
@@ -486,15 +579,34 @@
           // });
           for(let i = 0; i < issueNumber; i++) {
             let item = JSON.parse(JSON.stringify(this.defaultForm));
+            if(issueNumber == 1) {
+              item.moneyName = '';
+              item.type = 2;
+              item.typeName = '交货款';
+              item.ratio = 100;
+              item.key = i + 1;
+              item.issueNumber = i + 1;
+            } else {
               item.moneyName = '';
               item.type = '';
+              item.typeName = '';
+              item.ratio = '';
               item.key = i + 1;
               item.issueNumber = i + 1;
-              tempList.push(item);
+            }
+            tempList.push(item);
           }
         }
         console.log('tempList~~~', tempList);
-        this.form.datasource = tempList;
+        // 清空原数组并逐个添加新元素,确保Vue能够检测到变化
+        this.form.datasource = [];
+        this.$nextTick(() => {
+          this.form.datasource = tempList;
+          console.log('form.datasource after update:', this.form.datasource);
+          // 强制组件重新渲染
+          this.$forceUpdate();
+          console.log('forceUpdate called');
+        });
       },
 
       transformDaysFun(date) {
@@ -559,18 +671,30 @@
         return allMonthDates;
       },
       setDefaultList(dateRange, issueNumber) {
+        // console.log('setDefaultList-dateRange~~~', dateRange);
         const tempPeriod = issueNumber || 0;
 
         // 计算基本比例
         const basicRatio = 100 / tempPeriod;
         let totalRatio = 0;
         
+        // 保存原有数据
+        const existingData = [...this.form.datasource];
+        
         // 生成付款计划列表项
         const tempList = [];
         
         // 根据传入的period参数生成付款计划
         for (let i = 0; i < tempPeriod; i++) {
           let item = JSON.parse(JSON.stringify(this.defaultForm));
+          // let item;
+          // // 如果原有数据中有对应项,则保留原有数据
+          // if (i < existingData.length) {
+          //   item = JSON.parse(JSON.stringify(existingData[i]));
+          // } else {
+          //   item = JSON.parse(JSON.stringify(this.defaultForm));
+          // }
+          
           // 获取日期:如果i小于日期数组长度则使用对应日期,否则设为空
           const deadLine = i < dateRange.length ? dateRange[i] : '';
           const ratio = parseFloat(basicRatio.toFixed(2));
@@ -592,9 +716,16 @@
         // }
         
         console.log('付款计划列表:~~', tempList);
-        this.form.datasource = tempList;
         // this.$set(this.form, 'datasource', tempList);
         console.log('付款计划列表:', this.form.datasource);
+        this.form.datasource = [];
+        this.$nextTick(() => {
+          this.form.datasource = tempList;
+          console.log('form.datasource after update:', this.form.datasource);
+          // 强制组件重新渲染
+          this.$forceUpdate();
+          console.log('forceUpdate called');
+        });
       },
       // 添加
       handlAdd() {
@@ -602,6 +733,7 @@
         item.key = this.form.datasource.length + 1;
         item.issueNumber = this.form.datasource.length + 1;
         this.form.datasource.push(item);
+        this.$emit('getIssueNumber', this.form.datasource.length);
       },
 
       // validateForm(callback) {

+ 134 - 32
src/BIZComponents/setProduct.js

@@ -6,54 +6,129 @@ export function formatPrice(price, decimals = 4) {
 }
 
 //改变数量
-export function changeCount(row, countObj,noDiscountSingle) {
-  let total = row[countObj.countKey] || 0;
-  let data = row;
-  let endIndex = row.packageDispositionList.findIndex(
-    (ite) => row[countObj.unitIdKey] == ite.id
-  );
-  for (; 0 < endIndex; endIndex--) {
-    total = Vue.prototype.$math.format(
-      row.packageDispositionList[endIndex].packageCell * total,
-      14
+export function changeCount(row, countObj, noDiscountSingle, weightType) {
+  
+  let data = JSON.parse(JSON.stringify(row));
+  // console.log('changeCount~~', data);
+  let total = data[countObj.countKey] || 0;
+
+  let _endIndex = 0; //计算单重需要
+  if (data.packageDispositionList) {
+    let endIndex = data.packageDispositionList.findIndex(
+      (ite) => data[countObj.unitIdKey] == ite.id
+    );
+    _endIndex = endIndex;
+    let packageData = data.packageDispositionList.find(
+      (ite) => data[countObj.unitIdKey] == ite.id
     );
+    data[countObj.unitKey] = packageData.conversionUnit;
+    if (data.weightUnit == data.measuringUnit && data.singleWeight) {
+      data.packageDispositionList[1].packageCell = data.singleWeight;
+    }
+    for (; 0 < endIndex; endIndex--) {
+      total = Vue.prototype.$math.format(
+        data.packageDispositionList[endIndex].packageCell * total,
+        14
+      );
+    }
   }
   data['totalCount'] = total;
-  data['discountSinglePrice'] = !noDiscountSingle
-    ? data.singlePrice
-    : data.discountSinglePrice;
+  // data['discountSinglePrice'] = !noDiscountSingle
+  //   ? data.singlePrice
+  //   : data.discountSinglePrice;
+
+  data['discountSinglePrice'] = data.singlePrice && data.discountRatio ? formatPrice(+data.singlePrice * (+data.discountRatio /100)) : data.singlePrice;
+  // console.log('discountSinglePrice~~~', data.singlePrice, data.discountRatio);
 
-  setWeight(data);
-  if (row.totalCount && row.singlePrice) {
-    data['totalPrice'] = row.totalCount * row.singlePrice;
-    data['discountTotalPrice'] = !noDiscountSingle
-      ? data.totalPrice
-      : data.discountTotalPrice;
+  if (weightType == 'totalWeight') {
+    console.log('weightType~~', 1);
+    setSingleWeight(data, countObj, _endIndex);
+  } else {
+    console.log('weightType~~', 2);
+    setWeight(data, countObj);
   }
-  // getNotaxSinglePrice(data);
+
+  data['totalPrice'] = 0;
+  data['discountTotalPrice'] = 0;
+  if (data.pricingWay == 2 || data.pricingWay == 3) {
+    if (data.totalWeight && data.singlePrice) {
+      data['totalPrice'] = formatPrice(data.totalWeight * data.singlePrice);
+    }
+  } else {
+    if (data[countObj.countKey] && data.singlePrice) {
+      data['totalPrice'] = formatPrice(data[countObj.countKey] * data.singlePrice);
+    }
+  }
+  // data['discountTotalPrice'] = !noDiscountSingle
+  //   ? data.totalPrice
+  //   : data.discountTotalPrice;
+  data['discountTotalPrice'] = data['totalPrice'] && data.discountRatio ? formatPrice(+data['totalPrice'] * (data.discountRatio /100)) : data['totalPrice'];
   return data;
-  // if (row) {
-  //   singleWeightChange(row, index);
-  // }
-  // return getNumTotalPrice(arr, noDiscountSingle);
 }
-function setWeight(row) {
+// 计算总重
+function setWeight(row, countObj) {
+  // return
   if (row.weightUnit == row.measuringUnit) {
     row['totalWeight'] = row.totalCount;
   } else if (row.totalCount && row.singleWeight) {
-    row['totalWeight'] = row.totalCount * row.singleWeight;
+    row['totalWeight'] = Number((row.totalCount * row.singleWeight).toFixed(2));
   } else {
     row['totalWeight'] = 0;
   }
+  // if (row.weightUnit == row[countObj.unitKey]) {
+  //   row['totalWeight'] = row.totalCount;
+  // } else if (row[countObj.countKey] && row.singleWeight) {
+  //   row['totalWeight'] = (row[countObj.countKey] * row.singleWeight).toFixed(2);
+  // } else {
+  //   row['totalWeight'] = 0;
+  // }
+  // if (row.weightUnit == row.measuringUnit) {
+  //   row['totalCount'] = row.totalWeight;
+  // }
+  console.log(row['totalCount'], 'dsds');
 }
-export function getAllPrice(arr){
+// 计算单重
+function setSingleWeight(row, countObj, endIndex) {
+  console.log('setSingleWeight~~', row);
+  //  if (row.totalWeight && row[countObj.countKey]) {
+  //     row['singleWeight'] = (row.totalWeight / row[countObj.countKey]).toFixed(2);
+  //     console.log('singleWeight~~', row['singleWeight']);
+  //   } else {
+  //     row['singleWeight'] = 0;
+  //   }
+  // console.log(endIndex, 'endIndex');
+  if (row.weightUnit == row.measuringUnit) {
+    let totalWeight = row['totalWeight'];
+    for (; 1 < endIndex; endIndex--) {
+      totalWeight = Vue.prototype.$math.format(
+        totalWeight / row.packageDispositionList[endIndex].packageCell,
+        14
+      );
+    }
+    // console.log(totalWeight, 'totalWeight');
+    row['singleWeight'] = Number(totalWeight / row[countObj.countKey]).toFixed(
+      2
+    );
+  } else if (row.totalWeight && row.totalCount) {
+    row['singleWeight'] = Number((row.totalWeight / row.totalCount).toFixed(2));
+  } else {
+    row['singleWeight'] = 0;
+  }
+  if (row.weightUnit == row.measuringUnit) {
+    row['totalCount'] = row.totalWeight;
+  }
+  if (row.weightUnit == row[countObj.unitKey]) {
+    row[countObj.countKey] = row.totalWeight;
+  }
+}
+export function getAllPrice(arr) {
   let sum = 0;
-  arr.forEach(item=>{
-    if(item.totalPrice){
-      sum+=Number(item.totalPrice)
+  arr.forEach((item) => {
+    if (item.totalPrice) {
+      sum += Number(item.totalPrice);
     }
-  })
-  return sum
+  });
+  return isNaN(sum) ? 0 : formatPrice(sum);
 }
 
 export function getAllQuantity(arr, countObj) {
@@ -66,6 +141,33 @@ export function getAllQuantity(arr, countObj) {
   });
   return isNaN(sum) ? 0 : formatPrice(sum);
 }
+
+// 获取优惠后总金额
+export function getAllDiscountPrice(arr) {
+  let sum = 0;
+  arr.forEach((item) => {
+    if (item.discountTotalPrice) {
+      sum += Number(item.discountTotalPrice);
+    }
+  });
+  return isNaN(sum) ? 0 : formatPrice(sum);
+}
+
+//获取折让合计
+export function getDiscountTotalPrice(row) {
+  let num = 0;
+  num =
+    Number(row.discountSinglePrice) * Number(row[countObj.countKey]);
+  return isNaN(num) ? '' : formatPrice(num);
+}
+
+//获取折让单价
+export function getDiscountSinglePrice(row) {
+  let num =
+    Number(row.discountTotalPrice) *
+    Number(row[countObj.countKey]);
+  return isNaN(num) ? '' : formatPrice(num);
+}
 // //计算不含税单价
 // function getNotaxSinglePrice(row) {
 //   if (row.singlePrice && row.taxRate) {

+ 13 - 0
src/api/bpm/components/purchasingManage/purchaseOrder.js

@@ -40,3 +40,16 @@ export async function cancel(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+/**
+ * 更新采购订单
+ */
+export async function updateProductPrice(data) {
+  const res = await request.put(`/eom/purchaseorder/v1/updateProductPrice`, data);
+  if (res.data.code == 0) {
+    return Promise.resolve(res.data);
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+

+ 100 - 2
src/views/bpm/handleTask/components/purchaseOrder/detailDialog.vue

@@ -196,7 +196,7 @@
         <ele-pro-table
           ref="table"
           :needPage="false"
-          :columns="competAnalysisListcolumns"
+          :columns="columns"
           :datasource="detailData.productList"
           row-key="id"
           tool-class="ele-toolbar-form"
@@ -209,6 +209,19 @@
               <span class="amount">应付金额:{{ detailData.payAmount }}元</span>
             </div>
           </template>
+          <template v-slot:singlePrice="scope">
+            <el-input
+              v-if="$hasPermission('wt:todo:purchaseSingePrice')"
+              slot="reference"
+              v-model="scope.row.singlePrice"
+              type="number"
+              placeholder="请输入"
+              @input="changeCount(scope.row, scope.$index)"
+            >
+              <!-- <template slot="append">元</template> -->
+            </el-input>
+            <span v-else>{{ scope.row.singlePrice }}</span>
+      </template>
           <template v-slot:technicalDrawings="{ row }">
             <fileMain v-model="row.technicalDrawings" type="view"></fileMain>
           </template>
@@ -276,6 +289,7 @@
   import tableColumnsMixin from '@/mixins/tableColumnsMixin.js';
   import { shippingModePurchaseOp, transactionMethodsOp } from '@/enum/dict.js';
   import PaymentCollectionPlan from '@/BIZComponents/paymentCollectionPlan/Index.vue'
+  import { changeCount, getAllPrice, getAllDiscountPrice, formatPrice } from '@/BIZComponents/setProduct.js';
   export default {
     mixins: [dictMixins, tableColumnsMixin],
     components: { PaymentCollectionPlan },
@@ -346,7 +360,7 @@
             slot: 'remark'
           }
         ],
-        competAnalysisListcolumns: [
+        columns: [
           {
             width: 45,
             type: 'index',
@@ -909,6 +923,76 @@
       this.getDetailData(this.businessId);
     },
     methods: {
+      //改变数量
+      changeCount(row, index, weightType) {
+        // if (this.detailType) {
+        //   return;
+        // }
+
+        let countObj = {
+          countKey: 'purchaseCount',
+          unitKey: 'purchaseUnit',
+          unitIdKey: 'purchaseUnitId',
+          type: 'purchase'
+        };
+        if (!row) {
+          this.detailData.productList.forEach((item, index) => {
+            this.$set(this.detailData.productList, index, changeCount(item, countObj));
+            this.setIncreaseTotalWeight(item, index);
+          });
+        } else {
+          console.log(changeCount(row, countObj, false, weightType), '556644');
+
+          this.$set(
+            this.detailData.productList,
+            index,
+            changeCount(row, countObj, false, weightType)
+          );
+          this.setIncreaseTotalWeight(row, index);
+        }
+
+        this.$nextTick(() => {
+          this.getNotaxSinglePrice();
+          this.changeAll();
+          this.$forceUpdate();
+        })
+      },
+      setIncreaseTotalWeight(row, index) {
+        if (row.pricingWay == 3) {
+          this.$set(
+            this.form.datasource[index],
+            'totalPrice',
+            ((row.increaseTotalWeight || 0) * row.singlePrice).toFixed(2)
+          );
+          this.changeAll();
+        }
+      },
+      //计算不含税单价
+      getNotaxSinglePrice() {
+        this.detailData.productList.forEach((item, index) => {
+          if (item.singlePrice && item.taxRate) {
+            this.$set(
+              this.detailData.productList[index],
+              'notaxSinglePrice',
+              formatPrice(
+                item.singlePrice / (1 + item.taxRate / 100)
+              )
+            );
+          } else {
+            this.$set(this.detailData.productList[index], 'notaxSinglePrice', '');
+          }
+        });
+      },
+      changeAll() {
+        this.detailData.totalAmount = getAllPrice(this.detailData.productList) || 0;
+        this.detailData.payAmount = getAllDiscountPrice(this.detailData.productList) || 0;
+        this.form.totalAmount = this.detailData.totalAmount;
+        this.form.payAmount = this.detailData.payAmount;
+        this.$refs.paymentCollectionPlanRef?.setDiscountAmount(this.detailData.payAmount);
+        // this.$store.commit('concact/setDiscountAmount', this.form.discountTotalPrice);
+        // this.$store.commit('order/setAllcountAmount', this.allPrice);
+        // this.$emit('orderDiscountAmount', this.detailData.discountTotalPrice);
+      },
       downloadFile(file) {
         getFile({ objectName: file.storePath }, file.name);
       },
@@ -922,6 +1006,20 @@
           this.detailData = data;
           this.$refs.paymentCollectionPlanRef && this.$refs.paymentCollectionPlanRef.putTableValue(data);
         }
+      },
+      getTableValue() {
+        return new Promise(async (resolve, reject) => {
+          // 判断 productList 中的单价是否填写
+          const emptyPriceList = this.detailData.productList.filter(item => !item.singlePrice);
+          console.log(this.$hasPermission('wt:todo:purchaseSingePrice'));
+          if (emptyPriceList.length > 0) {
+            this.$message.warning('请填写产品单价');
+            reject(new Error('产品单价未填写'));
+          } else {
+            // let data = await UpdateInformation(this.detailData);
+            resolve(this.detailData);
+          }
+        })
       }
     }
   };

+ 12 - 0
src/views/bpm/handleTask/components/purchaseOrder/submit.vue

@@ -130,6 +130,8 @@
       },
 
       async handleAudit(status) {
+
+        // return;
         //发起人补充
         if (this.taskDefinitionKey === 'starter') {
           let arr = await this.getTableValue();
@@ -145,6 +147,16 @@
             return;
           }
         }
+        if(this.$hasPermission('wt:todo:purchaseSingePrice')) {
+          let arr = await this.getTableValue();
+          console.log('status~~~', status, arr);
+          let data = await UpdateInformation(arr);
+          if (data.code != '0') {
+            this.$message.warning(data.message);
+            return;
+          }
+        }
+        
         this._approveTaskWithVariables(status);
       },
       async _approveTaskWithVariables(status) {