Skip to content

Commit 18df708

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

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

src/api/mall/product/spu.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface Sku {
2525
salesCount?: number // 商品销量
2626
}
2727

28+
export interface GiveCouponTemplate {
29+
id?: number
30+
name?: string // 优惠券名称
31+
}
32+
2833
export interface Spu {
2934
id?: number
3035
name?: string // 商品名称
@@ -55,6 +60,7 @@ export interface Spu {
5560
stock?: number // 商品库存
5661
createTime?: Date // 商品创建时间
5762
status?: number // 商品状态
63+
giveCouponTemplate?: GiveCouponTemplate[]
5864
}
5965

6066
// 获得 Spu 列表

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ import {
150150
} from '@/views/mall/promotion/coupon/formatter'
151151
import { dateFormatter } from '@/utils/formatTime'
152152
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
153+
import type { GiveCouponTemplate } from '@/api/mall/product/spu'
153154
154155
defineOptions({ name: 'CouponSelect' })
155156
156157
defineProps<{
157-
multipleSelection: { id: number; name: string }[]
158+
multipleSelection: GiveCouponTemplate[]
158159
}>()
159160
const emit = defineEmits<{
160-
(e: 'update:multipleSelection', v: { id: number; name: string }[])
161+
(e: 'update:multipleSelection', v: GiveCouponTemplate[])
161162
}>()
162163
const dialogVisible = ref(false) // 弹窗的是否展示
163164
const dialogTitle = ref('选择优惠卷') // 弹窗的标题
@@ -212,6 +213,8 @@ const handleSelectionChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
212213
val.map((item) => ({ id: item.id, name: item.name }))
213214
)
214215
}
215-
const submitForm = async () => {}
216+
const submitForm = () => {
217+
dialogVisible.value = false
218+
}
216219
</script>
217220
<style lang="scss" scoped></style>

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,15 @@
8282
{{ row.recommendGood ? '是' : '否' }}
8383
</template>
8484
<template #activityOrders>
85-
<el-tag>默认</el-tag>
86-
<el-tag class="ml-2" type="success">秒杀</el-tag>
87-
<el-tag class="ml-2" type="info">砍价</el-tag>
88-
<el-tag class="ml-2" type="warning">拼团</el-tag>
85+
<el-tag v-for="coupon in couponTemplateList" :key="coupon.id as number" class="mr-[10px]">
86+
{{ coupon.name }}
87+
</el-tag>
8988
</template>
9089
</Descriptions>
91-
<CouponSelect ref="couponSelectRef" />
90+
<CouponSelect ref="couponSelectRef" v-model:multiple-selection="couponTemplateList" />
9291
</template>
9392
<script lang="ts" setup>
94-
import type { Spu } from '@/api/mall/product/spu'
93+
import type { GiveCouponTemplate, Spu } from '@/api/mall/product/spu'
9594
import { PropType } from 'vue'
9695
import { propTypes } from '@/utils/propTypes'
9796
import { copyValueToTarget } from '@/utils'
@@ -113,8 +112,8 @@ const props = defineProps({
113112
activeName: propTypes.string.def(''),
114113
isDetail: propTypes.bool.def(false) // 是否作为详情组件
115114
})
116-
const couponSelectRef = ref() // 优惠卷模版选择
117-
const couponTemplateList = ref<{ id: number; name: string }[]>([]) // 选择的优惠卷
115+
const couponSelectRef = ref() // 优惠卷模版选择 Ref
116+
const couponTemplateList = ref<GiveCouponTemplate[]>([]) // 选择的优惠卷
118117
const openCouponSelect = () => {
119118
couponSelectRef.value?.open()
120119
}
@@ -129,7 +128,8 @@ const formData = ref<Spu>({
129128
recommendBenefit: false, // 是否优惠
130129
recommendBest: false, // 是否精品
131130
recommendNew: false, // 是否新品
132-
recommendGood: false // 是否优品
131+
recommendGood: false, // 是否优品
132+
giveCouponTemplate: [] // 赠送的优惠券
133133
})
134134
// 表单规则
135135
const rules = reactive({
@@ -163,6 +163,9 @@ watch(
163163
return
164164
}
165165
copyValueToTarget(formData.value, data)
166+
if (data.giveCouponTemplate) {
167+
couponTemplateList.value = data.giveCouponTemplate
168+
}
166169
recommendOptions.forEach(({ value }) => {
167170
if (formData.value[value] && !checkboxGroup.value.includes(value)) {
168171
checkboxGroup.value.push(value)
@@ -189,6 +192,7 @@ const validate = async () => {
189192
throw new Error('商品其他设置未完善!!')
190193
} else {
191194
// 校验通过更新数据
195+
formData.value.giveCouponTemplate = couponTemplateList.value
192196
Object.assign(props.propFormData, formData.value)
193197
}
194198
})

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ const otherSettingsRef = ref() // 其他设置Ref
6262
// spu 表单数据
6363
const formData = ref<ProductSpuApi.Spu>({
6464
name: '', // 商品名称
65-
categoryId: null, // 商品分类
65+
categoryId: undefined, // 商品分类
6666
keyword: '', // 关键字
67-
unit: null, // 单位
67+
unit: undefined, // 单位
6868
picUrl: '', // 商品封面图
6969
sliderPicUrls: [], // 商品轮播图
7070
introduction: '', // 商品简介
71-
deliveryTemplateId: null, // 运费模版
72-
brandId: null, // 商品品牌
71+
deliveryTemplateId: undefined, // 运费模版
72+
brandId: undefined, // 商品品牌
7373
specType: false, // 商品规格
7474
subCommissionType: false, // 分销类型
7575
skus: [
@@ -94,7 +94,8 @@ const formData = ref<ProductSpuApi.Spu>({
9494
recommendBenefit: false, // 是否优惠
9595
recommendBest: false, // 是否精品
9696
recommendNew: false, // 是否新品
97-
recommendGood: false // 是否优品
97+
recommendGood: false, // 是否优品
98+
giveCouponTemplate: [] // 赠送的优惠券
9899
})
99100
100101
/** 获得详情 */

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: 'giveCouponTemplateIds'
99+
field: 'giveCouponTemplate'
100100
},
101101
{
102102
label: '活动显示排序',

0 commit comments

Comments
 (0)