<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-divider content-position="left">历史性能数据条件删除</el-divider>
      <el-header height="auto" style="background-color:inherit">
        <!-- 条件查询工具栏 -->
        <div class="header-search">
          <div class="search-input-box">
            <label>{{$t("Performance.startTime") + '：'}}</label>
            <el-date-picker
              v-model="beginTimestamp"
              type="datetime"
              size="mini"
              format="yyyy-MM-dd HH:mm"
              :clearable="true"
              align="center"
              :picker-options="startDatePicker"
              @change="beginDateChange"
              :placeholder="$t('Performance.startTimePlaceholder')">
            </el-date-picker>
          </div>
          <div class="search-input-box">
            <label>{{$t("Performance.endTime") + '：'}}</label>
            <el-date-picker
              v-model="endTimestamp"
              type="datetime"
              size="mini"
              format="yyyy-MM-dd HH:mm"
              :clearable="true"
              align="center"
              :picker-options="endDatePicker"
              @change="endDateChange"
              :placeholder="$t('Performance.endTimePlaceholder')">
            </el-date-picker>
          </div>
          <div class="search-input-box">
            <label>{{$t("Performance.networkElementType") + '：'}}</label>
            <el-select v-model="nodeType" size="mini" :placeholder="$t('common.selectOption')" :clearable="true" @change="changeNodeType">
              <el-option
                v-for="item in deviceTypeList"
                :key="item.deviceTypeKey"
                :label="item.deviceTypeKey"
                :value="item.deviceTypeKey">
              </el-option>
            </el-select>
          </div>
          <br>
          <div class="search-input-box">
            <label>{{$t("Performance.networkElementName") + '：'}}</label>
            <el-select v-model="deviceKey" size="mini" :placeholder="$t('common.selectOption')"
                       :disabled="queryDeviceShow" :clearable="true">
              <el-option
                v-for="item in queryDeviceOptions1"
                :key="item.deviceKey"
                :label="item.displayName"
                :value="item.displayName">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{$t("Performance.performanceEvent") + '：'}}</label>
            <el-select v-model="performType" size="mini" :placeholder="$t('common.selectOption')" :clearable="true">
              <el-option
                v-for="item in performTypeList"
                :key="item.deviceParam"
                :label="item.peformTypeName"
                :value="item.deviceParam">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">

            <el-button size='mini' icon="el-icon-delete" type="primary" @click="deletePerformDataByConditionInit" v-if="deletePerformanceCommand">{{$t("common.deleteBtn")}}</el-button>
          </div>
        </div>
      </el-header>

      <el-divider content-position="left">历史告警数据条件删除</el-divider>

      <el-header height="auto" style="background-color:inherit">
        <!-- 条件查询工具栏 -->
        <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="queryAlarmDeviceType"
              :placeholder="$t('common.placeholder')"
              :clearable="true"
              @change="deviceTypeChange"
            >
              <el-option
                v-for="item1 in deviceTypeList"
                :key="item1.deviceTypeKey"
                :label="item1.deviceTypeKey"
                :value="item1.deviceTypeKey">
              </el-option>
            </el-select>
          </div>
          <br>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.DeviceType1") }}</label>
            <el-select size='mini' v-model="queryDeviceType1" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item1 in deviceModelList1"
                :key="item1.key"
                :label="item1.label"
                :value="item1.value">
              </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="item1 in optionsDeviceName1"
                :key="item1.deviceKey"
                :label="item1.displayName"
                :value="item1.displayName">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t("AlarmQuery.AlarmCause") }}</label>
            <el-select size='mini' v-model="cause" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item1 in optionsAlarmCause"
                :key="item1.alarmCode"
                :label="item1.alarmName"
                :value="item1.alarmCode">
              </el-option>
            </el-select>
          </div>
          <br>
          <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="item1 in optionsAlarmLevel"
                :key="item1.value"
                :label="item1.label"
                :value="item1.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="item1 in optionsAlarmStauts"
                :key="item1.value"
                :label="item1.label"
                :value="item1.value">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <el-button size='mini' icon="el-icon-delete" type="primary" @click="deleteAlarmDataByConditionInit" v-if="deleteAlarmCommand"
                       v-loading.fullscreen.lock="fullscreenLoading">{{$t('common.deleteBtn')}}
            </el-button>
          </div>
        </div>
      </el-header>
    </el-container>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>

