hejianhao
2026-08-18 9a69a69bd56762ba8a9ee495460d829709e44830
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import { history, useAccess } from '@umijs/max';
import { Button, Cascader, DatePicker, Form, Input, Pagination, Select, Space, Table, Upload, message } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import dayjs, { type Dayjs } from 'dayjs';
import React, { useEffect, useState } from 'react';
import { downloadBlob } from '../../trade/points-exchange/shared';
import { clinicRegionOptions } from './regionOptions';
import { downloadClinicImportTemplate, exportClinics, getClinicPage, importClinicAgentBindings } from './service';
import './style.less';
 
type SearchValues = {
  regionCode?: string[];
  name?: string;
  phone?: string;
  status?: number;
  createdRange?: Dayjs[];
};
 
type ClinicItem = {
  id: number;
  name: string;
  phone?: string;
  regionName?: string;
  status: number;
  userCount: number;
  createdAt: string;
  businessLicenseUrl?: string;
};
 
const getSelectedRegionCode = (regionCode?: string[]) =>
  regionCode && regionCode.length ? regionCode[regionCode.length - 1] : undefined;
 
const buildSearchParams = (values: SearchValues) => ({
  regionCode: getSelectedRegionCode(values.regionCode),
  name: values.name?.trim() || undefined,
  phone: values.phone?.trim() || undefined,
  status: values.status,
  createdFrom: values.createdRange?.[0]
    ? dayjs(values.createdRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
    : undefined,
  createdTo: values.createdRange?.[1]
    ? dayjs(values.createdRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
    : undefined,
});
 
const ClinicListPage: React.FC = () => {
  const access = useAccess();
  const [searchForm] = Form.useForm<SearchValues>();
  const [list, setList] = useState<ClinicItem[]>([]);
  const [loading, setLoading] = useState(false);
  const [templateDownloading, setTemplateDownloading] = useState(false);
  const [importing, setImporting] = useState(false);
  const [pagination, setPagination] = useState({ page: 1, pageSize: 10, total: 0 });
 
  const canView = access['member:clinic:view'];
 
  const loadList = async (page = pagination.page, pageSize = pagination.pageSize) => {
    setLoading(true);
    try {
      const res = await getClinicPage({
        page,
        pageSize,
        ...buildSearchParams(searchForm.getFieldsValue()),
      });
      setList(res.data?.list || []);
      setPagination({
        page: Number(res.data?.page || page),
        pageSize: Number(res.data?.pageSize || pageSize),
        total: Number(res.data?.total || 0),
      });
    } finally {
      setLoading(false);
    }
  };
 
  useEffect(() => {
    if (!canView) {
      history.replace('/Welcome');
      return;
    }
    loadList(1, 10);
  }, [canView]);
 
  const handleExport = async () => {
    const blob = await exportClinics(buildSearchParams(searchForm.getFieldsValue()));
    downloadBlob(blob, '诊所列表.xlsx');
  };
 
  const handleTemplateDownload = async () => {
    setTemplateDownloading(true);
    try {
      const blob = await downloadClinicImportTemplate();
      downloadBlob(blob, '诊所省区代理导入模板.xlsx');
    } finally {
      setTemplateDownloading(false);
    }
  };
 
  const handleBindingImport = async (file: File) => {
    setImporting(true);
    try {
      await importClinicAgentBindings(file);
      message.success('绑定关系更新成功');
      await loadList(pagination.page, pagination.pageSize);
    } catch (error) {
      message.error((error as Error)?.message || '更新绑定关系失败');
    } finally {
      setImporting(false);
    }
  };
  const columns: ColumnsType<ClinicItem> = [
    {
      title: '序号',
      width: 72,
      render: (_, __, index) => (pagination.page - 1) * pagination.pageSize + index + 1,
    },
    {
      title: '诊所名称',
      dataIndex: 'name',
      width: 200,
      render: (value) => value || '-',
    },
    {
      title: '电话',
      dataIndex: 'phone',
      width: 150,
      render: (value) => value || '-',
    },
    {
      title: '诊所区域',
      dataIndex: 'regionName',
      width: 180,
      render: (value) => value || '-',
    },
    {
      title: '绑定用户数',
      dataIndex: 'userCount',
      width: 120,
      render: (value) => <span className="member-clinic-table__count">{value ?? 0}</span>,
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 150,
      render: (value) => (value === 1 ? '启用' : value === 2 ? '注销' : '禁用'),
    },
    {
      title: '注册时间',
      dataIndex: 'createdAt',
      width: 180,
    },
    {
      title: '操作',
      width: 150,
      render: (_, record) => (
        <Space size={16} className="member-clinic-table__actions">
        <button
          type="button"
          className="member-clinic-table__action"
          onClick={() => history.push(`/member/user/clinic/${record.id}`)}
        >
          详情
        </button>
        {access["member:clinic:edit"] ? <button type="button" className="member-clinic-table__action" onClick={() => history.push(`/member/user/clinic/${record.id}/edit`)}>编辑</button> : null}
        </Space>
      ),
    },
  ];
 
  return (
    <div className="member-clinic-page">
      <div className="member-clinic-page__panel">
        <div className="member-clinic-page__title">诊所管理</div>
        <div className="member-clinic-search-card">
          <Form form={searchForm} layout="horizontal" className="member-clinic-search-form">
            <Form.Item label="诊所区域" name="regionCode">
              <Cascader
                placeholder="全部"
                allowClear
                changeOnSelect
                options={clinicRegionOptions}
              />
            </Form.Item>
            <Form.Item label="诊所名称" name="name">
              <Input placeholder="请输入" allowClear />
            </Form.Item>
            <Form.Item label="电话" name="phone">
              <Input placeholder="请输入" allowClear />
            </Form.Item>
            <Form.Item label="状态" name="status">
              <Select
                placeholder="请选择"
                allowClear
                options={[
                  { label: '启用', value: 1 },
                  { label: '禁用', value: 0 },
                ]}
              />
            </Form.Item>
            <Form.Item label="注册时间" name="createdRange">
              <DatePicker.RangePicker className="member-clinic-search-form__range" />
            </Form.Item>
            <div className="member-clinic-search-form__actions">
              <Button
                onClick={async () => {
                  searchForm.resetFields();
                  await loadList(1, pagination.pageSize);
                }}
              >
                重置
              </Button>
              <Button type="primary" onClick={() => loadList(1, pagination.pageSize)}>
                查询
              </Button>
            </div>
          </Form>
        </div>
 
        <div className="member-clinic-toolbar">
          <Button onClick={handleExport}>导出</Button>
          <Upload
            accept=".xlsx,.xls"
            showUploadList={false}
            beforeUpload={(file) => {
              void handleBindingImport(file);
              return false;
            }}
          >
            <Button loading={importing}>更新绑定关系</Button>
          </Upload>
          <Button loading={templateDownloading} onClick={handleTemplateDownload}>
            下载模板
          </Button>
        </div>
 
        <div className="member-clinic-table-card">
          <Table<ClinicItem>
            rowKey="id"
            columns={columns}
            dataSource={list}
            loading={loading}
            pagination={false}
            scroll={{ x: 1200 }}
          />
          <div className="member-clinic-pagination">
            <Pagination
              current={pagination.page}
              pageSize={pagination.pageSize}
              total={pagination.total}
              showSizeChanger
              showQuickJumper
              showTotal={(total) => `共 ${total} 条`}
              onChange={(page, pageSize) => loadList(page, pageSize)}
            />
          </div>
        </div>
      </div>
    </div>
  );
};
 
export default ClinicListPage;