父组件
import React, { Component } from 'react';
import DailyTrainyLeft from './DailyTrainLeft';
import DailyTrainRight from './DailyTrainRight';
/**
* 日常训练模块
*/
export default class DailyTrain extends Component {
constructor(props) {
super(props);
this.state = {
activeKey: ''
};
}
componentDidMount(){
//右侧窗口默认显示第一个数据查询的列表
this.list && this.list.onRequestTable((list) => this.onEditClick(list[0]))
}
onEditClick = (record) => {
this.listTwo.onEdit(record.key)
}
render() {
return (
<div className="dailyTrain-safety">
<div className="dailyTrain-safty-content">
<div className="dailyTrain-top"></div>
<div className="dailyTrain-bottom">
<DailyTrainyLeft ref={node => this.list = node} onEditClick={this.onEditClick}/>
<DailyTrainRight ref={node => this.listTwo = node}/>
</div>
</div>
</div>
);
}
}
子组件
import React, { Component } from 'react';
import ReactEcharts from 'amos-viz/lib/echarts';
import { Table } from 'amos-antd';
import AmosGridTable from './../safetyManage/AmosGridTable';
import { Input, Button } from 'amos-antd';
import { DatePicker } from 'amos-antd';
import moment from 'moment';
import dt2react from 'dt2react';
const dateFormatList = ['DD/MM/YYYY', 'DD/MM/YY'];
const { RangePicker } = DatePicker;
const dateFormat = 'YYYY/MM/DD';
const monthFormat = 'YYYY/MM';
import { Select } from 'amos-framework';
const Option = Select.Option;
const Search = Input.Search;
const columns = [
{
title: '序号',
dataIndex: 'key',
width: '10%',
align: 'center', // 设置文本居中的属性
render: val => <span style={{color:"white"}}>{val}</span>,
},
{
title: '换流站名称',
width: '20%',
dataIndex: 'name',
render: val => <span style={{color:"yellow"}}>{val}</span>,
},
{
title: '科目数',
width: '10%',
dataIndex: 'kemu',
render: val => <span style={{color:"white"}}>{val}</span>,
},
{
title: '次数',
width: '10%',
dataIndex: 'cishu',
render: val => <span style={{color:"white"}}>{val}</span>,
},
{
title: '参加人员',
width: '10%',
dataIndex: 'cjry',
render: val => <span style={{color:"white"}}>{val}</span>,
},
{
title: '人员达标率',
width: '20%',
dataIndex: 'rydbl',
render: val => <span style={{color:"white"}}>{val}</span>,
},
{
title: '最近培训时间',
width: '20%',
dataIndex: 'date',
render: val => <span style={{color:"white"}}>{val}</span>,
}
];
const data = [
{
key: '1',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '2',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '3',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '4',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '5',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '6',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '7',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '8',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '9',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '10',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '11',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '12',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '13',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '14',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '15',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '16',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '17',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '18',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '19',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '20',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '21',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '22',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '23',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '225',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '25',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '26',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '27',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '28',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
},
{
key: '29',
name: '复龙换流站',
kemu: 3,
cishu:4,
cjry: 5,
rydbl:'50%',
date:"2019-01-01"
}
];
const selectdata = [
{ id: 0, name: '消防理论知识培训' },
{ id: 1, name: '消防技能培训' },
{ id: 3, name: '设备器材维护管理' },
{ id: 4, name: '火灾隐患管理' },
{ id: 5, name: '用火用电管理' }
];
//偏移
const offsetHeight = 110;
const defaultHeight = 450;
/**
* 日常训练左侧
*/
class DailyTrainyLeft extends Component {
constructor(props) {
super(props);
this.pageConfig = {
current: 1,
pageSize: 14
};
this.state = {
data: [],
loading: false,
equimentId:null,
pagination: true,
isChecked: false,
selectedRows: [],
selectedRowKeys: [],
dataList: [],
newDataList:[],
totalCount:0,
searchParam:'',
fname:'',
current: 1,
pageSize: 10,
total: 0,
tableHeight:450
};
}
componentDidMount() {
}
onRequestTable = (callback) => {
this.setState({
data:data,
totalCount:data.length
});
callback && callback(data);
// electricFireListAction(current, pageSize, searchName).then(d => {
// const { dataList, total } = d || {};
// });
}
onChange = (value, item) =>{
console.log(value, item);
}
onTimeChange= (value, dateString)=> {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString);
}
onOk=(value) =>{
console.log('onOk: ', value);
}
onChangeSelect = (value, item) =>{
console.log(value, item);
}
reload = r => {
this.setState(
{
reload: () => {
r();
this.setState({ selectedRows: [], selectedRowKeys: [] });
}
},
r()
);
};
getAcitonData = () =>{
this.setState({
data:data
})
}
/**
* 分页设置参数
*/
setPageConfig = ({ pageSize, current }) => {
if (pageSize !== undefined) {
this.pageConfig.pageSize = pageSize;
}
if (current !== undefined) {
this.pageConfig.pageNumber = current;
}
};
/**
* 获取表格所选则的行数据
*/
getSelectedRows = (selectedRows, selectedRowKeys) => {
this.setState({ selectedRows, selectedRowKeys });
let { riskSourceId, equipmentId, callBack } = this.props;
// callBack(selectedRowKeys,riskSourceId,equipmentId);
};
searchData =()=>{
let name = this.state.fname;
alert(name)
}
onChange = (e,value) =>{
this.setState({ fname: value });
}
getPanelHeight = () => {
//计算表格高度
var box1=document.getElementById("dailyTrain-bottom-left");
if(box1){ //此处在加一层判断,更加严密,如果box存在的情况下获取
return box1.offsetHeight * 0.91
}
};
SearchChange = (value) => {
alert(value)
}
rowClassName = (record, index) => {
let className = index % 2 ? 'back-01': 'back-02';
return className
}
render() {
let defaultPageConfig = this.pageConfig;
const { current, pageSize, total } = this.state;
const {onEditClick} =this.props;
let { pagination, isChecked, fname,data,totalCount,selectedRowKeys } = this.state;
return (
<div className="dailyTrain-bottom-left" id="dailyTrain-bottom-left">
<div className="dailyTrain-bottom-left-content">
<div className="one-div" id="one-div">
<div className="search-one">
{/* <div className="search-one-button" onClick={this.searchData} /> */}
<div className="search-one-input">
<Search placeholder="搜索" onSearch={this.SearchChange} />
</div>
</div>
<div className="search-two" >
<Select className="search-select-style"
data={selectdata}
renderOption={item => <Option value={item.id}>{item.name}</Option>}
defaultOption={<Option>请选择</Option>}
onChange={this.onChangeSelect}
/>
</div>
<div className="search-three">
<span className="three-font">日期: </span>
<DatePicker
placeholder="年-月-日"
showTime
onChange={this.onTimeChange}
style={{width:'37%'}}
onOk={this.onOk} />
{/* <DatePicker defaultValue={moment('2015/01/01', dateFormat)} format={dateFormat} /> */}
<font style={{color:'#5FFFFD'}}>一</font>
<DatePicker
placeholder="年-月-日"
showTime
onChange={this.onTimeChange}
style={{width:'37%'}}
onOk={this.onOk} />
</div>
</div>
<div className="two-div">
<AmosGridTable
columns={columns}
dataList={data}
isPageable={pagination}
totals={totalCount}
callBack={this.reload}
selectedRowKeys={selectedRowKeys}
getSelectedRows={this.getSelectedRows}
getTableDataAction={this.getAcitonData}
isChecked={isChecked}
setPageConfig={this.setPageConfig}
defaultPageConfig={defaultPageConfig}
getPanelHeight={this.getPanelHeight}
rowClassName={this.rowClassName}
onRowClick={(record) => onEditClick(record)}
/>
</div>
</div>
</div>
);
}
}
DailyTrainyLeft.propTypes = {
};
export default DailyTrainyLeft;