Эх сурвалжийг харах

fix: 0元订单类型显示逻辑调整、协议信息显示逻辑调整

Signed-off-by: tangshizhe <48740614+tangshizhe@users.noreply.github.com>
tangshizhe 3 сар өмнө
parent
commit
d4cea0dd5a

+ 101 - 49
src/views/create-order/components/order-detail-submodule/OrderDetailCard.vue

@@ -16,6 +16,11 @@
           <div v-else-if="item.key === 'commission'">
             {{ item.label }}:¥{{ formatNumber(orderData[item.key]) || '-' }}
           </div>
+          <div v-else-if="item.key === 'zero_type'">
+            <span v-if="shouldRenderItem(item)">
+              {{ item.label }}:{{ getFilteredValue(orderData[item.key], item.filter) || '-' }}
+            </span>
+          </div>
           <div v-else>{{ item.label }}:{{ getFilteredValue(orderData[item.key], item.filter ) || '-' }}</div>
         </div>
       </div>
@@ -129,7 +134,7 @@ export default {
         { label: '折扣率', key: 'rate_total' },
         { label: '渠道佣金', key: 'commission'},
         { label: '净合同金额合计', key: 'pure_amount'},
-        { label: '0元订单类型', key: 'zero_type'}
+        { label: '0元订单类型', key: 'zero_type', condition: () => this.orderData.final_price_total === '0.00' },
       ],
       productInfoItems: [
         { label: '活动产品', key: 'activity_code', span: 1, condition: (product) => product.activity_code },
@@ -186,11 +191,6 @@ export default {
           label: '创建时间', 
           width: 102
         } 
-      ],
-      orderColumns: [
-        { prop:'order_code', label: '订单编号', width: 154 },
-        { prop:'service_type', label: '付费类型', width: 80 },
-        { prop:'create_time', label: '创建时间', width: 102 } 
       ]
     }
   },
