liusheng
2026-11-03 f12b3e4c7c8d55217cc1d21f814a9a3d5fc57251
src/views/followvisit/discharge/index.vue
@@ -1934,7 +1934,7 @@
    },
    /**
     * 右下角「待处理随访任务」卡片点击数字跳转过来:
     * 按出院年月 + 待随访(sendstate 1/2/3/5/7)+ 出院满 7 天 过滤,口径与卡片一致
     * 按出院年月 + 待随访(sendstate 1/2/3/7)+ 出院满 7 天 过滤,口径与卡片一致
     * @returns {boolean} 是否已按卡片条件发起查询
     */
    applyPendingTaskQuery() {
@@ -1952,11 +1952,8 @@
      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;
      }
      // 卡片统计的是「出院满 7 天」的任务,截止日 = min(该月最后一天, 今天-7 天)
      const end = this.pendingTaskMonthEnd(month);
      this.dateRange = [start, end];
      this.topqueryParams.serviceType = serviceType;
      this.topqueryParams.sendstateView = 1;
@@ -1964,24 +1961,47 @@
      // 卡片统计的是全部待随访任务(不区分首轮/复诊),列表这里同步放开
      this.topqueryParams.visitCount = null;
      this.topqueryParams.pageNum = 1;
      // 当月还没到第 8 天时,该月不可能有「出院满 7 天」的任务(卡片显示 0),列表直接给空。
      // 日期框仍显示该月的自然区间,避免出现「起止倒挂」的筛选条件。
      if (end < start) {
        this.dateRange = [start, this.pendingTaskMonthLastDay(month)];
        this.userList = [];
        this.total = 0;
        this.loading = false;
        this.$message.info("该月暂无出院满 7 天的待随访任务");
        return true;
      }
      this.handleQuery(1);
      return true;
    },
    /**
     * 卡片口径的月份结束日:
     * 当月只统计出院满 7 天的,所以取「今天 - 7 天」;历史月份取当月最后一天
     * 该月最后一天(yyyy-MM-dd),只用于「当月还没有满 7 天任务」时展示正常月份区间
     */
    pendingTaskMonthLastDay(month) {
      const parts = String(month).split("-");
      const date = new Date(Number(parts[0]), Number(parts[1]), 0);
      const mm = String(date.getMonth() + 1).padStart(2, "0");
      const dd = String(date.getDate()).padStart(2, "0");
      return date.getFullYear() + "-" + mm + "-" + dd;
    },
    /**
     * 卡片口径的月份结束日:卡片只统计「出院满 7 天仍未随访」的任务,
     * 所以截止日永远是 min(该月最后一天, 今天-7 天);
     * 历史月份同样要按「今天-7 天」截断,否则月末几天出院的患者会被算进来(卡片 49、列表 77)。
     */
    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);
      }
      // 出院满 7 天:出院日期 <= 今天-7(与后端 endtime < 今天-6 00:00 等价)
      const cutoff = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() - 7
      );
      const monthEnd = new Date(year, mon, 0);
      const date = cutoff < monthEnd ? cutoff : monthEnd;
      const mm = String(date.getMonth() + 1).padStart(2, "0");
      const dd = String(date.getDate()).padStart(2, "0");
      return date.getFullYear() + "-" + mm + "-" + dd;