fix: 完善砍价活动管理对齐后端
This commit is contained in:
parent
7bf3e41c61
commit
44be35b5ce
@ -7,18 +7,20 @@ export interface BargainActivityVO {
|
||||
startTime?: Date
|
||||
endTime?: Date
|
||||
status?: number
|
||||
spuId?: number
|
||||
userSize?: number // 达到该人数,才能砍到低价
|
||||
bargainCount?: number // 最大帮砍次数
|
||||
totalLimitCount?: number // 最大购买次数
|
||||
stock?: number // 活动总库存
|
||||
spuId: number
|
||||
skuId: number
|
||||
bargainFirstPrice: number // 砍价起始价格,单位分
|
||||
bargainPrice: number // 砍价底价
|
||||
stock: number // 活动库存
|
||||
randomMinPrice?: number // 用户每次砍价的最小金额,单位:分
|
||||
randomMaxPrice?: number // 用户每次砍价的最大金额,单位:分
|
||||
successCount?: number // 砍价成功数量
|
||||
products?: BargainProductVO[]
|
||||
}
|
||||
|
||||
// 砍价活动所需属性
|
||||
// 砍价活动所需属性。 选择的商品和属性的时候使用方便使用活动的通用封装
|
||||
export interface BargainProductVO {
|
||||
spuId: number
|
||||
skuId: number
|
||||
|
@ -334,7 +334,7 @@ const validateSku = () => {
|
||||
for (const sku of formData.value!.skus!) {
|
||||
// 作为活动组件的校验
|
||||
if (props.isActivityComponent) {
|
||||
for (const rule of props.ruleConfig) {
|
||||
for (const rule of props?.ruleConfig) {
|
||||
const arg = getValue(sku, rule.name)
|
||||
if (!rule.rule(arg)) {
|
||||
validate = false // 只要有一个不通过则直接不通过
|
||||
@ -534,9 +534,10 @@ watch(
|
||||
}
|
||||
)
|
||||
const activitySkuListRef = ref<InstanceType<typeof ElTable>>()
|
||||
const clearSelection = () => {
|
||||
activitySkuListRef.value.clearSelection()
|
||||
|
||||
const getSkuTableRef = () => {
|
||||
return activitySkuListRef.value
|
||||
}
|
||||
// 暴露出生成 sku 方法,给添加属性成功时调用
|
||||
defineExpose({ generateTableData, validateSku, clearSelection })
|
||||
defineExpose({ generateTableData, validateSku, getSkuTableRef })
|
||||
</script>
|
||||
|
@ -51,7 +51,7 @@
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
<SpuSelect ref="spuSelectRef" :isSelectSku="true" @confirm="selectSpu" />
|
||||
<SpuSelect ref="spuSelectRef" :isSelectSku="true" :radio="true" @confirm="selectSpu" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as BargainActivityApi from '@/api/mall/promotion/bargain/bargainActivity'
|
||||
@ -87,12 +87,12 @@ const ruleConfig: RuleConfig[] = [
|
||||
},
|
||||
{
|
||||
name: 'productConfig.bargainPrice',
|
||||
rule: (arg) => arg > 0,
|
||||
rule: (arg) => arg >= 0,
|
||||
message: '商品砍价底价不能小于0 !!!'
|
||||
},
|
||||
{
|
||||
name: 'productConfig.stock',
|
||||
rule: (arg) => arg > 1,
|
||||
rule: (arg) => arg >= 1,
|
||||
message: '商品活动库存不能小于1 !!!'
|
||||
}
|
||||
]
|
||||
@ -164,7 +164,20 @@ const open = async (type: string, id?: number) => {
|
||||
// 用户每次砍价金额分转元, 分转元
|
||||
data.randomMinPrice = formatToFraction(data.randomMinPrice)
|
||||
data.randomMaxPrice = formatToFraction(data.randomMaxPrice)
|
||||
await getSpuDetails(data.spuId!, data.products?.map((sku) => sku.skuId), data.products)
|
||||
// 对齐活动商品处理结构
|
||||
await getSpuDetails(
|
||||
data.spuId!,
|
||||
[data.skuId],
|
||||
[
|
||||
{
|
||||
spuId: data.spuId!,
|
||||
skuId: data.skuId,
|
||||
bargainFirstPrice: data.bargainFirstPrice, // 砍价起始价格,单位分
|
||||
bargainPrice: data.bargainPrice, // 砍价底价
|
||||
stock: data.stock // 活动库存
|
||||
}
|
||||
]
|
||||
)
|
||||
formRef.value.setValues(data)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
@ -201,12 +214,12 @@ const submitForm = async () => {
|
||||
// 用户每次砍价金额分转元, 元转分
|
||||
data.randomMinPrice = convertToInteger(data.randomMinPrice)
|
||||
data.randomMaxPrice = convertToInteger(data.randomMaxPrice)
|
||||
data.products = products
|
||||
const formData = { ...data, ...products[0] }
|
||||
if (formType.value === 'create') {
|
||||
await BargainActivityApi.createBargainActivity(data)
|
||||
await BargainActivityApi.createBargainActivity(formData)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await BargainActivityApi.updateBargainActivity(data)
|
||||
await BargainActivityApi.updateBargainActivity(formData)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
|
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="CombinationRecord" setup></script>
|
@ -127,7 +127,8 @@ defineOptions({ name: 'PromotionSpuSelect' })
|
||||
const props = defineProps({
|
||||
// 默认不需要(不需要的情况下只返回 spu,需要的情况下返回 选中的 spu 和 sku 列表)
|
||||
// 其它活动需要选择商品和商品属性导入此组件即可,需添加组件属性 :isSelectSku='true'
|
||||
isSelectSku: propTypes.bool.def(false) // 是否需要选择 sku 属性
|
||||
isSelectSku: propTypes.bool.def(false), // 是否需要选择 sku 属性
|
||||
radio: propTypes.bool.def(false) // 是否单选 sku
|
||||
})
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
@ -146,7 +147,7 @@ const queryParams = ref({
|
||||
}) // 查询参数
|
||||
const propertyList = ref<PropertyAndValues[]>([]) // 商品属性列表
|
||||
const spuListRef = ref<InstanceType<typeof ElTable>>()
|
||||
const skuListRef = ref() // 商品属性选择 Ref
|
||||
const skuListRef = ref<InstanceType<typeof SkuList>>() // 商品属性选择 Ref
|
||||
const spuData = ref<ProductSpuApi.Spu>() // 商品详情
|
||||
const isExpand = ref(false) // 控制 SKU 列表显示
|
||||
const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。
|
||||
@ -155,12 +156,30 @@ const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属
|
||||
const selectedSpuId = ref<number>(0) // 选中的商品 spuId
|
||||
const selectedSkuIds = ref<number[]>([]) // 选中的商品 skuIds
|
||||
const selectSku = (val: ProductSpuApi.Sku[]) => {
|
||||
const skuTable = skuListRef.value?.getSkuTableRef()
|
||||
if (selectedSpuId.value === 0) {
|
||||
message.warning('请先选择商品再选择相应的规格!!!')
|
||||
skuListRef.value.clearSelection()
|
||||
skuTable?.clearSelection()
|
||||
return
|
||||
}
|
||||
selectedSkuIds.value = val.map((sku) => sku.id!)
|
||||
if (val.length === 0) {
|
||||
selectedSkuIds.value = []
|
||||
return
|
||||
}
|
||||
if (props.radio) {
|
||||
// 只选择一个
|
||||
selectedSkuIds.value = [val.map((sku) => sku.id!)[0]]
|
||||
// 如果大于1个
|
||||
if (val.length > 1) {
|
||||
// 清空选择
|
||||
skuTable?.clearSelection()
|
||||
// 变更为最后一次选择的
|
||||
skuTable?.toggleRowSelection(val.pop(), true)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
selectedSkuIds.value = val.map((sku) => sku.id!)
|
||||
}
|
||||
}
|
||||
const selectSpu = (val: ProductSpuApi.Spu[]) => {
|
||||
if (val.length === 0) {
|
||||
@ -176,9 +195,9 @@ const selectSpu = (val: ProductSpuApi.Spu[]) => {
|
||||
// 如果大于1个
|
||||
if (val.length > 1) {
|
||||
// 清空选择
|
||||
spuListRef.value.clearSelection()
|
||||
spuListRef.value?.clearSelection()
|
||||
// 变更为最后一次选择的
|
||||
spuListRef.value.toggleRowSelection(val.pop(), true)
|
||||
spuListRef.value?.toggleRowSelection(val.pop(), true)
|
||||
return
|
||||
}
|
||||
expandChange(val[0], val)
|
||||
@ -194,7 +213,7 @@ const expandChange = async (row: ProductSpuApi.Spu, expandedRows?: ProductSpuApi
|
||||
expandRowKeys.value = [selectedSpuId.value]
|
||||
return
|
||||
}
|
||||
// 如果以展开 skuList 则选择此对应的 spu 不需要重新获取渲染 skuList
|
||||
// 如果已展开 skuList 则选择此对应的 spu 不需要重新获取渲染 skuList
|
||||
if (isExpand.value && spuData.value?.id === row.id) {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user