<template>
  <div>
    <div class="d-flex flex-between pt7">
      <div class="">
        <el-button type="primary" @click="exportData">导出</el-button>
      </div>
      <el-form :model="searchForm" label-width="90px" :inline="true">
        <el-form-item class="mr10" label="" prop="xsxm">
          <el-input
            v-model="searchForm.xsxm"
            placeholder="请输入学生姓名"
            clearable
            @clear="getListData"
          >
          </el-input>
        </el-form-item>
        <el-form-item class="mr10" label="" prop="xsxh">
          <el-input
            v-model="searchForm.xsxh"
            placeholder="请输入学籍号"
            clearable
            @clear="getListData"
          >
          </el-input>
        </el-form-item>
        <el-form-item class="mr10" label="" prop="qtzz">
          <el-input
            v-model="searchForm.qtzz"
            placeholder="请输入疾病症状"
            clearable
            @clear="getListData"
          >
          </el-input>
        </el-form-item>
        <el-form-item class="mr10" label="">
          <el-select
            v-model="searchForm.tjlx"
            placeholder="请选择检查类别"
            @change="getListData"
          >
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="mr10" label="">
          <el-date-picker
            v-model="searchForm.tjrq"
            @change="getTime"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-button type="primary" class="ml5 mb20" @click="getListData"
          >搜索
        </el-button>
      </el-form>
    </div>

    <el-table
      @selection-change="handleSelectionChange"
      :data="tableData"
      v-loading="loading"
      tooltip-effect="dark"
      style="width: 100%"
    >
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>

      <el-table-column
        label="晨午检"
        prop="xdct_xslx"
        width=""
      ></el-table-column>
      <el-table-column label="班级" prop="class_name" width="150">
      </el-table-column>
      <el-table-column label="体检日期" prop="xdct_tjrq" width="150">
      </el-table-column>
      <el-table-column
        label="学生姓名"
        prop="xdct_xsxm"
        align="center"
        width=""
      >
      </el-table-column>
      <el-table-column
        label="学籍号"
        prop="xdct_xsxh"
        align="center"
        width="220"
      >
      </el-table-column>
      <el-table-column label="性别" prop="xdct_xsxb" align="center" width="">
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="xdct_nl" width="">
      </el-table-column>
      <el-table-column label="体检结果" align="center" width="120">
        <template v-slot="scope">
          <span v-if="scope.row.xdct_tjjg_option_k == 0">--</span>
          <span v-if="scope.row.xdct_tjjg_option_k == 1">良好</span>
          <span v-if="scope.row.xdct_tjjg_option_k == 2">及格</span>
          <span v-if="scope.row.xdct_tjjg_option_k == 3" class="text-red"
            >异常</span
          >
        </template>
      </el-table-column>
      <el-table-column label="异常症状" prop="xdct_qtzz"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="showDetail(scope.row)"
            >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <footer
      class="flex-item-none"
      style="display: flex; justify-content: flex-end; margin-top: 30px"
    >
      <el-pagination
        background
        layout="total,prev, pager, next"
        :page-size="limit"
        :total="total"
        :current-page.sync="cur_page"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </footer>
    <el-dialog
      title="学生体检详情"
      :visible.sync="checkDialogVisible"
      width="780px"
      v-loading="loading"
    >
      <div class="d-flex">
        <div class="flex-1">
          <h3 class="font-size-14">学生姓名：{{ detailInfo.xdct_xsxm }}</h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">学籍号：{{ detailInfo.xdct_xsxh }}</h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">
            体检类型：{{ detailInfo.xdct_xslx_option_n }}
          </h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">
            体检结果：<span class="text-red">{{
              detailInfo.xdct_tjjg_option_n
            }}</span>
          </h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">身高：{{ detailInfo.xdct_tjxx_sg }}cm</h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">体重：{{ detailInfo.xdct_tjxx_tz }}公斤</h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">胸围：{{ detailInfo.xdct_tjxx_xw }}cm</h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">肺活量：{{ detailInfo.xdct_tjxx_fhl }}</h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">血压：{{ detailInfo.xdct_tjxx_xy }}</h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">脉搏：{{ detailInfo.xdct_tjxx_mb }}</h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">视力：{{ detailInfo.xdct_tjxx_sl }}</h3>
        </div>
        <div class="flex-1">
          <h3 class="font-size-14">听力：{{ detailInfo.xdct_tjxx_tl }}</h3>
        </div>
      </div>
      <div class="d-flex mt15">
        <div class="flex-1">
          <h3 class="font-size-14">
            是否发病：{{ detailInfo.xdct_sffb_option_n }}
          </h3>
        </div>
        <div class="flex-1" v-if="detailInfo.xdct_sfqd_option_k == 1">
          <h3 class="font-size-14">其他症状：{{ detailInfo.xdct_qtzz }}</h3>
        </div>
      </div>
      <div slot="footer" class="text-center">
        <el-button @click="checkDialogVisible = false" type="primary"
          >确定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { tj_stu_list, tj_stu_detail } from "./api";
