feat:【ele】【crm】contact 的迁移初始化

This commit is contained in:
YunaiV
2025-11-19 08:23:18 +08:00
parent 20f0ed8415
commit 775fd1d732
11 changed files with 1381 additions and 9 deletions

View File

@@ -65,15 +65,15 @@ const routes: RouteRecordRaw[] = [
},
component: () => import('#/views/crm/receivable/detail/index.vue'),
},
// {
// path: 'contact/detail/:id',
// name: 'CrmContactDetail',
// meta: {
// title: '联系人详情',
// activePath: '/crm/contact',
// },
// component: () => import('#/views/crm/contact/detail/index.vue'),
// },
{
path: 'contact/detail/:id',
name: 'CrmContactDetail',
meta: {
title: '联系人详情',
activePath: '/crm/contact',
},
component: () => import('#/views/crm/contact/detail/index.vue'),
},
{
path: 'product/detail/:id',
name: 'CrmProductDetail',

View 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 },
},
},
];
}

View File

@@ -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 { ElButton, ElMessage } from 'element-plus';
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) {
ElMessage.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 }">
<ElButton type="primary" link @click="handleDetail(row)">
{{ row.name }}
</ElButton>
</template>
<template #customerName="{ row }">
<ElButton type="primary" link @click="handleCustomerDetail(row)">
{{ row.customerName }}
</ElButton>
</template>
</Grid>
</Modal>
</template>

View 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 { ElButton, ElMessage } from 'element-plus';
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) {
ElMessage.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) {
// 提示并返回成功
ElMessage.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.BusinessContactReqVO;
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 }">
<ElButton type="primary" link @click="handleDetail(row)">
{{ row.name }}
</ElButton>
</template>
<template #customerName="{ row }">
<ElButton type="primary" link @click="handleCustomerDetail(row)">
{{ row.customerName }}
</ElButton>
</template>
</Grid>
</div>
</template>

View File

@@ -0,0 +1 @@
export { default as ContactDetailsList } from './detail-list.vue';

View File

