Selaa lähdekoodia

refactor(order): 后台订单计算逻辑调整

- 新增 isBackstageOrder 计算属性,用于判断是否为后台订单
- 修改订单金额计算逻辑,区分后台订单和普通订单
- 优化折扣率计算公式,修复可能的除零错误

Signed-off-by: tangshizhe <48740614+tangshizhe@users.noreply.github.com>
tangshizhe 1 kuukausi sitten
vanhempi
commit
ac3cf7a72a

+ 8 - 8
src/views/create-order/components/order-detail-submodule/OrderDetailCardProductSummarize.vue

@@ -66,6 +66,9 @@ export default {
     ...mapState({
       orderDetail: state => state.order.orderDetail,
     }),
+    isBackstageOrder () {
+      return this.orderData?.is_backstage_order === 1;
+    },
   },
   methods: {
     async init(val) {
@@ -179,17 +182,11 @@ export default {
     // 设置合同金额合计和标准售价合计,以及计算折扣率总和。
     setTotalAmounts(productData) {
       this.orderData = this.orderDetail.orderData || {};
-      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 totalFinalPrice = this.isBackstageOrder ? (this.formatNumber(this.orderData.pay_money) || '0.00') : (this.formatNumber(this.orderData.order_money) || '0.00')
+      let totalOriginalPrice = productData.reduce((acc, cur) => acc + Number(cur.original_price), 0).toFixed(2);
       const totalDiscountRate = div(totalFinalPrice, totalOriginalPrice) * 100
       const rateTotal = totalDiscountRate ? (div(totalFinalPrice, totalOriginalPrice) * 100).toFixed(2) + '%' : '0%'
-      // 判断productData中每一项的original_price是否为0,如果有,则返回true
-      // const isAllOriginalPriceZero = productData.map(item => item.original_price === 0);
-      // console.log(isAllOriginalPriceZero, 'isAllOriginalPriceZero')
-      // const isAllOriginalPriceZeroBool = !isAllOriginalPriceZero.includes(true)
-
       // 无标准售价产品,标准售价合计展示为无法计算
-      // const noOriginalPriceProduct = ['企业商机管理', '医械通', '物业数字化营销', '运营商专版']
       let noOriginalPriceProductBool = false
       productData.forEach(product => {
         if(!product.original_price) {
@@ -197,6 +194,9 @@ export default {
         } 
       })
       const originalPriceTotal = !noOriginalPriceProductBool
+      if(originalPriceTotal) {
+        totalOriginalPrice = this.isBackstageOrder ? this.formatNumber(this.orderData.order_money || '0.00') : this.formatNumber(this.orderData.original_price || '0.00')
+      }
       this.orderData = {
         ...this.orderData,
         final_price_total: totalFinalPrice,

+ 14 - 9
src/views/create-order/components/order-detail-submodule/SelectOrderDetailCard.vue

@@ -719,12 +719,12 @@ export default {
 
     // 设置合同金额合计和标准售价合计,以及计算折扣率总和。
     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 = this.orderDetail.orderData || {};
+      const totalFinalPrice = this.isBackstageOrder ? (this.formatNumber(this.orderData.pay_money) || '0.00') : (this.formatNumber(this.orderData.order_money) || '0.00')
+      let totalOriginalPrice = productData.reduce((acc, cur) => acc + Number(cur.original_price), 0).toFixed(2);
+      const totalDiscountRate = div(totalFinalPrice, totalOriginalPrice) * 100
+      const rateTotal = totalDiscountRate ? (div(totalFinalPrice, totalOriginalPrice) * 100).toFixed(2) + '%' : '0%'
       // 无标准售价产品,标准售价合计展示为无法计算
-      // const noOriginalPriceProduct = ['企业商机管理', '医械通', '物业数字化营销', '运营商专版']
       let noOriginalPriceProductBool = false
       productData.forEach(product => {
         if(!product.original_price) {
@@ -732,11 +732,16 @@ export default {
         } 
       })
       const originalPriceTotal = !noOriginalPriceProductBool
-      this.orderData.final_price_total = totalFinalPrice;
-      this.orderData.original_price_total = originalPriceTotal ? '¥' + totalOriginalPrice : '无法计算';
-      this.orderData.rate_total = originalPriceTotal && Number(totalOriginalPrice) ? rateTotal : '无法计算';
+      if(originalPriceTotal) {
+        totalOriginalPrice = this.isBackstageOrder ? this.formatNumber(this.orderData.order_money || '0.00') : this.formatNumber(this.orderData.original_price || '0.00')
+      }
+      this.orderData = {
+        ...this.orderData,
+        final_price_total: totalFinalPrice,
+        original_price_total: originalPriceTotal ? '¥' + totalOriginalPrice : '无法计算',
+        rate_total: originalPriceTotal && Number(totalOriginalPrice) ? rateTotal : '无法计算'
+      }
     },
-
     // flattenLinkOrderList(linkOrderList) {
     //   const result = [];
     //   if (!linkOrderList || linkOrderList.length === 0) return result;

+ 5 - 5
vue.config.js

@@ -80,7 +80,7 @@ module.exports = {
     // allowedHosts: 'all',
     proxy: {
       '^/dev-api': {
-        target: 'https://web2-qmx_admin.jydev.jianyu360.com',
+        target: 'https://jymmi.jianyu360.com:10082/',
         changeOrigin: true,
         ws: false,
         logLevel: 'debug',
@@ -89,7 +89,7 @@ module.exports = {
         }
       },
       '^/bigmember': {
-        target: 'https://jybx2-webtest.jydev.jianyu360.com',
+        target: 'https://jymmi.jianyu360.com:10082/',
         changeOrigin: true,
         ws: false,
         logLevel: 'debug',
@@ -98,7 +98,7 @@ module.exports = {
         }
       },
       '^/filemanage': {
-        target: 'https://web2-qmx_admin.jydev.jianyu360.com',
+        target: 'https://jymmi.jianyu360.com:10082/',
         changeOrigin: true,
         ws: false,
         logLevel: 'debug',
@@ -107,13 +107,13 @@ module.exports = {
         }
       },
       '^/jyOrderManager': {
-        target: 'https://jybx2-webtest.jydev.jianyu360.com',
+        target: 'https://jymmi.jianyu360.com:10082/',
         changeOrigin: true,
         ws: false,
         logLevel: 'debug',
       },
       '^/succbi': {
-        target: 'https://web2-qmx_admin.jydev.jianyu360.com',
+        target: 'https://jymmi.jianyu360.com:10082/',
         changeOrigin: true,
         ws: false,
         logLevel: 'debug'