import React, { useState, useRef, useEffect } from 'react'; import { connect } from 'react-redux'; import { Button, Popconfirm, Tag } from 'antd'; import ProTable from '@ant-design/pro-table'; import PlanTemplateModal from '../components/planTemplateModal'; import { createPatrolTemplate, delPatrolTemplate, updatePatrolTemplate, getPatrolTemplate } from '../actions/template'; import { getCheckItemsGroup } from '../actions/checkItems'; function PatrolTemplate(props) { const { dispatch, user } = props; const tableRef = useRef(); const [dataSource, setDataSource] = useState([{}]); const [visible, setVisible] = useState(false); const [type, setType] = useState(); const [curRecord, setCurRecord] = useState(); useEffect(() => { dispatch(getCheckItemsGroup()) }, []) const columns = [{ title: '模板名称', dataIndex: 'name', key: 'name', ellipsis: true, }, { title: '模板描述', dataIndex: 'describe', key: 'describe', ellipsis: true, search: false, }, { title: '操作人', dataIndex: 'user.name', key: 'user.name', ellipsis: true, search: false, render: (t, r, i) => { return r.user ? r.user.name : '-' } }, { title: '检查项', dataIndex: 'checkItems', key: 'checkItems', ellipsis: true, search: false, render: (_, r) => { return r?.checkItems ? r?.checkItems.map(c => {c.name}) : '-' } }, { title: '操作', dataIndex: 'action', key: 'action', search: false, width: 200, render: (_, record) => { return <> { dispatch(delPatrolTemplate(record.id)).then(res => { if (res.success) { tableRef.current.reload(); } }) }}> }, }]; return ( <> [ ...dom.reverse(), , ], }} request={async (params = {}) => { const res = await dispatch(getPatrolTemplate(params)); setDataSource(res?.payload.data?.rows); return { ...res }; }} onReset={() => { }} rowClassName={(record, index) => { let className = 'global-light-row'; if (index % 2 === 1) className = 'global-dark-row'; return className; }} /> { visible ? { setVisible(false); setCurRecord({}) }} tableRef={tableRef} /> : null } ) } function mapStateToProps(state) { const { auth } = state return { user: auth.user } } export default connect(mapStateToProps)(PatrolTemplate);