</template>

<script>
  // import DeviceService from '../../domain/services/DeviceService'
  // import ServerService from '../../domain/services/ServerService'
  import DeviceService from '@/domain/services/DeviceService.js'
  import ServerService from '@/domain/services/ServerService.js'
  import PerformanceMonitorService from '../../domain/services/PerformanceMonitorService'
  import PerformanceDataDeleteService from '../../domain/services/PerformanceDataDeleteService'
  import AlarmDataDeleteService from '../../domain/services/AlarmDataDeleteService'
  import PerformanceManager from '../../domain/models/PerformanceManager'
  import DeviceManager from '../../domain/models/DeviceManager'
  import HelperUtil from '../../utils/HelperUtil'



  import AlarmManagerService from '@/domain/services/AlarmManagerService.js'

  import CommandExecuteContext from '@/commands/CommandExecuteContext'
  import PerformanceDataSafeCommands from '@/commands/PerformanceDataSafeCommands'


  export default {
    name: 'PerformanceDataQuery',

    components: {
      CommandExecuteContext,
    },

    //创建期间
    beforeCreate() {

    },
    //vue加载初始化函数，加载数据
  created: function () {
      this.setDefaultDateTime()
      this.getAllDevice1()
      this.getAllPerformType()


  /*--------------------------- ls历史告警数据清除初始化方法开始 ---------------------------*/
     this.getAllDeviceType()
     this.getAlarmTypeList()
     this.getAlarmTypeList1()
     this.getAllDevice(() => {
      this.getAllDeviceModelList()
     })

  /*--------------------------- ls历史告警数据清除初始化方法开始 ---------------------------*/

    },

    //存放数据
    data: function () {
      return {

        commandContext: {},
        deviceKeyShow: true,

        //日期控件
        beginTimestamp: "",  //开始时间
        endTimestamp: "",  //结束时间
        addBeginTimestamp: "00.000",  //查询开始时间默认添加
        addEndTimestamp: "59.999", //查询结束时间默认添加
        startDatePicker: this.beginDate(),
        endDatePicker: this.endDate(),

        //查询条件控件
        queryDeviceOptions: [],  //设备名称
        queryDeviceShow: false,  //设备名称选择器是否禁用
        deviceKey: "", //设备ID（对应设备名称）（下拉列表）
        deviceCollection:{},  //设备collection

        performTypeList: [], //全部性能事件
        performTypeCollection: {},
        queryPerformTypeOptions: [],  //性能事件选项
        performType: "", //性能属性（事件）（下拉列表）


        nodeType: null,  //节点类型0：设备；1：服务器（下拉列表）

        //双向绑定展示数据
        performList: [],

        //查询条件List
        //ls删除条件
        selectList: [],

        //多选分页控制
        multipleSelection: [],
        beginItem: 1,
        endItem: 100,
        total: 100,
        currentPage: 1,
        pageSize: 100,



        //ls历史告警数据条件清除所需条件数据
        queryDeviceName: "",  //设备名称
        queryDeviceType1: "",  //网元型号
        alarmLevel: "",  //告警等级：0警告；1严重；2紧急
        cause: '',  //报警状态
        alarmStatus: '', //状态：0告警；1已确认；2已清除；3已恢复：需对应
        //下拉菜单选择域
        //网元型号选择域
        optionsDeviceType1:[],
        optionsDeviceType2:[],  //给表格过滤使用
        //设备名称选择域
        optionsDeviceName: [],
        optionsDeviceName1: [],
        //服务器名称选择域
        optionServerName: [],
        //告警原因选择域
        optionsAlarmCause1: [],
        //告警原因选择域（备份：包含全部的告警原因）
        optionsAlarmCause0: [],
        //设备对应的内容
        optionsAlarmCause: [],
        //服务器对应的内容（SDNC服务器未识别、磁盘使用率过高、CPU使用率过高、内存使用率过高）
        optionsAlarmCause2: [
          {
            code:"1005",
            cause:"SDNC服务器未识别",
          },
          {
            code:"3001",
            cause:"磁盘使用率过高",
          },
          {
            code:"3002",
            cause:"CPU使用率过高",
          },
          {
            code:"3003",
            cause:"内存使用率过高",
          },
        ],
        //告警等级选择域
        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: [],
        deviceModelList1: [],//设备型号列表
        //告警列表实体类：未确认
        alarmCode: "", //告警码
        alarmCount: "", //频次
        firstTime: "", //首次发生时间
        curTime: "",  //最近发生时间
        recoverTime: "", //恢复时间
        clearTime: "", //清除时间
        confirmTime: "",  //确认时间
        confirmUser: "", //确认用户
        note: "",  //其他信息
        UserList: [], //用户列表

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

        beginItem: 1,
        endItem: 100,
        count: 10000,
        total: 100,
        currentPage: 1,
        pageSize: 100,
        deviceTypeList: [],

        queryAlarmDeviceType: null,  //设备类型
        deviceList: [],  //设备列表
      }

    },

    methods: {
      /**
       * @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       : 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() - 1000 * 3600 * 24) || 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))
        }
        if ((this.endTimestamp.getTime() - this.beginTimestamp.getTime()) > 24 * 60 * 60 * 1000) {
          setTimes.setTime(this.beginTimestamp.getTime() + (24 * 60 * 60 * 1000));
          this.endTimestamp = setTimes;
          this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PERIOD_TIME_CODE))
        }
      },
      //结束时间被清空后重新赋值
      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, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.END_TIME_EMPTY_CODE))
        }
        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))
        }
        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))
        }
        if ((this.endTimestamp.getTime() - this.beginTimestamp.getTime()) > 24 * 3600 * 1000) {
          setTimes.setTime(this.endTimestamp.getTime() - (24 * 60 * 60 * 1000));
          this.beginTimestamp = setTimes;
          this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PERIOD_TIME_CODE))
        }
      },


      /***
       * @Description  : 日期过滤
       * @author       : zf
       * @date         : 2019/1/2 19:40
       */
      formatDate: function (row, column) {
        var showDate;
        var arr;
        if (row.timestamp !== "") {
          arr = row.timestamp.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) + '.' + arr[2];
        }
        else {
          showDate = row.timestamp
        }
        return showDate
      },


      /***
       * @Description  : 网元类型网元名称/性能事件下拉框名称
       * @author       : zf
       * @date         : 2019/03/29 23:21
       */
      changeNodeType: function () {
        this.queryDeviceOptions1 = [];

        let DevMgr = DeviceManager(this.deviceCollection);
        this.queryDeviceOptions = Object.values(DevMgr.getInUsingDeviceList());

        for (var i=0; i < this.queryDeviceOptions.length;i++){
          if (this.nodeType === this.queryDeviceOptions[i]['deviceTypeKey']){
            this.queryDeviceOptions1.push(this.queryDeviceOptions[i])
          }
          if (this.nodeType === null || this.nodeType === ''){
            this.queryDeviceOptions1.push(this.queryDeviceOptions[i])
          }

        }
      },

      // /***
      //  * @Description  : 网元类型联动表头
      //  * @author       : zf
      //  * @date         : 2019/05/23 09:59
      //  */
      // nodeTypeDefineTable: function () {
      //   if (this.nodeType === 1) {
      //     this.deviceKeyShow = false;
      //   }
      //   else {
      //     this.deviceKeyShow = true;
      //   }
      // },

      /*---------------------------初始化页面数据---------------------------*/

      /***
       * @Description  : 获取默认时间
       * @author       : zf
       * @date         : 2019/1/4 11:32
       */
      setDefaultDateTime: function () {
        const start = new Date();
        const end = new Date();
        start.setTime(start.getTime() - 3600 * 1000);
        this.beginTimestamp = start;
        this.endTimestamp = end
      },

      /***
       * @Description  : 设备/服务器下拉列表
       * @author       : zf
       * @date         : 2018/12/24 11:29
       */
      getAllDevice1: function () {
        let _this = this;
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          _this.deviceCollection = result;
          let DevMgr = DeviceManager(_this.deviceCollection);
          _this.queryDeviceOptions = Object.values(DevMgr.getInUsingDeviceList());
          _this.queryDeviceOptions1 = Object.values(DevMgr.getInUsingDeviceList());
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        });
      },

      /***
       * @Description  : 获取全部性能事件
       * @author       : zf
       * @date         : 2019/03/29 23:09
       */
      getAllPerformType: function () {
        let _this = this;
        PerformanceMonitorService.getAllPerformanceTypeCollection().then(result => {
          //成功
          _this.performTypeList = Object.values(result);
          _this.performTypeCollection = result;
          _this.setQueryPerformTypeOption();
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /***
       * @Description  : 设置性能事件下拉列表
       * @author       : zf
       * @date         : 2019/03/29 23:10
       */
      setQueryPerformTypeOption: function () {
        let PerformanceMgr = PerformanceManager(this.performTypeCollection);
        if(this.nodeType === 0){
          this.queryPerformTypeOptions = PerformanceMgr.getPerformanceListByNodeTypeNode();
        }
        if(this.nodeType === 1){
          this.queryPerformTypeOptions = PerformanceMgr.getPerformanceListByNodeTypeServer();
        }
      },

      /*---------------------------查询功能实现---------------------------*/

      /***
       * @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 !== '' && this.beginTimestamp !== null) {
          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.addBeginTimestamp;
          this.selectList.push({
            quaryAttribute: 'timestamp',
            compareSymbol: ">=",
            compareValue: begin,
          })
        }
        if (this.endTimestamp !== '' && this.endTimestamp !== null) {
          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.addEndTimestamp;
          this.selectList.push({
            quaryAttribute: 'timestamp',
            compareSymbol: "<=",
            compareValue: end,
          })
        }
        if (this.deviceKey !== '' && this.deviceKey !== null) {
          this.selectList.push({
            quaryAttribute: 'displayName',
            compareSymbol: "like",
            compareValue: this.deviceKey,
          })
        }
        if (this.performType !== '' && this.performType !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceParam',
            compareSymbol: "like",
            compareValue: this.performType,
          })
        }
        if (this.nodeType !== '' && this.nodeType !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceTypeKey',
            compareSymbol: "like",
            compareValue: this.nodeType,
          });
        }
      },

      /***
       * @Description  : 当前页面变化获取新的性能List
       * @author       : zf
       * @date         : 2018/12/20 20:12
       */
      handleCurrentChange(val) {
        this.currentPage = val;
        this.beginItem = ((val - 1) * 100) + 1;
        this.endItem = this.beginItem + 99;
        if (this.endItem > this.total) {
          this.endItem = this.total
        }
        this.queryPerformDataByConditionCurrentPage();
      },

     //----------------------------删除性能数据方法------------------------------//


      deletePerformDataByConditionInit:function(){

        this.setDeletePerformanceSelectList()
        this.deletePerformanceCommand.execute()

      },
      //ls删除历史性能数据(已经被上面的方法替代)
      deletePerformDataByCondition: function(){
        this.setDeletePerformanceSelectList();
        this.deletePerformanceData();
      },

      //ls拼接删除条件
      setDeletePerformanceSelectList: function () {
        this.selectList = [];
        var year;
        var month;
        var day;
        var hours;
        var minutes;
        if (this.beginTimestamp !== '' && this.beginTimestamp !== null) {
          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.addBeginTimestamp;
          this.selectList.push({
            quaryAttribute: 'timestamp',
            compareSymbol: ">=",
            compareValue: begin,
          })
        }
        if (this.endTimestamp !== '' && this.endTimestamp !== null) {
          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.addEndTimestamp;
          this.selectList.push({
            quaryAttribute: 'timestamp',
            compareSymbol: "<=",
            compareValue: end,
          })
        }
        if (this.deviceKey !== '' && this.deviceKey !== null) {
          this.selectList.push({
            quaryAttribute: 'displayName',
            compareSymbol: "like",
            compareValue: this.deviceKey,
          })
        }
        if (this.performType !== '' && this.performType !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceParam',
            compareSymbol: "=",
            compareValue: this.performType,
          })
        }
        if (this.nodeType !== '' && this.nodeType !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceTypeKey',
            compareSymbol: "=",
            compareValue: this.nodeType,
          });
        }
      },

      deletePerformanceData: function () {
        let _this = this;
        let loadingInstance = _this.Loading.openLoading();
        PerformanceDataDeleteService.deletePerformData(this.selectList).then(result => {
          //成功
          _this.Loading.closeLoading(loadingInstance);
          this.InfoTip.successTip(this,HelperUtil.getStatusCodeObjectByCode(this.successCode.DELETE_CODE));
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /***
       * @Description  : 获取当前分页性能列表
       * @author       : zf
       * @date         : 2018/12/20 20:17
       */
      queryPerformDataByConditionCurrentPage: function () {
        let _this = this;
        let loadingInstance = _this.Loading.openLoading();
        PerformanceDataQuaryService.queryPerformDataSplitNumber(this.beginItem ,this.endItem,this.selectList).then(result => {
          //成功
          _this.performList = Object.values(result);
          _this.Loading.closeLoading(loadingInstance);
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /*---------------------------导出功能实现---------------------------*/

      /**
       * @Description  ：导出文件
       */
      exportToExcelInit: function () {
        this.setQuerySelectList();
        let _this = this;
        let loadingInstance = _this.Loading.openLoading();
        PerformanceDataQuaryService.exportToExcel(this.selectList).then(result => {
          //成功
          _this.Loading.closeLoading(loadingInstance);
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.errorTip(_this, err);
        })

      },

      /*--------------------------- ls历史告警数据清除方法开始 ---------------------------*/

      //获取告警信息列表
      getAlarmTypeList: function () {
        //console.log('获取告警列表')
        let _this = this;
        AlarmManagerService.getAlarmTypeList().then(result => {
          //成功
          _this.optionsAlarmCause = Object.values(result);
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },


      //获取告警信息列表备用
      getAlarmTypeList1: function () {
        let _this = this;
        AlarmManagerService.getAlarmTypeList().then(result => {
          //成功
          _this.optionsAlarmCause0 = Object.values(result);
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },


      /***
       * @Description  : 设备下拉列表
       * @author       : zf
       * @date         : 2018/12/24 11:29
       */
      getAllDevice: async function (callback = () =>{}) {
        //判断设备类型
        //设备类型是网元
        let _this = this;
        this.optionsDeviceName = [];
        if (_this.queryAlarmDeviceType === 0) {
          let a = DeviceService.getAllDeviceCollection().then(result => {
            //成功
            _this.optionsDeviceName = Object.values(result);
            _this.optionsDeviceName1 = Object.values(result);
            this.getAllDeviceModelList()
          }).catch(err => {
            //失败
            _this.InfoTip.errorTip(_this, err);
          });
          await a;
        }

        //设备类型是空
        if (this.queryAlarmDeviceType === null || this.queryAlarmDeviceType === "") {
          DeviceService.getAllDeviceCollection().then(result => {
            //成功
            _this.optionsDeviceName = Object.values(result);
            _this.optionsDeviceName1 = Object.values(result);
            _this.deviceList = Object.values(result);
            this.getAllDeviceModelList()
            callback();
          }).catch(err => {
            //失败
            _this.InfoTip.errorTip(_this, err);
          });
        }
      },


      //网元型号下拉列表
      deviceType1List:function () {
        this.queryDeviceType1 = '';
        if(this.queryAlarmDeviceType === 0){  //设备
          this.getAllDeviceModelList();
          this.optionsDeviceType1 =  this.deviceModelList;
        }else if(this.queryAlarmDeviceType === 1){  //服务器
          this.optionsDeviceType1 = this.serverTypeList;
        }else{
          this.getAllDeviceModelList();
          this.optionsDeviceType1 =  this.deviceModelList;
          this.optionsDeviceType1 = this.optionsDeviceType1.concat(this.serverTypeList);
        }
      },


      /***
       * @Description  : 获取设备型号列表
       * @author       : lxy
       * @date         : 2018/12/24 11:29
       */
      getAllDeviceModelList:function() {
        for (let key in this.optionsDeviceName) {
          //标记该设备型号是否已经存在在列表当中
          let containIs = false;
          //判断设备型号是否已经存在在设备型号列表当中
          for (let j = 0; j < this.deviceModelList.length; j++) {
            if (this.optionsDeviceName[key].deviceModel === this.deviceModelList[j].value) {
              containIs = true;
              break;
            }
          }
          //如果没有存在，存入设备型号列表当中
          if (containIs === false && this.optionsDeviceName[key].deviceModel !== "") {
            let device = {};
            device.key = this.optionsDeviceName[key].deviceTypeKey;
            device.label = this.optionsDeviceName[key].deviceModel;
            device.value = this.optionsDeviceName[key].deviceModel;
            this.deviceModelList.push(device);
            this.deviceModelList1.push(device);
          }
        }
        console.log(this.deviceModelList1)
      },






      deviceTypeChange: function () {
        this.queryDeviceType1 = "";
        this.queryDeviceName = "";
        this.queryAlarmCause = "";
        this.optionsDeviceName1 = [];
        this.optionsAlarmCause1 = [];
        this.deviceModelList1 = [];

        for (var i=0; i< this.optionsDeviceName.length;i++){
          if (this.queryAlarmDeviceType === null || this.queryAlarmDeviceType === ''){
            this.optionsDeviceName1.push(this.optionsDeviceName[i])
          }
          if (this.queryAlarmDeviceType === this.optionsDeviceName[i]['deviceTypeKey']){
            this.optionsDeviceName1.push(this.optionsDeviceName[i])
          }
        }

        for (var j=0; j<this.deviceModelList.length;j++){
          if (this.queryAlarmDeviceType === null || this.queryAlarmDeviceType === ''){
            this.deviceModelList1.push(this.deviceModelList[j])
          }
          if (this.queryAlarmDeviceType === this.deviceModelList[j]['key']){
            this.deviceModelList1.push(this.deviceModelList[j])
          }
        }
      },

      //-----------------删除告警数据方法-----------------------//
      deleteAlarmDataByConditionInit: function () {
        this.setDeleteAlarmDataSelectList()
        this.deleteAlarmCommand.execute()
      },

     //-----------------ls拼接告警数据删除条件-------------------//
      setDeleteAlarmDataSelectList: 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.beginTimestamp !== '' && this.beginTimestamp !== null) {
          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.addBeginTimestamp;
          this.selectList.push({
            quaryAttribute: 'firstTime',
            compareSymbol: ">=",
            compareValue: begin,
          })
        }
        if (this.endTimestamp !== '' && this.endTimestamp !== null) {
          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.addEndTimestamp;
          this.selectList.push({
            quaryAttribute: 'firstTime',
            compareSymbol: "<=",
            compareValue: end,
          })
        }

        if (this.queryDeviceName !== '' && this.queryDeviceName !== null) {
//          if (this.queryAlarmDeviceType === 0) {  //当选择的是网元，则上传deviceKey
//            this.selectList.push({
//              quaryAttribute: 'deviceKey',
//              compareSymbol: "==",
//              compareValue: this.queryDeviceName,
//            })
//          }
//          else if (this.queryAlarmDeviceType === 1) {   //当选择的是服务器，则上传serverKey
//            this.selectList.push({
//              quaryAttribute: 'deviceKey',
//              compareSymbol: "==",
//              compareValue: this.queryDeviceName,
//            })
//          }
          this.selectList.push({
            quaryAttribute: 'displayName',
            compareSymbol: "like",
            compareValue: this.queryDeviceName,
          })
        }
        if (this.queryDeviceType1 !== '' && this.queryDeviceType1 !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceModel',
            compareSymbol: "=",
            compareValue: this.queryDeviceType1,
          })
        }
        if (this.queryAlarmDeviceType !== '' && this.queryAlarmDeviceType !== null) {
          this.selectList.push({
            quaryAttribute: 'deviceTypeKey',
            compareSymbol: "=",
            compareValue: this.queryAlarmDeviceType,
          })
        }
        if (this.cause !== '' && this.cause !== null) {
          this.selectList.push({
            quaryAttribute: 'alarmCode',
            compareSymbol: "=",
            compareValue: this.cause,
          })
        }
        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),
          })
        }
      },


     //---------------ls告警删除调用方法---------------//
      deleteAlarmData: function () {
        let _this = this;
        let loadingInstance = _this.Loading.openLoading();
       AlarmDataDeleteService.deleteAlarmData(this.selectList).then(result => {
          //成功
          _this.Loading.closeLoading(loadingInstance);
          this.InfoTip.successTip(this,HelperUtil.getStatusCodeObjectByCode(this.successCode.DELETE_CODE));
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /*--------------------------- ls历史告警数据清除方法结束 ---------------------------*/

      /*---------------------------留用---------------------------*/

      /***
       * @Description  : 多选框变化：未用
       * @author       : zf
       * @date         : 2019/1/4 11:33
       */
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    },

    computed: {

      deletePerformanceCommand () {
        return PerformanceDataSafeCommands.deletePerformanceDataCommand(this.selectList, this.commandContext)
      },
      deleteAlarmCommand () {
        return PerformanceDataSafeCommands.deleteAlarmDataCommand(this.selectList, this.commandContext)
      }

    },

    watch:{
    }
  }
</script>

<style scoped>
</style>
