fix: 搜索表单的初始化

feature/2.0-sales-trade
Lei OT 2 years ago
parent 64c388eff9
commit 8656548a19

@ -63,7 +63,8 @@ class SearchInput extends React.Component {
componentDidMount() {
if (this.props.autoGet === true) {
const { map, resultkey, param } = this.props;
const { map, resultkey, dependenciesFun } = this.props;
const param = typeof dependenciesFun === 'function' ? dependenciesFun() : {};
const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {});
curl({ value: '', url: this.props.url || '', map: mapKey, resultkey, param }, (data) =>
this.setState({ data, autoData: data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : ''))
@ -87,7 +88,8 @@ class SearchInput extends React.Component {
this.setState({ data: f || [] });
return false;
}
const { map, resultkey, param } = this.props;
const { map, resultkey, dependenciesFun } = this.props;
const param = typeof dependenciesFun === 'function' ? dependenciesFun() : {};
const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {});
if (value) {
curl({ value, url: this.props.url || '', map: mapKey, resultkey, param }, (data) =>
@ -99,13 +101,12 @@ class SearchInput extends React.Component {
};
handleChange = (value, option) => {
// console.log('invoke denpendencies change', value);
this.setState({ value }, () => this.props.onChange(value, option));
};
render() {
const options = this.state.data.map(d => <Option key={d.key} extradata={d.options}>{d.label}</Option>);
const { onSearchAfter, defaultOptions, autoGet, ...props } = this.props;
const { onSearchAfter, defaultOptions, autoGet, dependenciesFun, ...props } = this.props;
return (
<Select
{...props}

@ -44,6 +44,7 @@ export default observer((props) => {
};
const { onSubmit, confirmText } = props;
const formValuesMapper = (values) => {
const destinationObject = {
'DateType': {
@ -149,7 +150,7 @@ export default observer((props) => {
},
};
let dest = {};
const { applyDate, applyDate2, year, yearDiff, ...omittedValue } = values;
const { applyDate, applyDate2, year, yearDiff, dates, months, ...omittedValue } = values;
dest = { ...omittedValue, ...objectMapper(values, destinationObject) };
for (const key in dest) {
if (Object.prototype.hasOwnProperty.call(dest, key)) {
@ -161,6 +162,12 @@ export default observer((props) => {
return dest;
};
useEffect(() => {
const dest = formValuesMapper(searchFormStore.formValues);
searchFormStore.setFormValuesToSub(dest);
return () => {};
}, []);
const onFinish = (values) => {
console.log('Received values of form, origin form value: ', values);
const dest = formValuesMapper(values);
@ -321,7 +328,7 @@ function getFields(props) {
map={{ 'op_id': 'key', 'cn_name': 'label' }}
resultkey={'result'}
placeholder="输入搜索顾问: 中/英名字"
param={{ dept_id: (form.getFieldValue('DepartmentList')?.value || '').replace('ALL', ''), ...(fieldProps?.operator?.param || {}) }}
dependenciesFun={() => ({ dept_id: (form.getFieldValue('DepartmentList')?.value || '').replace('ALL', ''), ...(fieldProps?.operator?.param || {}) })}
/>
</Form.Item>
),

@ -46,7 +46,7 @@ class DatePickerStore {
'WebCode': { 'key': 'ALL', 'label': '所有来源' },
'IncludeTickets': { 'key': '1', 'label': '含门票' },
'DateType': { 'key': 'applyDate', 'label': '提交日期' },
'years': this.start_date,
'year': this.start_date,
// 'months': [moment(), moment()],
'dates': [this.start_date, this.end_date],
};

Loading…
Cancel
Save