feat: business list

pull/128/head
xingyu4j 2025-06-04 21:17:36 +08:00
parent 4edd889883
commit 070274de15
7 changed files with 423 additions and 18 deletions

View File

@ -56,6 +56,15 @@ export function useFormSchema(): VbenFormSchema[] {
}, },
rules: 'required', rules: 'required',
}, },
{
fieldName: 'contactId',
label: '合同名称',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{ {
fieldName: 'statusTypeId', fieldName: 'statusTypeId',
label: '商机状态组', label: '商机状态组',
@ -69,7 +78,7 @@ export function useFormSchema(): VbenFormSchema[] {
}, },
dependencies: { dependencies: {
triggerFields: ['id'], triggerFields: ['id'],
disabled: (values) => !values.id, disabled: (values) => values.id,
}, },
rules: 'required', rules: 'required',
}, },
@ -285,3 +294,54 @@ export function useDetailBaseSchema(): DescriptionItemSchema[] {
}, },
]; ];
} }
/** 详情列表的字段 */
export function useDetailListColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'name',
title: '商机名称',
fixed: 'left',
slots: { default: 'name' },
},
{
field: 'customerName',
title: '客户名称',
fixed: 'left',
slots: { default: 'customerName' },
},
{
field: 'totalPrice',
title: '商机金额(元)',
formatter: 'formatNumber',
},
{
field: 'dealTime',
title: '预计成交日期',
formatter: 'formatDate',
},
{
field: 'ownerUserName',
title: '负责人',
},
{
field: 'ownerUserDeptName',
title: '所属部门',
},
{
field: 'statusTypeName',
title: '商机状态组',
fixed: 'right',
},
{
field: 'statusName',
title: '商机阶段',
fixed: 'right',
},
];
}

View File

@ -0,0 +1,155 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmBusinessApi } from '#/api/crm/business';
import { useRouter } from 'vue-router';
import { useVbenModal } from '@vben/common-ui';
import { Button } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getBusinessPageByCustomer } from '#/api/crm/business';
import { $t } from '#/locales';
import { useDetailListColumns } from '../data';
import Form from './form.vue';
const props = defineProps<{
customerId?: number; // customerId
}>();
const emit = defineEmits(['success']);
const { push } = useRouter();
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建商机 */
function handleCreate() {
formModalApi.setData({ customerId: props.customerId }).open();
}
/** 查看商机详情 */
function handleDetail(row: CrmBusinessApi.Business) {
push({ name: 'CrmBusinessDetail', params: { id: row.id } });
}
/** 查看客户详情 */
function handleCustomerDetail(row: CrmBusinessApi.Business) {
push({ name: 'CrmCustomerDetail', params: { id: row.customerId } });
}
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
// const { valid } = await formApi.validate();
// if (!valid) {
// return;
// }
// modalApi.lock();
// //
// const data = (await formApi.getValues()) as CrmBusinessApi.Business;
// try {
// await (formData.value?.id ? updateBusiness(data) : createBusiness(data));
// //
// await modalApi.close();
emit('success');
// message.success($t('ui.actionMessage.operationSuccess'));
// } finally {
// modalApi.unlock();
// }
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
return;
}
//
const data = modalApi.getData<any>();
if (!data) {
return;
}
modalApi.lock();
try {
// values
// await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: [
{
fieldName: 'name',
label: '商机名称',
component: 'Input',
},
],
},
gridOptions: {
columns: useDetailListColumns(),
height: 600,
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getBusinessPageByCustomer({
page: page.currentPage,
pageSize: page.pageSize,
customerId: props.customerId,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<CrmBusinessApi.Business>,
});
</script>
<template>
<Modal title="关联商机" class="w-[40%]">
<FormModal @success="onRefresh" />
<Grid>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['商机']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:business:create'],
onClick: handleCreate,
},
]"
/>
</template>
<template #name="{ row }">
<Button type="link" @click="handleDetail(row)">
{{ row.name }}
</Button>
</template>
<template #customerName="{ row }">
<Button type="link" @click="handleCustomerDetail(row)">
{{ row.customerName }}
</Button>
</template>
</Grid>
</Modal>
</template>

