diff --git a/apps/web-antd/src/api/crm/contact/index.ts b/apps/web-antd/src/api/crm/contact/index.ts index 108b31060..90dc71781 100644 --- a/apps/web-antd/src/api/crm/contact/index.ts +++ b/apps/web-antd/src/api/crm/contact/index.ts @@ -106,6 +106,14 @@ export function getSimpleContactList() { ); } +/** 获得联系人列表,基于指定客户 */ +export function getContactListByCustomer(customerId: number) { + return requestClient.get( + '/crm/contact/list-by-customer', + { params: { customerId } }, + ); +} + /** 批量新增联系人商机关联 */ export function createContactBusinessList( data: CrmContactApi.ContactBusinessReqVO, diff --git a/apps/web-antd/src/views/crm/contact/data.ts b/apps/web-antd/src/views/crm/contact/data.ts index b798a1227..429957d39 100644 --- a/apps/web-antd/src/views/crm/contact/data.ts +++ b/apps/web-antd/src/views/crm/contact/data.ts @@ -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', diff --git a/apps/web-antd/src/views/crm/contact/modules/form.vue b/apps/web-antd/src/views/crm/contact/modules/form.vue index a70060cf0..db301394f 100644 --- a/apps/web-antd/src/views/crm/contact/modules/form.vue +++ b/apps/web-antd/src/views/crm/contact/modules/form.vue @@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({ } // 加载数据 const data = modalApi.getData(); - 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 { diff --git a/apps/web-antdv-next/src/api/crm/contact/index.ts b/apps/web-antdv-next/src/api/crm/contact/index.ts index 108b31060..90dc71781 100644 --- a/apps/web-antdv-next/src/api/crm/contact/index.ts +++ b/apps/web-antdv-next/src/api/crm/contact/index.ts @@ -106,6 +106,14 @@ export function getSimpleContactList() { ); } +/** 获得联系人列表,基于指定客户 */ +export function getContactListByCustomer(customerId: number) { + return requestClient.get( + '/crm/contact/list-by-customer', + { params: { customerId } }, + ); +} + /** 批量新增联系人商机关联 */ export function createContactBusinessList( data: CrmContactApi.ContactBusinessReqVO, diff --git a/apps/web-antdv-next/src/views/crm/contact/data.ts b/apps/web-antdv-next/src/views/crm/contact/data.ts index f6e49e07e..9f4b3f310 100644 --- a/apps/web-antdv-next/src/views/crm/contact/data.ts +++ b/apps/web-antdv-next/src/views/crm/contact/data.ts @@ -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', diff --git a/apps/web-antdv-next/src/views/crm/contact/modules/form.vue b/apps/web-antdv-next/src/views/crm/contact/modules/form.vue index 376a84093..85fbde58b 100644 --- a/apps/web-antdv-next/src/views/crm/contact/modules/form.vue +++ b/apps/web-antdv-next/src/views/crm/contact/modules/form.vue @@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({ } // 加载数据 const data = modalApi.getData(); - 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 { diff --git a/apps/web-ele/src/api/crm/contact/index.ts b/apps/web-ele/src/api/crm/contact/index.ts index 108b31060..90dc71781 100644 --- a/apps/web-ele/src/api/crm/contact/index.ts +++ b/apps/web-ele/src/api/crm/contact/index.ts @@ -106,6 +106,14 @@ export function getSimpleContactList() { ); } +/** 获得联系人列表,基于指定客户 */ +export function getContactListByCustomer(customerId: number) { + return requestClient.get( + '/crm/contact/list-by-customer', + { params: { customerId } }, + ); +} + /** 批量新增联系人商机关联 */ export function createContactBusinessList( data: CrmContactApi.ContactBusinessReqVO, diff --git a/apps/web-ele/src/views/crm/contact/data.ts b/apps/web-ele/src/views/crm/contact/data.ts index a3631d915..b19e840e1 100644 --- a/apps/web-ele/src/views/crm/contact/data.ts +++ b/apps/web-ele/src/views/crm/contact/data.ts @@ -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', diff --git a/apps/web-ele/src/views/crm/contact/modules/form.vue b/apps/web-ele/src/views/crm/contact/modules/form.vue index 5b0b3c7d9..11d817514 100644 --- a/apps/web-ele/src/views/crm/contact/modules/form.vue +++ b/apps/web-ele/src/views/crm/contact/modules/form.vue @@ -58,12 +58,12 @@ const [Modal, modalApi] = useVbenModal({ } // 加载数据 const data = modalApi.getData(); - 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 {