import React, { Component } from "react"; import { Button, Modal, Checkbox, } from "antd"; import $ from "jquery/src/ajax"; import "./index.less"; import MySuspend from './index'; // 项目暂停 class SelectList extends Component { constructor(props) { super(props); this.state = { plainOptions: [], // 多选渲染数据 checkedList: [], // 选中数据的id checkedValues: [], // 渲染数据的id selectedRows: [], // 项目暂停用到的选中数据 indeterminate: false, checkAll: false, suspendVisible: false, }; this.onCheckAllChange = this.onCheckAllChange.bind(this); this.onChange = this.onChange.bind(this); this.onOk = this.onOk.bind(this); this.subClose = this.subClose.bind(this); } componentDidMount() { const { list = [], type } = this.props; let options = []; let defaultValue = []; let arr = []; if (type == "suspend") { // 项目暂停 arr = list.filter(v => { return (v.stopType != 0 && v.projectStatus != 29) }); } else if (type == "restart") { // 项目重启 arr = list.filter(v => { return (v.stopType == 0 && v.stopStatus == 1) }); } arr.forEach(item => { let obj = { label: item.commodityName + "-" + item.id, value: item.id }; options.push(obj) defaultValue.push(item.id) }) this.setState({ plainOptions: options, checkedValues: defaultValue, }) } // 全选 onCheckAllChange(e) { const { checkedValues } = this.state this.setState({ checkedList: e.target.checked ? checkedValues : [], indeterminate: false, checkAll: e.target.checked, }); } // 单选操作 onChange(checkedList) { const { checkedValues } = this.state this.setState({ checkedList, indeterminate: !!checkedList.length && (checkedList.length < checkedValues.length), checkAll: checkedList.length === checkedValues.length, }); } // 确定 onOk() { const { list } = this.props; const { checkedList } = this.state let rows = []; for (var i = 0; i < list.length; i++) { for (var j = 0; j < checkedList.length; j++) { if (list[i].id == checkedList[j]) { let obj = { commodityName: list[i].commodityName, id: list[i].id } rows.push(obj) } } } this.setState({ selectedRows: rows, suspendVisible: true }) } // 关闭 subClose() { const { subClose } = this.props this.setState({ suspendVisible: false, }, () => { subClose() }) } render() { const { plainOptions, checkedValues, indeterminate, checkAll, checkedList } = this.state const { visible, subClose, } = this.props const CheckboxGroup = Checkbox.Group; return (
{ plainOptions.length == 0 ?
暂无可操作的项目
:
全选
}
{ this.state.suspendVisible && }
); } } export default SelectList;