WXL
2025-12-30 e2eb5acfb3961315df21abfe6f33a959699b562b
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// 模拟器官分配数据
const mockOrganAllocationData = [
  {
    id: 1,
    hospitalNo: "D202512001",
    caseNo: "C202512001",
    donorName: "张三",
    gender: "2",
    age: 45,
    birthDate: "1978-05-15",
    diagnosis: "脑外伤",
    allocationStatus: "allocated",
    allocationTime: "2025-12-01 16:30:00",
    registrant: "李协调员",
    registrationTime: "2025-12-01 15:00:00",
    createTime: "2025-12-01 10:00:00"
  },
  {
    id: 2,
    hospitalNo: "D202512002",
    caseNo: "C202512002",
    donorName: "李四",
    gender: "1",
    age: 38,
    birthDate: "1985-08-22",
    diagnosis: "心脏骤停",
    allocationStatus: "allocated",
    allocationTime: "2025-12-02 11:20:00",
    registrant: "张协调员",
    registrationTime: "2025-12-02 10:00:00",
    createTime: "2025-12-02 08:30:00"
  },
  {
    id: 3,
    hospitalNo: "D202512003",
    caseNo: "C202512003",
    donorName: "王五",
    gender: "2",
    age: 52,
    birthDate: "1971-03-10",
    diagnosis: "脑梗死",
    allocationStatus: "pending",
    allocationTime: "",
    registrant: "赵协调员",
    registrationTime: "2025-12-03 17:20:00",
    createTime: "2025-12-03 14:00:00"
  }
];
 
// 模拟器官分配记录数据
const mockAllocationRecordData = [
  {
    id: 1,
    allocationId: 1,
    organName: "肝脏",
    organNo: "L001",
    caseNo: "C202512001",
    systemNo: "AL202512001",
    applicantTime: "2025-12-01 17:00:00",
    recipientName: "王",
    transplantHospitalNo: "H1001",
    transplantHospitalName: "北京协和医院",
    reallocationReason: "",
    organState: 1
  },
  {
    id: 2,
    allocationId: 1,
    organName: "肾脏",
    organNo: "K001",
    caseNo: "C202512001",
    systemNo: "AL202512002",
    applicantTime: "2025-12-01 17:30:00",
    recipientName: "李",
    transplantHospitalNo: "H1002",
    transplantHospitalName: "上海瑞金医院",
    reallocationReason: "",
    organState: 1
  },
  {
    id: 3,
    allocationId: 1,
    organName: "心脏",
    organNo: "H001",
    caseNo: "C202512001",
    systemNo: "AL202512003",
    applicantTime: "2025-12-01 18:00:00",
    recipientName: "张",
    transplantHospitalNo: "H1003",
    transplantHospitalName: "广州中山医院",
    reallocationReason: "",
    organState: 1
  }
];
 
// 模拟医院数据
const mockHospitalData = [
  { id: 1, hospitalNo: "H1001", hospitalName: "北京协和医院", type: "4" },
  { id: 2, hospitalNo: "H1002", hospitalName: "上海瑞金医院", type: "4" },
  { id: 3, hospitalNo: "H1003", hospitalName: "广州中山医院", type: "4" },
  { id: 4, hospitalNo: "H1004", hospitalName: "武汉同济医院", type: "4" },
  { id: 5, hospitalNo: "H1005", hospitalName: "成都华西医院", type: "4" }
];
 
// 模拟器官类型字典
const mockOrganDict = [
  { value: "L001", label: "肝脏" },
  { value: "K001", label: "肾脏" },
  { value: "H001", label: "心脏" },
  { value: "L002", label: "肺脏" },
  { value: "P001", label: "胰腺" },
  { value: "I001", label: "小肠" },
  { value: "C001", label: "角膜" }
];
 
// 模拟API响应延迟
const delay = (ms = 500) => new Promise(resolve => setTimeout(resolve, ms));
 
// 查询器官分配列表
export const listOrganAllocation = async (queryParams = {}) => {
  await delay();
 
  const {
    pageNum = 1,
    pageSize = 10,
    hospitalNo,
    donorName,
    allocationStatus
  } = queryParams;
 
  // 过滤数据
  let filteredData = mockOrganAllocationData.filter(item => {
    let match = true;
 
    if (hospitalNo && !item.hospitalNo.includes(hospitalNo)) {
      match = false;
    }
 
    if (donorName && !item.donorName.includes(donorName)) {
      match = false;
    }
 
    if (allocationStatus && item.allocationStatus !== allocationStatus) {
      match = false;
    }
 
    return match;
  });
 
  // 分页
  const startIndex = (pageNum - 1) * pageSize;
  const endIndex = startIndex + parseInt(pageSize);
  const paginatedData = filteredData.slice(startIndex, endIndex);
 
  return {
    code: 200,
    message: "success",
    data: {
      rows: paginatedData,
      total: filteredData.length,
      pageNum: parseInt(pageNum),
      pageSize: parseInt(pageSize)
    }
  };
};
 
