<template>
  <div v-loading="loading" style="overflow:hidden;">
    <layout :f-border="false" :show-chart="true" :result-info="chartResultInfo">
      <div slot="form_content">
        <div class="form_mainctn">
          <!-- 查询时间 -->
          <el-row :gutter="2">
            <!--            <el-col :span="5" class="date-class">-->
            <!--              <el-select placeholder="选择查询时间段" clearable v-model="queryPeriod.periodType" @change="changeDateTimeType">-->
            <!--                <el-option v-for="item in periodTimeList"  :label="item.dataName" :key="item.dataId" :value="item.dataId"></el-option>-->
            <!--              </el-select>-->
            <!--            </el-col>-->
            <!--            <el-col :span="7">-->
            <!--              <el-date-picker align="right" type="datetimerange" placeholder="选择时间"-->
            <!--              format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :picker-options="isDefine?'':pickerOptions" v-model="queryPeriod.periodTime" @change="changeDateTime"></el-date-picker>-->
            <!--            </el-col>-->
            <el-col :span="12">
              <el-date-picker
                v-model="queryPeriod.periodTime"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                :picker-options="pickerOptions"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                align="right"
                @change="changeDateTime"
              />
            </el-col>
            <el-col :span="11" style="margin-left: 10px">
              <el-button class="addnewbtn" @click="queryForm.page.current = 1;search()"><i class="el-icon-search" />查询</el-button>
              <el-dropdown style="margin-left: 5px" @command="searchRecordBack">
                <el-button class="configbtn" style="width: 100%;height: 200%" @click="searchRecord" @mouseover.native="searchRecord"><i class="el-icon-search" />查询记录</el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    v-for="(item,index) in searchRecordList"
                    :key="index"
                    :command="item"
                    v-text="item.createTime"
                  />
                </el-dropdown-menu>
              </el-dropdown>
              <el-button style="margin-left: 5px" class="configbtn" @click="configRecord"><i class="el-icon-s-tools" />配置记录</el-button>
              <el-button class="resetbtn" @click="queryForm.page.current = 1;resetForm()"><i class="el-icon-refresh-left" />重置</el-button>
            </el-col>
          </el-row>
          <el-row class="search_forms">
            <el-col :span="19">
              <div class="formContainer" @click="filterKeyFields">
                <div :class="['filter-condition-width','filter-condition']">
                  <el-tag
                    v-for="(item,index) in selectedPolicyArray"
                    :key="index"
                    class="tag-css"
                    effect="dark"
                    type="info"
                    closable
                    max-width="300px"
                    @close.stop="handleClose(item,index)"
                  >
                    <template v-if="item.type == 'input'||item.type == 'datetime'||item.type == 'datetimerange'||item.type == 'selectInput'">
                      {{ item.label }}:{{ item.conditionLabel }}{{ toConvert(item.value, statics[treeSelectField[item.prop]] || statics[['rule_level', 'event_level', 'level'].includes(item.prop) ? 'rule_level' : item.prop], 'dataId', treeSelectField[item.prop] ? 'label' : 'dataName') }}
                    </template>
                    <template v-if="item.type == 'select'">{{ item.label }}:{{ item.valueList.dataName }}</template>
                  </el-tag>
                </div>
                <div :class="['save-container-width1','save-container']" @click="saveOper($event)"><i class="el-icon-document-checked" /></div>
              </div>
            </el-col>
          </el-row>
          <el-popover v-model="isShowForm" placement="bottom" width="520" max-height="420" trigger="manual" class="popover">
            <div class="conditions-form">
              <p class="config-btn" @click="cfgKeyFieldOper">
                <span><i class="el-icon-setting" style="font-size:16px;" />关键字配置</span>
              </p>
              <el-form ref="form" :label-position="labelPosition" :model="queryForm" class="formLabel keyFieldsForm">
                <el-col v-if="showIndex" :span="23">
                  <el-form-item class="indexId" label="日志类型" prop="indexId" label-width="90px">
                    <el-select
                      v-if="!iotTag"
                      v-model="queryForm.indexId"
                      filterable
                      @change="(val)=>{getKeyFieldsData(val,'日志类型','indexId','select')}"
                    >
                      <el-option
                        v-for="item_child in logTypeList"
                        :key="item_child.indexId"
                        :label="item_child.indexName"
                        :value="item_child.indexId"
                      />
                    </el-select>
                    <el-select
                      v-else
                      v-model="queryForm.indexId"
                      filterable
                      @change="(val)=>{getKeyFieldsData(val,'日志类型','indexId','select')}"
                    >
                      <el-option
                        v-for="item_child in iotlogTypeList"
                        :key="item_child.indexId"
                        :label="item_child.indexName"
                        :value="item_child.indexId"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="23">
                  <div v-for="(item,index) in keyword" :key="index">
                    <el-row v-for="(item_child,index_child) in item.conditions" :key="index_child">
                      <el-tooltip effect="dark" placement="top" :content="item_child.fieldName">
                        <span class="label-title">{{ item_child.fieldName }}</span>
                      </el-tooltip>
                      <el-form-item label-width="10" style="display:inline-block;width:28%;">
                        <el-select v-model="item_child.itemCondition" @change="(val)=>{conditionKeywordSelect(val,item_child)}">
                          <el-option v-for="condItem in statics.conditionType" :key="condItem.value" :label="condItem.label" :value="condItem.value" :disabled="condItem.value == 12 && item_child.fieldType != 3" />
                        </el-select>
                      </el-form-item>
                      <el-form-item label-width="10" style="display:inline-block;width:calc(100% - 90px - 22%)">
                        <manager-tree-select
                          v-if="item_child.fieldNote != 'event_group' && treeSelectField[item_child.fieldNote]"
                          :ref="item_child.fieldNote"
                          v-model="item_child.itemValue"
                          class="logManagerTreeSelect"
                          :multiple="false"
                          :data="statics[treeSelectField[item_child.fieldNote]] || []"
                          @clear="item_child.itemValue = []; $refs[item_child.fieldNote][0].filterText = ''"
                          @change="conditionKeywordInput(item_child.itemValue.join(','), item_child)"
                        />

                        <el-tree-select
                          v-else-if="item_child.fieldNote == 'event_group'"
                          class="logManagerTreeSelect"
                          :value="selectedEventGroup"
                          key-name="label"
                          @clear="$refs['eventGroupTree'][0].setCheckedKeys([]); eventGroupFilterText = ''; selectedEventGroup = []; item_child.itemValue = []; conditionKeywordInput(item_child.itemValue.join(','), item_child)"
                        >
                          <div class="filter-input" style="padding:0 15px 8px;">
                            <el-input v-model="eventGroupFilterText" placeholder="输入关键字进行过滤" />
                          </div>
                          <el-tree
                            ref="eventGroupTree"
                            v-model="item_child.itemValue"
                            :filter-node-method="filterNode"
                            node-key="dataId"
                            :data="statics.eventGroupTree"
                            show-checkbox
                            :multiple="false"
                            :check-strictly="true"
                            accordion
                            highlight-current
                            @check-change="(val, selectedNode, selectedLeaf) => eventGroupChange(val, selectedNode, selectedLeaf, item_child)"
                          />
                        </el-tree-select>

                        <template v-else-if="item_child.fieldType == 3">
                          <el-date-picker
                            :key="item_child.itemCondition == '12' ? 'datetimerange' : 'datetime'"
                            v-model="item_child.itemValue"
                            :type="item_child.itemCondition == '12' ? 'datetimerange' : 'datetime'"
                            placeholder="选择日期时间"
                            format="yyyy-MM-dd HH:mm:ss"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            @change="(val)=>{conditionKeywordInput(item_child.itemValue,item_child)}"
                          />
                        </template>

                        <el-select v-else-if="selectFiledNote.includes(item_child.fieldNote)" v-model="item_child.itemValue" filterable clearable @change="conditionKeywordInput(String(item_child.itemValue),item_child)">
                          <template v-if="['rule_level', 'event_level', 'level'].includes(item_child.fieldNote)">
                            <el-option v-for="ruleItem in statics.rule_level" :key="ruleItem.dataId" :label="ruleItem.dataName" :value="ruleItem.dataId" />
                          </template>
                          <template v-else>
                            <el-option v-for="item in statics[item_child.fieldNote]" :key="item.dataId" :label="item.dataName" :value="item.dataId" />
                          </template>
                        </el-select>
                        <el-input v-else v-model="item_child.itemValue" @blur="(e)=>conditionKeywordInput(item_child.itemValue,item_child)" />
                      </el-form-item>
                    </el-row>
                  </div>
                </el-col>
              </el-form>
            </div>
          </el-popover>
        </div>
      </div>

      <div slot="chart_content">
        <div v-if="JSON.stringify(chartQuery.chartData) == '{}' || chartQuery.chartData.yAxisDataList.length == 0" class="nodata">
          <div style="text-align:center">
            <img src="../assets/img/icon_zanwu.png" alt="">
          </div>
          <p class="nodata_text">暂无数据</p>
        </div>
        <!-- <bar-charts v-if="JSON.stringify(chartQuery.chartData) == '{}' || chartQuery.chartData.yAxisDataList.length != 0" :height="height" :chart-bar-data="chartQuery.chartData"/>         -->
        <bar-chart v-else :height="height" :chart-bar-data="chartQuery.chartData" :option="option" :bar-width="58" />
      </div>
      <div slot="table_button">
        <div class="buttonTabs">
          <el-rule-button rule-code="eventMonitor_export">
            <span class="addnewbtn" @click="exportOper">
              <i class="el-icon-upload icon-margin" />
              导出
            </span>
          </el-rule-button>
          <el-rule-button rule-code="eventMonitor_exportReport">
            <span class="addnewbtn" @click="openReport">
              <i class="el-icon-upload icon-margin" />
              导出报表
            </span>
          </el-rule-button>
        </div>
      </div>
      <div slot="table_content">
        <!-- 列表+分页-->
        <c-Table
          ref="tableParent"
          :column="logColumns"
          :table-data="logTableData"
          :background="false"
          :page="pageQuery"
          @handleCurrentRowEvent="handleCurrentRowEvent"
          @handleCurrentChange="handleCurrentChangeMain"
          @handleSizeChange="handleSizeChangeMain"
        >
          <!-- slot 翻译 -->
        </c-Table>
      </div>
    </layout>
    <!-- 关键字配置  class="dialog-ctn-cfg"-->
    <manager-dialog :visible.sync="keyFieldsConfigDL" width="56%" class="dialog-cfg" @close="clearKeyFieldsConfigDL">
      <span slot="title" style="display: flex; align-items: center" class="dialog-title">
        <span>关键字段配置</span>
        <el-input v-model="keyFieldsSearch" style="max-width: 215px; margin-left: 20px" placeholder="请输入关键字" clearable />
      </span>
      <el-row style="height:380px;overflow:scroll">
        <el-checkbox v-if="filterWordType.length" v-model="keyFieldsCheckAll" :indeterminate="isIndeterminate" @change="handleKeyFieldsAllChange">全选</el-checkbox>
        <el-form ref="configForm" :model="keyFieldsQuery">
          <el-form-item label="" label-width="20px" prop="keyFieldSelected">
            <el-checkbox-group v-model="keyFieldsQuery.keyFieldSelected" @change="handleKeyFieldsChange">
              <el-checkbox v-for="item in filterWordType" :key="item.fieldId" class="checkbox" :label="item.fieldName">{{ item.fieldName }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button style="border-radius: 3px" type="primary" @click="submitCfgKeyFields">提交</el-button>
        <el-button style="border-radius: 3px" @click="clearKeyFieldsConfigDL">关闭</el-button>
      </span>
    </manager-dialog>
    <!-- 查询配置记录 -->
    <manager-dialog :visible.sync="configRecordDialog" title="策略配置记录" @close="closeConfigRecord">
      <el-row>
        <el-table
          v-loading="tableLoading"
          :data="cfgRecordData"
          border
          stripe
          element-loading-text="数据正在加载中"
          element-loading-spinner="el-icon-loading"
          :header-cell-style="{background:'#F5F5F5',border:'none',color:'#606266',fontSize:'13px',padding:'6px 0'}"
          :cell-style="{padding:'3px'}"
        >
          <el-table-column width="60px" align="center">
            <template slot-scope="scope">
              <!-- <span class="circle" style="display:block;height:10px;width:10px;border-radius:50%;border:1px solid #EBEEF5;cursor:pointer;"></span> -->
              <!-- <el-tooltip class="item" effect="dark" :content="'策略名称:'+scope.row.ruleName" placement="top-start"> -->
              <el-button icon="el-icon-thumb" type="text" @click="chooseCurrent(scope.row)" />
              <el-popover placement="top-start" trigger="hover" popper-class="poptooltip" content="点击查询当前策略结果">
                <i slot="reference" class="el-icon-info" style="color:orange;font-size:10px;cursor:pointer" />
              </el-popover>
              <!-- </el-tooltip> -->
            </template>
          </el-table-column>
          <el-table-column label="策略名称" prop="ruleName" show-overflow-tooltip />
          <el-table-column v-if="!iotTag" label="日志类型" prop="indexId" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.indexId | toCase(logTypeList,'indexId','indexName') }}
            </template>
          </el-table-column>
          <el-table-column v-if="iotTag" label="日志类型" prop="indexId" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.indexId | toCase(iotlogTypeList,'indexId','indexName') }}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="createTime" show-overflow-tooltip />
          <el-table-column label="操作" width="110px">
            <template slot-scope="scope">
              <el-button style="color:#D9001B;padding:4px 8px;border:none;" size="mini" @click="ruleDel(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          :page-size="pageCfg.size"
          layout="prev, pager, next,total"
          :total="pageCfg.total"
          :current-page.sync="pageCfg.current"
          @current-change="handleCurrentCfgRChange"
        />
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button style="border-radius: 3px" @click="closeConfigRecord">关闭</el-button>
      </span>
    </manager-dialog>
    <manager-dialog :visible.sync="eventDetailVisible" title="事件详情" :show-footer="false" @close="closeEventDetail">
      <el-row style="width:92%; margin:15px auto 0px 6px;">
        <el-col v-for="(item,index) in tabledata" :key="index" :span="12">
          <el-col :span="8" class="name border" :title="item.name">{{ item.name }}</el-col>
          <el-col :span="16" class="border" :title="item.value">{{ item.value }}</el-col>
        </el-col>
      </el-row>
      <el-row v-if="descriptionObj != null" style="width:92%; margin:0px auto 10px 6px;">
        <el-col :span="4" class="name" style="border: 1px solid #cdd9e3;padding:0 12px 0;min-height:40px;max-height:110px;line-height:110px;font-size:12px;font-weight: 500;" :title="descriptionObj.name">{{ descriptionObj.name }}</el-col>
        <el-col :span="20" style="border: 1px solid #cdd9e3;">
          <el-input v-model="descriptionObj.value" type="textarea" :rows="5" readonly />
        </el-col>
      </el-row>
    </manager-dialog>
    <manager-dialog :visible.sync="reportVisible" title="导出报表" @close="closeReport">
      <div>
      <el-row >
        <el-form ref="report" :model="reportForm">
          <el-form-item label="报表类型" label-width="120px" prop="reportType">
            <el-radio-group v-model="reportForm.reportType">
              <el-radio :label="'1'">月报</el-radio>
              <el-radio :label="'2'">年报</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="时间范围" label-width="120px" prop="reportDate" v-if="reportForm.reportType==='1'">
            <el-date-picker :picker-options="pickerOptions0" v-model="reportForm.reportDate" type="month"
                            placeholder="请选择月份" value-format="yyyy-MM" format="yyyy-MM">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="时间范围" label-width="120px" prop="reportDate" v-if="reportForm.reportType==='2'">
            <el-date-picker :picker-options="pickerOptions0" v-model="reportForm.reportDate" type="year"
                            placeholder="请选择月份" value-format="yyyy" format="yyyy">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button  @click="closeReport">关闭</el-button>
        <el-button  @click="exportReport">提交</el-button>
      </span>
    </manager-dialog>
    <transition name="fade" mode="out-in">
      <router-view />
    </transition>
  </div>
