WXL (wul)
5 天以前 fb34ba28cb908bd328cf6690ab0b19a56428f4e2
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<template>
  <div class="followup-patient" v-loading="loading">
    <div class="patient-header">
      <div class="patient-title">
        <span>患者随访信息表单</span>
        <el-tag type="success" size="mini" disable-transitions
          >已完成</el-tag
        >
        <el-tag type="info" size="mini" disable-transitions>{{
          visitLabel
        }}</el-tag>
      </div>
      <div class="patient-header-right">
        <span class="patient-meta">
          {{ meta.dateRangeText || "出院时间:全部" }} 共
          <b>{{ total }}</b> 条
        </span>
        <el-button
          type="warning"
          plain
          size="mini"
          icon="el-icon-download"
          :disabled="!total"
          @click="exportExcel"
          >导出</el-button
        >
      </div>
    </div>
 
    <el-table
      :data="pagedRows"
      border
      size="small"
      empty-text="暂无随访患者数据"
      :header-cell-style="{
        background: '#f8f9fa',
        color: '#333',
        fontWeight: 600,
      }"
    >
      <el-table-column
        prop="sendname"
        label="姓名"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="telcode"
        label="联系电话"
        width="115"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="taskName"
        label="任务名称"
        width="170"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="任务状态" width="110" align="center">
        <template slot-scope="scope">
          <el-tag
            :type="stateTagType(scope.row.sendstate)"
            size="small"
            disable-transitions
            >{{ stateText(scope.row.sendstate) }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="任务执行方式" width="150" align="center">
        <template slot-scope="scope">
          {{ preachformText(scope.row.preachform) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="visitTime"
        label="应随访时间"
        width="165"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="随访完成时间" width="165" align="center">
        <template slot-scope="scope">
          {{ dateTime(scope.row.finishtime) }}
        </template>
      </el-table-column>
      <el-table-column label="出院日期" width="120" align="center">
        <template slot-scope="scope">
          {{ dateOnly(scope.row.endtime) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="nurseName"
        label="责任护士"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="drname"
        label="主治医生"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="结果状态" width="120" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="(dict.type && dict.type.sys_yujing) || []"
            :value="scope.row.excep"
          />
        </template>
      </el-table-column>
      <el-table-column label="处理意见" width="120" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="(dict.type && dict.type.sys_suggest) || []"
            :value="scope.row.suggest"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="templatename"
        label="服务模板"
        width="170"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="remark"
        label="服务记录"
        width="180"
        align="center"
        show-overflow-tooltip
      />
    </el-table>
 
    <div class="patient-pagination" v-if="total > pageSize">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next"
        :current-page="pageNum"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100]"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      />
    </div>
  </div>
</template>
 
<script>
import ExcelJS from "exceljs";
import { saveAs } from "file-saver";
 
export default {
  name: "FollowupPatientTable",
  dicts: ["sys_yujing", "sys_suggest"],
  props: {
    rows: {
      type: Array,
      default: () => [],
    },
    loading: {
      type: Boolean,
      default: false,
    },
    meta: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 20,
    };
  },
  computed: {
    total() {
      return (this.rows || []).length;
    },
    pagedRows() {
      const start = (this.pageNum - 1) * this.pageSize;
      return (this.rows || []).slice(start, start + this.pageSize);
    },
    visitLabel() {
      return this.meta.visitCount === 2 ? "再次随访" : "首次随访";
    },
  },
  watch: {
    rows() {
      this.pageNum = 1;
    },
  },
  methods: {
    handleSizeChange(size) {
      this.pageSize = size;
      this.pageNum = 1;
    },
    handlePageChange(page) {
      this.pageNum = page;
    },
    dateTime(value) {
      return value ? this.parseTime(value) : "";
    },
    dateOnly(value) {
      return value ? this.formatTime(value) : "";
    },
    stateTagType(state) {
      const map = {
        1: "primary",
        2: "primary",
        3: "success",
        4: "info",
        5: "danger",
        6: "success",
        7: "danger",
      };
      return map[state] || "info";
    },
    stateText(state) {
      const map = {
        1: "表单已领取",
        2: "待随访",
        3: "表单已发送",
        4: "不执行",
        5: "发送失败",
        6: "已完成",
        7: "超时",
      };
      return map[state] || "未知状态";
    },
    preachformText(value) {
      if (!value) return "";
      const values = Array.isArray(value)
        ? value
        : String(value).split(",");
      const options = this.$store.getters.checkboxlist || [];
 
      return values
        .map((val) => {
          const found = options.find((item) => item.value == val);
          return found ? found.label : val;
        })
        .filter(Boolean)
        .join("、");
    },
    dictLabel(type, value) {
      const options = (this.dict && this.dict.type && this.dict.type[type]) || [];
      const found = options.find((item) => item.value == value);
      return found ? found.label : value || "";
    },
    fileDate() {
      const now = new Date();
      const pad = (val) => String(val).padStart(2, "0");
      return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(
        now.getDate()
      )}`;
    },
    async exportExcel() {
      if (!this.total) {
        this.$message.warning("暂无可导出的数据");
        return;
      }
 
      try {
        const workbook = new ExcelJS.Workbook();
        const worksheet = workbook.addWorksheet("患者随访信息表单");
        const headers = [
          "姓名",
          "联系电话",
          "任务名称",
          "任务状态",
          "任务执行方式",
          "应随访时间",
          "随访完成时间",
          "出院日期",
          "责任护士",
          "主治医生",
          "结果状态",
          "处理意见",
          "服务模板",
          "服务记录",
        ];
        const colCount = headers.length;
        const border = {
          top: { style: "thin", color: { argb: "FFD0D0D0" } },
          left: { style: "thin", color: { argb: "FFD0D0D0" } },
          bottom: { style: "thin", color: { argb: "FFD0D0D0" } },
          right: { style: "thin", color: { argb: "FFD0D0D0" } },
        };
 
        worksheet.mergeCells(1, 1, 1, colCount);
        const titleCell = worksheet.getCell(1, 1);
        titleCell.value = `患者随访信息表单(${this.visitLabel})`;
        titleCell.font = { size: 14, bold: true };
        titleCell.alignment = { horizontal: "center", vertical: "middle" };
        worksheet.getRow(1).height = 30;
 
        worksheet.mergeCells(2, 1, 2, colCount);
        const metaCell = worksheet.getCell(2, 1);
        metaCell.value = `时间:${
          this.meta.dateRangeText || "全部"
        }    共 ${this.total} 条`;
        metaCell.alignment = { horizontal: "left", vertical: "middle" };
        worksheet.getRow(2).height = 22;
 
        const headerRow = worksheet.addRow(headers);
        headerRow.height = 24;
        headerRow.eachCell((cell) => {
          cell.font = { bold: true };
          cell.fill = {
            type: "pattern",
            pattern: "solid",
            fgColor: { argb: "FFF5F7FA" },
          };
          cell.border = border;
          cell.alignment = { horizontal: "center", vertical: "middle" };
        });
 
        (this.rows || []).forEach((row) => {
          const dataRow = worksheet.addRow([
            row.sendname || "",
            row.telcode || "",
            row.taskName || "",
            this.stateText(row.sendstate),
            this.preachformText(row.preachform),
            row.visitTime || "",
            row.finishtime ? this.parseTime(row.finishtime) : "",
            row.endtime ? this.formatTime(row.endtime) : "",
            row.nurseName || "",
            row.drname || "",
            this.dictLabel("sys_yujing", row.excep),
            this.dictLabel("sys_suggest", row.suggest),
            row.templatename || "",
            row.remark || "",
          ]);
          dataRow.height = 22;
          dataRow.eachCell((cell) => {
            cell.border = border;
            cell.alignment = {
              horizontal: "center",
              vertical: "middle",
              wrapText: true,
            };
          });
        });
 
        worksheet.columns = [
          { width: 12 },
          { width: 15 },
          { width: 28 },
          { width: 12 },
          { width: 20 },
          { width: 20 },
          { width: 20 },
          { width: 14 },
          { width: 12 },
          { width: 12 },
          { width: 12 },
          { width: 12 },
          { width: 28 },
          { width: 30 },
        ];
 
        const buffer = await workbook.xlsx.writeBuffer();
        const blob = new Blob([buffer], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        });
        saveAs(
          blob,
          `患者随访信息表单_${this.visitLabel}_${this.fileDate()}.xlsx`
        );
        this.$message.success("导出成功");
      } catch (error) {
        console.error("导出患者随访信息表单失败:", error);
        this.$message.error("导出失败");
      }
    },
  },
};
</script>
 
<style lang="scss" scoped>
.followup-patient {
  padding: 4px 0 8px;
  min-height: 240px;
 
  .patient-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
  }
 
  .patient-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #303133;
  }
 
  .patient-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
  }
 
  .patient-meta {
    font-size: 13px;
    color: #606266;
 
    b {
      color: #303133;
    }
  }
 
  .patient-pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
  }
 
  ::v-deep .el-table th {
    background-color: #f8f9fa;
  }
}
</style>