// 获取器官分配详细信息
export const getOrganAllocationDetail = async (id) => {
  await delay();
 
  const detail = mockOrganAllocationData.find(item => item.id == id);
 
  if (detail) {
    // 获取分配记录
    const allocationRecords = mockAllocationRecordData.filter(item => item.allocationId == id);
 
    return {
      code: 200,
      message: "success",
      data: {
        ...detail,
        allocationRecords
      }
    };
  } else {
    return {
      code: 404,
      message: "器官分配记录不存在"
    };
  }
};
 
// 新增器官分配
export const addOrganAllocation = async (data) => {
  await delay();
 
  const newId = Math.max(...mockOrganAllocationData.map(item => item.id), 0) + 1;
  const hospitalNo = `D${new Date().getFullYear()}${String(new Date().getMonth() + 1).padStart(2, '0')}${String(newId).padStart(3, '0')}`;
  const caseNo = `C${new Date().getFullYear()}${String(new Date().getMonth() + 1).padStart(2, '0')}${String(newId).padStart(3, '0')}`;
 
  const newRecord = {
    ...data,
    id: newId,
    hospitalNo,
    caseNo,
    registrationTime: new Date().toISOString().replace('T', ' ').substring(0, 19),
    createTime: new Date().toISOString().replace('T', ' ').substring(0, 19)
  };
 
  mockOrganAllocationData.unshift(newRecord);
 
  return {
    code: 200,
    message: "新增成功",
    data: newRecord
  };
};
 
// 修改器官分配
export const updateOrganAllocation = async (data) => {
  await delay();
 
  const index = mockOrganAllocationData.findIndex(item => item.id == data.id);
 
  if (index !== -1) {
    mockOrganAllocationData[index] = {
      ...mockOrganAllocationData[index],
      ...data,
      updateTime: new Date().toISOString().replace('T', ' ').substring(0, 19)
    };
 
    return {
      code: 200,
      message: "修改成功",
      data: mockOrganAllocationData[index]
    };
  } else {
    return {
      code: 404,
      message: "器官分配记录不存在"
    };
  }
};
 
// 删除器官分配
export const delOrganAllocation = async (ids) => {
  await delay();
 
  const idArray = Array.isArray(ids) ? ids : [ids];
 
  idArray.forEach(id => {
    const index = mockOrganAllocationData.findIndex(item => item.id == id);
    if (index !== -1) {
      mockOrganAllocationData.splice(index, 1);
    }
  });
 
  return {
    code: 200,
    message: "删除成功"
  };
};
 
// 保存器官分配记录
export const saveAllocationRecords = async (allocationId, records) => {
  await delay();
 
  // 删除该分配ID的所有记录
  const existingIndexes = [];
  mockAllocationRecordData.forEach((item, index) => {
    if (item.allocationId == allocationId) {
      existingIndexes.push(index);
    }
  });
 
  // 从后往前删除避免索引问题
  existingIndexes.reverse().forEach(index => {
    mockAllocationRecordData.splice(index, 1);
  });
 
  // 添加新记录
  records.forEach(record => {
    const newId = Math.max(...mockAllocationRecordData.map(item => item.id), 0) + 1;
    mockAllocationRecordData.push({
      ...record,
      id: newId,
      allocationId: allocationId
    });
  });
 
  return {
    code: 200,
    message: "保存成功",
    data: records
  };
};
 
// 获取医院列表
export const getHospitalList = async () => {
  await delay();
 
  return {
    code: 200,
    message: "success",
    data: mockHospitalData
  };
};
 
// 获取器官字典
export const getOrganDict = async () => {
  await delay();
 
  return {
    code: 200,
    message: "success",
    data: mockOrganDict
  };
};
 
export default {
  listOrganAllocation,
  getOrganAllocationDetail,
  addOrganAllocation,
  updateOrganAllocation,
  delOrganAllocation,
  saveAllocationRecords,
  getHospitalList,
  getOrganDict
};