fix: 完善拼团活动 CRUD
This commit is contained in:
parent
3fd9f1b43e
commit
dc39ad0cd1
@ -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 })
|
|
||||||
}
|
|
||||||
|
@ -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!))
|
||||||
|
selectSkus?.forEach((sku) => {
|
||||||
|
let config: CombinationProductVO = {
|
||||||
spuId: spu.id!,
|
spuId: spu.id!,
|
||||||
skuId: sku.id!,
|
skuId: sku.id!,
|
||||||
activePrice: 0
|
activePrice: 0
|
||||||
}
|
}
|
||||||
|
if (typeof products !== 'undefined') {
|
||||||
|
const product = products.find((item) => item.skuId === sku.id)
|
||||||
|
if (product) {
|
||||||
|
// 分转元
|
||||||
|
product.activePrice = formatToFraction(product.activePrice)
|
||||||
|
}
|
||||||
|
config = product || config
|
||||||
|
}
|
||||||
sku.productConfig = config
|
sku.productConfig = config
|
||||||
})
|
})
|
||||||
spuProperties.push({ spuId: spu.id!, spuDetail: spu, propertyList: getPropertyList(spu) })
|
spu.skus = selectSkus as CombinationActivityApi.SkuExtension[]
|
||||||
|
spuProperties.push({
|
||||||
|
spuId: spu.id!,
|
||||||
|
spuDetail: spu,
|
||||||
|
propertyList: getPropertyList(spu)
|
||||||
})
|
})
|
||||||
spuList.value.push(...res)
|
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 () => {
|
||||||
|
@ -134,7 +134,7 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '拼团商品',
|
label: '拼团商品',
|
||||||
field: 'spuIds',
|
field: 'spuId',
|
||||||
isSearch: false,
|
isSearch: false,
|
||||||
form: {
|
form: {
|
||||||
colProps: {
|
colProps: {
|
||||||
|
@ -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>
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user