diff --git a/apps/web-antd/src/components/table-action/icons.ts b/apps/web-antd/src/components/table-action/icons.ts index 88cda5978b6cf8bb86b5835bf407ca2a91c963b2..df5bf1a779cb62fdab3eeccb7ff04c6986ae21ae 100644 --- a/apps/web-antd/src/components/table-action/icons.ts +++ b/apps/web-antd/src/components/table-action/icons.ts @@ -10,4 +10,5 @@ export const ACTION_ICON = { MORE: 'lucide:ellipsis-vertical', VIEW: 'lucide:eye', COPY: 'lucide:copy', + CLOSE: 'lucide:x', }; diff --git a/apps/web-antd/src/views/mall/product/spu/form/modules/spu-table-select.vue b/apps/web-antd/src/views/mall/product/spu/form/modules/spu-table-select.vue new file mode 100644 index 0000000000000000000000000000000000000000..850c5b94c09eaeff4e02a2037a9d64d7258bc5b0 --- /dev/null +++ b/apps/web-antd/src/views/mall/product/spu/form/modules/spu-table-select.vue @@ -0,0 +1,357 @@ + + + + + + + + + + + + + + + + + + + handleCheckOne(e.target.checked, row)" + /> + + + + diff --git a/apps/web-antd/src/views/mall/promotion/components/index.ts b/apps/web-antd/src/views/mall/promotion/components/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..dd1f9d3c81ca2a2cfb6922dbec42f7faeab7a76d --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/components/index.ts @@ -0,0 +1,5 @@ +export { default as SpuAndSkuList } from './spu-and-sku-list.vue'; +export { default as SpuSkuSelect } from './spu-sku-select.vue'; + +export type * from './types'; + diff --git a/apps/web-antd/src/views/mall/promotion/components/spu-and-sku-list.vue b/apps/web-antd/src/views/mall/promotion/components/spu-and-sku-list.vue new file mode 100644 index 0000000000000000000000000000000000000000..1011e52bcb16d3dc7114c52eb7543afb9bce2b34 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/components/spu-and-sku-list.vue @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/components/spu-sku-select.vue b/apps/web-antd/src/views/mall/promotion/components/spu-sku-select.vue new file mode 100644 index 0000000000000000000000000000000000000000..2b77a3bf86eb78a1ea48a8235d296393d84d28ee --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/components/spu-sku-select.vue @@ -0,0 +1,341 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/components/types.ts b/apps/web-antd/src/views/mall/promotion/components/types.ts new file mode 100644 index 0000000000000000000000000000000000000000..649c467177ddf7fc980eb4cf2d17ef78d3b66f13 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/components/types.ts @@ -0,0 +1,15 @@ +import type { PropertyAndValues } from '#/views/mall/product/spu/form'; + +/** + * SPU 属性配置 + * 用于活动商品选择中,关联 SPU 和其属性列表 + */ +export interface SpuProperty { + /** SPU ID */ + spuId: number; + /** SPU 详情 */ + spuDetail: T; + /** 属性列表 */ + propertyList: PropertyAndValues[]; +} + diff --git a/apps/web-antd/src/views/mall/promotion/point/activity/data.ts b/apps/web-antd/src/views/mall/promotion/point/activity/data.ts index 63353aa68ad00e822ff5dca14f3683e58fb76f64..f08fcc5998fb201365122b696291f29d2697d6fe 100644 --- a/apps/web-antd/src/views/mall/promotion/point/activity/data.ts +++ b/apps/web-antd/src/views/mall/promotion/point/activity/data.ts @@ -1,51 +1,18 @@ +// 1. 导入类型 import type { VbenFormSchema } from '#/adapter/form'; import type { VxeTableGridOptions } from '#/adapter/vxe-table'; -import { DICT_TYPE } from '@vben/constants'; +// 2. 导入 VBEN 常量和工具 +import { CommonStatusEnum, DICT_TYPE } from '@vben/constants'; +import { getDictOptions } from '@vben/hooks'; +import { $t } from '@vben/locales'; -/** 表单配置 */ -export function useFormSchema(): VbenFormSchema[] { - return [ - { - fieldName: 'id', - component: 'Input', - dependencies: { - triggerFields: [''], - show: () => false, - }, - }, - { - fieldName: 'spuId', - label: '积分商城活动商品', - component: 'Input', - componentProps: { - placeholder: '请选择商品', - }, - rules: 'required', - }, - { - fieldName: 'sort', - label: '排序', - component: 'InputNumber', - componentProps: { - placeholder: '请输入排序', - min: 0, - }, - rules: 'required', - }, - { - fieldName: 'remark', - label: '备注', - component: 'Textarea', - componentProps: { - placeholder: '请输入备注', - rows: 4, - }, - }, - ]; -} +// 3. 导入 Zod 用于高级验证 +import { z } from '#/adapter/form'; -/** 列表的搜索表单 */ +/** + * @description: 列表的搜索表单 + */ export function useGridFormSchema(): VbenFormSchema[] { return [ { @@ -53,17 +20,20 @@ export function useGridFormSchema(): VbenFormSchema[] { label: '活动状态', component: 'Select', componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), placeholder: '请选择活动状态', allowClear: true, - dictType: DICT_TYPE.COMMON_STATUS, }, }, ]; } -/** 列表的字段 */ +/** + * @description: 列表的字段 + */ export function useGridColumns(): VxeTableGridOptions['columns'] { return [ + { type: 'checkbox', width: 40 }, { field: 'id', title: '活动编号', @@ -75,6 +45,9 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { minWidth: 80, cellRender: { name: 'CellImage', + props: { + height: 40, + }, }, }, { @@ -86,55 +59,101 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { field: 'marketPrice', title: '原价', minWidth: 100, - formatter: 'formatAmount2', - }, - { - field: 'point', - title: '兑换积分', - minWidth: 100, - }, - { - field: 'price', - title: '兑换金额', - minWidth: 100, - formatter: 'formatAmount2', + formatter: 'formatAmount', }, { field: 'status', title: '活动状态', minWidth: 100, + align: 'center', cellRender: { name: 'CellDict', - props: { type: DICT_TYPE.COMMON_STATUS }, + props: { + type: DICT_TYPE.COMMON_STATUS, + value: CommonStatusEnum.ENABLE, + }, }, }, { field: 'stock', title: '库存', minWidth: 80, + align: 'center', }, { field: 'totalStock', title: '总库存', minWidth: 80, + align: 'center', }, { field: 'redeemedQuantity', title: '已兑换数量', minWidth: 100, - slots: { default: 'redeemedQuantity' }, + align: 'center', + // 使用 formatter 计算已兑换数量 + formatter: ({ row }) => { + return (row.totalStock || 0) - (row.stock || 0); + }, }, { field: 'createTime', - title: '创建时间', + title: $t('common.createTime'), minWidth: 180, + align: 'center', formatter: 'formatDateTime', }, { - title: '操作', + title: $t('common.action'), width: 150, fixed: 'right', slots: { default: 'actions' }, }, ]; } + +/** + * @description: 新增/修改的表单 + */ +export function useFormSchema(): VbenFormSchema[] { + return [ + // 隐藏的 ID 字段 + { + component: 'Input', + fieldName: 'id', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'spuId', + label: '积分商城活动商品', + component: 'Input', + rules: 'required', + formItemClass: 'col-span-2', + // 通过插槽实现自定义商品选择器 + renderComponentContent: () => ({ + default: () => null, + }), + }, + { + fieldName: 'sort', + label: '排序', + component: 'InputNumber', + componentProps: { + min: 0, + }, + rules: z.number().default(0), + }, + { + fieldName: 'remark', + label: '备注', + component: 'Textarea', + componentProps: { + rows: 4, + }, + formItemClass: 'col-span-2', + }, + ]; +} diff --git a/apps/web-antd/src/views/mall/promotion/point/activity/index.vue b/apps/web-antd/src/views/mall/promotion/point/activity/index.vue index a592d589eba27e84c10efbae9e6ad579869ac254..fa3f06c0540ee0e4a65f0568d0467235921c188e 100644 --- a/apps/web-antd/src/views/mall/promotion/point/activity/index.vue +++ b/apps/web-antd/src/views/mall/promotion/point/activity/index.vue @@ -1,10 +1,9 @@ - - - - - + + + + - - {{ getRedeemedQuantity(row) }} - + - + diff --git a/apps/web-antd/src/views/mall/promotion/point/activity/modules/form.vue b/apps/web-antd/src/views/mall/promotion/point/activity/modules/form.vue index f8103ef7a34c550057f6e0e6988070077fb86eeb..cf0b74e763a8f545dc72e6ff69b43d05a583fa0a 100644 --- a/apps/web-antd/src/views/mall/promotion/point/activity/modules/form.vue +++ b/apps/web-antd/src/views/mall/promotion/point/activity/modules/form.vue @@ -1,86 +1,208 @@ - - - - - 注意: - 积分活动涉及复杂的商品选择和SKU配置,当前为简化版本。 - 完整的商品选择和积分配置功能需要在后续版本中完善。 - - - - + + + + + + + 选择商品 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/point/components/index.ts b/apps/web-antd/src/views/mall/promotion/point/components/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..6dfdb2999ac21152974760149ec3f8e2fd6a8396 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/point/components/index.ts @@ -0,0 +1,2 @@ +export { default as PointShowcase } from './point-showcase.vue'; +export { default as PointTableSelect } from './point-table-select.vue'; diff --git a/apps/web-antd/src/views/mall/promotion/point/components/point-showcase.vue b/apps/web-antd/src/views/mall/promotion/point/components/point-showcase.vue new file mode 100644 index 0000000000000000000000000000000000000000..7f740c6f327f537f25f0e3add0f9e8ecc4926215 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/point/components/point-showcase.vue @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/point/components/point-table-select.vue b/apps/web-antd/src/views/mall/promotion/point/components/point-table-select.vue new file mode 100644 index 0000000000000000000000000000000000000000..41ae8ddf460ec76577f1571d343d8f485c838246 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/point/components/point-table-select.vue @@ -0,0 +1,354 @@ + + + + + + + + + + + + + + handleCheckOne(e.target.checked, row, true)" + /> + + + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/rewardActivity/components/index.ts b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..93b72c3267906181734b154711ad529c980a4a94 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/index.ts @@ -0,0 +1,2 @@ +export { default as RewardRuleCouponSelect } from './reward-rule-coupon-select.vue'; +export { default as RewardRule } from './reward-rule.vue'; diff --git a/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule-coupon-select.vue b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule-coupon-select.vue new file mode 100644 index 0000000000000000000000000000000000000000..46af006c9fddfb968437e7cfd576cc9c7a6e1625 --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule-coupon-select.vue @@ -0,0 +1,131 @@ + + + + + 添加优惠劵 + + + + 优惠券名称:{{ item.name }} + + 范围: + + {{ item.productScope }} + + + 优惠: + + + {{ item.discountType }} + + + + 送 + + 张 + 删除 + + + + + + + diff --git a/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule.vue b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule.vue new file mode 100644 index 0000000000000000000000000000000000000000..14f969136a3eb6daea87feb5d078d16f721eddee --- /dev/null +++ b/apps/web-antd/src/views/mall/promotion/rewardActivity/components/reward-rule.vue @@ -0,0 +1,184 @@ + + + + + + + + 活动层级{{ index + 1 }} + + 删除 + + + + + + + 满 + + + {{ isPriceCondition ? '元' : '件' }} + + + + + + + + 订单金额优惠 + + + 减 + + 元 + + + + + 包邮: + + + + + + 送积分: + 送 + + 积分 + + + + + 送优惠券: + + + + + + + + + + 添加优惠规则 + + + + 赠送积分为 0 时不赠送。未选优惠券时不赠送。 + + + diff --git a/apps/web-antd/src/views/mall/promotion/rewardActivity/data.ts b/apps/web-antd/src/views/mall/promotion/rewardActivity/data.ts index 435298fccb8fd086b1a4d125781adfc087397849..b75ecdb10a74d61def9b33e1da15e1a1fcab165f 100644 --- a/apps/web-antd/src/views/mall/promotion/rewardActivity/data.ts +++ b/apps/web-antd/src/views/mall/promotion/rewardActivity/data.ts @@ -1,84 +1,20 @@ +// 1. 导入类型 import type { VbenFormSchema } from '#/adapter/form'; import type { VxeTableGridOptions } from '#/adapter/vxe-table'; +// 2. 导入 VBEN 常量和工具 import { DICT_TYPE } from '@vben/constants'; import { getDictOptions } from '@vben/hooks'; +import { $t } from '@vben/locales'; -/** 表单配置 */ -export function useFormSchema(): VbenFormSchema[] { - return [ - { - fieldName: 'id', - component: 'Input', - dependencies: { - triggerFields: [''], - show: () => false, - }, - }, - { - fieldName: 'name', - label: '活动名称', - component: 'Input', - componentProps: { - placeholder: '请输入活动名称', - }, - rules: 'required', - }, - { - fieldName: 'startTime', - label: '开始时间', - component: 'DatePicker', - componentProps: { - placeholder: '请选择开始时间', - showTime: true, - valueFormat: 'x', - format: 'YYYY-MM-DD HH:mm:ss', - }, - rules: 'required', - }, - { - fieldName: 'endTime', - label: '结束时间', - component: 'DatePicker', - componentProps: { - placeholder: '请选择结束时间', - showTime: true, - valueFormat: 'x', - format: 'YYYY-MM-DD HH:mm:ss', - }, - rules: 'required', - }, - { - fieldName: 'conditionType', - label: '条件类型', - component: 'RadioGroup', - componentProps: { - options: getDictOptions(DICT_TYPE.PROMOTION_CONDITION_TYPE, 'number'), - }, - rules: 'required', - }, - { - fieldName: 'productScope', - label: '商品范围', - component: 'RadioGroup', - componentProps: { - options: getDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE, 'number'), - }, - rules: 'required', - }, - { - fieldName: 'remark', - label: '备注', - component: 'Textarea', - componentProps: { - placeholder: '请输入备注', - rows: 4, - }, - }, - ]; -} +// 3. 导入 Zod 用于高级验证 +import { z } from '#/adapter/form'; +// 4. 导入项目级工具函数 +import { getRangePickerDefaultProps } from '#/utils'; -/** 列表的搜索表单 */ +/** + * @description: 列表的搜索表单 + */ export function useGridFormSchema(): VbenFormSchema[] { return [ { @@ -95,9 +31,9 @@ export function useGridFormSchema(): VbenFormSchema[] { label: '活动状态', component: 'Select', componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), placeholder: '请选择活动状态', allowClear: true, - options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), }, }, { @@ -105,28 +41,30 @@ export function useGridFormSchema(): VbenFormSchema[] { label: '活动时间', component: 'RangePicker', componentProps: { - placeholder: ['活动开始日期', '活动结束日期'], + ...getRangePickerDefaultProps(), allowClear: true, - valueFormat: 'YYYY-MM-DD HH:mm:ss', }, }, ]; } -/** 列表的字段 */ +/** + * @description: 列表的字段 + */ export function useGridColumns(): VxeTableGridOptions['columns'] { return [ { field: 'name', title: '活动名称', - minWidth: 140, + minWidth: 200, }, { field: 'productScope', title: '活动范围', - minWidth: 100, + minWidth: 120, + align: 'center', cellRender: { - name: 'CellDict', + name: 'CellDictTag', props: { type: DICT_TYPE.PROMOTION_PRODUCT_SCOPE }, }, }, @@ -134,20 +72,23 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { field: 'startTime', title: '活动开始时间', minWidth: 180, + align: 'center', formatter: 'formatDateTime', }, { field: 'endTime', title: '活动结束时间', minWidth: 180, + align: 'center', formatter: 'formatDateTime', }, { field: 'status', title: '状态', minWidth: 100, + align: 'center', cellRender: { - name: 'CellDict', + name: 'CellDictTag', props: { type: DICT_TYPE.COMMON_STATUS }, }, }, @@ -159,9 +100,77 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { }, { title: '操作', - width: 180, + width: 200, fixed: 'right', slots: { default: 'actions' }, }, ]; } + +/** + * @description: 新增/修改的表单 + */ +export function useFormSchema(): VbenFormSchema[] { + return [ + // 隐藏的 ID 字段 + { + component: 'Input', + fieldName: 'id', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'name', + label: '活动名称', + component: 'Input', + componentProps: { + placeholder: '请输入活动名称', + }, + rules: z.string().min(1, '活动名称不能为空'), + }, + { + fieldName: 'startAndEndTime', + label: '活动时间', + component: 'RangePicker', + componentProps: { + showTime: true, + format: 'YYYY-MM-DD HH:mm:ss', + placeholder: [$t('common.startTimeText'), $t('common.endTimeText')], + }, + rules: z.array(z.any()).min(1, '活动时间不能为空'), + }, + { + fieldName: 'conditionType', + label: '条件类型', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.PROMOTION_CONDITION_TYPE, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number(), + }, + { + fieldName: 'productScope', + label: '活动范围', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number(), + }, + { + fieldName: 'remark', + label: '备注', + component: 'Textarea', + componentProps: { + placeholder: '请输入备注', + rows: 4, + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/mall/promotion/rewardActivity/index.vue b/apps/web-antd/src/views/mall/promotion/rewardActivity/index.vue index 7641805a4ea2ec376ece766b688ba49f0ae2f7fb..8523a85f3883b1d67c3bdca1e9c56643a6d42aa7 100644 --- a/apps/web-antd/src/views/mall/promotion/rewardActivity/index.vue +++ b/apps/web-antd/src/views/mall/promotion/rewardActivity/index.vue @@ -1,8 +1,9 @@ - - - - - + + - + + + + +import type { VbenFormProps } from '#/adapter/form'; import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity'; -import { computed, ref } from 'vue'; +import { computed, nextTick, ref } from 'vue'; -import { useVbenForm, useVbenModal } from '@vben/common-ui'; +import { useVbenModal } from '@vben/common-ui'; +import { + PromotionConditionTypeEnum, + PromotionProductScopeEnum, +} from '@vben/constants'; +import { convertToInteger, formatToFraction } from '@vben/utils'; -import { message } from 'ant-design-vue'; +import { Alert, FormItem, message } from 'ant-design-vue'; +import { useVbenForm } from '#/adapter/form'; import { createRewardActivity, getReward, updateRewardActivity, } from '#/api/mall/promotion/reward/rewardActivity'; import { $t } from '#/locales'; +import { SpuAndSkuList } from '#/views/mall/promotion/components'; +import RewardRule from '../components/reward-rule.vue'; import { useFormSchema } from '../data'; const emit = defineEmits(['success']); -const formData = ref(); -const getTitle = computed(() => { - return formData.value?.id - ? $t('ui.actionTitle.edit', ['满减送活动']) - : $t('ui.actionTitle.create', ['满减送活动']); +const formData = ref({ + conditionType: PromotionConditionTypeEnum.PRICE.type, + productScope: PromotionProductScopeEnum.ALL.scope, + rules: [], }); +const getTitle = computed(() => + formData.value?.id ? '编辑满减送' : '新增满减送', +); + +// 1. 使用 useVbenForm 初始化表单 const [Form, formApi] = useVbenForm({ + schema: useFormSchema(), + showDefaultActions: false, commonConfig: { componentProps: { class: 'w-full', }, - labelWidth: 100, - }, - wrapperClass: 'grid-cols-2', - layout: 'horizontal', - schema: useFormSchema(), - showDefaultActions: false, + } as VbenFormProps['commonConfig'], }); +const rewardRuleRef = ref>(); + +// 2. 使用 useVbenModal 定义弹窗行为 const [Modal, modalApi] = useVbenModal({ async onConfirm() { const { valid } = await formApi.validate(); - if (!valid) { - return; - } + if (!valid) return; + modalApi.lock(); - // 提交表单 - const data = - (await formApi.getValues()) as MallRewardActivityApi.RewardActivity; + try { + const data = await formApi.getValues(); - // 确保必要的默认值 - if (!data.rules) { - data.rules = []; - } + // 1. 设置活动规则优惠券 + rewardRuleRef.value?.setRuleCoupon(); - try { - await (formData.value?.id - ? updateRewardActivity(data) - : createRewardActivity(data)); - // 关闭并提示 + // 2. 时间段转换 + if (data.startAndEndTime && Array.isArray(data.startAndEndTime)) { + data.startTime = data.startAndEndTime[0]; + data.endTime = data.startAndEndTime[1]; + delete data.startAndEndTime; + } + + // 3. 规则元转分 + data.rules?.forEach((item: any) => { + item.discountPrice = convertToInteger(item.discountPrice || 0); + if (data.conditionType === PromotionConditionTypeEnum.PRICE.type) { + item.limit = convertToInteger(item.limit || 0); + } + }); + + // 4. 设置商品范围 + setProductScopeValues(data); + + if (formData.value?.id) { + await updateRewardActivity(data); + message.success($t('common.updateSuccess')); + } else { + await createRewardActivity(data); + message.success($t('common.createSuccess')); + } await modalApi.close(); emit('success'); - message.success($t('ui.actionMessage.operationSuccess')); } finally { modalApi.unlock(); } }, async onOpenChange(isOpen: boolean) { if (!isOpen) { - formData.value = undefined; - return; - } - // 加载数据 - const data = modalApi.getData(); - if (!data || !data.id) { + formData.value = { + conditionType: PromotionConditionTypeEnum.PRICE.type, + productScope: PromotionProductScopeEnum.ALL.scope, + rules: [], + }; return; } + + const data = modalApi.getData(); + if (!data || !data.id) return; + modalApi.lock(); try { - formData.value = await getReward(data.id); - // 设置到 values - await formApi.setValues(formData.value); + const result = await getReward(data.id); + + // 转区段时间 + result.startAndEndTime = [result.startTime, result.endTime]; + + // 规则分转元 + result.rules?.forEach((item: any) => { + item.discountPrice = formatToFraction(item.discountPrice || 0); + if (result.conditionType === PromotionConditionTypeEnum.PRICE.type) { + item.limit = formatToFraction(item.limit || 0); + } + }); + + formData.value = result; + await formApi.setValues(result); + + // 获得商品范围 + await getProductScope(); } finally { modalApi.unlock(); } }, }); + +/** 获得商品范围 */ +async function getProductScope() { + switch (formData.value.productScope) { + case PromotionProductScopeEnum.CATEGORY.scope: { + await nextTick(); + let productCategoryIds = formData.value.productScopeValues as any; + if ( + Array.isArray(productCategoryIds) && + productCategoryIds.length === 1 + ) { + // 单选时使用数组不能反显 + productCategoryIds = productCategoryIds[0]; + } + // 设置品类编号 + formData.value.productCategoryIds = productCategoryIds; + break; + } + case PromotionProductScopeEnum.SPU.scope: { + // 设置商品编号 + formData.value.productSpuIds = formData.value.productScopeValues; + break; + } + default: { + break; + } + } +} + +/** 设置商品范围 */ +function setProductScopeValues(data: any) { + switch (formData.value.productScope) { + case PromotionProductScopeEnum.CATEGORY.scope: { + data.productScopeValues = Array.isArray(formData.value.productCategoryIds) + ? formData.value.productCategoryIds + : [formData.value.productCategoryIds]; + break; + } + case PromotionProductScopeEnum.SPU.scope: { + data.productScopeValues = formData.value.productSpuIds; + break; + } + default: { + break; + } + } +} - + + + - - - - 说明: 当前为简化版本的满减送活动表单。 - 复杂的商品选择、优惠规则配置等功能已简化,仅保留基础字段配置。 - 如需完整功能,请参考原始 Element UI 版本的实现。 - - + + + + + + + + + + + +
- 注意: - 积分活动涉及复杂的商品选择和SKU配置,当前为简化版本。 - 完整的商品选择和积分配置功能需要在后续版本中完善。 -
- 说明: 当前为简化版本的满减送活动表单。 - 复杂的商品选择、优惠规则配置等功能已简化,仅保留基础字段配置。 - 如需完整功能,请参考原始 Element UI 版本的实现。 -