WXL
5 天以前 475a352a4bfd7ac3a81e8c7c92d3bb64e2e01037
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
<template>
  <div>
    <!-- 终止确认弹框 -->
    <el-dialog
      :title="terminateTitle"
      :visible.sync="terminateVisible"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
      @close="handleTerminateClose"
    >
      <div class="patient-info">
        <el-alert
          :title="
            `当前操作患者:${currentRecord.name} (${currentRecord.idcardno ||
              '无证件号'})`
          "
          type="info"
          :closable="false"
          show-icon
        />
      </div>
 
      <el-form
        :model="terminateForm"
        :rules="terminateRules"
        ref="terminateFormRef"
        label-width="100px"
        class="terminate-form"
      >
        <el-form-item label="终止类型" prop="terminationType">
          <el-select
            v-model="terminateForm.terminationType"
            placeholder="请选择终止类型"
            style="width: 100%;"
          >
            <el-option
              v-for="item in terminationTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
 
        <el-form-item label="详细原因" prop="terminationResult">
          <el-input
            v-model="terminateForm.terminationResult"
            type="textarea"
            :rows="3"
            placeholder="请输入终止的详细原因"
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
 
        <el-form-item label="二次确认" prop="confirmText">
          <el-input
            v-model="terminateForm.confirmText"
            placeholder="请输入'确认终止'以完成操作"
            @input="handleConfirmTextChange"
          />
        </el-form-item>
      </el-form>
 
      <div slot="footer">
        <el-button @click="handleTerminateClose" :disabled="terminateLoading"
          >取消</el-button
        >
        <el-button
          type="danger"
          :disabled="!canSubmitTerminate"
          @click="handleTerminateSubmit"
          :loading="terminateLoading"
        >
          确认终止
        </el-button>
      </div>
    </el-dialog>
 
    <!-- 恢复确认弹框 -->
    <el-dialog
      :title="restoreTitle"
      :visible.sync="restoreVisible"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
    >
      <div class="patient-info">
        <el-alert
          :title="
            `当前操作患者:${currentRecord.name} (${currentRecord.idcardno ||
              '无证件号'})`
          "
          type="info"
          :closable="false"
          show-icon
        />
      </div>
 
      <div style="margin: 20px 0;">
        <p>
          确定要恢复捐献者
          <strong>{{ currentRecord.name }}</strong> 的捐献进程吗?
        </p>
        <p style="color: #67c23a; font-size: 12px; margin-top: 10px;">
          恢复后,该案例将重新进入捐献流程
        </p>
      </div>
      <div slot="footer">
        <el-button @click="restoreVisible = false" :disabled="restoreLoading"
          >取消</el-button
        >
        <el-button
          type="success"
          @click="handleRestoreSubmit"
          :loading="restoreLoading"
        >
          确认恢复
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { updateDonatebaseinfo } from "@/api/project/donatebaseinfo";
 
