Commit 01cb6f2b authored by Bill's avatar Bill

fix: 修改新建加工通知单时,加工商品搜索bug

parent 35a5d377
import React, { useState, useEffect, useCallback } from 'react';
import { Modal, Spin } from 'antd';
import { PublicApi } from '@/services/api';
import EyePreview from '@/components/EyePreview';
import { BasicForm, TablePagination, SearchForm } from '../ModalForTable'
import { SearchForm } from '../ModalForTable'
import { createAsyncFormActions, FormEffectHooks } from '@formily/antd';
import { schema } from './schema';
import { getAuth } from '@/utils/auth';
import { useDebounceFn } from '@umijs/hooks';
import { Cascader } from 'antd';
const { onFieldInit$ } = FormEffectHooks
......@@ -22,13 +22,14 @@ const MALL_NAME = {
const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps}) => {
const authInfo = getAuth();
const fetchData = useCallback(async (params: any) => {
console.log(params);
const customerCategoryId = params.customerCategoryId && Array.isArray(params.customerCategoryId) && params.customerCategoryId.pop();
// /product/commodity/common/getCommodityListByBuyer
const postData = {
shopType: ENTERPRISE_MALL[authInfo.memberType],
environment: 1,
memberId:authInfo.memberId,
...params,
customerCategoryId: customerCategoryId,
}
let res = await PublicApi.getProductCommodityCommonGetCommodityListByBuyer(postData);
return res;
......@@ -55,11 +56,11 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
}
const effects = () => {
onFieldInit$('branchId').subscribe((fieldState) => {
onFieldInit$('brandId').subscribe((fieldState) => {
changeBrand({name: ''})
});
onFieldInit$('categoryId').subscribe((fieldState) => {
changeCategory({name: ''});
onFieldInit$('customerCategoryId').subscribe((fieldState) => {
changeCategory();
})
}
......@@ -69,30 +70,19 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
if(res.code === 1000) {
options = res.data.map((item) => {return { label: item.name, value: item.id }})
}
actions.setFieldState("branchId", (state) => {
actions.setFieldState("brandId", (state) => {
state.props["x-component-props"]["options"] = options;
})
})
}
const changeCategory = (params) => {
PublicApi.getProductSelectGetSelectCustomerCategory(params).then(res => {
let options = []
if(res.code === 1000) {
options = res.data.map((item) => {return { label: item.name, value: item.id }})
}
actions.setFieldState("categoryId", (state) => {
state.props["x-component-props"]["options"] = options;
const changeCategory = () => {
PublicApi.getProductCustomerGetCustomerCategoryTree().then(res => {
actions.setFieldState("customerCategoryId", (state) => {
state.props["x-component-props"]["options"] = res.data;
})
})
}
const filterCategroyOption = (input, option) => {
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
const onCategory = useDebounceFn((value) => {
changeCategory({name: value});
}, 500)
const filterBrandOption = (input, option) => {
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
......@@ -116,14 +106,13 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
<Spin spinning={loading}>
<SearchForm
request={fetchData}
components={{Cascader}}
schema={schema}
actions={actions}
effects={effects}
expressionScope={{
rowSelection: rowSelection,
columns: columns,
filterCategroyOption : filterCategroyOption,
onCategory: onCategory.run,
filterBrandOption: filterBrandOption,
onBrandSearch: onBrandSearch.run
}}
......
......@@ -62,7 +62,7 @@ export const schema = {
properties: {
customerCategoryId: {
type: 'string',
'x-component': 'Select',
'x-component': 'Cascader',
'x-component-props': {
placeholder: '请选择商品品类',
allowClear:true,
......@@ -70,16 +70,10 @@ export const schema = {
width: '200px',
margin: '0 20px 0 0'
},
showSearch: true,
optionFilterProp: "children",
filterOption: "{{filterCategroyOption}}",
onSearch: "{{onCategory}}"
// filterOption: {(input, option) =>
// option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
// }
fieldNames: { label: 'title', value: 'id', children: 'children' }
}
},
branchId: {
brandId: {
type: 'string',
'x-component': 'Select',
'x-component-props': {
......
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