<template>
  <!-- 查看端口光功率对话框 -->
  <el-dialog
    @close="close"
    @opened="getDeviceLuminousPower"
    v-dialogDrag
    style="font-size: 10px; text-align: center" width='500px'
    :title="$t('devicePanel.portLuminousPower')"
    v-if="devicePortFlowShow"
    :visible.sync="devicePortFlowShow"
    :append-to-body='true'>
    <el-table
      header-row-class-name="table-header"
      cell-class-name="table-cell"
      height="150px"
      ref="singleTable"
      :data="showList"
      highlight-current-row
      stripe
      tooltip-effect="dark">
      <el-table-column
        prop="portName"
        :label="$t('devicePanel.portName')"
        :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column
        prop="transmit"
        :label="$t('devicePanel.transmittedPower')"
        :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column
        prop="receive"
        :label="$t('devicePanel.receivedPower')"
        :show-overflow-tooltip="true">
      </el-table-column>
    </el-table>

    <el-row style="margin-bottom: 0px;" slot="footer" class="dialog-footer">
      <el-button size = 'mini' @click="ok">{{$t('common.ok')}}</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import DeviceService from '../../../domain/services/DeviceService'

export default {
  props: ['command'],

  created () {

  },
  mounted () {
    this.devicePortFlowShow = true
  },

  data () {
    return {
      devicePortFlowShow: false,
      device: this.command.target[0],
      port: this.command.target[1],
      showList: []
    }
  },
  methods: {
    /***
       * @Description  :点击关闭/确认按钮
       * @author       : zf
       * @date         : 2019/04/19 14:50
       */
    close () {
      this.command.done()
    },
    ok () {
      this.command.done()
    },

    /***
      * @Description  : 请求端口光功率
      * @author       : zf
      * @date         : 2019/05/15 15:23
      */
    getDeviceLuminousPower: function () {
      let _this = this
      let queryDevice = {}
      for (let key in _this.device) {
        if (key !== 'status' && key !== 'picUrl' && key !== 'label' && key !== 'key') {
          queryDevice[key] = _this.device[key]
        }
      }
      DeviceService.getDeviceLuminousPower(_this.port.portName, queryDevice).then(result => {
        // 成功
        _this.showList = []
        let object = {}
        object['portName'] = _this.port.portName
        object['transmit'] = result[0]
        object['receive'] = result[1]
        _this.showList.push(object)
      }).catch(err => {
        // 失败
        _this.InfoTip.errorTip(_this, err)
      })
    }
  }
}
</script>

<style scoped>

</style>
