feat: mall discountActivity
							parent
							
								
									065dde94e8
								
							
						
					
					
						commit
						e2561593d9
					
				|  | @ -0,0 +1,151 @@ | ||||||
|  | import type { VbenFormSchema } from '#/adapter/form'; | ||||||
|  | import type { VxeTableGridOptions } from '#/adapter/vxe-table'; | ||||||
|  | 
 | ||||||
|  | import { formatDate } from '@vben/utils'; | ||||||
|  | 
 | ||||||
|  | import { DICT_TYPE, getDictOptions } from '#/utils'; | ||||||
|  | 
 | ||||||
|  | /** 表单配置 */ | ||||||
|  | export function useFormSchema(): VbenFormSchema[] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       fieldName: 'name', | ||||||
|  |       label: '活动名称', | ||||||
|  |       component: 'Input', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入活动名称', | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'status', | ||||||
|  |       label: '活动状态', | ||||||
|  |       component: 'Select', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请选择活动状态', | ||||||
|  |         options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'startTime', | ||||||
|  |       label: '开始时间', | ||||||
|  |       component: 'DatePicker', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请选择开始时间', | ||||||
|  |         showTime: false, | ||||||
|  |         valueFormat: 'x', | ||||||
|  |         format: 'YYYY-MM-DD', | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'endTime', | ||||||
|  |       label: '结束时间', | ||||||
|  |       component: 'DatePicker', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请选择结束时间', | ||||||
|  |         showTime: false, | ||||||
|  |         valueFormat: 'x', | ||||||
|  |         format: 'YYYY-MM-DD', | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'remark', | ||||||
|  |       label: '备注', | ||||||
|  |       component: 'Textarea', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入备注', | ||||||
|  |         rows: 4, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     // TODO
 | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 列表的搜索表单 */ | ||||||
