From 62776dc439e90bf46957989d2bd03c209dc1d4f7 Mon Sep 17 00:00:00 2001
From: qb <1191961160@qq.com>
Date: Thu, 23 May 2024 14:15:41 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=B7=E6=A0=BC=E5=B8=A6?=
 =?UTF-8?q?=E5=87=BA=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../WaybillPrintTemplate.vue                  |   4 +-
 src/views/Pricesystem/Price/PriceBill.vue     |  13 +-
 .../Pricesystem/Price/PriceTrunkLine.vue      |  13 +-
 src/views/waybill/CreateZeroOrder.vue         | 156 +++++++++++++++---
 src/views/waybill/WaybillOrderList.vue        |  60 ++-----
 5 files changed, 175 insertions(+), 71 deletions(-)

diff --git a/src/components/WaybillPrintTemplate/WaybillPrintTemplate.vue b/src/components/WaybillPrintTemplate/WaybillPrintTemplate.vue
index 6df80b81..80dc072c 100644
--- a/src/components/WaybillPrintTemplate/WaybillPrintTemplate.vue
+++ b/src/components/WaybillPrintTemplate/WaybillPrintTemplate.vue
@@ -20,7 +20,7 @@
         </el-button>
 
         <el-form-item label="是否显示运费" style="margin: 0px 0px 0px 10px">
-          <el-checkbox></el-checkbox>
+          <el-checkbox v-model="isShowFreight"></el-checkbox>
         </el-form-item>
       </div>
     </el-dialog>
@@ -62,6 +62,8 @@ const props = defineProps({
   },
 });
 
