diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue index 4c021421..dbc62f45 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue @@ -27,14 +27,12 @@ import { defineOptions({ name: 'ShopMonthlyTargetFormModal' }); -const props = defineProps(); - -const emit = defineEmits(); - // Props interface Props { open: boolean; shopMonthlyTargetData?: null | ShopMonthlyTargetVO.Info; + /** 新增时预填店铺(编辑时忽略) */ + presetShopId?: number | null; } // Emits @@ -44,6 +42,12 @@ interface Emits { (e: 'cancel'): void; } +const props = withDefaults(defineProps(), { + presetShopId: null, +}); + +const emit = defineEmits(); + // 创建 vben modal(与父组件 v-model:open 同步 isOpen,避免仅点遮罩关闭时父级仍为 true 导致无法二次打开) const [Modal, modalApi] = useVbenModal({ draggable: true, @@ -131,6 +135,9 @@ watch( } else { // 新增模式,重置表单数据 resetFormData(); + if (props.presetShopId != null && props.presetShopId !== undefined) { + formData.value.shopId = props.presetShopId; + } } await nextTick(); modalApi.open(); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/index.vue index 861aeb3b..de70914e 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/index.vue @@ -7,15 +7,25 @@ import type { import type { ShopVO } from '#/api/ecommerce/shop/types'; import type { PageQueryDTO } from '#/types/common'; -import { computed, ref } from 'vue'; +import { computed, onMounted, ref, watch } from 'vue'; import { Page } from '@vben/common-ui'; import { createIconifyIcon } from '@vben/icons'; -import { Button, message, Popconfirm, Space } from 'ant-design-vue'; +import { + Button, + Card, + DatePicker, + Empty, + Flex, + message, + Popconfirm, + Space, + Spin, +} from 'ant-design-vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; -import { getShopPageApi } from '#/api/ecommerce/shop'; +import { getShopPageApi } from '#/api/ecommerce/shop/apis'; import { deleteShopMonthlyTargetApi, getShopMonthlyTargetPageApi, @@ -25,74 +35,101 @@ import ShopMonthlyTargetFormModal from './components/ShopMonthlyTargetFormModal. defineOptions({ name: 'ShopMonthlyTargetManagement' }); -// 创建图标组件 const PlusIcon = createIconifyIcon('lucide:plus'); +const StoreIcon = createIconifyIcon('lucide:store'); -// 响应式数据 const loading = ref(false); +const shopsLoading = ref(false); +const shops = ref([]); + +/** 未选择具体店铺:undefined 表示全部店铺 */ +const selectedShopId = ref(undefined); + const formModalVisible = ref(false); const currentShopMonthlyTargetData = ref(null); +const presetShopIdForModal = ref(null); -// 搜索表单 const searchForm = ref({ - shopId: undefined as number | undefined, startTargetMonth: undefined as string | undefined, endTargetMonth: undefined as string | undefined, }); -// 店铺选项(懒加载) -const shopOptions = ref<{ label: string; value: number }[]>([]); -const shopLoading = ref(false); -const shopFetched = ref(false); +async function loadShops() { + shopsLoading.value = true; + try { + const data = await getShopPageApi({ page: 1, pageSize: 500, filters: {} }); + shops.value = data.records ?? []; + } catch { + message.error('获取店铺列表失败'); + shops.value = []; + } finally { + shopsLoading.value = false; + } +} -// VbenVxeGrid 表格配置 -const gridOptions: VxeGridProps = { +const selectedShopLabel = computed(() => { + if (selectedShopId.value == null) { + return '全部店铺'; + } + const s = shops.value.find((x) => x.id === selectedShopId.value); + return s?.name ?? `店铺 #${selectedShopId.value}`; +}); + +function selectShopAll() { + selectedShopId.value = undefined; +} + +function selectShop(id: number) { + selectedShopId.value = id; +} + +const gridOptions: VxeGridProps = { columns: [ { type: 'seq' as const, - minWidth: 'auto', + minWidth: 56, title: '序号', }, { field: 'shopName', title: '店铺名称', - minWidth: 'auto', + minWidth: 120, showOverflow: 'tooltip' as const, }, { field: 'targetMonth', title: '目标月份', - minWidth: 'auto', + minWidth: 110, }, { title: '目标销售额', - minWidth: 'auto', + minWidth: 120, slots: { default: 'targetAmount' }, }, { field: 'targetOrderCount', title: '目标订单数', - minWidth: 'auto', + minWidth: 100, }, { field: 'remark', title: '备注', - minWidth: 'auto', + minWidth: 140, showOverflow: 'tooltip' as const, }, { field: 'createTime', title: '创建时间', - minWidth: 'auto', + minWidth: 160, }, { title: '操作', - minWidth: 'auto', + minWidth: 140, fixed: 'right' as const, slots: { default: 'action' }, }, ], - height: 'auto', + height: '100%', border: true, stripe: true, rowConfig: { isHover: true }, @@ -127,7 +164,6 @@ const gridOptions: VxeGridProps = { | 'Total' )[], }, - // 配置远程加载 proxyConfig: { ajax: { query: async ({ page }) => { @@ -137,23 +173,16 @@ const gridOptions: VxeGridProps = { page: page.currentPage, pageSize: page.pageSize, filters: { - shopId: searchForm.value.shopId, - startTargetMonth: searchForm.value.startTargetMonth, - endTargetMonth: searchForm.value.endTargetMonth, + shopId: selectedShopId.value, + startTargetMonth: searchForm.value.startTargetMonth || undefined, + endTargetMonth: searchForm.value.endTargetMonth || undefined, }, }; const data = await getShopMonthlyTargetPageApi(params); - return { - items: data.records, - total: data.total, - }; - } catch (error) { - console.error('获取店铺月销量目标列表失败:', error); + return { items: data.records, total: data.total }; + } catch { message.error('获取店铺月销量目标列表失败'); - return { - items: [], - total: 0, - }; + return { items: [], total: 0 }; } finally { loading.value = false; } @@ -162,93 +191,48 @@ const gridOptions: VxeGridProps = { }, }; -// 搜索表单配置 -const gridReloadRef = ref<(() => void) | null>(null); - -const formOptions = computed(() => ({ - schema: [ - { - component: 'Select', - componentProps: { - placeholder: '请选择店铺', - options: shopOptions, - allowClear: true, - showSearch: true, - filterOption: false, - loading: shopLoading, - onFocus: fetchShopOptions, - onChange: (val: any) => { - searchForm.value.shopId = val; - gridReloadRef.value?.(); - }, - }, - fieldName: 'shopId', - label: '店铺', - }, - { - component: 'DatePicker', - componentProps: { - placeholder: '开始月份', - picker: 'month', - style: { width: '100%' }, - onChange: (val: any) => { - searchForm.value.startTargetMonth = val ? val.format('YYYY-MM') : undefined; - gridReloadRef.value?.(); - }, - }, - fieldName: 'startTargetMonth', - label: '目标月份', - }, - { - component: 'DatePicker', - componentProps: { - placeholder: '结束月份', - picker: 'month', - style: { width: '100%' }, - onChange: (val: any) => { - searchForm.value.endTargetMonth = val ? val.format('YYYY-MM') : undefined; - gridReloadRef.value?.(); - }, - }, - fieldName: 'endTargetMonth', - label: '至', - }, - ], - showDefaultActions: true, - collapsed: true, - collapsedRows: 1, -})); - -// 刷新表格数据 function refreshTable() { - if (gridApi) { - gridApi.reload(); - } + gridApi?.reload(); } -// 创建 VbenVxeGrid 实例 const [Grid, gridApi] = useVbenVxeGrid({ gridOptions, - formOptions: formOptions.value, - showSearchForm: true, - tableTitle: '店铺月销量目标管理', + showSearchForm: false, + tableTitle: '月销量目标', }); -gridReloadRef.value = () => gridApi.reload(); -// 处理新增 +watch(selectedShopId, () => { + gridApi.reload(); +}); + +onMounted(() => { + void loadShops(); +}); + +function resetModalPreset() { + presetShopIdForModal.value = null; +} + const handleAdd = () => { currentShopMonthlyTargetData.value = null; + resetModalPreset(); formModalVisible.value = true; }; -// 处理编辑 +function handleAddForShop(shopId: number) { + selectShop(shopId); + currentShopMonthlyTargetData.value = null; + presetShopIdForModal.value = shopId; + formModalVisible.value = true; +} + const handleEdit = (record: ShopMonthlyTargetVO.Info) => { + resetModalPreset(); currentShopMonthlyTargetData.value = record; formModalVisible.value = true; }; -// 处理删除 -const handleDelete = async (id: number) => { +async function handleDelete(id: number) { try { await deleteShopMonthlyTargetApi(id); message.success('删除成功'); @@ -256,48 +240,39 @@ const handleDelete = async (id: number) => { } catch { message.error('删除失败'); } -}; +} -// 处理表单成功 const handleFormSuccess = () => { + resetModalPreset(); refreshTable(); }; -// 格式化金额 -const formatAmount = (amount: number) => { - return `¥${amount.toFixed(2)}`; +const handleFormCancel = () => { + resetModalPreset(); + formModalVisible.value = false; }; -// 获取店铺选项(首次触发时加载) -async function fetchShopOptions() { - if (shopFetched.value || shopLoading.value) return; - shopLoading.value = true; - try { - const response = await getShopPageApi({ - page: 1, - pageSize: 1000, - filters: {}, - }); - shopOptions.value = response.records.map((shop: ShopVO.Info) => ({ - label: shop.name, - value: shop.id, - })); - shopFetched.value = true; - } catch (error) { - console.error('获取店铺列表失败:', error); - } finally { - shopLoading.value = false; - } -} +const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`; -// 初始化 +function shopRowClass(id: number | 'all') { + const active = + id === 'all' + ? selectedShopId.value === undefined + : selectedShopId.value === id; + return [ + 'flex cursor-pointer items-center gap-2 rounded-lg border px-3 py-2.5 text-sm font-semibold transition-colors', + active + ? 'border-primary bg-primary/8 text-primary' + : 'border-transparent bg-muted/30 text-foreground hover:bg-muted/60', + ].join(' '); +} - - - - + +
+ + +
+
+ + +
+
+
+
+ - - + + + + - - -
+
+ 当前:{{ selectedShopLabel }} +
+ +
+ + + + + + + +
+ + -