|
|
@@ -223,6 +223,11 @@
|
|
|
<p>¥{{JSON.parse(scope.row.jsonInfo).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">
|
|
|
{{JSON.parse(scope.row.jsonInfo).sku}}
|
|
|
@@ -282,6 +287,22 @@
|
|
|
¥{{order.payDelivery.toFixed(2)}}
|
|
|
</span>
|
|
|
</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="折扣率" >
|
|
|
+ <span v-if="order!=null && productTotal > 0">
|
|
|
+ {{((order.payPrice / productTotal) * 100).toFixed(2)}}%
|
|
|
+ </span>
|
|
|
+ <span v-else-if="order!=null">
|
|
|
+ 0.00%
|
|
|
+ </span>
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="产品合计" >
|
|
|
+ <span v-if="order!=null && items!=null && items.length > 0">
|
|
|
+ ¥{{productTotal.toFixed(2)}}
|
|
|
+ </span>
|
|
|
+ <span v-else-if="order!=null">
|
|
|
+ ¥0.00
|
|
|
+ </span>
|
|
|
+ </el-descriptions-item>
|
|
|
</el-descriptions>
|
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
@@ -674,6 +695,27 @@ export default {
|
|
|
computed: {
|
|
|
company(){
|
|
|
return this.$store.state.user.user;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 计算产品合计:每个产品单价*数量之和
|
|
|
+ */
|
|
|
+ productTotal() {
|
|
|
+ if (!this.items || this.items.length === 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ let total = 0;
|
|
|
+ for (let i = 0; i < this.items.length; i++) {
|
|
|
+ const item = this.items[i];
|
|
|
+ try {
|
|
|
+ const jsonInfo = JSON.parse(item.jsonInfo);
|
|
|
+ const price = parseFloat(jsonInfo.price) || 0;
|
|
|
+ const num = parseFloat(item.num) || 0;
|
|
|
+ total += price * num;
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('解析商品信息失败', e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return total;
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -906,6 +948,60 @@ export default {
|
|
|
this.editForm.orderVisit = this.order.orderVisit;
|
|
|
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 计算出库价
|
|
|
+ * @param index 商品索引
|
|
|
+ * @param row 商品行数据
|
|
|
+ * @returns {number} 出库价
|
|
|
+ */
|
|
|
+ getOutboundPrice(index, row) {
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // 如果只有一个商品,直接按折扣率计算
|
|
|
+ if (this.items.length === 1) {
|
|
|
+ return price * discountRate;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 多个商品的情况
|
|
|
+ // 判断是否是最后一个商品
|
|
|
+ const isLastItem = index === this.items.length - 1;
|
|
|
+
|
|
|
+ if (isLastItem) {
|
|
|
+ // 最后一个商品:出库价 = (应付金额 - 之前所有产品出库价*数量的合计) / 数量
|
|
|
+ let previousTotal = 0;
|
|
|
+ for (let i = 0; i < index; i++) {
|
|
|
+ const prevRow = this.items[i];
|
|
|
+ const prevJsonInfo = JSON.parse(prevRow.jsonInfo);
|
|
|
+ const prevPrice = parseFloat(prevJsonInfo.price) || 0;
|
|
|
+ const prevNum = parseFloat(prevRow.num) || 0;
|
|
|
+ const prevOutboundPrice = prevPrice * discountRate;
|
|
|
+ previousTotal += prevOutboundPrice * prevNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (num > 0) {
|
|
|
+ return (payPrice - previousTotal) / num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ // 前n-1个商品:出库价 = 单价 * 折扣率
|
|
|
+ return price * discountRate;
|
|
|
+ }
|
|
|
+ },
|
|
|
getOrder(orderId){
|
|
|
this.orderId=orderId;
|
|
|
this.certificates = null;
|