!231 优惠券优化

Merge pull request !231 from 疯狂的世界/coupon
This commit is contained in:
芋道源码 2023-09-03 10:55:35 +00:00 committed by Gitee
commit 130208959d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 42 additions and 20 deletions

View File

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

View File

@ -13,21 +13,21 @@
<script lang="ts" setup> <script lang="ts" setup>
import { defaultProps, handleTree } from '@/utils/tree' import { defaultProps, handleTree } from '@/utils/tree'
import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductCategoryApi from '@/api/mall/product/category'
import { oneOf } from 'vue-types' import { oneOfType } from 'vue-types'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
/** 商品分类选择组件 */ /** 商品分类选择组件 */
defineOptions({ name: 'ProductCategorySelect' }) defineOptions({ name: 'ProductCategorySelect' })
const props = defineProps({ const props = defineProps({
value: oneOf([propTypes.number, propTypes.array.def([])]).isRequired, // ID modelValue: oneOfType([propTypes.number.def(undefined), propTypes.array.def([])]).def(undefined), // ID
multiple: propTypes.bool.def(false) // multiple: propTypes.bool.def(false) //
}) })
/** 选中的分类 ID */ /** 选中的分类 ID */
const selectCategoryId = computed({ const selectCategoryId = computed({
get: () => { get: () => {
return props.value return props.modelValue
}, },
set: (val: number | number[]) => { set: (val: number | number[]) => {
emit('update:modelValue', val) emit('update:modelValue', val)

View File

@ -75,13 +75,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<!-- TODO 疯狂可以看看为啥弹窗没把分页包进去可能和 footer 有关 -->
<Pagination <Pagination
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo" v-model:page="queryParams.pageNo"
:total="total" :total="total"
@pagination="getList" @pagination="getList"
/> />
<div class="clear-both"></div>
</Dialog> </Dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -36,7 +36,6 @@
</div> </div>
</div> </div>
</el-form-item> </el-form-item>
<!-- TODO 疯狂要不把 productSpuIds 改成 productScopeValues更通用另外改完后涉及到优惠劵的匹配逻辑要补充分类相关的逻辑例如说获得匹配的优惠劵列表之类的包括使用卷的时候 -->
<el-form-item <el-form-item
label="分类" label="分类"
v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope" v-if="formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
@ -153,7 +152,7 @@
<el-date-picker <el-date-picker
v-model="formData.validTimes" v-model="formData.validTimes"
style="width: 240px" style="width: 240px"
value-format="YYYY-MM-DD HH:mm:ss" value-format="x"
type="datetimerange" type="datetimerange"
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]" :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]"
/> />
@ -228,8 +227,9 @@ const formData = ref({
fixedStartTerm: undefined, fixedStartTerm: undefined,
fixedEndTerm: undefined, fixedEndTerm: undefined,
productScope: PromotionProductScopeEnum.ALL.scope, productScope: PromotionProductScopeEnum.ALL.scope,
productSpuIds: [], productScopeValues: [], //
productCategoryIds: [] productCategoryIds: [], //
productSpuIds: [] //
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '优惠券名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '优惠券名称不能为空', trigger: 'blur' }],
@ -246,8 +246,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' }] productCategoryIds: [{ required: true, message: '分类不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const productSpus = ref<ProductSpuApi.Spu[]>([]) // const productSpus = ref<ProductSpuApi.Spu[]>([]) //
@ -313,12 +313,10 @@ const submitForm = async () => {
formData.value.validTimes && formData.value.validTimes.length === 2 formData.value.validTimes && formData.value.validTimes.length === 2
? formData.value.validTimes[1] ? formData.value.validTimes[1]
: undefined : undefined
} as CouponTemplateApi.CouponTemplateVO } as unknown as CouponTemplateApi.CouponTemplateVO
if (formData.value.productCategoryIds?.length > 0) { //
// setProductScopeValues(data)
data.productSpuIds = formData.value.productCategoryIds
}
if (formType.value === 'create') { if (formType.value === 'create') {
await CouponTemplateApi.createCouponTemplate(data) await CouponTemplateApi.createCouponTemplate(data)
@ -355,6 +353,7 @@ const resetForm = () => {
fixedStartTerm: undefined, fixedStartTerm: undefined,
fixedEndTerm: undefined, fixedEndTerm: undefined,
productScope: PromotionProductScopeEnum.ALL.scope, productScope: PromotionProductScopeEnum.ALL.scope,
productScopeValues: [],
productSpuIds: [], productSpuIds: [],
productCategoryIds: [] productCategoryIds: []
} }
@ -366,13 +365,36 @@ const resetForm = () => {
const getProductScope = async () => { const getProductScope = async () => {
switch (formData.value.productScope) { switch (formData.value.productScope) {
case PromotionProductScopeEnum.SPU.scope: case PromotionProductScopeEnum.SPU.scope:
//
formData.value.productSpuIds = formData.value.productScopeValues
// //
productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productSpuIds) productSpus.value = await ProductSpuApi.getSpuDetailList(formData.value.productScopeValues)
break break
case PromotionProductScopeEnum.CATEGORY.scope: case PromotionProductScopeEnum.CATEGORY.scope:
// TODO @ await nextTick(() => {
formData.value.productCategoryIds = formData.value.productSpuIds let productCategoryIds = formData.value.productScopeValues
formData.value.productSpuIds = [] if (Array.isArray(productCategoryIds) && productCategoryIds.length > 0) {
// 使
productCategoryIds = productCategoryIds[0]
}
//
formData.value.productCategoryIds = productCategoryIds
})
break
default:
break
}
}
/** 设置商品范围 */
function setProductScopeValues(data: CouponTemplateApi.CouponTemplateVO) {
switch (formData.value.productScope) {
case PromotionProductScopeEnum.SPU.scope:
data.productScopeValues = formData.value.productSpuIds
break
case PromotionProductScopeEnum.CATEGORY.scope:
data.productScopeValues = Array.isArray(formData.value.productCategoryIds)
? formData.value.productCategoryIds
: [formData.value.productCategoryIds]
break break
default: default:
break break