yuhongqi hace 4 horas
padre
commit
485356648f

+ 76 - 1
src/views/live/liveOrder/liveOrderDetails.vue

@@ -140,6 +140,11 @@
             <p>¥{{scope.row.price.toFixed(2)}}</p>
           </template>
         </el-table-column>
+        <el-table-column label="出库价" width="240" align="center">
+          <template slot-scope="scope">
+            <p>¥{{getOutboundPrice(scope.$index, scope.row).toFixed(2)}}</p>
+          </template>
+        </el-table-column>
         <el-table-column label="市场价" width="240" align="center">
           <template slot-scope="scope">
             {{scope.row.otPrice}}
@@ -176,7 +181,14 @@
           <el-descriptions-item label="实付金额" >  <span v-if="item!=null">{{item.payMoney}}</span>  </el-descriptions-item>
           <el-descriptions-item label="代收金额" >  <span v-if="item!=null">{{item.payRemain}}</span>  </el-descriptions-item>
           <el-descriptions-item label="服务费" >  <span v-if="item!=null">{{0.00}}</span>  </el-descriptions-item>
-          <el-descriptions-item label=""/>
+          <el-descriptions-item label="折扣率"  >
+          <span v-if="item!=null && productTotal > 0">{{ discountRatePercent }}%</span>
+          <span v-else-if="item!=null">0.00%</span>
+        </el-descriptions-item>
+        <el-descriptions-item label="产品合计"  >
+          <span v-if="item!=null && showProd!=null && showProd.length > 0">¥{{productTotal.toFixed(2)}}</span>
+          <span v-else-if="item!=null">¥0.00</span>
+        </el-descriptions-item>
         </el-descriptions>
         <div style="float: right;margin: 20px" v-if="item.totalPrice!=null">
           合计:<span class="color-danger">¥{{item.totalPrice.toFixed(2)}}</span>
@@ -447,6 +459,35 @@ export default {
       this.deliveryTypeOptions = response.data;
     });
   },
+  computed: {
+    /**
+     * 产品合计:每个产品单价*数量之和(基于 showProd)
+     */
+    productTotal() {
+      if (!this.showProd || this.showProd.length === 0) {
+        return 0;
+      }
+      let total = 0;
+      for (let i = 0; i < this.showProd.length; i++) {
+        const row = this.showProd[i];
+        const price = parseFloat(row.price) || 0;
+        const num = parseFloat(row.totalNum) || 0;
+        total += price * num;
+      }
+      return total;
+    },
+    /**
+     * 折扣率百分比(四舍五入保留两位小数),用于费用信息展示
+     */
+    discountRatePercent() {
+      if (!this.item || this.productTotal <= 0) {
+        return '0.00';
+      }
+      const payMoney = parseFloat(this.item.payMoney) || 0;
+      const rate = parseFloat((payMoney / this.productTotal).toFixed(2));
+      return (rate * 100).toFixed(2);
+    }
+  },
   methods: {
 
     followMsg(row){
@@ -832,6 +873,40 @@ export default {
         }
       });
     },
+    /**
+     * 计算出库价
+     * @param index 商品索引
+     * @param row 商品行数据
+     * @returns {number} 出库价
+     */
+    getOutboundPrice(index, row) {
+      if (!this.item || !this.showProd || this.showProd.length === 0) {
+        return 0;
+      }
+      const price = parseFloat(row.price) || 0;
+      const num = parseFloat(row.totalNum) || 0;
+      const payMoney = parseFloat(this.item.payMoney) || 0;
+      if (this.productTotal <= 0) {
+        return 0;
+      }
+      const discountRate = parseFloat((payMoney / this.productTotal).toFixed(2));
+      if (this.showProd.length === 1) {
+        return price * discountRate;
+      }
+      const isLastItem = index === this.showProd.length - 1;
+      if (isLastItem) {
+        let previousTotal = 0;
+        for (let i = 0; i < index; i++) {
+          const prevRow = this.showProd[i];
+          const prevPrice = parseFloat(prevRow.price) || 0;
+          const prevNum = parseFloat(prevRow.totalNum) || 0;
+          const prevOutboundPrice = prevPrice * discountRate;
+          previousTotal += prevOutboundPrice * prevNum;
+        }
+        return num > 0 ? (payMoney - previousTotal) / num : 0;
+      }
+      return price * discountRate;
+    },
     // getlogList(orderId){
     //   logList(orderId).then(response => {
     //     this.logs = response.rows;

+ 22 - 11
src/views/store/components/productOrder.vue

@@ -289,7 +289,7 @@
           </el-descriptions-item>
           <el-descriptions-item label="折扣率"  >
               <span v-if="order!=null && productTotal > 0">
-                {{((order.payPrice / productTotal) * 100).toFixed(2)}}%
+                {{ discountRatePercent }}%
               </span>
               <span v-else-if="order!=null">
                 0.00%
@@ -716,6 +716,16 @@ export default {
         }
       }
       return total;
+    },
+    /**
+     * 折扣率百分比(四舍五入保留两位小数),用于费用信息展示
+     */
+    discountRatePercent() {
+      if (!this.order || this.productTotal <= 0) {
+        return '0.00';
+      }
+      const rate = parseFloat((this.order.payPrice / this.productTotal));
+      return (rate * 100).toFixed(2);
     }
   },
   methods: {
@@ -958,29 +968,30 @@ export default {
       if (!this.order || !this.items || this.items.length === 0) {
         return 0;
       }
-      
+
       const jsonInfo = JSON.parse(row.jsonInfo);
       const price = parseFloat(jsonInfo.price) || 0;
       const num = parseFloat(row.num) || 0;
-      
+
       // 计算折扣率:应付金额 / 产品合计
       const payPrice = parseFloat(this.order.payPrice) || 0;
-      
+
       if (this.productTotal <= 0) {
         return 0;
       }
-      
-      const discountRate = payPrice / this.productTotal;
-      
+
+      // 折扣率四舍五入保留两位小数后再参与计算出库价
+      const discountRate = this.discountRatePercent / 100;
+
       // 如果只有一个商品,直接按折扣率计算
       if (this.items.length === 1) {
         return price * discountRate;
       }
-      
+
       // 多个商品的情况
       // 判断是否是最后一个商品
       const isLastItem = index === this.items.length - 1;
-      
+
       if (isLastItem) {
         // 最后一个商品:出库价 = (应付金额 - 之前所有产品出库价*数量的合计) / 数量
         let previousTotal = 0;
@@ -990,9 +1001,9 @@ export default {
           const prevPrice = parseFloat(prevJsonInfo.price) || 0;
           const prevNum = parseFloat(prevRow.num) || 0;
           const prevOutboundPrice = prevPrice * discountRate;
-          previousTotal += prevOutboundPrice * prevNum;
+          previousTotal += prevOutboundPrice.toFixed(2) * prevNum;
         }
-        
+
         if (num > 0) {
           return (payPrice - previousTotal) / num;
         }