tsg-web/src/views/sz/pxjlgl/index.js

189 lines
6.8 KiB
JavaScript
Raw Normal View History

2024-09-24 16:52:53 +08:00
import React, { Fragment, useRef, useMemo,useEffect,useState } from 'react';
import { useSelector } from 'react-redux';
import BasicCrudModal from '../../../components/crud/BasicCrudModal';
import { Table, Card,Modal,Image,Input,Button,Row,Col,message } from 'antd';
import ToolBar from './toolbar';
import ChartToolBar from './chartToolbar';
import ModalForm from './form';
import apiurl from '../../../service/apiurl';
import options from "./options";
import ReactEcharts from 'echarts-for-react';
import usePageTable from '../../../components/crud/usePageTable2';
import { createCrudService } from '../../../components/crud/_';
import { CrudOpRender_text } from '../../../components/crud/CrudOpRender';
import "./index.less"
2024-09-26 17:45:57 +08:00
import { httpget2 } from '../../../utils/request';
import moment from 'moment';
2024-09-24 16:52:53 +08:00
const Page = () => {
const role = useSelector(state => state.auth.role);
const editBtn = role?.rule?.find(item => item.menuName == "编辑") || true;
const viewBtn = role?.rule?.find(item => item.menuName == "查看") || true;
const delBtn = role?.rule?.find(item => item.menuName == "删除") || true;
const refModal = useRef();
const [searchVal, setSearchVal] = useState(false)
const [searchChartVal, setSearchChartVal] = useState(false)
const columns = [
{ title: '序号', key: 'inx', dataIndex: 'inx', width: 60, align:"center" },
2024-09-26 17:45:57 +08:00
{ title: '培训日期', key: 'planDate', dataIndex: 'planDate', width: 200, ellipsis: true },
2024-09-24 16:52:53 +08:00
{
2024-09-26 17:45:57 +08:00
title: '标题', key: 'name', dataIndex: 'name', width: 200,ellipsis: true
2024-09-24 16:52:53 +08:00
},
2024-09-26 17:45:57 +08:00
{ title: '主办单位', key: 'unit', dataIndex: 'unit', width: 150 },
2024-09-24 16:52:53 +08:00
{
2024-09-26 17:45:57 +08:00
title: '培训内容', key: 'content', dataIndex: 'content', width: 200,ellipsis: true
2024-09-24 16:52:53 +08:00
},
2024-09-26 17:45:57 +08:00
{ title: '参训人员', key: 'trainees', dataIndex: 'trainees', width: 200, ellipsis: true },
{ title: '培训地点', key: 'addr', dataIndex: 'addr', width: 150, ellipsis: true },
{ title: '填报人', key: 'applicant', dataIndex: 'applicant', width: 150, ellipsis: true },
{ title: '登记日期', key: 'regDate', dataIndex: 'regDate', width: 150, ellipsis: true },
2024-09-24 16:52:53 +08:00
{
title: '操作', key: 'operation', width: 200, fixed: 'right',align: 'center',
render: (value, row, index) => (
<CrudOpRender_text
edit={editBtn ? true : false}
del={delBtn ? true : false}
view={viewBtn ? true : false}
command={(cmd) => () => command(cmd)(row)} />)
},
];
const width = useMemo(() => columns.reduce((total, cur) => total + (cur.width), 0), [columns]);
2024-09-26 17:45:57 +08:00
2024-09-24 16:52:53 +08:00
const command = (type) => (params) => {
if (type === 'save') {
refModal.current.showSave();
} else if (type === 'edit') {
refModal.current.showEdit({ ...params });
} else if (type === 'view') {
refModal.current.showView(params);
} else if (type === 'del') {
2024-09-26 17:45:57 +08:00
refModal.current.onDeleteGet(apiurl.pxjl.delete + `/${params.id}`);
2024-09-24 16:52:53 +08:00
}
}
2024-09-26 17:45:57 +08:00
const { tableProps, search, refresh } = usePageTable(createCrudService(apiurl.pxjl.page).find_noCode);
2024-09-24 16:52:53 +08:00
/**
* @description 处理成功的回调
*/
const successCallback = () => {
refresh()
}
2024-09-26 17:45:57 +08:00
// 获取统计数据
const [staData, setStaData] = useState()
const pxOptions = useMemo(() => {
if (staData) {
2024-10-16 15:30:22 +08:00
return options(staData,searchChartVal.teamName)
2024-09-26 17:45:57 +08:00
} else {
2024-10-16 15:30:22 +08:00
return options({},searchChartVal.teamName)
2024-09-26 17:45:57 +08:00
}
}, [staData])
const getStaData = async (params) => {
try {
const res = await httpget2(apiurl.pxjl.sta + `/${params.year}`)
if (res.code == 200) {
if (params.teamName == 1) {
setStaData({...res.data,list:res.data.list1})
} else {
setStaData({...res.data,list:res.data.list2})
}
2024-10-15 10:56:24 +08:00
}else{
message.error(res.description)
setStaData([])
2024-09-26 17:45:57 +08:00
}
} catch (error) {
console.log(error);
}
}
2024-09-24 16:52:53 +08:00
useEffect(()=>{
const params = {
search: {
...searchVal,
}
};
search(params)
}, [searchVal])
2024-09-26 17:45:57 +08:00
useEffect(() => {
if (searchChartVal) {
getStaData(searchChartVal)
}
}, [searchChartVal])
2024-09-24 16:52:53 +08:00
return (
<>
<div className='content-root clearFloat xybm' style={{paddingRight:"0",paddingBottom:"0"}}>
<div className='lf CrudAdcdTreeTableBox' style={{ width: "100%" }}>
<div style={{ width: "100%", height: "35vh", marginBottom: 20, padding: 10,display:"flex",columnGap:10 }}>
<div className='pxrecord-title-left'>
<div className='first-item'>
<img src={`${process.env.PUBLIC_URL}/assets/images/qishu.jpg`} alt='' />
<div className='children-itm'>
<span>本年培训期数</span>
<span>计划/实际</span>
2024-09-26 17:45:57 +08:00
<span><span style={{ fontSize: 22, fontWeight: "bold" }}>{ staData?.numberOfPeriods2 ?? 1}</span>&nbsp;期/
<span style={{fontSize:22,fontWeight:"bold"}}>{ staData?.numberOfPeriods1 ?? 1}</span>&nbsp;</span>
2024-09-24 16:52:53 +08:00
</div>
</div>
<div className='second-item'>
<img src={`${process.env.PUBLIC_URL}/assets/images/renchi.jpg`} alt='' />
<div className='children-itm'>
2024-10-16 15:30:22 +08:00
<span>本年培训人次</span>
2024-09-24 16:52:53 +08:00
<span>计划/实际</span>
2024-09-26 17:45:57 +08:00
<span><span style={{fontSize:22,fontWeight:"bold"}}>{ staData?.personNum2 ?? 1}</span>&nbsp;人次/
<span style={{fontSize:22,fontWeight:"bold"}}>{ staData?.personNum1 ?? 1}</span>&nbsp;</span>
2024-09-24 16:52:53 +08:00
</div>
</div>
</div>
<div className='pxrecord-title-right'>
<div className='chart-tool'>
<ChartToolBar
2024-09-26 17:45:57 +08:00
setSearchVal={setSearchChartVal}
2024-09-24 16:52:53 +08:00
/>
</div>
<div className='chart-box'>
<ReactEcharts
option={pxOptions || {}}
style={{ width: "100%", height: '100%' }}
notMerge={true}
/>
</div>
</div>
</div>
<Card className='nonebox'>
<ToolBar
setSearchVal={setSearchVal}
onSave={command('save')}
role={role}
callback={refresh}
/>
</Card>
<div className="ant-card-body" style={{padding:"20px 0 0 0"}}>
<Table columns={columns} rowKey="inx" {...tableProps} scroll={{ x: width , y: "calc( 100vh - 400px )"}}/>
</div>
</div>
<BasicCrudModal
width={1000}
ref={refModal}
title=""
component={ModalForm}
onCrudSuccess={successCallback}
// onCrudSuccess={()=>{refresh({addvcd:localStorage.getItem('ADCD6')})}}
/>
</div>
</>
);
}
export default Page;