<template>
  <div>
    <div style="margin: 10px 0">
	  <span>查询条件：</span>
      <span v-if="description" class="span1"
        ><i>规则名称：</i>{{ description }}</span
      >
      <span class="span1"><i>规则类型：</i>{{ row.ruleTypeName || "-" }}</span>
      <span class="span1"
        ><i>规则术语类型：</i>{{ row.libTypeName || "-" }}</span
      >
      <span class="span1"><i>医学标准术语：</i>{{ row.libName || "-" }}</span>
      <span v-if="baseTermTypeName" class="span1"
        ><i>基础规则术语类型：</i>{{ baseTermTypeName }}</span
      >
      <span v-if="baseLibName" class="span1"
        ><i>基础医学标准术语：</i>{{ baseLibName }}</span
      >
	  <span v-if="staticName" class="span1"
	    ><i>关联静态信息：</i>{{ staticName }}</span
	  >
      <!--<el-form :inline="true" style="margin-top: 10px;height: 45px;">
				<el-form-item label="基础规则术语类型：">
					<el-select v-model="filter.baseLibType" clearable placeholder="请选择" size="mini">
						<el-option v-for="item in baseTermTypeList2" :key="item.val" :label="item.name"
							:value="item.val">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="基础医学标准术语：">
					<el-input size="mini" v-model="filter.baseLibName" placeholder="请输入" clearable></el-input>
				</el-form-item>
				<el-form-item>
					<el-button size="mini" @click="getRuleDetail">确认</el-button>
				</el-form-item>
			</el-form>-->
    </div>
    <el-main>
      <ux-grid
        ref="plxTable"
        :merge-cells="tdSpanArr"
        show-overflow
        style="width: 100%"
        height="600px"
      >
        <ux-table-column
          field="id"
          :title="'组(共' + total + '组)'"
          width="120"
        ></ux-table-column>
        <ux-table-column field="description" title="规则名称" minWidth='100'></ux-table-column>
        <ux-table-column field="hasSubCond" title="子条件" minWidth='100'>
          <template slot-scope="scope">
            {{ scope.row.hasSubCond ? "有" : "无" }}
          </template>
        </ux-table-column>
        <ux-table-column
          field="msg"
          title="附加信息"
		  minWidth='100'
          show-overflow-tooltip
        ></ux-table-column>
		<ux-table-column field="names" title="关联静态信息"  minWidth='100' show-overflow-tooltip>
		  <template slot-scope="scope">
		    {{ transDataString(scope.row) }}
		  </template>
		</ux-table-column>
        <ux-table-column field="baseType" title="基础规则类型" minWidth='100'>
          <template slot-scope="scope">
            {{ transDataMap(baseTypeList)[scope.row.baseType] }}
          </template>
        </ux-table-column>
        <ux-table-column prop="baseLibType" title="基础规则术语类型" minWidth='100'>
          <template slot-scope="scope">
            {{ transDataMap(baseTermTypeList)[scope.row.baseLibType] }}
          </template>
        </ux-table-column>
        <ux-table-column
          field="baseLibName"
          title="基础医学标准术语"
		  minWidth='100'
        ></ux-table-column>
        <ux-table-column
          field="baseMinOperator"
          title="最小域比较符"
          minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseMinValue"
          title="最小域值"
           minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseMinUnit"
          title="最小域单位"
           minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseMaxOperator"
          title="最大域比较符"
           minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseMaxValue"
          title="最大域值"
          minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseMaxUnit"
          title="最大域单位"
          minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseEqValue"
          title="等于阈值"
          minWidth='80'
        ></ux-table-column>
        <ux-table-column
          field="baseEqUnit"
          title="等于域单位"
          minWidth='80'
        ></ux-table-column>
      </ux-grid>
    </el-main>
  </div>
</template>

<script>
import api from "@api/knowledgeLib.js";
export default {
  name: "CheckRule",
  data: function () {
    return {
      tdSpanArr: this.mergeCells,
      pos: 0,
      filter: {
        baseLibType: "",
        baseLibName: "",
      },
      baseTermTypeList2: [],
      total: this.ruleTeamNum,
    };
  },
  computed: {
    baseTermTypeName() {
      const item = this.baseTermTypeList.filter((it) => {
        return it.val === this.filterp.baseLibType;
      });
      return item[0] ? item[0].name : "";
    },
  },
  created() {
    this.baseTermTypeList2 = this.baseTermTypeList;
    this.filter.baseLibName = this.baseLibName;
    this.filter.baseLibType = this.baseLibType;
  },
  mounted() {
    this.$refs.plxTable.reloadData(this.rulelist);
    //this.loading.close();
  },
  props: [
    "loading",
    "mergeCells",
    "filterp",
    "rulelist",
    "ruleTeamNum",
    "baseTypeList",
    "baseTermTypeList",
    "row",
    "description",
    "baseLibType",
    "baseLibName",
	"staticName"
  ],
  methods: {
	transDataString(data){
		let array=[]
		if(data.names&&Array.isArray(data.names)){
			array=[...data.names];
			array=array.join(',')
			return array
		}
		return '';
	},
    transDataMap(data) {
      const obj = {};
      data.map((it) => {
        obj[it.val] = it.name;
      });
      return obj;
    },
    getRuleDetail() {
      console.log(456);
      const param = {
        baseLibName: this.filter.baseLibName,
        baseLibType: this.filter.baseLibType,
        description: this.description,
        libName: this.row.libName,
        libType: this.row.libType,
        ruleType: this.row.ruleType,
      };
      api
        .zskgetRuleDetail(param)
        .then((res) => {
          if (res.data.code == "0") {
            let datalist = [];
            const data = res.data.data.ruleConditionDTOList;
            this.total = data.length;
            let mergeArr = [];
            for (let i in data) {
              let datai = data[i];
              const dtoList = datai.ruleBaseDTOList;
              for (let j = 0; j < dtoList.length; j++) {
                const isFirst = j === 0;
                if (isFirst) {
                  const len = datalist.length;
                  mergeArr.push(
                    { row: len, col: 0, rowspan: dtoList.length, colspan: 1 },
                    { row: len, col: 1, rowspan: dtoList.length, colspan: 1 },
                    { row: len, col: 2, rowspan: dtoList.length, colspan: 1 }
                  );
                }
                datalist.push({
                  id: +i + 1,
                  rowspan: isFirst ? dtoList.length : 0,
                  colspan: isFirst ? 1 : 0,
                  ruleGroup: datai.ruleGroup,
                  msg: datai.msg,
                  description: datai.description,
                  ...dtoList[j],
                });
              }
            }
            this.tdSpanArr = mergeArr;
            this.$refs.plxTable.reloadData(datalist);
          } else {
            this.$message(res.data.msg || "获取详情失败，请稍后重试");
          }
        })
        .catch((error) => {
          this.$message(error.msg || "接口出错");
        });
    },
  },
};
</script>

<style scoped lang="less">
/deep/.el-table .cell {
  line-height: 25px;
}

.span1 {
  i {
    font-weight: bolder;
  }
  margin: 0 60px 0 0;
}

/deep/.el-form--inline .el-form-item__label {
  font-weight: bolder;
  font-size: 14px;
}
</style>
