Commit 1645734f by 胡悦

feat(订单): 添加删除商品功能并优化总价计算逻辑

添加删除商品的功能,点击删除图标可移除对应商品
优化总价计算逻辑,支持多种商品类型的价格计算
1 parent 8320c506
......@@ -116,7 +116,7 @@ export default {
frontWindow: true,
rearGear: true,
rearWindow: true,
sunRoof: true
sunRoof: true,
},
}
},
......@@ -346,14 +346,19 @@ export default {
// 计算所有产品的总价
changeTotalPrice() {
let total = 0
// 遍历所有产品槽位
Object.keys(this.productSlots).forEach(slotName => {
// 遍历所有商品
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
productFields.forEach(slotName => {
const productList = this.orderObj[slotName]
if (Array.isArray(productList) && productList.length > 0) {
// 计算每个产品的价格 * 数量,并累加到总价
productList.forEach(item => {
if (item.goods && item.goods.sellPrice && item.goods.number) {
total += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number)
} else if (item.packageGoods && item.packageGoods.upgradePrice && item.packageGoods.number) {
total += parseFloat(item.packageGoods.upgradePrice) * parseInt(item.packageGoods.number)
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice && item.multipleSpecificationsGoods.number) {
total += parseFloat(item.multipleSpecificationsGoods.goods.sellPrice) * parseInt(item.multipleSpecificationsGoods.number)
}
})
}
......
......@@ -4,7 +4,7 @@
<view class="package-item" v-for="(item, index) in list" :key="index">
<view class="header">
<view class="header-left">
<view class="sprite-icon icon-blue-delete"></view>
<view class="sprite-icon icon-blue-delete" @click="deleteGoods(index)"></view>
<view class="name">{{item.packageGoods.packageAlias||item.packageGoods.packageName}}</view>
<view class="control">
<view class="minus" @click="decreaseNumber(item)">-</view>
......@@ -135,6 +135,11 @@ export default {
this.$set(this.list[index].packageGoods.goodsList[ind], 'sellPrice', value)
this.$emit('changeTotalPrice')
},
// 删除商品
deleteGoods(index) {
this.list.splice(index, 1)
this.$emit('changeTotalPrice')
}
}
}
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!