Commit 01cb6f2b authored by Bill's avatar Bill

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

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