Commit 156967c1 authored by XieZhiXiong's avatar XieZhiXiong

添加远程检索

parent a7eb2caa
...@@ -10,6 +10,7 @@ import { SaveOutlined, PlusOutlined } from '@ant-design/icons'; ...@@ -10,6 +10,7 @@ import { SaveOutlined, PlusOutlined } from '@ant-design/icons';
import { createFormActions, FormEffectHooks } from '@formily/antd'; import { createFormActions, FormEffectHooks } from '@formily/antd';
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable'; import { useRowSelectionTable } from '@/hooks/useRowSelectionTable';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
import { useLinkageUtils } from '@/utils/formEffectUtils';
import ReutrnEle from '@/components/ReturnEle'; import ReutrnEle from '@/components/ReturnEle';
import NiceForm from '@/components/NiceForm'; import NiceForm from '@/components/NiceForm';
import ModalTable from '@/components/ModalTable'; import ModalTable from '@/components/ModalTable';
...@@ -43,6 +44,7 @@ import { createEffects } from './effects'; ...@@ -43,6 +44,7 @@ import { createEffects } from './effects';
const addSchemaAction = createFormActions(); const addSchemaAction = createFormActions();
const { const {
onFormInputChange$, onFormInputChange$,
onFormInit$,
} = FormEffectHooks; } = FormEffectHooks;
interface BillsFormProps { interface BillsFormProps {
...@@ -98,6 +100,28 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -98,6 +100,28 @@ const BillsForm: React.FC<BillsFormProps> = ({
}, },
] ]
// 获取品牌
const fetchBrand = async (name = '') => {
const res = await PublicApi.getProductSelectGetSelectBrand({
name,
});
if (res.code === 1000) {
return res.data;
}
return [];
}
// 获取会员品类
const fetchCustomerCategory = async (name = '') => {
const res = await PublicApi.getProductSelectGetSelectCustomerCategory({
name,
});
if (res.code === 1000) {
return res.data;
}
return [];
}
// 获取单据详情 // 获取单据详情
const getBillInfo = () => { const getBillInfo = () => {
if (!id) { if (!id) {
...@@ -878,12 +902,43 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -878,12 +902,43 @@ const BillsForm: React.FC<BillsFormProps> = ({
SearchSelect, SearchSelect,
}, },
effects: ($, actions) => { effects: ($, actions) => {
const linkage = useLinkageUtils();
useStateFilterSearchLinkageEffect( useStateFilterSearchLinkageEffect(
$, $,
actions, actions,
'name', 'name',
FORM_FILTER_PATH, FORM_FILTER_PATH,
); );
useAsyncSelect('brandId', fetchBrand, ['name', 'id']);
useAsyncSelect('customerCategoryId', fetchCustomerCategory, ['name', 'id']);
onFormInit$().subscribe(() => {
// 初始化远程检索逻辑
linkage.componentProps('customerCategoryId', {
onSearch: async value => {
linkage.loading('customerCategoryId');
const dataSource = await fetchCustomerCategory(value);
linkage.enum('customerCategoryId', dataSource.map(item => ({
label: item.name,
value: item.id,
})));
linkage.loaded('customerCategoryId');
},
});
// 初始化远程检索逻辑
linkage.componentProps('brandId', {
onSearch: async value => {
linkage.loading('brandId');
const dataSource = await fetchCustomerCategory(value);
linkage.enum('brandId', dataSource.map(item => ({
label: item.name,
value: item.id,
})));
linkage.loaded('brandId');
},
});
});
}, },
inline: false, inline: false,
} }
......
...@@ -779,24 +779,24 @@ export const goodsSearchSchema: ISchema = { ...@@ -779,24 +779,24 @@ export const goodsSearchSchema: ISchema = {
}, },
customerCategoryId: { customerCategoryId: {
type: 'string', type: 'string',
'x-component': 'SearchSelect', enum: [],
'x-component-props': { 'x-component-props': {
placeholder: '品类', placeholder: '品类',
fetchSearch: PublicApi.getProductSelectGetSelectCustomerCategory, showSearch: true,
style: { defaultActiveFirstOption: false,
width: '100%', showArrow: true,
} filterOption: false,
}, },
}, },
brandId: { brandId: {
type: 'string', type: 'string',
'x-component': 'SearchSelect', enum: [],
'x-component-props': { 'x-component-props': {
placeholder: '品牌', placeholder: '品牌',
fetchSearch: PublicApi.getProductSelectGetSelectBrand, showSearch: true,
style: { defaultActiveFirstOption: false,
width: '100%', showArrow: true,
} filterOption: false,
}, },
}, },
submit: { submit: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment