fix: mall SeckillActivity

pull/179/head
puhui999 2023-07-03 12:07:19 +08:00
parent a5330958ba
commit b98149f1a7
3 changed files with 19 additions and 21 deletions

View File

@ -86,6 +86,11 @@ export const getSpu = (id: number) => {
return request.get({ url: `/product/spu/get-detail?id=${id}` }) return request.get({ url: `/product/spu/get-detail?id=${id}` })
} }
// 获得商品 Spu 详情列表
export const getSpuDetailList = (ids: number[]) => {
return request.get({ url: `/product/spu/list?spuIds=${ids}` })
}
// 删除商品 Spu // 删除商品 Spu
export const deleteSpu = (id: number) => { export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` }) return request.delete({ url: `/product/spu/delete?id=${id}` })

View File

@ -47,17 +47,14 @@
</el-table> </el-table>
</template> </template>
<script generic="T extends Spu" lang="ts" setup> <script generic="T extends Spu" lang="ts" setup>
// TODO SPU
import { formatToFraction } from '@/utils' import { formatToFraction } from '@/utils'
import { createImageViewer } from '@/components/ImageViewer' import { createImageViewer } from '@/components/ImageViewer'
import { Spu } from '@/api/mall/product/spu' import { Spu } from '@/api/mall/product/spu'
import { RuleConfig, SkuList } from '@/views/mall/product/spu/components' import { RuleConfig, SkuList } from '@/views/mall/product/spu/components'
import { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
import { SpuProperty } from '@/views/mall/promotion/components/index' import { SpuProperty } from '@/views/mall/promotion/components/index'
defineOptions({ name: 'PromotionSpuAndSkuList' }) defineOptions({ name: 'PromotionSpuAndSkuList' })
// TODO @puhui999 spu
const props = defineProps<{ const props = defineProps<{
spuList: T[] spuList: T[]
ruleConfig: RuleConfig[] ruleConfig: RuleConfig[]
@ -70,12 +67,12 @@ const skuListRef = ref() // 商品属性列表Ref
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId sku const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId sku
/** /**
* 获取所有 sku 秒杀配置 * 获取所有 sku 活动配置
* @param extendedAttribute sku 上扩展的属性秒杀活动 sku 扩展属性 productConfig 请参考 seckillActivity.ts * @param extendedAttribute sku 上扩展的属性秒杀活动 sku 扩展属性 productConfig 请参考 seckillActivity.ts
*/ */
const getSkuConfigs: <V>(extendedAttribute: string) => V[] = (extendedAttribute: string) => { const getSkuConfigs = (extendedAttribute: string) => {
skuListRef.value.validateSku() skuListRef.value.validateSku()
const seckillProducts: SeckillProductVO[] = [] const seckillProducts = []
spuPropertyList.value.forEach((item) => { spuPropertyList.value.forEach((item) => {
item.spuDetail.skus.forEach((sku) => { item.spuDetail.skus.forEach((sku) => {
seckillProducts.push(sku[extendedAttribute]) seckillProducts.push(sku[extendedAttribute])

View File

@ -30,8 +30,8 @@ import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components'
import { allSchemas, rules } from './seckillActivity.data' import { allSchemas, rules } from './seckillActivity.data'
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity' import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
import * as ProductSpuApi from '@/api/mall/product/spu' import * as ProductSpuApi from '@/api/mall/product/spu'
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
defineOptions({ name: 'PromotionSeckillActivityForm' }) defineOptions({ name: 'PromotionSeckillActivityForm' })
@ -62,7 +62,7 @@ const open = async (type: string, id?: number) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
formType.value = type formType.value = type
resetForm() await resetForm()
// TODO // TODO
if (id) { if (id) {
formLoading.value = true formLoading.value = true
@ -89,34 +89,30 @@ const selectSpu = (spuIds: number[]) => {
*/ */
const getSpuDetails = async (spuIds: number[]) => { const getSpuDetails = async (spuIds: number[]) => {
const spuProperties: SpuProperty<SeckillActivityApi.SpuExtension>[] = [] const spuProperties: SpuProperty<SeckillActivityApi.SpuExtension>[] = []
const res = (await ProductSpuApi.getSpuDetailList(spuIds)) as SeckillActivityApi.SpuExtension[]
spuList.value = [] spuList.value = []
// TODO puhui999: spuIds res?.forEach((spu) => {
for (const spuId of spuIds) {
// SPU
const res = (await ProductSpuApi.getSpu(spuId)) as SeckillActivityApi.SpuExtension
if (!res) {
continue
}
spuList.value.push(res)
// sku // sku
res.skus?.forEach((sku) => { spu.skus?.forEach((sku) => {
const config: SeckillActivityApi.SeckillProductVO = { const config: SeckillActivityApi.SeckillProductVO = {
spuId, spuId: spu.id!,
skuId: sku.id!, skuId: sku.id!,
stock: 0, stock: 0,
seckillPrice: 0 seckillPrice: 0
} }
sku.productConfig = config sku.productConfig = config
}) })
spuProperties.push({ spuId, spuDetail: res, propertyList: getPropertyList(res) }) spuProperties.push({ spuId: spu.id!, spuDetail: spu, propertyList: getPropertyList(spu) })
} })
spuList.value.push(...res)
spuPropertyList.value = spuProperties spuPropertyList.value = spuProperties
} }
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = async () => {
spuList.value = [] spuList.value = []
spuPropertyList.value = [] spuPropertyList.value = []
await nextTick()
formRef.value.getElFormRef().resetFields() formRef.value.getElFormRef().resetFields()
} }
/** 提交表单 */ /** 提交表单 */