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

<script>
import HelperUtil from '@/utils/HelperUtil'
import UserCommands from '../../../commands/UserCommands'
import CommandExecuteContext from '../../../commands/CommandExecuteContext'

export default {
  props: ['command'],
  components: {
    CommandExecuteContext
  },
  data: function () {
    return {
      commandContext: {},
      confirmFlag: {
        confirm: false
      },
      device: this.command.target
    }
  },
  methods: {
    // 跳转
    turnToSwitches () {
      var url = ''
      var ipAdd = this.device.ipAddress === '' ? this.device.bussIpAddress : this.device.ipAddress
      if (ipAdd === '') {
        this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.IP_ERROR))
        return
      } else {
        if (this.device.deviceModel === 'SR650') {
          url = 'https://'.concat(ipAdd).concat('/#/login')
        } else if (this.device.deviceModel === 'V5000' || this.device.deviceModel === 'V5030' || this.device.deviceModel === 'V7000' || this.device.deviceModel === 'H3C R6800G2') {
          url = 'https://'.concat(ipAdd)
        }
      }
      window.open(url, '_blank')
    }
  },

  created () {
    this.confirmUserCommand.execute()
  },
  computed: {
    confirmUserCommand () {
      this.confirmFlag.confirm = false
      return UserCommands.confirmUserCommand(this.commandContext, this.confirmFlag)
    }
  },
  watch: {
    commandContext (newVal, oldVal) {
      let _this = this
      if (_this.confirmFlag.confirm) {
        this.turnToSwitches()
        this.confirmFlag.confirm = false
      } else {
        if (JSON.stringify(newVal) === '{}') {
          _this.close()
        }
      }
      deep: true
    }
  }
}
</script>
