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

110 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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';
const ToolBar = ({ setSearchVal, setDmName, setTrData, exportFile,role }) => {
const exportBtn = role?.rule?.find(item => item.menuName == "导出")||true;
const searchBtn = role?.rule?.find(item => item.menuName == "查询")||true;
const [form] = Form.useForm();
const [dmList, setDmList] = useState([])
const [dmTree, setDmTree] = useState([])
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})));
} catch (error) {
console.log(error);
}
}
const getDmTree = async() => {
try {
const res = await httppost2(apiurl.gcaqjc.sjtjcx.czcx.tree)
setDmTree(res.data)
} catch (error) {
console.log(error);
}
}
const onFinish = (values) => {
let dateSo;
if (values.tm) {
dateSo = moment(values.tm).format('YYYY')
}
delete values.tm
setSearchVal({ ...values, year: dateSo });
const dmName = dmList.find(item => item.value == values.profileCode).label
setDmName(dmName)
let filterData = dmTree.filter(s => s.profileName == dmName)
setTrData(filterData[0])
}
useEffect(() => {
getDmList()
getDmTree()
}, [])
useEffect(() => {
let time = moment()
if (dmList.length > 0 && dmTree.length>0) {
form.setFieldValue("tm", time)
form.setFieldValue("profileCode",dmList[0].value)
setSearchVal({ year: moment().format("YYYY"), profileCode: dmList[0].value })
const dmName = dmList[0].label
setDmName(dmName)
let filterData = dmTree.filter(s => s.profileName == dmName)
setTrData(filterData[0])
}
}, [dmList,dmTree])
return (
<>
<div style={{display:'flex',justifyContent:'space-between'}}>
<Form form={form} className='toolbarBox' layout="inline" onFinish={onFinish}>
<Form.Item label="上报时间" name="tm">
<DatePicker
allowClear={false}
picker="year"
style={{ width: "200px" }}
format={'YYYY'}
/>
</Form.Item>
<Form.Item label="监测断面" name="profileCode">
<NormalSelect
allowClear={false}
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;