mirror of
https://gitee.com/qqtt-ah/ai-crm.git
synced 2026-11-25 11:09:20 +08:00
feat: 落地 CRM Phase0 客户/产品(表结构、CRUD、Excel导入与菜单)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { CrmCustomerDTO, CrmCustomerVO, CrmImportResultVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export async function getCrmCustomerPageApi(
|
||||
params: PageQueryDTO<CrmCustomerDTO.Filters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<CrmCustomerVO.Info>>(
|
||||
'/crm/customer/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCrmCustomerApi(id: number) {
|
||||
return requestClient.get<CrmCustomerVO.Info>(`/crm/customer/${id}`);
|
||||
}
|
||||
|
||||
export async function createCrmCustomerApi(data: CrmCustomerDTO.Create) {
|
||||
return requestClient.post<CrmCustomerVO.Info>('/crm/customer/create', data);
|
||||
}
|
||||
|
||||
export async function updateCrmCustomerApi(
|
||||
id: number,
|
||||
data: CrmCustomerDTO.Update,
|
||||
) {
|
||||
return requestClient.put<CrmCustomerVO.Info>(
|
||||
`/crm/customer/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteCrmCustomerApi(id: number) {
|
||||
return requestClient.delete(`/crm/customer/delete/${id}`);
|
||||
}
|
||||
|
||||
export async function importCrmCustomerApi(file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
return requestClient.post<CrmImportResultVO>('/crm/customer/import', form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,27 @@
|
||||
/** 客户 DTO */
|
||||
export namespace CrmCustomerDTO {
|
||||
export interface Create {
|
||||
name: string;
|
||||
nameEn?: string;
|
||||
country?: string;
|
||||
address?: string;
|
||||
contactName?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
currency?: string;
|
||||
paymentTerms?: string;
|
||||
status?: string;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export type Update = Create;
|
||||
|
||||
export interface Filters {
|
||||
keyword?: string;
|
||||
status?: string;
|
||||
country?: string;
|
||||
ownerUserId?: number;
|
||||
onlyMine?: boolean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/** 客户 VO */
|
||||
export namespace CrmCustomerVO {
|
||||
export interface Info {
|
||||
id: number;
|
||||
companyId: number;
|
||||
name: string;
|
||||
nameEn?: string;
|
||||
country?: string;
|
||||
address?: string;
|
||||
contactName?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
currency?: string;
|
||||
paymentTerms?: string;
|
||||
status?: string;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CrmImportResultVO {
|
||||
successCount: number;
|
||||
failCount: number;
|
||||
errors: Array<{ rowNum: number; message: string }>;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { CrmProductDTO, CrmProductVO } from './types';
|
||||
import type { CrmImportResultVO } from '#/api/crm/customer';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export async function getCrmProductPageApi(
|
||||
params: PageQueryDTO<CrmProductDTO.Filters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<CrmProductVO.Info>>(
|
||||
'/crm/product/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCrmProductApi(id: number) {
|
||||
return requestClient.get<CrmProductVO.Info>(`/crm/product/${id}`);
|
||||
}
|
||||
|
||||
export async function createCrmProductApi(data: CrmProductDTO.Create) {
|
||||
return requestClient.post<CrmProductVO.Info>('/crm/product/create', data);
|
||||
}
|
||||
|
||||
export async function updateCrmProductApi(
|
||||
id: number,
|
||||
data: CrmProductDTO.Update,
|
||||
) {
|
||||
return requestClient.put<CrmProductVO.Info>(
|
||||
`/crm/product/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteCrmProductApi(id: number) {
|
||||
return requestClient.delete(`/crm/product/delete/${id}`);
|
||||
}
|
||||
|
||||
export async function importCrmProductApi(file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
return requestClient.post<CrmImportResultVO>('/crm/product/import', form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,25 @@
|
||||
/** 产品 DTO */
|
||||
export namespace CrmProductDTO {
|
||||
export interface Create {
|
||||
code: string;
|
||||
nameZh?: string;
|
||||
nameEn: string;
|
||||
spec?: string;
|
||||
unit?: string;
|
||||
unitPrice?: number;
|
||||
currency?: string;
|
||||
hsCode?: string;
|
||||
grossWeightKg?: number;
|
||||
netWeightKg?: number;
|
||||
volumeCbm?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export type Update = Create;
|
||||
|
||||
export interface Filters {
|
||||
keyword?: string;
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/** 产品 VO */
|
||||
export namespace CrmProductVO {
|
||||
export interface Info {
|
||||
id: number;
|
||||
companyId: number;
|
||||
code: string;
|
||||
nameZh?: string;
|
||||
nameEn: string;
|
||||
spec?: string;
|
||||
unit?: string;
|
||||
unitPrice?: number;
|
||||
currency?: string;
|
||||
hsCode?: string;
|
||||
grossWeightKg?: number;
|
||||
netWeightKg?: number;
|
||||
volumeCbm?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CrmCustomerVO } from '#/api/crm/customer';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createCrmCustomerApi,
|
||||
updateCrmCustomerApi,
|
||||
} from '#/api/crm/customer';
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[560px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const editingId = ref<number>();
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '潜在', value: 'lead' },
|
||||
{ label: '跟进中', value: 'following' },
|
||||
{ label: '成交', value: 'won' },
|
||||
{ label: '暂停', value: 'paused' },
|
||||
];
|
||||
|
||||
const formData = ref({
|
||||
name: '',
|
||||
nameEn: '',
|
||||
country: '',
|
||||
address: '',
|
||||
contactName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
currency: 'USD',
|
||||
paymentTerms: '',
|
||||
status: 'lead',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
const rules = {
|
||||
name: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
function open(edit = false, row?: CrmCustomerVO.Info) {
|
||||
isEdit.value = edit;
|
||||
editingId.value = row?.id;
|
||||
formData.value = {
|
||||
name: row?.name ?? '',
|
||||
nameEn: row?.nameEn ?? '',
|
||||
country: row?.country ?? '',
|
||||
address: row?.address ?? '',
|
||||
contactName: row?.contactName ?? '',
|
||||
email: row?.email ?? '',
|
||||
phone: row?.phone ?? '',
|
||||
currency: row?.currency ?? 'USD',
|
||||
paymentTerms: row?.paymentTerms ?? '',
|
||||
status: row?.status ?? 'lead',
|
||||
remark: row?.remark ?? '',
|
||||
};
|
||||
modalApi.setState({ title: edit ? '编辑客户' : '新建客户' });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
try {
|
||||
if (isEdit.value && editingId.value) {
|
||||
await updateCrmCustomerApi(editingId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCrmCustomerApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<Form.Item label="客户名称" name="name">
|
||||
<Input v-model:value="formData.name" placeholder="公司名" />
|
||||
</Form.Item>
|
||||
<Form.Item label="英文名" name="nameEn">
|
||||
<Input v-model:value="formData.nameEn" />
|
||||
</Form.Item>
|
||||
<Form.Item label="国家/地区" name="country">
|
||||
<Input v-model:value="formData.country" />
|
||||
</Form.Item>
|
||||
<Form.Item label="联系人" name="contactName">
|
||||
<Input v-model:value="formData.contactName" />
|
||||
</Form.Item>
|
||||
<Form.Item label="邮箱" name="email">
|
||||
<Input v-model:value="formData.email" />
|
||||
</Form.Item>
|
||||
<Form.Item label="电话" name="phone">
|
||||
<Input v-model:value="formData.phone" />
|
||||
</Form.Item>
|
||||
<Form.Item label="币种" name="currency">
|
||||
<Input v-model:value="formData.currency" placeholder="USD" />
|
||||
</Form.Item>
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select v-model:value="formData.status" :options="statusOptions" />
|
||||
</Form.Item>
|
||||
<Form.Item label="地址" name="address">
|
||||
<Input.TextArea v-model:value="formData.address" :rows="2" />
|
||||
</Form.Item>
|
||||
<Form.Item label="付款条款" name="paymentTerms">
|
||||
<Input v-model:value="formData.paymentTerms" />
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea v-model:value="formData.remark" :rows="2" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,233 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CrmCustomerDTO, CrmCustomerVO } from '#/api/crm/customer';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space, Tag, Upload } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCrmCustomerApi,
|
||||
getCrmCustomerPageApi,
|
||||
importCrmCustomerApi,
|
||||
} from '#/api/crm/customer';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
import { exportByGet } from '#/utils/export';
|
||||
|
||||
import CustomerModal from './components/CustomerModal.vue';
|
||||
|
||||
defineOptions({ name: 'CrmCustomer' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
|
||||
const loading = ref(false);
|
||||
const modalRef = ref<InstanceType<typeof CustomerModal>>();
|
||||
const searchForm = ref({ keyword: '', status: undefined as string | undefined });
|
||||
|
||||
const statusMap: Record<string, { color: string; label: string }> = {
|
||||
lead: { color: 'default', label: '潜在' },
|
||||
following: { color: 'processing', label: '跟进中' },
|
||||
won: { color: 'success', label: '成交' },
|
||||
paused: { color: 'warning', label: '暂停' },
|
||||
};
|
||||
|
||||
const actionCodes = [
|
||||
'crm:customer:create',
|
||||
'crm:customer:update',
|
||||
'crm:customer:delete',
|
||||
'crm:customer:import',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(actionCodes);
|
||||
|
||||
const baseColumns: VxeGridProps<CrmCustomerVO.Info>['columns'] = [
|
||||
{ type: 'seq', title: '序号', minWidth: 60 },
|
||||
{ field: 'name', title: '客户名称', minWidth: 160 },
|
||||
{ field: 'country', title: '国家', minWidth: 100 },
|
||||
{ field: 'contactName', title: '联系人', minWidth: 100 },
|
||||
{ field: 'email', title: '邮箱', minWidth: 160 },
|
||||
{ field: 'phone', title: '电话', minWidth: 120 },
|
||||
{ field: 'currency', title: '币种', minWidth: 80 },
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{ field: 'createTime', title: '创建时间', minWidth: 160 },
|
||||
];
|
||||
|
||||
const actionColumn: NonNullable<
|
||||
VxeGridProps<CrmCustomerVO.Info>['columns']
|
||||
>[number] = {
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(baseColumns ?? []), actionColumn]
|
||||
: (baseColumns ?? []),
|
||||
);
|
||||
|
||||
const gridOptions: VxeGridProps<CrmCustomerVO.Info> = {
|
||||
columns: tableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: { custom: true, refresh: true, zoom: true },
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<CrmCustomerDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
keyword: searchForm.value.keyword || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getCrmCustomerPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: {
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'keyword',
|
||||
label: '关键词',
|
||||
componentProps: { placeholder: '名称/联系人/邮箱' },
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: Object.entries(statusMap).map(([value, v]) => ({
|
||||
value,
|
||||
label: v.label,
|
||||
})),
|
||||
},
|
||||
},
|
||||
],
|
||||
handleSubmit: async (values: Record<string, any>) => {
|
||||
searchForm.value.keyword = values.keyword ?? '';
|
||||
searchForm.value.status = values.status;
|
||||
gridApi.reload();
|
||||
},
|
||||
},
|
||||
});
|
||||
syncVxeGridColumns(gridApi, tableColumns);
|
||||
|
||||
async function handleDelete(row: CrmCustomerVO.Info) {
|
||||
await deleteCrmCustomerApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function downloadTemplate() {
|
||||
await exportByGet(
|
||||
'/crm/customer/import/template',
|
||||
'crm-customer-import.xlsx',
|
||||
);
|
||||
}
|
||||
|
||||
async function handleImport(file: File) {
|
||||
const result = await importCrmCustomerApi(file);
|
||||
if (result.failCount > 0) {
|
||||
message.warning(
|
||||
`成功 ${result.successCount},失败 ${result.failCount}:${result.errors?.[0]?.message ?? ''}`,
|
||||
);
|
||||
} else {
|
||||
message.success(`成功导入 ${result.successCount} 条`);
|
||||
}
|
||||
gridApi.reload();
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<PermissionGate code="crm:customer:import">
|
||||
<Button @click="downloadTemplate">
|
||||
<DownloadIcon class="size-4" />
|
||||
下载模板
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:customer:import">
|
||||
<Upload
|
||||
:show-upload-list="false"
|
||||
:before-upload="handleImport"
|
||||
accept=".xlsx,.xls"
|
||||
>
|
||||
<Button>
|
||||
<UploadIcon class="size-4" />
|
||||
导入
|
||||
</Button>
|
||||
</Upload>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:customer:create">
|
||||
<Button type="primary" @click="modalRef?.open(false)">
|
||||
<PlusIcon class="size-4" />
|
||||
新建
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag :color="statusMap[row.status]?.color ?? 'default'">
|
||||
{{ statusMap[row.status]?.label ?? row.status }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<PermissionGate code="crm:customer:update">
|
||||
<Button type="link" size="small" @click="modalRef?.open(true, row)">
|
||||
编辑
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:customer:delete">
|
||||
<Popconfirm title="确认删除该客户?" @confirm="handleDelete(row)">
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<CustomerModal ref="modalRef" @success="gridApi.reload()" />
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,143 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CrmProductVO } from '#/api/crm/product';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, InputNumber, message, Select } from 'ant-design-vue';
|
||||
|
||||
import { createCrmProductApi, updateCrmProductApi } from '#/api/crm/product';
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[560px]',
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
const editingId = ref<number>();
|
||||
|
||||
const formData = ref({
|
||||
code: '',
|
||||
nameZh: '',
|
||||
nameEn: '',
|
||||
spec: '',
|
||||
unit: 'PCS',
|
||||
unitPrice: undefined as number | undefined,
|
||||
currency: 'USD',
|
||||
hsCode: '',
|
||||
status: 1,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
const rules = {
|
||||
code: [{ required: true, message: '请输入编码', trigger: 'blur' }],
|
||||
nameEn: [{ required: true, message: '请输入英文名', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
function open(edit = false, row?: CrmProductVO.Info) {
|
||||
isEdit.value = edit;
|
||||
editingId.value = row?.id;
|
||||
formData.value = {
|
||||
code: row?.code ?? '',
|
||||
nameZh: row?.nameZh ?? '',
|
||||
nameEn: row?.nameEn ?? '',
|
||||
spec: row?.spec ?? '',
|
||||
unit: row?.unit ?? 'PCS',
|
||||
unitPrice: row?.unitPrice,
|
||||
currency: row?.currency ?? 'USD',
|
||||
hsCode: row?.hsCode ?? '',
|
||||
status: row?.status ?? 1,
|
||||
remark: row?.remark ?? '',
|
||||
};
|
||||
modalApi.setState({ title: edit ? '编辑产品' : '新建产品' });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
try {
|
||||
if (isEdit.value && editingId.value) {
|
||||
await updateCrmProductApi(editingId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCrmProductApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<Form.Item label="编码" name="code">
|
||||
<Input v-model:value="formData.code" />
|
||||
</Form.Item>
|
||||
<Form.Item label="英文名" name="nameEn">
|
||||
<Input v-model:value="formData.nameEn" />
|
||||
</Form.Item>
|
||||
<Form.Item label="中文名" name="nameZh">
|
||||
<Input v-model:value="formData.nameZh" />
|
||||
</Form.Item>
|
||||
<Form.Item label="规格" name="spec">
|
||||
<Input v-model:value="formData.spec" />
|
||||
</Form.Item>
|
||||
<Form.Item label="单位" name="unit">
|
||||
<Input v-model:value="formData.unit" />
|
||||
</Form.Item>
|
||||
<Form.Item label="参考单价" name="unitPrice">
|
||||
<InputNumber
|
||||
v-model:value="formData.unitPrice"
|
||||
class="w-full"
|
||||
:min="0"
|
||||
:precision="4"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="币种" name="currency">
|
||||
<Input v-model:value="formData.currency" />
|
||||
</Form.Item>
|
||||
<Form.Item label="HS Code" name="hsCode">
|
||||
<Input v-model:value="formData.hsCode" />
|
||||
</Form.Item>
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
:options="[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea v-model:value="formData.remark" :rows="2" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,227 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CrmProductDTO, CrmProductVO } from '#/api/crm/product';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space, Tag, Upload } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCrmProductApi,
|
||||
getCrmProductPageApi,
|
||||
importCrmProductApi,
|
||||
} from '#/api/crm/product';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
import { exportByGet } from '#/utils/export';
|
||||
|
||||
import ProductModal from './components/ProductModal.vue';
|
||||
|
||||
defineOptions({ name: 'CrmProduct' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
|
||||
const loading = ref(false);
|
||||
const modalRef = ref<InstanceType<typeof ProductModal>>();
|
||||
const searchForm = ref({
|
||||
keyword: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
const actionCodes = [
|
||||
'crm:product:create',
|
||||
'crm:product:update',
|
||||
'crm:product:delete',
|
||||
'crm:product:import',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(actionCodes);
|
||||
|
||||
const baseColumns: VxeGridProps<CrmProductVO.Info>['columns'] = [
|
||||
{ type: 'seq', title: '序号', minWidth: 60 },
|
||||
{ field: 'code', title: '编码', minWidth: 120 },
|
||||
{ field: 'nameEn', title: '英文名', minWidth: 160 },
|
||||
{ field: 'nameZh', title: '中文名', minWidth: 140 },
|
||||
{ field: 'unit', title: '单位', minWidth: 80 },
|
||||
{ field: 'unitPrice', title: '单价', minWidth: 100 },
|
||||
{ field: 'currency', title: '币种', minWidth: 80 },
|
||||
{ field: 'hsCode', title: 'HS', minWidth: 100 },
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 90,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{ field: 'createTime', title: '创建时间', minWidth: 160 },
|
||||
];
|
||||
|
||||
const actionColumn: NonNullable<
|
||||
VxeGridProps<CrmProductVO.Info>['columns']
|
||||
>[number] = {
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(baseColumns ?? []), actionColumn]
|
||||
: (baseColumns ?? []),
|
||||
);
|
||||
|
||||
const gridOptions: VxeGridProps<CrmProductVO.Info> = {
|
||||
columns: tableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: { custom: true, refresh: true, zoom: true },
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<CrmProductDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
keyword: searchForm.value.keyword || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getCrmProductPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: {
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'keyword',
|
||||
label: '关键词',
|
||||
componentProps: { placeholder: '编码/名称/HS' },
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
handleSubmit: async (values: Record<string, any>) => {
|
||||
searchForm.value.keyword = values.keyword ?? '';
|
||||
searchForm.value.status = values.status;
|
||||
gridApi.reload();
|
||||
},
|
||||
},
|
||||
});
|
||||
syncVxeGridColumns(gridApi, tableColumns);
|
||||
|
||||
async function handleDelete(row: CrmProductVO.Info) {
|
||||
await deleteCrmProductApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function downloadTemplate() {
|
||||
await exportByGet('/crm/product/import/template', 'crm-product-import.xlsx');
|
||||
}
|
||||
|
||||
async function handleImport(file: File) {
|
||||
const result = await importCrmProductApi(file);
|
||||
if (result.failCount > 0) {
|
||||
message.warning(
|
||||
`成功 ${result.successCount},失败 ${result.failCount}:${result.errors?.[0]?.message ?? ''}`,
|
||||
);
|
||||
} else {
|
||||
message.success(`成功导入 ${result.successCount} 条`);
|
||||
}
|
||||
gridApi.reload();
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<PermissionGate code="crm:product:import">
|
||||
<Button @click="downloadTemplate">
|
||||
<DownloadIcon class="size-4" />
|
||||
下载模板
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:product:import">
|
||||
<Upload
|
||||
:show-upload-list="false"
|
||||
:before-upload="handleImport"
|
||||
accept=".xlsx,.xls"
|
||||
>
|
||||
<Button>
|
||||
<UploadIcon class="size-4" />
|
||||
导入
|
||||
</Button>
|
||||
</Upload>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:product:create">
|
||||
<Button type="primary" @click="modalRef?.open(false)">
|
||||
<PlusIcon class="size-4" />
|
||||
新建
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag :color="row.status === 1 ? 'success' : 'default'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<PermissionGate code="crm:product:update">
|
||||
<Button type="link" size="small" @click="modalRef?.open(true, row)">
|
||||
编辑
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:product:delete">
|
||||
<Popconfirm title="确认删除该产品?" @confirm="handleDelete(row)">
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<ProductModal ref="modalRef" @success="gridApi.reload()" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user