tsg-web/src/views/gcaqjc/sjtjcx/ndsytjb/toolbar.js

110 lines
3.7 KiB
JavaScript
Raw Normal View History

2024-09-20 15:02:50 +08:00
import React, { useEffect,useState } from 'react';
import { Form, Input, Button, DatePicker } from 'antd';
import { getDictService } from '../../../../service/SelectValue'
import AdcdFuzzyTreeSelect from '../../../../components/Form/AdcdFuzzyTreeSelect';
import NormalSelect from '../../../../components/Form/NormalSelect';
import { config } from '../../../../config';
import moment from 'moment';
import { httppost2 } from '../../../../utils/request';
import apiurl from '../../../../service/apiurl';
2025-09-19 17:14:29 +08:00
const ToolBar = ({ setSearchVal, setDmName, setTrData, exportFile,role }) => {
2024-09-23 13:49:58 +08:00
const exportBtn = role?.rule?.find(item => item.menuName == "导出")||true;
const searchBtn = role?.rule?.find(item => item.menuName == "查询")||true;
2024-09-20 15:02:50 +08:00
const [form] = Form.useForm();
const [dmList, setDmList] = useState([])
2025-09-19 17:14:29 +08:00
const [dmTree, setDmTree] = useState([])
2024-09-20 15:02:50 +08:00
const getDmList = async () => {
try {
const res = await httppost2(apiurl.gcaqjc.sjtjcx.sycx.list)
const sortedData = res.data.sort((a, b) => {
// 判断a、b是否为ZB0开头
const isAZB0 = a.profileCode.startsWith('ZB0');
const isBZB0 = b.profileCode.startsWith('ZB0');
// 规则ZB0开头的排前面同类型都ZB0/都非ZB0保持原顺序
if (isAZB0 && !isBZB0) return -1; // a是ZB0b不是 → a在前
if (!isAZB0 && isBZB0) return 1; // a不是ZB0b是 → b在前
return 0; // 同类型,保持原始相对顺序
});
setDmList(sortedData.map(s=>({label:s.profileName,value:s.profileCode})));
2024-09-20 15:02:50 +08:00
} catch (error) {
console.log(error);
}
}
2025-09-19 17:14:29 +08:00
const getDmTree = async() => {
try {
const res = await httppost2(apiurl.gcaqjc.sjtjcx.czcx.tree)
setDmTree(res.data)
} catch (error) {
console.log(error);
}
}
2024-09-20 15:02:50 +08:00
const onFinish = (values) => {
2024-09-27 17:49:18 +08:00
let dateSo;
2024-09-20 15:02:50 +08:00
if (values.tm) {
2024-09-27 17:49:18 +08:00
dateSo = moment(values.tm).format('YYYY')
2024-09-20 15:02:50 +08:00
}
delete values.tm
2024-09-27 17:49:18 +08:00
setSearchVal({ ...values, year: dateSo });
2025-09-19 17:14:29 +08:00
const dmName = dmList.find(item => item.value == values.profileCode).label
setDmName(dmName)
let filterData = dmTree.filter(s => s.profileName == dmName)
setTrData(filterData[0])
2024-09-20 15:02:50 +08:00
}
useEffect(() => {
getDmList()
2025-09-19 17:14:29 +08:00
getDmTree()
2024-09-20 15:02:50 +08:00
}, [])
2025-09-19 17:14:29 +08:00
2024-09-20 15:02:50 +08:00
useEffect(() => {
let time = moment()
2025-09-19 17:14:29 +08:00
if (dmList.length > 0 && dmTree.length>0) {
2024-09-20 15:02:50 +08:00
form.setFieldValue("tm", time)
form.setFieldValue("profileCode",dmList[0].value)
setSearchVal({ year: moment().format("YYYY"), profileCode: dmList[0].value })
2025-09-19 17:14:29 +08:00
const dmName = dmList[0].label
setDmName(dmName)
let filterData = dmTree.filter(s => s.profileName == dmName)
setTrData(filterData[0])
2024-09-20 15:02:50 +08:00
}
2025-09-19 17:14:29 +08:00
}, [dmList,dmTree])
2024-09-20 15:02:50 +08:00
return (
<>
<div style={{display:'flex',justifyContent:'space-between'}}>
<Form form={form} className='toolbarBox' layout="inline" onFinish={onFinish}>
<Form.Item label="上报时间" name="tm">
<DatePicker
2025-09-19 17:14:29 +08:00
allowClear={false}
2024-09-20 15:02:50 +08:00
picker="year"
style={{ width: "200px" }}
format={'YYYY'}
/>
</Form.Item>
<Form.Item label="监测断面" name="profileCode">
<NormalSelect
2025-09-19 17:14:29 +08:00
allowClear={false}
2024-09-20 15:02:50 +08:00
style={{ width: "150px" }}
options={dmList}
/>
</Form.Item>
{searchBtn ? <Form.Item>
<Button type="primary" htmlType="submit">查询</Button>
</Form.Item> : null}
<Form.Item>
<Button onClick={() => form.resetFields()}>重置</Button>
</Form.Item>
{exportBtn ? <Form.Item>
<Button onClick={()=>exportFile()}>导出</Button>
</Form.Item>: null}
</Form>
</div>
</>
);
}
export default ToolBar;