Commit df03b5e1 by cen

fix: 更新订单组件以支持新价格逻辑和回显数据

- 修改 env.js 中的 IP 地址以适应新的开发环境
- 在 ConfirmOrder 组件中根据订单类型动态计算价格,确保使用正确的 finalPrice 或 totalPrice
- 更新 CreateOrder 组件以优先使用商品级别的订单类型进行策略配置
- 优化 OrderManagement 组件中的价格计算逻辑,确保一致性
- 在多个组件中添加对 discountType 和 discountValue 的处理,避免重复初始化策略配置
1 parent 7f8426e2
...@@ -39,7 +39,7 @@ const secretKey = { ...@@ -39,7 +39,7 @@ const secretKey = {
const domain = { const domain = {
// ip: 'http://192.168.2.94:8558', // ip: 'http://192.168.2.94:8558',
// ip: 'http://192.168.2.3:8315', // ip: 'http://192.168.2.3:8315',
ip: 'http://192.168.1.170:8315', ip: 'http://192.168.1.122:8292',
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: 'https://scrm.dev.glsx.com.cn',
......
...@@ -287,7 +287,33 @@ export default { ...@@ -287,7 +287,33 @@ export default {
for (var i = 0; i < data?.subOrderList?.length; i++) { for (var i = 0; i < data?.subOrderList?.length; i++) {
let e = data?.subOrderList[i] let e = data?.subOrderList[i]
total_price += e.finalPrice total_price += e.finalPrice
e.price = Number(utils.decimal(Number(e.finalPrice / e.number), 2)).toFixed(2) // 根据订单类型决定使用哪个价格:
// - 正常订单(1)和冲量活动(4):使用 totalPrice(原价)
// - 打折策略(2)、买赠策略(3)、组合付款(5):使用 finalPrice(优惠后价格)
const orderType = e.djOrderType || data.djOrderType
if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价
if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} else if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
}
} else {
// 优惠类型订单,使用优惠后价格
if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} else if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
}
}
e.positionStr = this.positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || '' e.positionStr = this.positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || ''
if (e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) { if (e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) {
warrantyCardList.push({ warrantyCardList.push({
...@@ -297,12 +323,46 @@ export default { ...@@ -297,12 +323,46 @@ export default {
} }
} }
data.packageGoodsList?.forEach(item => { data.packageGoodsList?.forEach(item => {
// 获取订单类型(优先使用套餐内商品的订单类型,否则使用订单级别的)
const orderType = item.packageGoodsOrderList?.[0]?.djOrderType || data.djOrderType
item.packageGoodsOrderList.forEach(g => { item.packageGoodsOrderList.forEach(g => {
g.price = g.finalPrice ? Number(g.finalPrice) / Number(g.number) : g.upgradePrice // 根据订单类型决定使用哪个价格
if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价
if (g.totalPrice !== undefined && g.totalPrice !== null) {
g.price = Number(g.totalPrice) / Number(g.number || 1)
} else if (g.finalPrice !== undefined && g.finalPrice !== null) {
g.price = Number(g.finalPrice) / Number(g.number || 1)
} else {
g.price = g.upgradePrice || 0
}
} else {
// 优惠类型订单,使用优惠后价格
if (g.finalPrice !== undefined && g.finalPrice !== null) {
g.price = Number(g.finalPrice) / Number(g.number || 1)
} else if (g.totalPrice !== undefined && g.totalPrice !== null) {
g.price = Number(g.totalPrice) / Number(g.number || 1)
} else {
g.price = g.upgradePrice || 0
}
}
}) })
item.goodsList = item.packageGoodsOrderList item.goodsList = item.packageGoodsOrderList
// 套餐价格根据订单类型计算
item.price = item.goodsList.reduce((prev, cur) => { item.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.finalPrice) / Number(cur.number) // 根据订单类型决定使用哪个价格
const unitPrice = (orderType === 1 || orderType === 4)
? (cur.totalPrice !== undefined && cur.totalPrice !== null
? Number(cur.totalPrice) / Number(cur.number || 1)
: (cur.finalPrice !== undefined && cur.finalPrice !== null
? Number(cur.finalPrice) / Number(cur.number || 1)
: cur.price || 0))
: (cur.finalPrice !== undefined && cur.finalPrice !== null
? Number(cur.finalPrice) / Number(cur.number || 1)
: (cur.totalPrice !== undefined && cur.totalPrice !== null
? Number(cur.totalPrice) / Number(cur.number || 1)
: cur.price || 0))
return prev + unitPrice
}, 0) }, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1 item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count let total = item.price * item.count
......
...@@ -328,41 +328,72 @@ export default { ...@@ -328,41 +328,72 @@ export default {
buildStrategyConfigFromDiscountFields(item, orderTypeCode) { buildStrategyConfigFromDiscountFields(item, orderTypeCode) {
const strategyConfig = {} const strategyConfig = {}
const orderType = String(orderTypeCode || '') const orderType = String(orderTypeCode || '')
// 确保 discountType 是数字类型进行比较
const discountType = item.discountType !== undefined && item.discountType !== null ? Number(item.discountType) : null
// '2' 打折策略 // '2' 打折策略
if (orderType === '2') { if (orderType === '2') {
if (item.discountType === 1 && item.discountValue) { if (discountType === 1) {
// 比例折扣 // 比例折扣
strategyConfig.mode = 'ratio' strategyConfig.mode = 'ratio'
strategyConfig.discountRatio = parseFloat(item.discountValue) // 确保 discountValue 存在且有效
} else if (item.discountType === 2 && item.discountValue) { const discountValue = item.discountValue !== undefined && item.discountValue !== null && item.discountValue !== ''
? parseFloat(item.discountValue)
: null
if (discountValue !== null && !isNaN(discountValue)) {
strategyConfig.discountRatio = discountValue
} else {
// 如果 discountValue 无效,但 discountType 是 1,仍然设置为 ratio 模式,但 discountRatio 为空
strategyConfig.discountRatio = ''
}
} else if (discountType === 2) {
// 折扣金额 // 折扣金额
strategyConfig.mode = 'amount' strategyConfig.mode = 'amount'
strategyConfig.discountAmount = parseFloat(item.discountValue) // 确保 discountValue 存在且有效
const discountValue = item.discountValue !== undefined && item.discountValue !== null && item.discountValue !== ''
? parseFloat(item.discountValue)
: null
if (discountValue !== null && !isNaN(discountValue)) {
strategyConfig.discountAmount = discountValue
} else { } else {
// 无折扣 // 如果 discountValue 无效,但 discountType 是 2,仍然设置为 amount 模式,但 discountAmount 为空
strategyConfig.discountAmount = ''
}
} else {
// 无折扣(discountType === 3 或其他)
strategyConfig.mode = 'none' strategyConfig.mode = 'none'
strategyConfig.discountRatio = ''
strategyConfig.discountAmount = ''
} }
} }
// '3' 买赠策略 // '3' 买赠策略
else if (orderType === '3') { else if (orderType === '3') {
if (item.discountType === 4) { if (discountType === 4) {
// 赠品 // 赠品
strategyConfig.isGift = '1' strategyConfig.isGift = '1'
} else { } else {
// 非赠品 // 非赠品(discountType === 5 或其他)
strategyConfig.isGift = '0' strategyConfig.isGift = '0'
} }
} }
// '5' 组合付款 // '5' 组合付款
else if (orderType === '5') { else if (orderType === '5') {
if (item.discountType === 2 && item.discountValue) { if (discountType === 2) {
// 抵扣金额 // 抵扣金额
strategyConfig.mode = 'deduct' strategyConfig.mode = 'deduct'
strategyConfig.deductAmount = parseFloat(item.discountValue) // 确保 discountValue 存在且有效
const discountValue = item.discountValue !== undefined && item.discountValue !== null && item.discountValue !== ''
? parseFloat(item.discountValue)
: null
if (discountValue !== null && !isNaN(discountValue)) {
strategyConfig.deductAmount = discountValue
} else { } else {
// 无抵扣 strategyConfig.deductAmount = ''
}
} else {
// 无抵扣(discountType === 3 或其他)
strategyConfig.mode = 'none' strategyConfig.mode = 'none'
strategyConfig.deductAmount = ''
} }
} }
...@@ -1248,9 +1279,13 @@ export default { ...@@ -1248,9 +1279,13 @@ export default {
if (e && !e.packageName) { if (e && !e.packageName) {
if (e.specificationData.indexOf(';~;') == -1) { if (e.specificationData.indexOf(';~;') == -1) {
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
if (!e.price) { // 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格
// 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算
if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = utils.decimal(Number(e.totalPrice / e.number), 2) e.price = utils.decimal(Number(e.totalPrice / e.number), 2)
//最低价 } else if (!e.price) {
// 如果没有 totalPrice,才使用已存在的 price 或计算默认值
e.price = utils.decimal(Number((e.finalPrice || 0) / e.number), 2)
} }
e.sellPrice = e.price e.sellPrice = e.price
e.goodsId = e.merchantGoodsId e.goodsId = e.merchantGoodsId
...@@ -1259,13 +1294,25 @@ export default { ...@@ -1259,13 +1294,25 @@ export default {
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName
} }
e.merchantGoodsId = e.merchantGoodsId || e.id e.merchantGoodsId = e.merchantGoodsId || e.id
// 确保 number 字段存在且正确(用于回显)
if (e.number !== undefined && e.number !== null) {
e.number = String(e.number)
} else {
e.number = '1'
}
// 回显 finalPrice 和 strategyConfig // 回显 finalPrice 和 strategyConfig
if (e.finalPrice !== undefined && e.finalPrice !== null) { if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.finalPrice = parseFloat(e.finalPrice) e.finalPrice = parseFloat(e.finalPrice)
} }
if (this.orderObj.orderTypeCode && (e.discountType !== undefined || e.djOrderType)) { // 优先使用商品级别的 djOrderType,否则使用订单级别的 orderTypeCode
e.strategyConfig = this.buildStrategyConfigFromDiscountFields(e, this.orderObj.orderTypeCode || e.djOrderType) const goodsOrderTypeCode = e.djOrderType ? String(e.djOrderType) : this.orderObj.orderTypeCode
// 始终根据 discountType 和 discountValue 重新构建 strategyConfig,忽略后端可能错误的 strategyConfig
if (goodsOrderTypeCode && e.discountType !== undefined && e.discountType !== null) {
// 删除后端可能错误的 strategyConfig,重新构建
delete e.strategyConfig
const newStrategyConfig = this.buildStrategyConfigFromDiscountFields(e, goodsOrderTypeCode)
this.$set(e, 'strategyConfig', newStrategyConfig)
} }
chooseList.push({ chooseList.push({
...@@ -1278,25 +1325,39 @@ export default { ...@@ -1278,25 +1325,39 @@ export default {
// 多规格商品 // 多规格商品
if (e.specificationData.indexOf(';~;') > -1) { if (e.specificationData.indexOf(';~;') > -1) {
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
if (!e.price) { // 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格
// 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算
if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = utils.decimal(Number(e.totalPrice / e.number), 2) e.price = utils.decimal(Number(e.totalPrice / e.number), 2)
//最低价 } else if (!e.price) {
e.sellPrice = e.price // 如果没有 totalPrice,才使用已存在的 price 或计算默认值
e.price = utils.decimal(Number((e.finalPrice || 0) / e.number), 2)
} }
e.sellPrice = e.price
e.goodsId = e.merchantGoodsId e.goodsId = e.merchantGoodsId
if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice
e.goodsInfo = { e.goodsInfo = {
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName
} }
// 确保数量字段正确回显(多规格商品使用 count 字段)
if (e.number !== undefined && e.number !== null) {
e.count = e.number e.count = e.number
} else {
e.count = 1
}
e.merchantGoodsId = e.merchantGoodsId || e.id e.merchantGoodsId = e.merchantGoodsId || e.id
// 回显 finalPrice 和 strategyConfig(多规格商品需要传递给 handleSpecificationsEcho) // 回显 finalPrice 和 strategyConfig(多规格商品需要传递给 handleSpecificationsEcho)
if (e.finalPrice !== undefined && e.finalPrice !== null) { if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.finalPrice = parseFloat(e.finalPrice) e.finalPrice = parseFloat(e.finalPrice)
} }
if (this.orderObj.orderTypeCode && (e.discountType !== undefined || e.djOrderType)) { // 优先使用商品级别的 djOrderType,否则使用订单级别的 orderTypeCode
e.strategyConfig = this.buildStrategyConfigFromDiscountFields(e, this.orderObj.orderTypeCode || e.djOrderType) const goodsOrderTypeCode = e.djOrderType ? String(e.djOrderType) : this.orderObj.orderTypeCode
if (goodsOrderTypeCode && e.discountType !== undefined && e.discountType !== null) {
// 删除后端可能错误的 strategyConfig,重新构建
delete e.strategyConfig
const newStrategyConfig = this.buildStrategyConfigFromDiscountFields(e, goodsOrderTypeCode)
this.$set(e, 'strategyConfig', newStrategyConfig)
} }
let specificdata = this.handleSpecificationsEcho(e) let specificdata = this.handleSpecificationsEcho(e)
...@@ -1316,8 +1377,13 @@ export default { ...@@ -1316,8 +1377,13 @@ export default {
if (g.finalPrice !== undefined && g.finalPrice !== null) { if (g.finalPrice !== undefined && g.finalPrice !== null) {
g.finalPrice = parseFloat(g.finalPrice) g.finalPrice = parseFloat(g.finalPrice)
} }
if (this.orderObj.orderTypeCode && (g.discountType !== undefined || g.djOrderType)) { // 优先使用商品级别的 djOrderType,否则使用订单级别的 orderTypeCode
g.strategyConfig = this.buildStrategyConfigFromDiscountFields(g, this.orderObj.orderTypeCode || g.djOrderType) const goodsOrderTypeCode = g.djOrderType ? String(g.djOrderType) : this.orderObj.orderTypeCode
if (goodsOrderTypeCode && g.discountType !== undefined && g.discountType !== null) {
// 删除后端可能错误的 strategyConfig,重新构建
delete g.strategyConfig
const newStrategyConfig = this.buildStrategyConfigFromDiscountFields(g, goodsOrderTypeCode)
this.$set(g, 'strategyConfig', newStrategyConfig)
} }
}) })
e.goodsList = e.packageGoodsOrderList e.goodsList = e.packageGoodsOrderList
...@@ -1361,12 +1427,12 @@ export default { ...@@ -1361,12 +1427,12 @@ export default {
this.$set( this.$set(
this.orderObj, this.orderObj,
'rearWindow', 'rearWindow',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 3) _singleGoods.filter(item => item.goods.upgradeGoodsPosition == 4)
) )
this.$set( this.$set(
this.orderObj, this.orderObj,
'rearGear', 'rearGear',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 4) _singleGoods.filter(item => item.goods.upgradeGoodsPosition == 3)
) )
this.$set( this.$set(
this.orderObj, this.orderObj,
...@@ -1408,24 +1474,47 @@ export default { ...@@ -1408,24 +1474,47 @@ export default {
tempData.forEach(temp => { tempData.forEach(temp => {
if (temp.merchantGoodsId == item.goodsId) { if (temp.merchantGoodsId == item.goodsId) {
// 回显 finalPrice 和 strategyConfig(多规格商品) // 回显 finalPrice 和 strategyConfig(多规格商品)
// 确保使用原价(totalPrice),而不是可能被设置为优惠后的 item.price
let goodsPrice = item.price
if (item.totalPrice !== undefined && item.totalPrice !== null) {
// 优先使用 totalPrice(原价)计算单价
goodsPrice = utils.decimal(Number(item.totalPrice / item.number), 2)
} else if (!item.price && item.finalPrice !== undefined && item.finalPrice !== null) {
// 如果没有 totalPrice 和 price,才使用 finalPrice
goodsPrice = utils.decimal(Number(item.finalPrice / item.number), 2)
}
const goodsData = { const goodsData = {
...temp, ...temp,
price: item.price, price: goodsPrice,
sellPrice: item.price, sellPrice: goodsPrice,
goodsId: item.goodsId, goodsId: item.goodsId,
specificationStr: item.specificationData.replace(/;~;/g, '/') specificationStr: item.specificationData.replace(/;~;/g, '/')
} }
if (item.finalPrice !== undefined && item.finalPrice !== null) { if (item.finalPrice !== undefined && item.finalPrice !== null) {
goodsData.finalPrice = parseFloat(item.finalPrice) goodsData.finalPrice = parseFloat(item.finalPrice)
} }
if (this.orderObj.orderTypeCode && (item.discountType !== undefined || item.djOrderType)) { // 确保 discountType 和 discountValue 也传递到 goodsData 中,以便 initStrategyConfig 能正确识别回显数据
goodsData.strategyConfig = this.buildStrategyConfigFromDiscountFields(item, this.orderObj.orderTypeCode || item.djOrderType) if (item.discountType !== undefined && item.discountType !== null) {
goodsData.discountType = item.discountType
}
if (item.discountValue !== undefined && item.discountValue !== null) {
goodsData.discountValue = item.discountValue
}
// 优先使用商品级别的 djOrderType,否则使用订单级别的 orderTypeCode
const goodsOrderTypeCode = item.djOrderType ? String(item.djOrderType) : this.orderObj.orderTypeCode
if (goodsOrderTypeCode && item.discountType !== undefined && item.discountType !== null) {
// 删除后端可能错误的 strategyConfig,重新构建
delete goodsData.strategyConfig
const newStrategyConfig = this.buildStrategyConfigFromDiscountFields(item, goodsOrderTypeCode)
goodsData.strategyConfig = newStrategyConfig
} }
obj.multipleSpecificationsGoods = { obj.multipleSpecificationsGoods = {
...data.multipleSpecificationsGoods, ...data.multipleSpecificationsGoods,
baseGoodsName: item.goodsName || item.upgradeGoodsName, baseGoodsName: item.goodsName || item.upgradeGoodsName,
goods: goodsData goods: goodsData,
// 确保数量字段正确回显
number: item.count !== undefined && item.count !== null ? String(item.count) : '1'
} }
skuArr.push(obj) skuArr.push(obj)
} }
......
...@@ -416,15 +416,15 @@ export default { ...@@ -416,15 +416,15 @@ export default {
e.packageGoodsList?.forEach(item => { e.packageGoodsList?.forEach(item => {
item.packageGoodsOrderList.forEach(g => { item.packageGoodsOrderList.forEach(g => {
g.price = g.totalPrice ? Number(g.totalPrice) / Number(g.number) : g.upgradePrice g.price = g.finalPrice ? Number(g.finalPrice) / Number(g.number) : g.upgradePrice
}) })
item.goodsList = item.packageGoodsOrderList item.goodsList = item.packageGoodsOrderList
item.price = item.goodsList.reduce((prev, cur) => { item.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number) return prev + Number(cur.finalPrice) / Number(cur.number)
}, 0) }, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1 item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count let total = item.price * item.count
item.totalPrice = utils.decimal(total, 2) item.finalPrice = utils.decimal(total, 2)
}) })
if (e.packageGoodsList && e.packageGoodsList.length) { if (e.packageGoodsList && e.packageGoodsList.length) {
e.subOrderList = e.subOrderList.concat(e.packageGoodsList) e.subOrderList = e.subOrderList.concat(e.packageGoodsList)
......
...@@ -374,6 +374,12 @@ export default { ...@@ -374,6 +374,12 @@ export default {
this.list.forEach(item => { this.list.forEach(item => {
if (!item.packageGoods || !item.packageGoods.goodsList) return if (!item.packageGoods || !item.packageGoods.goodsList) return
item.packageGoods.goodsList.forEach(goods => { item.packageGoods.goodsList.forEach(goods => {
// 如果商品已经有 discountType 和 discountValue(回显数据),则跳过初始化
const hasDiscountData = goods.discountType !== undefined && goods.discountType !== null
if (hasDiscountData && goods.strategyConfig && Object.keys(goods.strategyConfig).length > 0) {
// 回显时已经有正确的 strategyConfig,不重置
return
}
// 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') { if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', { this.$set(goods, 'strategyConfig', {
......
...@@ -202,6 +202,12 @@ export default { ...@@ -202,6 +202,12 @@ export default {
this.list.forEach(item => { this.list.forEach(item => {
if (!item.goods) return if (!item.goods) return
// 如果商品已经有 discountType 和 discountValue(回显数据),则跳过初始化
const hasDiscountData = item.goods.discountType !== undefined && item.goods.discountType !== null
if (hasDiscountData && item.goods.strategyConfig && Object.keys(item.goods.strategyConfig).length > 0) {
// 回显时已经有正确的 strategyConfig,不重置
return
}
// 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') { if (strategyType === 'discount') {
this.$set(item.goods, 'strategyConfig', { this.$set(item.goods, 'strategyConfig', {
......
...@@ -118,12 +118,14 @@ export default { ...@@ -118,12 +118,14 @@ export default {
this.list.forEach(item => { this.list.forEach(item => {
if (!item.multipleSpecificationsGoods) { if (!item.multipleSpecificationsGoods) {
// 如果没有多规格商品,直接设置goods的number // 如果没有多规格商品,直接设置goods的number
if (!item.goods.number) { // 只有当 number 字段完全不存在(undefined/null)时才设置默认值,避免覆盖回显的数量
if (item.goods && (item.goods.number === undefined || item.goods.number === null)) {
this.$set(item.goods, 'number', '1') this.$set(item.goods, 'number', '1')
} }
} else if (item.multipleSpecificationsGoods) { } else if (item.multipleSpecificationsGoods) {
// 如果有多规格商品,给multipleSpecificationsGoods中的goods添加number // 如果有多规格商品,给multipleSpecificationsGoods中的goods添加number
if (!item.multipleSpecificationsGoods.number) { // 只有当 number 字段完全不存在(undefined/null)时才设置默认值,避免覆盖回显的数量
if (item.multipleSpecificationsGoods.number === undefined || item.multipleSpecificationsGoods.number === null) {
this.$set(item.multipleSpecificationsGoods, 'number', '1') this.$set(item.multipleSpecificationsGoods, 'number', '1')
} }
} }
...@@ -450,6 +452,13 @@ export default { ...@@ -450,6 +452,13 @@ export default {
if (!goods) return if (!goods) return
// 如果商品已经有 discountType 和 discountValue(回显数据),则跳过初始化
const hasDiscountData = goods.discountType !== undefined && goods.discountType !== null
if (hasDiscountData && goods.strategyConfig && Object.keys(goods.strategyConfig).length > 0) {
// 回显时已经有正确的 strategyConfig,不重置
return
}
// 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化 // 无论 strategyConfig 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') { if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', { this.$set(goods, 'strategyConfig', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!