Skip to content

Commit 4f7d679

Browse files
committed
code review:优惠劵逻辑
1 parent 190c6e3 commit 4f7d679

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

src/utils/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ export const CouponTemplateValidityTypeEnum = {
215215
export const PromotionProductScopeEnum = {
216216
ALL: {
217217
scope: 1,
218-
name: '全部商品参与'
218+
name: '通用劵'
219219
},
220220
SPU: {
221221
scope: 2,
222-
name: '指定商品参与'
222+
name: '商品劵'
223223
},
224224
CATEGORY: {
225225
scope: 3,
226-
name: '指定品类参与'
226+
name: '品类劵'
227227
}
228228
}
229229

src/views/mall/product/category/components/ProductCategorySelect.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const props = defineProps({
2424
multiple: propTypes.bool.def(false) // 是否多选
2525
})
2626
27-
/** 选中的分类ID */
27+
/** 选中的分类 ID */
2828
const selectCategoryId = computed({
2929
get: () => {
3030
return props.value
@@ -37,8 +37,8 @@ const selectCategoryId = computed({
3737
/** 分类选择 */
3838
const emit = defineEmits(['update:modelValue'])
3939
40+
/** 初始化 **/
4041
const categoryList = ref([]) // 分类树
41-
4242
onMounted(async () => {
4343
// 获得分类树
4444
const data = await ProductCategoryApi.getCategoryList({})

src/views/mall/promotion/coupon/components/CouponSend.vue renamed to src/views/mall/promotion/coupon/components/CouponSendForm.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<Dialog v-model="dialogVisible" :appendToBody="true" title="发送优惠券" width="70%">
3+
<!-- 搜索工作栏 -->
34
<el-form
45
ref="queryFormRef"
56
:inline="true"
@@ -27,6 +28,8 @@
2728
</el-button>
2829
</el-form-item>
2930
</el-form>
31+
32+
<!-- 列表 -->
3033
<el-table v-loading="loading" :data="list" show-overflow-tooltip>
3134
<el-table-column align="center" label="优惠券名称" prop="name" min-width="60" />
3235
<el-table-column
@@ -41,7 +44,7 @@
4144
label="最低消费"
4245
prop="usePrice"
4346
min-width="60"
44-
:formatter="userPriceFormat"
47+
:formatter="usePriceFormat"
4548
/>
4649
<el-table-column
4750
align="center"
@@ -72,6 +75,7 @@
7275
</el-table-column>
7376
</el-table>
7477
<!-- 分页 -->
78+
<!-- TODO 疯狂:可以看看,为啥弹窗没把分页包进去,可能和 footer 有关? -->
7579
<Pagination
7680
v-model:limit="queryParams.pageSize"
7781
v-model:page="queryParams.pageNo"
@@ -80,18 +84,17 @@
8084
/>
8185
</Dialog>
8286
</template>
83-
8487
<script lang="ts" setup>
8588
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
8689
import * as CouponApi from '@/api/mall/promotion/coupon/coupon'
8790
import {
8891
discountFormat,
8992
remainedCountFormat,
90-
userPriceFormat,
93+
usePriceFormat,
9194
validityTypeFormat
9295
} from '@/views/mall/promotion/coupon/formatter'
9396
94-
defineOptions({ name: 'PromotionCouponSend' })
97+
defineOptions({ name: 'PromotionCouponSendForm' })
9598
9699
const message = useMessage() // 消息弹窗
97100
const total = ref(0) // 列表的总页数
@@ -147,7 +150,7 @@ const handleSendCoupon = async (templateId: number) => {
147150
try {
148151
sendLoading.value = true
149152
await CouponApi.sendCoupon({ templateId, userIds })
150-
153+
// 提示
151154
message.success('发送成功')
152155
dialogVisible.value = false
153156
} finally {

src/views/mall/promotion/coupon/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export const remainedCountFormat = (row: CouponTemplateVO) => {
3939
}
4040

4141
// 格式化【最低消费】
42-
export const userPriceFormat = (row: CouponTemplateVO) => {
42+
export const usePriceFormat = (row: CouponTemplateVO) => {
4343
return `¥${floatToFixed2(row.usePrice)}`
4444
}

src/views/mall/promotion/coupon/template/CouponTemplateForm.vue

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,41 @@
1010
<el-form-item label="优惠券名称" prop="name">
1111
<el-input v-model="formData.name" placeholder="请输入优惠券名称" />
1212
</el-form-item>
13-
<el-form-item label="优惠券类型" prop="discountType">
13+
<el-form-item label="优惠劵类型" prop="productScope">
14+
<el-radio-group v-model="formData.productScope">
15+
<el-radio
16+
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
17+
:key="dict.value"
18+
:label="dict.value"
19+
>
20+
{{ dict.label }}
21+
</el-radio>
22+
</el-radio-group>
23+
</el-form-item>
24+
<el-form-item
25+
label="商品"
26+
v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope"
27+
prop="productSpuIds"
28+
>
29+
<div class="flex items-center gap-1 flex-wrap">
30+
<div class="select-box spu-pic" v-for="(spu, index) in productSpus" :key="spu.id">
31+
<el-image :src="spu.picUrl" />
32+
<Icon icon="ep:circle-close-filled" class="del-icon" @click="handleRemoveSpu(index)" />
33+
</div>
34+
<div class="select-box" @click="openSpuTableSelect">
35+
<Icon icon="ep:plus" />
36+
</div>
37+
</div>
38+
</el-form-item>
39+
<!-- TODO 疯狂:要不把 productSpuIds 改成 productScopeValues,更通用?另外,改完后,涉及到优惠劵的匹配逻辑,要补充分类相关的逻辑,例如说获得匹配的优惠劵列表之类的,包括使用卷的时候; -->
40+
<el-form-item
41+
label="分类"
42+
v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
43+
prop="productCategoryIds"
44+
>
45+
<ProductCategorySelect v-model="formData.productCategoryIds" />
46+
</el-form-item>
47+
<el-form-item label="优惠类型" prop="discountType">
1448
<el-radio-group v-model="formData.discountType">
1549
<el-radio
1650
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
@@ -147,37 +181,6 @@
147181
/>
148182
天有效
149183
</el-form-item>
150-
<el-form-item label="活动商品" prop="productScope">
151-
<el-radio-group v-model="formData.productScope">
152-
<el-radio
153-
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
154-
:key="dict.value"
155-
:label="dict.value"
156-
>
157-
{{ dict.label }}
158-
</el-radio>
159-
</el-radio-group>
160-
</el-form-item>
161-
<el-form-item
162-
v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope"
163-
prop="productSpuIds"
164-
>
165-
<div class="flex items-center gap-1 flex-wrap">
166-
<div class="select-box spu-pic" v-for="(spu, index) in productSpus" :key="spu.id">
167-
<el-image :src="spu.picUrl" />
168-
<Icon icon="ep:circle-close-filled" class="del-icon" @click="handleRemoveSpu(index)" />
169-
</div>
170-
<div class="select-box" @click="openSpuTableSelect">
171-
<Icon icon="ep:plus" />
172-
</div>
173-
</div>
174-
</el-form-item>
175-
<el-form-item
176-
v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
177-
prop="productCategoryIds"
178-
>
179-
<ProductCategorySelect v-model="formData.productCategoryIds" multiple />
180-
</el-form-item>
181184
</el-form>
182185
<template #footer>
183186
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
@@ -367,6 +370,7 @@ const getProductScope = async () => {
367370
productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productSpuIds)
368371
break
369372
case PromotionProductScopeEnum.CATEGORY.scope:
373+
// TODO @疯狂:貌似分类不会选中。
370374
formData.value.productCategoryIds = formData.value.productSpuIds
371375
formData.value.productSpuIds = []
372376
break
@@ -375,7 +379,7 @@ const getProductScope = async () => {
375379
}
376380
}
377381
378-
/** 活动商品 按钮 */
382+
/** 活动商品的按钮 */
379383
const spuTableSelectRef = ref()
380384
const openSpuTableSelect = () => {
381385
spuTableSelectRef.value.open(productSpus.value)

src/views/member/user/index.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
<!-- 修改用户等级弹窗 -->
155155
<UpdateLevelForm ref="updateLevelFormRef" @success="getList" />
156156
<!-- 发送优惠券弹窗 -->
157-
<CouponSend ref="couponSend" />
157+
<CouponSendForm ref="couponSendFormRef" />
158158
</template>
159159
<script setup lang="ts">
160160
import { dateFormatter } from '@/utils/formatTime'
@@ -164,7 +164,7 @@ import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
164164
import MemberLevelSelect from '@/views/member/level/components/MemberLevelSelect.vue'
165165
import MemberGroupSelect from '@/views/member/group/components/MemberGroupSelect.vue'
166166
import UpdateLevelForm from '@/views/member/user/UpdateLevelForm.vue'
167-
import CouponSend from '@/views/mall/promotion/coupon/components/CouponSend.vue'
167+
import CouponSendForm from '@/views/mall/promotion/coupon/components/CouponSendForm.vue'
168168
169169
defineOptions({ name: 'MemberUser' })
170170
@@ -224,14 +224,13 @@ const handleSelectionChange = (rows: UserApi.UserVO[]) => {
224224
}
225225
226226
/** 发送优惠券 */
227-
const couponSend = ref()
227+
const couponSendFormRef = ref()
228228
const openCoupon = () => {
229229
if (selectedIds.value.length === 0) {
230230
message.warning('请选择要发送优惠券的用户')
231231
return
232232
}
233-
234-
couponSend.value.open(selectedIds.value)
233+
couponSendFormRef.value.open(selectedIds.value)
235234
}
236235
237236
/** 初始化 **/

0 commit comments

Comments
 (0)