liusheng
2 天以前 9903954c85f651dd5cc6d4b538cfe66b17fc5baa
src/views/followvisit/discharge/index.vue
@@ -5,6 +5,8 @@
      :ycvalue="ycvalue"
      :jgvalue="jgvalue"
      :show-warning-condition="orgname == '省立同德翠苑院区'"
      clickable
      @card-click="handleCardClick"
    />
    <el-row :gutter="20">
      <!--用户数据-->
@@ -92,10 +94,11 @@
            v-model="topqueryParams.scopetype"
            placeholder="默认全部"
            :options="sourcetype"
            :props="{ expandTrigger: 'hover' }"
            :props="{ expandTrigger: 'hover', multiple: true }"
            @change="handleChange"
            filterable
            clearable
            collapse-tags
          ></el-cascader>
        </el-form-item>
@@ -169,7 +172,7 @@
                plain
                icon="el-icon-warning-outline"
                size="medium"
                @click="toleadExport(1)"
                @click="toleadExport(1, 1)"
                >执行失败</el-button
              >
            </div>
@@ -183,7 +186,7 @@
                plain
                icon="el-icon-warning"
                size="medium"
                @click="toleadExport(2)"
                @click="toleadExport(2, 1)"
                >结果异常</el-button
              >
            </div>
