<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-header height="auto">
        <!-- 条件查询工具栏 -->
        <div class="header-search">
          <div class="search-input-box">
            <label>{{ $t('AlarmQuery.beginTimestamp') }}</label>
            <el-date-picker
              v-model="beginTimestamp"
              type="datetime"
              size="mini"
              format="yyyy-MM-dd HH:mm"
              clearable="false"
              align="center"
              :picker-options="startDatePicker"
              @change="beginDateChange"
              :placeholder="$t('AlarmQuery.chooseStartTime')">
            </el-date-picker>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.endTimestamp") }}</label>
            <el-date-picker
              v-model="endTimestamp"
              type="datetime"
              size="mini"
              format="yyyy-MM-dd HH:mm"
              clearable="false"
              align="center"
              :picker-options="endDatePicker"
              @change="endDateChange"
              :placeholder="$t('AlarmQuery.chooseEndTime')">
            </el-date-picker>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.DeviceType") }}</label>
            <el-select size='mini'
                       v-model="deviceType"
                       :placeholder="$t('common.placeholder')"
                       :clearable="true"
                       @change="deviceTypeChange">
              <el-option
                v-for="item in deviceTypeList"
                :key="item.deviceTypeKey"
                :label="item.deviceTypeName"
                :value="item.deviceTypeKey">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.DeviceType1") }}</label>
            <el-select size='mini'
                       v-model="deviceModel"
                       :placeholder="$t('common.placeholder')"
                       @change="deviceModelChange"
                       :clearable="true">
              <el-option v-for="item in deviceModelList"
                         :key="item.deviceModelKey"
                         :label="item.deviceModel"
                         :value="item.deviceModel">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.DeviceName") }}</label>
            <el-select size='mini' v-model="queryDeviceName" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in deviceList"
                :key="item.deviceKey"
                :label="item.displayName"
                :value="item.deviceKey">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.AlarmCause") }}</label>
            <el-select size='mini' v-model="queryAlarmCause" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in optionsAlarmCause"
                :key="item.alarmCode"
                :label="item.alarmName"
                :value="item.alarmCode">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.AlarmLevel") }}</label>
            <el-select size='mini' v-model="alarmLevel" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in optionsAlarmLevel"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.AlarmStatus") }}</label>
            <el-select size='mini' v-model="alarmStatus" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in optionsAlarmStauts"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <el-button size='mini' icon="el-icon-search" type="primary" @click="queryAlarmDataByCondition"
                       v-loading.fullscreen.lock="fullscreenLoading">{{$t('common.queryBtn')}}
            </el-button>
            <el-button size='mini' icon="el-icon-download" type="success" @click="downloadInit = true"
                       v-loading.fullscreen.lock="fullscreenLoading">{{$t('common.exportBtn')}}
            </el-button>
          </div>
        </div>
      </el-header>
      <!-- table数据表格 -->
      <el-main class="adapt-height-box">
        <el-table
          :empty-text="$t('common.noData')"
          header-row-class-name="table-header"
          cell-class-name="table-cell"
          class="adapt-height"
          ref="multipleTable"
          :data="alarmList"
          stripe
          tooltip-effect="dark"
          :highlight-current-row="true"
          height="auto"
          border
          :default-sort="{prop: 'firstTime', order: 'descending'}">
          <el-table-column
            type="index"
            :label="$t('AlarmQuery.No')">
          </el-table-column>
          <el-table-column
            :prop="isLink"
            :label="$t('AlarmQuery.isLink')"
            :formatter="formatAlarmType"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="elementName"
            :label="$t('AlarmQuery.deviceName')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="deviceTypeName"
            :label="$t('AlarmQuery.deviceType')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="deviceModel"
            :label="$t('AlarmQuery.deviceType1')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="resourceName"
            width="100"
            :label="$t('AlarmQuery.portName')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="alarmName"
            :label="$t('AlarmQuery.cause')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="alarmLevel"
            :label="$t('AlarmQuery.alarmLevel')"
            :formatter="formatAlarmLevel">
          </el-table-column>
          <el-table-column
            prop="alarmStatus"
            :label="$t('AlarmQuery.alarmStatus')"
            :formatter="formatAlarmStatus">
          </el-table-column>
          <el-table-column
            prop="firstTime"
            :label="$t('AlarmQuery.firstTime')"
            sortable
            :min-width="'首次发生时间'.length * 25"
            :formatter="formatFirstDate">
          </el-table-column>
          <el-table-column
            prop="recoverTime"
            :label="$t('AlarmQuery.recoverTime')"
            sortable
            :min-width="'告警恢复时间'.length * 25"
            :formatter="formatRecoverDate">
          </el-table-column>
          <el-table-column
            prop="curTime"
            :label="$t('AlarmQuery.curTime')"
            sortable
            :min-width="'最近发生时间'.length * 25"
            :formatter="formatCurDate">
          </el-table-column>
          <el-table-column
            prop="confirmTime"
            :label="$t('AlarmQuery.confirmTime')"
            sortable
            :min-width="'告警确认时间'.length * 25"
            :formatter="formatConfirmDate">
          </el-table-column>
          <el-table-column
            prop="confirmUser"
            :label="$t('AlarmQuery.confirmUser')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="clearTime"
            :label="$t('AlarmQuery.clearTime')"
            sortable
            :min-width="'告警清除时间'.length * 25"
            :formatter="formatClearDate">
          </el-table-column>
          <el-table-column
            prop="clearUser"
            :label="$t('AlarmQuery.clearUser')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="deleteTime"
            :label="$t('AlarmQuery.deleteTime')"
            sortable
            :min-width="'告警删除时间'.length * 25"
            :formatter="formatClearDate">
          </el-table-column>
          <el-table-column
            prop="deleteUser"
            :label="$t('AlarmQuery.deleteUser')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="note"
            :label="$t('AlarmQuery.note')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            fixed="right"
            width="103px"
            :label="$t('common.operation')">
            <template slot-scope="scope">
              <el-button
                size="mini"
                style="background: #53D214"
                :title="$t('AlarmQuery.view')"
                @click="viewDetail(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-chakan"></use>
                </svg>
              </el-button>
              <el-button
                v-if="queryCreateAlarmMangExpCommand.visible"
                size="mini"
                style="background: #175BE3"
                :title="$t('common.createBtn')"
                @click="createAlarmMangExpInit(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-zengjia-cuxiantiao"></use>
                </svg>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-main>
    </el-container>

    <el-dialog
      v-dialogDrag
      title="导出文件格式选择"
      :visible.sync="downloadInit"
      width="400px"
      height="360px"
      style="font-size: 20px; "
    >
      <div>
        <el-radio-group v-model="radio1"  size="mini">
          <el-radio label="excel表格" border>excel</el-radio>
          <el-radio label="csv" border>csv</el-radio>
        </el-radio-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" icon='el-icon-circle-check' @click="exportToInit" size="mini">{{$t("common.ok")}}</el-button>
        <el-button icon='el-icon-circle-close' @click="downloadCancle" size="mini">{{$t("common.cancel")}}</el-button>
      </span>
    </el-dialog>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>
