海口龙华志愿者后端管理页面
zhouxiantao
8 days ago 4def10e6567cf651ae333a2a65c497e717c06403
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
import React, { useState, useEffect, useCallback } from 'react';
import { Table, Card, Input, Button, Space, Row, Col, Form, message, Spin } from 'antd';
import { SearchOutlined, DownloadOutlined } from '@ant-design/icons';
import { userAPI } from '../../services/api';
 
 
const VolunteerPoints = () => {
  const [searchForm] = Form.useForm();
  const [volunteerPoints, setVolunteerPoints] = useState([]);
  const [loading, setLoading] = useState(false);
  const [pagination, setPagination] = useState({
    current: 1,
    pageSize: 10,
    total: 0,
  });
  const [filters, setFilters] = useState({});
 
  const columns = [
    {
      title: '志愿者姓名',
      dataIndex: 'name',
      key: 'name',
    },
    {
      title: '手机号',
      dataIndex: 'phone',
      key: 'phone',
    },
    {
      title: '总积分',
      dataIndex: 'totalPoints',
      key: 'totalPoints',
      render: (points) => <span style={{ color: '#52c41a', fontWeight: 'bold' }}>{points || 0}</span>,
    },
    {
      title: '获得积分',
      dataIndex: 'points',
      key: 'points',
      render: (points) => <span style={{ color: '#1890ff' }}>+{points || 0}</span>,
    },
    {
      title: '使用积分',
      dataIndex: 'redeemedPoints',
      key: 'redeemedPoints',
      render: (points) => <span style={{ color: '#ff4d4f' }}>-{points || 0}</span>,
    },
  ];
 
  // 获取积分数据
  const fetchPointsData = useCallback(async (params = {}) => {
    try {
      setLoading(true);
      const queryParams = {
        page: pagination.current,
        size: pagination.pageSize,
        ...filters,
        ...params,
      };
      
      const response = await userAPI.getUserList(queryParams);
      if (response.code === 0) {
        setVolunteerPoints(response.data.content || []);
        setPagination(prev => ({
          ...prev,
          total: response.data.totalElements || 0,
        }));
      }
    } catch (error) {
      console.error('获取积分数据失败:', error);
      message.error('获取积分数据失败');
    } finally {
      setLoading(false);
    }
  }, [pagination.current, pagination.pageSize, filters]);
 
  // 页面初始化加载数据
  useEffect(() => {
    fetchPointsData();
  }, [fetchPointsData]);
 
  const handleSearch = (values) => {
    setFilters(values);
    setPagination(prev => ({ ...prev, current: 1 }));
    fetchPointsData({ ...values, page: 1 });
  };
 
  const handleReset = () => {
    searchForm.resetFields();
    setFilters({});
    setPagination(prev => ({ ...prev, current: 1 }));
    fetchPointsData({ page: 1 });
  };
 
  // 处理分页变化
  const handleTableChange = (paginationInfo) => {
    setPagination(prev => ({
      ...prev,
      current: paginationInfo.current,
      pageSize: paginationInfo.pageSize,
    }));
    fetchPointsData({
      page: paginationInfo.current,
      size: paginationInfo.pageSize,
    });
  };
 
  const handleExport = () => {
    console.log('导出数据');
  };
 
  return (
    <div>
      <div className="page-header">
        <h1 className="page-title">积分查询</h1>
        <p className="page-description">查询志愿者积分情况,支持导出数据</p>
      </div>
 
      <Card className="search-form">
        <Form
          form={searchForm}
          layout="inline"
          onFinish={handleSearch}
        >
          <Row gutter={[16, 16]} style={{ width: '100%' }} align="middle">
            <Col xs={24} sm={12} md={6}>
              <Form.Item name="name" label="姓名">
                <Input placeholder="请输入姓名" />
              </Form.Item>
            </Col>
            <Col xs={24} sm={12} md={6}>
              <Form.Item name="phone" label="手机号">
                <Input placeholder="请输入手机号" />
              </Form.Item>
            </Col>
            <Col xs={24} sm={12} md={12}>
              <Space>
                <Button type="primary" htmlType="submit" icon={<SearchOutlined />}>
                  搜索
                </Button>
                <Button onClick={handleReset}>
                  重置
                </Button>
                <Button icon={<DownloadOutlined />} onClick={handleExport}>
                  导出
                </Button>
              </Space>
            </Col>
          </Row>
        </Form>
      </Card>
 
      <Card>
        <Table
          columns={columns}
          dataSource={volunteerPoints}
          rowKey="id"
          loading={loading}
          pagination={{
            ...pagination,
            showSizeChanger: true,
            showQuickJumper: true,
            showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
          }}
          onChange={handleTableChange}
        />
      </Card>
    </div>
  );
};
 
export default VolunteerPoints;