mall:优惠券 商品适用范围,增加商品分类

This commit is contained in:
owen 2023-08-30 20:54:20 +08:00
parent 60d2e3114b
commit 27219e1833
4 changed files with 75 additions and 4 deletions

View File

@ -9,7 +9,7 @@ export interface CouponTemplateVO {
takeType: number takeType: number
usePrice: number usePrice: number
productScope: number productScope: number
productSpuIds: string productSpuIds: number[]
validityType: number validityType: number
validStartTime: Date validStartTime: Date
validEndTime: Date validEndTime: Date

View File

@ -220,6 +220,10 @@ export const PromotionProductScopeEnum = {
SPU: { SPU: {
scope: 2, scope: 2,
name: '指定商品参与' name: '指定商品参与'
},
CATEGORY: {
scope: 3,
name: '指定品类参与'
} }
} }

View File

@ -0,0 +1,47 @@
<template>
<el-tree-select
v-model="selectCategoryId"
:data="categoryList"
:props="defaultProps"
:multiple="multiple"
:show-checkbox="multiple"
class="w-1/1"
node-key="id"
placeholder="请选择商品分类"
/>
</template>
<script lang="ts" setup>
import { defaultProps, handleTree } from '@/utils/tree'
import * as ProductCategoryApi from '@/api/mall/product/category'
import { oneOf } from 'vue-types'
import { propTypes } from '@/utils/propTypes'
/** 商品分类选择组件 */
defineOptions({ name: 'ProductCategorySelect' })
const props = defineProps({
value: oneOf([propTypes.number, propTypes.array.def([])]).isRequired, // ID
multiple: propTypes.bool.def(false) //
})
/** 选中的分类ID */
const selectCategoryId = computed({
get: () => {
return props.value
},
set: (val: number | number[]) => {
emit('update:modelValue', val)
}
})
/** 分类选择 */
const emit = defineEmits(['update:modelValue'])
const categoryList = ref([]) //
onMounted(async () => {
//
const data = await ProductCategoryApi.getCategoryList({})
categoryList.value = handleTree(data, 'id', 'parentId')
})
</script>

View File

@ -172,6 +172,12 @@
</div> </div>
</div> </div>
</el-form-item> </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> </el-form>
<template #footer> <template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button> <el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
@ -190,6 +196,7 @@ import {
PromotionProductScopeEnum PromotionProductScopeEnum
} from '@/utils/constants' } from '@/utils/constants'
import SpuTableSelect from '@/views/mall/product/spu/components/SpuTableSelect.vue' import SpuTableSelect from '@/views/mall/product/spu/components/SpuTableSelect.vue'
import ProductCategorySelect from '@/views/mall/product/category/components/ProductCategorySelect.vue'
defineOptions({ name: 'CouponTemplateForm' }) defineOptions({ name: 'CouponTemplateForm' })
@ -218,7 +225,8 @@ const formData = ref({
fixedStartTerm: undefined, fixedStartTerm: undefined,
fixedEndTerm: undefined, fixedEndTerm: undefined,
productScope: PromotionProductScopeEnum.ALL.scope, productScope: PromotionProductScopeEnum.ALL.scope,
productSpuIds: [] productSpuIds: [],
productCategoryIds: []
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '优惠券名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '优惠券名称不能为空', trigger: 'blur' }],
@ -235,7 +243,8 @@ const formRules = reactive({
fixedStartTerm: [{ required: true, message: '开始领取天数不能为空', trigger: 'blur' }], fixedStartTerm: [{ required: true, message: '开始领取天数不能为空', trigger: 'blur' }],
fixedEndTerm: [{ required: true, message: '开始领取天数不能为空', trigger: 'blur' }], fixedEndTerm: [{ required: true, message: '开始领取天数不能为空', trigger: 'blur' }],
productScope: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }], productScope: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }],
productSpuIds: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }] productSpuIds: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }],
productCategoryIds: [{ required: true, message: '分类范围不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const productSpus = ref<ProductSpuApi.Spu[]>([]) // const productSpus = ref<ProductSpuApi.Spu[]>([]) //
@ -302,6 +311,12 @@ const submitForm = async () => {
? formData.value.validTimes[1] ? formData.value.validTimes[1]
: undefined : undefined
} as CouponTemplateApi.CouponTemplateVO } as CouponTemplateApi.CouponTemplateVO
if (formData.value.productCategoryIds?.length > 0) {
//
data.productSpuIds = formData.value.productCategoryIds
}
if (formType.value === 'create') { if (formType.value === 'create') {
await CouponTemplateApi.createCouponTemplate(data) await CouponTemplateApi.createCouponTemplate(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
@ -337,7 +352,8 @@ const resetForm = () => {
fixedStartTerm: undefined, fixedStartTerm: undefined,
fixedEndTerm: undefined, fixedEndTerm: undefined,
productScope: PromotionProductScopeEnum.ALL.scope, productScope: PromotionProductScopeEnum.ALL.scope,
productSpuIds: [] productSpuIds: [],
productCategoryIds: []
} }
formRef.value?.resetFields() formRef.value?.resetFields()
productSpus.value = [] productSpus.value = []
@ -350,6 +366,10 @@ const getProductScope = async () => {
// //
productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productSpuIds) productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productSpuIds)
break break
case PromotionProductScopeEnum.CATEGORY.scope:
formData.value.productCategoryIds = formData.value.productSpuIds
formData.value.productSpuIds = []
break
default: default:
break break
} }