Skip to content

Commit 4057130

Browse files
author
puhui999
committed
fix: mall SeckillActivity and CombinationActivity
1 parent ce3ca7c commit 4057130

File tree

10 files changed

+152
-65
lines changed

10 files changed

+152
-65
lines changed

src/api/mall/promotion/combination/combinationactivity.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
import request from '@/config/axios'
2+
import { Sku, Spu } from '@/api/mall/product/spu'
23

34
export interface CombinationActivityVO {
4-
id: number
5-
name: string
5+
id?: number
6+
name?: string
7+
spuIds?: number[]
8+
totalLimitCount?: number
9+
singleLimitCount?: number
10+
startTime?: Date
11+
endTime?: Date
12+
userSize?: number
13+
totalNum?: number
14+
successNum?: number
15+
orderUserCount?: number
16+
virtualGroup?: number
17+
status?: number
18+
limitDuration?: number
19+
products: CombinationProductVO[]
20+
}
21+
22+
// 拼团活动所需属性
23+
export interface CombinationProductVO {
624
spuId: number
7-
totalLimitCount: number
8-
singleLimitCount: number
9-
startTime: Date
10-
endTime: Date
11-
userSize: number
12-
totalNum: number
13-
successNum: number
14-
orderUserCount: number
15-
virtualGroup: number
16-
status: number
17-
limitDuration: number
25+
skuId: number
26+
activePrice: number // 拼团价格
27+
}
28+
29+
// 扩展 Sku 配置
30+
type SkuExtension = Sku & {
31+
productConfig: CombinationProductVO
32+
}
33+
34+
export interface SpuExtension extends Spu {
35+
skus: SkuExtension[] // 重写类型
1836
}
1937

2038
// 查询拼团活动列表

