fix: mall SeckillActivity

pull/179/head
puhui999 2023-07-05 17:12:53 +08:00
parent 36c0bce184
commit ce3ca7c6ce
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' import { Sku, Spu } from '@/api/mall/product/spu'
export interface SeckillActivityVO { export interface SeckillActivityVO {
id: number id?: number
spuIds: number[] spuId?: number
name: string name?: string
status: number status?: number
remark: string remark?: string
startTime: Date startTime?: Date
endTime: Date endTime?: Date
sort: number sort?: number
configIds: string configIds?: string
orderCount: number orderCount?: number
userCount: number userCount?: number
totalPrice: number totalPrice?: number
totalLimitCount: number totalLimitCount?: number
singleLimitCount: number singleLimitCount?: number
stock: number stock?: number
totalStock: number totalStock?: number
products: SeckillProductVO[] products?: SeckillProductVO[]
} }
// 秒杀活动所需属性 // 秒杀活动所需属性

View File

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

View File

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

View File

@ -57,6 +57,7 @@
<template #default> <template #default>
<SkuList <SkuList
v-if="isExpand" v-if="isExpand"
ref="skuListRef"
:isComponent="true" :isComponent="true"
:isDetail="true" :isDetail="true"
:prop-form-data="spuData" :prop-form-data="spuData"
@ -145,6 +146,7 @@ const queryParams = ref({
}) // }) //
const propertyList = ref<Properties[]>([]) // const propertyList = ref<Properties[]>([]) //
const spuListRef = ref<InstanceType<typeof ElTable>>() const spuListRef = ref<InstanceType<typeof ElTable>>()
const skuListRef = ref() // 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
@ -154,6 +156,8 @@ 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[]) => {
if (selectedSpuId.value === 0) { if (selectedSpuId.value === 0) {
message.warning('请先选择商品再选择相应的规格!!!')
skuListRef.value.clearSelection()
return return
} }
selectedSkuIds.value = val.map((sku) => sku.id!) selectedSkuIds.value = val.map((sku) => sku.id!)
@ -233,6 +237,8 @@ const confirm = () => {
: emits('confirm', selectedSpuId.value) : emits('confirm', selectedSpuId.value)
// //
dialogVisible.value = false 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 { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
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' import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
import { convertToInteger } from '@/utils' import { convertToInteger, formatToFraction } from '@/utils'
defineOptions({ name: 'PromotionSeckillActivityForm' }) defineOptions({ name: 'PromotionSeckillActivityForm' })
@ -89,7 +89,11 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
* 获取 SPU 详情 * 获取 SPU 详情
* @param spuIds * @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 spuProperties: SpuProperty<SeckillActivityApi.SpuExtension>[] = []
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as SeckillActivityApi.SpuExtension[] const res = (await ProductSpuApi.getSpuDetailList([spuId])) as SeckillActivityApi.SpuExtension[]
if (res.length == 0) { if (res.length == 0) {
@ -98,13 +102,22 @@ const getSpuDetails = async (spuId: number, skuIds: number[]) => {
spuList.value = [] spuList.value = []
// //
const spu = res[0] 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) => { selectSkus?.forEach((sku) => {
const config: SeckillActivityApi.SeckillProductVO = { let config: SeckillActivityApi.SeckillProductVO = {
skuId: sku.id!, skuId: sku.id!,
stock: 0, stock: 0,
seckillPrice: 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 sku.productConfig = config
}) })
spu.skus = selectSkus as SeckillActivityApi.SkuExtension[] spu.skus = selectSkus as SeckillActivityApi.SkuExtension[]
@ -113,7 +126,7 @@ const getSpuDetails = async (spuId: number, skuIds: number[]) => {
spuDetail: spu, spuDetail: spu,
propertyList: getPropertyList(spu) propertyList: getPropertyList(spu)
}) })
spuList.value.push(...res) spuList.value.push(spu)
spuPropertyList.value = spuProperties spuPropertyList.value = spuProperties
} }
@ -125,11 +138,18 @@ const open = async (type: string, id?: number) => {
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
formType.value = type formType.value = type
await resetForm() await resetForm()
// TODO //
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { 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) formRef.value.setValues(data)
} finally { } finally {
formLoading.value = false formLoading.value = false
@ -162,7 +182,7 @@ const submitForm = async () => {
item.seckillPrice = convertToInteger(item.seckillPrice) item.seckillPrice = convertToInteger(item.seckillPrice)
}) })
// //
data.products = spuAndSkuListRef.value.getSkuConfigs('productConfig') data.products = products
if (formType.value === 'create') { if (formType.value === 'create') {
await SeckillActivityApi.createSeckillActivity(data) await SeckillActivityApi.createSeckillActivity(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))