@@ -201,62 +201,110 @@ export default {
   computed: {},
   methods: {
     init() {
-      this.orderData = {}
       this.orderData = this.orderDetailInfo?.orderData || {}
-      if(this.orderDetailInfo?.productData && this.orderDetailInfo.productData.length > 0) {
-        this.productData = this.orderDetailInfo.productData.map(product => { 
+      let productData = this.orderDetailInfo?.productData || []
+      if(productData.length > 0) {
+        productData = productData.map(product => {
           try {
-            let parsedFilter = {}
-            if(typeof product.filter === 'string' && product.filter !== '') {
-              parsedFilter = JSON.parse(product?.filter || '{}')
-            }
-            // 计算折扣率
-            let rate = 0
-            if(product.original_price) {
-              rate = (div(product.final_price, product.original_price) * 100).toFixed(2) + '%'
-            } else {
-              rate = '无法计算'
-            }
-            // 设置有效周期
-            product.validity_period = this.calculateValidityPeriod(
+            const parsedFilter = this.parseProductFilter(product);
+            const rate = this.calculateDiscountRate(product);
+            const validityPeriod = this.calculateValidityPeriod(
               parsedFilter.buy_cycle,
               parsedFilter.buy_type,
               parsedFilter.give_cycle,
               parsedFilter.give_type,
               product
             );
-            // 设置子账号数量
-            if (product.product_type === 'VIP订阅') {
-              const countTotal = Number(product.buyAccountCount) + Number(product.giftAccountCount) || 0
-              product.subAccountCount = `付费${product.buyAccountCount || 0}个,赠送${product.giftAccountCount || 0}个,合计:<span class="color_main">${countTotal}</span>个`
-              product.mainAccountCount = `付费1个,合计<span class="color_main">1</span>个`;
-            }
-            // 设置合同金额和标准售价
-            product.final_price = (product.final_price / 100).toFixed(2)
-            product.original_price = (product.original_price / 100).toFixed(2)
-            // 设置关联订单信息
-            if(product.linkedOrder && Object.keys(product.linkedOrder).length > 0) {
-              const orderList =  product.linkOrderList.push(product.linkedOrder)
-              product.linkedOrder = this.flattenLinkOrderList(orderList)
-            } else {
-              product.linkedOrder = []
-            }
-            return Object.assign(product, { filter: parsedFilter,  rate});
+            const subAccountCount = this.buildSubAccountCount(product);
+            const mainAccountCount = this.buildMainAccountCount(product);
+            const linkedOrder = this.processLinkedOrder(product);
+            const finalPrice = this.formatNumber(product.final_price);
+            const originalPrice = this.formatNumber(product.original_price);
+
+            return {
+              ...product,
+              filter: parsedFilter,
+              rate,
+              validity_period: validityPeriod,
+              subAccountCount,
+              mainAccountCount,
+              linkedOrder,
+              final_price: finalPrice,
+              original_price: originalPrice
+            };
           } catch (error) {
-            console.error('JSON 解析失败:', error);
+            console.error('产品信息初始化失败:', error);
             return product;
           }
-        })
+        });
+      }
+
+      this.setTotalAmounts(productData);
+      this.productData = productData;
+    },
+
+    parseProductFilter(product) {
+      let parsedFilter = {};
+      if (typeof product.filter === 'string') {
+        try {
+          parsedFilter = JSON.parse(product.filter || '{}');
+        } catch {
+          parsedFilter = {};
+        }
+      } else {
+        parsedFilter = product.filter || {};
+      }
+      return parsedFilter;
+    },
+
+    // 计算折扣率
+    calculateDiscountRate(product) {
+      let rate = '无法计算';
+      if (product.original_price && Number(product.original_price) !== 0) {
+        rate = (div(product.final_price, product.original_price) * 100).toFixed(2) + '%';
+      }
+      return rate;
+    },
+
+    // 构造子账号数量字符串。
+    buildSubAccountCount(product) {
+      if (product.product_type === 'VIP订阅') {
+        const buyCount = Number(product.buyAccountCount) || 0;
+        const giftCount = Number(product.giftAccountCount) || 0;
+        const countTotal = buyCount + giftCount;
+        return `付费${buyCount}个,赠送${giftCount}个,合计:<span class="color_main">${countTotal}</span>个`;
       }
-      // 设置合同金额合计和标准售价合计
-      const totalFinalPrice = (this.productData.reduce((acc, cur) => acc + Number(cur.final_price), 0)).toFixed(2)
-      const totalOriginalPrice = (this.productData.reduce((acc, cur) => acc + Number(cur.original_price), 0)).toFixed(2)
-      this.orderData.final_price_total = '¥' + totalFinalPrice
-      this.orderData.original_price_total = '¥' + totalOriginalPrice
-      // 计算折扣率总和
-      this.orderData.rate_total = (div(totalFinalPrice, totalOriginalPrice) * 100).toFixed(2) + '%'
-      this.productData = this.orderDetailInfo?.productData || []
+      return '';
     },
+
+    // 构造主账号数量字符串。
+    buildMainAccountCount(product) {
+      if (product.product_type === 'VIP订阅') {
+        return `付费1个,合计<span class="color_main">1</span>个`;
+      }
+      return '';
+    },
+
+    // 处理关联订单数据。
+    processLinkedOrder(product) {
+      if (product.linkedOrder && Object.keys(product.linkedOrder).length > 0) {
+        const orderList = [product.linkedOrder];
+        return this.flattenLinkOrderList(orderList);
+      }
+      return [];
+    },
+
+    // 设置合同金额合计和标准售价合计,以及计算折扣率总和。
+    setTotalAmounts(productData) {
+      const totalFinalPrice = productData.reduce((acc, cur) => acc + Number(cur.final_price), 0).toFixed(2);
+      const totalOriginalPrice = productData.reduce((acc, cur) => acc + Number(cur.original_price), 0).toFixed(2);
+      const rateTotal = div(totalFinalPrice, totalOriginalPrice) ? (div(totalFinalPrice, totalOriginalPrice) * 100).toFixed(2) + '%' : '无法计算';
+
+      this.orderData.final_price_total = '¥' + totalFinalPrice;
+      this.orderData.original_price_total = '¥' + totalOriginalPrice;
+      this.orderData.rate_total = rateTotal;
+    },
+
     flattenLinkOrderList(linkOrderList) {
       const result = [];
       linkOrderList.forEach(item => {
@@ -270,6 +318,7 @@ export default {
       });
       return result;
     },
+
     shouldRenderItem(item, product) {
       if (item.condition && typeof item.condition === 'function') {
         const conditionResult = item.condition(product)
@@ -280,6 +329,7 @@ export default {
       }
       return true;
     },
+
     calculateValidityPeriod(buyCycle, buyType, giveCycle, giveType, product) {
       let totalMonths = 0;
       let buyText = '';
@@ -327,11 +377,13 @@ export default {
       const returned_open = product.returned_open === '1' ? '(全额回款当日开通)' : '';
       return `付费${buyText},赠送${giveText},合计<span class="color_main">${totalMonths.toFixed(0)}</span>个月${returned_open}`;
     },
+
     getValidityPeriodHtml(product, item) {
       const label = item.label;
       const value = product[item.key] || '-';
       return `${label}:${value}`;
     },
+
     // 替代过滤器的通用方法
     getFilteredValue(value, filterName) {
       if (!filterName) return value || '-';

+ 24 - 13
src/views/create-order/components/order-detail-submodule/PaymentPlan.vue

@@ -50,26 +50,37 @@ export default {
   data() {
     return {
       paymentPlanList: [
-        // {"code":1,"money":999,"time":"2025-04-22"},
-        // {"code":2,"money":7000,"time":"2025-04-23"},
-        // {"code":"合计","money":7999,"time":"-"}
+        {"code":1,"money":999,"time":"2025-04-22"},
+        {"code":2,"money":7000,"time":"2025-04-23"},
+        {"code":"合计","money":7999,"time":"-"}
       ],
       returnMoneyPlant: {}
     } 
   },
   mounted() {
-    this.returnMoneyPlant = this.orderDetail?.returnMoneyPlant || {}
-    const listMap = this.orderDetail?.returnMoneyPlant?.list || {}
-    if (Object.keys(listMap).length) {
-      let plantList = listMap.plantList
-      if(!plantList) return this.paymentPlanList = []
-      plantList = JSON.parse(plantList)
-      this.paymentPlanList = plantList || []
-    } else {
-      this.paymentPlanList = [] 
-    }
+    this.getPaymentPlanList()
   },
   methods: {
+    getPaymentPlanList() {
+      this.returnMoneyPlant = this.orderDetail?.returnMoneyPlant || {};
+      const listMap = this.orderDetail?.returnMoneyPlant?.list || {};
+
+      let plantList = listMap.plantList;
+
+      if (!plantList) {
+        this.paymentPlanList = [];
+        return;
+      }
+
+      try {
+        plantList = JSON.parse(plantList);
+      } catch (error) {
+        console.error('Failed to parse plantList JSON:', error);
+        plantList = [];
+      }
+
+      this.paymentPlanList = Array.isArray(plantList) ? plantList : [];
+    },
     formatNumber(num, x = 2) {
       return (num / 100).toFixed(x)
     }