From ac4341ea6b66ae02427d39d35f41d42d78b2eb2e Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 14 二月 2025 10:08:32 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/components/TableSearch/index.jsx |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 152 insertions(+), 18 deletions(-)

diff --git a/zy-asrs-flow/src/components/TableSearch/index.jsx b/zy-asrs-flow/src/components/TableSearch/index.jsx
index f91197d..2da0dcf 100644
--- a/zy-asrs-flow/src/components/TableSearch/index.jsx
+++ b/zy-asrs-flow/src/components/TableSearch/index.jsx
@@ -1,18 +1,25 @@
 import React from 'react';
 import { Input, Button, Space, Select, DatePicker } from 'antd';
+import { FormattedMessage, useIntl } from '@umijs/max';
+import Http from '@/utils/http';
 import moment from 'moment';
 
 const NONE_OPTION = -9999;
+const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
 
 const TextFilter = (props) => {
+    const intl = useIntl();
+    const [condition, setCondition] = React.useState('');
+
     return (
         <div style={{ padding: 8 }}>
             <Input
                 style={{ width: 188, marginBottom: 8, display: 'block' }}
-                placeholder="璇疯緭鍏�"
-                value={props.selectedKeys[0]}
+                placeholder={intl.formatMessage({ id: 'commont.enter', defaultMessage: '璇疯緭鍏�' })}
+                value={condition}
                 onChange={e => {
-                    props.setSelectedKeys(e.target.value ? [e.target.value] : [])
+                    props.setSelectedKeys(e.target.value ? [e.target.value] : []);
+                    setCondition(e.target.value)
                 }}
             />
             <Space>
@@ -20,23 +27,43 @@
                     type="primary"
                     onClick={() => {
                         props.confirm();
-                        props.setSearchParam(prevState => ({
-                            ...prevState,
-                            [props.name]: props.selectedKeys[0]
-                        }));
+                        if (condition === '' || condition === null || condition === undefined) {
+                            props.setSearchParam(prevState => {
+                                const state = { ...prevState };
+                                delete state[props.name];
+                                return state;
+                            })
+                        } else {
+                            props.setSearchParam(prevState => ({
+                                ...prevState,
+                                [props.name]: condition
+                            }));
+                        }
                         props.actionRef.current?.reload();
                     }}
                     size="small"
                     style={{ width: 90 }}
                 >
-                    纭畾
+                    <FormattedMessage id='common.submit' defaultMessage='纭畾' />
                 </Button>
                 <Button
-                    onClick={() => props.clearFilters && props.clearFilters()}
+                    onClick={() => {
+                        setCondition('')
+                        props.setSelectedKeys([]);
+                        props.clearFilters()
+
+                        props.confirm();
+                        props.setSearchParam(prevState => {
+                            const state = { ...prevState };
+                            delete state[props.name];
+                            return state;
+                        })
+                        props.actionRef.current?.reload();
+                    }}
                     size="small"
                     style={{ width: 90 }}
                 >
-                    閲嶇疆
+                    <FormattedMessage id='common.reset' defaultMessage='閲嶇疆' />
                 </Button>
             </Space>
         </div>
@@ -44,6 +71,7 @@
 }
 
 const SelectFilter = (props) => {
+    const intl = useIntl();
     const [currentOption, setCurrentOption] = React.useState();
 
     return (
@@ -51,7 +79,7 @@
             <div>
                 <Select
                     style={{ width: 188, marginBottom: 8, display: 'block' }}
-                    placeholder="璇烽�夋嫨"
+                    placeholder={intl.formatMessage({ id: 'commont.select', defaultMessage: '璇烽�夋嫨' })}
                     value={currentOption === NONE_OPTION ? undefined : currentOption}
                     onChange={value => {
                         setCurrentOption(value)
@@ -87,18 +115,26 @@
                     size="small"
                     style={{ width: 90 }}
                 >
-                    纭畾
+                    <FormattedMessage id='common.submit' defaultMessage='纭畾' />
                 </Button>
                 <Button
                     onClick={() => {
                         setCurrentOption(NONE_OPTION)
                         props.setSelectedKeys([]);
                         props.clearFilters();
+
+                        props.confirm();
+                        props.setSearchParam(prevState => {
+                            const state = { ...prevState };
+                            delete state[props.name];
+                            return state;
+                        })
+                        props.actionRef.current?.reload();
                     }}
                     size="small"
                     style={{ width: 90 }}
                 >
-                    閲嶇疆
+                    <FormattedMessage id='common.reset' defaultMessage='閲嶇疆' />
                 </Button>
             </Space>
         </div>
@@ -106,6 +142,7 @@
 }
 
 const DatetimeRangeFilter = (props) => {
+    const intl = useIntl();
     const [dates, setDates] = React.useState([null, null]);
     const [startDate, setStartDate] = React.useState(null);
     const [endDate, setEndDate] = React.useState(null);
@@ -120,9 +157,9 @@
                         onChange={changeDates => {
                             setDates(changeDates);
                             if (changeDates && changeDates[0] && changeDates[1]) {
-                                const changeStartStr = changeDates[0]?.toISOString()
+                                const changeStartStr = moment(changeDates[0]).format(DATE_FORMAT);
                                 setStartDate(changeStartStr);
-                                const changeEndStr = changeDates[1]?.toISOString()
+                                const changeEndStr = moment(changeDates[1]).format(DATE_FORMAT);
                                 setEndDate(changeEndStr);
                                 props.setSelectedKeys([changeStartStr + '-' + changeEndStr]);
                             }
@@ -149,7 +186,7 @@
                             }}
                             size="small"
                         >
-                            纭畾
+                            <FormattedMessage id='common.submit' defaultMessage='纭畾' />
                         </Button>
                         <Button
                             onClick={() => {
@@ -158,10 +195,18 @@
                                 setEndDate(null);
                                 props.setSelectedKeys([]);
                                 props.clearFilters();
+
+                                props.confirm();
+                                props.setSearchParam(prevState => {
+                                    const nextState = { ...prevState };
+                                    delete nextState[props.name + 'Range'];
+                                    return nextState;
+                                });
+                                props.actionRef.current?.reload();
                             }}
                             size="small"
                         >
-                            閲嶇疆
+                            <FormattedMessage id='common.reset' defaultMessage='閲嶇疆' />
                         </Button>
                     </Space>
                 </Space>
@@ -170,5 +215,94 @@
     );
 }
 
+const LinkFilter = (props) => {
+    const intl = useIntl();
+    const [currentOption, setCurrentOption] = React.useState();
+    const [options, setOptions] = React.useState([]);
 
-export { TextFilter, SelectFilter, DatetimeRangeFilter };
\ No newline at end of file
+    const fetchData = async (value) => {
+        return await Http.doPostForm(`api/${props.major}/query`, { condition: value });
+    }
+
+    async function initOptions(value) {
+        const { data } = await fetchData(value);
+        setOptions(data);
+    }
+
+    React.useEffect(() => {
+        initOptions()
+    }, []);
+
+    const handleSearch = (value) => {
+        initOptions(value)
+    }
+
+    return (
+        <div style={{ padding: 8 }}>
+            <div>
+                <Select
+                    style={{ width: 188, marginBottom: 8, display: 'block' }}
+                    placeholder={intl.formatMessage({ id: 'commont.select', defaultMessage: '璇烽�夋嫨' })}
+                    value={currentOption === NONE_OPTION ? undefined : currentOption}
+                    onChange={value => {
+                        setCurrentOption(value)
+                        props.setSelectedKeys(value !== undefined && value !== null ? [value] : []);
+                    }}
+                    onSearch={handleSearch}
+                    options={options.map(item => ({ value: item.value, label: item.label }))}
+                    filterOption={false}
+                    showSearch={true}
+                >
+                </Select>
+            </div>
+            <Space>
+                <Button
+                    type="primary"
+                    onClick={() => {
+                        props.confirm();
+                        if (currentOption === NONE_OPTION) {
+                            props.setSearchParam(prevState => {
+                                const state = { ...prevState };
+                                delete state[props.name];
+                                return state;
+                            })
+                        } else {
+                            props.setSearchParam(prevState => ({
+                                ...prevState,
+                                [props.name]: currentOption
+                            }));
+                        }
+                        props.actionRef.current?.reload();
+                    }}
+                    size="small"
+                    style={{ width: 90 }}
+                >
+                    <FormattedMessage id='common.submit' defaultMessage='纭畾' />
+                </Button>
+                <Button
+                    onClick={() => {
+                        setCurrentOption(NONE_OPTION)
+                        props.setSelectedKeys([]);
+                        props.clearFilters();
+                        initOptions()
+
+                        props.confirm();
+                        props.setSearchParam(prevState => {
+                            const state = { ...prevState };
+                            delete state[props.name];
+                            return state;
+                        })
+                        props.actionRef.current?.reload();
+                    }}
+                    size="small"
+                    style={{ width: 90 }}
+                >
+                    <FormattedMessage id='common.reset' defaultMessage='閲嶇疆' />
+                </Button>
+            </Space>
+        </div>
+    );
+}
+
+
+export { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter };
\ No newline at end of file

--
Gitblit v1.9.1