@@ -242,7 +245,23 @@
            </div>
          </div>
        </el-col>
        <div class="color-legend">
          <span class="legend-item" v-if="orgname == '南华大学附属第一医院'">
            <span class="legend-block legend-blue"></span>未到随访时间
          </span>
          <span class="legend-item">
            <span class="legend-block legend-red"></span>填报内容存在异常
          </span>
          <span class="legend-item">
            <span class="legend-block legend-yellow"></span>填报内容存在警告
          </span>
        </div>
      </el-row>
      <div v-if="cardFilter" class="card-filter-tip">
        当前按顶部卡片筛选:<b>{{ cardFilter }}</b>
        <span class="tip-desc">(不影响上方表单条件,点「搜索」可恢复表单条件)</span>
        <el-button type="text" size="mini" @click="clearCardFilter">清除</el-button>
      </div>
      <div class="selected-info">
        已选中
        <span style="color: #409eff; font-weight: bold">{{
@@ -310,7 +329,55 @@
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          v-if="orgname == '浙江省新华医院'"
          label="任务状态"
          align="center"
          key="sendstate"
          prop="sendstate"
          width="120"
        >
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.remark"
              placement="top-start"
            >
              <div v-if="scope.row.sendstate == 1">
                <el-tag type="primary" :disable-transitions="false"
                  >表单已领取</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 2">
                <el-tag type="primary" :disable-transitions="false"
                  >待随访</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 3">
                <el-tag type="success" :disable-transitions="false"
                  >表单已发送</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 4">
                <el-tag type="info" :disable-transitions="false">不执行</el-tag>
              </div>
              <div v-if="scope.row.sendstate == 5">
                <el-tag type="danger" :disable-transitions="false"
                  >发送失败</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 6">
                <el-tag type="success" :disable-transitions="false"
                  >已完成</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 7">
                <el-tag type="danger" :disable-transitions="false">超时</el-tag>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          label="随访状态"
          align="center"
@@ -437,6 +504,20 @@
          prop="drname"
        />
        <el-table-column
          label="责任护士"
          width="120"
          align="center"
          key="nurseName"
          prop="nurseName"
        />
        <el-table-column
          label="经管医生"
          align="center"
          key="managementDoctor"
          prop="managementDoctor"
          width="120"
        />
        <el-table-column
          v-if="orgname != '丽水市中医院'"
          label="随访人员"
          align="center"
@@ -445,6 +526,7 @@
          width="120"
        />
        <el-table-column
          v-if="orgname != '浙江省新华医院'"
          label="任务状态"
          align="center"
          key="sendstate"
@@ -511,6 +593,29 @@
          prop="phone"
        />
        <el-table-column
          v-if="
            orgname == '景宁畲族自治县人民医院' ||
            orgname == '丽水市中医院'
          "
          label="拨号状态"
          width="120"
          align="center"
          key="isManuallyCalled"
          prop="isManuallyCalled"
        >
          <template slot-scope="scope">
            <el-tag
              v-if="Number(scope.row.isManuallyCalled) > 0"
              type="success"
              :disable-transitions="false"
              >拨通{{ scope.row.isManuallyCalled }}次</el-tag
            >
            <el-tag v-else type="info" :disable-transitions="false"
              >未拨通</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          label="身份证号码"
          width="200"
          align="center"
@@ -518,20 +623,6 @@
          prop="sfzh"
        />
        <el-table-column
          label="责任护士"
          width="120"
          align="center"
          key="nurseName"
          prop="nurseName"
        />
        <el-table-column
          label="经管医生"
          align="center"
          key="managementDoctor"
          prop="managementDoctor"
          width="120"
        />
        <!-- <el-table-column
          label="病历号"
          align="center"
@@ -547,8 +638,8 @@
        <el-table-column
          label="科室"
          align="center"
          key="deptname"
          prop="deptname"
          key="leaveldeptname"
          prop="leaveldeptname"
          width="120"
        >
        </el-table-column>
@@ -641,7 +732,7 @@
                size="medium"
                type="text"
                @click="handlestop(scope.row)"
                v-hasPermi="['system:user:edit']"
                ><span class="button-sc"
                  ><i class="el-icon-remove-outline"></i>暂停服务</span
                ></el-button
@@ -658,6 +749,15 @@
              @click="handleUpdate(scope.row)"
              ><span class="button-textxga"
                ><i class="el-icon-edit"></i>患者过滤</span
              ></el-button
            >
            <el-button
              size="medium"
              type="text"
              v-if="orgname == '南华大学附属第一医院'"
              @click="handleTransferOpen(scope.row)"
              ><span class="button-textxgc"
                ><i class="el-icon-sort"></i>变更科/区</span
              ></el-button
            >
          </template>
@@ -919,81 +1019,7 @@
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 修改发送时间对话框 -->
    <el-dialog
      title="发送时间设置"
      :visible.sync="modificationVisible"
      width="45%"
    >
      <div style="margin-bottom: 20px; color: red">
        统一修改当天未发送的任务时间
      </div>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-form-item label="发送日期">
          <el-date-picker
            v-model="ruleForm.value1"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="时间段" prop="type">
          <el-checkbox-group v-model="ruleForm.type">
            <el-checkbox label="上午" name="type"></el-checkbox>
            <el-checkbox label="下午" name="type"></el-checkbox>
            <el-checkbox label="晚上" name="type"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="上午时间区间" required>
          <el-time-picker
            is-range
            v-model="ruleForm.value2"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="选择时间范围"
          >
          </el-time-picker>
        </el-form-item>
        <el-form-item label="下午时间区间" required>
          <el-time-picker
            is-range
            v-model="ruleForm.value3"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="选择时间范围"
          >
          </el-time-picker>
        </el-form-item>
        <el-form-item label="晚上时间区间" required>
          <el-time-picker
            is-range
            v-model="ruleForm.value4"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="选择时间范围"
          >
          </el-time-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="modificationVisible = false">取 消</el-button>
        <el-button type="primary" @click="modificationVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 再次随访 -->
    <el-dialog title="患者再次随访" :visible.sync="dialogFormVisible">
      <el-form ref="zcform" :rules="zcrules" :model="zcform" label-width="80px">
@@ -1022,7 +1048,7 @@
          <el-input
            style="width: 400px"
            disabled
            v-model="zcform.deptname"
            v-model="zcform.leaveldeptname"
          ></el-input>
        </el-form-item>
        <el-form-item label="病区">
@@ -1066,6 +1092,57 @@
        <el-button type="primary" @click="setupsubtask">确认创建服务</el-button>
      </div>
    </el-dialog>
    <!-- 变更科室/病区弹窗 -->
    <el-dialog
      title="变更科室/病区"
      :visible.sync="transferDialogVisible"
      width="480px"
      :close-on-click-modal="false"
    >
      <el-form :model="transferForm" label-width="100px">
        <el-form-item label="当前科室">
          <span>{{ transferForm.currentDeptName || "-" }}</span>
        </el-form-item>
        <el-form-item label="当前病区">
          <span>{{ transferForm.currentWardName || "-" }}</span>
        </el-form-item>
        <el-form-item label="目标科室">
          <el-cascader
            v-model="transferDeptValue"
            :options="deptOptionsks"
            :props="cascaderPropsa"
            placeholder="请选择目标科室"
            filterable
            clearable
            style="width: 100%"
            @change="handleDeptCascaderChange"
          />
        </el-form-item>
        <el-form-item label="目标病区">
          <el-cascader
            v-model="transferWardValue"
            :options="deptOptionsbq"
            :props="cascaderPropsa"
            placeholder="请选择目标病区"
            filterable
            clearable
            style="width: 100%"
            @change="handleWardCascaderChange"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="transferDialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          :loading="transferLoading"
          @click="handleTransferSubmit"
        >
          确认变更
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
@@ -1076,6 +1153,7 @@
  updateUser,
  resetUserPwd,
  changeUserStatus,
  deptTreeSelect,
} from "@/api/system/user";
import {
  getTaskservelist,
@@ -1083,6 +1161,7 @@
  addserviceSubtask,
  query360PatInfo,
  addsatisfaction,
  transferDept,
  query360PatInfonh,
} from "@/api/AiCentre/index";
import { alterpatient, particularpatient } from "@/api/patient/homepage";
@@ -1117,8 +1196,7 @@
      title: "新增影像随访",
      // 是否显示修改、添加弹出层
      addalteropen: false,
      // 修改发送时间对话框
      modificationVisible: false,
      // 部门名称
      deptName: undefined,
      // 默认密码
@@ -1136,7 +1214,7 @@
      inputVisible: false,
      Labelchange: false,
      ycvalue: 0,
      jgvalue: "",
      jgvalue: 0,
      yfsvalue: "",
      inputValue: "",
      preachform: "",
@@ -1205,7 +1283,10 @@
          label: "全部",
        },
      ],
      lastScopeType: 3, // 患者范围上次选择的一级类型(1=科室,2=病区,3=全部)
      loading: false,
      // 顶部卡片点击带来的临时筛选(只作用于下面列表,不动表单、不改卡片数字;点「搜索」时清空)
      cardFilter: null,
      cardlist: [
        {
          name: "患者服务总量",
@@ -1294,12 +1375,22 @@
        pageNum: 1,
        pageSize: 10,
        sendstateView: 1,
        sort: localStorage.getItem("orgname") == "丽水市中医院" ? 8 : 1, //0 出院时间(正序)    1 出院时间(倒序)   2 发送时间(正序)    3 发送时间(倒序)  7应随访日期(倒序) 应随访日期(正序)
        sort:
          localStorage.getItem("orgname") == "丽水市中医院"
            ? 8
            : localStorage.getItem("orgname") == "景宁畲族自治县人民医院"
            ? 2
            : 1, //0 出院时间(正序)    1 出院时间(倒序)   2 发送时间(正序)    3 发送时间(倒序)  7应随访日期(倒序) 应随访日期(正序)
        serviceType: 2,
        sendstate: null,
        searchscope: 3,
        visitCount: 1,
        scopetype: [],
        managementDoctor:
          localStorage.getItem("orgname") == "缙云县人民医院" ||
          localStorage.getItem("orgname") == "丽水市中医院"
            ? store.getters.nickName
            : "",
        leaveldeptcodes: [],
        leavehospitaldistrictcodes: [],
      },
@@ -1397,6 +1488,25 @@
      leavehospitaldistrictcode: "",
      serviceState: [],
      checkboxlist: [],
      // 变更科室/病区
      transferDialogVisible: false,
      transferForm: {
        subId: null,
        leavelDeptCode: "",
        leavelDeptName: "",
        leavehospitaldistrictcode: "",
        leavehospitaldistrictname: "",
      },
      deptOptionsks: [],
      deptOptionsbq: [],
      transferDeptValue: [],
      transferWardValue: [],
      cascaderPropsa: {
        value: "deptCode",
        label: "label",
        checkStrictly: true,
      },
      transferLoading: false,
      // 表单校验
      rules: {},
    };
