table.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-04-27 18:08:04
  4. * @LastEditTime: 2021-04-30 15:47:42
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /react-antd-admin-template/src/views/checkPointManage/checkItem/table.js
  8. */
  9. /*
  10. * @Author: your name
  11. * @Date: 2021-04-27 11:19:40
  12. * @LastEditTime: 2021-04-27 15:20:38
  13. * @LastEditors: Please set LastEditors
  14. * @Description: In User Settings Edit
  15. * @FilePath: /react-antd-admin-template/src/views/groupManage/groupIdentity/table.js
  16. */
  17. import React from 'react';
  18. import { Table,Popconfirm, Form,Divider} from 'antd';
  19. class EditableTable extends React.Component {
  20. static defaultProps = {
  21. editCallback: ()=>{},
  22. deleteCallback:()=>{},
  23. callbackFromChild:()=>{},
  24. config:{
  25. action:{
  26. deleteBtn:true,
  27. editBtn:true,
  28. editPermissionBtn:false
  29. }
  30. }
  31. }
  32. constructor(props) {
  33. super(props);
  34. this.state = { data:[], editingKey: '',loading:false};
  35. this.columns = [
  36. ...props.columns,
  37. {
  38. title: '操作',
  39. dataIndex: 'operation',
  40. render: (text, record) => {
  41. const { editingKey} = this.state;
  42. // console.log({editingKey,record});
  43. return (
  44. <span>
  45. <a disabled={editingKey !== ''} onClick={() => this.editItem(record)}>
  46. 编辑
  47. </a>
  48. <Divider type="vertical" />
  49. <Popconfirm title=" 是否确定删除?" onConfirm={()=>this.delItem(record)}>
  50. <a disabled={editingKey !== ''} >
  51. 删除
  52. </a>
  53. </Popconfirm>
  54. {/* <Divider type="vertical" />
  55. <a disabled={editingKey !== ''} onClick={() => this.bindGroup(record)}>
  56. 绑定单位
  57. </a> */}
  58. </span>
  59. );
  60. },
  61. },
  62. ];
  63. }
  64. componentDidMount(){
  65. this.setState({
  66. data:this.props.data
  67. });
  68. }
  69. componentDidUpdate(prevProps, prevState){
  70. // console.log({prevProps, prevState});
  71. if(prevProps.ifUpdateList){
  72. console.log('update');
  73. this.setState({
  74. data:this.props.data
  75. });
  76. }
  77. }
  78. isEditing = record => {
  79. // console.log(record.id,this.state.editingKey);
  80. return record.id === this.state.editingKey;
  81. }
  82. editItem=(record)=>{
  83. this.props.callbackFromChild(record);
  84. }
  85. delItem=record=>{
  86. this.props.deleteCallback(record);
  87. }
  88. changePage(current){
  89. this.setState({ loading: true });
  90. this.props.paginationCallback({'currPage':current-1})
  91. }
  92. render() {
  93. const columns = this.columns.map(col => {
  94. if (!col.editable) {
  95. return col;
  96. }
  97. return {
  98. ...col,
  99. onCell: record => ({
  100. record,
  101. }),
  102. };
  103. });
  104. const {
  105. currPage,
  106. totalCount,
  107. } = this.props.pages;
  108. const paginationProps = {
  109. showSizeChanger: false,
  110. showQuickJumper: false,
  111. showTotal: () => `共${totalCount}条`,
  112. pageSize: 10,
  113. current: currPage+1,
  114. total: totalCount,
  115. onChange: (current) => this.changePage(current),
  116. }
  117. return (
  118. <Table
  119. bordered
  120. loading={this.state.loading}
  121. pagination={paginationProps}
  122. dataSource={this.state.data}
  123. columns={columns}
  124. rowClassName="editable-row"
  125. />
  126. );
  127. }
  128. }
  129. const EditableFormTable = Form.create()(EditableTable);
  130. export default EditableFormTable;