fix: mall SeckillActivity

(cherry picked from commit ce3ca7c6ce)
This commit is contained in:
puhui999 2023-07-05 17:12:53 +08:00 committed by shizhong
parent de53abb249
commit d1cc7d134b
5 changed files with 64 additions and 31 deletions

View File

@ -2,23 +2,23 @@ import request from '@/config/axios'
import { Sku, Spu } from '@/api/mall/product/spu'
export interface SeckillActivityVO {
id: number
spuIds: number[]
name: string
status: number
remark: string
startTime: Date
endTime: Date
sort: number
configIds: string
orderCount: number
userCount: number
totalPrice: number
totalLimitCount: number
singleLimitCount: number
stock: number
totalStock: number
products: SeckillProductVO[]
id?: number
spuId?: number
name?: string
status?: number
remark?: string
startTime?: Date
endTime?: Date
sort?: number
configIds?: string
orderCount?: number
userCount?: number
totalPrice?: number
totalLimitCount?: number
singleLimitCount?: number
stock?: number
totalStock?: number
products?: SeckillProductVO[]
}
// 秒杀活动所需属性

View File

@ -113,6 +113,7 @@
<!-- 情况二详情 -->
<el-table
v-if="isDetail"
ref="activitySkuListRef"
:data="formData!.skus"
border
max-height="500"
@ -194,7 +195,6 @@
<!-- 情况三作为活动组件 -->
<el-table
v-if="isActivityComponent"
ref="activitySkuListRef"
:data="formData!.skus"
border
max-height="500"
@ -261,6 +261,7 @@ import type { Property, Sku, Spu } from '@/api/mall/product/spu'
import { createImageViewer } from '@/components/ImageViewer'
import { RuleConfig } from '@/views/mall/product/spu/components/index'
import { Properties } from './index'
import { ElTable } from 'element-plus'
defineOptions({ name: 'SkuList' })
const message = useMessage() //
@ -515,7 +516,6 @@ watch(
// nameindex
tableHeaders.value.push({ prop: `name${index}`, label: item.name })
})
// sku
if (validateData(propertyList)) {
return
@ -532,6 +532,10 @@ watch(
immediate: true
}
)
const activitySkuListRef = ref<InstanceType<typeof ElTable>>()
const clearSelection = () => {
activitySkuListRef.value.clearSelection()
}
// sku
defineExpose({ generateTableData, validateSku })
defineExpose({ generateTableData, validateSku, clearSelection })
</script>

View File

@ -1,5 +1,5 @@
<template>
<el-table :data="spuData" :default-expand-all="true">
<el-table :data="spuData" :expand-row-keys="expandRowKeys" row-key="id">
<el-table-column type="expand" width="30">
<template #default="{ row }">
<SkuList
@ -48,9 +48,8 @@ const props = defineProps<{
const spuData = ref<Spu[]>([]) // spu
const skuListRef = ref() // Ref
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId sku
const expandRowKeys = ref<number[]>() // row-key 使 keys
/**
* 获取所有 sku 活动配置
* @param extendedAttribute sku 上扩展的属性秒杀活动 sku 扩展属性 productConfig 请参考 seckillActivity.ts
@ -98,6 +97,10 @@ watch(
(data) => {
if (!data) return
spuPropertyList.value = data as SpuProperty<T>[]
// spu sku SkuList
setTimeout(() => {
expandRowKeys.value = data.map((item) => item.spuId)
}, 200)
},
{
deep: true,

View File

@ -57,6 +57,7 @@
<template #default>
<SkuList
v-if="isExpand"
ref="skuListRef"
:isComponent="true"
:isDetail="true"
:prop-form-data="spuData"
@ -145,6 +146,7 @@ const queryParams = ref({
}) //
const propertyList = ref<Properties[]>([]) //
const spuListRef = ref<InstanceType<typeof ElTable>>()
const skuListRef = ref() // Ref
const spuData = ref<ProductSpuApi.Spu>() //
const isExpand = ref(false) // SKU
const expandRowKeys = ref<number[]>() // row-key 使 keys
@ -154,6 +156,8 @@ const selectedSpuId = ref<number>(0) // 选中的商品 spuId
const selectedSkuIds = ref<number[]>([]) // skuIds
const selectSku = (val: ProductSpuApi.Sku[]) => {
if (selectedSpuId.value === 0) {
message.warning('请先选择商品再选择相应的规格!!!')
skuListRef.value.clearSelection()
return
}
selectedSkuIds.value = val.map((sku) => sku.id!)
@ -233,6 +237,8 @@ const confirm = () => {
: emits('confirm', selectedSpuId.value)
//
dialogVisible.value = false
selectedSpuId.value = 0
selectedSkuIds.value = []
}
/** 打开弹窗 */

View File

@ -50,7 +50,7 @@ import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivit
import { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
import * as ProductSpuApi from '@/api/mall/product/spu'
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
import { convertToInteger } from '@/utils'
import { convertToInteger, formatToFraction } from '@/utils'
defineOptions({ name: 'PromotionSeckillActivityForm' })
@ -89,7 +89,11 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
* 获取 SPU 详情
* @param spuIds
*/
const getSpuDetails = async (spuId: number, skuIds: number[]) => {
const getSpuDetails = async (
spuId: number,
skuIds: number[] | undefined,
products?: SeckillProductVO[]
) => {
const spuProperties: SpuProperty<SeckillActivityApi.SpuExtension>[] = []
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as SeckillActivityApi.SpuExtension[]
if (res.length == 0) {
@ -98,13 +102,22 @@ const getSpuDetails = async (spuId: number, skuIds: number[]) => {
spuList.value = []
//
const spu = res[0]
const selectSkus = spu?.skus?.filter((sku) => skuIds.includes(sku.id!))
const selectSkus =
typeof skuIds === 'undefined' ? spu?.skus : spu?.skus?.filter((sku) => skuIds.includes(sku.id!))
selectSkus?.forEach((sku) => {
const config: SeckillActivityApi.SeckillProductVO = {
let config: SeckillActivityApi.SeckillProductVO = {
skuId: sku.id!,
stock: 0,
seckillPrice: 0
}
if (typeof products !== 'undefined') {
const product = products.find((item) => item.skuId === sku.id)
if (product) {
//
product.seckillPrice = formatToFraction(product.seckillPrice)
}
config = product || config
}
sku.productConfig = config
})
spu.skus = selectSkus as SeckillActivityApi.SkuExtension[]
@ -113,7 +126,7 @@ const getSpuDetails = async (spuId: number, skuIds: number[]) => {
spuDetail: spu,
propertyList: getPropertyList(spu)
})
spuList.value.push(...res)
spuList.value.push(spu)
spuPropertyList.value = spuProperties
}
@ -125,11 +138,18 @@ const open = async (type: string, id?: number) => {
dialogTitle.value = t('action.' + type)
formType.value = type
await resetForm()
// TODO
//
if (id) {
formLoading.value = true
try {
const data = await SeckillActivityApi.getSeckillActivity(id)
const data = (await SeckillActivityApi.getSeckillActivity(
id
)) as SeckillActivityApi.SeckillActivityVO
await getSpuDetails(
data.spuId!,
data.products?.map((sku) => sku.skuId),
data.products
)
formRef.value.setValues(data)
} finally {
formLoading.value = false
@ -162,7 +182,7 @@ const submitForm = async () => {
item.seckillPrice = convertToInteger(item.seckillPrice)
})
//
data.products = spuAndSkuListRef.value.getSkuConfigs('productConfig')
data.products = products
if (formType.value === 'create') {
await SeckillActivityApi.createSeckillActivity(data)
message.success(t('common.createSuccess'))