<template>
  <div>
    <crumbs title="静态知识映射测试" class="topBack">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item
          label=""
          class="selectMedicine"
          style="marginbottom: -1px"
        >
          <el-select
            size="mini"
            v-model="hospitalId"
            placeholder="选择医院"
            @change="handleChange"
          >
            <el-option
              v-for="item in hospitalData"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item style="marginbottom: 0px">
          <el-button size="mini" @click="handleAllTest"
            >所有术语类型映射测试</el-button
          >
        </el-form-item>
      </el-form>
    </crumbs>
    <div style="margin: 60px 20px 0">
      <el-table :data="list" border>
        <el-table-column
          :resizable="false"
          type="index"
          :index="indexMethod"
          label="编号"
          width="80"
        ></el-table-column>
        <el-table-column
          :resizable="false"
          prop="caseName"
          label="术语类型"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          :resizable="false"
          prop="gmtModified"
          label="测试时间"
        ></el-table-column>

        <el-table-column
          :resizable="false"
          prop="totleNum"
          label="医院术语总条数"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="未映射到标准术语条数">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="goToInnerPage(scope.row,'noMap')"
              >{{ scope.row.unMappingNum }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="缺少静态知识术语条数">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="goToInnerPage(scope.row,'lessStatic')"
              >{{ scope.row.withoutKnowledgeNum }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleTest(scope.row)"
              >执行测试</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import api from '@api/cdss.js';
import config from '@api/config.js';
import utils from '@api/utils.js';
export default {
  name: 'KnowledgeMapRuleTest',
  data() {
    return {
      list: [],
      hospitalData: [],
      hospitalId: '', //选中医院
    };
  },
  created() {
    this._getHospitalInfoCDSS();
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      Object.assign(vm, to.params);
      if (Object.keys(to.params).length === 0) return;
      vm.getDataList(to.params.hospitalId);
    });
  },
  methods: {
    indexMethod(index) {
      return index + 1;
    },
    // 获取医院信息
    _getHospitalInfoCDSS() {
      api.getHospitalInfo().then((res) => {
        if (res.data.code === '0') {
          this.hospitalData = res.data && res.data.data;
        }
      });
    },
    // 执行测试
    handleTest() {},
    // 所有规则测试
    handleAllTest() {},

    // 跳转至未映射到标准术语条数页面 / 缺少静态知识术语条数
    goToInnerPage(row,type) {
      let hospital = this.hospitalData.find(
        (item) => item.id === this.hospitalId
      );
      let hospitalName = hospital.name;
      this.$router.push({
        name: 'LessStaticDisease',
        params: {
          data: { ...row },
          hospitalId: this.hospitalId,
          hospitalName,
          type
        },
      });
    },

    // 选中医院
    handleChange(val) {
      if (val === '') return;
      this.getDataList(val);
    },

    // 获取列表数据
    getDataList(id) {
      const params = {
        hospitalId: id,
      };
      this.searched = true;
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      });
      api.getStaticCaseResultList(params).then((res) => {
        loading.close();
        if (res.data.code === '0') {
          this.list = res.data && res.data.data;
        }
      });
    },
  },
};
</script>

<style lang="less" scored>
@import '../../../less/admin.less';
</style>