@@ -1405,6 +1515,15 @@
    // 监听路由参数变化
    "$route.query": {
      handler(newQuery, oldQuery) {
        // 右下角「待处理随访任务」卡片再次点击(当前已在本页)
        if (
          newQuery?.month &&
          newQuery?.fromPendingTask === "1" &&
          this.taskQueryReady
        ) {
          this.applyPendingTaskQuery();
          return;
        }
        if (newQuery?.errtype !== oldQuery?.errtype) {
          console.log(22);
          this.loadData();
@@ -1433,7 +1552,12 @@
        value: dept.districtCode,
      };
    });
    if (this.errtype == 1) {
    // 免登直达:根据科室/病区编码预填患者范围
    this.applyFollowUpScope();
    // 右下角「待处理随访任务」卡片跳转:按出院年月 + 待随访 + 出院满 7 天过滤
    if (this.applyPendingTaskQuery()) {
      // 已按卡片条件查询,不再走默认分支
    } else if (this.errtype == 1) {
      this.toleadExport(2);
    } else if (this.errtype == 2) {
      // 待随访
@@ -1453,9 +1577,16 @@
    this.getConfigKey("sys.user.initPassword").then((response) => {
      this.initPassword = response.msg;
    });
    // created 初始化完成,之后路由 query 变化才按卡片条件重新查询
    this.taskQueryReady = true;
  },
  activated() {
    // 从别的标签页切回来时,以表单条件为准,丢弃卡片带来的一次性筛选
    this.cardFilter = null;
    this.errtype = this.$route.query.errtype;
    if (this.applyPendingTaskQuery()) {
      return;
    }
    if (this.errtype == 1) {
      this.toleadExport(2);
    } else if (this.errtype == 2) {
@@ -1478,14 +1609,8 @@
    /** 查询随访服务列表 */
    async getList(refresh) {
      // 默认全部
      if (this.topqueryParams.searchscope == 3) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
          (obj) => obj.deptCode
        );
        this.topqueryParams.leavehospitaldistrictcodes =
          store.getters.belongWards.map((obj) => obj.districtCode);
      }
      if (this.endOut == 0) {
      this.applyDeptWardScope();
      if (this.endOut == 0 && !this.topqueryParams.endSendDateTime) {
        this.topqueryParams.endSendDateTime = this.formatDateToYYYYMMDDHHMMSS(
          this.getEndOfDay()
        );
@@ -1516,7 +1641,9 @@
      }
      try {
        const response = await getTaskservelist(this.topqueryParams);
        // 顶部卡片点击的临时条件只加在本次请求上,不写回表单
        const query = this.applyCardFilter({ ...this.topqueryParams });
        const response = await getTaskservelist(query);
        // ✅ 第一步:先锁定恢复状态
        this.isRestoring = true;
@@ -1533,15 +1660,10 @@
        // ✅ 第四步:处理其他数据
        if (refresh) {
          this.cardlist[0].value =
            Number(response.rows[0].wxsf) + Number(response.rows[0].xsf) || 0;
          this.cardlist[1].value = response.rows[0].wxsf || 0;
          this.ycvalue = Number(response.rows[0].yc) || 0;
          this.jgvalue = response.rows[0].jg;
          this.cardlist[2].value = response.rows[0].xsf || 0;
          this.cardlist[3].value = response.rows[0].dsf || 0;
          this.cardlist[4].value = response.rows[0].ywc || 0;
          this.yfsvalue = response.rows[0].yfs;
          // 顶部卡片的数字不跟「随访状态/异常」走:单独查一次去掉状态条件的统计,
          // 否则筛了「待随访」后「已完成」永远是 0,看着像算错了
          this.refreshCardCounts(query);
        }
        // ✅ 第五步:处理 preachform 等其他数据
@@ -1552,10 +1674,8 @@
          }
          if (item.preachform) {
            if (item.endtime) {
              item.preachformson = item.preachform;
              idArray = item.preachform.split(",");
            }
            item.preachformson = item.preachform;
            idArray = item.preachform.split(",");
            item.preachform = idArray.map((value) => {
              const item = this.checkboxlist.find(
@@ -1648,26 +1768,31 @@
      return `${year}-${month}-${day}`;
    },
    affiliation() {
      this.resetQuerykj();
      this.topqueryParams.managementDoctorCode = store.getters.hisUserId;
      this.getList(1);
    },
    onthatday() {
      this.topqueryParams.startSendDateTime = this.getCurrentDate();
      this.topqueryParams.endSendDateTime = this.getCurrentDate();
      this.resetQuerykj();
      this.topqueryParams.sendstateView = 1; // 待随访
      this.topqueryParams.sendstate = null;
      this.topqueryParams.startSendDateTime = null;
      this.topqueryParams.endSendDateTime = this.getCurrentDate(); // 开始随访日期 <= 今天
      this.getList(1);
    },
    getCurrentDate() {
      const now = new Date();
      return now.toISOString().slice(0, 10); // 截取前10个字符,即 YYYY-MM-DD
    },
    buidegetTasklist(type) {
      if (this.topqueryParams.searchscope == 3) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
          (obj) => obj.deptCode
        );
        this.topqueryParams.leavehospitaldistrictcodes =
          store.getters.belongWards.map((obj) => obj.districtCode);
      }
      // 用户权限下所有待随访任务:传递全部科室和病区
      this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
        (obj) => obj.deptCode
      );
      this.topqueryParams.leavehospitaldistrictcodes =
        store.getters.belongWards.map((obj) => obj.districtCode);
      // 接受异常跳转
      if (this.errtype) {
        this.topqueryParams.leavehospitaldistrictcodes.push(
@@ -1679,7 +1804,7 @@
        pageSize: 10,
        leavehospitaldistrictcodes:
          this.topqueryParams.leavehospitaldistrictcodes,
        sendstates: [2, 3],
        sendstateView: 1,
        leaveldeptcodes: this.topqueryParams.leaveldeptcodes,
      };
      buidegetTasklist(obj).then((response) => {
@@ -1775,13 +1900,10 @@
    },
    /** 搜索按钮操作 */
    handleQuery(refresh) {
      if (this.topqueryParams.searchscope == 3) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
          (obj) => obj.deptCode
        );
        this.topqueryParams.leavehospitaldistrictcodes =
          store.getters.belongWards.map((obj) => obj.districtCode);
      }
      // 点「搜索」时以表单条件为准,清掉卡片点击带来的临时条件
      this.cardFilter = null;
      this.applyDeptWardScope();
      this.clearAllSelection();
      this.topqueryParams.pageNum = 1;
      // 判断是不是工作台快捷查询
      if (this.errtype != 2) {
@@ -1792,33 +1914,126 @@
      }
      this.getList(refresh);
    },
    // 患者范围处理
    // 免登直达:根据路由中的科室/病区编码预填患者范围
    applyFollowUpScope() {
      const deptCode = this.$route.query.followUpDeptCode;
      const wardCode = this.$route.query.followUpWardCode;
      if (!deptCode && !wardCode) return;
      const scope = [];
      if (deptCode) scope.push([1, deptCode]);
      if (wardCode) scope.push([2, wardCode]);
      this.topqueryParams.scopetype = scope;
      this.lastScopeType = deptCode ? 1 : 2;
    },
    /**
     * 右下角「待处理随访任务」卡片点击数字跳转过来:
     * 按出院年月 + 待随访(sendstate 1/2/3/5/7)+ 出院满 7 天 过滤,口径与卡片一致
     * @returns {boolean} 是否已按卡片条件发起查询
     */
    applyPendingTaskQuery() {
      const query = this.$route.query || {};
      if (!query.month || query.fromPendingTask !== "1") {
        return false;
      }
      // 页面被 keep-alive 复用时会重复触发 activated,同一次点击只处理一次
      if (this.pendingTaskToken && this.pendingTaskToken === query._t) {
        return false;
      }
      this.pendingTaskToken = query._t;
      const month = String(query.month);
      const serviceType = Number(query.serviceType) === 3 ? 3 : 2;
      this.errtype = undefined;
      const start = month + "-01";
      let end = this.pendingTaskMonthEnd(month);
      // 月初 7 天内,"今天-7天" 会早于月初,兜底成月初,避免日期区间倒挂
      if (end < start) {
        end = start;
      }
      this.dateRange = [start, end];
      this.topqueryParams.serviceType = serviceType;
      this.topqueryParams.sendstateView = 1;
      this.topqueryParams.sendstate = null;
      // 卡片统计的是全部待随访任务(不区分首轮/复诊),列表这里同步放开
      this.topqueryParams.visitCount = null;
      this.topqueryParams.pageNum = 1;
      this.handleQuery(1);
      return true;
    },
    /**
     * 卡片口径的月份结束日:
     * 当月只统计出院满 7 天的,所以取「今天 - 7 天」;历史月份取当月最后一天
     */
    pendingTaskMonthEnd(month) {
      const parts = String(month).split("-");
      const year = Number(parts[0]);
      const mon = Number(parts[1]);
      const now = new Date();
      let date;
      if (year === now.getFullYear() && mon === now.getMonth() + 1) {
        date = new Date(year, mon - 1, now.getDate() - 7);
      } else {
        date = new Date(year, mon, 0);
      }
      const mm = String(date.getMonth() + 1).padStart(2, "0");
      const dd = String(date.getDate()).padStart(2, "0");
      return date.getFullYear() + "-" + mm + "-" + dd;
    },
    // 患者范围处理:从多选级联 scopetype 解析科室/病区
    applyDeptWardScope() {
      const value = this.topqueryParams.scopetype || [];
      const deptCodes = [];
      const wardCodes = [];
      let isAll = false;
      value.forEach((item) => {
        const type = item[0];
        if (type == 3) {
          isAll = true;
        } else if (type == 1) {
          deptCodes.push(item[item.length - 1]);
        } else if (type == 2) {
          wardCodes.push(item[item.length - 1]);
        }
      });
      // 选了全部 或 未选择 → 用户全部科室/病区
      if (isAll || (!deptCodes.length && !wardCodes.length)) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
          (obj) => obj.deptCode
        );
        this.topqueryParams.leavehospitaldistrictcodes =
          store.getters.belongWards.map((obj) => obj.districtCode);
      } else {
        this.topqueryParams.leaveldeptcodes = deptCodes;
        this.topqueryParams.leavehospitaldistrictcodes = wardCodes;
      }
    },
    // 患者范围多选变更(科室/病区互斥)
    handleChange(value) {
      console.log("选择的患者范围:", value);
      const types = (value || []).map((item) => item[0]);
      const hasDept = types.includes(1);
      const hasWard = types.includes(2);
      // 清空之前的查询参数
      this.topqueryParams.leavehospitaldistrictcodes = [];
      this.topqueryParams.leaveldeptcodes = [];
      this.topqueryParams.searchscope = null;
      if (!value || value.length === 0) {
      // 互斥:科室和病区不能同时选
      if (hasDept && hasWard) {
        if (this.lastScopeType == 1) {
          // 上次选了科室,这次新增病区 → 保留病区
          this.topqueryParams.scopetype = value.filter((item) => item[0] === 2);
          this.lastScopeType = 2;
          this.$message.warning("科室和病区不能同时选择,已切换为病区");
        } else {
          // 上次选了病区,这次新增科室 → 保留科室
          this.topqueryParams.scopetype = value.filter((item) => item[0] === 1);
          this.lastScopeType = 1;
          this.$message.warning("科室和病区不能同时选择,已切换为科室");
        }
        this.applyDeptWardScope();
        return;
      }
      let type = value[0];
      let code = value.slice(-1)[0];
      if (type == 1) {
        this.topqueryParams.leaveldeptcodes.push(code);
        this.topqueryParams.leavehospitaldistrictcodes = [];
        this.topqueryParams.searchscope = 1;
      } else if (type == 2) {
        this.topqueryParams.leavehospitaldistrictcodes.push(code);
        this.topqueryParams.leaveldeptcodes = [];
        this.topqueryParams.searchscope = 2;
      } else {
        this.topqueryParams.searchscope = 3;
      }
      this.lastScopeType = hasDept ? 1 : hasWard ? 2 : 3;
      this.applyDeptWardScope();
    },
    // 服务状态变更处理
    handleServiceStatusChange(value) {
@@ -1856,6 +2071,7 @@
      this.dateRange = [];
      this.dateRangefs = [];
      this.serviceStatusValue = 10;
      this.lastScopeType = 3;
      this.topqueryParams = {
        pageNum: 1,
        pageSize: 10,
@@ -1869,6 +2085,25 @@
        leavehospitaldistrictcodes: [],
      };
      this.handleQuery(1);
    },
    /** 重置按钮操作 */
    resetQuerykj() {
      this.dateRange = [];
      this.dateRangefs = [];
      this.serviceStatusValue = null;
      this.lastScopeType = 3;
      this.topqueryParams = {
        pageNum: 1,
        pageSize: 10,
        sendstateView: null,
        sort: 2, //0 出院时间(正序)    1 出院时间(倒序)   2 发送时间(正序)    3 发送时间(倒序)
        serviceType: 2,
        searchscope: 3,
        visitCount: 1,
        scopetype: [],
        leaveldeptcodes: [],
        leavehospitaldistrictcodes: [],
      };
    },
    handleSelectionChange(rows) {
      // ✅ 如果是恢复选中状态触发的,直接返回
@@ -2091,10 +2326,7 @@
        })
        .catch(() => {});
    },
    // 设置发送时间
    Sendtimesetting() {
      this.modificationVisible = true;
    },
    // 跳转详情页
    Seedetails(row) {
      let type = "";
@@ -2160,8 +2392,10 @@
      this.Labelchange = true;
    },
    // 便捷按钮
    toleadExport(too) {
      console.log(too, "too");
    toleadExport(too, type) {
      if (type) {
        this.resetQuerykj();
      }
      if (too == 1) {
        this.topqueryParams.sendstate = 4;
@@ -2173,7 +2407,6 @@
        this.topqueryParams.endSendDateTime = this.formatDateToYYYYMMDDHHMMSS(
          this.getEndOfDay()
        );
        console.log(1111, this.topqueryParams.endSendDateTime);
        this.topqueryParams.excep = null;
        this.topqueryParams.sendstate = 2;
@@ -2188,6 +2421,74 @@
        this.topqueryParams.scopetype = null;
      }
      this.handleQuery(1);
    },
    // 顶部统计卡片点击:把对应筛选条件下带到下面的列表(数值为 0 的卡片同样可点)
    // 顶部卡片统计:去掉「随访状态 / 异常」条件后再统计,
    // 这样卡片数字只跟日期、科室/病区等条件走,不会因为筛了「待随访」就把「已完成」算成 0
    async refreshCardCounts(baseQuery) {
      const query = {
        ...(baseQuery || this.topqueryParams),
        pageNum: 1,
        pageSize: 1,
        sendstate: null,
        sendstateView: null,
        sendstates: null,
        excep: null,
      };
      try {
        const res = await getTaskservelist(query);
        const row = (res && res.rows && res.rows[0]) || {};
        this.cardlist[0].value = Number(row.wxsf || 0) + Number(row.xsf || 0);
        this.cardlist[1].value = Number(row.wxsf) || 0;
        this.cardlist[2].value = Number(row.xsf) || 0;
        this.cardlist[3].value = Number(row.dsf) || 0;
        this.cardlist[4].value = Number(row.ywc) || 0;
        this.ycvalue = Number(row.yc) || 0;
        this.jgvalue = Number(row.jg) || 0;
      } catch (e) {
        console.warn("刷新顶部卡片统计失败", e);
      }
    },
    // 顶部统计卡片点击:只给下面的列表加临时条件,不动上方表单、也不改卡片数字;
    // 卡片数字只在点「搜索」时按表单条件重算
    handleCardClick(item) {
      this.cardFilter = item && item.name ? item.name : null;
      this.topqueryParams.pageNum = 1;
      // 传 0:刷新列表,但不回写顶部卡片数字
      this.getList(0);
    },
    // 把卡片点击的条件叠加到查询参数(返回新对象,不修改表单本身)
    applyCardFilter(query) {
      const name = this.cardFilter;
      if (!name) return query;
      // 卡片数字是「不含随访状态/异常」的总量,所以点卡片时也把表单里的状态条件去掉,
      // 只按卡片自己的条件查,否则会出现「卡片 922、列表 3 条」
      query.sendstate = null;
      query.sendstateView = null;
      query.sendstates = null;
      query.excep = null;
      if (name === "无需随访") {
        query.sendstateView = 3;
      } else if (name === "待随访") {
        query.sendstateView = 1;
      } else if (name === "已完成") {
        query.sendstateView = 2;
      } else if (name === "需随访") {
        query.sendstates = [1, 2, 3, 5, 6, 7];
      } else if (name === "异常") {
        query.excep = "1";
      } else if (name === "警告") {
        query.excep = "2";
      }
      // 「患者服务总量」= 只去掉状态条件,不加别的
      return query;
    },
    // 清除卡片筛选,回到表单条件
    clearCardFilter() {
      this.cardFilter = null;
      this.topqueryParams.pageNum = 1;
      this.getList(0);
    },
    /** 导出按钮操作 */
    handleExport() {
@@ -2209,14 +2510,41 @@
        this.getList();
      });
    },
    // 异常列渲染
    // 行颜色渲染:蓝色(未到随访时间) / 红色(异常) / 黄色(警告)
    tableRowClassName({ row, rowIndex }) {
      // 当前时间小于应随访时间且任务状态为待随访 → 整行蓝色(南华大学附属第一医院不生效)
      if (
        this.orgname == "南华大学附属第一医院" &&
        row.sendstate == 2 &&
        this.isBeforeVisitTime(row.visitTime)
      ) {
        return "blue-row";
      }
      if (row.excep == 1) {
        return "warning-row";
      } else if (row.excep == 2) {
        return "remind-row";
      }
      return "";
    },
    // 判断当前时间是否早于应随访时间(按“天”比较)
    isBeforeVisitTime(visitTime) {
      if (!visitTime) return false;
      let date;
      if (typeof visitTime === "number") {
        date = new Date(visitTime);
      } else {
        date = new Date(String(visitTime).replace(/-/g, "/"));
      }
      if (isNaN(date.getTime())) return false;
      const now = new Date();
      const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
      const visitDay = new Date(
        date.getFullYear(),
        date.getMonth(),
        date.getDate()
      );
      return today.getTime() < visitDay.getTime();
    },
    restoreSelection() {
      if (!this.$refs.userform) {
@@ -2330,6 +2658,104 @@
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    // ---------- 变更科室/病区 ----------
    handleTransferOpen(row) {
      if (!this.deptOptionsks.length) {
        deptTreeSelect(1).then((res) => {
          this.deptOptionsks = res.data || [];
        });
        deptTreeSelect(2).then((res) => {
          this.deptOptionsbq = res.data || [];
        });
      }
      this.transferForm = {
        subId: row.id || row.subtaskid,
        leavelDeptCode: "",
        leavelDeptName: "",
        leavehospitaldistrictcode: "",
        leavehospitaldistrictname: "",
        currentDeptName: row.leaveldeptname || row.deptName || "",
        currentWardName:
          row.leavehospitaldistrictname || row.leavehospitaldistrictName || "",
      };
      this.transferDeptValue = [];
      this.transferWardValue = [];
      this.transferDialogVisible = true;
    },
    handleDeptCascaderChange(val) {
      if (val && val.length) {
        this.transferForm.leavelDeptCode = val[val.length - 1];
        // 从选项树中查找对应名称
        const node = this.findCascaderNode(
          this.deptOptionsks,
          this.transferForm.leavelDeptCode
        );
        this.transferForm.leavelDeptName = node ? node.label : "";
      } else {
        this.transferForm.leavelDeptCode = "";
        this.transferForm.leavelDeptName = "";
      }
    },
    handleWardCascaderChange(val) {
      if (val && val.length) {
        this.transferForm.leavehospitaldistrictcode = val[val.length - 1];
        const node = this.findCascaderNode(
          this.deptOptionsbq,
          this.transferForm.leavehospitaldistrictcode
        );
        this.transferForm.leavehospitaldistrictname = node ? node.label : "";
      } else {
        this.transferForm.leavehospitaldistrictcode = "";
        this.transferForm.leavehospitaldistrictname = "";
      }
    },
    findCascaderNode(options, code) {
      for (const item of options) {
        if (item.deptCode === code || item.value === code) return item;
        if (item.children) {
          const found = this.findCascaderNode(item.children, code);
          if (found) return found;
        }
      }
      return null;
    },
    handleTransferSubmit() {
      const hasDept = !!this.transferForm.leavelDeptCode;
      const hasWard = !!this.transferForm.leavehospitaldistrictcode;
      if (!hasDept && !hasWard) {
        this.$modal.msgError("请至少选择目标科室或目标病区");
        return;
      }
      console.log(this.transferForm);
      // 组装变更提示文本
      const deptName = this.transferForm.leavelDeptName || "不变";
      const wardName = this.transferForm.leavehospitaldistrictname || "不变";
      const tip = `确认将科室变更为"${deptName}"、病区变更为"${wardName}"?`;
      this.$modal
        .confirm(tip, "变更确认")
        .then(() => {
          this.transferLoading = true;
          transferDept(this.transferForm)
            .then((res) => {
              if (res.code === 200) {
                this.$modal.msgSuccess("科室/病区变更成功");
                this.transferDialogVisible = false;
                this.getList();
              } else {
                this.$modal.msgError(res.msg || "变更失败");
              }
            })
            .catch(() => {
              this.$modal.msgError("变更失败,请重试");
            })
            .finally(() => {
              this.transferLoading = false;
            });
        })
        .catch(() => {});
    },
  },
};
</script>
@@ -2337,8 +2763,8 @@
<style lang="scss" scoped>
.el-button--primary.is-plain {
  color: #ffffff;
  background: #409eff;
  border-color: #4fabe9;
  background: #5b7cfa;
  border-color: #5b7cfa;
}
.document {
@@ -2351,10 +2777,44 @@
::v-deep.el-table .remind-row {
  background: #fcf5aa;
}
::v-deep.el-table .blue-row {
  background: #c6e2ff;
}
.documentf {
  display: flex;
  justify-content: flex-end;
}
.color-legend {
  float: right;
  display: flex;
  align-items: center;
  height: 40px;
  gap: 16px;
  margin-right: 5px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  font-size: 16px;
  color: #666;
}
.legend-block {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-right: 6px;
}
.legend-blue {
  background: #9cc9fa;
}
.legend-red {
  background: #f1aaaa;
}
.legend-yellow {
  background: #faf18d;
}
.download {
@@ -2509,6 +2969,9 @@
.button-textxga {
  color: #de7897;
}
.button-textxgc {
  color: #9054e4;
}
.purple-button.is-disabled {
  background-color: #d8b4fe;
  border-color: #d8b4fe;
@@ -2568,4 +3031,89 @@
  font-size: 14px;
  color: #666;
}
.card-filter-tip {
  margin: 2px 0 4px;
  padding: 6px 10px;
  font-size: 13px;
  color: #303133;
  background: #f0f7ff;
  border: 1px solid #d6e9ff;
  border-radius: 4px;
}
.card-filter-tip .tip-desc {
  margin: 0 6px;
  font-size: 12px;
  color: #909399;
}
/* ================= 清新高级简约风 ================= */
.app-container {
  background: #f5f7fb;
  border-radius: 14px;
  padding: 20px;
}
/* 查询表单:白色圆角卡片 */
::v-deep .el-form--inline {
  background: #ffffff;
  border-radius: 14px;
  padding: 22px 22px 8px;
  margin-bottom: 18px;
  box-shadow: 0 2px 12px rgba(31, 45, 61, 0.05);
}
/* 隐藏分割线 */
::v-deep .el-divider {
  display: none;
}
/* 工具栏底部间距 */
.mb8 {
  margin-bottom: 18px;
}
/* 按钮:圆角 + 柔和过渡 */
::v-deep .el-button {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.25s ease;
}
/* 主按钮:清新靛蓝 */
::v-deep .el-button--primary:not(.is-plain) {
  background: #5b7cfa;
  border-color: #5b7cfa;
}
::v-deep .el-button--primary:not(.is-plain):hover,
::v-deep .el-button--primary:not(.is-plain):focus {
  background: #7593fb;
  border-color: #7593fb;
}
/* 表格:白色圆角卡片 + 柔和表头 */
::v-deep .el-table {
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(31, 45, 61, 0.05);
}
::v-deep .el-table::before {
  display: none;
}
::v-deep .el-table th {
  background: #f7f9fd !important;
  color: #3f4d63;
  font-weight: 600;
}
::v-deep .el-table td {
  padding: 12px 0;
}
/* 标签圆角 */
::v-deep .el-tag {
  border-radius: 6px;
}
/* 分页间距 */
::v-deep .pagination-container {
  padding-top: 18px;
}
</style>