+const isShowFreight = ref(true);
+
 const $emit = defineEmits(['update:modelValue']);
 
 const visible = computed({
diff --git a/src/views/Pricesystem/Price/PriceBill.vue b/src/views/Pricesystem/Price/PriceBill.vue
index 9b54dd62..fb476b06 100644
--- a/src/views/Pricesystem/Price/PriceBill.vue
+++ b/src/views/Pricesystem/Price/PriceBill.vue
@@ -215,7 +215,13 @@
       <div class="flex-c-sb">
         <el-divider content-position="left">提货路径</el-divider>
 
-        <el-button icon="CirclePlus" class="ml10" type="primary" @click="handleAdd" v-if="!$route.query.Viewdetails">
+        <el-button
+          icon="CirclePlus"
+          class="ml10"
+          type="primary"
+          @click="handleAdd"
+          v-if="!$route.query.Viewdetails"
+        >
           新 增
         </el-button>
       </div>
@@ -1191,6 +1197,11 @@ const initAssignmentForm = (data, isLine = true) => {
             data.weightCategory;
       if (!Arr || Arr.length === 0) break;
 
+      if (Arr.length === 1 && !Arr[0].categoryId) {
+        value.categories[0].price = Arr[0].price;
+        continue;
+      }
+
       for (let index = 0; index < Arr.length; index++) {
         const val = Arr[index];
         if (val.categoryId !== item.categoryId) continue;
diff --git a/src/views/Pricesystem/Price/PriceTrunkLine.vue b/src/views/Pricesystem/Price/PriceTrunkLine.vue
index b1a47b27..36518b70 100644
--- a/src/views/Pricesystem/Price/PriceTrunkLine.vue
+++ b/src/views/Pricesystem/Price/PriceTrunkLine.vue
@@ -221,7 +221,13 @@
       <div class="flex-c-sb">
         <el-divider content-position="left">干线路径</el-divider>
 
-        <el-button icon="CirclePlus" class="ml10" type="primary" @click="handleAdd" v-if="!$route.query.Viewdetails">
+        <el-button
+          icon="CirclePlus"
+          class="ml10"
+          type="primary"
+          @click="handleAdd"
+          v-if="!$route.query.Viewdetails"
+        >
           新 增
         </el-button>
       </div>
@@ -1169,6 +1175,11 @@ const initAssignmentForm = (data, isLine = true) => {
             data.weightCategory;
       if (!Arr || Arr.length === 0) break;
 
+      if (Arr.length === 1 && !Arr[0].categoryId) {
+        value.categories[0].price = Arr[0].price;
+        continue;
+      }
+
       for (let index = 0; index < Arr.length; index++) {
         const val = Arr[index];
         if (val.categoryId !== item.categoryId) continue;
diff --git a/src/views/waybill/CreateZeroOrder.vue b/src/views/waybill/CreateZeroOrder.vue
index 78e437e8..58d4aaa7 100644
--- a/src/views/waybill/CreateZeroOrder.vue
+++ b/src/views/waybill/CreateZeroOrder.vue
@@ -1977,16 +1977,38 @@ const handleComputed = (row: any) => {
     handleSpecialBrandPrice(row, trunkLine, template);
 
   details.query.goodsCode = '-' + details.totalObj.totalCount;
-  if (row.chargeType === 1) row.subtotalFreight = computeNumber(row.num, '*', row.price).result;
-  else if (row.chargeType === 2)
-    row.subtotalFreight = computeNumber(row.volume, '*', row.price).result;
-  else if (row.chargeType === 3)
-    row.subtotalFreight = computeNumber(row.weight, '*', row.price).result;
 
-  row.totalPickupPrice = computeNumber(row.num, '*', row.pickupPrice || 0).result;
+  const typeArr = { 1: 'num', 2: 'volume', 3: 'weight' };
+
+  const _trunklineKey = typeArr[row.chargeType];
+  const _dispatchKey = typeArr[row.dispatchType];
+
+  // 计算干线价格 -- 行
+  if (_trunklineKey)
+    row.subtotalFreight = _trunklineKey
+      ? computeNumber(row.price, '*', row[_trunklineKey]).result
+      : 0;
+
+  console.log('_dispatchKey :>> ', _dispatchKey);
+  console.log('_trunklineKey :>> ', _trunklineKey);
 
   console.log('row :>> ', row);
 
+  // 计算配送价格 -- 行
+  if (_dispatchKey)
+    row.subtotalDispatch = _dispatchKey
+      ? computeNumber(row.dispatchPrice, '*', row[_dispatchKey]).result
+      : 0;
+
+  // if (row.chargeType === 1) row.subtotalFreight = computeNumber(row.num, '*', row.price).result;
+  // else if (row.chargeType === 2)
+  //   row.subtotalFreight = computeNumber(row.volume, '*', row.price).result;
+  // else if (row.chargeType === 3)
+  //   row.subtotalFreight = computeNumber(row.weight, '*', row.price).result;
+
+  // 计算提货价格 -- 行
+  row.totalPickupPrice = computeNumber(row.num, '*', row.pickupPrice || 0).result;
+
   handlePrice();
 };
 
@@ -2187,35 +2209,37 @@ const handleTrunkLinePrice = (trunkLine, template) => {
       if (value.subtotalFreight) _total += computeNumber(_total, '+', value.subtotalFreight).result;
     }
 
+    console.log('trunkLine :>> ', trunkLine);
+
     // 是否存在最低计费
-    if ((trunkLine || template) && template.trunklineIsMinCost) {
+    if (trunkLine && template && template.trunklineIsMinCost) {
       switch (Number(template.trunklineMinCostType)) {
         // 价格
         case 1:
-          details.query.totalFreight = template.minCost > _total ? template.minCost : _total;
+          details.query.totalFreight = trunkLine.minCost > _total ? trunkLine.minCost : _total;
           break;
 
         // 件
         case 2:
           details.query.totalFreight =
-            template.minCost > details.totalObj.totalCount
-              ? _total + (template.additionalCost || 0)
+            trunkLine.minCost > details.totalObj.totalCount
+              ? _total + (trunkLine.additionalCost || 0)
               : _total;
           break;
 
         // 方
         case 3:
           details.query.totalFreight =
-            template.minCost > details.totalObj.totalVolume
-              ? _total + (template.additionalCost || 0)
+            trunkLine.minCost > details.totalObj.totalVolume
+              ? _total + (trunkLine.additionalCost || 0)
               : _total;
           break;
 
         // 重量
         case 4:
           details.query.totalFreight =
-            template.minCost > details.totalObj.totalFreight
-              ? _total + (template.additionalCost || 0)
+            trunkLine.minCost > details.totalObj.totalFreight
+              ? _total + (trunkLine.additionalCost || 0)
               : _total;
           break;
 
@@ -2230,6 +2254,53 @@ const handleTrunkLinePrice = (trunkLine, template) => {
 const handleDispatchPrice = (dispatch, template) => {
   // 是否存在模板和维护价格
   if (!dispatch || !template) return;
+
+  console.log('dispatch :>> ', dispatch);
+
+  // 非整车
+  let _total = 0;
+
+  for (let i = 0; i < details.goodsList.length; i++) {
+    const value = details.goodsList[i];
+    if (value.subtotalDispatch) _total += computeNumber(_total, '+', value.subtotalDispatch).result;
+  }
+
+  // 是否存在最低计费
+  if ((dispatch || template) && template.trunklineIsMinCost) {
+    switch (Number(template.dispatchMinCostType)) {
+      // 价格
+      case 1:
+        details.query.deliveryFee = dispatch.minCost > _total ? dispatch.minCost : _total;
+        break;
+
+      // 件
+      case 2:
+        details.query.deliveryFee =
+          dispatch.minCost > details.totalObj.totalCount
+            ? _total + (dispatch.additionalCost || 0)
+            : _total;
+        break;
+
+      // 方
+      case 3:
+        details.query.deliveryFee =
+          dispatch.minCost > details.totalObj.totalVolume
+            ? _total + (dispatch.additionalCost || 0)
+            : _total;
+        break;
+
+      // 重量
+      case 4:
+        details.query.deliveryFee =
+          dispatch.minCost > details.totalObj.deliveryFee
+            ? _total + (dispatch.additionalCost || 0)
+            : _total;
+        break;
+
+      default:
+        break;
+    }
+  } else details.query.deliveryFee = _total;
 };
 
 /** 处理模板费用 */
@@ -2576,7 +2647,7 @@ const handleAssignmentItemPriceTrunkline = (value, trunkLine, template, chargeTy
 
       const _priceArr = _arr[chargeType];
 
-      let _item;
+      let _item: any = {};
 
       if (getObjType(_priceArr) === 'array' && !_item.chargeType) {
         for (let j = 0; j < _priceArr.length; j++) {
@@ -2707,14 +2778,44 @@ const handleSpecialBrandPrice = (value, trunkLine, template) => {
 };
 
 /** 配送价格赋值 */
-const handleAssignmentItemPriceDispatch = (value, dispatch, template) => {
+const handleAssignmentItemPriceDispatch = (
+  value,
+  dispatch,
+  template,
+  chargeType?: number | undefined
+) => {
   const { pieceCategory, cubeCategory, weightCategory } = dispatch;
 
   // 是否区分品类
   if (template.dispatchIsByCategory) {
     // 品类是否存在id
     if (!value.goodsId) value.dispatchPrice = 0;
-    else {
+    else if (getObjType(chargeType) === 'number') {
+      const _arr = {
+        1: pieceCategory,
+        2: cubeCategory,
+        3: weightCategory,
+      };
+
+      const _priceArr = _arr[chargeType];
+
+      let _item: any = {};
+
+      if (getObjType(_priceArr) === 'array' && !_item.chargeType) {
+        for (let j = 0; j < _priceArr.length; j++) {
+          const item = _priceArr[j];
+
+          if (item.categoryId !== value.goodsId) continue;
+          _item = item;
+          break;
+        }
+      }
+
+      console.log('_item :>> ', _item);
+
+      value.dispatchPrice = _item ? _item.price || 0 : 0;
+      value.dispatchType = chargeType;
+    } else {
       let _item: any = {};
       // 件
       if (getObjType(pieceCategory) === 'array') {
@@ -2724,7 +2825,7 @@ const handleAssignmentItemPriceDispatch = (value, dispatch, template) => {
           if (item.categoryId !== value.goodsId) continue;
           _item = item;
 
-          // _item.chargeType = 1;
+          _item.chargeType = 1;
           break;
         }
       }
@@ -2737,7 +2838,7 @@ const handleAssignmentItemPriceDispatch = (value, dispatch, template) => {
           if (item.categoryId !== value.goodsId) continue;
           _item = item;
 
-          // _item.chargeType = 2;
+          _item.chargeType = 2;
           break;
         }
       }
@@ -2750,15 +2851,17 @@ const handleAssignmentItemPriceDispatch = (value, dispatch, template) => {
           if (item.categoryId !== value.goodsId) continue;
           _item = item;
 
-          // _item.chargeType = 3;
+          _item.chargeType = 3;
           break;
         }
       }
 
-      if (!_item) value.dispatchPrice = 0;
-      else {
-        // value.chargeType = _item.chargeType;
-        value.dispatchPrice = _item.price;
+      if (!_item) {
+        value.dispatchType = 1;
+        value.dispatchPrice = 0;
+      } else {
+        value.dispatchType = _item.chargeType;
+        value.dispatchPrice = _item.price || 0;
       }
 
       console.log('_item', _item);
@@ -2793,6 +2896,8 @@ const handleAssignmentItemPriceDispatch = (value, dispatch, template) => {
       default:
         break;
     }
+
+    value.dispatchType = value.chargeType;
   }
 };
 
@@ -2847,7 +2952,8 @@ const handleAssignmentItemPrice = (value, isOnload = false, chargeType?: number
   } else value.pickupPrice = 0;
 
   // 配送
-  if (dispatch && template) handleAssignmentItemPriceDispatch(value, dispatch, template);
+  if (dispatch && template)
+    handleAssignmentItemPriceDispatch(value, dispatch, template, chargeType);
   else value.dispatchPrice = 0;
 
   console.log('value :>> ', value);
diff --git a/src/views/waybill/WaybillOrderList.vue b/src/views/waybill/WaybillOrderList.vue
index 3c43f09d..c0174cf4 100644
--- a/src/views/waybill/WaybillOrderList.vue
+++ b/src/views/waybill/WaybillOrderList.vue
@@ -206,45 +206,6 @@
   </el-dialog>
 
   <!-- 打印 -->
-  <!-- <el-dialog
-    title="运单打印"
-    width="780px"
-    :show-close="false"
-    :fullscreen="details.fullscreenObj.WaybillPrintTemplate"
-    :align-center="true"
-    v-model="details.popUpShow.WaybillPrintTemplate"
-  >
-    <template #header="{ close, titleId, titleClass }">
-      <div class="my-header flex-c-sb">
-        <div :id="titleId" :class="titleClass">运单打印</div>
-        <div class="flex-c-c">
-          <el-button type="text" v-if="!details.fullscreenObj.WaybillPrintTemplate">
-            <el-icon class="" @click="handleFullScrean('open', 'WaybillPrintTemplate')"
-              ><FullScreen
-            /></el-icon>
-          </el-button>
-          <el-button type="text" v-else>
-            <el-icon class="" @click="handleFullScrean('close', 'WaybillPrintTemplate')"
-              ><CopyDocument
-            /></el-icon>
-          </el-button>
-
-          <el-button type="text">
-            <el-icon class="" @click="close"><Close /></el-icon>
-          </el-button>
-        </div>
-      </div>
-    </template>
-
-    <div class="mt10 el-dialog-QRCode-container">
-      <WaybillPrintTemplate
-        v-for="item in details.selectionList"
-        :key="item.id"
-        :waybillInfo="item"
-      />
-    </div>
-  </el-dialog> -->
-
   <WaybillPrintTemplate
     v-model="details.popUpShow.WaybillPrintTemplate"
     :html="details.html"
@@ -373,7 +334,6 @@ const details = reactive<any>({
   fullscreenObj: {
     /** 查看 */
     view: false,
-    WaybillPrintTemplate: false,
   },
   /** 预览图片地址 */
   dialogImageUrl: '',
@@ -630,10 +590,24 @@ const batchPrint = async () => {
 
     let _html = '';
 
-    for (let i = 0; i < data.length; i++) {
-      const value = data[i];
+    if (getObjType(data) !== 'object') return;
+
+    for (const key in data) {
+      const element = data[key];
+
+      for (let i = 0; i < element.length; i++) {
+        const value = element[i];
 
-      _html += JSON.parse(JSON.stringify(value.templateHtml));
+        let template = value.templateHtml;
+
+        console.log('value.templateHtml :>> ', value.templateHtml);
+
+        template = template.replace('第n页', `第${i + 1}页`);
+        template = template.replace('共n页', `共${element.length}页`);
+        template = template.replaceAll('0.00', ``);
+
+        _html += JSON.parse(JSON.stringify(template));
+      }
     }
 
     console.log('res :>> ', res);