Commit 07b64f2f by 胡悦

feat(订单创建): 改进商品选择和价格计算逻辑

- 在Package组件中添加价格计算方法并初始化商品数量
- 在CreateOrder组件中优化商品选择逻辑和总价计算
- 添加商品最低价提示和空商品校验
- 调整弹窗按钮配置,增加继续编辑选项
1 parent 89fccaad
...@@ -349,7 +349,7 @@ ...@@ -349,7 +349,7 @@
background-position: calc(100vmin * (1173 / 768) * -0.18414322250639387) calc(100vmin * (1173 / 768) * -0.6321398124467178);} background-position: calc(100vmin * (1173 / 768) * -0.18414322250639387) calc(100vmin * (1173 / 768) * -0.6321398124467178);}
.icon-zj-icon { width: calc(100vmin * (1173 / 768) * 0.013640238704177323); height: calc(100vmin * (1173 / 768) * 0.013640238704177323); .icon-zj-icon { width: calc(100vmin * (1173 / 768) * 0.013640238704177323); height: calc(100vmin * (1173 / 768) * 0.013640238704177323);
background-position: calc(100vmin * (1173 / 768) * -0.24040920716112532) calc(100vmin * (1173 / 768) * -0.6572890025575447);} background-position: calc(100vmin * (1173 / 768) * -0.24040920716112532) calc(100vmin * (1173 / 768) * -0.6572890025575447);}
.icon-topTipsRightIcon { width: calc(100vmin * (1173 / 768) * 0.06990622335890878); height: calc(100vmin * (1173 / 768) * 0.05115089514066496);
background-position: calc(100vmin * (1173 / 768) * -0.2855924978687127) calc(100vmin * (1173 / 768) * -0.20758738277919864);}
.icon-filter { width: calc(100vmin * (1173 / 768) * 0.0068201193520886615); height: calc(100vmin * (1173 / 768) * 0.0068201193520886615); .icon-filter { width: calc(100vmin * (1173 / 768) * 0.0068201193520886615); height: calc(100vmin * (1173 / 768) * 0.0068201193520886615);
background-position: calc(100vmin * (1173 / 768) * -0.639386189258312) calc(100vmin * (1173 / 768) * -0.12766410912190965);}
\ No newline at end of file \ No newline at end of file
background-position: calc(100vmin * (1173 / 768) * -0.639386189258312) calc(100vmin * (1173 / 768) * -0.12766410912190965);}
.icon-topTipsRightIcon { width: calc(100vmin * (1173 / 768) * 0.06990622335890878); height: calc(100vmin * (1173 / 768) * 0.05115089514066496);
background-position: calc(100vmin * (1173 / 768) * -0.2855924978687127) calc(100vmin * (1173 / 768) * -0.20758738277919864);}
\ No newline at end of file \ No newline at end of file
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
</Product> </Product>
</template> </template>
<template slot="package"> <template slot="package">
<Package v-if="orderObj.package" :list="orderObj.package" :positionTypeList="positionTypeList"></Package> <Package v-if="orderObj.package" @changeTotalPrice="changeTotalPrice" :list="orderObj.package" :positionTypeList="positionTypeList"></Package>
</template> </template>
<template slot="skuGoods"> <template slot="skuGoods">
<SkuGoods v-if="orderObj.skuGoods" :list="orderObj.skuGoods" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData"></SkuGoods> <SkuGoods v-if="orderObj.skuGoods" :list="orderObj.skuGoods" @changeTotalPrice="changeTotalPrice" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData"></SkuGoods>
<view class="total" v-if="totalPrice > 0"> <view class="total" v-if="totalPrice > 0">
<view class="total-left">总价</view> <view class="total-left">总价</view>
<view class="total-right">¥{{totalPrice}}</view> <view class="total-right">¥{{totalPrice}}</view>
...@@ -211,12 +211,26 @@ export default { ...@@ -211,12 +211,26 @@ export default {
}) })
this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode) this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode)
} else if (productFields.includes(_typeValue.key)) { } else if (productFields.includes(_typeValue.key)) {
if (_typeValue.key == 'skuGoods') {
if (!this.orderObj[_typeValue.key]) {
this.$set(this.orderObj, _typeValue.key, chooseContent)
} else {
// 过滤出已选的goodFlag为2的对象
const selectedGoods = this.orderObj[_typeValue.key].filter(item => item.goodsFlag === 2)
const singleGoods = chooseContent.filter(item => item.goodsFlag === 1)
const moreGoods = chooseContent.filter(item => item.goodsFlag === 2).filter(item => {
return !selectedGoods.some(selectedItem => selectedItem.multipleSpecificationsGoods.id === item.multipleSpecificationsGoods.id)
})
// 合并已选的goodFlag为2的对象
this.orderObj[_typeValue.key] = [...singleGoods, ...moreGoods, ...selectedGoods]
}
} else {
this.$set(this.orderObj, _typeValue.key, chooseContent)
}
// 商品类,需计算总价 // 商品类,需计算总价
this.$set(this.orderObj, _typeValue.key, val.chooseContent) setTimeout(() => {
this.$nextTick(() => {
// 确保数据更新后再计算总价
this.changeTotalPrice() this.changeTotalPrice()
}) }, 0)
} else if (_typeValue.key) { } else if (_typeValue.key) {
this.orderObj[_typeValue.targetIdKey] = chooseContent[_typeValue.sourceIdKey] this.orderObj[_typeValue.targetIdKey] = chooseContent[_typeValue.sourceIdKey]
this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey]) this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey])
...@@ -276,7 +290,7 @@ export default { ...@@ -276,7 +290,7 @@ export default {
// 处理onlyLabel为true的特殊校验 // 处理onlyLabel为true的特殊校验
if (onlyLabelItem.length > 0) { if (onlyLabelItem.length > 0) {
// 检查frontGear、frontWindow、rearGear、rearWindow、sunRoof和couponInfo字段中是否至少有一个不为空 // 检查frontGear、frontWindow、rearGear、rearWindow、sunRoof和couponInfo字段中是否至少有一个不为空
const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof'] const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
const hasValue = labelFields.some(field => { const hasValue = labelFields.some(field => {
console.log(field, this.orderObj[field]) console.log(field, this.orderObj[field])
const value = this.orderObj[field] const value = this.orderObj[field]
...@@ -285,7 +299,7 @@ export default { ...@@ -285,7 +299,7 @@ export default {
console.log(hasValue, hasValue) console.log(hasValue, hasValue)
if (!hasValue) { if (!hasValue) {
uni.showToast({ uni.showToast({
title: '请至少选择一个产品', title: '商品不能为空',
icon: 'none' icon: 'none'
}) })
return false return false
...@@ -313,8 +327,9 @@ export default { ...@@ -313,8 +327,9 @@ export default {
}, {}) }, {})
} }
// 将 frontGear、frontWindow、rearGear、rearWindow、sunRoof 字段合并到 goodsList 中 // 将 frontGear、frontWindow、rearGear、rearWindow、sunRoof 字段合并到 goodsList 中
const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof'] const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
let goodsList = [] let goodsList = []
let subGoodsList = []
labelFields.forEach(field => { labelFields.forEach(field => {
if (Array.isArray(obj[field]) && obj[field].length > 0) { if (Array.isArray(obj[field]) && obj[field].length > 0) {
goodsList = goodsList.concat(obj[field]); goodsList = goodsList.concat(obj[field]);
...@@ -322,13 +337,18 @@ export default { ...@@ -322,13 +337,18 @@ export default {
delete obj[field]; delete obj[field];
}); });
if (goodsList.length > 0) { if (goodsList.length > 0) {
obj.subOrderList = goodsList.map(item => { goodsList.map(e => {
return { if (e.goodsFlag == 1) {
totalPrice: item.goods.sellPrice, // 单商品
number: item.goods.number,
merchantGoodsId: item.goods.merchantGoodsId
} }
}) })
// obj.subOrderList = goodsList.map(item => {
// return {
// totalPrice: item.goods.sellPrice,
// number: item.goods.number,
// merchantGoodsId: item.goods.merchantGoodsId
// }
// })
} }
delete obj.carBrand delete obj.carBrand
delete obj.couponInfo delete obj.couponInfo
...@@ -357,6 +377,9 @@ export default { ...@@ -357,6 +377,9 @@ export default {
total += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number) total += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number)
} else if (item.packageGoods && item.packageGoods.upgradePrice && item.packageGoods.number) { } else if (item.packageGoods && item.packageGoods.upgradePrice && item.packageGoods.number) {
total += parseFloat(item.packageGoods.upgradePrice) * parseInt(item.packageGoods.number) total += parseFloat(item.packageGoods.upgradePrice) * parseInt(item.packageGoods.number)
// item.packageGoods.goodsList.forEach(i => {
// total += parseFloat(i.sellPrice) * parseInt(item.packageGoods.number)
// })
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice && item.multipleSpecificationsGoods.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) total += parseFloat(item.multipleSpecificationsGoods.goods.sellPrice) * parseInt(item.multipleSpecificationsGoods.number)
} }
......
...@@ -61,18 +61,6 @@ export default { ...@@ -61,18 +61,6 @@ export default {
buttonsList: [] buttonsList: []
} }
}, },
computed: {
// 根据类型返回对应的图标
iconSrc() {
const iconMap = {
success: 'https://img01.glsx.com.cn/weapp/resource/app-tape/media/common/icon-success.png',
error: 'https://img01.glsx.com.cn/weapp/resource/app-tape/media/common/icon-error.png',
warning: '@/assets/images/common/warning-notice.png',
info: 'https://img01.glsx.com.cn/weapp/resource/app-tape/media/common/icon-info.png'
}
return iconMap[this.type] || iconMap.info
}
},
methods: { methods: {
open() { open() {
this.$refs.popup.open("center"); this.$refs.popup.open("center");
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<view class="add" @click="increaseNumber(item)">+</view> <view class="add" @click="increaseNumber(item)">+</view>
</view> </view>
</view> </view>
<view class="price">¥{{item.packageGoods.upgradePrice}}</view> <view class="price">¥{{changeTotal(item)}}</view>
</view> </view>
<view class="goods-item" v-for="(goods, ind) in item.packageGoods.goodsList" :key="ind"> <view class="goods-item" v-for="(goods, ind) in item.packageGoods.goodsList" :key="ind">
<view class="goods-name">{{goods.goodsAlias || goods.upgradeGoodsName}}</view> <view class="goods-name">{{goods.goodsAlias || goods.upgradeGoodsName}}</view>
...@@ -47,13 +47,27 @@ export default { ...@@ -47,13 +47,27 @@ export default {
}, },
created() { created() {
// 初始化商品数量 // 初始化商品数量
this.list.forEach(item => { this.initProductNumbers()
if (!item.packageGoods.number) { },
this.$set(item.packageGoods, 'number', '1') mounted() {
} // 确保每次使用组件时都检查并设置number属性
}) this.initProductNumbers()
},
updated() {
// 当组件数据更新时也检查number属性
this.initProductNumbers()
}, },
methods: { methods: {
// 初始化商品数量方法
initProductNumbers() {
if (this.list && this.list.length > 0) {
this.list.forEach(item => {
if (!item.packageGoods.number) {
this.$set(item.packageGoods, 'number', '1')
}
})
}
},
// 格式化位置信息 // 格式化位置信息
formatPosition(item, positionTypeList) { formatPosition(item, positionTypeList) {
const filterData = positionTypeList.filter(v => v.positionValue == item) const filterData = positionTypeList.filter(v => v.positionValue == item)
...@@ -129,6 +143,10 @@ export default { ...@@ -129,6 +143,10 @@ export default {
// 如果validMinSellPrice为Y,则强制修改值为最小值 // 如果validMinSellPrice为Y,则强制修改值为最小值
if (goods.validMinSellPrice === 'Y' && goods.minSellPrice && parseFloat(value) < parseFloat(goods.minSellPrice)) { if (goods.validMinSellPrice === 'Y' && goods.minSellPrice && parseFloat(value) < parseFloat(goods.minSellPrice)) {
console.log('最小值', goods.minSellPrice) console.log('最小值', goods.minSellPrice)
uni.showToast({
title: '单价不可低于商品最低价',
icon: 'none'
})
value = goods.minSellPrice.toString() value = goods.minSellPrice.toString()
} }
// 更新值 // 更新值
...@@ -139,6 +157,15 @@ export default { ...@@ -139,6 +157,15 @@ export default {
deleteGoods(index) { deleteGoods(index) {
this.list.splice(index, 1) this.list.splice(index, 1)
this.$emit('changeTotalPrice') this.$emit('changeTotalPrice')
},
// 计算套餐的总价
changeTotal(item) {
let total = 0
item.packageGoods.goodsList.forEach(i => {
total += parseFloat(i.sellPrice) * parseInt(item.packageGoods.number)
})
item.packageGoods.upgradePrice = total
return total
} }
} }
} }
......
...@@ -79,17 +79,23 @@ export default { ...@@ -79,17 +79,23 @@ export default {
// 配置弹窗按钮 // 配置弹窗按钮
this.$refs.notice.buttonsList = [ this.$refs.notice.buttonsList = [
{ {
text: '确认退出', text: '确认退出',
type: 'default', type: 'default',
callback: () => { callback: () => {
// 点击确认后才切换组件 // 点击确认后才切换组件
this.toolComponentName = selectedItem.name this.toolComponentName = selectedItem.name
if (selectedItem.name !== 'CreateOrder') { if (selectedItem.name !== 'CreateOrder') {
this.transmissionOfData = null this.transmissionOfData = null
}
} }
this.$refs.notice.close()
} }
] }, {
text: '继续编辑',
type: 'primary',
callback: () => {
this.$refs.notice.close()
}
}]
// 打开弹窗 // 打开弹窗
this.$refs.notice.open() this.$refs.notice.open()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!