<template>
  <el-dialog title="提示" :visible.sync="dialogVisible" width="40%" id="applyRules">
    <p>按对应规则配置动态参数，已完成！</p>
    <p>请检查并关注以下实例及相关动态参数，自动配置结果是否正确</p>
    <div ref="message" style="max-height:400px;overflow-x:hidden;overflow-y:auto;">
      <div v-for="item in ContentList" :key="item.code" v-show="item.children.length">
        <p>【{{item.name}}】</p>
        <div v-for="t in item.children" :key="t.ObjectID+t.Id">
          <p v-if="t.TypeCode=='Eq'">
            {{`${t.ObjectLocalName?t.ObjectLocalName:'--'}/${t.ObjectID?t.ObjectID:'--'}/${t.TypeName?t.TypeName:'--'}/${t.BuildLocalName?t.BuildLocalName:'--' }/${t.FloorLocalName?t.FloorLocalName:'--'}/${t.RoomLocalName?t.RoomLocalName:'--'}`}}
          </p>
          <p v-if="t.TypeCode=='Ec'">
            {{`${t.ObjectLocalName?t.ObjectLocalName:'--'}/${t.ObjectID?t.ObjectID:'--'}/${t.TypeName?t.TypeName:'--'}/${t.CascadeEquipLocalName}/${t.BuildLocalName?t.BuildLocalName:'--' }/${t.FloorLocalName?t.FloorLocalName:'--'}/${t.RoomLocalName?t.RoomLocalName:'--'}`}}
          </p>
          <p v-if="t.TypeCode=='Sp'">
            {{`${t.ObjectLocalName?t.ObjectLocalName:'--'}/${t.ObjectID?t.ObjectID:'--'}/${t.TypeName?t.TypeName:'--'}/${t.BuildLocalName?t.BuildLocalName:'--' }/${t.FloorLocalName?t.FloorLocalName:'--'}`}}
          </p>
          <p v-if="t.TypeCode=='Sy'">{{`${t.ObjectLocalName?t.ObjectLocalName:'--'}/${t.ObjectID?t.ObjectID:'--'}/${t.TypeName?t.TypeName:'--'}`}}</p>
          <p>{{`${t.InfomationPoint}/${t.Old}/${t.New}`}}</p>
          <hr style="margin:10px 0;width:50%;">
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="copy">复制信息</el-button>
      <el-button size="small" type="primary" @click="dialogVisible=false">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>

import {
  dynamicExecuteDetail // 查询执行日志
} from "@/api/scan/request";
export default {
  data() {
    return {
      dialogVisible: false, //弹窗显示与隐藏
      ContentList: [
        { name: '人工维护过值的信息点', children: [], code: 'MeterDiff' },
        { name: '多个表号功能号对应一个信息点，无法执行对应规则，请检查', children: [], code: 'Multiple' },
      ],
      typeList: ["MeterDiff", "Multiple"], //此分类索引需与上list保持一致
    };
  },
  methods: {
    showDialog(Id) {
      this.dialogVisible = true
      this.getApplyLog(Id)
    },
    handleClose() {
      this.dialogVisible = false;
    },
    //复制信息
    copy() {
      let text = this.$refs.message.innerText;
      let copyUrl = $('<input type="text" />').val(text);//创建一个input框获取需要复制的文本内容
      copyUrl.appendTo('body');
      copyUrl.select();
      document.execCommand("Copy");
      copyUrl.remove()
      this.$message.success('复制成功')
    },
    //查询执行日志
    getApplyLog(Id) {
      let param = {
        Filters: `Type='Multiple' or Type='MeterDiff';Id='${Id}'`,
        PageNumber: 1,
        PageSize: 50
      }
      dynamicExecuteDetail(param, res => {
        res.Content.map(t => {
          this.ContentList[this.typeList.indexOf(t.Type)].children.push(t)
        })
        this.ContentList[1].children = this.unique(this.ContentList[1].children)
      })
    },
    //数组去重
    unique(arr) {
      let hash = [];
      if (arr.length) {
        for (var i = 0; i < arr.length; i++) {
          for (var j = i + 1; j < arr.length; j++) {
            if (arr[i].ObjectID === arr[j].ObjectID && arr[i].InfomationPointCode === arr[j].InfomationPointCode) {
              ++i;
              arr[i].New += '/' + arr[j].New
            }
          }
          hash.push(arr[i]);
        }
      }
      return hash;
    }
  }
};
</script>