</template>

<script>
import AlarmManagerService from '@/domain/services/AlarmManagerService.js'
import DeviceService from '@/domain/services/DeviceService.js'
import HelperUtil from '../../utils/HelperUtil'
import AlarmMangExpCommands from "../../commands/AlarmMangExpCommands";
import CommandExecuteContext from "../../commands/CommandExecuteContext";

export default {
  name: 'AlarmQuery',
  data: function () {
    return {
      fullscreenLoading: false,
      commandContext: {},
      downloadInit: false, // 文件下载弹出框显示与否
      radio1: 'excel表格',
      rowDeviceKey: 'deviceKey', // 表格的设备编号（有deviceKey , serverKey两种）
      // 日期控件
      beginTimestamp: '', // 开始时间
      endTimestamp: '', // 结束时间
      addTimestamp: '00.000', // 查询时间默认添加
      addTimestamp1: '59.999', // 查询时间默认添加
      startDatePicker: this.beginDate(),
      endDatePicker: this.endDate(),
      // 查询条件
      queryDeviceName: '', // 设备名称
      deviceModel: '', // 网元型号
      queryAlarmCause: '', // 告警原因
      alarmLevel: '', // 告警等级：0警告；1严重；2紧急
      alarmStatus: '', // 状态：0告警；1已确认；2已清除；3已恢复：需对应
      // 下拉菜单选择域
      // 网元型号选择域
      optionsDeviceType1: [],
      optionsDeviceType2: [], // 给表格过滤使用
      // 设备名称选择域
      optionsDeviceName: [],
      // 服务器名称选择域
      optionServerName: [],
      // 告警原因选择域
      optionsAlarmCause1: [],
      // 告警原因选择域（备份：包含全部的告警原因）
      optionsAlarmCause0: [],
      // 设备对应的内容
      optionsAlarmCause: [],
      // 服务器对应的内容（SDNC服务器未识别、磁盘使用率过高、CPU使用率过高、内存使用率过高）
      // 告警等级选择域
      optionsAlarmLevel: [{
        value: '0',
        label: this.$t('AlarmQuery.MinorAlarm')
      }, {
        value: '1',
        label: this.$t('AlarmQuery.MajorAlarm')
      }, {
        value: '2',
        label: this.$t('AlarmQuery.CriticalAlarm')
      }
      ],
      // 告警状态选择域
      optionsAlarmStauts: [{
        value: '0',
        label: this.$t('AlarmQuery.Notconfirmed')
      }, {
        value: '1',
        label: this.$t('AlarmQuery.Confirmed')
      }, {
        value: '2',
        label: this.$t('AlarmQuery.Cleared')
      }, {
        value: '3',
        label: this.$t('AlarmQuery.Restored')
      }, {
        value: '4',
        label: this.$t('AlarmQuery.Delete')
      }],
      deviceModelList: [], // 设备型号列表
      // 告警列表实体类：未确认
      elementKey: '',
      isLink: '',
      alarmCode: '', // 告警码
      alarmCount: '', // 频次
      deviceTypeKey: '',
      firstTime: '', // 首次发生时间
      curTime: '', // 最近发生时间
      recoverTime: '', // 恢复时间
      clearTime: '', // 清除时间
      confirmTime: '', // 确认时间
      confirmUser: '', // 确认用户
      note: '', // 其他信息
      UserList: [], // 用户列表
      deviceTypeList: [],

      // 双向绑定展示数据
      alarmList: [],
      // 选择条件
      selectList: [],

      beginItem: 1,
      endItem: 100,
      count: 10000,
      total: 100,
      currentPage: 1,
      pageSize: 100,
      optionsAlarmDeviceType: [],
      // 服务器类型列表
      deviceType: '', // 设备类型
      deviceList: [], // 设备列表
      deviceList0: [],
      deviceModelList0: [],
      deviceModelList1: [],
      createAndCopyTitle: '',
      createAndCopyInitList: {}
    }
  },
  created: function () {
    this.setDefaultDateTime()
    this.getAlarmTypeList()
    this.getAllDeviceType()
    this.getAllDevice()
    this.getAllDeviceModel()
  },
  computed: {
    queryCreateAlarmMangExpCommand () {
      return AlarmMangExpCommands.queryCreateAlarmMangExpCommand(this.createAndCopyTitle, this.createAndCopyInitList, this.commandContext)
    },
    openTab () {
      return this.$store.state.openTab
    }
  },
  methods: {
    /**
     * @Description  : 查看经验维护
     * @author       : ls
     * @date         : 2020/7/29 9:01
     * @param        :
     * @return       :
     */
    viewDetail: function (row) {
      let flag = false
      for (let item of this.openTab) {
        if (item.name === '告警经验维护') {
          this.$store.commit('delete_keepAliveRouter', 'AlarmMangExp')
          this.$store.commit('delete_tabs', '/TheLayout/AlarmMangExp')
          this.$store.commit('add_tabs', {route: '/TheLayout/AlarmMangExp', name: '告警经验维护', title: 'TheLayoutHeader.AlarmMangExp'})
          this.$store.commit('set_active_index', '/TheLayout/AlarmMangExp')
          this.$store.commit('add_keepAliveRouter', 'AlarmMangExp')
          this.$router.push({path: '/TheLayout/AlarmMangExp', query: {alarmMangExp: row}})
          flag = true
          break
        }
      }
      if (!flag) {
        this.$store.commit('add_tabs', {route: '/TheLayout/AlarmMangExp', name: '告警经验维护', title: 'TheLayoutHeader.AlarmMangExp'})
        this.$store.commit('add_keepAliveRouter', 'AlarmMangExp')
        this.$store.commit('set_active_index', '/TheLayout/AlarmMangExp')
        this.$router.push({path: '/TheLayout/AlarmMangExp', query: {alarmMangExp: row}})
      }
    },
    /**
     * @Description  : 创建告警经验
     * @author       : ls
     * @date         : 2020/7/24 16:26
     * @param        :
     * @return       :
     */
    createAlarmMangExpInit: function (val) {
      this.createAndCopyTitle = this.$t('AlarmMangExp.createAlarmMangExp')
      this.createAndCopyInitList = val
      this.queryCreateAlarmMangExpCommand.execute()
    },
    /***
     * @Description  : 检测时间合法
     * @author       : zf
     * @date         : 2019/1/21 13:37
     */
    // 设置禁止选择当前日期之后的时间，且开始时间小于结束时间
    beginDate: function () {
      let self = this
      return {
        disabledDate (time) {
          return time.getTime() > self.endTimestamp.getTime() || time.getTime() > Date.now()
        }
      }
    },
    // 结束时间必须大于开始时间
    endDate: function () {
      let self = this
      return {
        disabledDate (time) {
          return time.getTime() < self.beginTimestamp.getTime() || time.getTime() > Date.now()
        }
      }
    },
    // 开始时间被清空后重新赋值
    beginDateChange: function () {
      const setTimes = new Date()
      if (this.beginTimestamp === null) {
        setTimes.setTime(this.endTimestamp.getTime() - (60 * 60 * 1000))
        this.beginTimestamp = setTimes
        // 开始时间不能为空
        this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.START_TIME_EMPTY_CODE))
      }
      if (this.beginTimestamp > this.endTimestamp) {
        setTimes.setTime(this.endTimestamp.getTime() - (60 * 60 * 1000))
        this.beginTimestamp = setTimes
        // 开始时间不能大于结束时间
        this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.START_END_TIME_CODE))
      }
      this.changeValuePeriod()
    },
    // 结束时间被清空后重新赋值
    endDateChange: function () {
      const setTimes = new Date()
      const curTimes = new Date()
      if (this.endTimestamp === null) {
        if ((this.beginTimestamp.getTime() + (60 * 60 * 1000)) > curTimes.getTime()) {
          this.endTimestamp = curTimes
        } else {
          setTimes.setTime(this.beginTimestamp.getTime() + (60 * 60 * 1000))
          this.endTimestamp = setTimes
        }

        this.InfoTip.warningTip_alarm(this, {message: this.$t('AlarmQuery.endTimeEmpty')})

        //          this.$message({
        //            type: 'error',
        //            message: '结束时间不能为空！',
        //            //duration: 10000,
        //            showClose: true,
        //          });
      }
      if (this.endTimestamp < this.beginTimestamp) {
        if ((this.beginTimestamp.getTime() + (60 * 60 * 1000)) > curTimes.getTime()) {
          this.endTimestamp = curTimes
        } else {
          setTimes.setTime(this.beginTimestamp.getTime() + (60 * 60 * 1000))
          this.endTimestamp = setTimes
        }
        // 开始时间不能大于结束时间
        this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.START_END_TIME_CODE))

        //          this.$message({
        //            type: 'error',
        //            message: '结束时间不能小于开始时间！',
        //            //duration: 10000,
        //            showClose: true,
        //          });
      }
      if (this.endTimestamp > curTimes) {
        if ((this.beginTimestamp.getTime() + (60 * 60 * 1000)) > curTimes.getTime()) {
          this.endTimestamp = curTimes
        } else {
          setTimes.setTime(this.beginTimestamp.getTime() + (60 * 60 * 1000))
          this.endTimestamp = setTimes
        }
        // 结束时间不能大于当前时间
        this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.END_TIME_CURRENT_CODE))

        //          this.$message({
        //            type: 'error',
        //            message: '结束时间不能大于当前时间！',
        //            //duration: 10000,
        //            showClose: true,
        //          });
      }
      this.changeValuePeriod()
    },
    /**
     * @Description  : deviceTypeChange
     * @author       : ls
     * @date         : 2020/11/17 23:48
     * @param        :
     * @return       :
     */
    deviceTypeChange: function () {
      var a = HelperUtil.deviceTypeChangeDevice(this.deviceModelList1, this.deviceType, this.deviceModel, this.deviceList0)
      this.deviceModelList = a[0]
      this.deviceModel = a[1]
      this.queryDeviceName = ''
      this.deviceList = []
      this.deviceList = a[2]



      // this.deviceModel = ''
      // this.queryDeviceName = ''
      // this.deviceModelList = []
      // this.deviceList = []
      // for (let j in this.deviceModelList0) {
      //   if (this.deviceType === null) {
      //     this.deviceModelList.push(this.deviceModelList0[j])
      //   } else {
      //     if (this.deviceModelList0[j]['deviceTypeKey'] === this.deviceType) {
      //       this.deviceModelList.push(this.deviceModelList0[j])
      //     }
      //   }
      // }
      // for (let i in this.deviceList0) {
      //   if (this.deviceType === null) {
      //     this.deviceList.push(this.deviceList0[i])
      //   } else {
      //     if (this.deviceType === this.deviceList0[i].deviceTypeKey) {
      //       this.deviceList.push(this.deviceList0[i])
      //     }
      //   }
      // }
    },
    /**
     * @Description  : deviceModelChange
     * @author       : ls
     * @date         : 2020/11/17 23:48
     * @param        :
     * @return       :
     */
    deviceModelChange: function () {
      this.queryDeviceName = ''
      this.deviceList = []
      this.deviceList = HelperUtil.deviceModelChange(this.deviceType, this.deviceModel, this.deviceList0)

      // this.queryDeviceName = ''
      // this.deviceList = []
      // for (let k in this.deviceList0) {
      //   if (this.deviceModel === null) {
      //     if (this.deviceType === null) {
      //       this.deviceList.push(this.deviceList0[k])
      //     }
      //   } else {
      //     if (this.deviceModel === this.deviceList0[k]['deviceModel']) {
      //       if (this.deviceType === null) {
      //         this.deviceList.push(this.deviceList0[k])
      //       } else {
      //         if (this.deviceType === this.deviceList0[k]['deviceTypeKey']) {
      //           this.deviceList.push(this.deviceList0[k])
      //         }
      //       }
      //     }
      //   }
      // }
    },
    /***
     * @Description  : 告警等级过滤器
     * @author       : zf
     * @date         : 2018/12/24 16:07
     */
    formatAlarmLevel: function (row, column) {
      if (row.alarmLevel === 0) {
        return this.$t('AlarmQuery.MinorAlarm')
      } else if (row.alarmLevel === 1) {
        return this.$t('AlarmQuery.MajorAlarm')
      } else if (row.alarmLevel === 2) {
        return this.$t('AlarmQuery.CriticalAlarm')
      } else {
        return ''
      }
    },
    /**
     * @Description  : formatAlarmType
     * @author       : ls
     * @date         : 2020/11/8 16:30
     * @param        :
     * @return       :
     */
    formatAlarmType: function (row, column) {
      if (row.isLink === 0) {
        return this.$t('AlarmQuery.nodeAlarm')
      } else if (row.isLink === 1) {
        return this.$t('AlarmQuery.linkAlarm')
      } else {
        return this.$t('AlarmQuery.businessAlarm')
      }
    },
    /***
     * @Description  : 告警状态过滤器
     * @author       : zf
     * @date         : 2018/12/24 16:07
     */
    formatAlarmStatus: function (row, column) {
      if (row.alarmStatus === 0) {
        return this.$t('AlarmQuery.Notconfirmed')
      } else if (row.alarmStatus === 1) {
        return this.$t('AlarmQuery.Confirmed')
      } else if (row.alarmStatus === 2) {
        return this.$t('AlarmQuery.Cleared')
      } else if (row.alarmStatus === 3) {
        return this.$t('AlarmQuery.Restored')
      } else if (row.alarmStatus === 4) {
        return this.$t('AlarmQuery.Delete')
      } else {
        return ''
      }
    },

    /***
     * @Description  : 告警日期过滤
     * @author       : zf
     * @date         : 2019/1/2 19:40
     */
    formatCurDate: function (row, column) {
      var showDate
      var arr

      if (row.curTime !== '') {
        arr = row.curTime.split('.')
        showDate = '' + arr[0].substring(0, 4) + '-' + arr[0].substring(4, 6) + '-' + arr[0].substring(6, 8) + ' '
        showDate = showDate + arr[1].substring(0, 2) + ':' + arr[1].substring(2, 4) + ':' + arr[1].substring(4, 6)
      } else {
        showDate = ''
      }
      //        console.log(showDate)
      return showDate
    },

    /***
     * @Description  : 确认日期过滤
     * @author       : zf
     * @date         : 2019/1/2 19:40
     */
    formatConfirmDate: function (row, column) {
      var showDate
      var arr
      if (row.confirmTime === '') {
        showDate = ''
      } else {
        arr = row.confirmTime.split('.')
        showDate = '' + arr[0].substring(0, 4) + '-' + arr[0].substring(4, 6) + '-' + arr[0].substring(6, 8) + ' '
        showDate = showDate + arr[1].substring(0, 2) + ':' + arr[1].substring(2, 4) + ':' + arr[1].substring(4, 6)
      }
      return showDate
    },

    /***
     * @Description  : 恢复日期过滤
     * @author       : zf
     * @date         : 2019/1/2 19:40
     */
    formatRecoverDate: function (row, column) {
      var showDate
      var arr
      if (row.recoverTime === '') {
        showDate = ''
      } else {
        arr = row.recoverTime.split('.')
        showDate = '' + arr[0].substring(0, 4) + '-' + arr[0].substring(4, 6) + '-' + arr[0].substring(6, 8) + ' '
        showDate = showDate + arr[1].substring(0, 2) + ':' + arr[1].substring(2, 4) + ':' + arr[1].substring(4, 6)
      }
      return showDate
    },

    /***
     * @Description  : 首次发生日期过滤
     * @author       : zf
     * @date         : 2019/1/2 19:40
     */
    formatFirstDate: function (row, column) {
      var showDate
      var arr

      if (row.firstTime !== '') {
        arr = row.firstTime.split('.')
        showDate = '' + arr[0].substring(0, 4) + '-' + arr[0].substring(4, 6) + '-' + arr[0].substring(6, 8) + ' '
        showDate = showDate + arr[1].substring(0, 2) + ':' + arr[1].substring(2, 4) + ':' + arr[1].substring(4, 6)
      } else {
        showDate = ''
      }
      //        console.log(showDate)
      return showDate
    },

    /***
     * @Description  : 最近发生日期过滤
     * @author       : zf
     * @date         : 2019/1/2 19:40
     */
    formatClearDate: function (row, column) {
      var showDate
      var arr

      if (row.clearTime !== '') {
        arr = row.clearTime.split('.')
        showDate = '' + arr[0].substring(0, 4) + '-' + arr[0].substring(4, 6) + '-' + arr[0].substring(6, 8) + ' '
        showDate = showDate + arr[1].substring(0, 2) + ':' + arr[1].substring(2, 4) + ':' + arr[1].substring(4, 6)
      } else {
        showDate = ''
      }
      //        console.log(showDate)
      return showDate
    },
    /**
     * ---------------------------初始化页面数据---------------------------
     * */

    /***
     * @Description  : 获取默认时间
     * @author       : zf
     * @date         : 2019/1/4 11:32
     */
    setDefaultDateTime: function () {
      console.log('setDefaultDateTime')
      const start = new Date()
      const end = new Date()
      start.setTime(start.getTime() - 3600 * 1000)
      this.beginTimestamp = start
      this.endTimestamp = end
    },
    /**
     * @Description  : getAllDevice
     * @author       : ls
     * @date         : 2020/11/18 0:43
     * @param        :
     * @return       :
     */
    getAllDeviceModelListSelf: function () {
      for (let key in this.deviceList) {
        let containIs = false
        for (let i in this.deviceModelList) {
          if (this.deviceList[key].deviceModel === this.deviceModelList[i].value) {
            containIs = true
            break
          }
        }
        if (containIs === false && this.deviceList[key].deviceModel !== '') {
          let device = {}
          device.key = key
          device.deviceTypeKey = this.deviceList[key].deviceTypeKey
          device.label = this.deviceList[key].deviceModel
          device.value = this.deviceList[key].deviceModel
          this.deviceModelList.push(device)
          this.deviceModelList0.push(device)
        }
      }
    },
    /**
     * @Description  :获取全部网元类型
     * @author       :zyh
     * @date         :2020/1/7
     */
    getAllDeviceType: function () {
      let _this = this
      DeviceService.getAllDeviceTypeCollection().then(result => {
        _this.deviceTypeList = Object.values(result)
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },

    /**
     * @Description  :获取全部网元
     * @author       :zyh
     * @date         :2020/1/7
     */
    getAllDevice: function () {
      let _this = this
      DeviceService.getAllDeviceCollection().then(result => {
        _this.deviceList = Object.values(result)
        _this.deviceList0 = Object.values(result)
        // _this.getAllDeviceModelListSelf()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /**
     * @Description  : getAllDeviceModel
     * @author       : ls
     * @date         : 2021/3/8 16:51
     * @param        :
     * @return       :
     */
    getAllDeviceModel: function () {
      let _this = this
      DeviceService.getAllDeviceModelCollection().then(result => {
        _this.deviceModelList = Object.values(result)
        _this.deviceModelList1 = Object.values(result)
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /***
     * @Description  : 获取告警列表
     * @author       : lxy
     * @date         : 2018/12/20 20:17
     */
    getAlarmTypeList: function () {
      // console.log('获取告警列表')
      let _this = this
      AlarmManagerService.getAlarmTypeList().then(result => {
        // 成功
        _this.optionsAlarmCause = Object.values(result)
        console.log(this.optionsAlarmCause)
        _this.optionsAlarmCause1 = Object.values(result)
      }).catch(err => {
        // 失败
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /***
     * @Description  : 获取查询条件列表
     * @author       : zf
     * @date         : 2019/1/4 11:29
     */
    setQuerySelectList: function () {
      this.selectList = []
      var year
      var month
      var day
      var hours
      var minutes
      if (this.beginTimestamp !== '') {
        year = '' + this.beginTimestamp.getFullYear()
        month = '' + (this.beginTimestamp.getMonth() + 1)
        day = '' + this.beginTimestamp.getDate()
        hours = '' + this.beginTimestamp.getHours()
        minutes = '' + this.beginTimestamp.getMinutes()
        if (month.length === 1) {
          month = '0' + month
        }
        if (day.length === 1) {
          day = '0' + day
        }
        if (hours.length === 1) {
          hours = '0' + hours
        }
        if (minutes.length === 1) {
          minutes = '0' + minutes
        }
        var begin = '' + year + month + day + '.' + hours + minutes + this.addTimestamp
        console.log('开始时间')
        console.log(begin)
        this.selectList.push({
          quaryAttribute: 'firstTime',
          compareSymbol: '>=',
          compareValue: begin
        })
      }
      if (this.endTimestamp !== '') {
        year = '' + this.endTimestamp.getFullYear()
        month = '' + (this.endTimestamp.getMonth() + 1)
        day = '' + this.endTimestamp.getDate()
        hours = '' + this.endTimestamp.getHours()
        minutes = '' + this.endTimestamp.getMinutes()
        if (month.length === 1) {
          month = '0' + month
        }
        if (day.length === 1) {
          day = '0' + day
        }
        if (hours.length === 1) {
          hours = '0' + hours
        }
        if (minutes.length === 1) {
          minutes = '0' + minutes
        }
        var end = '' + year + month + day + '.' + hours + minutes + this.addTimestamp1
        console.log('结束时间')
        console.log(end)
        this.selectList.push({
          quaryAttribute: 'firstTime',
          compareSymbol: '<=',
          compareValue: end
        })
      }
      if (this.queryDeviceName !== '' && this.queryDeviceName !== null) {
        this.selectList.push({
          quaryAttribute: 'deviceKey',
          compareSymbol: '=',
          compareValue: this.queryDeviceName
        })
      }
      if (this.deviceModel !== '' && this.deviceModel !== null) {
        this.selectList.push({
          quaryAttribute: 'deviceModel',
          compareSymbol: '=',
          compareValue: this.deviceModel
        })
      }
      if (this.deviceType !== '' && this.deviceType !== null) {
        this.selectList.push({
          quaryAttribute: 'deviceTypeKey',
          compareSymbol: '=',
          compareValue: this.deviceType
        })
      }
      if (this.queryAlarmCause !== '' && this.queryAlarmCause !== null) {
        this.selectList.push({
          quaryAttribute: 'alarmCode',
          compareSymbol: '=',
          compareValue: this.queryAlarmCause
        })
      }
      if (this.alarmLevel !== '' && this.alarmLevel !== null) {
        this.selectList.push({
          quaryAttribute: 'alarmLevel',
          compareSymbol: '=',
          compareValue: parseInt(this.alarmLevel)
        })
      }
      if (this.alarmStatus !== '' && this.alarmStatus !== null) {
        this.selectList.push({
          quaryAttribute: 'alarmStatus',
          compareSymbol: '=',
          compareValue: parseInt(this.alarmStatus)
        })
      }
    },

    /***
     * @Description  : 当前页面变化获取新的告警List
     * @author       : zf
     * @date         : 2018/12/20 20:12
     */
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.currentPage = val
      this.beginItem = ((val - 1) * 100) + 1
      this.endItem = this.beginItem + 99
      if (this.endItem > this.total) {
        this.endItem = this.total
      }
      console.log('当前页' + this.beginItem + this.endItem)
      this.queryAlarmDataByConditionCurrentPage()
    },

    /***
     * @Description  : 点击查询按钮事件
     * @author       : zf
     * @date         : 2018/12/13 16:37
     */
    queryAlarmDataByCondition: function () {
      console.log('告警数据按条件查询')
      this.beginItem = 1
      this.alarmList = []
      //        this.optionsDeviceType2 = Object.assign({},this.optionsDeviceType1);
      this.optionsDeviceType2 = JSON.parse(JSON.stringify(this.optionsDeviceType1))
      this.setQuerySelectList()
      this.queryAlarmDataTotalNumber()
    },

    /***
     * @Description  : 按条件查询性能数据总条数
     * @author       : zf
     * @date         : 2018/12/13 16:37
     */
    queryAlarmDataTotalNumber: function () {
      console.log('告警数据按条件查询：总条数')
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      // 查询告警总条数
      AlarmManagerService.getTotalCounts(this.selectList).then(result => {
        // 成功
        _this.total = result
        _this.Loading.closeLoading(loadingInstance)
        console.log('性能数据按条件查询：总条数' + this.total)
        if (this.total === 0 || this.total < 0) {
          _this.InfoTip.warningTip_alarm(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
        } else {
          if (this.total < 100 && this.total > 0) {
            this.endItem = this.total
          } else {
            this.endItem = 100
          }
          // 获取该分页的告警内容
          this.queryAlarmDataByConditionCurrentPage()
        }
      }).catch(err => {
        // 失败
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },

    /***
     * @Description  : 获取当前分页性能列表
     * @author       : lxy
     * @date         : 2018/12/20 20:17
     */
    queryAlarmDataByConditionCurrentPage: function () {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      AlarmManagerService.queryAlarmPaging(this.beginItem, this.endItem, this.selectList).then(result => {
        // 成功
        _this.alarmList = Object.values(result)
        _this.Loading.closeLoading(loadingInstance)
      }).catch(err => {
        // 失败
        this.$message.error('分页数据请求失败！')
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },

    /**
     * ---------------------------导出功能实现---------------------------
     * */
    /**
     * @Description  ：导出文件
     * @author       : bjh
     * @param        :
     * @return       :
     * @exception    :
     * @date         : 2018/12/19 18:39
     */
    // exportToExcelInit: function () {
    //   let _this = this;
    //   this.setQuerySelectList();
    //   let loadingInstance = _this.Loading.openLoading();
    //   AlarmManagerService.downloadAlarmConfig(this.selectList).then(result => {
    //     //成功
    //     _this.Loading.closeLoading(loadingInstance);
    //   }).catch(err => {
    //     //失败
    //     _this.Loading.closeLoading(loadingInstance);
    //     _this.InfoTip.errorTip(_this, err);
    //   })
    // },

    exportToInit: function () {
      switch (this.radio1) {
        case 'excel表格':
          this.exportToExcel()
          break
        case 'csv':
          this.exportToCsv()
          break
        default:
          this.exportToExcel()
      }
    },

    // 导出格式为excel
    exportToExcel: function () {
      this.downloadInit = false
      let _this = this
      this.setQuerySelectList()
      let loadingInstance = _this.Loading.openLoading()
      AlarmManagerService.downloadAlarmConfig(this.selectList).then(result => {
        // 成功
        this.radio1 = 'excel表格'
        _this.Loading.closeLoading(loadingInstance)
      }).catch(err => {
        // 失败
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },

    // 导出格式为csv
    exportToCsv: function () {
      this.downloadInit = false
      let _this = this
      this.setQuerySelectList()
      let loadingInstance = _this.Loading.openLoading()
      AlarmManagerService.downloadAlarmConfigCsv(this.selectList).then(result => {
        // 成功
        this.radio1 = 'excel表格'
        _this.Loading.closeLoading(loadingInstance)
      }).catch(err => {
        // 失败
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
      })
    },

    downloadCancle: function () {
      this.downloadInit = false
      this.radio1 = 'excel表格'
    }
  },
  components: {
    CommandExecuteContext
  }
}
</script>

<style scoped>

</style>
