<template>
	<div>
		<div style="margin-top: 10px;">
			<span class="span1">规则类型：</span>{{row.ruleTypeName||'-'}}
			<span class="span1" style="margin-left:100px;">规则术语类型：</span>{{row.libTypeName||'-'}}
			<span class="span1" style="margin-left:100px;">医学标准术语：</span>{{row.libName||'-'}}
			<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="规则名称"></ux-table-column>
				<ux-table-column field="msg" title="附加信息" show-overflow-tooltip></ux-table-column>
				<ux-table-column field="baseType" title="基础规则类型">
					<template slot-scope="scope">
						{{transDataMap(baseTypeList)[scope.row.baseType]}}
					</template>
				</ux-table-column>
				<ux-table-column prop="baseLibType" title="基础规则术语类型">
					<template slot-scope="scope">
						{{transDataMap(baseTermTypeList)[scope.row.baseLibType]}}
					</template>
				</ux-table-column>
				<ux-table-column field="baseLibName" title="基础医学标准术语"></ux-table-column>
				<ux-table-column field="baseMinOperator" title="最小域比较符" width="80"></ux-table-column>
				<ux-table-column field="baseMinValue" title="最小域值" width="80"></ux-table-column>
				<ux-table-column field="baseMinUnit" title="最小域单位" width="80"></ux-table-column>
				<ux-table-column field="baseMaxOperator" title="最大域比较符" width="80"></ux-table-column>
				<ux-table-column field="baseMaxValue" title="最大域值" width="80"></ux-table-column>
				<ux-table-column field="baseMaxUnit" title="最大域单位" width="80"></ux-table-column>
				<ux-table-column field="baseEqOperator" title="等于阈值" width="80"></ux-table-column>
				<ux-table-column field="baseEqUnit" title="等于域单位" width="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,
			};
		},
		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','rulelist','ruleTeamNum', 'baseTypeList', 'baseTermTypeList', 'row', 'description','baseLibType','baseLibName'],
		methods: {
		  transDataMap(data){
			const obj = {};
			data.map((it)=>{
			  obj[it.val] = it.name;
			});
			return obj;
		  },
			getRuleDetail() {
				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 {
		font-weight: bolder;
	}

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