<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-header height="auto">
        <!-- 通用工具栏 -->
        <div class="header-button-box">
          <el-button size='mini' icon="el-icon-circle-plus-outline" type="primary" @click="createElineTemplateInit" v-if="createAndCopyCommand.visible">
            {{$t('common.createBtn')}}
          </el-button>
          <el-button size='mini' icon="el-icon-document" type="primary" @click="copyElineTemplateInit" v-if="createAndCopyCommand.visible">
            {{$t('common.copyBtn')}}
          </el-button>
          <el-button size='mini' icon="el-icon-edit" type="primary" @click="updateElineTemplateInit" v-if="updateElineCommand.visible">
            {{$t('common.updateBtn')}}
          </el-button>
          <el-button size='mini' icon="el-icon-delete" type="primary" @click="deleteElineInit" >
            {{$t('common.deleteBtn')}}
          </el-button>
        </div>
        <!-- 条件查询工具栏 -->
        <div class="header-search">
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.vpnId") }}:</label>
            <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="queryVpnId" clearable></el-input>
          </div>
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.serviceName") }}:</label>
            <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="queryServiceName" clearable></el-input>
          </div>
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.serviceTypeID") }}:</label>
            <el-select v-model="queryServiceTypeID" size="mini" :placeholder="$t('common.placeholder')"
                       :clearable="true">
              <el-option
                v-for="item in ServiceTypeList"
                :key="item.serviceTypeID"
                :label="item.serviceTypeName"
                :value="item.serviceTypeID">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.startDeviceId") }}:</label>
            <el-select v-model="queryStartDevice" size="mini" :placeholder="$t('common.placeholder')"
                       :clearable="true">
              <el-option
                v-for="item in deviceList"
                :key="item.deviceKey"
                :label="item.deviceName"
                :value="item.deviceKey">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.end1DeviceId") }}:</label>
            <el-select v-model="queryEndDevice" size="mini" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in deviceList"
                :key="item.deviceKey"
                :label="item.deviceName"
                :value="item.deviceKey">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label style="width: 79px">{{ $t("EthernetELineServiceConfigurationManagement.protectionMode") }}:</label>
            <el-select v-model="queryProtectionMode" size="mini" :placeholder="$t('common.placeholder')" :clearable="true">
              <el-option
                v-for="item in protectionModeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <el-button icon="el-icon-search" type="primary" size = 'mini' @click="queryElineByCondition" v-loading.fullscreen.lock="fullscreenLoading">{{$t('common.queryBtn')}}</el-button>
          </div>
        </div>
      </el-header>
      <!-- table数据表格 -->
      <el-main class="adapt-height-box">
        <el-table
          :empty-text="$t('common.noData')"
          tooltip-effect="dark"
          stripe
          header-row-class-name="table-header"
          cell-class-name="table-cell"
          class="adapt-height"
          height="auto"
          border
          ref="singleTable"
          :data="ElineList"
          highlight-current-row
          @current-change="handleCurrentChange"
          @selection-change="handleSelectionChange">

          <el-table-column
            type="selection"
            width="28">
          </el-table-column>
          <!-- 新增一列 ,查看路由视图 -->
          <el-table-column
            fixed
            :label="$t('EthernetELineServiceConfigurationManagement.routeView')"
            width="100">
            <template slot-scope="scope">
              <el-button
                style="margin-top:-3.8px"
                @click.native.prevent="handleRouteView(scope.$index, scope.row)"
                type="text"
                size="small">
                {{ $t("EthernetELineServiceConfigurationManagement.view") }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            text-align="left"
            prop="vpnId"
            :label="$t('EthernetELineServiceConfigurationManagement.vpnId')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            text-align="left"
            prop="serviceName"
            :label="$t('EthernetELineServiceConfigurationManagement.serviceName')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            text-align="left"
            prop="serviceTypeID"
            :label="$t('EthernetELineServiceConfigurationManagement.serviceTypeID')"
            :formatter="formatServerType"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            text-align="left"
            prop="serviceSubnetID"
            :label="$t('EthernetELineServiceConfigurationManagement.serviceSubnetID')"
            :formatter="formatServiceSubnetID"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="protectionMode"
            :label="$t('EthernetELineServiceConfigurationManagement.protectionMode')"
            :formatter="formatProtectionMode"
            width="120"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="reversion"
            :label="$t('EthernetELineServiceConfigurationManagement.reversion')"
            :formatter="formatReversionFlag"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="wtr"
            :label="$t('EthernetELineServiceConfigurationManagement.wtr')"
            width="100"
            :formatter="formatWtr"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="oamInfo"
            :label="$t('EthernetELineServiceConfigurationManagement.oamInfo')"
            :formatter="formatOamInfo"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="ccmInterval"
            :label="$t('EthernetELineServiceConfigurationManagement.ccmInterval')"
            :formatter="formatccmInterval"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="encapsulationType"
            :label="$t('EthernetELineServiceConfigurationManagement.encapsulationType')"
            width="100"
            :formatter="formatEncapsulationType"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="l2AccessType"
            :label="$t('EthernetELineServiceConfigurationManagement.l2AccessType')"
            width="100"
            :formatter="formatL2AccessType"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="vlanAccess"
            :label="$t('EthernetELineServiceConfigurationManagement.vlanAccess')"
            width="100"
            :formatter="formatVlanAccess"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="vlanRangeStart"
            :label="$t('EthernetELineServiceConfigurationManagement.vlanRangeStart')"
            width="120"
            :formatter="formatVlanRangeStart"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="vlanRangeEnd"
            :label="$t('EthernetELineServiceConfigurationManagement.vlanRangeEnd')"
            width="120"
            :formatter="formatVlanRangeEnd"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="vlanSet"
            :label="$t('EthernetELineServiceConfigurationManagement.vlanSet')"
            width="120"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="startDeviceId"
            :label="$t('EthernetELineServiceConfigurationManagement.startDeviceId')"
            width="100"
            :formatter="formatStartDeviceId"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="startDevicePort"
            :label="$t('EthernetELineServiceConfigurationManagement.startDevicePort')"
            width="120"
            :formatter="formatStartDevicePort"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="end1DeviceId"
            :label="$t('EthernetELineServiceConfigurationManagement.end1DeviceId')"
            width="100"
            :formatter="formatEnd1DeviceId"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="end1DevicePort"
            :label="$t('EthernetELineServiceConfigurationManagement.end1DevicePort')"
            width="120"
            :formatter="formatEnd1DevicePort"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="isDualHomed"
            :label="$t('EthernetELineServiceConfigurationManagement.isDualHomed')"
            width="100"
            :formatter="formatIsDualHomed"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="end2DeviceId"
            :label="$t('EthernetELineServiceConfigurationManagement.end2DeviceId')"
            width="140"
            :formatter="formatEnd2DeviceId"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="end2DevicePort"
            :label="$t('EthernetELineServiceConfigurationManagement.end2DevicePort')"
            width="160"
            :formatter="formatEnd2DevicePort"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="cosId"
            label="cos-Id"
            :formatter="formatCosId"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="limitedBandwidth"
            :label="$t('EthernetELineServiceConfigurationManagement.limitedBandwidth')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="qosProfile"
            :label="$t('EthernetELineServiceConfigurationManagement.qosProfile')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="startTime"
            :label="$t('EthernetELineServiceConfigurationManagement.startTime')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="elineStatus"
            :label="$t('EthernetELineServiceConfigurationManagement.elineStatus')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>

    <!-- E-line路由视图对话框-->
    <ElineRouteViewDialog
      :routeViewDialogVisible.sync = 'routeViewDialogShow'
      :routePathObject = 'routePathObject'
      :topologyCollection = 'topologyCollection'
      :drawGraphSizeConfig = 'drawGraphSizeConfig'
      :endPointObject = 'endPointObject'>
    </ElineRouteViewDialog>

    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>


  </div>
</template>

<script>
  import ElineRouteViewDialog from '../DialogComponents/ElineDialog/ElineRouteViewDialog.vue';
  import ElRow from "element-ui/packages/row/src/row";
  import ElDialog from "../../../node_modules/element-ui/packages/dialog/src/component.vue";
  import CreateEthernetELineServiceConfigurationManagementDialog from '../DialogComponents/ElineDialog/CreateEthernetELineServiceConfigurationManagementDialog.vue';
  import UpdateEthernetELineServiceConfigurationManagementDialog from '../DialogComponents/ElineDialog/UpdateEthernetELineServiceConfigurationManagementDialog.vue';
  import DeleteEthernetELineServiceConfigurationManagementDialog from '../DialogComponents/ElineDialog/DeleteEthernetELineServiceConfigurationManagementDialog.vue';
  import ElineService from '@/domain/services/Business/ElineService.js'
  import ServiceTypeService from '@/domain/services/Business/ServiceTypeService.js'
  import CDPService from '@/domain/services/Business/CDPService.js'
  import DeviceService from '@/domain/services/DeviceService.js'
  import CommandExecuteContext from '@/commands/CommandExecuteContext';
  import ElineCommands from '@/commands/ElineCommands'
  import HelperUtil from "../../utils/HelperUtil";
  import ServiceSubnetService from '@/domain/services/Business/ServiceSubnetService.js'

  export default {
    components: {
      ElDialog,
      ElRow,
      ElineRouteViewDialog,
      CommandExecuteContext
    },
    name: 'EthernetELineServiceConfigurationManagementFather',
    props: {
      topologyCollection: null,
    },
    data: function () {   //存放数据
      return {
        routeViewDialogShow: false,
        routePathObject: null,
        endPointObject: null,
        drawGraphSizeConfig: {
          svgWidth: 1200,
          svgHeight: 300,
          imageWidth: 32,
          imageHeight: 32,
          textSize: 14,
        },
        //命令
        commandContext: {},
        fullscreenLoading: false,

        //创建修改复制窗口是否打开
        dialog_elineCreate: false,
        dialog_elineUpdate: false,
        //删除标记
        deleteFlag: false,

        //-----------------表格数据过滤---------------------------------------
        //业务类型过滤
        ServiceTypeList: [],
        //保护模式过滤
        protectionModeList: [
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.unprotected')
          },
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.one2one')
          },
          {
            value: 2,
            label: this.$t('EthernetELineServiceConfigurationManagement.lspone2one')
          },
        ],
        //是否回滚过滤
        reversionFlag: [
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.is')
          },
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.no')
          }
        ],
        //oam选项过滤
        oamInfoFlag: [
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.is')
          },
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.no')
          }
        ],
        //ccm间隔时间过滤
        ccmIntervalList: [
          {
            ccmIntervalTime: '3.3min',
            value:1
          },
          {
            ccmIntervalTime: '10min',
            value:2
          },
          {
            ccmIntervalTime: '60min',
            value:3
          },
          {
            ccmIntervalTime: '100min',
            value:4
          },
          {
            ccmIntervalTime: '600min',
            value:5
          },
          {
            ccmIntervalTime: '6000min',
            value:6
          }
        ],
        //vlan类别过滤
        encapsulationTypeList: [
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.ethernetType')
          },
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.vlanType')
          }
        ],
        //l2AccessType类别过滤
        l2AccessTypeList:[
          {
            value: 0,
            label: "untag"
          },
          {
            value: 1,
            label: "dot1q"
          },
          {
            value: 2,
            label: "qinq"
          },
        ],
        //是否双规模式过滤
        isDualHomedList:[
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.no')
          },
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.is')
          }
        ],
        //vlan设置方式过滤
        vlanAccessList: [
          {
            value: 0,
            label: this.$t('EthernetELineServiceConfigurationManagement.vlanRange1')
          },
          {
            value: 1,
            label: this.$t('EthernetELineServiceConfigurationManagement.vlanSet')
          }
        ],
        //cos-id过滤
        cosIdList: [
          {
            value: 0,
            label: '0'
          },
          {
            value: 1,
            label: '1'
          },
          {
            value: 2,
            label: '2'
          },
          {
            value: 3,
            label: '3'
          },
          {
            value: 4,
            label: '4'
          },
          {
            value: 5,
            label: '5'
          },
          {
            value: 6,
            label: '6'
          },
          {
            value: 7,
            label: '7'
          },
        ],
        //*****双向绑定展示数据*********
        //假数据
        ElineList: [],

        //-------------剩余的变量列表------------------------------------
        //qos策略名称下拉框列表绑定
        CDPProfileCreationList: [],
        //业务起点设备下拉框列表
        startDeviceIdList: [],
        //业务起点设备端口下拉框列表
        startDevicePortList: [],
        //业务终点设备下拉框列表
        end1DeviceIdList: [],
        //业务终点设备端口下拉框列表
        end1DevicePortList: [],
        //第二个业务终点设备下拉框列表
        end2DeviceIdList: [],
        //第二个业务终点设备端口下拉框列表
        end2DevicePortList: [],
        //业务状态下拉框列表
        elineStatusList: [
          {
            value: "submitted",
            label: 'submitted'
          },
          {
            value: "success",
            label: 'success'
          },
          {
            value: "failure",
            label: 'failure'
          },
        ],
        //获取的eline设备列表(第一个string是子网ID,第二个就是对应的设备)
        elineDeviceList: [],

        //*******条件查询***********************
        queryVpnId:'', //业务ID
        queryServiceName: '',//业务名称
        queryServiceTypeID: '',   //业务类型
        queryStartDevice: '',   //起点设备
        queryEndDevice: '',   //终点设备
        queryProtectionMode: '',//保护模式

        //创建复制标题
        createAndCopyTitle: '',
        //双向绑定弹出窗口input域
        form: {
          vpnId:"",
          serviceName: "",
          serviceTypeID: "",
          protectionMode: "",
          reversion: "",
          wtr: "",
          oamInfo: "",
          ccmInterval: "",
          encapsulationType: "",
          l2AccessType: "",
          startDeviceId: "",
          startDevicePort: "",
          end1DeviceId: "",
          end1DevicePort: "",
          isDualHomed:"",
          end2DeviceId: "",
          end2DevicePort: "",
          vlanAccess: "",
          vlanRangeStart: "",
          vlanRangeEnd: "",
          vlanSet: "",
          cosId: "",
          limitedBandwidth: "",
          qosProfile: "",
          startTime: "",
          elineStatus: "submitted",
          serviceSubnetID: "",
        },
        //创建初始化
        initList: {},
        //保存当前行数据
        currentRow: null,
        //保存多选行数据
        multipleSelection: [],
        //设备列表
        deviceList: [],
        //删除列表
        deleteList:[],
        //子网列表
        subnetList: [],
      }
    },
    //vue加载初始化函数,加载数据
    created: function () {
      console.log('业务管理界面初始化:')
      this.getSubnetList();
      this.getAllElineListInit()
      //获取下拉框业务类型信息
      this.getAllServiceType()
      //获取下拉框qos信息
      this.getAllCDPProfileCreation()
      this.getAllDevice();
      //this.getElineDeviceList()
    },
    computed: {
      openTab() {
        return this.$store.state.openTab;
      },
      activeIndex: {
        get() {
          return this.$store.state.activeIndex;
        },
        set(val) {
          this.$store.commit('set_active_index', val);
        }
      },
      //命令
      createAndCopyCommand(){
        return ElineCommands.createAndCopyELineCommand(this.createAndCopyTitle, this.form , this.commandContext)
      },
      deleteELineCommand(){
        return ElineCommands.deleteELineCommand(this.deleteList, this.commandContext)
      },
      updateElineCommand(){
        return ElineCommands.updateELineCommand(this.form, this.commandContext)
      },
      queryNodeTypeChange(){
        this.reversionFlag[0].label=this.$t('EthernetELineServiceConfigurationManagement.is');
        this.reversionFlag[1].label=this.$t('EthernetELineServiceConfigurationManagement.no');
        this.oamInfoFlag[0].label=this.$t('EthernetELineServiceConfigurationManagement.is');
        this.oamInfoFlag[1].label=this.$t('EthernetELineServiceConfigurationManagement.no');
        this.isDualHomedList[0].label=this.$t('EthernetELineServiceConfigurationManagement.is');
        this.isDualHomedList[1].label=this.$t('EthernetELineServiceConfigurationManagement.no');
        this.protectionModeList[0].label=this.$t('EthernetELineServiceConfigurationManagement.unprotected');
        this.protectionModeList[1].label=this.$t('EthernetELineServiceConfigurationManagement.one2one');
        this.protectionModeList[2].label=this.$t('EthernetELineServiceConfigurationManagement.lspone2one');
        this.encapsulationTypeList[0].label=this.$t('EthernetELineServiceConfigurationManagement.ethernetType');
        this.encapsulationTypeList[1].label=this.$t('EthernetELineServiceConfigurationManagement.vlanType');
        this.vlanAccessList[0].label=this.$t('EthernetELineServiceConfigurationManagement.vlanRange1');
        this.vlanAccessList[1].label=this.$t('EthernetELineServiceConfigurationManagement.vlanSet');
      },

    },

    methods: {
      /**
       * @Description  :对点击查看 路由视图的响应函数
       * @author       : yjz
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      async handleRouteView(index, row) {
        let _this = this;
        _this.endPointObject = {  //1.获取到当前点击行的ID。
          startDeviceId: row.startDeviceId,
          end1DeviceId: row.end1DeviceId,
          end2DeviceId: row.end2DeviceId
        };
        /** 2.实例化一个service,调用getRouteViewObject(id),返回一个该ID的Object,里面带有id,带宽,pathList。*/
        let getDataFlag = ElineService.getAllServiceTunnelCollection(row.vpnId).then(result => {
          //成功
          _this.routePathObject = result;
          _this.routeViewDialogShow = true;
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        });
        await getDataFlag;
      },

      /**
       * @Description  :单选一行,将所选行进行保存
       */
      handleCurrentChange(val) {
        this.currentRow = val;
      },

      /**
       * @Description  :表格多选框改变时,将所选行进行保存
       */
      handleSelectionChange(val) {
        this.multipleSelection = val
      },

      /**
       *  --------表格过滤方法------------------------------------------------------
       **/

      /**
       * @Description  :业务类型过滤
       */
      formatServerType: function (row, column) {
        for (var j = 0; j < this.ServiceTypeList.length; j++) {
          if (row.serviceTypeID == (this.ServiceTypeList[j]['serviceTypeID'])) {
            return this.ServiceTypeList[j]['serviceTypeName']
          }
        }
      },

      /**
       * @Description  :业务子网过滤
       */
      formatServiceSubnetID:function (row, column) {
        for (let i = 0; i < this.subnetList.length; i++) {
          if (this.subnetList[i]['serviceSubnetID'] === row.serviceSubnetID) {
            return this.subnetList[i]['serviceSubnetName'];
            break;
          }
        }
        return row.serviceSubnetID
      },

      /**
       * @Description  :保护模式过滤
       */
      formatProtectionMode: function (row, column) {
        for (let i = 0; i < this.protectionModeList.length; i++) {
          if (this.protectionModeList[i]['value'] === row.protectionMode) {
            return this.protectionModeList[i]['label'];
            break;
          }
        }
      },

      /**
       * @Description  :是否回滚过滤
       */
      formatReversionFlag: function (row, column) {
        for (var i = 0; i < this.reversionFlag.length; i++) {
          if (this.reversionFlag[i]['value'] === row.reversion) {
            return this.reversionFlag[i]['label'];
            break;
          }
        }
      },

      /**
       * @Description  :回滚等待时间过滤
       */
      formatWtr:function (row, column) {
        if(row.wtr === -999){
          return ""
        }
        return row.wtr;
      },

      /**
       * @Description  :oamInfo选项过滤
       */
      formatOamInfo: function (row, column) {
        if(row.oamInfo === -999){
          return ""
        }
        for (var i = 0; i < this.oamInfoFlag.length; i++) {
          if (this.oamInfoFlag[i]['value'] === row.oamInfo) {
            return this.oamInfoFlag[i]['label'];
            break;
          }
        }
      },

      /**
       * @Description  :ccm间隔时间过滤
       */
      formatccmInterval: function (row, column) {
        if(row.ccmInterval === -999){
          return ""
        }
        for (var i = 0; i < this.ccmIntervalList.length; i++) {
          if (this.ccmIntervalList[i]['value'] === row.ccmInterval) {
            return this.ccmIntervalList[i]['ccmIntervalTime'];
            break;
          }
        }
      },

      /**
       * @Description  :vlan类别过滤
       */
      formatEncapsulationType: function (row, column) {
        for (var i = 0; i < this.encapsulationTypeList.length; i++) {
          if (this.encapsulationTypeList[i]['value'] === row.encapsulationType) {
            return this.encapsulationTypeList[i]['label']
            break;
          }
        }
      },

      /**
       * @Description  :vlan协议过滤
       */
      formatL2AccessType:function (row, column) {
        if(row.l2AccessType === -999){
          return ""
        }
        for (let i = 0; i < this.l2AccessTypeList.length; i++) {
          if (this.l2AccessTypeList[i]['value'] === row.l2AccessType) {
            return this.l2AccessTypeList[i]['label'];
            break;
          }
        }
      },

      /**
       * @Description  :是否为双规模式选项过滤
       */
      formatIsDualHomed:function (row, column) {
        for (let i = 0; i < this.isDualHomedList.length; i++) {
          if (this.isDualHomedList[i]['value'] === row.isDualHomed) {
            return this.isDualHomedList[i]['label'];
            break;
          }
        }
      },

      /**
       * @Description  :vlan设置方式过滤
       */
      formatVlanAccess: function (row, column) {
        if(row.vlanAccess === -999){
          return ""
        }
        for (var i = 0; i < this.vlanAccessList.length; i++) {
          if (this.vlanAccessList[i]['value'] === row.vlanAccess) {
            return this.vlanAccessList[i]['label']
            break;
          }
        }
      },

      /**
       * @Description  :vlan-range起点过滤
       */
      formatVlanRangeStart:function (row, column) {
        if(row.vlanRangeStart === -999){
          return ""
        }
        return row.vlanRangeStart;
      },

      /**
       * @Description  :vlan-range终点过滤
       */
      formatVlanRangeEnd:function (row, column) {
        if(row.vlanRangeEnd === -999){
          return ""
        }
        return row.vlanRangeEnd;
      },

      /**
       * @Description  :业务起点设备过滤
       */
      formatStartDeviceId:function (row, column) {
        for (let i = 0; i < this.deviceList.length; i++) {
          if (this.deviceList[i]['deviceKey'] === row.startDeviceId) {
            return this.deviceList[i]['deviceName'];
            break;
          }
        }
        return row.startDeviceId;
      },

      /**
       * @Description  :业务起点设备端口过滤
       */
      formatStartDevicePort:function (row, column) {
        if(row.startDevicePort === -999){
          return ""
        }
        return row.startDevicePort;
      },

      /**
       * @Description  :业务终点设备过滤
       */
      formatEnd1DeviceId:function (row, column) {
        for (let i = 0; i < this.deviceList.length; i++) {
          if (this.deviceList[i]['deviceKey'] === row.end1DeviceId) {
            return this.deviceList[i]['deviceName'];
            break;
          }
        }
        return row.end1DeviceId;
      },

      /**
       * @Description  :业务终点设备端口过滤
       */
      formatEnd1DevicePort:function (row, column) {
        if(row.end1DevicePort === -999){
          return ""
        }
        return row.end1DevicePort;
      },

      /**
       * @Description  :第二个业务终点设备过滤
       */
      formatEnd2DeviceId:function (row, column) {
        for (let i = 0; i < this.deviceList.length; i++) {
          if (this.deviceList[i]['deviceKey'] === row.end2DeviceId) {
            return this.deviceList[i]['deviceName'];
            break;
          }
        }
        return row.end2DeviceId;
      },

      /**
       * @Description  :第二个业务终点设备端口过滤
       */
      formatEnd2DevicePort:function (row, column) {
        if(row.end2DevicePort === -999){
          return ""
        }
        return row.end2DevicePort;
      },

      /**
       * @Description  :cosId设置方式过滤
       */
      formatCosId: function (row, column) {
        for (let i = 0; i < this.cosIdList.length; i++) {
          if (this.cosIdList[i]['value'] === row.cosId) {
            return this.cosIdList[i]['label'];
            break;
          }
        }
      },

      /**
       * ----------获取处理数据方法------------------------------------------------------
       * */

      /**
       * @Description  :获取业务子网列表
       * @date         : 2019/03/19 16:56
       */
      getSubnetList: function () {
        //调用domin函数
        let _this = this;
        ServiceSubnetService.getAllEveSubnetCollection().then(result => {
          //成功
          _this.subnetList = Object.values(result);
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /***
       * @Description  : 获取所有设备列表
       * @author       : lxy
       * @date         : 2018/12/24 11:29
       */
      getAllDevice: function () {
        let _this = this
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          _this.optionsDeviceName = Object.values(result)
          _this.deviceList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * @Description  :获取下拉框所有业务类型消息
       * @date         : 2019/03/19 15:20
       */
      getAllServiceType: function () {
        console.log('获取全部业务类型信息:')
        let _this = this
        ServiceTypeService.getAllServiceTypeCollection().then(result => {
          //成功
          _this.ServiceTypeList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * @Description  :获取下拉框所有qosfile消息
       * @date         : 2019/03/19 16:56
       */
      getAllCDPProfileCreation: function () {
        console.log('获取全部qosfile信息:CDPProfileCreationList')
        let _this = this
        CDPService.getAllCDPCollection().then(result => {
          //成功
          _this.CDPProfileCreationList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * @Description  :获取设备列表(第一个string是子网ID,第二个就是对应的设备拿的是deviceKey,port)
       * @date         : 2019/03/19 16:56
       */
      getElineDeviceList: function () {
        this.elineDeviceList = [];
        let _this = this
        ElineService.getElineDeviceList(this.form.serviceTypeID).then(result => {
          //成功
          _this.elineDeviceList =  Object.values(result);
          _this.handleElineDeviceList();
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        });
      },

      /**
       * @Description  :处理设备列表的信息
       * @date         : 2019/03/19 16:56
       */
      handleElineDeviceList: function () {
        this.startDeviceIdList = [];
        this.end1DeviceIdList = [];
        this.end2DeviceIdList = [];
        for (let i = 0; i < this.elineDeviceList.length; i++) {  //遍历设备列表
          let elineDevice1 = this.elineDeviceList[i].value;
          elineDevice1.deviceName = this.handleDeviceKeys(this.elineDeviceList[i].value.deviceKey);
          this.startDeviceIdList.push(elineDevice1);
          this.end1DeviceIdList.push(elineDevice1);
          this.end2DeviceIdList.push(elineDevice1);
        }
      },

      /***
       * @Description  : 设备名称处理
       * @author       : zf
       * @date         : 2018/12/24 16:07
       */
      handleDeviceKeys: function (deviceKey) {
        let _this = this
        //获取设备列表
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          _this.deviceList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        });
//        let flag = 0;//标记是否查到,0未查到,1查到
        for (let i = 0; i < this.deviceList.length; i++) {
          if (this.deviceList[i].deviceKey === deviceKey) {
            return this.deviceList[i].deviceName;
          }
        }
        return deviceKey;
      },

      /**
       * @Description  :获取业务信息
       * @date         : 2019/03/19 15:22
       */
      getAllElineListInit: function () {
        console.log('获取全部业务信息:');
        let _this = this
        ElineService.getAllElineCollection().then(result => {
          //成功
          _this.ElineList = Object.values(result);
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * @Description  :增删改后调用,重新加载table
       * @date         : 2019/03/19 15:24
       */
      getAllElineList: function (vue) {
        console.log('获取全部服务器信息:');
        let _this = this;
        ElineService.getAllElineCollection().then(result => {
          //成功
          _this.ElineList = Object.values(result);
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * ----------业务处理初始化------------------------------------------------------
       * */
      /**
       * @Description  :创建业务初始化
       * @date         : 2019/03/19 15:54
       */
      createElineTemplateInit: function () {
        this.createAndCopyTitle = '创建以太网E-Line业务';

        this.wtr_input_disable = false
        this.oaminfo_select_disable = false
        this.vlanRangeStart_input_disable = false
        this.vlanRangeEnd_input_disable = false
        this.vlanRangeSet_input_disable = false
        this.ccmInterval_select_disable = false
        this.defaultFlag_select_disable = false
        this.l2AccessType_select_disable = false;

        this.form.vpnId = '';
        this.form.serviceName = '';
        this.form.serviceTypeID = '';
        this.form.protectionMode = '';
        this.form.reversion = '';
        this.form.wtr = '';
        this.form.oamInfo = '';
        this.form.ccmInterval = '';
        this.form.encapsulationType = '';
        this.form.l2AccessType = '';
        this.form.startDeviceId = '';
        this.form.startDevicePort = '';
        this.form.end1DeviceId = '';
        this.form.end1DevicePort = '';
        this.form.isDualHomed = 1;
        this.form.end2DeviceId = '';
        this.form.end2DevicePort = '';
        this.form.vlanAccess = '';
        this.form.vlanRangeStart = '';
        this.form.vlanRangeEnd = '';
        this.form.vlanSet = '';
        this.form.cosId = '';
        this.form.limitedBandwidth = '';
        this.form.qosProfile = '';
        this.form.startTime = '';
        this.form.elineStatus = 'submitted';
        this.form.serviceSubnetID = '';

        this.initList = this.form;
        this.createAndCopyCommand.execute();
      },

      /**
       * @Description  :复制业务信息初始化
       * @date         : 2019/03/19 16:31
       */
      copyElineTemplateInit: function () {
        if (this.multipleSelection.length === 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.COPY_SELECT_CODE))
          return;
        } else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.COPY_ONLY_ONE_CODE))
          return;
        } else {
          this.createAndCopyTitle = '复制以太网E-Line业务';
          this.currentRow = this.multipleSelection[0];

          this.form.vpnId = this.currentRow.vpnId;
          this.form.serviceName = this.currentRow.serviceName;
          this.form.serviceTypeID = this.currentRow.serviceTypeID;
          this.form.protectionMode = this.currentRow.protectionMode;
          this.form.reversion = this.currentRow.reversion;
          this.form.wtr = this.currentRow.wtr;
          this.form.oamInfo = this.currentRow.oamInfo;
          this.form.ccmInterval = this.currentRow.ccmInterval;
          this.form.encapsulationType = this.currentRow.encapsulationType;
          this.form.l2AccessType = this.currentRow.l2AccessType;
          this.form.startDeviceId = this.currentRow.startDeviceId;
          this.form.startDevicePort = this.currentRow.startDevicePort;
          this.form.end1DeviceId = this.currentRow.end1DeviceId;
          this.form.end1DevicePort = this.currentRow.end1DevicePort;
          this.form.isDualHomed = this.currentRow.isDualHomed;
          this.form.end2DeviceId = this.currentRow.end2DeviceId;
          this.form.end2DevicePort = this.currentRow.end2DevicePort;
          this.form.vlanAccess = this.currentRow.vlanAccess;
          this.form.vlanRangeStart = this.currentRow.vlanRangeStart;
          this.form.vlanRangeEnd = this.currentRow.vlanRangeEnd;
          this.form.vlanSet = this.currentRow.vlanSet;
          this.form.cosId = this.currentRow.cosId;
          this.form.limitedBandwidth = this.currentRow.limitedBandwidth;
          this.form.qosProfile = this.currentRow.qosProfile;
          this.form.startTime = this.currentRow.startTime;
          this.form.elineStatus = this.currentRow.elineStatus;
          this.form.serviceSubnetID = this.currentRow.serviceSubnetID;
          this.createAndCopyCommand.execute();
        }
      },

      /**
       * @Description  :修改业务信息初始化
       * @date         : 2019/03/19 16:03
       */
      updateElineTemplateInit: function () {
        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPDATE_SELECT_CODE))
          return;
        } else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPDATE_SELECT_CODE))
          return;
        } else {
          this.currentRow = this.multipleSelection[0];

          this.form.vpnId = this.currentRow.vpnId;
          this.form.serviceName = this.currentRow.serviceName;
          this.form.serviceTypeID = this.currentRow.serviceTypeID;
          this.form.serviceSubnetID = this.currentRow.serviceSubnetID;
          this.form.protectionMode = this.currentRow.protectionMode;
          this.form.reversion = this.currentRow.reversion;
          this.form.wtr = this.currentRow.wtr;
          this.form.oamInfo = this.currentRow.oamInfo;
          this.form.ccmInterval = this.currentRow.ccmInterval;
          this.form.encapsulationType = this.currentRow.encapsulationType;
          this.form.l2AccessType = this.currentRow.l2AccessType;
          this.form.startDeviceId = this.currentRow.startDeviceId;
          this.form.startDevicePort = this.currentRow.startDevicePort;
          this.form.end1DeviceId = this.currentRow.end1DeviceId;
          this.form.end1DevicePort = this.currentRow.end1DevicePort;
          this.form.isDualHomed = this.currentRow.isDualHomed;
          this.form.end2DeviceId = this.currentRow.end2DeviceId;
          this.form.end2DevicePort = this.currentRow.end2DevicePort;
          this.form.vlanAccess = this.currentRow.vlanAccess;
          this.form.vlanRangeStart = this.currentRow.vlanRangeStart;
          this.form.vlanRangeEnd = this.currentRow.vlanRangeEnd;
          this.form.vlanSet = this.currentRow.vlanSet;
          this.form.cosId = this.currentRow.cosId;
          this.form.limitedBandwidth = this.currentRow.limitedBandwidth;
          this.form.qosProfile = this.currentRow.qosProfile;
          this.form.startTime = this.currentRow.startTime;
          this.form.elineStatus = this.currentRow.elineStatus;
          this.updateElineCommand.execute();
        }
      },

      /**
       * @Description  :删除业务信息初始化
       * @date         : 2019/03/19 16:36
       */
      deleteElineInit: function () {
        if (this.multipleSelection.length === 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.DELETE_SELECT_CODE))
          return;
        } else if(this.multipleSelection.length > 1){

        }
        else {
          this.deleteFlag = false;
          this.deleteList = "";
          for (let i = 0; i < this.multipleSelection.length; i++) {
            this.deleteList = this.multipleSelection[i]['vpnId'];
          }
          this.deleteELineCommand.execute();
        }
      },

      /**
       * @Description  :条件查询
       * @date         : 2019/03/19 17:06
       */
      queryElineByCondition: function () {
        console.log('业务信息按条件查询:');

        if (this.queryVpnId === '' && this.queryServiceName === '' && this.queryServiceTypeID === '' &&
          this.queryStartDevice === ''&& this.queryEndDevice === '' && parseInt(this.queryProtectionMode).toString() === "NaN" ) {
          //所有查询条件为空点击查询--》重新刷新表格
          //this.$options.methods.getAllElineList(this);
          this.getAllElineListInit();
          this.InfoTip.successTip(this,HelperUtil.getStatusCodeObjectByCode(this.successCode.QUERY_CODE));
          return;
        }
        var selectList = new Array();
        if (this.queryVpnId !== '') {
          selectList.push({
            quaryAttribute: 'vpnId',
            compareSymbol: "like",
            compareValue: this.queryVpnId,
          })
        }
        if (this.queryServiceName !== '') {
          selectList.push({
            quaryAttribute: 'serviceName',
            compareSymbol: "like",
            compareValue: this.queryServiceName,
          })
        }
        if (this.queryServiceTypeID !== ''&& this.queryServiceTypeID !== null) {
          selectList.push({
            quaryAttribute: 'serviceTypeID',
            compareSymbol: "==",
            compareValue: this.queryServiceTypeID,
          })
        }
        if (this.queryStartDevice !== '' && this.queryStartDevice !== null) {
          selectList.push({
            quaryAttribute: 'startDeviceId',
            compareSymbol: "==",
            compareValue: this.queryStartDevice,
          })
        }
        if (this.queryEndDevice !== '' && this.queryEndDevice !== null) {
          selectList.push({
            quaryAttribute: 'end1DeviceId',
            compareSymbol: "==",
            compareValue: this.queryEndDevice,
          })
        }
        if (parseInt(this.queryProtectionMode).toString() !== "NaN") {
          selectList.push({
            quaryAttribute: 'protectionMode',
            compareSymbol: "==",
            compareValue: this.queryProtectionMode,
          })
        }
        let _this = this;
        let loadingInstance = _this.Loading.openLoading();
        //按条件查询
        ElineService.conditionQueryEline(selectList).then(result => {
          //成功
          _this.ElineList = Object.values(result);
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.successTip(_this,HelperUtil.getStatusCodeObjectByCode(_this.successCode.QUERY_CODE));
          if (Object.values(result).length === 0) {
            _this.$message({
              type: 'warning',
              message: '无符合条件查询数据! ',
              duration: 10000,
              showClose: true,
            })
          } else {
            _this.$message({
              type: 'success',
              message: '查询成功! ',
              duration: 10000,
              showClose: true,
            })
          }
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.errorTip(_this, err);
        })
      },

      /**
       * @Description  :清空查询条件
       * @date         : 2019/03/19 17:06
       */
      clearQueryCondition:function () {
        this.queryVpnId = ''; //业务ID
        this.queryServiceName = '';//业务名称
        this.queryServiceTypeID = '';   //业务类型
        this.queryStartDevice = '';   //起点设备
        this.queryEndDevice = '';   //终点设备
        this.queryProtectionMode = '';//保护模式
      },
    },
    watch:{
      commandContext(newVal, oldVal){
        if(JSON.stringify(newVal) === '{}'){
          //
          this.getAllElineListInit();
          this.clearQueryCondition();
        }
        deep: true
      },
      '$i18n.locale' () {
        this.queryNodeTypeChange()
      },
    },
  }
</script>

<style scoped>
</style>