View File

@ -1,4 +1,190 @@
<script lang="ts" setup></script> <script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmBusinessApi } from '#/api/crm/business';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { confirm, useVbenModal } from '@vben/common-ui';
import { Button, message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getBusinessPage } from '#/api/crm/business';
import { createContactBusinessList } from '#/api/crm/contact';
import { BizTypeEnum } from '#/api/crm/permission';
import { $t } from '#/locales';
import { useDetailListColumns } from '../data';
import DetailForm from './detail-form.vue';
import Form from './form.vue';
const props = defineProps<{
bizId: number; //
bizType: number; //
contactId?: number; //
customerId?: number; // customerId
}>();
const { push } = useRouter();
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [DetailFormModal, detailFormModalApi] = useVbenModal({
connectedComponent: DetailForm,
destroyOnClose: true,
});
const checkedRows = ref<CrmBusinessApi.Business[]>([]);
function setCheckedRows({ records }: { records: CrmBusinessApi.Business[] }) {
checkedRows.value = records;
}
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建商机 */
function handleCreate() {
formModalApi
.setData({ customerId: props.customerId, contactId: props.contactId })
.open();
}
function handleCreateBusiness() {
detailFormModalApi.setData({ customerId: props.customerId }).open();
}
async function handleDeleteContactBusinessList() {
if (checkedRows.value.length === 0) {
message.error('请先选择商机后操作!');
return;
}
return new Promise((resolve, reject) => {
confirm({
content: `确定要将${checkedRows.value.map((item) => item.name).join(',')}解除关联吗?`,
})
.then(async () => {
const res = await createContactBusinessList({
contactId: props.bizId,
businessIds: checkedRows.value.map((item) => item.id),
});
if (res) {
//
message.success($t('ui.actionMessage.operationSuccess'));
onRefresh();
resolve(true);
} else {
reject(new Error($t('ui.actionMessage.operationFailed')));
}
})
.catch(() => {
reject(new Error('取消操作'));
});
});
}
/** 查看商机详情 */
function handleDetail(row: CrmBusinessApi.Business) {
push({ name: 'CrmBusinessDetail', params: { id: row.id } });
}
/** 查看客户详情 */
function handleCustomerDetail(row: CrmBusinessApi.Business) {
push({ name: 'CrmCustomerDetail', params: { id: row.customerId } });
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useDetailListColumns(),
height: 600,
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
if (props.bizType === BizTypeEnum.CRM_CUSTOMER) {
return await getBusinessPage({
page: page.currentPage,
pageSize: page.pageSize,
customerId: props.customerId,
...formValues,
});
} else if (props.bizType === BizTypeEnum.CRM_CONTACT) {
return await getBusinessPage({
page: page.currentPage,
pageSize: page.pageSize,
contactId: props.contactId,
...formValues,
});
} else {
return [];
}
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<CrmBusinessApi.Business>,
gridEvents: {
checkboxAll: setCheckedRows,
checkboxChange: setCheckedRows,
},
});
</script>
<template> <template>
<div>businessList</div> <div>
<FormModal @success="onRefresh" />
<DetailFormModal :customer-id="customerId" @success="onRefresh" />
<Grid>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['商机']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:business:create'],
onClick: handleCreate,
},
{
label: '关联',
icon: ACTION_ICON.ADD,
type: 'default',
auth: ['crm:contact:create-business'],
ifShow: () => !!contactId,
onClick: handleCreateBusiness,
},
{
label: '解除关联',
icon: ACTION_ICON.ADD,
type: 'default',
auth: ['crm:contact:create-business'],
ifShow: () => !!contactId,
onClick: handleDeleteContactBusinessList,
},
]"
/>
</template>
<template #name="{ row }">
<Button type="link" @click="handleDetail(row)">
{{ row.name }}
</Button>
</template>
<template #customerName="{ row }">
<Button type="link" @click="handleCustomerDetail(row)">
{{ row.customerName }}
</Button>
</template>
</Grid>
</div>
</template> </template>

