Skip to content

Commit 3500a20

Browse files
author
puhui999
committed
营销活动:完善 review 提到的问题,添加拼团列表查看弹窗
1 parent 86323f9 commit 3500a20

File tree

10 files changed

+213
-93
lines changed

10 files changed

+213
-93
lines changed

src/api/mall/promotion/bargain/bargainActivity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface BargainProductVO {
2424
spuId: number
2525
skuId: number
2626
bargainFirstPrice: number // 砍价起始价格,单位分
27-
bargainPrice: number // 砍价底价
27+
bargainMinPrice: number // 砍价底价
2828
stock: number // 活动库存
2929
}
3030

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const getCombinationRecordPage = async (params) => {
2222
return await request.get({ url: '/promotion/combination-record/page', params })
2323
}
2424

25+
// 查询一个拼团的完整拼团记录
26+
export const getCombinationRecordPageByHeadId = async (params) => {
27+
return await request.get({ url: '/promotion/combination-record/page-by-headId', params })
28+
}
29+
2530
// 获得拼团记录的概要信息
2631
export const getCombinationRecordSummary = async () => {
2732
return await request.get({ url: '/promotion/combination-record/get-summary' })

src/utils/formatTime.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
import dayjs from 'dayjs'
22

3+
/**
4+
* 日期快捷选项适用于 el-date-picker
5+
*/
6+
export const defaultShortcuts = [
7+
{
8+
text: '今天',
9+
value: () => {
10+
return new Date()
11+
}
12+
},
13+
{
14+
text: '昨天',
15+
value: () => {
16+
const date = new Date()
17+
date.setTime(date.getTime() - 3600 * 1000 * 24)
18+
return [date, date]
19+
}
20+
},
21+
{
22+
text: '最近七天',
23+
value: () => {
24+
const date = new Date()
25+
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
26+
return [date, new Date()]
27+
}
28+
},
29+
{
30+
text: '最近 30 天',
31+
value: () => {
32+
const date = new Date()
33+
date.setTime(date.getTime() - 3600 * 1000 * 24 * 30)
34+
return [date, new Date()]
35+
}
36+
},
37+
{
38+
text: '本月',
39+
value: () => {
40+
const date = new Date()
41+
date.setDate(1) // 设置为当前月的第一天
42+
return [date, new Date()]
43+
}
44+
},
45+
{
46+
text: '今年',
47+
value: () => {
48+
const date = new Date()
49+
return [new Date(`${date.getFullYear()}-01-01`), date]
50+
}
51+
}
52+
]
53+
354
/**
455
* 时间日期转换
556
* @param date 当前时间,new Date() 格式

src/utils/formatter.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { fenToYuan } from '@/utils'
2-
import { TableColumnCtx } from 'element-plus'
1+
import { floatToFixed2 } from '@/utils'
32

43
// 格式化金额【分转元】
5-
export const fenToYuanFormat = (
6-
row: any,
7-
column: TableColumnCtx<any>,
8-
cellValue: any,
9-
index: number
10-
) => {
11-
return `¥${fenToYuan(cellValue)}`
4+
// @ts-ignore
5+
export const fenToYuanFormat = (_, _, cellValue: any, _) => {
6+
return `¥${floatToFixed2(cellValue)}`
127
}

src/utils/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,12 @@ export const convertToInteger = (num: number | string | undefined): number => {
224224
* 元转分
225225
*/
226226
export const yuanToFen = (amount: string | number): number => {
227-
return Math.round(Number(amount) * 100)
227+
return convertToInteger(amount)
228228
}
229229

230230
/**
231231
* 分转元
232232
*/
233233
export const fenToYuan = (price: string | number): number => {
234-
price = Number(price)
235-
return (price / 100.0).toFixed(2)
234+
return formatToFraction(price)
236235
}

src/views/mall/promotion/bargain/activity/BargainActivityForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { SpuAndSkuList, SpuProperty, SpuSelect } from '@/views/mall/promotion/co
6161
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
6262
import * as ProductSpuApi from '@/api/mall/product/spu'
6363
import { convertToInteger, formatToFraction } from '@/utils'
64+
import { cloneDeep } from 'lodash-es'
6465
6566
defineOptions({ name: 'PromotionBargainActivityForm' })
6667
@@ -204,8 +205,7 @@ const submitForm = async () => {
204205
// 提交请求
205206
formLoading.value = true
206207
try {
207-
// TODO @puhui999: 这样要深克隆
208-
const data = formRef.value.formModel as BargainActivityApi.BargainActivityVO
208+
const data = cloneDeep(formRef.value.formModel) as BargainActivityApi.BargainActivityVO
209209
const products = spuAndSkuListRef.value.getSkuConfigs('productConfig')
210210
products.forEach((item: BargainProductVO) => {
211211
// 砍价价格元转分

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ const submitForm = async () => {
167167
products.forEach((item: CombinationActivityApi.CombinationProductVO) => {
168168
item.combinationPrice = convertToInteger(item.combinationPrice)
169169
})
170-
// TODO @puhui999: 这样要深克隆
171-
const data = formRef.value.formModel as CombinationActivityApi.CombinationActivityVO
170+
const data = cloneDeep(formRef.value.formModel) as CombinationActivityApi.CombinationActivityVO
172171
data.products = products
173172
// 真正提交
174173
if (formType.value === 'create') {
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<template>
2+
<Dialog v-model="dialogVisible" title="拼团列表">
3+
<!-- 列表 -->
4+
<ContentWrap>
5+
<el-table v-loading="loading" :data="list">
6+
<el-table-column align="center" label="编号" prop="id" />
7+
<el-table-column align="center" label="头像" prop="avatar" />
8+
<el-table-column align="center" label="昵称" prop="nickname" />
9+
<el-table-column align="center" label="开团团长" prop="headId">
10+
<template #default="{ row }: { row: CombinationRecordApi.CombinationRecordVO }">
11+
{{ row.headId ? list.find((item) => item.id === row.headId)?.nickname : row.nickname }}
12+
</template>
13+
</el-table-column>
14+
<el-table-column
15+
:formatter="dateFormatter"
16+
align="center"
17+
label="开团时间"
18+
prop="startTime"
19+
width="180"
20+
/>
21+
<el-table-column
22+
align="center"
23+
label="拼团商品"
24+
prop="type"
25+
show-overflow-tooltip
26+
width="300"
27+
>
28+
<template #defaul="{ row }">
29+
<el-image
30+
:src="row.picUrl"
31+
class="mr-5px h-30px w-30px align-middle"
32+
@click="imagePreview(row.picUrl)"
33+
/>
34+
<span class="align-middle">{{ row.spuName }}</span>
35+
</template>
36+
</el-table-column>
37+
<el-table-column align="center" label="几人团" prop="userSize" />
38+
<el-table-column align="center" label="参与人数" prop="userCount" />
39+
<el-table-column
40+
:formatter="dateFormatter"
41+
align="center"
42+
label="参团时间"
43+
prop="createTime"
44+
width="180"
45+
/>
46+
<el-table-column
47+
:formatter="dateFormatter"
48+
align="center"
49+
label="结束时间"
50+
prop="endTime"
51+
width="180"
52+
/>
53+
<el-table-column align="center" label="拼团状态" prop="status">
54+
<template #default="scope">
55+
<dict-tag
56+
:type="DICT_TYPE.PROMOTION_COMBINATION_RECORD_STATUS"
57+
:value="scope.row.status"
58+
/>
59+
</template>
60+
</el-table-column>
61+
</el-table>
62+
<!-- 分页 -->
63+
<Pagination
64+
v-model:limit="queryParams.pageSize"
65+
v-model:page="queryParams.pageNo"
66+
:total="total"
67+
@pagination="getList"
68+
/>
69+
</ContentWrap>
70+
</Dialog>
71+
</template>
72+
73+
<script lang="ts" setup>
74+
import { dateFormatter } from '@/utils/formatTime'
75+
import * as CombinationRecordApi from '@/api/mall/promotion/combination/combinationRecord'
76+
import { DICT_TYPE } from '@/utils/dict'
77+
import { createImageViewer } from '@/components/ImageViewer'
78+
79+
/** 助力列表 */
80+
defineOptions({ name: 'CombinationRecordListDialog' })
81+
82+
const message = useMessage() // 消息弹窗
83+
84+
const loading = ref(true) // 列表的加载中
85+
const total = ref(0) // 列表的总页数
86+
const list = ref([]) // 列表的数据
87+
const queryParams = reactive({
88+
pageNo: 1,
89+
pageSize: 10,
90+
headId: undefined
91+
})
92+
93+
/** 打开弹窗 */
94+
const dialogVisible = ref(false) // 弹窗的是否展示
95+
const open = async (headId: any) => {
96+
dialogVisible.value = true
97+
queryParams.headId = headId
98+
await getList()
99+
}
100+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
101+
102+
/** 查询列表 */
103+
const getList = async () => {
104+
loading.value = true
105+
try {
106+
const data = await CombinationRecordApi.getCombinationRecordPageByHeadId(queryParams)
107+
list.value = data.list
108+
total.value = data.total
109+
} finally {
110+
loading.value = false
111+
}
112+
}
113+
/** 商品图预览 */
114+
const imagePreview = (imgUrl: string) => {
115+
createImageViewer({
116+
urlList: [imgUrl]
117+
})
118+
}
119+
</script>

src/views/mall/promotion/combination/record/index.vue

Lines changed: 20 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<el-form-item label="创建时间" prop="createTime">
7979
<el-date-picker
8080
v-model="queryParams.createTime"
81-
:shortcuts="shortcuts"
81+
:shortcuts="defaultShortcuts"
8282
class="!w-240px"
8383
end-placeholder="结束日期"
8484
start-placeholder="开始日期"
@@ -171,9 +171,17 @@
171171
/>
172172
</template>
173173
</el-table-column>
174-
<!-- TODO puhui999:这里加个查看拼团?点击后,查看完整的拼团列表? -->
175174
<el-table-column align="center" fixed="right" label="操作">
176-
<template #default></template>
175+
<template #default="scope">
176+
<el-button
177+
v-hasPermi="['promotion:combination-record:query']"
178+
link
179+
type="primary"
180+
@click="openRecordListDialog(scope.row)"
181+
>
182+
查看拼团
183+
</el-button>
184+
</template>
177185
</el-table-column>
178186
</el-table>
179187
<!-- 分页 -->
@@ -184,23 +192,27 @@
184192
@pagination="getList"
185193
/>
186194
</ContentWrap>
195+
196+
<!-- 表单弹窗 -->
197+
<CombinationRecordListDialog ref="combinationRecordListRef" />
187198
</template>
188199
<script lang="ts" setup>
200+
import CombinationRecordListDialog from './CombinationRecordListDialog.vue'
189201
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
190-
import { dateFormatter } from '@/utils/formatTime'
202+
import { dateFormatter, defaultShortcuts } from '@/utils/formatTime'
191203
import { createImageViewer } from '@/components/ImageViewer'
192204
import * as CombinationRecordApi from '@/api/mall/promotion/combination/combinationRecord'
193205
194206
defineOptions({ name: 'CombinationRecord' })
195207
196208
const queryParams = ref({
197-
dateType: 0, // 日期类型
198209
status: undefined, // 拼团状态
199210
createTime: undefined, // 创建时间
200211
pageSize: 10,
201212
pageNo: 1
202213
})
203214
const queryFormRef = ref() // 搜索的表单
215+
const combinationRecordListRef = ref() // 查询表单 Ref
204216
const loading = ref(true) // 列表的加载中
205217
const total = ref(0) // 总记录数
206218
const pageList = ref<CombinationRecordApi.CombinationRecordVO[]>([]) // 分页数据
@@ -225,68 +237,10 @@ const recordSummary = ref({
225237
const getSummary = async () => {
226238
recordSummary.value = await CombinationRecordApi.getCombinationRecordSummary()
227239
}
228-
// 日期快捷选项
229-
// TODO @puhui999:不用 dateType,而是 shortcuts 选择后,设置到对应的 date 就 ok 啦。直接通过它查询。然后,看看怎么把 shortcuts 变成一个公共变量,类似 defaultProps 一样
230-
const shortcuts = ref([
231-
{
232-
text: '今天',
233-
type: 'toDay',
234-
value: () => {
235-
queryParams.value.dateType = 1
236-
return new Date()
237-
}
238-
},
239-
{
240-
text: '昨天',
241-
type: 'yesterday',
242-
value: () => {
243-
const date = new Date()
244-
date.setTime(date.getTime() - 3600 * 1000 * 24)
245-
queryParams.value.dateType = 2
246-
return [date, date]
247-
}
248-
},
249-
{
250-
text: '最近七天',
251-
type: 'lastSevenDays',
252-
value: () => {
253-
const date = new Date()
254-
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
255-
queryParams.value.dateType = 3
256-
return [date, new Date()]
257-
}
258-
},
259-
{
260-
text: '最近 30 天',
261-
type: 'last30Days',
262-
value: () => {
263-
const date = new Date()
264-
date.setTime(date.getTime() - 3600 * 1000 * 24 * 30)
265-
queryParams.value.dateType = 4
266-
return [date, new Date()]
267-
}
268-
},
269-
{
270-
text: '本月',
271-
type: 'thisMonth',
272-
value: () => {
273-
const date = new Date()
274-
date.setDate(1) // 设置为当前月的第一天
275-
queryParams.value.dateType = 5
276-
return [date, new Date()]
277-
}
278-
},
279-
{
280-
text: '今年',
281-
type: 'thisYear',
282-
value: () => {
283-
const date = new Date()
284-
queryParams.value.dateType = 6
285-
return [new Date(`${date.getFullYear()}-01-01`), date]
286-
}
287-
}
288-
])
289240
241+
const openRecordListDialog = (row: CombinationRecordApi.CombinationRecordVO) => {
242+
combinationRecordListRef.value?.open(row.headId)
243+
}
290244
/** 搜索按钮操作 */
291245
const handleQuery = () => {
292246
queryParams.value.pageNo = 1

0 commit comments

Comments
 (0)