export default {
  name: "TerminateRestoreModal",
  props: {
    // 当前操作记录
    currentRecord: {
      type: Object,
      default: () => ({})
    },
    // 弹框显示状态
    visible: {
      type: Object,
      default: () => ({
        terminate: false,
        restore: false
      })
    },
    // 自定义标题
    titles: {
      type: Object,
      default: () => ({
        terminate: "终止捐献进程",
        restore: "恢复捐献进程"
      })
    }
  },
  data() {
    return {
      // 终止表单
      terminateForm: {
        terminationType: "",
        terminationResult: "",
        confirmText: ""
      },
      // 终止类型选项
      terminationTypes: [
        { label: "好转", value: "1" },
        { label: "死亡", value: "2" },
        { label: "不符合捐献进程", value: "3" },
        { label: "家属放弃捐献", value: "4" },
        { label: "其他", value: "5" }
      ],
      // 验证规则
      terminateRules: {
        terminationType: [
          { required: true, message: "请选择终止类型", trigger: "change" }
        ],
        terminationResult: [
          { required: true, message: "请输入终止原因", trigger: "blur" },
          { min: 5, message: "终止原因至少5个字符", trigger: "blur" }
        ]
      },
      // 加载状态
      terminateLoading: false,
      restoreLoading: false,
      // 控制提交
      canSubmitTerminate: false
    };
  },
  computed: {
    terminateVisible: {
      get() {
        return this.visible.terminate;
      },
      set(value) {
        this.$emit("update:visible", { ...this.visible, terminate: value });
      }
    },
    restoreVisible: {
      get() {
        return this.visible.restore;
      },
      set(value) {
        this.$emit("update:visible", { ...this.visible, restore: value });
      }
    },
    terminateTitle() {
      return this.titles.terminate;
    },
    restoreTitle() {
      return this.titles.restore;
    },
    // 患者信息显示
    patientInfo() {
      return `${this.currentRecord.name} (${this.currentRecord.idcardno ||
        "无证件号"})`;
    }
  },
  watch: {
    "visible.terminate": {
      handler(newVal) {
        if (newVal) {
          this.resetTerminateForm();
        }
      },
      immediate: true
    }
  },
  methods: {
    /** 重置终止表单 */
    resetTerminateForm() {
      this.terminateForm = {
        terminationType: "",
        terminationResult: "",
        confirmText: ""
      };
      this.canSubmitTerminate = false;
      this.terminateLoading = false;
 
      // 重置表单验证
      this.$nextTick(() => {
        if (this.$refs.terminateFormRef) {
          this.$refs.terminateFormRef.clearValidate();
        }
      });
    },
 
    /** 确认文本变化处理 */
    handleConfirmTextChange(value) {
      this.canSubmitTerminate = value === "确认终止";
    },
 
    /** 终止弹框关闭处理 */
    handleTerminateClose() {
      this.terminateVisible = false;
      this.resetTerminateForm();
    },
 
    /** 终止前的二次确认 */
    async confirmTermination() {
      try {
        await this.$confirm(
          `是否确认终止患者 ${this.patientInfo} 的捐献案例?此操作将终止该患者的捐献进程。`,
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
            closeOnClickModal: false,
            closeOnPressEscape: false
          }
        );
        return true;
      } catch (error) {
        console.log("用户取消终止操作");
        return false;
      }
    },
 
    /** 恢复前的二次确认 */
    async confirmRestoration() {
      try {
        await this.$confirm(
          `是否确认恢复患者 ${this.patientInfo} 的捐献案例?恢复后该案例将重新进入捐献流程。`,
          "确认恢复",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "info",
            closeOnClickModal: false,
            closeOnPressEscape: false
          }
        );
        return true;
      } catch (error) {
        console.log("用户取消恢复操作");
        return false;
      }
    },
 
    /** 提交终止 */
    async handleTerminateSubmit() {
      try {
        // 表单验证
        await this.$refs.terminateFormRef.validate();
 
        if (!this.canSubmitTerminate) {
          this.$message.warning('请输入"确认终止"完成验证');
          return;
        }
        console.log(66);
 
        // 二次确认
        const userConfirmed = await this.confirmTermination();
        if (!userConfirmed) {
          return;
        }
 
        this.terminateLoading = true;
 
        // 调用终止接口
        await updateDonatebaseinfo({
          id: this.currentRecord.id,
          caseNo: this.currentRecord.caseNo,
          terminationType: this.terminateForm.terminationType,
          terminationResult: this.terminateForm.terminationResult,
          terminationCase: 1
        });
 
        this.$message.success("终止成功");
        this.terminateVisible = false;
 
        // 通知父组件操作完成,需要刷新数据
        this.$emit("operation-success", {
          type: "terminate",
          record: this.currentRecord,
          terminationType: this.terminateForm.terminationType
        });
      } catch (error) {
        if (error instanceof Error) {
          this.$message.error("终止失败");
          console.error("终止错误:", error);
        }
        // 验证失败不显示错误消息
      } finally {
        this.terminateLoading = false;
      }
    },
 
    /** 提交恢复 */
    async handleRestoreSubmit() {
      try {
        // 二次确认
        const userConfirmed = await this.confirmRestoration();
        if (!userConfirmed) {
          return;
        }
 
        this.restoreLoading = true;
 
        // 调用恢复接口
        await updateDonatebaseinfo({
          id: this.currentRecord.id,
          caseNo: this.currentRecord.caseNo,
          terminationCase: 0
        });
 
        this.$message.success("恢复成功");
        this.restoreVisible = false;
 
        // 通知父组件操作完成,需要刷新数据
        this.$emit("operation-success", {
          type: "restore",
          record: this.currentRecord
        });
      } catch (error) {
        this.$message.error("恢复失败");
        console.error("恢复错误:", error);
      } finally {
        this.restoreLoading = false;
      }
    }
  }
};
</script>
 
<style scoped>
.patient-info {
  margin-bottom: 20px;
  font-size: 18px;
}
 
.terminate-form {
  margin-top: 15px;
}
 
/* 响应式调整 */
@media (max-width: 768px) {
  .patient-info ::v-deep .el-alert {
    padding: 8px 16px;
  }
 
  .terminate-form ::v-deep .el-form-item__label {
    width: 80px !important;
  }
 
  .terminate-form ::v-deep .el-form-item__content {
    margin-left: 80px !important;
  }
}
</style>