Commit df03b5e1 by cen

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

- 修改 env.js 中的 IP 地址以适应新的开发环境
- 在 ConfirmOrder 组件中根据订单类型动态计算价格,确保使用正确的 finalPrice 或 totalPrice
- 更新 CreateOrder 组件以优先使用商品级别的订单类型进行策略配置
- 优化 OrderManagement 组件中的价格计算逻辑,确保一致性
- 在多个组件中添加对 discountType 和 discountValue 的处理,避免重复初始化策略配置
1 parent 7f8426e2
......@@ -39,7 +39,7 @@ const secretKey = {
const domain = {
// ip: 'http://192.168.2.94:8558',
// 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:8558 */
dev: 'https://scrm.dev.glsx.com.cn',
......
......@@ -287,7 +287,33 @@ export default {
for (var i = 0; i < data?.subOrderList?.length; i++) {
let e = data?.subOrderList[i]
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 || ''
if (e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) {
warrantyCardList.push({
......@@ -297,12 +323,46 @@ export default {
}
}
data.packageGoodsList?.forEach(item => {
// 获取订单类型(优先使用套餐内商品的订单类型,否则使用订单级别的)
const orderType = item.packageGoodsOrderList?.[0]?.djOrderType || data.djOrderType
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.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)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count
......
......@@ -416,15 +416,15 @@ export default {
e.packageGoodsList?.forEach(item => {
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.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number)
return prev + Number(cur.finalPrice) / Number(cur.number)
}, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count
item.totalPrice = utils.decimal(total, 2)
item.finalPrice = utils.decimal(total, 2)
})
if (e.packageGoodsList && e.packageGoodsList.length) {
e.subOrderList = e.subOrderList.concat(e.packageGoodsList)
......
......@@ -374,6 +374,12 @@ export default {
this.list.forEach(item => {
if (!item.packageGoods || !item.packageGoods.goodsList) return
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 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') {
this.$set(goods, 'strategyConfig', {
......
......@@ -202,6 +202,12 @@ export default {
this.list.forEach(item => {
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 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') {
this.$set(item.goods, 'strategyConfig', {
......
......@@ -118,12 +118,14 @@ export default {
this.list.forEach(item => {
if (!item.multipleSpecificationsGoods) {
// 如果没有多规格商品,直接设置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')
}
} else if (item.multipleSpecificationsGoods) {
// 如果有多规格商品,给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')
}
}
......@@ -450,6 +452,13 @@ export default {
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 是否存在,都根据新的策略类型重新初始化
if (strategyType === 'discount') {
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!