mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 13:49:20 +08:00
feat: 完善公司全店概览
This commit is contained in:
+274
@@ -0,0 +1,274 @@
|
||||
<script setup lang="ts">
|
||||
import type {
|
||||
ShopMonthlyTargetDTO,
|
||||
ShopMonthlyTargetVO,
|
||||
} from '#/api/ecommerce/shop-monthly-target';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
DatePicker,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createShopMonthlyTargetApi,
|
||||
updateShopMonthlyTargetApi,
|
||||
} from '#/api/ecommerce/shop-monthly-target';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
defineOptions({ name: 'ShopMonthlyTargetFormModal' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean;
|
||||
shopMonthlyTargetData?: null | ShopMonthlyTargetVO.Info;
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
(e: 'success'): void;
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[700px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<ShopMonthlyTargetDTO.Create>({
|
||||
shopId: undefined as any,
|
||||
targetMonth: '',
|
||||
targetAmount: undefined as any,
|
||||
targetOrderCount: undefined as any,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 目标月份选择器的值(dayjs对象)
|
||||
const targetMonthValue = ref<dayjs.Dayjs | null>(null);
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
targetMonth: [
|
||||
{ required: true, message: '请选择目标月份', trigger: 'change' },
|
||||
],
|
||||
targetAmount: [
|
||||
{ required: true, message: '请输入目标销售额', trigger: 'blur' },
|
||||
],
|
||||
targetOrderCount: [
|
||||
{ required: true, message: '请输入目标订单数', trigger: 'blur' },
|
||||
],
|
||||
} as any;
|
||||
|
||||
// 店铺列表
|
||||
const shopList = ref<ShopVO.Info[]>([]);
|
||||
const shopListLoading = ref(false);
|
||||
|
||||
// 监听props变化
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
modalApi.open();
|
||||
isEdit.value = !!props.shopMonthlyTargetData;
|
||||
if (props.shopMonthlyTargetData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: props.shopMonthlyTargetData.shopId,
|
||||
targetMonth: props.shopMonthlyTargetData.targetMonth,
|
||||
targetAmount: props.shopMonthlyTargetData.targetAmount,
|
||||
targetOrderCount: props.shopMonthlyTargetData.targetOrderCount,
|
||||
remark: props.shopMonthlyTargetData.remark || '',
|
||||
};
|
||||
// 设置目标月份选择器的值
|
||||
targetMonthValue.value = dayjs(props.shopMonthlyTargetData.targetMonth);
|
||||
} else {
|
||||
// 新增模式,重置表单数据
|
||||
resetFormData();
|
||||
}
|
||||
} else {
|
||||
modalApi.close();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 监听目标月份选择器变化
|
||||
watch(
|
||||
() => targetMonthValue.value,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
// 格式化为 YYYY-MM-01
|
||||
formData.value.targetMonth = newVal.format('YYYY-MM-01');
|
||||
} else {
|
||||
formData.value.targetMonth = '';
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 加载店铺列表
|
||||
const loadShopList = async () => {
|
||||
shopListLoading.value = true;
|
||||
try {
|
||||
const response = await getShopPageApi({
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
filters: {},
|
||||
});
|
||||
shopList.value = response.records;
|
||||
} catch (error) {
|
||||
console.error('加载店铺列表失败:', error);
|
||||
} finally {
|
||||
shopListLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 重置表单数据
|
||||
const resetFormData = () => {
|
||||
formData.value = {
|
||||
shopId: undefined as any,
|
||||
targetMonth: '',
|
||||
targetAmount: undefined as any,
|
||||
targetOrderCount: undefined as any,
|
||||
remark: '',
|
||||
};
|
||||
targetMonthValue.value = null;
|
||||
};
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && props.shopMonthlyTargetData) {
|
||||
// 更新店铺月销量目标
|
||||
const updateData: ShopMonthlyTargetDTO.Update = {
|
||||
targetMonth: formData.value.targetMonth,
|
||||
targetAmount: formData.value.targetAmount,
|
||||
targetOrderCount: formData.value.targetOrderCount,
|
||||
remark: formData.value.remark,
|
||||
};
|
||||
await updateShopMonthlyTargetApi(
|
||||
props.shopMonthlyTargetData.id,
|
||||
updateData,
|
||||
);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
// 创建店铺月销量目标
|
||||
await createShopMonthlyTargetApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
} catch (error) {
|
||||
console.error('操作失败:', error);
|
||||
message.error(isEdit.value ? '更新失败' : '创建失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
};
|
||||
|
||||
// 组件挂载时加载数据
|
||||
onMounted(() => {
|
||||
loadShopList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="isEdit ? '编辑月销量目标' : '新增月销量目标'">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺" name="shopId" required>
|
||||
<Select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
:loading="shopListLoading"
|
||||
:options="
|
||||
shopList.map((shop) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="目标月份" name="targetMonth" required>
|
||||
<DatePicker
|
||||
v-model:value="targetMonthValue"
|
||||
placeholder="请选择目标月份"
|
||||
picker="month"
|
||||
format="YYYY-MM"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="目标销售额" name="targetAmount" required>
|
||||
<InputNumber
|
||||
v-model:value="formData.targetAmount"
|
||||
placeholder="请输入目标销售额"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="目标订单数" name="targetOrderCount" required>
|
||||
<InputNumber
|
||||
v-model:value="formData.targetOrderCount"
|
||||
placeholder="请输入目标订单数"
|
||||
:min="0"
|
||||
:precision="0"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入备注(可选)"
|
||||
:rows="4"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type {
|
||||
ShopMonthlyTargetDTO,
|
||||
ShopMonthlyTargetVO,
|
||||
} from '#/api/ecommerce/shop-monthly-target';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import {
|
||||
deleteShopMonthlyTargetApi,
|
||||
getShopMonthlyTargetPageApi,
|
||||
} from '#/api/ecommerce/shop-monthly-target';
|
||||
|
||||
import ShopMonthlyTargetFormModal from './components/ShopMonthlyTargetFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopMonthlyTargetManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const formModalVisible = ref(false);
|
||||
const currentShopMonthlyTargetData = ref<null | ShopMonthlyTargetVO.Info>(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 }[]>([]);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'shopName',
|
||||
title: '店铺名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'targetMonth',
|
||||
title: '目标月份',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '目标销售额',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'targetAmount' },
|
||||
},
|
||||
{
|
||||
field: 'targetOrderCount',
|
||||
title: '目标订单数',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ShopMonthlyTargetDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: searchForm.value.shopId,
|
||||
startTargetMonth: searchForm.value.startTargetMonth,
|
||||
endTargetMonth: searchForm.value.endTargetMonth,
|
||||
},
|
||||
};
|
||||
const data = await getShopMonthlyTargetPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取店铺月销量目标列表失败:', error);
|
||||
message.error('获取店铺月销量目标列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择店铺',
|
||||
options: shopOptions.value,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '店铺',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '开始月份',
|
||||
picker: 'month',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'startTargetMonth',
|
||||
label: '目标月份',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '结束月份',
|
||||
picker: 'month',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'endTargetMonth',
|
||||
label: '至',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '店铺月销量目标管理',
|
||||
});
|
||||
|
||||
// 处理新增
|
||||
const handleAdd = () => {
|
||||
currentShopMonthlyTargetData.value = null;
|
||||
formModalVisible.value = true;
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
const handleEdit = (record: ShopMonthlyTargetVO.Info) => {
|
||||
currentShopMonthlyTargetData.value = record;
|
||||
formModalVisible.value = true;
|
||||
};
|
||||
|
||||
// 处理删除
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteShopMonthlyTargetApi(id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 处理表单成功
|
||||
const handleFormSuccess = () => {
|
||||
refreshTable();
|
||||
};
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toFixed(2)}`;
|
||||
};
|
||||
|
||||
// 获取店铺选项
|
||||
const fetchShopOptions = async () => {
|
||||
try {
|
||||
const response = await getShopPageApi({
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
filters: {},
|
||||
});
|
||||
shopOptions.value = response.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchShopOptions();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="店铺月销量目标管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理店铺月销量目标,支持按店铺、目标月份等维度查询和统计
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-2 h-4 w-4" />
|
||||
新增月销量目标
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<span class="text-gray-500">
|
||||
支持按店铺、目标月份等维度查询月销量目标
|
||||
</span>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 目标销售额列 -->
|
||||
<template #targetAmount="{ row }: { row: any }">
|
||||
<span class="font-medium text-red-600">
|
||||
{{ formatAmount(row.targetAmount) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这条月销量目标吗?"
|
||||
@confirm="handleDelete(row.id)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<ShopMonthlyTargetFormModal
|
||||
v-model:open="formModalVisible"
|
||||
:shop-monthly-target-data="currentShopMonthlyTargetData"
|
||||
@success="handleFormSuccess"
|
||||
@cancel="formModalVisible = false"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user