fix(crm): 按客户筛选联系人直属上级

This commit is contained in:
YunaiV
2026-07-19 19:33:50 +08:00
parent cb951f536f
commit f97bb9f33a
9 changed files with 102 additions and 27 deletions

View File

@@ -106,6 +106,14 @@ export function getSimpleContactList() {
);
}
/** 获得联系人列表,基于指定客户 */
export function getContactListByCustomer(customerId: number) {
return requestClient.get<CrmContactApi.Contact[]>(
'/crm/contact/list-by-customer',
{ params: { customerId } },
);
}
/** 批量新增联系人商机关联 */
export function createContactBusinessList(
data: CrmContactApi.ContactBusinessReqVO,

View File

@@ -7,7 +7,7 @@ import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { useUserStore } from '@vben/stores';
import { getSimpleContactList } from '#/api/crm/contact';
import { getContactListByCustomer } from '#/api/crm/contact';
import { getCustomerSimpleList } from '#/api/crm/customer';
import { getSimpleUserList } from '#/api/system/user';
import { AreaCascader } from '#/components/area';
@@ -55,12 +55,13 @@ export function useFormSchema(): VbenFormSchema[] {
label: '客户名称',
component: 'ApiSelect',
rules: 'required',
componentProps: {
componentProps: (_values, form) => ({
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
onChange: () => form.setFieldValue('parentId', undefined),
}),
},
{
fieldName: 'mobile',
@@ -134,13 +135,29 @@ export function useFormSchema(): VbenFormSchema[] {
{
fieldName: 'parentId',
label: '直属上级',
component: 'ApiSelect',
component: 'Select',
componentProps: {
api: getSimpleContactList,
labelField: 'name',
valueField: 'id',
options: [],
placeholder: '请选择直属上级',
},
dependencies: {
triggerFields: ['customerId', 'id'],
disabled: (values) => !values.customerId,
async componentProps(values) {
if (!values.customerId) {
return { options: [], placeholder: '请先选择客户' };
}
const contacts = await getContactListByCustomer(values.customerId);
return {
options: contacts.map((item) => ({
disabled: item.id === values.id,
label: item.name,
value: item.id,
})),
placeholder: '请选择直属上级',
};
},
},
},
{
fieldName: 'areaId',

View File

@@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({
}
// 加载数据
const data = modalApi.getData<CrmContactApi.Contact>();
if (!data || !data.id) {
if (!data) {
return;
}
modalApi.lock();
try {
formData.value = await getContact(data.id);
formData.value = data.id ? await getContact(data.id) : data;
// 设置到 values
await formApi.setValues(formData.value);
} finally {

View File

@@ -106,6 +106,14 @@ export function getSimpleContactList() {
);
}
/** 获得联系人列表,基于指定客户 */
export function getContactListByCustomer(customerId: number) {
return requestClient.get<CrmContactApi.Contact[]>(
'/crm/contact/list-by-customer',
{ params: { customerId } },
);
}
/** 批量新增联系人商机关联 */
export function createContactBusinessList(
data: CrmContactApi.ContactBusinessReqVO,

View File

@@ -7,7 +7,7 @@ import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { useUserStore } from '@vben/stores';
import { getSimpleContactList } from '#/api/crm/contact';
import { getContactListByCustomer } from '#/api/crm/contact';
import { getCustomerSimpleList } from '#/api/crm/customer';
import { getSimpleUserList } from '#/api/system/user';
import { AreaCascader } from '#/components/area';
@@ -55,12 +55,13 @@ export function useFormSchema(): VbenFormSchema[] {
label: '客户名称',
component: 'ApiSelect',
rules: 'required',
componentProps: {
componentProps: (_values, form) => ({
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
onChange: () => form.setFieldValue('parentId', undefined),
}),
},
{
fieldName: 'mobile',
@@ -134,13 +135,29 @@ export function useFormSchema(): VbenFormSchema[] {
{
fieldName: 'parentId',
label: '直属上级',
component: 'ApiSelect',
component: 'Select',
componentProps: {
api: getSimpleContactList,
labelField: 'name',
valueField: 'id',
options: [],
placeholder: '请选择直属上级',
},
dependencies: {
triggerFields: ['customerId', 'id'],
disabled: (values) => !values.customerId,
async componentProps(values) {
if (!values.customerId) {
return { options: [], placeholder: '请先选择客户' };
}
const contacts = await getContactListByCustomer(values.customerId);
return {
options: contacts.map((item) => ({
disabled: item.id === values.id,
label: item.name,
value: item.id,
})),
placeholder: '请选择直属上级',
};
},
},
},
{
fieldName: 'areaId',

View File

@@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({
}
// 加载数据
const data = modalApi.getData<CrmContactApi.Contact>();
if (!data || !data.id) {
if (!data) {
return;
}
modalApi.lock();
try {
formData.value = await getContact(data.id);
formData.value = data.id ? await getContact(data.id) : data;
// 设置到 values
await formApi.setValues(formData.value);
} finally {

View File

@@ -106,6 +106,14 @@ export function getSimpleContactList() {
);
}
/** 获得联系人列表,基于指定客户 */
export function getContactListByCustomer(customerId: number) {
return requestClient.get<CrmContactApi.Contact[]>(
'/crm/contact/list-by-customer',
{ params: { customerId } },
);
}
/** 批量新增联系人商机关联 */
export function createContactBusinessList(
data: CrmContactApi.ContactBusinessReqVO,

View File

@@ -7,7 +7,7 @@ import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { useUserStore } from '@vben/stores';
import { getSimpleContactList } from '#/api/crm/contact';
import { getContactListByCustomer } from '#/api/crm/contact';
import { getCustomerSimpleList } from '#/api/crm/customer';
import { getSimpleUserList } from '#/api/system/user';
import { AreaCascader } from '#/components/area';
@@ -55,12 +55,13 @@ export function useFormSchema(): VbenFormSchema[] {
label: '客户名称',
component: 'ApiSelect',
rules: 'required',
componentProps: {
componentProps: (_values, form) => ({
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
onChange: () => form.setFieldValue('parentId', undefined),
}),
},
{
fieldName: 'mobile',
@@ -132,13 +133,29 @@ export function useFormSchema(): VbenFormSchema[] {
{
fieldName: 'parentId',
label: '直属上级',
component: 'ApiSelect',
component: 'Select',
componentProps: {
api: getSimpleContactList,
labelField: 'name',
valueField: 'id',
options: [],
placeholder: '请选择直属上级',
},
dependencies: {
triggerFields: ['customerId', 'id'],
disabled: (values) => !values.customerId,
async componentProps(values) {
if (!values.customerId) {
return { options: [], placeholder: '请先选择客户' };
}
const contacts = await getContactListByCustomer(values.customerId);
return {
options: contacts.map((item) => ({
disabled: item.id === values.id,
label: item.name,
value: item.id,
})),
placeholder: '请选择直属上级',
};
},
},
},
{
fieldName: 'areaId',

View File

@@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({
}
// 加载数据
const data = modalApi.getData<CrmContactApi.Contact>();
if (!data || !data.id) {
if (!data) {
return;
}
modalApi.lock();
try {
formData.value = await getContact(data.id);
formData.value = data.id ? await getContact(data.id) : data;
// 设置到 values
await formApi.setValues(formData.value);
} finally {