/*
|
* @Company: hugeInfo
|
* @Author: victor
|
* @Date: 2024-07-30 10:00:00
|
* @LastEditTime: 2024-07-30 10:00:00
|
* @LastEditors: victor
|
* @Version: 1.0.0
|
* @Description: 草稿箱页面
|
*/
|
import React, { useState, useEffect } from 'react';
|
import { useHistory } from 'react-router-dom';
|
import { Input, Button, Tag, List, Modal } from 'antd';
|
import { SearchOutlined } from '@ant-design/icons';
|
import NavBarPage from '../../components/NavBarPage';
|
import * as $$ from '../../utils/utility';
|
import './index.less';
|
|
// 接口 - 分页查询草稿箱
|
function pageQueryApi(data) {
|
return $$.ax.request({ url: 'casedraftInfo/pageQuery', type: 'get', data, service: 'mediate' });
|
}
|
|
// 接口 - 删除草稿
|
function deleteDraftApi(id) {
|
// 注意:请替换为实际的删除接口URL和参数
|
return $$.ax.request({ url: `casedraftInfo/deleteById?id=${id}`, type: 'get', service: 'mediate' });
|
}
|
|
|
const DraftBox = () => {
|
const history = useHistory();
|
const [searchKeyword, setSearchKeyword] = useState('');
|
const [draftList, setDraftList] = useState([]);
|
const [total, setTotal] = useState(0);
|
const [loading, setLoading] = useState(false);
|
// 分页状态可以根据需要添加,这里简化处理,一次性加载
|
// const [pagination, setPagination] = useState({ current: 1, pageSize: 10 });
|
|
// 获取草稿列表数据
|
const fetchDrafts = async (keyword = '') => {
|
setLoading(true);
|
global.setSpinning(true);
|
try {
|
const params = {
|
// current: pagination.current,
|
// pageSize: pagination.pageSize,
|
// plaintiffs: keyword.trim(), // 传递搜索关键词 - 旧逻辑
|
page:1,
|
size:10,
|
sortColmn:1,
|
sortType:2
|
};
|
// 当 keyword 有值时才添加 plaintiffs 参数
|
if (keyword && keyword.trim()) {
|
params.plaintiffs = keyword.trim();
|
}
|
const res = await pageQueryApi(params);
|
if (res.type) {
|
setDraftList(res.data?.content || []);
|
setTotal(res.data?.totalElements || 0);
|
// setPagination({ ...pagination, total: res.data?.total || 0 });
|
} else {
|
$$.infoError(res.message || '获取草稿列表失败', 'error');
|
}
|
} catch (error) {
|
$$.infoError('获取草稿列表异常');
|
} finally {
|
setLoading(false);
|
global.setSpinning(false);
|
}
|
};
|
|
// 初始化加载数据
|
useEffect(() => {
|
fetchDrafts();
|
}, []); // 移除 pagination 依赖,简化为初始化加载
|
|
// 处理搜索
|
const handleSearch = () => {
|
// setPagination({ ...pagination, current: 1 }); // 重置到第一页
|
fetchDrafts(searchKeyword);
|
};
|
|
// 处理删除
|
const handleDelete = (item) => {
|
Modal.confirm({
|
title: '确认删除',
|
content: '您确定要删除此草稿吗?删除后不可恢复。',
|
okText: '确认',
|
cancelText: '取消',
|
onOk: async () => {
|
global.setSpinning(true);
|
try {
|
const res = await deleteDraftApi(item.id); // 假设item有id字段
|
if (res.success) {
|
$$.infoSuccess('删除成功', 'success');
|
fetchDrafts(searchKeyword); // 刷新列表
|
} else {
|
$$.infoError(res.message || '删除失败', 'error');
|
}
|
} catch (error) {
|
console.error('删除草稿失败:', error);
|
$$.infoError('删除草稿异常', 'error');
|
} finally {
|
global.setSpinning(false);
|
}
|
},
|
});
|
};
|
|
// 处理修改
|
const handleModify = (item) => {
|
// 跳转到编辑页面,传递草稿ID或其他必要信息
|
// history.push(`/gzdyh/editDraft/${item.id}`); // 假设有编辑页路由
|
console.log('跳转修改:', item);
|
$$.infoSuccess('修改功能待实现', 'info');
|
};
|
|
// 渲染列表项
|
const renderItem = (item) => (
|
<List.Item className="draft-item">
|
<div className="draft-item-content">
|
<div className="draft-item-title">{item.plaintiffs+','+item.defendants || '未知申请方'}</div>
|
<div className="draft-item-tags">
|
{!item.tags && <Tag className="draft-item-tag">{item.caseTypeFirstName}/{item.caseTypeName}</Tag>}
|
</div>
|
<div className="draft-item-bottom">
|
<div className="draft-item-time">保存时间:{$$.timeFormat(item.updateTime)}</div>
|
<div className="draft-item-actions">
|
<Button className="draft-item-delete-btn" onClick={() => handleDelete(item)}>删除</Button>
|
<Button type="primary" className="draft-item-modify-btn" onClick={() => handleModify(item)}>修改</Button>
|
</div>
|
</div>
|
</div>
|
</List.Item>
|
);
|
|
return (
|
<div className="draft-box">
|
<NavBarPage title="草稿箱" leftContentVisible={true} className="draft-box-navbar">
|
<div className="draft-box-search">
|
<div className="search-inner-container">
|
<Input
|
placeholder="申请方/被申请方姓名"
|
prefix={<SearchOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
|
value={searchKeyword}
|
onChange={(e) => setSearchKeyword(e.target.value)}
|
onPressEnter={handleSearch} // 支持回车搜索
|
className="search-input"
|
/>
|
<Button type="primary" onClick={handleSearch} className="search-button">查询</Button>
|
</div>
|
</div>
|
|
<div className="draft-box-summary">
|
共<span className="summary-total">{total}</span>条记录
|
</div>
|
|
<List
|
className="draft-box-list"
|
loading={loading}
|
itemLayout="horizontal"
|
dataSource={draftList}
|
renderItem={renderItem}
|
// 可以添加分页组件 <Pagination {...pagination} onChange={(page, pageSize) => setPagination({ ...pagination, current: page, pageSize })} />
|
locale={{ emptyText: '暂无草稿' }}
|
/>
|
{draftList.length > 0 && (
|
<div className="draft-box-footer">已加载全部</div>
|
)}
|
</NavBarPage>
|
</div>
|
);
|
};
|
|
export default DraftBox;
|