@@ -0,0 +1,365 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { useUserStore } from '@vben/stores';
import { getSimpleContactList } from '#/api/crm/contact';
import { getCustomerSimpleList } from '#/api/crm/customer';
import { getAreaTree } from '#/api/system/area';
import { getSimpleUserList } from '#/api/system/user';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
const userStore = useUserStore();
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'name',
label: '联系人姓名',
component: 'Input',
rules: 'required',
componentProps: {
placeholder: '请输入联系人姓名',
},
},
{
fieldName: 'ownerUserId',
label: '负责人',
component: 'ApiSelect',
rules: 'required',
dependencies: {
triggerFields: ['id'],
disabled: (values) => values.id,
},
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
placeholder: '请选择负责人',
},
defaultValue: userStore.userInfo?.id,
},
{
fieldName: 'customerId',
label: '客户名称',
component: 'ApiSelect',
rules: 'required',
componentProps: {
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
},
{
fieldName: 'mobile',
label: '手机',
component: 'Input',
componentProps: {
placeholder: '请输入手机号',
},
},
{
fieldName: 'telephone',
label: '电话',
component: 'Input',
componentProps: {
placeholder: '请输入电话',
},
},
{
fieldName: 'email',
label: '邮箱',
component: 'Input',
componentProps: {
placeholder: '请输入邮箱',
},
},
{
fieldName: 'wechat',
label: '微信',
component: 'Input',
componentProps: {
placeholder: '请输入微信',
},
},
{
fieldName: 'qq',
label: 'QQ',
component: 'Input',
componentProps: {
placeholder: '请输入QQ',
},
},
{
fieldName: 'post',
label: '职位',
component: 'Input',
componentProps: {
placeholder: '请输入职位',
},
},
{
fieldName: 'master',
label: '关键决策人',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
placeholder: '请选择是否关键决策人',
},
defaultValue: false,
},
{
fieldName: 'sex',
label: '性别',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
placeholder: '请选择性别',
},
},
{
fieldName: 'parentId',
label: '直属上级',
component: 'ApiSelect',
componentProps: {
api: getSimpleContactList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择直属上级',
},
},
{
fieldName: 'areaId',
label: '地址',
component: 'ApiTreeSelect',
componentProps: {
api: getAreaTree,
fieldNames: { label: 'name', value: 'id', children: 'children' },
placeholder: '请选择地址',
},
},
{
fieldName: 'detailAddress',
label: '详细地址',
component: 'Input',
componentProps: {
placeholder: '请输入详细地址',
},
},
{
fieldName: 'contactNextTime',
label: '下次联系时间',
component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
placeholder: '请选择下次联系时间',
},
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
componentProps: {
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
},
{
fieldName: 'name',
label: '姓名',
component: 'Input',
componentProps: {
placeholder: '请输入联系人姓名',
allowClear: true,
},
},
{
fieldName: 'mobile',
label: '手机号',
component: 'Input',
componentProps: {
placeholder: '请输入手机号',
allowClear: true,
},
},
{
fieldName: 'telephone',
label: '电话',
component: 'Input',
componentProps: {
placeholder: '请输入电话',
allowClear: true,
},
},
{
fieldName: 'wechat',
label: '微信',
component: 'Input',
componentProps: {
placeholder: '请输入微信',
allowClear: true,
},
},
{
fieldName: 'email',
label: '电子邮箱',
component: 'Input',
componentProps: {
placeholder: '请输入电子邮箱',
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'name',
title: '联系人姓名',
fixed: 'left',
minWidth: 240,
slots: { default: 'name' },
},
{
field: 'customerName',
title: '客户名称',
fixed: 'left',
minWidth: 240,
slots: { default: 'customerName' },
},
{
field: 'mobile',
title: '手机',
minWidth: 120,
},
{
field: 'telephone',
title: '电话',
minWidth: 130,
},
{
field: 'email',
title: '邮箱',
minWidth: 180,
},
{
field: 'post',
title: '职位',
minWidth: 120,
},
{
field: 'areaName',
title: '地址',
minWidth: 120,
},
{
field: 'detailAddress',
title: '详细地址',
minWidth: 180,
},
{
field: 'master',
title: '关键决策人',
minWidth: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
},
},
{
field: 'parentId',
title: '直属上级',
minWidth: 120,
slots: { default: 'parentId' },
},
{
field: 'contactNextTime',
title: '下次联系时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
field: 'sex',
title: '性别',
minWidth: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_USER_SEX },
},
},
{
field: 'remark',
title: '备注',
minWidth: 200,
},
{
field: 'contactLastTime',
title: '最后跟进时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
field: 'ownerUserName',
title: '负责人',
minWidth: 120,
},
{
field: 'ownerUserDeptName',
title: '所属部门',
minWidth: 120,
},
{
field: 'updateTime',
title: '更新时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
field: 'createTime',
title: '创建时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
field: 'creatorName',
title: '创建人',
minWidth: 120,
},
{
title: '操作',
width: 180,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,106 @@
import type { DescriptionItemSchema } from '#/components/description';
import { h } from 'vue';
import { DICT_TYPE } from '@vben/constants';
import { formatDateTime } from '@vben/utils';
import { DictTag } from '#/components/dict-tag';
/** 详情页的基础字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
return [
{
field: 'customerName',
label: '客户名称',
},
{
field: 'post',
label: '职务',
},
{
field: 'mobile',
label: '手机',
},
{
field: 'createTime',
label: '创建时间',
render: (val) => formatDateTime(val) as string,
},
];
}
/** 详情页的基础字段 */
export function useDetailBaseSchema(): DescriptionItemSchema[] {
return [
{
field: 'name',
label: '姓名',
},
{
field: 'customerName',
label: '客户名称',
},
{
field: 'mobile',
label: '手机',
},
{
field: 'telephone',
label: '电话',
},
{
field: 'email',
label: '邮箱',
},
{
field: 'qq',
label: 'QQ',
},
{
field: 'wechat',
label: '微信',
},
{
field: 'areaName',
label: '地址',
render: (val, data) => {
const areaName = val ?? '';
const detailAddress = data?.detailAddress ?? '';
return [areaName, detailAddress].filter((item) => !!item).join(' ');
},
},
{
field: 'post',
label: '职务',
},
{
field: 'parentName',
label: '直属上级',
},
{
field: 'master',
label: '关键决策人',
render: (val) =>
h(DictTag, {
type: DICT_TYPE.INFRA_BOOLEAN_STRING,
value: val,
}),
},
{
field: 'sex',
label: '性别',
render: (val) =>
h(DictTag, { type: DICT_TYPE.SYSTEM_USER_SEX, value: val }),
},
{
field: 'contactNextTime',
label: '下次联系时间',
render: (val) => formatDateTime(val) as string,
},
{
field: 'remark',
label: '备注',
},
];
}

View File

@@ -0,0 +1,159 @@
<script setup lang="ts">
import type { CrmContactApi } from '#/api/crm/contact';
import type { SystemOperateLogApi } from '#/api/system/operate-log';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { ElCard, ElTabPane, ElTabs } from 'element-plus';
import { getContact } from '#/api/crm/contact';
import { getOperateLogPage } from '#/api/crm/operateLog';
import { BizTypeEnum } from '#/api/crm/permission';
import { useDescription } from '#/components/description';
import { OperateLog } from '#/components/operate-log';
import { ACTION_ICON, TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { BusinessDetailsList } from '#/views/crm/business/components';
import { FollowUp } from '#/views/crm/followup';
import { PermissionList, TransferForm } from '#/views/crm/permission';
import Form from '../modules/form.vue';
import { useDetailSchema } from './data';
import Info from './modules/info.vue';
const route = useRoute();
const router = useRouter();
const tabs = useTabs();
const loading = ref(false); // 加载中
const contactId = ref(0); // 联系人编号
const contact = ref<CrmContactApi.Contact>({} as CrmContactApi.Contact); // 联系人详情
const activeTabName = ref('1'); // 选中 Tab 名
const logList = ref<SystemOperateLogApi.OperateLog[]>([]); // 操作日志
const permissionListRef = ref<InstanceType<typeof PermissionList>>(); // 团队成员列表 Ref
const [Descriptions] = useDescription({
border: false,
column: 4,
class: 'mx-4',
schema: useDetailSchema(),
});
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [TransferModal, transferModalApi] = useVbenModal({
connectedComponent: TransferForm,
destroyOnClose: true,
});
/** 加载联系人详情 */
async function getContactDetail() {
loading.value = true;
try {
contact.value = await getContact(contactId.value);
// 操作日志
const res = await getOperateLogPage({
bizType: BizTypeEnum.CRM_CONTACT,
bizId: contactId.value,
});
logList.value = res.list;
} finally {
loading.value = false;
}
}
/** 返回列表页 */
function handleBack() {
tabs.closeCurrentTab();
router.push({ name: 'CrmContact' });
}
/** 编辑联系人 */
function handleEdit() {
formModalApi.setData({ id: contactId.value }).open();
}
/** 转移联系人 */
function handleTransfer() {
transferModalApi.setData({ id: contactId.value }).open();
}
/** 加载数据 */
onMounted(() => {
contactId.value = Number(route.params.id);
getContactDetail();
});
</script>
<template>
<Page auto-content-height :title="contact?.name" :loading="loading">
<FormModal @success="getContactDetail" />
<TransferModal @success="getContactDetail" />
<template #extra>
<TableAction
:actions="[
{
label: '返回',
type: 'default',
icon: 'lucide:arrow-left',
onClick: handleBack,
},
{
label: $t('ui.actionTitle.edit'),
type: 'primary',
icon: ACTION_ICON.EDIT,
auth: ['crm:contact:update'],
ifShow: permissionListRef?.validateWrite,
onClick: handleEdit,
},
{
label: '转移',
type: 'primary',
ifShow: permissionListRef?.validateOwnerUser,
onClick: handleTransfer,
},
]"
/>
</template>
<ElCard class="min-h-[10%]">
<Descriptions :data="contact" />
</ElCard>
<ElCard class="mt-4 min-h-[60%]">
<ElTabs v-model:model-value="activeTabName">
<ElTabPane label="跟进记录" name="1">
<FollowUp :biz-id="contactId" :biz-type="BizTypeEnum.CRM_CONTACT" />
</ElTabPane>
<ElTabPane label="详细资料" name="2">
<Info :contact="contact" />
</ElTabPane>
<ElTabPane label="操作日志" name="3">
<OperateLog :log-list="logList" />
</ElTabPane>
<ElTabPane label="团队成员" name="4">
<PermissionList
ref="permissionListRef"
:biz-id="contactId"
:biz-type="BizTypeEnum.CRM_CONTACT"
:show-action="true"
@quit-team="handleBack"
/>
</ElTabPane>
<ElTabPane label="商机" name="5">
<BusinessDetailsList
:biz-id="contactId"
:biz-type="BizTypeEnum.CRM_CONTACT"
:contact-id="contactId"
:customer-id="contact.customerId"
/>
</ElTabPane>
</ElTabs>
</ElCard>
</Page>
</template>

View File

@@ -0,0 +1,38 @@
<script lang="ts" setup>
import type { CrmContactApi } from '#/api/crm/contact';
import { ElDivider } from 'element-plus';
import { useDescription } from '#/components/description';
import { useFollowUpDetailSchema } from '#/views/crm/followup/data';
import { useDetailBaseSchema } from '../data';
defineProps<{
contact: CrmContactApi.Contact;
}>();
const [BaseDescriptions] = useDescription({
title: '基本信息',
border: false,
column: 4,
class: 'mx-4',
schema: useDetailBaseSchema(),
});
const [SystemDescriptions] = useDescription({
title: '系统信息',
border: false,
column: 3,
class: 'mx-4',
schema: useFollowUpDetailSchema(),
});
</script>
<template>
<div class="p-4">
<BaseDescriptions :data="contact" />
<ElDivider />
<SystemDescriptions :data="contact" />
</div>
</template>

View File

@@ -0,0 +1,203 @@
<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 { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { ElButton, ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteContact,
exportContact,
getContactPage,
} from '#/api/crm/contact';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const { push } = useRouter();
const sceneType = ref('1');
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 处理场景类型的切换 */
function handleChangeSceneType(key: number | string) {
sceneType.value = key.toString();
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const formValues = await gridApi.formApi.getValues();
const data = await exportContact({
sceneType: sceneType.value,
...formValues,
});
downloadFileFromBlobPart({ fileName: '联系人.xls', source: data });
}
/** 创建联系人 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑联系人 */
function handleEdit(row: CrmContactApi.Contact) {
formModalApi.setData(row).open();
}
/** 删除联系人 */
async function handleDelete(row: CrmContactApi.Contact) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteContact(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 查看联系人详情 */
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({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getContactPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
sceneType: sceneType.value,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<CrmContactApi.Contact>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【客户】客户管理、公海客户"
url="https://doc.iocoder.cn/crm/customer/"
/>
<DocAlert
title="【通用】数据权限"
url="https://doc.iocoder.cn/crm/permission/"
/>
</template>
<FormModal @success="handleRefresh" />
<Grid>
<template #toolbar-actions>
<ElTabs class="w-full" v-model:model-value="sceneType" @tab-change="handleChangeSceneType">
<ElTabPane label="我负责的" name="1" />
<ElTabPane label="我参与的" name="2" />
<ElTabPane label="下属负责的" name="3" />
</ElTabs>
</template>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['联系人']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:contact:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['crm:contact:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #name="{ row }">
<ElButton type="primary" link @click="handleDetail(row)">
{{ row.name }}
</ElButton>
</template>
<template #customerName="{ row }">
<ElButton type="primary" link @click="handleCustomerDetail(row)">
{{ row.customerName }}
</ElButton>
</template>
<template #parentId="{ row }">
<ElButton type="primary" link @click="handleDetail(row)">
{{ row.parentName }}
</ElButton>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['crm:contact:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['crm:contact:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,80 @@
<script lang="ts" setup>
import type { CrmContactApi } from '#/api/crm/contact';
import { computed, ref } from 'vue';
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { createContact, getContact, updateContact } from '#/api/crm/contact';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<CrmContactApi.Contact>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['联系人'])
: $t('ui.actionTitle.create', ['联系人']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
},
wrapperClass: 'grid-cols-2',
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as CrmContactApi.Contact;
try {
await (formData.value?.id ? updateContact(data) : createContact(data));
// 关闭并提示
await modalApi.close();
emit('success');
ElMessage.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
// 加载数据
const data = modalApi.getData<CrmContactApi.Contact>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getContact(data.id);
// 设置到 values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" />
</Modal>
</template>