import { useUserStore } from "@/stores/user";
const { token, real_name } = useUserStore();
export default {
  name: "index",
  data() {
    return {
      grade_id: "",
      class_id: "",
      searchForm: {
        xsxm: "",
        xsxh: "",
        qtzz: "",
        tjjg: "3",
        tjlx: "",
        tjrq: ["", ""],
      },
      tableData: [],
      limit: 10,
      total: 0,
      loading: false,
      cur_page: 1,
      typeList: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "晨检",
          value: 1,
        },
        {
          label: "午检",
          value: 2,
        },
      ],
      jgList: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "良好",
          value: 1,
        },
        {
          label: "及格",
          value: 2,
        },
        {
          label: "异常",
          value: 3,
        },
      ],
      checkDialogVisible: false,
      detailInfo: {},
      multipleSelection1: [],
    };
  },
  methods: {
    getListData() {
      this.loading = true;
      let data = {
        grade_id: this.grade_id,
        class_id: this.class_id,
        xdct_xsxm: this.searchForm.xsxm,
        xdct_xsxh: this.searchForm.xsxh,
        xdct_tjjg: this.searchForm.tjjg,
        xdct_xslx: this.searchForm.tjlx,
        xdct_qtzz: this.searchForm.qtzz,
        page: this.cur_page,
        limit: this.limit,
      };

      if (this.searchForm.tjrq.length > 0) {
        data.xdct_tjrq =
          this.searchForm.tjrq[0] + " - " + this.searchForm.tjrq[1];
      } else {
        data.xdct_tjrq = "";
      }
      tj_stu_list(data).then((res) => {
        this.loading = false;
        if (res.code == 1) {
          this.tableData = res.data.page_data;
          this.cur_page = Number(res.data.page_now);
          this.total = Number(res.data.total_rows);
        }
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    handleSelectionChange(val) {
      this.multipleSelection1 = [];
      for (let i in val) {
        this.multipleSelection1.push(val[i].xdct_id);
        console.log(this.multipleSelection1, 123);
      }
    },
    getTimeFormat() {
      var date = new Date();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }

      this.searchForm.tjrq = [
        date.getFullYear() + "-" + month + "-" + strDate,
        date.getFullYear() + "-" + month + "-" + strDate,
      ];
      console.log(this.searchForm.tjrq[0], this.searchForm.tjrq[1]);
    },
    getTime() {
      if (!this.searchForm.tjrq) {
        this.searchForm.tjrq = ["", ""];
      }
      this.cur_page = 1;
      this.getListData();
    },
    exportData() {
      let time = "";
      if (this.searchForm.tjrq.length > 0) {
        time = this.searchForm.tjrq[0] + " - " + this.searchForm.tjrq[1];
      } else {
        time = "";
      }
      let link =
        window.globalVariables.api +
        "/xddy/dygl_cjxt_tjdj/index?api=xls&page=1&limit=10000&token=" +
        token +
        "&xdct_id=" +
        this.multipleSelection1.join(",");
      window.open(link, "_self");
    },
    showDetail(item) {
      let data = {
        xdct_id: item.xdct_id,
      };
      tj_stu_detail(data).then((res) => {
        if (res.code == 1) {
          this.detailInfo = res.data.one_info;
          this.checkDialogVisible = true;
        }
      });
    },
  },
  mounted() {
    this.getTimeFormat();
    this.getListData();

    if (this.$route.params.grade_id != "") {
      this.grade_id = this.$route.params.grade_id;
      this.class_id = this.$route.params.class_id;
    }
  },
};
</script>


<style scoped>
::v-deep .el-input {
  width: 160px;
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 300px;
}
::v-deep .el-date-editor .el-range-separator {
  width: 8%;
}
</style>