feat:【antd】【crm】联系人列表和详情组件的重构与优化
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
|||||||
BusinessForm,
|
BusinessForm,
|
||||||
UpStatusForm,
|
UpStatusForm,
|
||||||
} from '#/views/crm/business';
|
} from '#/views/crm/business';
|
||||||
import { ContactDetailsList } from '#/views/crm/contact';
|
import { ContactDetailsList } from '#/views/crm/contact/components';
|
||||||
import { ContractDetailsList } from '#/views/crm/contract';
|
import { ContractDetailsList } from '#/views/crm/contract';
|
||||||
import { FollowUp } from '#/views/crm/followup';
|
import { FollowUp } from '#/views/crm/followup';
|
||||||
import { PermissionList, TransferForm } from '#/views/crm/permission';
|
import { PermissionList, TransferForm } from '#/views/crm/permission';
|
||||||
|
|||||||
62
apps/web-antd/src/views/crm/contact/components/data.ts
Normal file
62
apps/web-antd/src/views/crm/contact/components/data.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
|
||||||
|
/** 联系人明细列表列配置 */
|
||||||
|
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: 'sex',
|
||||||
|
title: '性别',
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'mobile',
|
||||||
|
title: '手机',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'telephone',
|
||||||
|
title: '电话',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'email',
|
||||||
|
title: '邮箱',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'post',
|
||||||
|
title: '职位',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'detailAddress',
|
||||||
|
title: '地址',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'master',
|
||||||
|
title: '关键决策人',
|
||||||
|
cellRender: {
|
||||||
|
name: 'CellDict',
|
||||||
|
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<!-- 联系人列表的选择:用于【商机】详情中,选择它要关联的联系人 -->
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { CrmContactApi } from '#/api/crm/contact';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { Button, message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getContactPageByCustomer } from '#/api/crm/contact';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import Form from '../modules/form.vue';
|
||||||
|
import { useDetailListColumns } from './data';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
customerId?: number; // 关联联系人与商机时,需要传入 customerId 进行筛选
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
|
||||||
|
const { push } = useRouter();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const checkedRows = ref<CrmContactApi.Contact[]>([]);
|
||||||
|
function setCheckedRows({ records }: { records: CrmContactApi.Contact[] }) {
|
||||||
|
checkedRows.value = records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建商机 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData({ customerId: props.customerId }).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查看商机详情 */
|
||||||
|
function handleDetail(row: CrmContactApi.Contact) {
|
||||||
|
push({ name: 'CrmContactDetail', params: { id: row.id } });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查看客户详情 */
|
||||||
|
function handleCustomerDetail(row: CrmContactApi.Contact) {
|
||||||
|
push({ name: 'CrmCustomerDetail', params: { id: row.customerId } });
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
if (checkedRows.value.length === 0) {
|
||||||
|
message.error('请先选择联系人后操作!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
// 提交表单
|
||||||
|
try {
|
||||||
|
const contactIds = checkedRows.value.map((item) => item.id);
|
||||||
|
// 关闭并提示
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success', contactIds, checkedRows.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 getContactPageByCustomer({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
customerId: props.customerId,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<CrmContactApi.Contact>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: setCheckedRows,
|
||||||
|
checkboxChange: setCheckedRows,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal title="关联联系人" class="w-2/5">
|
||||||
|
<FormModal @success="handleRefresh" />
|
||||||
|
<Grid>
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['联系人']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['crm:contact: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>
|
||||||
210
apps/web-antd/src/views/crm/contact/components/detail-list.vue
Normal file
210
apps/web-antd/src/views/crm/contact/components/detail-list.vue
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
<!-- 联系人列表:用于【联系人】【商机】详情种,展示它们关联的联系人列表 -->
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { CrmContactApi } from '#/api/crm/contact';
|
||||||
|
|
||||||
|
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 {
|
||||||
|
createBusinessContactList,
|
||||||
|
deleteBusinessContactList,
|
||||||
|
getContactPageByBusiness,
|
||||||
|
getContactPageByCustomer,
|
||||||
|
} from '#/api/crm/contact';
|
||||||
|
import { BizTypeEnum } from '#/api/crm/permission';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import Form from '../modules/form.vue';
|
||||||
|
import { useDetailListColumns } from './data';
|
||||||
|
import ListModal from './detail-list-modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
bizId: number; // 业务编号
|
||||||
|
bizType: number; // 业务类型
|
||||||
|
businessId?: number; // 特殊:商机编号;在【商机】详情中,可以传递商机编号,默认新建的联系人关联到该商机
|
||||||
|
customerId?: number; // 特殊:客户编号;在【商机】详情中,可以传递客户编号,默认新建的联系人关联到该客户
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { push } = useRouter();
|
||||||
|
|
||||||
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: Form,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [DetailListModal, detailListModalApi] = useVbenModal({
|
||||||
|
connectedComponent: ListModal,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const checkedRows = ref<CrmContactApi.Contact[]>([]);
|
||||||
|
function setCheckedRows({ records }: { records: CrmContactApi.Contact[] }) {
|
||||||
|
checkedRows.value = records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建联系人 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi
|
||||||
|
.setData({ customerId: props.customerId, businessId: props.businessId })
|
||||||
|
.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 关联联系人 */
|
||||||
|
function handleCreateContact() {
|
||||||
|
detailListModalApi.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 deleteBusinessContactList({
|
||||||
|
businessId: props.bizId,
|
||||||
|
contactIds: checkedRows.value.map((item) => item.id),
|
||||||
|
});
|
||||||
|
if (res) {
|
||||||
|
// 提示并返回成功
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
handleRefresh();
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
reject(new Error($t('ui.actionMessage.operationFailed')));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
reject(new Error('取消操作'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建商机联系人关联 */
|
||||||
|
async function handleCreateBusinessContactList(contactIds: number[]) {
|
||||||
|
const data = {
|
||||||
|
businessId: props.bizId,
|
||||||
|
contactIds,
|
||||||
|
} as CrmContactApi.BusinessContactReq;
|
||||||
|
await createBusinessContactList(data);
|
||||||
|
handleRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查看联系人详情 */
|
||||||
|
function handleDetail(row: CrmContactApi.Contact) {
|
||||||
|
push({ name: 'CrmContactDetail', params: { id: row.id } });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查看客户详情 */
|
||||||
|
function handleCustomerDetail(row: CrmContactApi.Contact) {
|
||||||
|
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 getContactPageByCustomer({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
customerId: props.bizId,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
} else if (props.bizType === BizTypeEnum.CRM_BUSINESS) {
|
||||||
|
return await getContactPageByBusiness({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
businessId: props.bizId,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<CrmContactApi.Contact>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: setCheckedRows,
|
||||||
|
checkboxChange: setCheckedRows,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<FormModal @success="handleRefresh" />
|
||||||
|
<DetailListModal
|
||||||
|
:customer-id="customerId"
|
||||||
|
@success="handleCreateBusinessContactList"
|
||||||
|
/>
|
||||||
|
<Grid>
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['联系人']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关联',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
type: 'default',
|
||||||
|
auth: ['crm:contact:create-business'],
|
||||||
|
ifShow: () => !!businessId,
|
||||||
|
onClick: handleCreateContact,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '解除关联',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
type: 'default',
|
||||||
|
auth: ['crm:contact:create-business'],
|
||||||
|
ifShow: () => !!businessId,
|
||||||
|
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>
|
||||||
1
apps/web-antd/src/views/crm/contact/components/index.ts
Normal file
1
apps/web-antd/src/views/crm/contact/components/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default as ContactDetailsList } from './detail-list.vue';
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import { defineAsyncComponent } from 'vue';
|
|
||||||
|
|
||||||
export const ContactDetailsList = defineAsyncComponent(
|
|
||||||
() => import('./components/detail-list.vue'),
|
|
||||||
);
|
|
||||||
@@ -23,7 +23,7 @@ import { useDescription } from '#/components/description';
|
|||||||
import { AsyncOperateLog } from '#/components/operate-log';
|
import { AsyncOperateLog } from '#/components/operate-log';
|
||||||
import { ACTION_ICON, TableAction } from '#/components/table-action';
|
import { ACTION_ICON, TableAction } from '#/components/table-action';
|
||||||
import { BusinessDetailsList } from '#/views/crm/business';
|
import { BusinessDetailsList } from '#/views/crm/business';
|
||||||
import { ContactDetailsList } from '#/views/crm/contact';
|
import { ContactDetailsList } from '#/views/crm/contact/components';
|
||||||
import { ContractDetailsList } from '#/views/crm/contract';
|
import { ContractDetailsList } from '#/views/crm/contract';
|
||||||
import {
|
import {
|
||||||
CustomerDetailsInfo,
|
CustomerDetailsInfo,
|
||||||
|
|||||||
Reference in New Issue
Block a user