|  | export function useGridFormSchema(): VbenFormSchema[] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       fieldName: 'name', | ||||||
|  |       label: '活动名称', | ||||||
|  |       component: 'Input', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入活动名称', | ||||||
|  |         clearable: true, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'status', | ||||||
|  |       label: '活动状态', | ||||||
|  |       component: 'Select', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请选择活动状态', | ||||||
|  |         clearable: true, | ||||||
|  |         options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'activeTime', | ||||||
|  |       label: '活动时间', | ||||||
|  |       component: 'RangePicker', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: ['开始时间', '结束时间'], | ||||||
|  |         clearable: true, | ||||||
|  |         valueFormat: 'YYYY-MM-DD HH:mm:ss', | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 列表的字段 */ | ||||||
|  | export function useGridColumns(): VxeTableGridOptions['columns'] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       field: 'id', | ||||||
|  |       title: '活动编号', | ||||||
|  |       minWidth: 80, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'name', | ||||||
|  |       title: '活动名称', | ||||||
|  |       minWidth: 140, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'activityTime', | ||||||
|  |       title: '活动时间', | ||||||
|  |       minWidth: 210, | ||||||
|  |       formatter: ({ row }) => { | ||||||
|  |         if (!row.startTime || !row.endTime) return ''; | ||||||
|  |         return `${formatDate(row.startTime, 'YYYY-MM-DD')} ~ ${formatDate(row.endTime, 'YYYY-MM-DD')}`; | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'status', | ||||||
|  |       title: '活动状态', | ||||||
|  |       minWidth: 100, | ||||||
|  |       cellRender: { | ||||||
|  |         name: 'CellDict', | ||||||
|  |         props: { type: DICT_TYPE.COMMON_STATUS }, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'remark', | ||||||
|  |       title: '备注', | ||||||
|  |       minWidth: 200, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'createTime', | ||||||
|  |       title: '创建时间', | ||||||
|  |       width: 180, | ||||||
|  |       formatter: 'formatDateTime', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       title: '操作', | ||||||
|  |       width: 150, | ||||||
|  |       fixed: 'right', | ||||||
|  |       slots: { default: 'actions' }, | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | @ -1,32 +1,178 @@ | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
| import { DocAlert, Page } from '@vben/common-ui'; | import type { VxeTableGridOptions } from '#/adapter/vxe-table'; | ||||||
|  | import type { MallDiscountActivityApi } from '#/api/mall/promotion/discount/discountActivity'; | ||||||
| 
 | 
 | ||||||
| import { Button } from 'ant-design-vue'; | import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; | ||||||
|  | 
 | ||||||
|  | import { message } from 'ant-design-vue'; | ||||||
|  | 
 | ||||||
|  | import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; | ||||||
|  | import { | ||||||
|  |   closeDiscountActivity, | ||||||
|  |   deleteDiscountActivity, | ||||||
|  |   getDiscountActivityPage, | ||||||
|  | } from '#/api/mall/promotion/discount/discountActivity'; | ||||||
|  | import { $t } from '#/locales'; | ||||||
|  | 
 | ||||||
|  | import { useGridColumns, useGridFormSchema } from './data'; | ||||||
|  | import DiscountActivityForm from './modules/form.vue'; | ||||||
|  | 
 | ||||||
|  | defineOptions({ name: 'PromotionDiscountActivity' }); | ||||||
|  | 
 | ||||||
|  | const [FormModal, formModalApi] = useVbenModal({ | ||||||
|  |   connectedComponent: DiscountActivityForm, | ||||||
|  |   destroyOnClose: true, | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | /** 刷新表格 */ | ||||||
|  | function onRefresh() { | ||||||
|  |   gridApi.query(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 创建满减活动 */ | ||||||
|  | function handleCreate() { | ||||||
|  |   formModalApi.setData(null).open(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 编辑满减活动 */ | ||||||
|  | function handleEdit(row: MallDiscountActivityApi.DiscountActivity) { | ||||||
|  |   formModalApi.setData(row).open(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 关闭满减活动 */ | ||||||
|  | async function handleClose(row: MallDiscountActivityApi.DiscountActivity) { | ||||||
|  |   try { | ||||||
|  |     await confirm({ | ||||||
|  |       content: '确认关闭该限时折扣活动吗?', | ||||||
|  |     }); | ||||||
|  |   } catch { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   const hideLoading = message.loading({ | ||||||
|  |     content: '正在关闭中', | ||||||
|  |     key: 'action_key_msg', | ||||||
|  |   }); | ||||||
|  |   try { | ||||||
|  |     await closeDiscountActivity(row.id as number); | ||||||
|  |     message.success({ | ||||||
|  |       content: '关闭成功', | ||||||
|  |       key: 'action_key_msg', | ||||||
|  |     }); | ||||||
|  |     onRefresh(); | ||||||
|  |   } finally { | ||||||
|  |     hideLoading(); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 删除满减活动 */ | ||||||
|  | async function handleDelete(row: MallDiscountActivityApi.DiscountActivity) { | ||||||
|  |   const hideLoading = message.loading({ | ||||||
|  |     content: $t('ui.actionMessage.deleting', [row.name]), | ||||||
|  |     key: 'action_key_msg', | ||||||
|  |   }); | ||||||
|  |   try { | ||||||
|  |     await deleteDiscountActivity(row.id as number); | ||||||
|  |     message.success({ | ||||||
|  |       content: $t('ui.actionMessage.deleteSuccess', [row.name]), | ||||||
|  |       key: 'action_key_msg', | ||||||
|  |     }); | ||||||
|  |     onRefresh(); | ||||||
|  |   } finally { | ||||||
|  |     hideLoading(); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const [Grid, gridApi] = useVbenVxeGrid({ | ||||||
|  |   formOptions: { | ||||||
|  |     schema: useGridFormSchema(), | ||||||
|  |   }, | ||||||
|  |   gridOptions: { | ||||||
|  |     columns: useGridColumns(), | ||||||
|  |     height: 'auto', | ||||||
|  |     keepSource: true, | ||||||
|  |     proxyConfig: { | ||||||
|  |       ajax: { | ||||||
|  |         query: async ({ page }, formValues) => { | ||||||
|  |           return await getDiscountActivityPage({ | ||||||
|  |             pageNo: page.currentPage, | ||||||
|  |             pageSize: page.pageSize, | ||||||
|  |             ...formValues, | ||||||
|  |           }); | ||||||
|  |         }, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     rowConfig: { | ||||||
|  |       keyField: 'id', | ||||||
|  |       isHover: true, | ||||||
|  |     }, | ||||||
|  |     toolbarConfig: { | ||||||
|  |       refresh: { code: 'query' }, | ||||||
|  |       search: true, | ||||||
|  |     }, | ||||||
|  |   } as VxeTableGridOptions<MallDiscountActivityApi.DiscountActivity>, | ||||||
|  | }); | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|   <Page> |   <Page auto-content-height> | ||||||
|  |     <template #doc> | ||||||
|       <DocAlert |       <DocAlert | ||||||
|         title="【营销】限时折扣" |         title="【营销】限时折扣" | ||||||
|         url="https://doc.iocoder.cn/mall/promotion-discount/" |         url="https://doc.iocoder.cn/mall/promotion-discount/" | ||||||
|       /> |       /> | ||||||
|     <Button |     </template> | ||||||
|       danger | 
 | ||||||
|       type="link" |     <FormModal @success="onRefresh" /> | ||||||
|       target="_blank" | 
 | ||||||
|       href="https://github.com/yudaocode/yudao-ui-admin-vue3" |     <Grid table-title="限时折扣活动列表"> | ||||||
|     > |       <template #toolbar-tools> | ||||||
|       该功能支持 Vue3 + element-plus 版本! |         <TableAction | ||||||
|     </Button> |           :actions="[ | ||||||
|     <br /> |             { | ||||||
|     <Button |               label: $t('ui.actionTitle.create', ['限时折扣活动']), | ||||||
|       type="link" |               type: 'primary', | ||||||
|       target="_blank" |               icon: ACTION_ICON.ADD, | ||||||
|       href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/discountActivity/index" |               auth: ['promotion:discount-activity:create'], | ||||||
|     > |               onClick: handleCreate, | ||||||
|       可参考 |             }, | ||||||
|       https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/discountActivity/index |           ]" | ||||||
|       代码,pull request 贡献给我们! |         /> | ||||||
|     </Button> |       </template> | ||||||
|  |       <template #actions="{ row }"> | ||||||
|  |         <TableAction | ||||||
|  |           :actions="[ | ||||||
|  |             { | ||||||
|  |               label: $t('common.edit'), | ||||||
|  |               type: 'link', | ||||||
|  |               icon: ACTION_ICON.EDIT, | ||||||
|  |               auth: ['promotion:discount-activity:update'], | ||||||
|  |               onClick: handleEdit.bind(null, row), | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               label: '关闭', | ||||||
|  |               type: 'link', | ||||||
|  |               danger: true, | ||||||
|  |               icon: ACTION_ICON.DELETE, | ||||||
|  |               auth: ['promotion:discount-activity:close'], | ||||||
|  |               ifShow: row.status === 0, | ||||||
|  |               onClick: handleClose.bind(null, row), | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               label: $t('common.delete'), | ||||||
|  |               type: 'link', | ||||||
|  |               danger: true, | ||||||
|  |               icon: ACTION_ICON.DELETE, | ||||||
|  |               auth: ['promotion:discount-activity:delete'], | ||||||
|  |               ifShow: row.status !== 0, | ||||||
|  |               popConfirm: { | ||||||
|  |                 title: $t('ui.actionMessage.deleteConfirm', [row.name]), | ||||||
|  |                 confirm: handleDelete.bind(null, row), | ||||||
|  |               }, | ||||||
|  |             }, | ||||||
|  |           ]" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </Grid> | ||||||
|   </Page> |   </Page> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
|  | @ -0,0 +1,98 @@ | ||||||
|  | <script lang="ts" setup> | ||||||
|  | import type { MallDiscountActivityApi } from '#/api/mall/promotion/discount/discountActivity'; | ||||||
|  | 
 | ||||||
|  | import { computed, ref } from 'vue'; | ||||||
|  | 
 | ||||||
|  | import { useVbenForm, useVbenModal } from '@vben/common-ui'; | ||||||
|  | 
 | ||||||
|  | import { message } from 'ant-design-vue'; | ||||||
|  | 
 | ||||||
|  | import { | ||||||
|  |   createDiscountActivity, | ||||||
|  |   getDiscountActivity, | ||||||
|  |   updateDiscountActivity, | ||||||
|  | } from '#/api/mall/promotion/discount/discountActivity'; | ||||||
|  | import { $t } from '#/locales'; | ||||||
|  | 
 | ||||||
|  | import { useFormSchema } from '../data'; | ||||||
|  | 
 | ||||||
|  | defineOptions({ name: 'DiscountActivityForm' }); | ||||||
|  | 
 | ||||||
|  | const emit = defineEmits(['success']); | ||||||
|  | const formData = ref<MallDiscountActivityApi.DiscountActivity>(); | ||||||
|  | const getTitle = computed(() => { | ||||||
|  |   return formData.value?.id | ||||||
|  |     ? $t('ui.actionTitle.edit', ['限时折扣活动']) | ||||||
|  |     : $t('ui.actionTitle.create', ['限时折扣活动']); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | const [Form, formApi] = useVbenForm({ | ||||||
|  |   commonConfig: { | ||||||
|  |     componentProps: { | ||||||
|  |       class: 'w-full', | ||||||
|  |     }, | ||||||
|  |     labelWidth: 100, | ||||||
|  |   }, | ||||||
|  |   wrapperClass: 'grid-cols-2', | ||||||
|  |   layout: 'horizontal', | ||||||
|  |   schema: useFormSchema(), | ||||||
|  |   showDefaultActions: false, | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | const [Modal, modalApi] = useVbenModal({ | ||||||
|  |   async onConfirm() { | ||||||
|  |     const { valid } = await formApi.validate(); | ||||||
|  |     if (!valid) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     modalApi.lock(); | ||||||
|  |     // 提交表单 | ||||||
|  |     const data = | ||||||
|  |       (await formApi.getValues()) as MallDiscountActivityApi.DiscountActivity; | ||||||
|  | 
 | ||||||
|  |     // 确保必要的默认值 | ||||||
|  |     if (!data.products) { | ||||||
|  |       data.products = []; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     try { | ||||||
|  |       await (formData.value?.id | ||||||
|  |         ? updateDiscountActivity(data) | ||||||
|  |         : createDiscountActivity(data)); | ||||||
|  |       // 关闭并提示 | ||||||
|  |       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<MallDiscountActivityApi.DiscountActivity>(); | ||||||
|  |     if (!data || !data.id) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     modalApi.lock(); | ||||||
|  |     try { | ||||||
|  |       formData.value = await getDiscountActivity(data.id as number); | ||||||
|  |       // 设置到 values | ||||||
|  |       if (formData.value) { | ||||||
|  |         await formApi.setValues(formData.value); | ||||||
|  |       } | ||||||
|  |     } finally { | ||||||
|  |       modalApi.unlock(); | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  | }); | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <Modal class="w-3/5" :title="getTitle"> | ||||||
|  |     <Form /> | ||||||
|  |   </Modal> | ||||||
|  | </template> | ||||||
		Loading…
	
		Reference in New Issue
	
	 xingyu4j
						xingyu4j