<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" label-width="90px">
      <el-row>
        <el-col :span="6">
          <el-form-item>
            <el-radio-group v-model="queryParams.timeType">
              <el-radio label="createTime">创建时间</el-radio>
              <el-radio label="checkTime">审核时间</el-radio>
              <el-radio label="reserveTime">预约时间</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="日期范围">
            <el-date-picker
              v-model="queryParams.date"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="datePickerOptions"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查类型" prop="checkType" v-show="showSearch">
            <el-select
              v-model="queryParams.checkType"
              placeholder="请选择检查类型"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in checkTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查诊室" prop="checkRoom" v-show="showSearch">
            <el-select
              v-model="queryParams.checkRoom"
              placeholder="请选择检查诊室"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in checkRoomList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查部位" prop="checkPart" v-show="showSearch">
            <el-input
              v-model="queryParams.checkPart"
              placeholder="请输入检查部位"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查设备" prop="checkDevice" v-show="showSearch">
            <el-select
              v-model="queryParams.checkDevice"
              placeholder="请选择检查设备"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in checkDeviceList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="诊断医师"
            prop="diagnosisDoctor"
            v-show="showSearch"
          >
            <el-input
              v-model="queryParams.diagnosisDoctor"
              placeholder="请输入诊断医师"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="审核医生" prop="auditDoctor" v-show="showSearch">
            <el-input
              v-model="queryParams.auditDoctor"
              placeholder="请输入审核医生"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="病例类型" prop="caseType">
            <el-select
              v-model="queryParams.caseType"
              placeholder="请选择病例类型"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in caseTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="患者姓名" prop="patientName" v-show="showSearch">
            <el-input
              v-model="queryParams.patientName"
              placeholder="请输入患者姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="病例号"
            prop="patientRecordNumber"
            v-show="showSearch"
          >
            <el-input
              v-model="queryParams.patientRecordNumber"
              placeholder="请输入病例号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查结果" prop="checkResult" v-show="showSearch">
            <el-select
              v-model="queryParams.checkResult"
              placeholder="请选择检查结果"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in checkResultList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleQuery"
            >
              查询
            </el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd">
          新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>
    <el-table v-loading="loading" :data="caseList" border>
      <el-table-column
        label="检查号"
        prop="id"
        width="80"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="患者姓名"
        prop="patientName"
        width="100"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            scope.row.patientName
              ? scope.row.patientName.replace(/^(.).*(.)$/, "$1***$2")
              : "-"
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="病例号"
        prop="patientRecordNumber"
        width="110"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="性别"
        width="70"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ genderList.find((i) => i.value == scope.row.gender).label || "-" }}
        </template>
      </el-table-column>
      <el-table-column
        label="年龄"
        width="80"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.age || "" }}
          {{
            ageUnitList.find((i) => i.value == scope.row.ageUnit).label || ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="预约时间"
        prop="reserveTime"
        width="160"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="检查部位"
        width="120"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.customPart || scope.row.checkPart || "-" }}
        </template>
      </el-table-column>
      <el-table-column
        label="检查类型"
        width="90"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            checkTypeList.find((i) => i.value == scope.row.checkType).label ||
            "-"
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="检查结果"
        width="90"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            checkResultList.find((i) => i.value == scope.row.checkResult)
              .label || "-"
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="检查诊室"
        width="100"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            checkRoomList.find((i) => i.value == scope.row.checkRoom).label ||
            "-"
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="诊断医师"
        prop="diagnosisDoctor"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="审核医生"
        prop="auditDoctor"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="报告状态"
        prop="reportStatus"
        width="90"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="打印次数"
        prop="printCount"
        width="80"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建时间"
        prop="createTime"
        width="160"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="审核时间"
        prop="checkTime"
        width="160"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="门诊号"
        prop="outpatientNumber"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="门诊号"
        prop="outpatientNumber"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="住院号"
        prop="inpatientNumber"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="病区号"
        prop="wardNumber"
        width="80"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="床位号"
        prop="bedNumber"
        width="80"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="申请医师"
        prop="applyDoctor"
        width="100"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        width="200"
        align="center"
        show-overflow-tooltip
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >
            查看
          </el-button>
          <el-button
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="患者姓名" prop="patientName">
              <el-input
                v-model="form.patientName"
                placeholder="请输入患者姓名"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="性别" prop="gender">
              <el-select
                v-model="form.gender"
                style="width: 100%"
                placeholder="请选择性别"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in genderList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="年龄" prop="age">
              <el-input-number
                v-model="form.age"
                placeholder="请输入年龄"
                clearable
                :min="0"
                style="width: 100%"
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="" prop="ageUnit" label-width="0">
              <el-select
                v-model="form.ageUnit"
                style="width: 100%"
                placeholder="请选择年龄单位"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in ageUnitList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="病例号" prop="patientRecordNumber">
              <el-input
                v-model="form.patientRecordNumber"
                placeholder="请输入病例号"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查类型" prop="checkType">
              <el-select
                v-model="form.checkType"
                style="width: 100%"
                placeholder="请选择检查类型"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in checkTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门诊号" prop="outpatientNumber">
              <el-input
                v-model="form.outpatientNumber"
                placeholder="请输入门诊号"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住院号" prop="inpatientNumber">
              <el-input
                v-model="form.inpatientNumber"
                placeholder="请输入住院号"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="病区号" prop="wardNumber">
              <el-input
                v-model="form.wardNumber"
                placeholder="请输入病区号"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="床位号" prop="bedNumber">
              <el-input
                v-model="form.bedNumber"
                placeholder="请输入床位号"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请医师" prop="applyDoctor">
              <el-input
                v-model="form.applyDoctor"
                placeholder="请输入申请医师"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专家" prop="expertDoctor">
              <el-select
                v-model="form.expertDoctor"
                multiple
                style="width: 100%"
                placeholder="请选择专家"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in doctorList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查设备" prop="checkDevice">
              <el-select
                v-model="form.checkDevice"
                multiple
                style="width: 100%"
                placeholder="请选择检查设备"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in checkDeviceList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查部位" prop="checkPart">
              <el-select
                v-model="form.checkPart"
                multiple
                style="width: 100%"
                placeholder="请选择检查部位"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in checkPartList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                  <span style="float: left">{{ item.label }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">
                    {{ item.category }}
                  </span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查诊室" prop="checkRoom">
              <el-select
                v-model="form.checkRoom"
                style="width: 100%"
                placeholder="请选择检查诊室"
                @change="handleCheckRoomChange"
                filterable
                clearable
                :disabled="isEditMode"
              >
                <el-option
                  v-for="item in checkRoomList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="自定义部位" prop="customPart">
              <el-input
                v-model="form.customPart"
                placeholder="请输入自定义部位"
                clearable
                :disabled="isEditMode"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预约日期" prop="reserveDate">
              <el-date-picker
                v-model="form.reserveDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择预约日期"
                @change="handleDateChange"
                style="width: 100%"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="" prop="reserveTime">
              <el-select
                v-model="form.reserveTime"
                placeholder="请选择预约时间"
                style="width: 100%"
                filterable
                clearable
              >
                <el-option label="自动" value="auto" />
                <el-option
                  v-for="slot in availableTimeSlots"
                  :key="slot.value"
                  :label="slot.label"
                  :value="slot.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  listCase,
  getCase,
  delCase,
  addCase,
  updateCase,
} from "@/api/cases/index.js";
export default {
  name: "Case",
  data() {
    // 获取今天日期
    const today = new Date().toISOString().split("T")[0];
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 表格数据
      caseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否为编辑模式
      isEditMode: false,
      // 字典
      genderList: [
        { label: "未知", value: "0" },
        { label: "男", value: "1" },
        { label: "女", value: "2" },
      ],
      ageUnitList: [
        { label: "岁", value: "1" },
        { label: "月", value: "2" },
        { label: "天", value: "3" },
      ],
      checkTypeList: [
        { label: "门诊", value: "1" },
        { label: "急诊", value: "2" },
        { label: "住院", value: "3" },
      ],
      checkDeviceList: [
        { label: "默认设备", value: "1" },
        { label: "测试添加设备", value: "2" },
      ],
      checkRoomList: [
        { label: "默认诊室", value: "1" },
        { label: "测试添加诊室", value: "2" },
      ],
      doctorList: [
        { label: "专家1", value: "1" },
        { label: "专家2", value: "2" },
      ],
      caseTypeList: [
        { label: "本院报告", value: "1" },
        { label: "我参与的会诊", value: "2" },
        { label: "我审核的", value: "3" },
      ],
      checkResultList: [
        { label: "阴性", value: "negative" },
        { label: "阳性", value: "positive" },
      ],
      checkPartList: [
        { label: "肝脏", value: "1", category: "腹部" },
        { label: "胆囊", value: "2", category: "腹部" },
        { label: "胰腺", value: "3", category: "腹部" },
        { label: "肾脏", value: "4", category: "腹部" },
        { label: "脾脏", value: "5", category: "腹部" },
        { label: "腹部血管", value: "6", category: "腹部" },
        { label: "子宫", value: "7", category: "子宫" },
        { label: "颈部血管", value: "8", category: "外周血管" },
        { label: "上肢血管", value: "9", category: "外周血管" },
        { label: "下肢血管", value: "10", category: "外周血管" },
        { label: "产科", value: "11", category: "产科" },
        { label: "甲状腺", value: "12", category: "甲状腺" },
        { label: "乳腺", value: "13", category: "乳腺" },
        { label: "睾丸", value: "14", category: "睾丸" },
        { label: "泌尿", value: "15", category: "泌尿" },
        { label: "心脏", value: "16", category: "心脏" },
        { label: "其它", value: "17", category: "其它" },
        { label: "眼科", value: "18", category: "眼科" },
      ],
      availableTimeSlots: [],
      datePickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "昨天",
            onClick: (picker) => {
              const end = new Date();
              end.setTime(end.getTime() - 3600 * 1000 * 24);
              const start = new Date(end);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "本周",
            onClick: (picker) => {
              const end = new Date();
              const start = new Date();
              const day = start.getDay();
              start.setDate(start.getDate() - day + (day === 0 ? -6 : 1));
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "本月",
            onClick: (picker) => {
              const end = new Date();
              const start = new Date(
                new Date().getFullYear(),
                new Date().getMonth(),
                1
              );
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "上月",
            onClick: (picker) => {
              const end = new Date(
                new Date().getFullYear(),
                new Date().getMonth(),
                0
              );
              const start = new Date(
                new Date().getFullYear(),
                new Date().getMonth() - 1,
                1
              );
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "今年",
            onClick: (picker) => {
              const end = new Date();
              const start = new Date(new Date().getFullYear(), 0, 1);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: "",
        gender: "",
        patientRecordNumber: "",
        checkType: "",
        outpatientNumber: "",
        inpatientNumber: "",
        wardNumber: "",
        bedNumber: "",
        applyDoctor: "",
        expertDoctor: "",
        checkDevice: "",
        checkPart: "",
        checkRoom: "",
        customPart: "",
        reserveDate: "",
        reserveTime: "",
        diagnosisDoctor: "",
        auditDoctor: "",
        reportStatus: "",
        dateRange: "",
        timeType: "reserveTime", // 默认预约时间
        date: [today, today], // 默认当天
        caseType: "1", // 默认病例类型为第一个（本院报告）
        checkResult: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        patientName: [
          { required: true, message: "患者姓名不能为空", trigger: "blur" },
        ],
        patientRecordNumber: [
          { required: true, message: "病例号不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.resetQuery();
  },
  methods: {
    // 查询列表
    getList() {
      this.loading = true;
      listCase(this.queryParams)
        .then((response) => {
          this.caseList = response.rows;
          this.total = response.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
          this.caseList = [
            {
              id: 294,
              patientName: "测试患者",
              gender: "0",
              age: 3,
              ageUnit: "2",
              patientRecordNumber: "病例号",
              checkType: "3",
              outpatientNumber: "门诊",
              inpatientNumber: "住院",
              wardNumber: "病区",
              bedNumber: "床号",
              applyDoctor: "申请医师",
              expertDoctor: "会诊专家",
              checkDevice: "",
              checkRoom: "1",
              customPart: "",
              reserveDate: "2026-05-14",
              reserveTime: "13:30-14:00",
              diagnosisDoctor: "会诊专家",
              auditDoctor: "",
              reportStatus: "已提交",
              printCount: 3,
              createTime: "2026-05-14 09:51:45",
              checkTime: "",
              checkResult: "negative",
            },
          ];
        });
    },
    cancel() {
      this.open = false;
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
      this.resetForm("queryForm");
      const today = new Date().toISOString().split("T")[0];
      this.queryParams.timeType = "reserveTime";
      this.queryParams.date = [today, today];
      this.queryParams.caseType = "1";
      this.handleQuery();
    },
    // 新增按钮操作
    handleAdd() {
      this.reset();
      const today = new Date().toISOString().split("T")[0];
      this.form = {
        gender: this.genderList[0].value,
        checkType: this.checkTypeList[0].value,
        ageUnit: this.ageUnitList[0].value,
        reserveDate: today,
      };
      this.open = true;
      this.title = "新增病例";
      this.isEditMode = false;
    },
    // 修改按钮操作
    handleUpdate(row) {
      this.reset();
      this.form = { ...row };
      this.open = true;
      this.title = "修改病例";
      this.isEditMode = true;
    },
    // 提交按钮
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updateCase(this.form).then(() => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCase(this.form).then(() => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.handleView(this.form);
            });
          }
        }
      });
    },
    // 选择检查室后，根据日期和检查室获取可用时间槽
    handleCheckRoomChange(roomId) {
      this.form.reserveTime = "";
      if (roomId && this.form.reserveDate)
        this.fetchTimeSlots(roomId, this.form.reserveDate);
      else this.availableTimeSlots = [];
    },
    handleDateChange(date) {
      this.form.reserveTime = "";
      if (this.form.checkRoom && date)
        this.fetchTimeSlots(this.form.checkRoom, date);
      else this.availableTimeSlots = [];
    },
    async fetchTimeSlots(roomId) {
      const mockData = {
        1: [
          { label: "13:30-14:00", value: "13:30-14:00" },
          { label: "14:00-14:30", value: "14:00-14:30" },
          { label: "14:30-15:00", value: "14:30-15:00" },
          { label: "15:00-15:30", value: "15:00-15:30" },
        ],
        2: [
          { label: "09:00-09:30", value: "09:00-09:30" },
          { label: "09:30-10:00", value: "09:30-10:00" },
          { label: "10:00-10:30", value: "10:00-10:30" },
          { label: "10:30-11:00", value: "10:30-11:00" },
        ],
      };
      this.availableTimeSlots = mockData[roomId] || [];
    },
    getTimeSlots(roomId) {
      const mockData = {
        1: [
          { label: "13:30-14:00", value: "13:30-14:00" },
          { label: "14:00-14:30", value: "14:00-14:30" },
          { label: "14:30-15:00", value: "14:30-15:00" },
          { label: "15:00-15:30", value: "15:00-15:30" },
        ],
        2: [
          { label: "09:00-09:30", value: "09:00-09:30" },
          { label: "09:30-10:00", value: "09:30-10:00" },
          { label: "10:00-10:30", value: "10:00-10:30" },
          { label: "10:30-11:00", value: "10:30-11:00" },
        ],
      };
      return mockData[roomId] || [];
    },
    // 选择预约时间后，更新预约时间
    handleReserveTimeChange(row) {
      updateCase(row).then(() => {
        this.$modal.msgSuccess("预约时间修改成功");
      });
    },
    // 查看按钮操作
    handleView(row) {
      this.$router.push({
        name: "PatientDetail",
        params: {
          id: row.id,
          patientName: row.patientName,
        },
      });
    },
  },
};
</script>