Skip to content

Commit 01d7842

Browse files
author
puhui999
committed
SPU: 完善优惠卷选择
1 parent 18df708 commit 01d7842

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

src/api/mall/product/spu.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export interface Spu {
6060
stock?: number // 商品库存
6161
createTime?: Date // 商品创建时间
6262
status?: number // 商品状态
63-
giveCouponTemplate?: GiveCouponTemplate[]
63+
activityOrders: number[] // 活动排序
64+
giveCouponTemplates: GiveCouponTemplate[] // 优惠卷
6465
}
6566

6667
// 获得 Spu 列表

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

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<!-- TODO @puhui999:tag展示暂时不考虑排序;支持拖动排序 -->
4545
<el-form-item label="活动优先级">
4646
<el-tag
47-
v-for="type in getIntDictOptions(DICT_TYPE.PROMOTION_TYPE_ENUM)"
47+
v-for="type in promotionTypes"
4848
:key="type.value as number"
4949
:type="type.colorType"
5050
class="mr-[10px]"
@@ -55,7 +55,11 @@
5555
</el-col>
5656
<el-col :span="24">
5757
<el-form-item label="赠送优惠劵">
58-
<el-tag v-for="coupon in couponTemplateList" :key="coupon.id as number" class="mr-[10px]">
58+
<el-tag
59+
v-for="coupon in formData.giveCouponTemplates"
60+
:key="coupon.id as number"
61+
class="mr-[10px]"
62+
>
5963
{{ coupon.name }}
6064
</el-tag>
6165
<el-button @click="openCouponSelect">选择优惠券</el-button>
@@ -67,35 +71,49 @@
6771
<!-- 情况二:详情 -->
6872
<Descriptions v-if="isDetail" :data="formData" :schema="allSchemas.detailSchema">
6973
<template #recommendHot="{ row }">
70-
{{ row.recommendHot ? '是' : '否' }}
74+
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.recommendHot" />
7175
</template>
7276
<template #recommendBenefit="{ row }">
73-
{{ row.recommendBenefit ? '是' : '否' }}
77+
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.recommendBenefit" />
7478
</template>
7579
<template #recommendBest="{ row }">
76-
{{ row.recommendBest ? '是' : '否' }}
80+
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.recommendBest" />
7781
</template>
7882
<template #recommendNew="{ row }">
79-
{{ row.recommendNew ? '是' : '否' }}
83+
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.recommendNew" />
8084
</template>
8185
<template #recommendGood="{ row }">
82-
{{ row.recommendGood ? '是' : '否' }}
86+
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.recommendGood" />
87+
</template>
88+
<template #activityOrders="{ row }">
89+
<el-tag
90+
v-for="activityType in row.activityOrders"
91+
:key="activityType"
92+
:type="promotionTypes.find((item) => item.value === activityType)?.colorType"
93+
class="mr-[10px]"
94+
>
95+
{{ promotionTypes.find((item) => item.value === activityType)?.label }}
96+
</el-tag>
8397
</template>
84-
<template #activityOrders>
85-
<el-tag v-for="coupon in couponTemplateList" :key="coupon.id as number" class="mr-[10px]">
98+
<template #giveCouponTemplates="{ row }">
99+
<el-tag
100+
v-for="coupon in row.giveCouponTemplates"
101+
:key="coupon.id as number"
102+
class="mr-[10px]"
103+
>
86104
{{ coupon.name }}
87105
</el-tag>
88106
</template>
89107
</Descriptions>
90-
<CouponSelect ref="couponSelectRef" v-model:multiple-selection="couponTemplateList" />
108+
<CouponSelect ref="couponSelectRef" v-model:multiple-selection="formData.giveCouponTemplates" />
91109
</template>
92110
<script lang="ts" setup>
93-
import type { GiveCouponTemplate, Spu } from '@/api/mall/product/spu'
111+
import type { Spu } from '@/api/mall/product/spu'
94112
import { PropType } from 'vue'
95113
import { propTypes } from '@/utils/propTypes'
96114
import { copyValueToTarget } from '@/utils'
97115
import { otherSettingsSchema } from './spu.data'
98-
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
116+
import { DICT_TYPE, DictDataType, getIntDictOptions } from '@/utils/dict'
99117
import CouponSelect from './CouponSelect.vue'
100118
101119
defineOptions({ name: 'OtherSettingsForm' })
@@ -112,12 +130,16 @@ const props = defineProps({
112130
activeName: propTypes.string.def(''),
113131
isDetail: propTypes.bool.def(false) // 是否作为详情组件
114132
})
133+
134+
// 优惠卷
115135
const couponSelectRef = ref() // 优惠卷模版选择 Ref
116-
const couponTemplateList = ref<GiveCouponTemplate[]>([]) // 选择的优惠卷
117136
const openCouponSelect = () => {
118137
couponSelectRef.value?.open()
119138
}
120139
140+
// 活动优先级处理
141+
const promotionTypes = ref<DictDataType[]>(getIntDictOptions(DICT_TYPE.PROMOTION_TYPE_ENUM))
142+
121143
const otherSettingsFormRef = ref() // 表单Ref
122144
// 表单数据
123145
const formData = ref<Spu>({
@@ -129,7 +151,8 @@ const formData = ref<Spu>({
129151
recommendBest: false, // 是否精品
130152
recommendNew: false, // 是否新品
131153
recommendGood: false, // 是否优品
132-
giveCouponTemplate: [] // 赠送的优惠券
154+
activityOrders: [], // 活动排序
155+
giveCouponTemplates: [] // 赠送的优惠券
133156
})
134157
// 表单规则
135158
const rules = reactive({
@@ -163,9 +186,6 @@ watch(
163186
return
164187
}
165188
copyValueToTarget(formData.value, data)
166-
if (data.giveCouponTemplate) {
167-
couponTemplateList.value = data.giveCouponTemplate
168-
}
169189
recommendOptions.forEach(({ value }) => {
170190
if (formData.value[value] && !checkboxGroup.value.includes(value)) {
171191
checkboxGroup.value.push(value)
@@ -192,7 +212,6 @@ const validate = async () => {
192212
throw new Error('商品其他设置未完善!!')
193213
} else {
194214
// 校验通过更新数据
195-
formData.value.giveCouponTemplate = couponTemplateList.value
196215
Object.assign(props.propFormData, formData.value)
197216
}
198217
})

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ const formData = ref<ProductSpuApi.Spu>({
9595
recommendBest: false, // 是否精品
9696
recommendNew: false, // 是否新品
9797
recommendGood: false, // 是否优品
98-
giveCouponTemplate: [] // 赠送的优惠券
98+
activityOrders: [], // 活动排序
99+
giveCouponTemplates: [] // 赠送的优惠券
99100
})
100101
101102
/** 获得详情 */
@@ -109,7 +110,7 @@ const getDetail = async () => {
109110
try {
110111
const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.Spu
111112
res.skus?.forEach((item) => {
112-
if (isDetail.value === true) {
113+
if (isDetail.value) {
113114
item.price = floatToFixed2(item.price)
114115
item.marketPrice = floatToFixed2(item.marketPrice)
115116
item.costPrice = floatToFixed2(item.costPrice)

src/views/mall/product/spu/form/spu.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const otherSettingsSchema = reactive<CrudSchema[]>([
9696
},
9797
{
9898
label: '赠送的优惠劵',
99-
field: 'giveCouponTemplate'
99+
field: 'giveCouponTemplates'
100100
},
101101
{
102102
label: '活动显示排序',

0 commit comments

Comments
 (0)