diff --git a/apps/web-antd/src/views/mall/promotion/coupon/template/data.ts b/apps/web-antd/src/views/mall/promotion/coupon/template/data.ts index a66a875bb..5d9b14928 100644 --- a/apps/web-antd/src/views/mall/promotion/coupon/template/data.ts +++ b/apps/web-antd/src/views/mall/promotion/coupon/template/data.ts @@ -243,7 +243,6 @@ export function useFormSchema(): VbenFormSchema[] { defaultValue: CouponTemplateValidityTypeEnum.DATE.type, rules: 'required', }, - // TODO @AI:不太对; { fieldName: 'validTimes', label: '固定日期', diff --git a/apps/web-ele/src/api/mall/promotion/coupon/coupon.ts b/apps/web-ele/src/api/mall/promotion/coupon/coupon.ts index 52bc96290..99792e4ed 100644 --- a/apps/web-ele/src/api/mall/promotion/coupon/coupon.ts +++ b/apps/web-ele/src/api/mall/promotion/coupon/coupon.ts @@ -5,46 +5,28 @@ import { requestClient } from '#/api/request'; export namespace MallCouponApi { /** 优惠券 */ export interface Coupon { - /** 优惠券编号 */ - id: number; - /** 优惠券名称 */ - name: string; - /** 优惠券状态 */ - status: number; - /** 优惠券类型 */ - type: number; - /** 优惠券金额 */ - price: number; - /** 使用门槛 */ - usePrice: number; - /** 商品范围 */ - productScope: number; - /** 商品编号数组 */ - productSpuIds: number[]; - /** 有效期类型 */ - validityType: number; - /** 固定日期-生效开始时间 */ - validStartTime: Date; - /** 固定日期-生效结束时间 */ - validEndTime: Date; - /** 领取日期-开始天数 */ - fixedStartTerm: number; - /** 领取日期-结束天数 */ - fixedEndTerm: number; - /** 每人限领个数 */ - takeLimitCount: number; - /** 是否设置满多少金额可用 */ - usePriceEnabled: boolean; - /** 商品分类编号数组 */ - productCategoryIds: number[]; + id: number; // 优惠券编号 + name: string; // 优惠券名称 + status: number; // 优惠券状态 + type: number; // 优惠券类型 + price: number; // 优惠券金额 + usePrice: number; // 使用门槛 + productScope: number; // 商品范围 + productSpuIds: number[]; // 商品编号数组 + validityType: number; // 有效期类型 + validStartTime: Date; // 固定日期-生效开始时间 + validEndTime: Date; // 固定日期-生效结束时间 + fixedStartTerm: number; // 领取日期-开始天数 + fixedEndTerm: number; // 领取日期-结束天数 + takeLimitCount: number; // 每人限领个数 + usePriceEnabled: boolean; // 是否设置满多少金额可用 + productCategoryIds: number[]; // 商品分类编号数组 } /** 发送优惠券 */ export interface CouponSendReqVO { - /** 优惠券编号 */ - templateId: number; - /** 用户编号数组 */ - userIds: number[]; + templateId: number; // 优惠券编号 + userIds: number[]; // 用户编号数组 } } diff --git a/apps/web-ele/src/api/mall/promotion/coupon/couponTemplate.ts b/apps/web-ele/src/api/mall/promotion/coupon/couponTemplate.ts index f09455a1c..d5453ed79 100644 --- a/apps/web-ele/src/api/mall/promotion/coupon/couponTemplate.ts +++ b/apps/web-ele/src/api/mall/promotion/coupon/couponTemplate.ts @@ -5,54 +5,26 @@ import { requestClient } from '#/api/request'; export namespace MallCouponTemplateApi { /** 优惠券模板 */ export interface CouponTemplate { - /** 模板编号 */ - id: number; - /** 模板名称 */ - name: string; - /** 状态 */ - status: number; - /** 发放数量 */ - totalCount: number; - /** 每人限领个数 */ - takeLimitCount: number; - /** 领取方式 */ - takeType: number; - /** 使用门槛 */ - usePrice: number; - /** 商品范围 */ - productScope: number; - /** 商品范围值 */ - productScopeValues: number[]; - /** 有效期类型 */ - validityType: number; - /** 固定日期-生效开始时间 */ - validStartTime: Date; - /** 固定日期-生效结束时间 */ - validEndTime: Date; - /** 领取日期-开始天数 */ - fixedStartTerm: number; - /** 领取日期-结束天数 */ - fixedEndTerm: number; - /** 优惠类型 */ - discountType: number; - /** 折扣百分比 */ - discountPercent: number; - /** 优惠金额 */ - discountPrice: number; - /** 折扣上限 */ - discountLimitPrice: number; - /** 已领取数量 */ - takeCount: number; - /** 已使用数量 */ - useCount: number; - } - - /** 优惠券模板状态更新 */ - export interface StatusUpdate { - /** 模板编号 */ - id: number; - /** 状态 */ - status: 0 | 1; + id: number; // 模板编号 + name: string; // 模板名称 + status: number; // 状态 + totalCount: number; // 发放数量 + takeLimitCount: number; // 每人限领个数 + takeType: number; // 领取方式 + usePrice: number; // 使用门槛 + productScope: number; // 商品范围 + productScopeValues: number[]; // 商品范围值 + validityType: number; // 有效期类型 + validStartTime: Date; // 固定日期-生效开始时间 + validEndTime: Date; // 固定日期-生效结束时间 + fixedStartTerm: number; // 领取日期-开始天数 + fixedEndTerm: number; // 领取日期-结束天数 + discountType: number; // 优惠类型 + discountPercent?: number; // 折扣百分比 + discountPrice: number; // 优惠金额 + discountLimitPrice?: number; // 折扣上限 + takeCount: number; // 已领取数量 + useCount: number; // 已使用数量 } } @@ -71,9 +43,11 @@ export function updateCouponTemplate( } /** 更新优惠劵模板的状态 */ -export function updateCouponTemplateStatus(id: number, status: 0 | 1) { - const data: MallCouponTemplateApi.StatusUpdate = { id, status }; - return requestClient.put('/promotion/coupon-template/update-status', data); +export function updateCouponTemplateStatus(id: number, status: number) { + return requestClient.put('/promotion/coupon-template/update-status', { + id, + status, + }); } /** 删除优惠劵模板 */ @@ -102,11 +76,3 @@ export function getCouponTemplateList(ids: number[]) { `/promotion/coupon-template/list?ids=${ids}`, ); } - -/** 导出优惠劵模板 Excel */ -export function exportCouponTemplateExcel(params: PageParam) { - return requestClient.get('/promotion/coupon-template/export-excel', { - params, - responseType: 'blob', - }); -} diff --git a/apps/web-ele/src/api/mall/trade/order/index.ts b/apps/web-ele/src/api/mall/trade/order/index.ts index 07f4b173e..c2410f9cf 100644 --- a/apps/web-ele/src/api/mall/trade/order/index.ts +++ b/apps/web-ele/src/api/mall/trade/order/index.ts @@ -6,11 +6,11 @@ export namespace MallOrderApi { /** 商品属性 */ export interface ProductProperty { /** 属性的编号 */ - propertyId?: null | number; + propertyId?: number; /** 属性的名称 */ propertyName?: string; /** 属性值的编号 */ - valueId?: null | number; + valueId?: number; /** 属性值的名称 */ valueName?: string; } @@ -18,35 +18,35 @@ export namespace MallOrderApi { /** 订单项 */ export interface OrderItem { /** 编号 */ - id?: null | number; + id?: number; /** 用户编号 */ - userId?: null | number; + userId?: number; /** 订单编号 */ - orderId?: null | number; + orderId?: number; /** 商品 SPU 编号 */ - spuId?: null | number; + spuId?: number; /** 商品 SPU 名称 */ spuName?: string; /** 商品 SKU 编号 */ - skuId?: null | number; + skuId?: number; /** 商品图片 */ picUrl?: string; /** 购买数量 */ - count?: null | number; + count?: number; /** 商品原价(总) */ - originalPrice?: null | number; + originalPrice?: number; /** 商品原价(单) */ - originalUnitPrice?: null | number; + originalUnitPrice?: number; /** 商品优惠(总) */ - discountPrice?: null | number; + discountPrice?: number; /** 商品实付金额(总) */ - payPrice?: null | number; + payPrice?: number; /** 子订单分摊金额(总) */ - orderPartPrice?: null | number; + orderPartPrice?: number; /** 分摊后子订单实付金额(总) */ - orderDividePrice?: null | number; + orderDividePrice?: number; /** 售后状态 */ - afterSaleStatus?: null | number; + afterSaleStatus?: number; /** 属性数组 */ properties?: ProductProperty[]; price?: number; @@ -54,104 +54,104 @@ export namespace MallOrderApi { /** 订单日志 */ export interface OrderLog { - /** 日志编号 */ - id: number; /** 日志内容 */ content?: string; /** 创建时间 */ createTime?: Date; /** 用户类型 */ userType?: number; + /** 用户编号 */ + userId?: number; } /** 订单 */ export interface Order { /** 订单编号 */ - id?: null | number; + id?: number; /** 订单流水号 */ no?: string; /** 下单时间 */ - createTime?: Date | null; + createTime?: Date; /** 订单类型 */ - type?: null | number; + type?: number; /** 订单来源 */ - terminal?: null | number; + terminal?: number; /** 用户编号 */ - userId?: null | number; + userId?: number; /** 用户 IP */ userIp?: string; /** 用户备注 */ userRemark?: string; /** 订单状态 */ - status?: null | number; + status?: number; /** 购买的商品数量 */ - productCount?: null | number; + productCount?: number; /** 订单完成时间 */ - finishTime?: Date | null; + finishTime?: Date; /** 订单取消时间 */ - cancelTime?: Date | null; + cancelTime?: Date; /** 取消类型 */ - cancelType?: null | number; + cancelType?: number; /** 商家备注 */ remark?: string; /** 支付订单编号 */ - payOrderId?: null | number; + payOrderId?: number; /** 是否已支付 */ payStatus?: boolean; /** 付款时间 */ - payTime?: Date | null; + payTime?: Date; /** 支付渠道 */ payChannelCode?: string; /** 商品原价(总) */ - totalPrice?: null | number; + totalPrice?: number; /** 订单优惠(总) */ - discountPrice?: null | number; + discountPrice?: number; /** 运费金额 */ - deliveryPrice?: null | number; + deliveryPrice?: number; /** 订单调价(总) */ - adjustPrice?: null | number; + adjustPrice?: number; /** 应付金额(总) */ - payPrice?: null | number | string; + payPrice?: number; /** 发货方式 */ - deliveryType?: null | number; + deliveryType?: number; /** 自提门店编号 */ pickUpStoreId?: number; /** 自提核销码 */ pickUpVerifyCode?: string; /** 配送模板编号 */ - deliveryTemplateId?: null | number; + deliveryTemplateId?: number; /** 发货物流公司编号 */ logisticsId?: number; /** 发货物流单号 */ logisticsNo?: string; /** 发货时间 */ - deliveryTime?: Date | null; + deliveryTime?: Date; /** 收货时间 */ - receiveTime?: Date | null; + receiveTime?: Date; /** 收件人名称 */ receiverName?: string; /** 收件人手机 */ receiverMobile?: string; /** 收件人邮编 */ - receiverPostCode?: null | number; + receiverPostCode?: number; /** 收件人地区编号 */ - receiverAreaId?: null | number; + receiverAreaId?: number; /** 收件人地区名字 */ receiverAreaName?: string; /** 收件人详细地址 */ receiverDetailAddress?: string; /** 售后状态 */ - afterSaleStatus?: null | number; + afterSaleStatus?: number; /** 退款金额 */ - refundPrice?: null | number; + refundPrice?: number; /** 优惠劵编号 */ - couponId?: null | number; + couponId?: number; /** 优惠劵减免金额 */ - couponPrice?: null | number; + couponPrice?: number; /** 积分抵扣的金额 */ - pointPrice?: null | number; + pointPrice?: number; /** VIP 减免金额 */ - vipPrice?: null | number; + vipPrice?: number; /** 订单项列表 */ items?: OrderItem[]; /** 下单用户信息 */ @@ -159,7 +159,7 @@ export namespace MallOrderApi { /** 用户头像 */ avatar?: string; /** 用户编号 */ - id?: null | number; + id?: number; /** 用户昵称 */ nickname?: string; }; @@ -168,7 +168,7 @@ export namespace MallOrderApi { /** 用户头像 */ avatar?: string; /** 用户编号 */ - id?: null | number; + id?: number; /** 用户昵称 */ nickname?: string; }; @@ -195,7 +195,7 @@ export namespace MallOrderApi { /** 发货方式 */ expressType: string; /** 物流公司编号 */ - logisticsId: null | number; + logisticsId: number; /** 物流编号 */ logisticsNo: string; } @@ -229,13 +229,6 @@ export namespace MallOrderApi { /** 收件人详细地址 */ receiverDetailAddress: string; } - - export interface OrderExpressTrackRespDTO { - /** 发生时间 */ - time: Date; - /** 快递状态 */ - content: string; - } } /** 查询交易订单列表 */ @@ -264,9 +257,7 @@ export function getOrder(id: number) { /** 查询交易订单物流详情 */ export function getExpressTrackList(id: number) { - return requestClient.get( - `/trade/order/get-express-track-list?id=${id}`, - ); + return requestClient.get(`/trade/order/get-express-track-list?id=${id}`); } /** 订单发货 */ @@ -296,7 +287,7 @@ export function pickUpOrder(id: number) { /** 订单核销 */ export function pickUpOrderByVerifyCode(pickUpVerifyCode: string) { - return requestClient.put('/trade/order/pick-up-by-verify-code', { + return requestClient.put('/trade/order/pick-up-by-verify-code', undefined, { params: { pickUpVerifyCode }, }); } diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/coupon-select.vue b/apps/web-ele/src/views/mall/promotion/coupon/components/coupon-select.vue deleted file mode 100644 index 8784224f3..000000000 --- a/apps/web-ele/src/views/mall/promotion/coupon/components/coupon-select.vue +++ /dev/null @@ -1,223 +0,0 @@ - - diff --git a/apps/web-ele/src/views/mall/promotion/coupon/template/data.ts b/apps/web-ele/src/views/mall/promotion/coupon/template/data.ts index 319d1da6b..035259be5 100644 --- a/apps/web-ele/src/views/mall/promotion/coupon/template/data.ts +++ b/apps/web-ele/src/views/mall/promotion/coupon/template/data.ts @@ -1,11 +1,17 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTemplate'; -import { CommonStatusEnum, DICT_TYPE } from '@vben/constants'; +import { + CommonStatusEnum, + CouponTemplateTakeTypeEnum, + CouponTemplateValidityTypeEnum, + DICT_TYPE, + PromotionDiscountTypeEnum, + PromotionProductScopeEnum, +} from '@vben/constants'; import { getDictOptions } from '@vben/hooks'; -// 格式化函数移到组件内部实现 -import { z } from '#/adapter/form'; import { getRangePickerDefaultProps } from '#/utils'; import { @@ -40,69 +46,289 @@ export function useFormSchema(): VbenFormSchema[] { fieldName: 'description', label: '优惠券描述', component: 'Textarea', + componentProps: { + placeholder: '请输入优惠券描述', + }, }, - // TODO @霖:不同的优惠,不同的选择 { fieldName: 'productScope', - label: '优惠类型', + label: '优惠劵类型', component: 'RadioGroup', componentProps: { options: getDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE, 'number'), }, rules: 'required', + defaultValue: PromotionProductScopeEnum.ALL.scope, + }, + // TODO @puhui999: 商品选择器优化 + { + fieldName: 'productSpuIds', + label: '商品', + component: 'Input', + componentProps: { + placeholder: '请选择商品', + }, + dependencies: { + triggerFields: ['productScope', 'productScopeValues'], + show: (model) => + model.productScope === PromotionProductScopeEnum.SPU.scope, + trigger(values, form) { + // 当加载已有数据时,根据 productScopeValues 设置 productSpuIds + if ( + values.productScope === PromotionProductScopeEnum.SPU.scope && + values.productScopeValues + ) { + form.setFieldValue('productSpuIds', values.productScopeValues); + } + }, + }, + rules: 'required', + }, + // TODO @puhui999: 商品分类选择器优化 + { + fieldName: 'productCategoryIds', + label: '商品分类', + component: 'Input', + componentProps: { + placeholder: '请选择商品分类', + }, + dependencies: { + triggerFields: ['productScope', 'productScopeValues'], + show: (model) => + model.productScope === PromotionProductScopeEnum.CATEGORY.scope, + trigger(values, form) { + // 当加载已有数据时,根据 productScopeValues 设置 productCategoryIds + if ( + values.productScope === PromotionProductScopeEnum.CATEGORY.scope && + values.productScopeValues + ) { + const categoryIds = values.productScopeValues; + // 单选时使用数组不能反显,取第一个元素 + form.setFieldValue( + 'productCategoryIds', + Array.isArray(categoryIds) && categoryIds.length > 0 + ? categoryIds[0] + : categoryIds, + ); + } + }, + }, + rules: 'required', + }, + { + fieldName: 'discountType', + label: '优惠类型', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE, 'number'), + }, + rules: 'required', + defaultValue: PromotionDiscountTypeEnum.PRICE.type, + }, + { + fieldName: 'discountPrice', + label: '优惠券面额', + component: 'InputNumber', + componentProps: { + min: 0, + precision: 2, + placeholder: '请输入优惠金额,单位:元', + addonAfter: '元', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['discountType'], + show: (model) => + model.discountType === PromotionDiscountTypeEnum.PRICE.type, + }, + rules: 'required', + }, + { + fieldName: 'discountPercent', + label: '优惠券折扣', + component: 'InputNumber', + componentProps: { + min: 1, + max: 9.9, + precision: 1, + placeholder: '优惠券折扣不能小于 1 折,且不可大于 9.9 折', + addonAfter: '折', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['discountType'], + show: (model) => + model.discountType === PromotionDiscountTypeEnum.PERCENT.type, + }, + rules: 'required', + }, + { + fieldName: 'discountLimitPrice', + label: '最多优惠', + component: 'InputNumber', + componentProps: { + min: 0, + precision: 2, + placeholder: '请输入最多优惠', + addonAfter: '元', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['discountType'], + show: (model) => + model.discountType === PromotionDiscountTypeEnum.PERCENT.type, + }, + rules: 'required', + }, + { + fieldName: 'usePrice', + label: '满多少元可以使用', + component: 'InputNumber', + componentProps: { + min: 0, + precision: 2, + placeholder: '无门槛请设为 0', + addonAfter: '元', + controlsPosition: 'right', + class: '!w-full', + }, + rules: 'required', }, { fieldName: 'takeType', label: '领取方式', - component: 'Select', + component: 'RadioGroup', componentProps: { - placeholder: '请选择领取方式', options: getDictOptions(DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE, 'number'), }, rules: 'required', - }, - // TODO @xingu:不同的有效期,不同的类型 - { - fieldName: 'validityType', - label: '有效期类型', - component: 'Select', - componentProps: { - placeholder: '请选择有效期类型', - options: getDictOptions( - DICT_TYPE.PROMOTION_COUPON_TEMPLATE_VALIDITY_TYPE, - 'number', - ), - }, - rules: 'required', + defaultValue: CouponTemplateTakeTypeEnum.USER.type, }, { fieldName: 'totalCount', label: '发放数量', component: 'InputNumber', componentProps: { - min: 0, - placeholder: '请输入发放数量', + min: -1, + placeholder: '发放数量,没有之后不能领取或发放,-1 为不限制', + addonAfter: '张', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['takeType'], + show: (model) => + model.takeType === CouponTemplateTakeTypeEnum.USER.type, }, rules: 'required', }, { fieldName: 'takeLimitCount', - label: '领取上限', + label: '每人限领个数', component: 'InputNumber', componentProps: { - min: 0, - placeholder: '请输入领取上限', + min: -1, + placeholder: '设置为 -1 时,可无限领取', + addonAfter: '张', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['takeType'], + show: (model) => model.takeType === 1, }, rules: 'required', }, { - fieldName: 'status', - label: '优惠券状态', + fieldName: 'validityType', + label: '有效期类型', component: 'RadioGroup', componentProps: { - options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + options: getDictOptions( + DICT_TYPE.PROMOTION_COUPON_TEMPLATE_VALIDITY_TYPE, + 'number', + ), + }, + defaultValue: CouponTemplateValidityTypeEnum.DATE.type, + rules: 'required', + }, + { + fieldName: 'validTimes', + label: '固定日期', + component: 'RangePicker', + componentProps: { + ...getRangePickerDefaultProps(), + valueFormat: 'x', + }, + dependencies: { + triggerFields: ['validityType'], + show: (model) => + model.validityType === CouponTemplateValidityTypeEnum.DATE.type, + }, + rules: 'required', + }, + { + fieldName: 'fixedStartTerm', + label: '领取日期', + component: 'InputNumber', + componentProps: { + min: 0, + placeholder: '第 0 为今天生效', + addonBefore: '第', + addonAfter: '天', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['validityType'], + show: (model) => + model.validityType === CouponTemplateValidityTypeEnum.TERM.type, + }, + rules: 'required', + }, + { + fieldName: 'fixedEndTerm', + component: 'InputNumber', + componentProps: { + min: 0, + placeholder: '请输入结束天数', + addonBefore: '至', + addonAfter: '天有效', + controlsPosition: 'right', + class: '!w-full', + }, + dependencies: { + triggerFields: ['validityType'], + show: (model) => + model.validityType === CouponTemplateValidityTypeEnum.TERM.type, + }, + rules: 'required', + }, + { + fieldName: 'productScopeValues', + component: 'Input', + dependencies: { + triggerFields: ['productScope', 'productSpuIds', 'productCategoryIds'], + show: () => false, + trigger(values, form) { + switch (values.productScope) { + case PromotionProductScopeEnum.CATEGORY.scope: { + const categoryIds = Array.isArray(values.productCategoryIds) + ? values.productCategoryIds + : [values.productCategoryIds]; + form.setFieldValue('productScopeValues', categoryIds); + break; + } + case PromotionProductScopeEnum.SPU.scope: { + form.setFieldValue('productScopeValues', values.productSpuIds); + break; + } + } + }, }, - rules: z.number().default(CommonStatusEnum.ENABLE), }, ]; } @@ -115,7 +341,7 @@ export function useGridFormSchema(): VbenFormSchema[] { label: '优惠券名称', component: 'Input', componentProps: { - placeholder: '请输入优惠券名称', + placeholder: '请输入优惠劵名', clearable: true, }, }, @@ -152,9 +378,13 @@ export function useGridFormSchema(): VbenFormSchema[] { } /** 列表的字段 */ -export function useGridColumns(): VxeTableGridOptions['columns'] { +export function useGridColumns( + onStatusChange?: ( + newStatus: number, + row: MallCouponTemplateApi.CouponTemplate, + ) => PromiseLike, +): VxeTableGridOptions['columns'] { return [ - { type: 'checkbox', width: 40 }, { field: 'name', title: '优惠券名称', @@ -231,7 +461,15 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { field: 'status', title: '状态', minWidth: 100, - slots: { default: 'status' }, + align: 'center', + cellRender: { + attrs: { beforeChange: onStatusChange }, + name: 'CellSwitch', + props: { + activeValue: CommonStatusEnum.ENABLE, + inactiveValue: CommonStatusEnum.DISABLE, + }, + }, }, { field: 'createTime', diff --git a/apps/web-ele/src/views/mall/promotion/coupon/template/index.vue b/apps/web-ele/src/views/mall/promotion/coupon/template/index.vue index d8667120a..95be66c76 100644 --- a/apps/web-ele/src/views/mall/promotion/coupon/template/index.vue +++ b/apps/web-ele/src/views/mall/promotion/coupon/template/index.vue @@ -2,13 +2,11 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTemplate'; -import { ref } from 'vue'; - -import { DocAlert, Page, useVbenModal } from '@vben/common-ui'; +import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { CommonStatusEnum } from '@vben/constants'; import { $t } from '@vben/locales'; -import { ElLoading, ElMessage, ElSwitch } from 'element-plus'; +import { ElLoading, ElMessage } from 'element-plus'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { @@ -48,7 +46,7 @@ async function handleDelete(row: MallCouponTemplateApi.CouponTemplate) { text: $t('ui.actionMessage.deleting', [row.name]), }); try { - await deleteCouponTemplate(row.id as number); + await deleteCouponTemplate(row.id!); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name])); handleRefresh(); } finally { @@ -56,33 +54,30 @@ async function handleDelete(row: MallCouponTemplateApi.CouponTemplate) { } } -const checkedIds = ref([]); -function handleRowCheckboxChange({ - records, -}: { - records: MallCouponTemplateApi.CouponTemplate[]; -}) { - checkedIds.value = records.map((item) => item.id!); -} - /** 优惠券模板状态修改 */ -async function handleStatusChange(row: MallCouponTemplateApi.CouponTemplate) { - const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'; - const loadingInstance = ElLoading.service({ - text: `正在${text}优惠券模板...`, +async function handleStatusChange( + newStatus: number, + row: MallCouponTemplateApi.CouponTemplate, +): Promise { + return new Promise((resolve, reject) => { + confirm({ + content: `你要将${row.name}的状态切换为【${newStatus === CommonStatusEnum.ENABLE ? '启用' : '停用'}】吗?`, + }) + .then(async () => { + // 更新优惠券模板状态 + const res = await updateCouponTemplateStatus(row.id!, newStatus); + if (res) { + // 提示并返回成功 + ElMessage.success($t('ui.actionMessage.operationSuccess')); + resolve(true); + } else { + reject(new Error('更新失败')); + } + }) + .catch(() => { + reject(new Error('取消操作')); + }); }); - try { - await updateCouponTemplateStatus(row.id as number, row.status as 0 | 1); - ElMessage.success(`${text}成功`); - } catch { - // 异常时,需要将 row.status 状态重置回之前的 - row.status = - row.status === CommonStatusEnum.ENABLE - ? CommonStatusEnum.DISABLE - : CommonStatusEnum.ENABLE; - } finally { - loadingInstance.close(); - } } const [Grid, gridApi] = useVbenVxeGrid({ @@ -90,7 +85,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ schema: useGridFormSchema(), }, gridOptions: { - columns: useGridColumns(), + columns: useGridColumns(handleStatusChange), height: 'auto', keepSource: true, proxyConfig: { @@ -113,10 +108,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ search: true, }, } as VxeTableGridOptions, - gridEvents: { - checkboxAll: handleRowCheckboxChange, - checkboxChange: handleRowCheckboxChange, - }, }); @@ -144,15 +135,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ ]" /> - -