WXL (wul)
20 小时以前 bb0a72311792bb57e1e90668c00f1c077d9f1761
src/views/patient/patient/hospital.vue
@@ -128,7 +128,7 @@
    :disabled="multiple"
    @click="handleBatchAddTask"
  >
    批量添加任务
              添加延续护理任务
  </el-button>
</el-col>
          <el-col :span="1.5">
@@ -337,7 +337,7 @@
    </el-row>
<!-- 批量添加任务弹窗 -->
<el-dialog
  title="批量添加任务"
      title="批量添加延续护理"
  :visible.sync="batchTaskVisible"
  width="90%"
  append-to-body
@@ -554,7 +554,7 @@
import Treeselect from "@riophae/vue-treeselect";
import { listDept } from "@/api/system/dept";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { query360PatInfo } from "@/api/AiCentre/index";
import { query360PatInfo, getTasklist, addSubtask } from "@/api/AiCentre/index";
import store from "@/store";
@@ -793,6 +793,144 @@
          this.$modal.msgWarning("360查询无结果");
        }
      });
    },
    /** 批量添加任务按钮点击 */
    handleBatchAddTask() {
      // 校验是否选中患者
      if (this.ids.length === 0) {
        this.$modal.msgWarning("请至少选中1名患者");
        return;
      }
      // 获取选中患者的科室信息
      const patientDepts = new Set();
      let deptcode = "";
      this.ids.forEach((patId) => {
        const patient = this.userList.find((item) => item.patid === patId);
        if (patient) {
          patientDepts.add(patient.deptname);
          deptcode = patient.deptcode;
        }
      });
      // 获取选中患者列表
      this.selectedPatients = this.userList.filter((item) =>
        this.ids.includes(item.patid)
      );
      // 显示弹窗
      this.batchTaskVisible = true;
      // 获取任务列表
      this.loadTaskList(deptcode);
    },
    /** 加载任务列表 */
    loadTaskList(deptcode) {
      this.batchLoading = true;
      let topqueryParams = {
        pageNum: 1,
        pageSize: 100, // 设置较大的分页获取更多任务
        type: 2, // 根据实际情况调整
      };
      getTasklist(topqueryParams)
        .then((response) => {
          this.taskList = response.rows;
          this.batchLoading = false;
          if (this.taskList.length === 0) {
            this.$modal.msgWarning("当前科室无可用任务");
          }
        })
        .catch((error) => {
          this.$modal.msgError("获取任务列表失败:" + error.message);
          this.batchLoading = false;
        });
    },
    /** 处理任务选择变化 */
    handleTaskSelectionChange(currentRow) {
      this.selectedTask = currentRow;
    },
    /** 批量提交任务 */
    async submitBatchTask() {
      // 校验是否选中任务
      if (!this.selectedTask) {
        this.$modal.msgWarning("请选择1个任务");
        return;
      }
      this.batchLoading = true;
      const successPatients = [];
      const failedPatients = [];
      const errorMessages = [];
      try {
        // 遍历选中的患者,逐个调用接口
        for (const patient of this.selectedPatients) {
          const params = {
            taskid: this.selectedTask.taskid,
            type: this.selectedTask.type,
            taskName: this.selectedTask.taskName,
            serviceType: this.selectedTask.serviceType,
            preachform: this.selectedTask.preachform,
            templateid: this.selectedTask.templateid,
            libtemplateid: this.selectedTask.libtemplateid,
            sendstate: 2,
            ...patient,
            sendname: patient.patname,
            endtime: patient.endtime ? patient.endtime + " 00:00:00" : "",
            leavediagname: patient.leavediagname || patient.diagname || "",
            age: patient.age || "",
          };
          try {
            const response = await addSubtask(params);
            if (response.code === 200) {
              successPatients.push(patient.patname);
            } else {
              failedPatients.push(patient.patname);
              errorMessages.push(
                `${patient.patname}: ${response.msg || "添加失败"}`
              );
            }
          } catch (error) {
            failedPatients.push(patient.patname);
            errorMessages.push(
              `${patient.patname}: ${error.message || "网络错误"}`
            );
          }
        }
        // 显示处理结果
        if (failedPatients.length === 0) {
          this.$modal.msgSuccess(
            `成功为 ${successPatients.length} 名患者添加任务`
          );
        } else {
          this.$modal.msgWarning(
            `成功添加 ${successPatients.length} 人,失败 ${failedPatients.length} 人。` +
              (errorMessages.length > 0
                ? `失败原因:${errorMessages.join("; ")}`
                : "")
          );
        }
        this.batchTaskVisible = false;
        this.getList(); // 刷新患者列表
      } catch (error) {
        this.$modal.msgError("批量添加任务过程中出错:" + error.message);
      } finally {
        this.batchLoading = false;
      }
    },
    /** 格式化时间 */
    formatTime(time) {
      if (!time) return "";
      return time;
    },
    /** 查询标签列表 */
    gettabList() {
@@ -1074,6 +1212,43 @@
  }
}
.button-textsc {
  color: #3664D9;
  color: #3664d9;
}
// 批量任务弹窗样式
.batch-patient-section,
.batch-task-section {
  h4 {
    margin: 0 0 10px 0;
    color: #606266;
    font-size: 16px;
  }
}
.empty-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  color: #909399;
  i {
    font-size: 24px;
    margin-bottom: 8px;
  }
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 20px;
  border-top: 1px solid #ebeef5;
}
// 响应式调整
@media screen and (max-width: 1200px) {
  .batch-patient-section,
  .batch-task-section {
    margin-bottom: 20px;
  }
}
</style>