fix: 完善拼团活动 CRUD

This commit is contained in:
puhui999 2023-07-14 17:35:35 +08:00
parent 3fd9f1b43e
commit dc39ad0cd1
5 changed files with 89 additions and 32 deletions

View File

@ -4,7 +4,7 @@ import { Sku, Spu } from '@/api/mall/product/spu'
export interface CombinationActivityVO { export interface CombinationActivityVO {
id?: number id?: number
name?: string name?: string
spuIds?: number[] spuId?: number
totalLimitCount?: number totalLimitCount?: number
singleLimitCount?: number singleLimitCount?: number
startTime?: Date startTime?: Date
@ -27,7 +27,7 @@ export interface CombinationProductVO {
} }
// 扩展 Sku 配置 // 扩展 Sku 配置
type SkuExtension = Sku & { export type SkuExtension = Sku & {
productConfig: CombinationProductVO productConfig: CombinationProductVO
} }
@ -59,8 +59,3 @@ export const updateCombinationActivity = async (data: CombinationActivityVO) =>
export const deleteCombinationActivity = async (id: number) => { export const deleteCombinationActivity = async (id: number) => {
return await request.delete({ url: '/promotion/combination-activity/delete?id=' + id }) return await request.delete({ url: '/promotion/combination-activity/delete?id=' + id })
} }
// 导出拼团活动 Excel
export const exportCombinationActivity = async (params) => {
return await request.download({ url: '/promotion/combination-activity/export-excel', params })
}

View File

@ -7,7 +7,7 @@
:rules="rules" :rules="rules"
:schema="allSchemas.formSchema" :schema="allSchemas.formSchema"
> >
<template #spuIds> <template #spuId>
<el-button @click="spuSelectRef.open()">选择商品</el-button> <el-button @click="spuSelectRef.open()">选择商品</el-button>
<SpuAndSkuList <SpuAndSkuList
ref="spuAndSkuListRef" ref="spuAndSkuListRef"
@ -34,7 +34,7 @@
<el-button @click="dialogVisible = false"> </el-button> <el-button @click="dialogVisible = false"> </el-button>
</template> </template>
</Dialog> </Dialog>
<SpuSelect ref="spuSelectRef" @confirm="selectSpu" /> <SpuSelect ref="spuSelectRef" :isSelectSku="true" @confirm="selectSpu" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity' import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity'
@ -43,7 +43,7 @@ import { allSchemas, rules } from './combinationActivity.data'
import { SpuAndSkuList, SpuProperty, SpuSelect } from '@/views/mall/promotion/components' import { SpuAndSkuList, SpuProperty, SpuSelect } from '@/views/mall/promotion/components'
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components' 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 { convertToInteger } from '@/utils' import { convertToInteger, formatToFraction } from '@/utils'
defineOptions({ name: 'PromotionCombinationActivityForm' }) defineOptions({ name: 'PromotionCombinationActivityForm' })
@ -71,32 +71,51 @@ const ruleConfig: RuleConfig[] = [
] ]
const selectSpu = (spuId: number, skuIds: number[]) => { const selectSpu = (spuId: number, skuIds: number[]) => {
formRef.value.setValues({ spuId }) formRef.value.setValues({ spuId })
getSpuDetails([spuId]) getSpuDetails(spuId, skuIds)
console.log(skuIds)
} }
/** /**
* 获取 SPU 详情 * 获取 SPU 详情
* @param spuIds
*/ */
const getSpuDetails = async (spuIds: number[]) => { const getSpuDetails = async (
spuId: number,
skuIds: number[] | undefined,
products?: CombinationProductVO[]
) => {
const spuProperties: SpuProperty<CombinationActivityApi.SpuExtension>[] = [] const spuProperties: SpuProperty<CombinationActivityApi.SpuExtension>[] = []
const res = (await ProductSpuApi.getSpuDetailList( const res = (await ProductSpuApi.getSpuDetailList([
spuIds spuId
)) as CombinationActivityApi.SpuExtension[] ])) as CombinationActivityApi.SpuExtension[]
if (res.length == 0) {
return
}
spuList.value = [] spuList.value = []
res?.forEach((spu) => { //
// sku const spu = res[0]
spu.skus?.forEach((sku) => { const selectSkus =
const config: CombinationActivityApi.CombinationProductVO = { typeof skuIds === 'undefined' ? spu?.skus : spu?.skus?.filter((sku) => skuIds.includes(sku.id!))
spuId: spu.id!, selectSkus?.forEach((sku) => {
skuId: sku.id!, let config: CombinationProductVO = {
activePrice: 0 spuId: spu.id!,
skuId: sku.id!,
activePrice: 0
}
if (typeof products !== 'undefined') {
const product = products.find((item) => item.skuId === sku.id)
if (product) {
//
product.activePrice = formatToFraction(product.activePrice)
} }
sku.productConfig = config config = product || config
}) }
spuProperties.push({ spuId: spu.id!, spuDetail: spu, propertyList: getPropertyList(spu) }) sku.productConfig = config
}) })
spuList.value.push(...res) spu.skus = selectSkus as CombinationActivityApi.SkuExtension[]
spuProperties.push({
spuId: spu.id!,
spuDetail: spu,
propertyList: getPropertyList(spu)
})
spuList.value.push(spu)
spuPropertyList.value = spuProperties spuPropertyList.value = spuProperties
} }
@ -107,11 +126,19 @@ 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
await resetForm()
// //
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
const data = await CombinationActivityApi.getCombinationActivity(id) const data = (await CombinationActivityApi.getCombinationActivity(
id
)) as CombinationActivityApi.CombinationActivityVO
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
@ -120,6 +147,14 @@ const open = async (type: string, id?: number) => {
} }
defineExpose({ open }) // open defineExpose({ open }) // open
/** 重置表单 */
const resetForm = async () => {
spuList.value = []
spuPropertyList.value = []
await nextTick()
formRef.value.getElFormRef().resetFields()
}
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
const submitForm = async () => { const submitForm = async () => {

View File

@ -134,7 +134,7 @@ const crudSchemas = reactive<CrudSchema[]>([
}, },
{ {
label: '拼团商品', label: '拼团商品',
field: 'spuIds', field: 'spuId',
isSearch: false, isSearch: false,
form: { form: {
colProps: { colProps: {

View File

@ -29,6 +29,14 @@
total: tableObject.total total: tableObject.total
}" }"
> >
<template #spuId="{ row }">
<el-image
:src="row.picUrl"
class="w-30px h-30px align-middle mr-5px"
@click="imagePreview(row.picUrl)"
/>
<span class="align-middle">{{ row.spuName }}</span>
</template>
<template #action="{ row }"> <template #action="{ row }">
<el-button <el-button
v-hasPermi="['promotion:combination-activity:update']" v-hasPermi="['promotion:combination-activity:update']"
@ -57,6 +65,8 @@
import { allSchemas } from './combinationActivity.data' import { allSchemas } from './combinationActivity.data'
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity' import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity'
import CombinationActivityForm from './CombinationActivityForm.vue' import CombinationActivityForm from './CombinationActivityForm.vue'
import { cloneDeep } from 'lodash-es'
import { createImageViewer } from '@/components/ImageViewer'
defineOptions({ name: 'PromotionCombinationActivity' }) defineOptions({ name: 'PromotionCombinationActivity' })
@ -70,6 +80,13 @@ const { tableObject, tableMethods } = useTable({
// //
const { getList, setSearchParams } = tableMethods const { getList, setSearchParams } = tableMethods
/** 商品图预览 */
const imagePreview = (imgUrl: string) => {
createImageViewer({
urlList: [imgUrl]
})
}
/** 添加/修改操作 */ /** 添加/修改操作 */
const formRef = ref() const formRef = ref()
const openForm = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
@ -83,6 +100,17 @@ const handleDelete = (id: number) => {
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(() => {
/*
TODO
后面准备封装成一个函数来操作 tableColumns 重新排列比如说需求是表单上商品选择是在后面的而列表展示的时候需要调到位置
封装效果支持批量操作给出 field 和需要插入的位置[{field:'spuId',index: 1}] 效果为把 field spuId column 移动到第一个位置
*/
//
const index = allSchemas.tableColumns.findIndex((item) => item.field === 'spuId')
const column = cloneDeep(allSchemas.tableColumns[index])
allSchemas.tableColumns.splice(index, 1)
//
allSchemas.tableColumns.unshift(column)
getList() getList()
}) })
</script> </script>

View File

@ -87,7 +87,6 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
} }
/** /**
* 获取 SPU 详情 * 获取 SPU 详情
* @param spuIds
*/ */
const getSpuDetails = async ( const getSpuDetails = async (
spuId: number, spuId: number,
@ -113,7 +112,7 @@ const getSpuDetails = async (
if (typeof products !== 'undefined') { if (typeof products !== 'undefined') {
const product = products.find((item) => item.skuId === sku.id) const product = products.find((item) => item.skuId === sku.id)
if (product) { if (product) {
// //
product.seckillPrice = formatToFraction(product.seckillPrice) product.seckillPrice = formatToFraction(product.seckillPrice)
} }
config = product || config config = product || config