广州矛调粤政易端
xusd
7 days ago d27794814b69d18aeb8ee96a46cae91d5613570c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * @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;