code review:优惠劵逻辑

This commit is contained in:
YunaiV
2023-09-02 00:12:21 +08:00
parent 190c6e384c
commit 4f7d6793fd
6 changed files with 55 additions and 49 deletions

View File

@@ -24,7 +24,7 @@ const props = defineProps({
multiple: propTypes.bool.def(false) // 是否多选
})
/** 选中的分类ID */
/** 选中的分类 ID */
const selectCategoryId = computed({
get: () => {
return props.value
@@ -37,8 +37,8 @@ const selectCategoryId = computed({
/** 分类选择 */
const emit = defineEmits(['update:modelValue'])
/** 初始化 **/
const categoryList = ref([]) // 分类树
onMounted(async () => {
// 获得分类树
const data = await ProductCategoryApi.getCategoryList({})

View File

@@ -1,5 +1,6 @@
<template>
<Dialog v-model="dialogVisible" :appendToBody="true" title="发送优惠券" width="70%">
<!-- 搜索工作栏 -->
<el-form
ref="queryFormRef"
:inline="true"
@@ -27,6 +28,8 @@
</el-button>
</el-form-item>
</el-form>
<!-- 列表 -->
<el-table v-loading="loading" :data="list" show-overflow-tooltip>
<el-table-column align="center" label="优惠券名称" prop="name" min-width="60" />
<el-table-column
@@ -41,7 +44,7 @@
label="最低消费"
prop="usePrice"
min-width="60"
:formatter="userPriceFormat"
:formatter="usePriceFormat"
/>
<el-table-column
align="center"
@@ -72,6 +75,7 @@
</el-table-column>
</el-table>
<!-- 分页 -->
<!-- TODO 疯狂可以看看为啥弹窗没把分页包进去可能和 footer 有关 -->
<Pagination
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
@@ -80,18 +84,17 @@
/>
</Dialog>
</template>
<script lang="ts" setup>
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
import * as CouponApi from '@/api/mall/promotion/coupon/coupon'
import {
discountFormat,
remainedCountFormat,
userPriceFormat,
usePriceFormat,
validityTypeFormat
} from '@/views/mall/promotion/coupon/formatter'
defineOptions({ name: 'PromotionCouponSend' })
defineOptions({ name: 'PromotionCouponSendForm' })
const message = useMessage() //
const total = ref(0) //
@@ -147,7 +150,7 @@ const handleSendCoupon = async (templateId: number) => {
try {
sendLoading.value = true
await CouponApi.sendCoupon({ templateId, userIds })
//
message.success('发送成功')
dialogVisible.value = false
} finally {

View File

@@ -39,6 +39,6 @@ export const remainedCountFormat = (row: CouponTemplateVO) => {
}
// 格式化【最低消费】
export const userPriceFormat = (row: CouponTemplateVO) => {
export const usePriceFormat = (row: CouponTemplateVO) => {
return `${floatToFixed2(row.usePrice)}`
}

View File

@@ -10,7 +10,41 @@
<el-form-item label="优惠券名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入优惠券名称" />
</el-form-item>
<el-form-item label="优惠类型" prop="discountType">
<el-form-item label="优惠类型" prop="productScope">
<el-radio-group v-model="formData.productScope">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
label="商品"
v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope"
prop="productSpuIds"
>
<div class="flex items-center gap-1 flex-wrap">
<div class="select-box spu-pic" v-for="(spu, index) in productSpus" :key="spu.id">
<el-image :src="spu.picUrl" />
<Icon icon="ep:circle-close-filled" class="del-icon" @click="handleRemoveSpu(index)" />
</div>
<div class="select-box" @click="openSpuTableSelect">
<Icon icon="ep:plus" />
</div>
</div>
</el-form-item>
<!-- TODO 疯狂要不把 productSpuIds 改成 productScopeValues更通用另外改完后涉及到优惠劵的匹配逻辑要补充分类相关的逻辑例如说获得匹配的优惠劵列表之类的包括使用卷的时候 -->
<el-form-item
label="分类"
v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
prop="productCategoryIds"
>
<ProductCategorySelect v-model="formData.productCategoryIds" />
</el-form-item>
<el-form-item label="优惠类型" prop="discountType">
<el-radio-group v-model="formData.discountType">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
@@ -147,37 +181,6 @@
/>
天有效
</el-form-item>
<el-form-item label="活动商品" prop="productScope">
<el-radio-group v-model="formData.productScope">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope"
prop="productSpuIds"
>
<div class="flex items-center gap-1 flex-wrap">
<div class="select-box spu-pic" v-for="(spu, index) in productSpus" :key="spu.id">
<el-image :src="spu.picUrl" />
<Icon icon="ep:circle-close-filled" class="del-icon" @click="handleRemoveSpu(index)" />
</div>
<div class="select-box" @click="openSpuTableSelect">
<Icon icon="ep:plus" />
</div>
</div>
</el-form-item>
<el-form-item
v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
prop="productCategoryIds"
>
<ProductCategorySelect v-model="formData.productCategoryIds" multiple />
</el-form-item>
</el-form>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
@@ -367,6 +370,7 @@ const getProductScope = async () => {
productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productSpuIds)
break
case PromotionProductScopeEnum.CATEGORY.scope:
// TODO @疯狂:貌似分类不会选中。
formData.value.productCategoryIds = formData.value.productSpuIds
formData.value.productSpuIds = []
break
@@ -375,7 +379,7 @@ const getProductScope = async () => {
}
}
/** 活动商品 按钮 */
/** 活动商品按钮 */
const spuTableSelectRef = ref()
const openSpuTableSelect = () => {
spuTableSelectRef.value.open(productSpus.value)