src/utils/formatTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function formatDate(date: Date, format?: string): string {
2727
* 获取当前的日期+时间
2828
*/
2929
export function getNowDateTime() {
30-
return dayjs().format('YYYY-MM-DD HH:mm:ss')
30+
return dayjs()
3131
}
3232

3333
/**

src/views/mall/product/spu/components/SkuList.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- 情况一:添加/修改 -->
33
<el-table
44
v-if="!isDetail && !isActivityComponent"
5-
:data="isBatch ? skuList : formData!.skus"
5+
:data="isBatch ? skuList : formData!.skus!"
66
border
77
class="tabNumWidth"
88
max-height="500"
@@ -114,7 +114,7 @@
114114
<el-table
115115
v-if="isDetail"
116116
ref="activitySkuListRef"
117-
:data="formData!.skus"
117+
:data="formData!.skus!"
118118
border
119119
max-height="500"
120120
size="small"
@@ -195,7 +195,7 @@
195195
<!-- 情况三:作为活动组件 -->
196196
<el-table
197197
v-if="isActivityComponent"
198-
:data="formData!.skus"
198+
:data="formData!.skus!"
199199
border
200200
max-height="500"
201201
size="small"
@@ -260,7 +260,7 @@ import { UploadImg } from '@/components/UploadFile'
260260
import type { Property, Sku, Spu } from '@/api/mall/product/spu'
261261
import { createImageViewer } from '@/components/ImageViewer'
262262
import { RuleConfig } from '@/views/mall/product/spu/components/index'
263-
import { Properties } from './index'
263+
import { PropertyAndValues } from './index'
264264
import { ElTable } from 'element-plus'
265265
266266
defineOptions({ name: 'SkuList' })
@@ -272,7 +272,7 @@ const props = defineProps({
272272
default: () => {}
273273
},
274274
propertyList: {
275-
type: Array as PropType<Properties[]>,
275+
type: Array as PropType<PropertyAndValues[]>,
276276
default: () => []
277277
},
278278
ruleConfig: {
@@ -482,7 +482,7 @@ const build = (propertyValuesList: Property[][]) => {
482482
/** 监听属性列表,生成相关参数和表头 */
483483
watch(
484484
() => props.propertyList,
485-
(propertyList: Properties[]) => {
485+
(propertyList: PropertyAndValues[]) => {
486486
// 如果不是多规格则结束
487487
if (!formData.value!.specType) {
488488
return

src/views/mall/product/spu/components/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import SkuList from './SkuList.vue'
77

88
import { Spu } from '@/api/mall/product/spu'
99

10-
// TODO @puhui999:Properties 改成 Property 更合适?
11-
interface Properties {
10+
// TODO @puhui999:Properties 改成 Property 更合适?Property 在 Spu 中已存在避免冲突 PropertyAndValues
11+
interface PropertyAndValues {
1212
id: number
1313
name: string
14-
values?: Properties[]
14+
values?: PropertyAndValues[]
1515
}
1616

1717
interface RuleConfig {
@@ -23,7 +23,7 @@ interface RuleConfig {
2323
// 例:需要校验价格必须大于0.01
2424
// {
2525
// name:'price',
26-
// rule:(arg) => arg > 0.01
26+
// rule:(arg: number) => arg > 0.01
2727
// }
2828
rule: (arg: any) => boolean
2929
// 校验不通过时的消息提示
@@ -34,11 +34,11 @@ interface RuleConfig {
3434
* 获得商品的规格列表
3535
*
3636
* @param spu
37-
* @return Property 规格列表
37+
* @return PropertyAndValues 规格列表
3838
*/
39-
const getPropertyList = (spu: Spu): Properties[] => {
39+
const getPropertyList = (spu: Spu): PropertyAndValues[] => {
4040
// 直接拿返回的 skus 属性逆向生成出 propertyList
41-
const properties: Properties[] = []
41+
const properties: PropertyAndValues[] = []
4242
// 只有是多规格才处理
4343
if (spu.specType) {
4444
spu.skus?.forEach((sku) => {
@@ -66,6 +66,6 @@ export {
6666
ProductPropertyAddForm,
6767
SkuList,
6868
getPropertyList,
69-
Properties,
69+
PropertyAndValues,
7070
RuleConfig
7171
}

src/views/mall/promotion/combination/activity/CombinationActivityForm.vue

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
11
<template>
2-
<Dialog v-model="dialogVisible" :title="dialogTitle">
2+
<Dialog v-model="dialogVisible" :title="dialogTitle" width="65%">
33
<Form
44
ref="formRef"
55
v-loading="formLoading"
66
:is-col="true"
77
:rules="rules"
88
:schema="allSchemas.formSchema"
9-
/>
9+
>
10+
<template #spuIds>
11+
<el-button @click="spuSelectRef.open()">选择商品</el-button>
12+
<SpuAndSkuList
13+
ref="spuAndSkuListRef"
14+
:rule-config="ruleConfig"
15+
:spu-list="spuList"
16+
:spu-property-list-p="spuPropertyList"
17+
>
18+
<el-table-column align="center" label="拼团价格(元)" min-width="168">
19+
<template #default="{ row: sku }">
20+
<el-input-number
21+
v-model="sku.productConfig.activePrice"
22+
:min="0"
23+
:precision="2"
24+
:step="0.1"
25+
class="w-100%"
26+
/>
27+
</template>
28+
</el-table-column>
29+
</SpuAndSkuList>
30+
</template>
31+
</Form>
1032
<template #footer>
1133
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
1234
<el-button @click="dialogVisible = false">取 消</el-button>
1335
</template>
1436
</Dialog>
37+
<SpuSelect ref="spuSelectRef" @confirm="selectSpu" />
1538
</template>
1639
<script lang="ts" setup>
1740
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity'
41+
import { CombinationProductVO } from '@/api/mall/promotion/combination/combinationactivity'
1842
import { allSchemas, rules } from './combinationActivity.data'
43+
import { SpuAndSkuList, SpuProperty, SpuSelect } from '@/views/mall/promotion/components'
44+
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
45+
import * as ProductSpuApi from '@/api/mall/product/spu'
46+
import { convertToInteger } from '@/utils'
1947
2048
defineOptions({ name: 'PromotionCombinationActivityForm' })
2149
@@ -28,6 +56,52 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加
2856
const formType = ref('') // 表单的类型:create - 新增;update - 修改
2957
const formRef = ref() // 表单 Ref
3058
59+
// ================= 商品选择相关 =================
60+
61+
const spuSelectRef = ref() // 商品和属性选择 Ref
62+
const spuAndSkuListRef = ref() // sku 秒杀配置组件Ref
63+
const spuList = ref<CombinationActivityApi.SpuExtension[]>([]) // 选择的 spu
64+
const spuPropertyList = ref<SpuProperty<CombinationActivityApi.SpuExtension>[]>([])
65+
const ruleConfig: RuleConfig[] = [
66+
{
67+
name: 'productConfig.activePrice',
68+
rule: (arg) => arg > 0.01,
69+
message: '商品拼团价格不能小于0.01 !!!'
70+
}
71+
]
72+
const selectSpu = (spuId: number, skuIds: number[]) => {
73+
formRef.value.setValues({ spuId })
74+
getSpuDetails([spuId])
75+
console.log(skuIds)
76+
}
77+
/**
78+
* 获取 SPU 详情
79+
* @param spuIds
80+
*/
81+
const getSpuDetails = async (spuIds: number[]) => {
82+
const spuProperties: SpuProperty<CombinationActivityApi.SpuExtension>[] = []
83+
const res = (await ProductSpuApi.getSpuDetailList(
84+
spuIds
85+
)) as CombinationActivityApi.SpuExtension[]
86+
spuList.value = []
87+
res?.forEach((spu) => {
88+
// 初始化每个 sku 秒杀配置
89+
spu.skus?.forEach((sku) => {
90+
const config: CombinationActivityApi.CombinationProductVO = {
91+
spuId: spu.id!,
92+
skuId: sku.id!,
93+
activePrice: 0
94+
}
95+
sku.productConfig = config
96+
})
97+
spuProperties.push({ spuId: spu.id!, spuDetail: spu, propertyList: getPropertyList(spu) })
98+
})
99+
spuList.value.push(...res)
100+
spuPropertyList.value = spuProperties
101+
}
102+
103+
// ================= end =================
104+
31105
/** 打开弹窗 */
32106
const open = async (type: string, id?: number) => {
33107
dialogVisible.value = true
@@ -57,6 +131,12 @@ const submitForm = async () => {
57131
formLoading.value = true
58132
try {
59133
const data = formRef.value.formModel as CombinationActivityApi.CombinationActivityVO
134+
const products = spuAndSkuListRef.value.getSkuConfigs('productConfig')
135+
products.forEach((item: CombinationProductVO) => {
136+
// 拼团价格元转分
137+
item.activePrice = convertToInteger(item.activePrice)
138+
})
139+
data.products = products
60140
if (formType.value === 'create') {
61141
await CombinationActivityApi.createCombinationActivity(data)
62142
message.success(t('common.createSuccess'))

src/views/mall/promotion/combination/activity/combinationActivity.data.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ const crudSchemas = reactive<CrudSchema[]>([
3838
show: true,
3939
component: 'DatePicker',
4040
componentProps: {
41-
valueFormat: 'YYYY-MM-DD HH:mm:ss',
42-
type: 'datetimerange'
41+
valueFormat: 'x',
42+
type: 'datetimerange',
43+
rangeSeparator: '至'
4344
}
4445
},
4546
form: {
4647
component: 'DatePicker',
4748
componentProps: {
48-
valueFormat: 'YYYY-MM-DD HH:mm:ss',
49-
type: 'datetimerange'
49+
valueFormat: 'x',
50+
type: 'datetimerange',
51+
rangeSeparator: '至'
5052
},
51-
value: [getNowDateTime(), getNowDateTime()],
53+
value: [getNowDateTime().valueOf(), getNowDateTime().valueOf()],
5254
colProps: {
5355
span: 24
5456
}
@@ -120,10 +122,7 @@ const crudSchemas = reactive<CrudSchema[]>([
120122
field: 'virtualGroup',
121123
isSearch: false,
122124
isTable: false,
123-
form: {
124-
component: 'InputNumber',
125-
value: 0
126-
}
125+
isForm: false
127126
},
128127
{
129128
label: '活动状态',
@@ -133,25 +132,9 @@ const crudSchemas = reactive<CrudSchema[]>([
133132
isSearch: true,
134133
isForm: false
135134
},
136-
{
137-
label: '创建时间',
138-
field: 'createTime',
139-
formatter: dateFormatter,
140-
isSearch: false,
141-
isTable: false,
142-
search: {
143-
component: 'DatePicker',
144-
componentProps: {
145-
valueFormat: 'YYYY-MM-DD HH:mm:ss',
146-
type: 'daterange',
147-
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
148-
}
149-
},
150-
isForm: false
151-
},
152135
{
153136
label: '拼团商品',
154-
field: 'spuId',
137+
field: 'spuIds',
155138
isSearch: false,
156139
form: {
157140
colProps: {

src/views/mall/promotion/components/SpuSelect.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
</template>
112112

113113
<script lang="ts" setup>
114-
import { getPropertyList, Properties, SkuList } from '@/views/mall/product/spu/components'
114+
import { getPropertyList, PropertyAndValues, SkuList } from '@/views/mall/product/spu/components'
115115
import { ElTable } from 'element-plus'
116116
import { dateFormatter } from '@/utils/formatTime'
117117
import { createImageViewer } from '@/components/ImageViewer'
@@ -144,7 +144,7 @@ const queryParams = ref({
144144
categoryId: null,
145145
createTime: []
146146
}) // 查询参数
147-
const propertyList = ref<Properties[]>([]) // 商品属性列表
147+
const propertyList = ref<PropertyAndValues[]>([]) // 商品属性列表
148148
const spuListRef = ref<InstanceType<typeof ElTable>>()
149149
const skuListRef = ref() // 商品属性选择 Ref
150150
const spuData = ref<ProductSpuApi.Spu>() // 商品详情

src/views/mall/promotion/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import SpuSelect from './SpuSelect.vue'
22
import SpuAndSkuList from './SpuAndSkuList.vue'
3-
import { Properties } from '@/views/mall/product/spu/components'
3+
import { PropertyAndValues } from '@/views/mall/product/spu/components'
44

55
type SpuProperty<T> = {
66
spuId: number
77
spuDetail: T
8-
propertyList: Properties[]
8+
propertyList: PropertyAndValues[]
99
}
1010

1111
/**

0 commit comments

Comments
 (0)