diff --git a/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/index.vue b/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/index.vue index b97b54140..5f6bcbb32 100644 --- a/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/index.vue +++ b/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/index.vue @@ -60,7 +60,7 @@ watch( { immediate: true, deep: true }, ); -/** 提取手机宽度 */ +/** 初始化 */ onMounted(() => { phoneWidth.value = containerRef.value?.wrapRef?.offsetWidth || 375; }); diff --git a/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/property.vue b/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/property.vue index 9913bf542..d84038775 100644 --- a/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/property.vue +++ b/apps/web-ele/src/views/mall/promotion/components/diy-editor/components/mobile/coupon-card/property.vue @@ -5,6 +5,7 @@ import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTe import { ref, watch } from 'vue'; +import { useVbenModal } from '@vben/common-ui'; import { CouponTemplateTakeTypeEnum, PromotionDiscountTypeEnum, @@ -26,10 +27,9 @@ import { import * as CouponTemplateApi from '#/api/mall/promotion/coupon/couponTemplate'; import UploadImg from '#/components/upload/image-upload.vue'; import { ColorInput } from '#/views/mall/promotion/components'; +import CouponSelect from '#/views/mall/promotion/coupon/components/select.vue'; import ComponentContainerProperty from '../../component-container-property.vue'; -// TODO: 添加组件 -// import CouponSelect from '#/views/mall/promotion/coupon/components/coupon-select.vue'; /** 优惠券卡片属性面板 */ defineOptions({ name: 'CouponCardProperty' }); @@ -41,18 +41,26 @@ const emit = defineEmits(['update:modelValue']); const formData = useVModel(props, 'modelValue', emit); const couponList = ref([]); // 已选择的优惠券列表 -const couponSelectDialog = ref(); + +const [CouponSelectModal, couponSelectModalApi] = useVbenModal({ + connectedComponent: CouponSelect, + destroyOnClose: true, +}); /** 添加优惠劵 */ const handleAddCoupon = () => { - couponSelectDialog.value.open(); + couponSelectModalApi.open(); }; /** 处理优惠劵选择 */ -const handleCouponSelect = () => { - formData.value.couponIds = couponList.value.map((coupon) => coupon.id); +const handleCouponSelect = ( + selectedCoupons: MallCouponTemplateApi.CouponTemplate[], +) => { + couponList.value = selectedCoupons; + formData.value.couponIds = selectedCoupons.map((coupon) => coupon.id); }; +/** 监听优惠券 ID 变化,加载优惠券列表 */ watch( () => formData.value.couponIds, async () => { @@ -157,11 +165,8 @@ watch( - - diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/index.ts b/apps/web-ele/src/views/mall/promotion/coupon/components/index.ts index 00a6c3f32..24cb4e274 100644 --- a/apps/web-ele/src/views/mall/promotion/coupon/components/index.ts +++ b/apps/web-ele/src/views/mall/promotion/coupon/components/index.ts @@ -1,2 +1,2 @@ -export * from './data'; +export { default as CouponSelect } from './select.vue'; export { default as CouponSendForm } from './send-form.vue'; diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/select-data.ts b/apps/web-ele/src/views/mall/promotion/coupon/components/select-data.ts new file mode 100644 index 000000000..bf7c993e3 --- /dev/null +++ b/apps/web-ele/src/views/mall/promotion/coupon/components/select-data.ts @@ -0,0 +1,119 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; + +import { DICT_TYPE } from '@vben/constants'; +import { getDictOptions } from '@vben/hooks'; + +import { + discountFormat, + remainedCountFormat, + takeLimitCountFormat, + validityTypeFormat, +} from '../formatter'; + +/** 优惠券选择的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'name', + label: '优惠券名称', + component: 'Input', + componentProps: { + placeholder: '请输入优惠劵名', + clearable: true, + }, + }, + { + fieldName: 'discountType', + label: '优惠类型', + component: 'Select', + componentProps: { + options: getDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE, 'number'), + placeholder: '请选择优惠券类型', + clearable: true, + }, + }, + ]; +} + +/** 优惠券选择的表格列 */ +export function useGridColumns(): VxeTableGridOptions['columns'] { + return [ + { type: 'checkbox', width: 55 }, + { + field: 'name', + title: '优惠券名称', + minWidth: 140, + }, + { + field: 'productScope', + title: '类型', + minWidth: 80, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.PROMOTION_PRODUCT_SCOPE }, + }, + }, + { + field: 'discountType', + title: '优惠类型', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.PROMOTION_DISCOUNT_TYPE }, + }, + }, + { + field: 'discountPrice', + title: '优惠力度', + minWidth: 100, + formatter: ({ row }) => discountFormat(row), + }, + { + field: 'takeType', + title: '领取方式', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE }, + }, + }, + { + field: 'validityType', + title: '使用时间', + minWidth: 185, + align: 'center', + formatter: ({ row }) => validityTypeFormat(row), + }, + { + field: 'totalCount', + title: '发放数量', + minWidth: 100, + align: 'center', + }, + { + field: 'remainedCount', + title: '剩余数量', + minWidth: 100, + align: 'center', + formatter: ({ row }) => remainedCountFormat(row), + }, + { + field: 'takeLimitCount', + title: '领取上限', + minWidth: 100, + align: 'center', + formatter: ({ row }) => takeLimitCountFormat(row), + }, + { + field: 'status', + title: '状态', + minWidth: 80, + align: 'center', + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + }, + ]; +} diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/select.vue b/apps/web-ele/src/views/mall/promotion/coupon/components/select.vue new file mode 100644 index 000000000..8d75c2388 --- /dev/null +++ b/apps/web-ele/src/views/mall/promotion/coupon/components/select.vue @@ -0,0 +1,69 @@ + + + + diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/data.ts b/apps/web-ele/src/views/mall/promotion/coupon/components/send-form-data.ts similarity index 100% rename from apps/web-ele/src/views/mall/promotion/coupon/components/data.ts rename to apps/web-ele/src/views/mall/promotion/coupon/components/send-form-data.ts diff --git a/apps/web-ele/src/views/mall/promotion/coupon/components/send-form.vue b/apps/web-ele/src/views/mall/promotion/coupon/components/send-form.vue index 83e989227..9a8c4b192 100644 --- a/apps/web-ele/src/views/mall/promotion/coupon/components/send-form.vue +++ b/apps/web-ele/src/views/mall/promotion/coupon/components/send-form.vue @@ -11,7 +11,7 @@ import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { sendCoupon } from '#/api/mall/promotion/coupon/coupon'; import { getCouponTemplatePage } from '#/api/mall/promotion/coupon/couponTemplate'; -import { useFormSchema, useGridColumns } from './data'; +import { useFormSchema, useGridColumns } from './send-form-data.ts'; /** 发送优惠券 */ async function handleSendCoupon(row: MallCouponTemplateApi.CouponTemplate) {