<template>
  <div class="listPage">
    <div class="listPage-min" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

        <el-form-item label="检查项名称" prop="name" label-width="100px">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入检查项名称"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item style="float: right">
          <el-col :span="1.5">
            <span class="reset-button-one"
              style="font-weight:700;margin-bottom:20px;"
              @click="backPage"><i class="el-icon-arrow-left"></i>返回</span>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="checkOptionList">
        <el-table-column label="检查项名称" align="left" prop="name" />
        <el-table-column label="检查项" align="left" prop="parentNames">
          <template slot-scope="scope">{{scope.row.parentId == 0?'根目录':scope.row.parentNames}}</template>
        </el-table-column>
        <el-table-column label="检查人" align="left" prop="nickName" />
        <el-table-column label="检查时间" align="left" prop="createTime" />
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="goInfo(scope.row)">查看</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        style="margin-bottom:20px;"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <check-record-info-page v-if="pageType == 2" :infoId="infoId"></check-record-info-page>
  </div>
</template>

<script>
  import { tempListCheckRecord,getCheckIdByoptionId } from "@/api/laboratory/checkRecord";
  import checkRecordInfoPage from "../checkRecord/checkRecordInfoPage.vue"
  export default {
    name: 'listPage',
    components: {
      checkRecordInfoPage
    },
    data() {
      return {
        pageType:1,
        infoId:"",
        loading:false,
        total:0,
        checkOptionList:[],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize:20,
          deptId: null,
          deptName: null,
          userId: null,
          name: null,
          parentId: null
        },
      }
    },
    mounted(){
      this.getList();
    },
    methods:{
      //页面状态切换
      goPageInfo(type){
        if(type == 1){
          this.pageType = 1;
          this.getList();
        }
      },
      //查看详情
      goInfo(row){
        console.log("row",row)
        getCheckIdByoptionId({jcxId:row.id}).then( response => {
          console.log("response",response)
          if(response.data.id == 0){
            this.msgError("该检查项没有相关检查记录")
            return
          }
          this.infoId = response.data.id;
          this.pageType = 2;
        });
      },
      //返回
      backPage(){
        this.$parent.goPageType(1);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.$set(this,'queryParams',{
          pageNum: 1,
          pageSize:20,
          name:"",
        });
        this.handleQuery();
      },
      /** 查询检查项选项列表 */
      getList() {
        this.loading = true;
        tempListCheckRecord(this.queryParams).then( response => {
          this.checkOptionList =  response.rows;
          this.total =  response.total;
          this.loading = false;
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .listPage{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .listPage-min{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
  }
</style>