</template>

<script>
import layout from '../components/layout/index'
import sourceData from './data'
import barChart from '../../../components/Echarts/BarChart'
import cTable from '../../../components/cTable'
// import theQueryModule from './components/queryModule'
// import sourceMethods from './logRetrieval/methods'
import ElRuleButton from '../components/button'
import { getEventDetailInfo, getLogTypeList, getFieldList, getListData, exportListData, exportReportData, getChartData, saveRuleConfig, searchRuleConfig, delRuleConfig, getDefaultTime, querySearchRecord, getAllDeviceType, getEventGroup, getStaticParamByTypeId, getTopSecTree } from '../api/log-retrival-manage'
import staticsData from '@ability/mixins/staticsData'

export default {
  name: '',
  components: {
    layout,
    cTable,
    // pagination,
    // theQueryModule,
    // ruleButton,
    barChart,
    ElRuleButton
  },
  mixins: [staticsData],
  data() {
    // return JSON.parse(JSON.stringify(sourceData))
    return sourceData
  },
  computed: {
    filterWordType() {
      return this.statics.wordType.filter(el => el.fieldName.includes(this.keyFieldsSearch))
    },
    searchData() {
      const departTree = this.$store.getters.departTree
      const assetType = this.$store.getters.assetType
      const newAssetType = []
      assetType.map(item => {
        if (item.dataId != 4) {
          newAssetType.push(item)
        }
      })
      return {
        businessTree: this.businessTree,
        departTree,
        taskTypeList: this.taskTypeList,
        logTypeList: this.logTypeList,
        analyzeLogTimingList: this.analyzeLogTimingList,
        chartTypeList: this.chartTypeList
      }
    },
    iotTag() {
      return this.$store.getters.iotTag
    }
  },
  watch: {
    businessTree(val) {
      this.statics.businessTree = val
    },
    eventGroupFilterText(val) {
      this.$refs['eventGroupTree'][0].filter(val)
    },
    keyFieldsSearch(val) {
      if (this.keyFieldsQuery.keyFieldSelected.length) {
        const selectedStr = this.keyFieldsQuery.keyFieldSelected.join()
        const every = this.filterWordType.every(el => selectedStr.includes(el.fieldName))
        if (every) {
          this.isIndeterminate = false
          this.keyFieldsCheckAll = true
        } else {
          const some = this.filterWordType.some(el => selectedStr.includes(el.fieldName))
          if (some) {
            this.isIndeterminate = true
            this.keyFieldsCheckAll = false
          } else {
            this.isIndeterminate = false
            this.keyFieldsCheckAll = false
          }
        }
      }
    }
  },
  created() {
    this.getTopsecTree()
    this.getTopsecType('TOPSEC_TYPE', 'attack_event_type')
    this.getTopsecType('TOPSEC_APP_PROTO', 'app_pro')
    this.getAllDeviceType()
    this.getEventGroup()
    this.getBusinessTree()
    this.$store.dispatch('alarm/getAllAlarmStaticList')
    // 时间处理
    this.getLogTypeData()
    Date.prototype.Format = function(fmt) { // author: meizz
      var o = {
        'M+': this.getMonth() + 1, // 月份
        'd+': this.getDate(), // 日
        'h+': this.getHours(), // 小时
        'm+': this.getMinutes(), // 分
        's+': this.getSeconds(), // 秒
        'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
        'S': this.getMilliseconds() // 毫秒
      }
      if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
      for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) }
      return fmt
    }
    this.keyword[0].conditions = []
    this.selectedPolicyArray = []
    this.logColumns = []
    this.queryPeriod.periodType = ''
    this.currentClick = false
    // this.changeDateTime(5)
    if (this.$route.query.timestamp) {
      console.log(this.$route.query.timestamp)
      console.log('1232323')
      // 根据毫秒数构建 Date 对象
      var timestamp = this.$route.query.timestamp
      var startDate = new Date(timestamp - 1000 * 60 * 60 * 3)
      var endDate = new Date(startDate.getTime() + 1000 * 60 * 60 * 3 * 2)
      this.queryPeriod.periodTime = [startDate, endDate]
    } else {
      this.getDefaultTime()
    }
    this.keyFieldsQuery.keyFieldSelected = []
    this.pageQuery.total = 0
    this.pageQuery.current = 1
    this.queryForm.page.current = 1
    this.chartResultInfo = ''
    this.chartQuery.chartData = {}
  },
  methods: {
    // 获取子分类下拉树
    getTopsecTree() {
      getTopSecTree().then(resp => {
        if (resp.data.returnCode == '0') {
          this.statics.subTypeTree = [resp.data.data]
        }
      }, error => {
        this.$message.error(error.message)
      })
    },
    // 获取分类、应用层协议下拉列表
    getTopsecType(params, attrName) {
      getStaticParamByTypeId(params).then(resp => {
        if (resp.data.returnCode == '0') {
          this.statics[attrName] = resp.data.data
        }
      }, error => {
        this.$message.error('静态数据获取失败')
      })
    },
    eventGroupChange(val, selectedNode, selectedLeaf, item_child) {
      if (selectedNode) {
        if (this.selectedEventGroup.length != 0) {
          this.$refs['eventGroupTree'][0].setChecked(this.selectedEventGroup[0].dataId, false)
          this.selectedEventGroup = []
          item_child.itemValue = []
        }
        this.selectedEventGroup = [{ dataId: val.dataId, label: val.label }]
        item_child.itemValue = [val.dataId]
        this.conditionKeywordInput(item_child.itemValue.join(','), item_child)
      }
    },
    filterNode(value, data, node) {
      if (!value) {
        node.expanded = false
        return true
      }
      return data.label.indexOf(value) !== -1
    },
    handleKeyFieldsAllChange(val) {
      const array = this.filterWordType.map(el => el.fieldName)
      if (this.keyFieldsSearch != '') {
        const selectedStr = array.join()
        this.keyFieldsQuery.keyFieldSelected = val ? Array.from(new Set(array.concat(this.keyFieldsQuery.keyFieldSelected))) : this.keyFieldsQuery.keyFieldSelected.filter(el => !selectedStr.includes(el))
      } else {
        this.keyFieldsQuery.keyFieldSelected = val ? array : []
      }
      this.isIndeterminate = false
    },
    handleKeyFieldsChange(val) {
      if (this.keyFieldsSearch != '') {
        const selectedStr = val.join()
        const res = this.filterWordType.every(el => selectedStr.includes(el.fieldName))
        this.keyFieldsCheckAll = res
        this.isIndeterminate = !res
      } else {
        const checkedCount = val.length
        this.keyFieldsCheckAll = checkedCount === this.filterWordType.length
        this.isIndeterminate = checkedCount > 0 && checkedCount < this.filterWordType.length
      }
    },
    toConvert(input = '', source, keyName, valueName) {
      if (!(source instanceof Array) || !source.length) return input
      if (source[0].children) {
        source = this.recursiveArray(source)
      }
      for (const e of source) {
        if (e[keyName] == input) { return e[valueName] }
      }
      return input
      // let str = ''
      // for (const e of source) {
      //   String(input).split(',').map(el => {
      //     if (e[keyName] == el) { str += e[valueName] + ' ' }
      //   })
      // }
      // return str
    },
    recursiveArray(list) {
      const source = []
      list.forEach(el => {
        source.push(el)
        if (el.children) {
          const childList = this.recursiveArray(el.children)
          source.push(...childList)
        }
      })
      return source
    },
    // 获取事件分组
    getEventGroup() {
      this.statics.eventGroupTree = []
      getEventGroup().then(resp => {
        if (resp.data.returnCode == '0') {
          this.statics.eventGroupTree.push(resp.data.data.list)
        }
      }, error => {
        this.$message.error('事件分组获取失败')
      })
    },
    // 获取设备来源
    getAllDeviceType() {
      getAllDeviceType().then(resp => {
        if (resp.data.returnCode == '0') {
          this.statics.device_type = resp.data.data.list
        }
      }, error => {
        this.$message.error('设备类型获取失败')
      })
    },
    closeEventDetail() {
      this.eventDetailVisible = false
    },
    // 判断奇数偶数
    checkNum(num) {
      let flag
      if (num % 2 == 0) {
        flag = true
      } else {
        flag = false
      }
      return flag
    },
    // 获取关键字字段
    convertData(data) {
      var res = []
      for (var i = 0; i < data.length; i++) {
        var geoCoord = this.detailInfo[data[i].fieldNote]
        res.push({
          name: data[i].fieldName,
          key: data[i].fieldNote,
          value: geoCoord == undefined ? '' : geoCoord
        })
      }
      return res
    },
    getEventDetailInfo() {
      getEventDetailInfo(this.queryForm.indexId).then(resp => {
        if (resp.data.returnCode == '0') {
          this.keyWordsList = resp.data.data
          const list = this.convertData(this.keyWordsList); let descriptionObj = {}
          setTimeout(() => {
            this.tabledata = list.filter(item => {
              return item.value != null && item.value != undefined && item.value != '' && item.key != 'description'
            })
            descriptionObj = list.find(item => {
              return item.key == 'description'
            })
            this.descriptionObj = JSON.parse(JSON.stringify(descriptionObj))

            this.eventDetailVisible = true
          })
        }
      }, error => {
        this.$message.error('关键字字段列表获取失败！')
      })
    },
    // 根据选中的关键字字段 渲染查询条件
    myFilter(arr1, arr2) {
      var ret = []
      for (let i = 0; i < arr2.length; i++) {
        const findEle = arr1.find(item => item.fieldName == arr2[i])
        findEle ? ret.push(findEle) : ''
      }
      return ret
    },
    concat_arr(arr1, arr2) {
      const result = []
      for (var i = 0; i < arr1.length; i++) {
        var obj = arr1[i]
        var num = obj.fieldNote
        var flag = false
        for (var j = 0; j < arr2.length; j++) {
          var aj = arr2[j]
          var n = aj.fieldNote
          if (n != num || n == num) {
            flag = true
            break
          }
        }
        if (flag) {
          result.push(obj)
        }
      }
      return result
    },
    // 关键字配置 -- 提交
    submitCfgKeyFields() {
      this.$refs['configForm'].validate(valid => {
        if (valid) {
          let tempList = []; const tempColumns = []; const tempFormList = []; const differCondition = []; const differColumn = []
          // 过滤出选中的关键字数组
          tempList = this.myFilter(this.statics.countType, this.keyFieldsQuery.keyFieldSelected)
          if (tempList.length == 0) {
            this.$message({
              message: '至少选择一个关键字段',
              type: 'warning'
            })
          } else {
            for (let i = 0; i < this.keyword.length; i++) {
              // this.keyword[i].conditions = []//重置关键字配置数组
              this.logColumns = [] // 重置列表
              tempList.forEach(item => {
                const obj = {}
                obj.fieldName = item.fieldName
                obj.fieldNote = item.fieldNote
                obj.field = item.fieldId
                obj.itemCondition = null
                obj.itemValue = this.treeSelectField[item.fieldNote] ? [] : ''
                tempFormList.push(obj)
              })
              // this.keyword[i].conditions = this.uniqueForm(this.keyword[i].conditions.concat(tempFormList))
              this.keyword[i].conditions = this.concat_arr(tempFormList, this.keyword[i].conditions)
            }
            // 表格列数据
            for (let i = 0; i < tempList.length; i++) {
              const obj = {}
              obj.label = tempList[i].fieldName
              obj.prop = tempList[i].fieldNote
              if (i == 0) {
                obj.fixed = 'left'
              }
              obj.minWidth = '120px'
              tempColumns.push(obj)
            }
            this.logColumns = this.unique(this.logColumns.concat(tempColumns))
            this.keyFieldsConfigDL = false
            this.keyFieldsSearch = ''
            this.selectedPolicyArray = []
            if (this.logTypeList.length != 0) {
              // 选中的关键字 默认值为2
              // this.queryForm.indexId = 2;
              // this.getKeyFieldsData(2,'日志类型','indexId','select')
              this.commonChangeOptions(this.queryForm.indexId, '日志类型', 'indexId', 'select')
            }
          }
        } else {
          return false
        }
      })
    },
    // 选择当前行
    chooseCurrent(row) {
      this.currentClick = true
      this.keyFieldsQuery.keyFieldSelected = []
      this.selectedPolicyArray = []
      this.queryForm.indexId = row.indexId
      const keyFieldsSelected = row.eir.items[0].conditions
      this.getKeyFieldsData(row.indexId, '日志类型', 'indexId', 'select')
      let indexObj = {}
      indexObj = this.logTypeList.find((item) => {
        return item.indexId === row.indexId
      })
      this.queryForm.indexNote = indexObj.indexNote
      this.keyword = row.eir.items
      this.search()

      this.keyword[0].conditions.forEach(item => {
        let obj = {}
        obj = this.statics.countType.find(m => {
          return m.fieldNote == item.fieldNote
        })
        this.$set(item, 'fieldName', obj.fieldName)
        if (item.itemCondition != null && item.itemValue != null) {
          this.conditionKeywordSelect(item.itemCondition, item)
          this.conditionKeywordInput(item.itemValue, item)
        } else if (item.itemCondition != null && (item.itemValue == null || item.itemValue == '')) {
          this.$set(item, 'itemCondition', null)
        } else {
          this.$set(item, 'itemValue', '')
        }
      })
      keyFieldsSelected.forEach(item => {
        this.keyFieldsQuery.keyFieldSelected.push(item.fieldName)
      })
      let tempList = []; const tempColumns = []; const tempFormList = []
      // 过滤出选中的关键字数组
      tempList = this.myFilter(this.statics.countType, this.keyFieldsQuery.keyFieldSelected)
      // 表格列数据
      for (let i = 0; i < tempList.length; i++) {
        const obj = {}
        obj.label = tempList[i].fieldName
        obj.prop = tempList[i].fieldNote
        if (i == 0) {
          obj.fixed = 'left'
        }
        obj.minWidth = '120px'
        tempColumns.push(obj)
      }
      this.logColumns = this.unique(this.logColumns.concat(tempColumns))
      this.configRecordDialog = false
    },
    // 配置记录关闭按钮
    closeConfigRecord() {
      this.cfgRecordQuery.page.current = 1
      this.configRecordDialog = false
    },
    // 关键字配置
    clearKeyFieldsConfigDL() {
      this.keyFieldsQuery.keyFieldSelected = this.keyword[0].conditions.map(el => el.fieldName)
      this.isIndeterminate = !!this.keyFieldsQuery.keyFieldSelected.length
      this.keyFieldsConfigDL = false
    },
    handleCurrentChangeMain(current) {
      this.queryForm.page.current = current
      this.search()
    },
    handleSizeChangeMain(size) {
      this.queryForm.page.size = size
      this.search()
    },
    // 重置
    resetForm() {
      this.isShowForm = false
      this.$refs.form.resetFields()
      this.queryForm.page.current = 1
      this.pageQuery.total = 0
      this.pageQuery.current = 1
      this.selectedPolicyArray = []
      this.keyword[0].conditions = []
      this.queryForm.eir.items = []
      this.$set(this.queryForm, 'indexId', null)
      this.queryForm.beginTime = ''
      this.queryForm.endTime = ''
      this.queryForm.indexNote = ''
      this.queryPeriod.periodTime = ''
      this.queryPeriod.periodType = ''
      this.queryForm.selectFiled = []
      this.currentClick = false

      // 关键字配置选中的id
      this.keyFieldsQuery.keyFieldSelected = []
      this.cfgRecordQuery.logRetrievaRuleMap.indexId = null // 配置记录
      // 清空列data和表格data
      this.logColumns = []
      this.logTableData = []
      // 清空事件分组
      this.selectedEventGroup = []
      this.eventGroupFilterText = ''
      if (this.$refs['eventGroupTree']) this.$refs['eventGroupTree'][0].setCheckedKeys([])
      this.getDefaultTime()
      setTimeout(() => {
        this.getLogTypeData()
      }, 500)
    },
    // 查询条件展开与收缩
    filterKeyFields() {
      this.isShowForm = !this.isShowForm
    },
    // 增加选中数据项
    addConditionTags(isExit, obj) {
      if (!this.showIndex) {
        if (obj.prop === 'indexId') {
          return
        }
      }
      // console.log(obj)
      if (this.selectedPolicyArray.length == 0) {
        this.selectedPolicyArray.push(obj)
      } else {
        for (let i = 0; i < this.selectedPolicyArray.length; i++) {
          if (this.selectedPolicyArray[i].prop == obj.prop) {
            isExit = true
            this.selectedPolicyArray[i].conditionLabel = obj.conditionLabel
            this.selectedPolicyArray[i].value = obj.value
            this.$set(this.selectedPolicyArray, i, obj)
            break
          }
        }
        if (!isExit) {
          this.$set(this.selectedPolicyArray, this.selectedPolicyArray.length, obj)
        }
      }
    },
    handleClose(item, index) {
      this.selectedPolicyArray.splice(index, 1)
      for (const val in this.queryForm) {
        if (item.prop == val && item.type == 'select') {
          this.$set(this.queryForm, val, null)
        } else if (item.type == 'selectInput') {
          this.keyword[0].conditions.forEach((i, index) => {
            if (item.prop == i.fieldNote) {
              this.$set(this.keyword[0].conditions[index], 'itemCondition', null)
              this.$set(this.keyword[0].conditions[index], 'itemValue', this.treeSelectField[item.prop] ? [] : '')
              if (i.fieldNote == 'event_group') {
                this.selectedEventGroup = []
                this.eventGroupFilterText = ''
                this.$refs['eventGroupTree'][0].setCheckedKeys([])
              } else if (this.treeSelectField[i.fieldNote]) {
                this.$refs[i.fieldNote][0].filterText = ''
              }
            }
          })
        }
      }
      if (item.type == 'treeSelect') {
        this.queryList.map(i => {
          if (i.type == 'treeSelect') {
            this.$refs[i.ref][0].setCheckedKeys([]) // 取消勾选节点
          }
        })
      }
      this.search()
    },
    conditionKeywordSelect(val, item) {
      if (item.fieldType == 3 && Object.prototype.toString.call(item.itemValue) == '[object Array]') {
        const index = this.selectedPolicyArray.findIndex(el => el.prop == item.fieldNote)
        this.selectedPolicyArray[index].value = ''
        item.itemValue = ''
      }
      let valObj = {}; const isExit = false; const obj = { label: '', prop: '', value: '', type: 'selectInput' }
      valObj = this.statics.conditionType.find((item) => {
        return item.value === val
      })
      if (valObj != undefined) {
        this.$set(item, 'conditionLabel', valObj.label)
        // obj.label = item.fieldNote
        obj.label = item.fieldName
        obj.prop = item.fieldNote
        obj.conditionLabel = item.conditionLabel
        obj.value = item.itemValue
        if (obj.value != NaN) {
          this.addConditionTags(isExit, obj)
        }
      }
    },
    conditionKeywordInput(val, item) {
      const valObj = {}; const isExit = false; const inputValue = ''; const obj = { label: '', prop: '', value: '', type: 'selectInput' }
      obj.label = item.fieldName
      obj.prop = item.fieldNote
      obj.conditionLabel = item.conditionLabel
      obj.value = val

      if (val != undefined && val != '') {
        this.addConditionTags(isExit, obj)
      } else {
        const index = this.selectedPolicyArray.findIndex(el => el.prop == obj.prop)
        if (index != -1) {
          this.selectedPolicyArray.splice(this.selectedPolicyArray.findIndex(el => el.prop == obj.prop), 1)
        }
      }
    },
    commonChangeOptions(val, label, prop, type) {
      const isExit = false
      const obj = { label: '', prop: '', value: '', valueList: { dataId: '', dataName: '' }}
      obj.label = label // 条件名
      obj.prop = prop // 条件key
      obj.type = type// 类型
      if (type == 'select') {
        obj.value = val // 选中值
        obj.multiple = false
        let list = {}
        list = this.logTypeList.find(m => {
          return m.indexId == val
        })
        obj.valueList.dataId = list.indexId
        obj.valueList.dataName = list.indexName
      }
      this.addConditionTags(isExit, obj)
    },
    // input 输入框
    conditionInput(val, type, item) {
      this.commonChangeOptions(val, type, item)
    },
    handleCurrentChangeMain(current) {
      this.queryForm.page.current = current
      this.search()
    },
    handleSizeChangeMain(size) {
      this.queryForm.page.size = size
      this.search()
    },
    handleCurrentRowEvent(val) {
      // this.detailInfo = JSON.parse(JSON.stringify(val))
      // this.getEventDetailInfo()
      // const path = `/asp/eventDetail?indexId=${this.queryForm.indexId}&detailInfo=${encodeURIComponent(JSON.stringify(val).replace(/%/g, '%25'))}`
      this.$router.push({ name: 'eventDetail',query:{
        indexId:this.queryForm.indexId,
        detailInfo:encodeURIComponent(JSON.stringify(val).replace(/%/g, '%25'))
      } })
      // window.open(path, '_blank')
    },
    // 获取默认时间
    getDefaultTime() {
      getDefaultTime().then(res => {
        if (res.data.returnCode == '0') {
          this.changeDateTime(res.data.data)
        }
      })
    },
    // 获取日志类型
    getLogTypeData() {
      this.iotlogTypeList = []
      getLogTypeList().then(resp => {
        if (resp.data.returnCode == '0') {
          this.logTypeList = resp.data.data
          this.iotlogTypeList = resp.data.data.filter(item => {
            return item.indexNote == 'default' || item.indexNote == 'default_new'
          })
          if (this.$route.params.id) {
            var indexNum = parseInt(this.$route.params.id)
            this.queryForm.indexId = indexNum
            // this.showIndex = false
            this.getKeyFieldsData(indexNum, '日志类型', 'indexId', 'select')
          } else if (this.logTypeList.length != 0) {
            // 选中的关键字 默认值为2
            this.showIndex = true
            this.queryForm.indexId = 2
            this.getKeyFieldsData(2, '日志类型', 'indexId', 'select')
          }
        }
      })
    },
    // 根据时间段类型触发默认时间
    changeDateTimeType(val) {
      if (val == '1000') { // 5
        this.changeDateTime(1000)
      } else if (val == '2000') { // 30
        this.changeDateTime(2000)
      } else if (val == '3000') { // 60
        this.changeDateTime(3000)
      } else if (val == '4000') { // 一天
        this.changeDateTime(4000)
      } else if (val == '5000') { // 自定义
        this.changeDateTime(5000)
      } else {
        this.isDefine = true
        this.changeDateTime()
      }
    },
    // 默认时间
    changeDateTime(type) {
      if (typeof type == 'number') {
        const start = new Date()
        const end = new Date()
        if (type == '1000') {
          start.setTime(end.getTime() - 60 * 5 * 1000)
          this.queryPeriod.periodTime = [start, end]
        } else if (type == '2000') {
          start.setTime(end.getTime() - 60 * 30 * 1000)
          this.queryPeriod.periodTime = [start, end]
        } else if (type == '3000') {
          start.setTime(end.getTime() - 60 * 60 * 1000)
          this.queryPeriod.periodTime = [start, end]
        } else if (type == '4000') {
          start.setTime(end.getTime() - 3600 * 1000 * 24 * 1)
          this.queryPeriod.periodTime = [start, end]
        } else if (type == '5000') {
          start.setTime(end.getTime() - 3600 * 1000 * 24 * 7)
          this.queryPeriod.periodTime = [start, end]
        } else {
          start.setTime(end.getTime() - 60 * 60 * 1000 * type)
          this.queryPeriod.periodTime = [start, end]
        }
        this.queryForm.beginTime = start.Format('yyyy-MM-dd hh:mm:ss')
        this.queryForm.endTime = end.Format('yyyy-MM-dd hh:mm:ss')
      } else {
        if (type != undefined) {
          this.queryForm.beginTime = type[0]
          this.queryForm.endTime = type[1]
        }
      }
      this.search()
    },
    // 根据日志类型获取关键字段信息
    getKeyFieldsData(IndexId, label, prop, type) {
      this.logColumns = []
      this.currentClick = false
      let indexObj = {}
      if (this.logTypeList.length != 0) {
        indexObj = this.logTypeList.find((item) => {
          return item.indexId === IndexId
        })
      }
      if (indexObj != undefined) {
        this.queryForm.indexNote = indexObj.indexNote
      }
      this.commonChangeOptions(IndexId, label, prop, type)
      getFieldList(IndexId).then(resp => {
        if (resp.data.returnCode == '0') {
          let i = 0; let listLength = 0; const tempList = []; const tempFormList = []; const tempColumns = []
          this.keyFieldsQuery.keyFieldSelected = []
          var list = resp.data.data
          listLength = list.length
          this.statics.countType = []
          this.statics.wordType = []          
          for (i = 0; i < listLength; i++) {
            const obj = list[i]
            if (obj.conditionFlag == '1') {
              this.statics.wordType.push(obj)
            }
            if (obj.dimensionsFlag == '1') {
              this.statics.countType.push(obj)
            }
            if (obj.selected == '1') {
              tempList.push(obj)
            }
          }
          if (this.currentClick == false) {
            var k = 0
            if (tempList.length != 0) {
              tempList.forEach(item => {
                const obj = {}; const objColumn = {}
                obj.fieldName = item.fieldName
                obj.fieldNote = item.fieldNote
                obj.field = item.fieldId
                obj.itemCondition = null
                obj.itemValue = this.treeSelectField[item.fieldNote] ? [] : ''
                obj.fieldType = item.fieldType

                if (this.$route.query.eventId && item.fieldNote == 'event_id' && this.firstLoad) {
                  obj.itemValue = this.$route.query.eventId
                  obj.itemCondition = 1
                  this.addConditionTags(false, {
                    label: '事件ID',
                    prop: 'event_id',
                    conditionLabel: '等于',
                    value: this.$route.query.eventId,
                    type: 'selectInput'
                  })
                  this.firstLoad = false
                }

                tempFormList.push(obj)
                this.keyword[0].conditions = this.uniqueForm(this.keyword[0].conditions.concat(tempFormList))
                objColumn.label = item.fieldName
                objColumn.prop = item.fieldNote
                if (k == 0) {
                  objColumn.fixed = 'left'
                }
                objColumn.minWidth = '120px'
                tempColumns.push(objColumn)
                k++
                this.logColumns = this.unique(this.logColumns.concat(tempColumns))
                this.keyFieldsQuery.keyFieldSelected.push(item.fieldName)
              })
              this.search()
            }
          }
        }
      }, error => {
        this.$message.error(error.returnMsg)
      })
      this.keyword[0].conditions = []
    },
    // 判断表格列是否包含重复字段
    unique(arr) {
      const res = new Map()
      return arr.filter((arr) => !res.has(arr.prop) && res.set(arr.prop, 1))
    },
    uniqueForm(arr) {
      const res = new Map()
      return arr.filter((arr) => !res.has(arr.fieldNote) && res.set(arr.fieldNote, 1))
    },
    commonChangeOptions(val, label, prop, type) {
      const isExit = false
      const obj = { label: '', prop: '', value: '', valueList: { dataId: '', dataName: '' }}
      obj.label = label // 条件名
      obj.prop = prop // 条件key
      obj.type = type// 类型
      if (type == 'select') {
        obj.value = val // 选中值
        obj.multiple = false
        let list = {}
        list = this.logTypeList.find(m => {
          return m.indexId == val
        })
        obj.valueList.dataId = list.indexId
        obj.valueList.dataName = list.indexName
      }
      this.addConditionTags(isExit, obj)
    },
    // 导出
    exportOper() {
      this.queryForm.selectFiled = []
      if (this.logColumns.length > 0) {
        for (let i = 0; i < this.logColumns.length; i++) {
          const obj = {}; const item = this.logColumns[i]
          obj.fieldNote = item.prop
          obj.fieldName = item.label
          this.queryForm.selectFiled.push(obj)
        }
        let indexObj = {}
        indexObj = this.logTypeList.find((item) => {
          return item.indexId === this.queryForm.indexId
        })
        if (indexObj != undefined) {
          this.queryForm.indexId = indexObj.indexId
          this.queryForm.indexNote = indexObj.indexNote
        } else {
          this.queryForm.indexId = null
          this.queryForm.indexNote = ''
        }
        exportListData(this.queryForm).then(resp => {
          if (resp.data.returnCode == '0') {
            this.$store.dispatch('beginRefresh')
            this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
          }
        }, error => {
          this.$message.error(error.returnMsg)
        })
      } else {
        this.$message.warning('请先配置关键字')
        return false
      }
    },
    openReport() {
      this.reportVisible = true
    },
    closeReport() {
      this.reportVisible = false
      this.reportForm.reportType = '1'
      this.reportForm.reportDate = null
    },
    exportReport() {
      exportReportData(this.reportForm).then(resp => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
          this.closeReport()
        }
      }, error => {
        this.$message.error(error.returnMsg)
      })
    },
    // 获取柱状图图表参数
    getBarChartData() {
      let indexObj = {}
      indexObj = this.logTypeList.find((item) => {
        return item.indexId === this.queryForm.indexId
      })
      if (indexObj != undefined) {
        this.queryForm.indexId = indexObj.indexId
        this.queryForm.indexNote = indexObj.indexNote
      } else {
        this.queryForm.indexId = null
        this.queryForm.indexNote = ''
      }
      getChartData(this.queryForm).then(resp => {
        if (resp.data.returnCode == '0') {
          this.chartResultInfo = resp.data.data.auditTaskName
          if (resp.data.data.chartData != null) {
            this.option.xAxis = [{
              type: 'category',
              data: resp.data.data.chartData.xAxisData,
              axisTick: {
                alignWithLabel: true
              }
            }]
            this.$set(this.chartQuery, 'chartData', resp.data.data.chartData)
          }
        }
      }, error => {
        this.$message.error(error.returnMsg)
      })
    },
    // 关键字配置 - 弹窗
    cfgKeyFieldOper() {
      if (this.queryForm.indexId != null) {
        if (this.keyFieldsQuery.keyFieldSelected.length == this.filterWordType.length) {
          this.keyFieldsCheckAll = true
          this.isIndeterminate = false
        }
        this.keyFieldsConfigDL = true
      } else {
        this.$message.warning('请先选择日志类型！')
      }
    },
    // 保存配置
    saveOper() {
      for (let i = 0; i < this.keyword.length; i++) {
        if (this.keyword[i].conditions.length != 0) {
          const obj = this.keyword[i].conditions.find(item => item.itemCondition != null && item.itemValue != '')
          if (obj == undefined) {
            this.$message.warning('请至少完整填写一项关键字信息！')
            return false
          } else {
            this.definePolicyName()
          }
        } else {
          this.$message.warning('请先配置关键字！')
        }
      }
    },
    // 保存策略->1、输入名称
    definePolicyName() {
      this.$prompt('请输入你要保存的策略名称', '提示', {
        confirmButtonText: '保存',
        cancelButtonText: '关闭',
        closeOnClickModal: false,
        closeOnPressEscape: false,
        inputErrorMessage: '请输入策略名称',
        inputValidator: (value) => {
          if (value.trim().length < 1) {
            return '策略名称不能为空'
          }
        },
        beforeClose: (action, instance, done) => {
          if (action == 'confirm') {
            const value = instance.inputValue
            if (value && value != '') {
              const keyword = JSON.parse(JSON.stringify(this.keyword))
              keyword[0].conditions.forEach(el => {
                if (this.treeSelectField[el.fieldNote]) el.itemValue = el.itemValue.join()
              })
              this.saveQuery.eir.items = keyword
              this.saveQuery.ruleName = value
              this.saveQuery.indexId = this.queryForm.indexId
              saveRuleConfig(this.saveQuery).then(resp => {
                if (resp.data.returnCode == '0') {
                  this.$message.success('保存记录成功')
                  done()
                }
              }, error => {
                this.$message.error(error.returnMsg)
              })
            } else {
              this.$notify({
                type: 'error',
                message: '请输入名称',
                duration: 2000
              })
            }
          } else {
            done()
          }
        }
      })
    },
    // 查询
    search() {
      this.queryForm.eir.items = JSON.parse(JSON.stringify(this.keyword))
      this.queryForm.eir.items[0].conditions.forEach(el => {
        if (this.treeSelectField[el.fieldNote]) {
          if (Object.prototype.toString.call(el.itemValue) == '[object Array]') el.itemValue = el.itemValue.join('')
        }
      })
      // 获取列表
      this.isShowForm = false
      this.loading = true
      if (this.queryForm.eir.items[0].conditions.length == 0) {
        this.loading = false
      } else {
        getListData(this.queryForm).then(resp => {
          if (resp.data.returnCode == '0') {
            if (resp.data.data != null) {
              this.logTableData = resp.data.data.list
              this.pageQuery.currentPage = resp.data.data.page.current
              this.pageQuery.total = resp.data.data.page.total
              this.pageQuery.size = resp.data.data.page.size
            }
            this.loading = false
          } else {
            this.loading = false
          }
        }, error => {
          this.loading = false
          this.$message.error(error.returnMsg)
        })
      }
      // 获取图表
      this.getBarChartData()
    },
    searchClick() {
      this.search()
    },
    // 查询搜索记录
    searchRecord() {
      this.searchRecordList = []
      querySearchRecord(this.querySearch).then(resp => {
        if (resp.data.returnCode == '0') {
          this.searchRecordList = resp.data.data.list
        }
      }, error => {
        this.$message.error(error.returnMsg)
      })
    },
    searchRecordBack(temp) {
      this.selectedPolicyArray = []
      temp.searchParam.eir.items[0].conditions.forEach(el => {
        if (this.treeSelectField[el.fieldNote]) {
          if (Object.prototype.toString.call(el.itemValue) == '[object String]') {
            if (el.itemValue == '') {
              el.itemValue = []
            } else {
              el.itemValue = el.itemValue.split()
            }
          }
        }
      })
      this.keyword = JSON.parse(JSON.stringify(temp.searchParam.eir.items))
      this.commonChangeOptions(temp.searchParam.indexId, '日志类型', 'indexId', 'select')
      this.keyword[0].conditions.forEach(item => {
        this.conditionKeywordSelect(item.itemCondition, item)
      })
      this.queryForm = JSON.parse(JSON.stringify(temp.searchParam))
      this.queryPeriod.periodTime = [this.queryForm.beginTime, this.queryForm.endTime]
      this.queryForm.indexId = temp.searchParam.indexId
      this.search()
    },
    // 配置记录
    configRecord() {
      this.cfgRecordQuery.logRetrievaRuleMap.indexId = this.queryForm.indexId
      this.isShowForm = false
      this.tableLoading = true
      searchRuleConfig(this.cfgRecordQuery).then(resp => {
        if (resp.data.returnCode == '0') {
          this.cfgRecordData = resp.data.data.list
          this.pageCfg.size = resp.data.data.page.size
          this.pageCfg.current = resp.data.data.page.current
          this.pageCfg.total = resp.data.data.page.total
          this.configRecordDialog = true
          this.tableLoading = false
        }
        this.loading = false
      }, error => {
        this.tableLoading = false
        this.$message.error(error.returnMsg)
      })
    },
    handleCurrentCfgRChange(current) {
      this.cfgRecordQuery.page.current = current
      this.configRecord()
    },
    ruleDel(row) {
      this.deleteData.ids = []
      this.deleteData.ids.push(row.ruleId)
      this.confirmDel()
    },
    // 删除前确认
    confirmDel() {
      this.$confirm('是否确定删除当前查询策略?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handledel()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handledel() {
      delRuleConfig(this.deleteData).then(rep => {
        if (rep.data.returnCode == '0') {
          this.deleteData.ids = []
          this.cfgRecordQuery.page.current = 1
          this.configRecord()
          this.$message.success('策略规则删除成功！')
        }
      })
    }

  }
}
</script>
<style>
  .el-popover ::-webkit-scrollbar {
    width: 2px; /* 对纵向滚动条起作用*/
    background: #dcdfe6;
  }
  /* 滚动条最外面滑块样式 :: 前面保留一个空格*/
  .el-popover ::-webkit-scrollbar-thumb {
    background: #dcdfe6;
    border-radius: 2px;
    width: 2px; /* 对纵向滚动条起作用*/
  }

  .logManagerTreeSelect .dropdownCls {
    min-width: auto;
    padding-right: 15px;
  }
  .conditions-form .keyFieldsForm .el-row {
    display: flex;
  }
  .conditions-form .indexId .el-form-item__label {
    color: #606266;
    font-size: 12px;
    font-weight: 700;
  }
