Skip to content

Commit 3464bb9

Browse files
author
puhui999
committed
SPU: 新增优惠卷选择
1 parent 5b3bcec commit 3464bb9

File tree

5 files changed

+251
-14
lines changed

5 files changed

+251
-14
lines changed

src/api/mall/product/spu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export interface Sku {
2828
export interface Spu {
2929
id?: number
3030
name?: string // 商品名称
31-
categoryId?: number | null // 商品分类
31+
categoryId?: number | undefined // 商品分类
3232
keyword?: string // 关键字
33-
unit?: number | null // 单位
33+
unit?: number | undefined // 单位
3434
picUrl?: string // 商品封面图
3535
sliderPicUrls?: string[] // 商品轮播图
3636
introduction?: string // 商品简介
37-
deliveryTemplateId?: number | null // 运费模版
38-
brandId?: number | null // 商品品牌编号
37+
deliveryTemplateId?: number | undefined // 运费模版
38+
brandId?: number | undefined // 商品品牌编号
3939
specType?: boolean // 商品规格
4040
subCommissionType?: boolean // 分销类型
4141
skus?: Sku[] // sku数组

src/utils/dict.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export enum DICT_TYPE {
155155
// ========== MALL - 商品模块 ==========
156156
PRODUCT_UNIT = 'product_unit', // 商品单位
157157
PRODUCT_SPU_STATUS = 'product_spu_status', //商品状态
158+
PROMOTION_TYPE_ENUM = 'promotion_type_enum', // 营销类型枚举
158159

159160
// ========== MALL - 交易模块 ==========
160161
EXPRESS_CHARGE_MODE = 'trade_delivery_express_charge_mode', //快递的计费方式
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<template>
2+
<Dialog v-model="dialogVisible" :title="dialogTitle" width="65%">
3+
<!-- 搜索工作栏 -->
4+
<ContentWrap>
5+
<el-form
6+
ref="queryFormRef"
7+
:inline="true"
8+
:model="queryParams"
9+
class="-mb-15px"
10+
label-width="82px"
11+
>
12+
<el-form-item label="优惠券名称" prop="name">
13+
<el-input
14+
v-model="queryParams.name"
15+
class="!w-240px"
16+
clearable
17+
placeholder="请输入优惠劵名"
18+
@keyup="handleQuery"
19+
/>
20+
</el-form-item>
21+
<el-form-item label="优惠类型" prop="discountType">
22+
<el-select
23+
v-model="queryParams.discountType"
24+
class="!w-240px"
25+
clearable
26+
placeholder="请选择优惠券类型"
27+
>
28+
<el-option
29+
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
30+
:key="dict.value"
31+
:label="dict.label"
32+
:value="dict.value"
33+
/>
34+
</el-select>
35+
</el-form-item>
36+
<el-form-item label="优惠券状态" prop="status">
37+
<el-select
38+
v-model="queryParams.status"
39+
class="!w-240px"
40+
clearable
41+
placeholder="请选择优惠券状态"
42+
>
43+
<el-option
44+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
45+
:key="dict.value"
46+
:label="dict.label"
47+
:value="dict.value"
48+
/>
49+
</el-select>
50+
</el-form-item>
51+
<el-form-item label="创建时间" prop="createTime">
52+
<el-date-picker
53+
v-model="queryParams.createTime"
54+
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
55+
class="!w-240px"
56+
end-placeholder="结束日期"
57+
start-placeholder="开始日期"
58+
type="daterange"
59+
value-format="YYYY-MM-DD HH:mm:ss"
60+
/>
61+
</el-form-item>
62+
<el-form-item>
63+
<el-button @click="handleQuery">
64+
<Icon class="mr-5px" icon="ep:search" />
65+
搜索
66+
</el-button>
67+
<el-button @click="resetQuery">
68+
<Icon class="mr-5px" icon="ep:refresh" />
69+
重置
70+
</el-button>
71+
</el-form-item>
72+
</el-form>
73+
</ContentWrap>
74+
75+
<!-- 列表 -->
76+
<ContentWrap>
77+
<el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
78+
<el-table-column type="selection" width="55" />
79+
<el-table-column label="优惠券名称" min-width="140" prop="name" />
80+
<el-table-column label="类型" min-width="80" prop="productScope">
81+
<template #default="scope">
82+
<dict-tag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="scope.row.productScope" />
83+
</template>
84+
</el-table-column>
85+
<el-table-column label="优惠" min-width="100" prop="discount">
86+
<template #default="scope">
87+
<dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" />
88+
{{ discountFormat(scope.row) }}
89+
</template>
90+
</el-table-column>
91+
<el-table-column label="领取方式" min-width="100" prop="takeType">
92+
<template #default="scope">
93+
<dict-tag :type="DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE" :value="scope.row.takeType" />
94+
</template>
95+
</el-table-column>
96+
<el-table-column
97+
:formatter="validityTypeFormat"
98+
align="center"
99+
label="使用时间"
100+
prop="validityType"
101+
width="185"
102+
/>
103+
<el-table-column align="center" label="发放数量" prop="totalCount" />
104+
<el-table-column
105+
:formatter="remainedCountFormat"
106+
align="center"
107+
label="剩余数量"
108+
prop="totalCount"
109+
/>
110+
<el-table-column
111+
:formatter="takeLimitCountFormat"
112+
align="center"
113+
label="领取上限"
114+
prop="takeLimitCount"
115+
/>
116+
<el-table-column align="center" label="状态" prop="status">
117+
<template #default="scope">
118+
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
119+
</template>
120+
</el-table-column>
121+
<el-table-column
122+
:formatter="dateFormatter"
123+
align="center"
124+
label="创建时间"
125+
prop="createTime"
126+
width="180"
127+
/>
128+
</el-table>
129+
<!-- 分页 -->
130+
<Pagination
131+
v-model:limit="queryParams.pageSize"
132+
v-model:page="queryParams.pageNo"
133+
:total="total"
134+
@pagination="getList"
135+
/>
136+
</ContentWrap>
137+
<template #footer>
138+
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
139+
<el-button @click="dialogVisible = false">取 消</el-button>
140+
</template>
141+
</Dialog>
142+
</template>
143+
<script lang="ts" setup>
144+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
145+
import {
146+
discountFormat,
147+
remainedCountFormat,
148+
takeLimitCountFormat,
149+
validityTypeFormat
150+
} from '@/views/mall/promotion/coupon/formatter'
151+
import { dateFormatter } from '@/utils/formatTime'
152+
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
153+
154+
defineOptions({ name: 'CouponSelect' })
155+
156+
defineProps<{
157+
multipleSelection: { id: number; name: string }[]
158+
}>()
159+
const emit = defineEmits<{
160+
(e: 'update:multipleSelection', v: { id: number; name: string }[])
161+
}>()
162+
const dialogVisible = ref(false) // 弹窗的是否展示
163+
const dialogTitle = ref('选择优惠卷') // 弹窗的标题
164+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
165+
const loading = ref(true) // 列表的加载中
166+
const total = ref(0) // 列表的总页数
167+
const list = ref([]) // 字典表格数据
168+
const queryParams = reactive({
169+
pageNo: 1,
170+
pageSize: 10,
171+
name: null,
172+
status: null,
173+
discountType: null,
174+
type: null,
175+
createTime: []
176+
})
177+
const queryFormRef = ref() // 搜索的表单
178+
179+
/** 查询列表 */
180+
const getList = async () => {
181+
loading.value = true
182+
try {
183+
// 执行查询
184+
const data = await CouponTemplateApi.getCouponTemplatePage(queryParams)
185+
list.value = data.list
186+
total.value = data.total
187+
} finally {
188+
loading.value = false
189+
}
190+
}
191+
192+
/** 搜索按钮操作 */
193+
const handleQuery = () => {
194+
queryParams.pageNo = 1
195+
getList()
196+
}
197+
198+
/** 重置按钮操作 */
199+
const resetQuery = () => {
200+
queryFormRef?.value?.resetFields()
201+
handleQuery()
202+
}
203+
/** 打开弹窗 */
204+
const open = async () => {
205+
dialogVisible.value = true
206+
resetQuery()
207+
}
208+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
209+
const handleSelectionChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
210+
emit(
211+
'update:multipleSelection',
212+
val.map((item) => ({ id: item.id, name: item.name }))
213+
)
214+
}
215+
const submitForm = async () => {}
216+
</script>
217+
<style lang="scss" scoped></style>

src/views/mall/product/spu/form/OtherSettingsForm.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,22 @@
4343
<el-col :span="24">
4444
<!-- TODO @puhui999:tag展示暂时不考虑排序;支持拖动排序 -->
4545
<el-form-item label="活动优先级">
46-
<el-tag>默认</el-tag>
47-
<el-tag class="ml-2" type="success">秒杀</el-tag>
48-
<el-tag class="ml-2" type="info">砍价</el-tag>
49-
<el-tag class="ml-2" type="warning">拼团</el-tag>
46+
<el-tag
47+
v-for="type in getIntDictOptions(DICT_TYPE.PROMOTION_TYPE_ENUM)"
48+
:key="type.value as number"
49+
:type="type.colorType"
50+
class="mr-[10px]"
51+
>
52+
{{ type.label }}
53+
</el-tag>
5054
</el-form-item>
5155
</el-col>
52-
<!-- TODO @puhui999:等优惠劵 ok 在搞 -->
5356
<el-col :span="24">
5457
<el-form-item label="赠送优惠劵">
55-
<el-button>选择优惠券</el-button>
58+
<el-tag v-for="coupon in couponTemplateList" :key="coupon.id as number" class="mr-[10px]">
59+
{{ coupon.name }}
60+
</el-tag>
61+
<el-button @click="openCouponSelect">选择优惠券</el-button>
5662
</el-form-item>
5763
</el-col>
5864
</el-row>
@@ -82,13 +88,16 @@
8288
<el-tag class="ml-2" type="warning">拼团</el-tag>
8389
</template>
8490
</Descriptions>
91+
<CouponSelect ref="couponSelectRef" />
8592
</template>
8693
<script lang="ts" setup>
8794
import type { Spu } from '@/api/mall/product/spu'
8895
import { PropType } from 'vue'
8996
import { propTypes } from '@/utils/propTypes'
9097
import { copyValueToTarget } from '@/utils'
9198
import { otherSettingsSchema } from './spu.data'
99+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
100+
import CouponSelect from './CouponSelect.vue'
92101
93102
defineOptions({ name: 'OtherSettingsForm' })
94103
@@ -104,6 +113,11 @@ const props = defineProps({
104113
activeName: propTypes.string.def(''),
105114
isDetail: propTypes.bool.def(false) // 是否作为详情组件
106115
})
116+
const couponSelectRef = ref() // 优惠卷模版选择
117+
const couponTemplateList = ref<{ id: number; name: string }[]>([]) // 选择的优惠卷
118+
const openCouponSelect = () => {
119+
couponSelectRef.value?.open()
120+
}
107121
108122
const otherSettingsFormRef = ref() // 表单Ref
109123
// 表单数据

src/views/mall/product/spu/index.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
:props="defaultProps"
2525
class="w-1/1"
2626
clearable
27-
placeholder="请选择商品分类"
2827
filterable
28+
placeholder="请选择商品分类"
2929
/>
3030
</el-form-item>
3131
<el-form-item label="创建时间" prop="createTime">
@@ -48,7 +48,12 @@
4848
<Icon class="mr-5px" icon="ep:refresh" />
4949
重置
5050
</el-button>
51-
<el-button v-hasPermi="['product:spu:create']" plain type="primary" @click="openForm">
51+
<el-button
52+
v-hasPermi="['product:spu:create']"
53+
plain
54+
type="primary"
55+
@click="openForm(undefined)"
56+
>
5257
<Icon class="mr-5px" icon="ep:plus" />
5358
新增
5459
</el-button>
@@ -278,8 +283,8 @@ const queryParams = ref({
278283
pageSize: 10,
279284
tabType: 0,
280285
name: '',
281-
categoryId: null,
282-
createTime: []
286+
categoryId: undefined,
287+
createTime: undefined
283288
}) // 查询参数
284289
const queryFormRef = ref() // 搜索的表单Ref
285290

0 commit comments

Comments
 (0)