import React from 'react' import { Modal, Checkbox, Row, message } from 'antd' class EDBenchMarkingModel extends React.Component { constructor (props) { super(props) this.state = { visible: false, options: [], defaultValue: [], boxData: [], boxDefaultValue: [], indeterminate: false, // 全反选 checkAll: true } }; componentDidMount() { if (this.props.onRef) { this.props.onRef(this) } }; showModal = () => { this.getCheckboxData(true) this.setState({ visible: true, }) } handleOk = e => { this.SettingSave() }; handleCancel = e => { this.setState({ visible: false, }) }; getCheckboxData = (isFirst) => { const json = { OrgId: this.props.login.OrgId, ParentIds: this.state.defaultValue, IsFirst: isFirst } this.props.dispatch({ type: 'app/getDataByPost', url: 'ED/EDProdRecord/GetEnergyMeasuringData', payload: json, onlyData: false, onComplete: (re) => { if (re && re.IsSuccessful && re.Data) { let tmp = [] re.Data.DefaultValue.forEach(element => { tmp.push(element) }) this.setState({ boxData: re.Data.Options }, () => { const checkedValues = re.Data.DefaultValue this.setState({ boxDefaultValue: checkedValues, indeterminate: !!checkedValues.length && checkedValues.length < this.state.boxData.length, checkAll: checkedValues.length === this.state.boxData.length }) }) } } }) }; SettingSave = () => { const json = { OrgId: this.props.login.OrgId, ParentIds: this.state.defaultValue, ChildIds: this.state.boxDefaultValue, } this.props.dispatch({ type: 'app/getDataByPost', url: 'ED/EDProdRecord/SettingSave', payload: json, onlyData: false, onComplete: (re) => { if (re && re.IsSuccessful && re.Data) { if (re.Data.IsSucceed) { message.success(re.Data.Msg) this.setState({ visible: false, }, () => { this.props.getTableData() }) } else message.error(re.Data.Msg) } } }) }; onCheck = (checkedValues) => { this.setState({ boxDefaultValue: checkedValues }) } onCheckAllChange = (e) => { const checkedValues = e.target.checked ? this.state.boxData.map(item => item.Value) : [] this.setState({ boxDefaultValue: checkedValues, indeterminate: false, checkAll: e.target.checked }) } render() { return (
全/反选
{ this.state.boxData.map(item => { return (
{item.Label}
) }) }
) } } export default EDBenchMarkingModel