</style>
<style scoped>
  .name {
    background: #f4fafb;
    border:1px solid #cad9ea;
  }
  .border{
    border: 1px solid #cdd9e3;
    height: 40px;
    line-height: 40px;
    font-weight: 500;
    font-size:12px;
    padding:0 12px 0;
  }
  .conditions-form{
    padding-top:0px;
    padding-left:6px;
    margin-bottom:0px;
    position: relative;
    max-height:400px;
    overflow-y:scroll;
  }
  .label-title{
    color:#606266;
    font-weight:700;
    line-height:32px;
    font-size:12px;
    text-align:right;
    max-width:44%;
    display:inline-block;
    padding-right: 12px;
    width: 90px;
    white-space: nowrap;
    overflow-x: hidden;
    text-overflow: ellipsis;
  }
  .form_mainctn{
    width:100%;
    height: auto;
    position: relative;
  }
  .search_forms{
    margin-top:5px;
  }
  .formContainer{
    clear: both;
    width: 100%;
    overflow:hidden;
    height: auto;
    min-height:32px;
    border:1px solid #dcdfe6;
    vertical-align:middle;
    border-radius:3px;
    cursor: pointer;
  }
  .operContainer{
    padding-left:8px;
  }
  .tag-css{
    height: 26px;
    margin:3px 6px;
    line-height: 26px;
  }
  .filter-condition{
    height:100%;
    float:left;
    overflow:hidden;
  }
  .filter-condition-width{
    width: 94%;
  }
  .search-btn,
  .reset-btn{
    width:86px;
    margin-left:0px !important;
  }
  .config-record-btn{
    width: 100px;
    margin-left:0px !important;
  }
  .config-btn{
    width:100%;
    height:32px;
    line-height:32px;
    text-align:right;
    color:#409EFF;
    cursor: pointer;
    font-size: 13px;;
  }
  .save-container{
    height:32px;
    float:right;
    text-align:center;
    line-height:32px;
    color:#6fb6ff;
    font-size:22px;
    font-weight: bolder;
    background:#f3f3f3;
  }
  .save-container-width1{
    width:6%;
  }
  .retrievalPointer {
    cursor: pointer;
  }
  /**关键字配置 */
  .checkbox{
    /* width:24%; */
    width:230px;
    margin-left:0px !important;
    margin-right:0px;
  }
  .circle:hover{
    border-color:#ffffff;
    background:#409fee;
  }
  .nodata_text{
    text-align:center;
    height:20px;
    line-height:20px;
    font-size:12px;
    /* background:#DFDFDF; */
    width:80px;
    padding:3px;
    color:#838383;
    font-weight:500;
    border-radius:3px;
    position:absolute;
    top:60%;
    left:50%;
    transform:translate(-50%,-50%);
  }
  .nodata{
    height:300px;
    text-align:center;
    position:relative;
  }
  .nodata img{
    max-width:100%;
    /* height: */
    max-height:200px;
    max-width:250px;
    position:absolute;
    top:40%;
    left:50%;
    transform:translate(-50%,-50%);
  }
  .container-title .buttonTabs {
    position: absolute;
    right: 0;
  }

</style>
<style scoped>
  .dialog-cfg .el-dialog__body{
    padding:30px 20px;
    z-index: 999;
  }
  .input_indexNote .el-input__inner{
    border:1px solid #fff;
    padding:0px 0px 0px 26px;
  }
</style>
