批量删除
This commit is contained in:
@@ -70,6 +70,7 @@ const orderStatusConfig = {
|
|||||||
|
|
||||||
const WorkOrderPage = () => {
|
const WorkOrderPage = () => {
|
||||||
const [activeTab, setActiveTab] = useState('1');
|
const [activeTab, setActiveTab] = useState('1');
|
||||||
|
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]); // 批量选中
|
||||||
const [selectedRowKey, setSelectedRowKey] = useState('');
|
const [selectedRowKey, setSelectedRowKey] = useState('');
|
||||||
// 接口相关状态
|
// 接口相关状态
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -205,12 +206,15 @@ const WorkOrderPage = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 选中表格行
|
// 选中表格行(单选查看详情)
|
||||||
const handleRowSelect = (keys) => {
|
const handleRowSelect = (record) => {
|
||||||
if (keys.length > 0) {
|
setSelectedRowKey(record.id);
|
||||||
setSelectedRowKey(keys[0]);
|
getWorkOrderDetail(record.id);
|
||||||
getWorkOrderDetail(keys[0]);
|
};
|
||||||
}
|
|
||||||
|
// 表格多选变化
|
||||||
|
const onSelectChange = (keys: string[]) => {
|
||||||
|
setSelectedRowKeys(keys);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 打开修改工单弹窗
|
// 打开修改工单弹窗
|
||||||
@@ -299,7 +303,7 @@ const WorkOrderPage = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 删除工单(修复版:删除当前行)
|
// 删除单行
|
||||||
const handleDelete = async (record) => {
|
const handleDelete = async (record) => {
|
||||||
if (!record?.id) return messageApi.warning('无效工单');
|
if (!record?.id) return messageApi.warning('无效工单');
|
||||||
try {
|
try {
|
||||||
@@ -312,6 +316,22 @@ const WorkOrderPage = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 批量删除
|
||||||
|
// 批量删除 - 传给后端 id数组
|
||||||
|
const handleBatchDelete = async () => {
|
||||||
|
if (selectedRowKeys.length === 0) return messageApi.warning('请选择要删除的工单');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteWorkOrder(selectedRowKeys);
|
||||||
|
messageApi.success(`成功删除 ${selectedRowKeys.length} 条工单`);
|
||||||
|
setSelectedRowKeys([]); // 清空选中
|
||||||
|
getWorkOrderList(); // 刷新列表
|
||||||
|
} catch (e) {
|
||||||
|
messageApi.error('批量删除失败');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getWorkOrderList();
|
getWorkOrderList();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -375,15 +395,21 @@ const WorkOrderPage = () => {
|
|||||||
fixed: "right",
|
fixed: "right",
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space size={4}>
|
<Space size={4}>
|
||||||
<Button type="link" size="small" onClick={() => { setSelectedRowKey(record.id); getWorkOrderDetail(record.id); }}>查看</Button>
|
<Button type="link" size="small" onClick={() => handleRowSelect(record)}>查看</Button>
|
||||||
<Button type="link" size="small" onClick={() => { setSelectedRowKey(record.id); getWorkOrderDetail(record.id); openEditModal(); }}>修改</Button>
|
<Button type="link" size="small" onClick={() => { handleRowSelect(record); openEditModal(); }}>修改</Button>
|
||||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record)}
|
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record)}>
|
||||||
><Button type="link" size="small" danger>删除</Button></Popconfirm>
|
<Button type="link" size="small" danger>删除</Button>
|
||||||
|
</Popconfirm>
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const rowSelection = {
|
||||||
|
selectedRowKeys,
|
||||||
|
onChange: onSelectChange,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: '0px 0px', background: '#f5f7fa', minHeight: '100vh', boxSizing: 'border-box' }}>
|
<div style={{ padding: '0px 0px', background: '#f5f7fa', minHeight: '100vh', boxSizing: 'border-box' }}>
|
||||||
<style>{`
|
<style>{`
|
||||||
@@ -459,7 +485,10 @@ const WorkOrderPage = () => {
|
|||||||
<Input placeholder="请输入工单编号/标题" prefix={<SearchOutlined />} size="small" />
|
<Input placeholder="请输入工单编号/标题" prefix={<SearchOutlined />} size="small" />
|
||||||
</div></Col>
|
</div></Col>
|
||||||
<Col xs={24} sm={8} md={4} xl={3} style={{ textAlign: 'right' }}>
|
<Col xs={24} sm={8} md={4} xl={3} style={{ textAlign: 'right' }}>
|
||||||
<Space><Button size="small">重置</Button><Button type="primary" size="small" icon={<SearchOutlined />}>查询</Button></Space>
|
<Space>
|
||||||
|
<Button size="small">重置</Button>
|
||||||
|
<Button type="primary" size="small" icon={<SearchOutlined />}>查询</Button>
|
||||||
|
</Space>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -467,8 +496,27 @@ const WorkOrderPage = () => {
|
|||||||
<Row gutter={[8, 8]}>
|
<Row gutter={[8, 8]}>
|
||||||
{/* 左侧:列表 + 底部图表 */}
|
{/* 左侧:列表 + 底部图表 */}
|
||||||
<Col xs={24} xl={15}>
|
<Col xs={24} xl={15}>
|
||||||
<Card bordered={false} title={<Space size={8}><Text strong style={{ fontSize: 15, color: '#1D2129' }}>工单列表</Text><Text type="secondary" style={{ fontSize: 12 }}>(共 {workOrderTotal} 条)</Text></Space>}
|
<Card
|
||||||
bodyStyle={{ padding: 0 }} style={{ ...cardStyle, marginBottom: 8 }}>
|
bordered={false}
|
||||||
|
title={
|
||||||
|
<Space size={8}>
|
||||||
|
<Text strong style={{ fontSize: 15, color: '#1D2129' }}>工单列表</Text>
|
||||||
|
<Text type="secondary" style={{ fontSize: 12 }}>(共 {workOrderTotal} 条)</Text>
|
||||||
|
{selectedRowKeys.length > 0 && (
|
||||||
|
<Popconfirm
|
||||||
|
title={`确定删除已选中的 ${selectedRowKeys.length} 条工单吗?`}
|
||||||
|
onConfirm={handleBatchDelete}
|
||||||
|
>
|
||||||
|
<Button size="small" danger icon={<DeleteOutlined />}>
|
||||||
|
批量删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
bodyStyle={{ padding: 0 }}
|
||||||
|
style={{ ...cardStyle, marginBottom: 8 }}
|
||||||
|
>
|
||||||
<Table
|
<Table
|
||||||
dataSource={workOrderList}
|
dataSource={workOrderList}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -478,7 +526,10 @@ const WorkOrderPage = () => {
|
|||||||
rowKey="id"
|
rowKey="id"
|
||||||
className="compact-table"
|
className="compact-table"
|
||||||
scroll={{ x: 'max-content' }}
|
scroll={{ x: 'max-content' }}
|
||||||
rowSelection={{ type: 'radio', selectedRowKeys: [selectedRowKey], onChange: handleRowSelect }}
|
rowSelection={rowSelection}
|
||||||
|
onRow={(record) => ({
|
||||||
|
onClick: () => handleRowSelect(record)
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
<div style={{ padding: '12px 16px', textAlign: 'right' }}>
|
<div style={{ padding: '12px 16px', textAlign: 'right' }}>
|
||||||
<Pagination size="small" total={workOrderTotal} showSizeChanger showQuickJumper />
|
<Pagination size="small" total={workOrderTotal} showSizeChanger showQuickJumper />
|
||||||
|
|||||||
Reference in New Issue
Block a user