Commit 4162e2f0 by 岑成威

fix: 更新产品

1 parent bace7c2f
...@@ -81,7 +81,7 @@ import SkuGoods from './SkuGoods.vue' ...@@ -81,7 +81,7 @@ import SkuGoods from './SkuGoods.vue'
import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant' import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant'
import { interceptionMixin } from '@/mixin/index' import { interceptionMixin } from '@/mixin/index'
import { validateVin, formatVinInput } from '@/utils/vinVaildate' import { validateVin, formatVinInput } from '@/utils/vinVaildate'
import { getMarketingFlag, getActivityId, getSubmitMarketingFlag, getSubmitModifyFlag, getSubmitActivityId, snapshotOriginalPrice, snapshotOrderItemsOriginalPrice } from '@/utils/marketingFlag' import { getMarketingFlag, getActivityId, getSubmitMarketingFlag, getSubmitModifyFlag, getSubmitActivityId, snapshotOriginalPrice, snapshotOrderItemsOriginalPrice, snapshotActivityPriceFromCatalog } from '@/utils/marketingFlag'
import { collectBelowMinSellPriceItems, shouldUseMinPriceApproval } from '@/utils/minSellPrice' import { collectBelowMinSellPriceItems, shouldUseMinPriceApproval } from '@/utils/minSellPrice'
import MinPriceApprovalDrawer from './MinPriceApprovalDrawer.vue' import MinPriceApprovalDrawer from './MinPriceApprovalDrawer.vue'
export default { export default {
...@@ -1501,13 +1501,14 @@ export default { ...@@ -1501,13 +1501,14 @@ export default {
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
// 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格 // 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格
// 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算 // 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算
const catalogMatch = this.findCatalogGoodsMatch({ merchantGoodsId: e.merchantGoodsId, goodsId: e.goodsId })
snapshotActivityPriceFromCatalog(e, catalogMatch)
if (e.totalPrice !== undefined && e.totalPrice !== null) { if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)) e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1))
} else if (!e.price) { } else if (!e.price) {
// 如果没有 totalPrice,才使用已存在的 price 或计算默认值 // 如果没有 totalPrice,才使用已存在的 price 或计算默认值
e.price = utils.ceilDecimal(Number(e.finalPrice || 0) / Number(e.number || 1)) e.price = utils.ceilDecimal(Number(e.finalPrice || 0) / Number(e.number || 1))
} }
snapshotOriginalPrice(e)
e.sellPrice = e.price 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
...@@ -1555,13 +1556,14 @@ export default { ...@@ -1555,13 +1556,14 @@ export default {
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
// 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格 // 始终使用 totalPrice(原价)来计算单价,确保编辑时显示的是原价,而不是优惠后的价格
// 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算 // 即使 e.price 已存在(可能被 ConfirmOrder.vue 设置为优惠后的价格),也要重新计算
const catalogMatch = this.findCatalogGoodsMatch({ merchantGoodsId: e.merchantGoodsId, goodsId: e.goodsId })
snapshotActivityPriceFromCatalog(e, catalogMatch)
if (e.totalPrice !== undefined && e.totalPrice !== null) { if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)) e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1))
} else if (!e.price) { } else if (!e.price) {
// 如果没有 totalPrice,才使用已存在的 price 或计算默认值 // 如果没有 totalPrice,才使用已存在的 price 或计算默认值
e.price = utils.ceilDecimal(Number(e.finalPrice || 0) / Number(e.number || 1)) e.price = utils.ceilDecimal(Number(e.finalPrice || 0) / Number(e.number || 1))
} }
snapshotOriginalPrice(e)
e.sellPrice = e.price 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
...@@ -1596,12 +1598,9 @@ export default { ...@@ -1596,12 +1598,9 @@ export default {
} }
// 套餐 // 套餐
if (e && e.packageName) { if (e && e.packageName) {
const catalogMatch = this.findCatalogGoodsMatch({ packageGoods: e })
e.packageGoodsOrderList.forEach(g => { e.packageGoodsOrderList.forEach(g => {
if (g.oldPrice == null || g.oldPrice === '') { snapshotActivityPriceFromCatalog(g, catalogMatch)
g.oldPrice = g.sellPrice ?? g.upgradePrice
}
snapshotOriginalPrice(g)
// g.sellPrice = g.sellPrice || g.upgradePrice;
// 注意:价格为 0 时也要回显,不能用 truthy 判断 // 注意:价格为 0 时也要回显,不能用 truthy 判断
if (g.totalPrice !== undefined && g.totalPrice !== null) { if (g.totalPrice !== undefined && g.totalPrice !== null) {
g.price = utils.ceilDecimal(Number(g.totalPrice) / Number(g.number || 1)).toFixed(2) g.price = utils.ceilDecimal(Number(g.totalPrice) / Number(g.number || 1)).toFixed(2)
...@@ -1734,6 +1733,7 @@ export default { ...@@ -1734,6 +1733,7 @@ export default {
// 如果没有 totalPrice 和 price,才使用 finalPrice // 如果没有 totalPrice 和 price,才使用 finalPrice
goodsPrice = utils.ceilDecimal(Number(item.finalPrice) / Number(item.number || 1)) goodsPrice = utils.ceilDecimal(Number(item.finalPrice) / Number(item.number || 1))
} }
const catalogMatch = this.findCatalogGoodsMatch({ merchantGoodsId: item.goodsId, goodsId: item.goodsId })
const goodsData = { const goodsData = {
...temp, ...temp,
price: goodsPrice, price: goodsPrice,
...@@ -1741,7 +1741,10 @@ export default { ...@@ -1741,7 +1741,10 @@ export default {
goodsId: item.goodsId, goodsId: item.goodsId,
specificationStr: item.specificationData.replace(/;~;/g, '/') specificationStr: item.specificationData.replace(/;~;/g, '/')
} }
snapshotOriginalPrice(goodsData) snapshotActivityPriceFromCatalog(goodsData, catalogMatch)
if ((goodsData.oldPrice == null || goodsData.oldPrice === '') && temp.sellPrice != null && temp.sellPrice !== '') {
goodsData.oldPrice = temp.sellPrice
}
if (item.finalPrice !== undefined && item.finalPrice !== null) { if (item.finalPrice !== undefined && item.finalPrice !== null) {
goodsData.finalPrice = parseFloat(item.finalPrice) goodsData.finalPrice = parseFloat(item.finalPrice)
} }
...@@ -1827,6 +1830,9 @@ export default { ...@@ -1827,6 +1830,9 @@ export default {
return id != null && (id == merchantGoodsId || id == goodsId) return id != null && (id == merchantGoodsId || id == goodsId)
} }
if (item.goodsFlag == 3 && packageGoods) { if (item.goodsFlag == 3 && packageGoods) {
const pkgCode = item.packageGoods?.packageCode
const targetCode = packageGoods.packageCode
if (pkgCode && targetCode && pkgCode === targetCode) return true
const pkgId = item.packageGoods?.merchantGoodsId ?? item.packageGoods?.id ?? item.packageGoods?.packageId const pkgId = item.packageGoods?.merchantGoodsId ?? item.packageGoods?.id ?? item.packageGoods?.packageId
const targetId = packageGoods.merchantGoodsId ?? packageGoods.id ?? packageGoods.packageId const targetId = packageGoods.merchantGoodsId ?? packageGoods.id ?? packageGoods.packageId
return pkgId != null && targetId != null && pkgId == targetId return pkgId != null && targetId != null && pkgId == targetId
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
></view> ></view>
</view> </view>
<view <view
v-if="item.type === 'single' && hasActivityPrice(item.activityPrice)" v-if="item.type === 'single' && shouldShowActivityPrice(item)"
class="min-price" class="min-price"
>活动价 ¥ {{ item.activityPrice }}</view> >活动价 ¥ {{ item.activityPrice }}</view>
</view> </view>
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<view class="child-name">{{ child.name }}</view> <view class="child-name">{{ child.name }}</view>
</view> </view>
<view <view
v-if="hasActivityPrice(child.activityPrice)" v-if="shouldShowActivityPrice(child)"
class="min-price" class="min-price"
>活动价 ¥ {{ child.activityPrice }}</view> >活动价 ¥ {{ child.activityPrice }}</view>
</view> </view>
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</template> </template>
<script> <script>
import { shouldShowMarketingIcon as checkMarketingIcon } from '@/utils/marketingFlag' import { shouldShowMarketingIcon as checkMarketingIcon, isMarketingGoods } from '@/utils/marketingFlag'
export default { export default {
name: 'MinPriceApprovalDrawer', name: 'MinPriceApprovalDrawer',
...@@ -84,8 +84,12 @@ export default { ...@@ -84,8 +84,12 @@ export default {
} }
}, },
methods: { methods: {
hasActivityPrice(value) { shouldShowActivityPrice(item) {
return value != null && value !== '' if (item.activityPrice == null || item.activityPrice === '') return false
if (item.sourceGoods) {
return isMarketingGoods(item.sourceGoods)
}
return isMarketingGoods(item.sourceItem?.goods, item.sourceItem)
}, },
shouldShowMarketingIcon(item) { shouldShowMarketingIcon(item) {
return checkMarketingIcon(item, true) return checkMarketingIcon(item, true)
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<script> <script>
import utils from '@/utils/utils' import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue' import OrderStrategy from './OrderStrategy.vue'
import { shouldShowMarketingIcon as checkMarketingIcon } from '@/utils/marketingFlag' import { shouldShowMarketingIcon as checkMarketingIcon, snapshotOriginalPrice } from '@/utils/marketingFlag'
import { isBelowMinSellPrice, normalizeGoodsPrice, shouldUseMinPriceApproval, applyLegacyMinSellPriceClamp } from '@/utils/minSellPrice' import { isBelowMinSellPrice, normalizeGoodsPrice, shouldUseMinPriceApproval, applyLegacyMinSellPriceClamp } from '@/utils/minSellPrice'
export default { export default {
...@@ -247,6 +247,8 @@ export default { ...@@ -247,6 +247,8 @@ export default {
if (!item.goods.number) { if (!item.goods.number) {
this.$set(item.goods, 'number', '1') this.$set(item.goods, 'number', '1')
} }
// 仅首次快照商品列表 sellPrice,避免改价后写回 oldPrice
snapshotOriginalPrice(item.goods)
}) })
} }
}, },
......
...@@ -50,6 +50,11 @@ export function shouldShowMarketingIcon(item, enabled = false) { ...@@ -50,6 +50,11 @@ export function shouldShowMarketingIcon(item, enabled = false) {
return flag == SHOW_MARKETING_VALUE || flag === String(SHOW_MARKETING_VALUE) return flag == SHOW_MARKETING_VALUE || flag === String(SHOW_MARKETING_VALUE)
} }
export function isMarketingGoods(goods, orderItem) {
const flag = getMarketingFlag(orderItem || { goods }) ?? goods?.marketingFlag
return flag == SHOW_MARKETING_VALUE || flag === String(SHOW_MARKETING_VALUE)
}
export function getActivityId(item) { export function getActivityId(item) {
if (!item) return undefined if (!item) return undefined
if (hasActivityValue(item.activityId)) { if (hasActivityValue(item.activityId)) {
...@@ -83,13 +88,36 @@ export function getSubmitActivityId(orderItem, goods) { ...@@ -83,13 +88,36 @@ export function getSubmitActivityId(orderItem, goods) {
return activityId return activityId
} }
// 商品加入订单时快照原价,供 modifyFlag 提交时对比 // 商品加入订单时快照商品列表 sellPrice,供活动价展示和 modifyFlag 对比
export function snapshotOriginalPrice(goods) { export function snapshotOriginalPrice(goods) {
if (!goods) return if (!goods) return
if (goods.oldPrice != null && goods.oldPrice !== '') return if (goods.oldPrice != null && goods.oldPrice !== '') return
const source = goods.upgradePrice ?? goods.price ?? goods.sellPrice if (goods.sellPrice == null || goods.sellPrice === '') return
if (source == null || source === '') return goods.oldPrice = goods.sellPrice
goods.oldPrice = source }
function findCatalogPackageGoods(catalogItem, merchantGoodsId) {
const list = catalogItem?.packageGoods?.goodsList
if (!Array.isArray(list) || merchantGoodsId == null) return undefined
return list.find(g => g.merchantGoodsId == merchantGoodsId)
}
// 订单回显时,从商品列表恢复活动价快照(不覆盖用户已改动的 sellPrice)
export function snapshotActivityPriceFromCatalog(goods, catalogItem) {
if (!goods || !catalogItem) return
if (goods.oldPrice != null && goods.oldPrice !== '') return
let catalogSellPrice
if (catalogItem.goodsFlag == 1 && catalogItem.goods) {
catalogSellPrice = catalogItem.goods.sellPrice
} else if (catalogItem.goodsFlag == 2) {
catalogSellPrice = catalogItem.multipleSpecificationsGoods?.goods?.sellPrice
} else if (catalogItem.goodsFlag == 3) {
catalogSellPrice = findCatalogPackageGoods(catalogItem, goods.merchantGoodsId)?.sellPrice
}
if (catalogSellPrice == null || catalogSellPrice === '') return
goods.oldPrice = catalogSellPrice
} }
export function snapshotOrderItemOriginalPrice(item) { export function snapshotOrderItemOriginalPrice(item) {
......
import { isMarketingGoods } from './marketingFlag'
export function isBelowMinSellPrice(goods, value) { export function isBelowMinSellPrice(goods, value) {
if (!goods || goods.validMinSellPrice !== 'Y' || goods.minSellPrice == null || goods.minSellPrice === '') { if (!goods || goods.validMinSellPrice !== 'Y' || goods.minSellPrice == null || goods.minSellPrice === '') {
return false return false
...@@ -10,12 +12,11 @@ export function getGoodsDisplayName(goods) { ...@@ -10,12 +12,11 @@ export function getGoodsDisplayName(goods) {
return goods.goodsAlias || goods.upgradeGoodsName || goods.goodsInfo?.goodsName || goods.baseGoodsName || '' return goods.goodsAlias || goods.upgradeGoodsName || goods.goodsInfo?.goodsName || goods.baseGoodsName || ''
} }
// 活动价:商品列表返回的原始售价,加入订单时快照,不随用户改价变化 // 活动价:活动商品加入订单时商品列表 sellPrice 的快照(oldPrice),不随用户改价变化
export function getGoodsActivityPrice(goods) { export function getGoodsActivityPrice(goods, orderItem) {
if (!goods) return undefined if (!goods || !isMarketingGoods(goods, orderItem)) return undefined
const price = goods.oldPrice ?? goods.upgradePrice ?? goods.price if (goods.oldPrice == null || goods.oldPrice === '') return undefined
if (price == null || price === '') return undefined return goods.oldPrice
return price
} }
function buildSingleApprovalItem(item, goods, number) { function buildSingleApprovalItem(item, goods, number) {
...@@ -25,7 +26,7 @@ function buildSingleApprovalItem(item, goods, number) { ...@@ -25,7 +26,7 @@ function buildSingleApprovalItem(item, goods, number) {
type: 'single', type: 'single',
name: getGoodsDisplayName(goods), name: getGoodsDisplayName(goods),
sellPrice, sellPrice,
activityPrice: getGoodsActivityPrice(goods), activityPrice: getGoodsActivityPrice(goods, item),
number: number || '1', number: number || '1',
sourceItem: item sourceItem: item
} }
...@@ -55,7 +56,7 @@ function buildPackageApprovalItem(item, orderTypeCode) { ...@@ -55,7 +56,7 @@ function buildPackageApprovalItem(item, orderTypeCode) {
return { return {
name: getGoodsDisplayName(goods), name: getGoodsDisplayName(goods),
sellPrice, sellPrice,
activityPrice: getGoodsActivityPrice(goods), activityPrice: getGoodsActivityPrice(goods, item),
number: item.packageGoods.number || '1', number: item.packageGoods.number || '1',
sourceGoods: goods sourceGoods: goods
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!