View File

@ -64,12 +64,12 @@ const [Modal, modalApi] = useVbenModal({
} }
// //
const data = modalApi.getData<CrmBusinessApi.Business>(); const data = modalApi.getData<CrmBusinessApi.Business>();
if (!data || !data.id) { if (!data) {
return; return;
} }
modalApi.lock(); modalApi.lock();
try { try {
formData.value = await getBusiness(data.id as number); formData.value = data.id ? await getBusiness(data.id as number) : data;
// values // values
await formApi.setValues(formData.value); await formApi.setValues(formData.value);
} finally { } finally {

View File

@ -21,6 +21,14 @@ const CustomerDetailsInfo = defineAsyncComponent(
() => import('./detail-info.vue'), () => import('./detail-info.vue'),
); );
const CustomerForm = defineAsyncComponent(
() => import('#/views/crm/customer/modules/form.vue'),
);
const BusinessList = defineAsyncComponent(
() => import('#/views/crm/business/modules/detail-list.vue'),
);
const FollowUp = defineAsyncComponent( const FollowUp = defineAsyncComponent(
() => import('#/views/crm/followup/index.vue'), () => import('#/views/crm/followup/index.vue'),
); );
@ -37,10 +45,6 @@ const OperateLog = defineAsyncComponent(
() => import('#/components/operate-log'), () => import('#/components/operate-log'),
); );
const CustomerForm = defineAsyncComponent(
() => import('#/views/crm/customer/modules/form.vue'),
);
const loading = ref(false); const loading = ref(false);
const route = useRoute(); const route = useRoute();
@ -236,7 +240,11 @@ onMounted(async () => {
/> />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab="商机" key="5" :force-render="true"> <Tabs.TabPane tab="商机" key="5" :force-render="true">
<div>商机</div> <BusinessList
:biz-id="customerId"
:biz-type="BizTypeEnum.CRM_CUSTOMER"
:customer-id="customerId"
/>
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab="合同" key="6" :force-render="true"> <Tabs.TabPane tab="合同" key="6" :force-render="true">
<div>合同</div> <div>合同</div>

View File

@ -5,7 +5,7 @@ import type { CrmFollowUpApi } from '#/api/crm/followup';
import { watch } from 'vue'; import { watch } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { Button, message } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
@ -79,7 +79,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
field: 'createTime', field: 'createTime',
title: '创建时间', title: '创建时间',
width: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ field: 'creatorName', title: '跟进人' }, { field: 'creatorName', title: '跟进人' },
@ -95,7 +94,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
field: 'nextTime', field: 'nextTime',
title: '下次联系时间', title: '下次联系时间',
width: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
@ -113,11 +111,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
field: 'actions', field: 'actions',
title: '操作', title: '操作',
width: 100,
slots: { default: 'actions' }, slots: { default: 'actions' },
}, },
], ],
height: 'auto', height: 600,
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
ajax: { ajax: {
@ -149,7 +146,7 @@ watch(
</script> </script>
<template> <template>
<Page auto-content-height> <div>
<FormModal @success="onRefresh" /> <FormModal @success="onRefresh" />
<Grid> <Grid>
<template #toolbar-tools> <template #toolbar-tools>
@ -191,5 +188,5 @@ watch(
/> />
</template> </template>
</Grid> </Grid>
</Page> </div>
</template> </template>

View File

@ -102,7 +102,6 @@ function handleDelete() {
content: `你要将${checkedRows.value.map((item) => item.nickname).join(',')}移出团队吗?`, content: `你要将${checkedRows.value.map((item) => item.nickname).join(',')}移出团队吗?`,
}) })
.then(async () => { .then(async () => {
//
const res = await deletePermissionBatch( const res = await deletePermissionBatch(
checkedRows.value.map((item) => item.id as number), checkedRows.value.map((item) => item.id as number),
); );