<template>
    <!-- 设备上传配置文件对话框 -->
    <el-dialog v-dialogDrag
               @close="close"
               style="font-size: 10px; " width='600px' :title="$t('ProfileManagement.equipmentToUpload')"
              v-if="DeviceUploadConfig"
               :visible.sync="DeviceUploadConfig">

      <el-table
        ref="singleTable"
        :data="deviceList"
        header-row-class-name="table-header"
        cell-class-name="table-cell"
        highlight-current-row
        stripe
        height="350"
        tooltip-effect="dark"
        @current-change="handleCurrentChange"
        @selection-change="handleSelectionChangeUpload">
        <el-table-column
          type="selection"
          width="28">
        </el-table-column>
        <el-table-column
          prop="displayName"
          :label="$t('ProfileManagement.deviceName')"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column
          prop="configFileName"
          :label="$t('ProfileManagement.currentProfile')"

          :show-overflow-tooltip="true">

        </el-table-column>


      </el-table>


      <el-row style="margin-bottom: 0px;" slot="footer" class="dialog-footer">
        <el-button style="margin-bottom: -10px;" size='mini' type="primary" @click="equipmentUpload"
                   v-loading.fullscreen.lock="fullscreenLoading">{{$t("ProfileManagement.upload")}}
        </el-button>
        <el-button style="margin-bottom: -10px;" size='mini' @click="close">
          {{$t("common.cancel")}}
        </el-button>
      </el-row>
    </el-dialog>

</template>

<script>
  let curThis = '';

  import ConfigFileService from '@/domain/services/ConfigFileService.js'
  import DeviceService from '@/domain/services/DeviceService.js'
  import HelperUtil from '../../../utils/HelperUtil'
  export default {


    props: ['command'],

    data() {
      return {
        deviceList: [],

        flag: false,

        multipleSelectionUpload: [],
        tableHeight:'250px',

        DeviceUploadConfig: true,
        currentConfigKey: this.command.target,
        // 数据加载过程中，覆盖界面
        fullscreenLoading: false,
      };
    },
    methods: {
      close() {
        this.command.done()
      },
      getAllDevice: function () {
        console.log('获取全部网元信息:')
        let _this = this;
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          _this.deviceList = Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :设备上传表格多选框改变时，将所选行进行保存
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      handleSelectionChangeUpload(val) {
        this.multipleSelectionUpload = val
      },
      /**
       * @Description  从设备上传：设备上传配置文件判断选择数据条数是否合法
       * @author       ::
       * @date         :
       */
      equipmentUpload: function () {
        if (this.multipleSelectionUpload.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_AT_LEASE_ONE_DEVICE))
          return
        }
        else {
          //上传
          this.uploadByEquipment()
        }
      },

      /**
       * @Description  从设备上传：设备上传配置文件
       * @author       ::
       * @date         :
       */
      uploadByEquipment: function () {
        //开始上传到后台
        let _this = this;
        var selectList = new Array()
        for (var i = 0; i < this.multipleSelectionUpload.length; i++) {
          selectList[i] = this.multipleSelectionUpload[i]['deviceKey']
          console.log(this.multipleSelectionUpload[i]['deviceKey'])

        }
        let loadingInstance = _this.Loading.openLoading();
        ConfigFileService.batchUploadConfigFile(selectList).then(result => {
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.successTip(_this,HelperUtil.getStatusCodeObjectByCode(_this.successCode.OTHERS_CODE));
          _this.close()
        }).catch(err => {
          //失败
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.errorTip(_this,err);
        })
      },
    },

    watch: {},
    created() {
      curThis = this
      console.log('获取全部配置信息：')
      this.getAllDevice()
    }
  }
  ;
</script>

<style scoped>


</style>
