fix: 完善砍价活动管理对齐后端

This commit is contained in:
puhui999 2023-08-17 10:52:40 +08:00
parent 7bf3e41c61
commit 44be35b5ce
5 changed files with 62 additions and 22 deletions

View File

@ -7,18 +7,20 @@ export interface BargainActivityVO {
startTime?: Date startTime?: Date
endTime?: Date endTime?: Date
status?: number status?: number
spuId?: number
userSize?: number // 达到该人数,才能砍到低价 userSize?: number // 达到该人数,才能砍到低价
bargainCount?: number // 最大帮砍次数 bargainCount?: number // 最大帮砍次数
totalLimitCount?: number // 最大购买次数 totalLimitCount?: number // 最大购买次数
stock?: number // 活动总库存 spuId: number
skuId: number
bargainFirstPrice: number // 砍价起始价格,单位分
bargainPrice: number // 砍价底价
stock: number // 活动库存
randomMinPrice?: number // 用户每次砍价的最小金额,单位:分 randomMinPrice?: number // 用户每次砍价的最小金额,单位:分
randomMaxPrice?: number // 用户每次砍价的最大金额,单位:分 randomMaxPrice?: number // 用户每次砍价的最大金额,单位:分
successCount?: number // 砍价成功数量 successCount?: number // 砍价成功数量
products?: BargainProductVO[]
} }
// 砍价活动所需属性 // 砍价活动所需属性。 选择的商品和属性的时候使用方便使用活动的通用封装
export interface BargainProductVO { export interface BargainProductVO {
spuId: number spuId: number
skuId: number skuId: number

View File

@ -334,7 +334,7 @@ const validateSku = () => {
for (const sku of formData.value!.skus!) { for (const sku of formData.value!.skus!) {
// //
if (props.isActivityComponent) { if (props.isActivityComponent) {
for (const rule of props.ruleConfig) { for (const rule of props?.ruleConfig) {
const arg = getValue(sku, rule.name) const arg = getValue(sku, rule.name)
if (!rule.rule(arg)) { if (!rule.rule(arg)) {
validate = false // validate = false //
@ -534,9 +534,10 @@ watch(
} }
) )
const activitySkuListRef = ref<InstanceType<typeof ElTable>>() const activitySkuListRef = ref<InstanceType<typeof ElTable>>()
const clearSelection = () => {
activitySkuListRef.value.clearSelection() const getSkuTableRef = () => {
return activitySkuListRef.value
} }
// sku // sku
defineExpose({ generateTableData, validateSku, clearSelection }) defineExpose({ generateTableData, validateSku, getSkuTableRef })
</script> </script>

View File

@ -51,7 +51,7 @@
<el-button @click="dialogVisible = false"> </el-button> <el-button @click="dialogVisible = false"> </el-button>
</template> </template>
</Dialog> </Dialog>
<SpuSelect ref="spuSelectRef" :isSelectSku="true" @confirm="selectSpu" /> <SpuSelect ref="spuSelectRef" :isSelectSku="true" :radio="true" @confirm="selectSpu" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import * as BargainActivityApi from '@/api/mall/promotion/bargain/bargainActivity' import * as BargainActivityApi from '@/api/mall/promotion/bargain/bargainActivity'
@ -87,12 +87,12 @@ const ruleConfig: RuleConfig[] = [
}, },
{ {
name: 'productConfig.bargainPrice', name: 'productConfig.bargainPrice',
rule: (arg) => arg > 0, rule: (arg) => arg >= 0,
message: '商品砍价底价不能小于0 ' message: '商品砍价底价不能小于0 '
}, },
{ {
name: 'productConfig.stock', name: 'productConfig.stock',
rule: (arg) => arg > 1, rule: (arg) => arg >= 1,
message: '商品活动库存不能小于1 ' message: '商品活动库存不能小于1 '
} }
] ]
@ -164,7 +164,20 @@ const open = async (type: string, id?: number) => {
// , // ,
data.randomMinPrice = formatToFraction(data.randomMinPrice) data.randomMinPrice = formatToFraction(data.randomMinPrice)
data.randomMaxPrice = formatToFraction(data.randomMaxPrice) 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) formRef.value.setValues(data)
} finally { } finally {
formLoading.value = false formLoading.value = false
@ -201,12 +214,12 @@ const submitForm = async () => {
// , // ,
data.randomMinPrice = convertToInteger(data.randomMinPrice) data.randomMinPrice = convertToInteger(data.randomMinPrice)
data.randomMaxPrice = convertToInteger(data.randomMaxPrice) data.randomMaxPrice = convertToInteger(data.randomMaxPrice)
data.products = products const formData = { ...data, ...products[0] }
if (formType.value === 'create') { if (formType.value === 'create') {
await BargainActivityApi.createBargainActivity(data) await BargainActivityApi.createBargainActivity(formData)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await BargainActivityApi.updateBargainActivity(data) await BargainActivityApi.updateBargainActivity(formData)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
dialogVisible.value = false dialogVisible.value = false

View File

@ -0,0 +1,5 @@
<template>
<div></div>
</template>
<script lang="ts" name="CombinationRecord" setup></script>

View File

@ -127,7 +127,8 @@ defineOptions({ name: 'PromotionSpuSelect' })
const props = defineProps({ const props = defineProps({
// spu spu sku // spu spu sku
// :isSelectSku='true' // :isSelectSku='true'
isSelectSku: propTypes.bool.def(false) // sku isSelectSku: propTypes.bool.def(false), // sku
radio: propTypes.bool.def(false) // sku
}) })
const message = useMessage() // const message = useMessage() //
@ -146,7 +147,7 @@ const queryParams = ref({
}) // }) //
const propertyList = ref<PropertyAndValues[]>([]) // const propertyList = ref<PropertyAndValues[]>([]) //
const spuListRef = ref<InstanceType<typeof ElTable>>() const spuListRef = ref<InstanceType<typeof ElTable>>()
const skuListRef = ref() // Ref const skuListRef = ref<InstanceType<typeof SkuList>>() // Ref
const spuData = ref<ProductSpuApi.Spu>() // const spuData = ref<ProductSpuApi.Spu>() //
const isExpand = ref(false) // SKU const isExpand = ref(false) // SKU
const expandRowKeys = ref<number[]>() // row-key 使 keys const expandRowKeys = ref<number[]>() // row-key 使 keys
@ -155,12 +156,30 @@ const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属
const selectedSpuId = ref<number>(0) // spuId const selectedSpuId = ref<number>(0) // spuId
const selectedSkuIds = ref<number[]>([]) // skuIds const selectedSkuIds = ref<number[]>([]) // skuIds
const selectSku = (val: ProductSpuApi.Sku[]) => { const selectSku = (val: ProductSpuApi.Sku[]) => {
const skuTable = skuListRef.value?.getSkuTableRef()
if (selectedSpuId.value === 0) { if (selectedSpuId.value === 0) {
message.warning('请先选择商品再选择相应的规格!!!') message.warning('请先选择商品再选择相应的规格!!!')
skuListRef.value.clearSelection() skuTable?.clearSelection()
return 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[]) => { const selectSpu = (val: ProductSpuApi.Spu[]) => {
if (val.length === 0) { if (val.length === 0) {
@ -176,9 +195,9 @@ const selectSpu = (val: ProductSpuApi.Spu[]) => {
// 1 // 1
if (val.length > 1) { if (val.length > 1) {
// //
spuListRef.value.clearSelection() spuListRef.value?.clearSelection()
// //
spuListRef.value.toggleRowSelection(val.pop(), true) spuListRef.value?.toggleRowSelection(val.pop(), true)
return return
} }
expandChange(val[0], val) expandChange(val[0], val)
@ -194,7 +213,7 @@ const expandChange = async (row: ProductSpuApi.Spu, expandedRows?: ProductSpuApi
expandRowKeys.value = [selectedSpuId.value] expandRowKeys.value = [selectedSpuId.value]
return return
} }
// skuList spu skuList // skuList spu skuList
if (isExpand.value && spuData.value?.id === row.id) { if (isExpand.value && spuData.value?.id === row.id) {
return return
} }