SPU: 完善优惠卷选择

This commit is contained in:
puhui999 2023-10-20 11:48:59 +08:00
parent 3464bb9c74
commit 18df708b49
5 changed files with 32 additions and 18 deletions

View File

@ -25,6 +25,11 @@ export interface Sku {
salesCount?: number // 商品销量 salesCount?: number // 商品销量
} }
export interface GiveCouponTemplate {
id?: number
name?: string // 优惠券名称
}
export interface Spu { export interface Spu {
id?: number id?: number
name?: string // 商品名称 name?: string // 商品名称
@ -55,6 +60,7 @@ export interface Spu {
stock?: number // 商品库存 stock?: number // 商品库存
createTime?: Date // 商品创建时间 createTime?: Date // 商品创建时间
status?: number // 商品状态 status?: number // 商品状态
giveCouponTemplate?: GiveCouponTemplate[]
} }
// 获得 Spu 列表 // 获得 Spu 列表

View File

@ -150,14 +150,15 @@ import {
} from '@/views/mall/promotion/coupon/formatter' } from '@/views/mall/promotion/coupon/formatter'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate' import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
import type { GiveCouponTemplate } from '@/api/mall/product/spu'
defineOptions({ name: 'CouponSelect' }) defineOptions({ name: 'CouponSelect' })
defineProps<{ defineProps<{
multipleSelection: { id: number; name: string }[] multipleSelection: GiveCouponTemplate[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'update:multipleSelection', v: { id: number; name: string }[]) (e: 'update:multipleSelection', v: GiveCouponTemplate[])
}>() }>()
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('选择优惠卷') // const dialogTitle = ref('选择优惠卷') //
@ -212,6 +213,8 @@ const handleSelectionChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
val.map((item) => ({ id: item.id, name: item.name })) val.map((item) => ({ id: item.id, name: item.name }))
) )
} }
const submitForm = async () => {} const submitForm = () => {
dialogVisible.value = false
}
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@ -82,16 +82,15 @@
{{ row.recommendGood ? '是' : '否' }} {{ row.recommendGood ? '是' : '否' }}
</template> </template>
<template #activityOrders> <template #activityOrders>
<el-tag>默认</el-tag> <el-tag v-for="coupon in couponTemplateList" :key="coupon.id as number" class="mr-[10px]">
<el-tag class="ml-2" type="success">秒杀</el-tag> {{ coupon.name }}
<el-tag class="ml-2" type="info">砍价</el-tag> </el-tag>
<el-tag class="ml-2" type="warning">拼团</el-tag>
</template> </template>
</Descriptions> </Descriptions>
<CouponSelect ref="couponSelectRef" /> <CouponSelect ref="couponSelectRef" v-model:multiple-selection="couponTemplateList" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { Spu } from '@/api/mall/product/spu' import type { GiveCouponTemplate, Spu } from '@/api/mall/product/spu'
import { PropType } from 'vue' import { PropType } from 'vue'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils' import { copyValueToTarget } from '@/utils'
@ -113,8 +112,8 @@ const props = defineProps({
activeName: propTypes.string.def(''), activeName: propTypes.string.def(''),
isDetail: propTypes.bool.def(false) // isDetail: propTypes.bool.def(false) //
}) })
const couponSelectRef = ref() // const couponSelectRef = ref() // Ref
const couponTemplateList = ref<{ id: number; name: string }[]>([]) // const couponTemplateList = ref<GiveCouponTemplate[]>([]) //
const openCouponSelect = () => { const openCouponSelect = () => {
couponSelectRef.value?.open() couponSelectRef.value?.open()
} }
@ -129,7 +128,8 @@ const formData = ref<Spu>({
recommendBenefit: false, // recommendBenefit: false, //
recommendBest: false, // recommendBest: false, //
recommendNew: false, // recommendNew: false, //
recommendGood: false // recommendGood: false, //
giveCouponTemplate: [] //
}) })
// //
const rules = reactive({ const rules = reactive({
@ -163,6 +163,9 @@ watch(
return return
} }
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
if (data.giveCouponTemplate) {
couponTemplateList.value = data.giveCouponTemplate
}
recommendOptions.forEach(({ value }) => { recommendOptions.forEach(({ value }) => {
if (formData.value[value] && !checkboxGroup.value.includes(value)) { if (formData.value[value] && !checkboxGroup.value.includes(value)) {
checkboxGroup.value.push(value) checkboxGroup.value.push(value)
@ -189,6 +192,7 @@ const validate = async () => {
throw new Error('商品其他设置未完善!!') throw new Error('商品其他设置未完善!!')
} else { } else {
// //
formData.value.giveCouponTemplate = couponTemplateList.value
Object.assign(props.propFormData, formData.value) Object.assign(props.propFormData, formData.value)
} }
}) })

View File

@ -62,14 +62,14 @@ const otherSettingsRef = ref() // 其他设置Ref
// spu // spu
const formData = ref<ProductSpuApi.Spu>({ const formData = ref<ProductSpuApi.Spu>({
name: '', // name: '', //
categoryId: null, // categoryId: undefined, //
keyword: '', // keyword: '', //
unit: null, // unit: undefined, //
picUrl: '', // picUrl: '', //
sliderPicUrls: [], // sliderPicUrls: [], //
introduction: '', // introduction: '', //
deliveryTemplateId: null, // deliveryTemplateId: undefined, //
brandId: null, // brandId: undefined, //
specType: false, // specType: false, //
subCommissionType: false, // subCommissionType: false, //
skus: [ skus: [
@ -94,7 +94,8 @@ const formData = ref<ProductSpuApi.Spu>({
recommendBenefit: false, // recommendBenefit: false, //
recommendBest: false, // recommendBest: false, //
recommendNew: false, // recommendNew: false, //
recommendGood: false // recommendGood: false, //
giveCouponTemplate: [] //
}) })
/** 获得详情 */ /** 获得详情 */

View File

@ -96,7 +96,7 @@ export const otherSettingsSchema = reactive<CrudSchema[]>([
}, },
{ {
label: '赠送的优惠劵', label: '赠送的优惠劵',
field: 'giveCouponTemplateIds' field: 'giveCouponTemplate'
}, },
{ {
label: '活动显示排序', label: '活动显示排序',