selectList.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import React, { Component } from "react";
  2. import { Button, Modal, Checkbox, } from "antd";
  3. import $ from "jquery/src/ajax";
  4. import "./index.less";
  5. import MySuspend from './index'; // 项目暂停
  6. class SelectList extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. plainOptions: [], // 多选渲染数据
  11. checkedList: [], // 选中数据的id
  12. checkedValues: [], // 渲染数据的id
  13. selectedRows: [], // 项目暂停用到的选中数据
  14. indeterminate: false,
  15. checkAll: false,
  16. suspendVisible: false,
  17. };
  18. this.onCheckAllChange = this.onCheckAllChange.bind(this);
  19. this.onChange = this.onChange.bind(this);
  20. this.onOk = this.onOk.bind(this);
  21. this.subClose = this.subClose.bind(this);
  22. }
  23. componentDidMount() {
  24. const { list = [], type } = this.props;
  25. let options = [];
  26. let defaultValue = [];
  27. let arr = [];
  28. if (type == "suspend") {
  29. // 项目暂停
  30. arr = list.filter(v => {
  31. return (v.stopType != 0 && v.projectStatus != 29)
  32. });
  33. } else if (type == "restart") {
  34. // 项目重启
  35. arr = list.filter(v => {
  36. return (v.stopType == 0 && v.stopStatus == 1)
  37. });
  38. }
  39. arr.forEach(item => {
  40. let obj = {
  41. label: item.commodityName + "-" + item.id,
  42. value: item.id
  43. };
  44. options.push(obj)
  45. defaultValue.push(item.id)
  46. })
  47. this.setState({
  48. plainOptions: options,
  49. checkedValues: defaultValue,
  50. })
  51. }
  52. // 全选
  53. onCheckAllChange(e) {
  54. const { checkedValues } = this.state
  55. this.setState({
  56. checkedList: e.target.checked ? checkedValues : [],
  57. indeterminate: false,
  58. checkAll: e.target.checked,
  59. });
  60. }
  61. // 单选操作
  62. onChange(checkedList) {
  63. const { checkedValues } = this.state
  64. this.setState({
  65. checkedList,
  66. indeterminate: !!checkedList.length && (checkedList.length < checkedValues.length),
  67. checkAll: checkedList.length === checkedValues.length,
  68. });
  69. }
  70. // 确定
  71. onOk() {
  72. const { list } = this.props;
  73. const { checkedList } = this.state
  74. let rows = [];
  75. for (var i = 0; i < list.length; i++) {
  76. for (var j = 0; j < checkedList.length; j++) {
  77. if (list[i].id == checkedList[j]) {
  78. let obj = {
  79. commodityName: list[i].commodityName,
  80. id: list[i].id
  81. }
  82. rows.push(obj)
  83. }
  84. }
  85. }
  86. this.setState({
  87. selectedRows: rows,
  88. suspendVisible: true
  89. })
  90. }
  91. // 关闭
  92. subClose() {
  93. const { subClose } = this.props
  94. this.setState({
  95. suspendVisible: false,
  96. }, () => {
  97. subClose()
  98. })
  99. }
  100. render() {
  101. const { plainOptions, checkedValues, indeterminate, checkAll, checkedList } = this.state
  102. const { visible, subClose, } = this.props
  103. const CheckboxGroup = Checkbox.Group;
  104. return (
  105. <Modal
  106. maskClosable={false}
  107. visible={visible}
  108. width={"520px"}
  109. title="请勾选"
  110. footer=""
  111. onCancel={subClose}
  112. >
  113. <div>
  114. {
  115. plainOptions.length == 0
  116. ? <div
  117. style={{
  118. margin: 50,
  119. color: "red",
  120. fontSize: "24px",
  121. textAlign: "center"
  122. }}
  123. >暂无可操作的项目</div>
  124. : <div>
  125. <Checkbox
  126. indeterminate={indeterminate}
  127. onChange={this.onCheckAllChange}
  128. checked={checkAll}>
  129. 全选
  130. </Checkbox>
  131. <CheckboxGroup
  132. className={"selectlist"}
  133. options={plainOptions}
  134. value={checkedList}
  135. onChange={this.onChange}
  136. />
  137. </div>
  138. }
  139. <div style={{ height: 30 }}>
  140. <Button
  141. disabled={checkedList.length == 0}
  142. type="primary"
  143. style={{
  144. float: "right",
  145. }}
  146. onClick={this.onOk}
  147. >
  148. 确定
  149. </Button>
  150. </div>
  151. </div>
  152. {
  153. this.state.suspendVisible &&
  154. <MySuspend
  155. type={this.props.type}
  156. title={this.props.type == "suspend" ? "项目暂停" : "项目重启"}
  157. contractNo={this.props.contractNo}
  158. orderNo={this.props.orderNo}
  159. userName={this.props.userName}
  160. selectedRowKeys={this.state.checkedList}
  161. selectedRows={this.state.selectedRows}
  162. visible={this.state.suspendVisible}
  163. subClose={this.subClose}
  164. />
  165. }
  166. </Modal>
  167. );
  168. }
  169. }
  170. export default SelectList;