<template>
  <!-- 跳转交换机配置确认用户对话框 -->
  <div>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>
</template>

<script>
import TopologyService from '@/domain/services/TopologyService.js'
import UserCommands from '../../../commands/UserCommands'
import CommandExecuteContext from '../../../commands/CommandExecuteContext'

export default {
  props: ['command'],
  components: {
    CommandExecuteContext
  },
  data: function () {
    return {
      device: this.command.target,
      commandContext: {},
      confirmFlag: {
        confirm: false
      },
      form: {
        account: '',
        password: ''
      }
    }
  },
  methods: {
    // 跳转
    turnToSwitches () {
      // if(this.accountCheck() && this.passwordCheck()){
      TopologyService.getInterchangeData(this.device.bussIpAddress, this.form.account, this.form.password)
      this.close()
      // }
    }
  },

  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.TurnToSwitchesVisible = true;
        this.turnToSwitches()
        this.confirmFlag.confirm = false
      } else {
        if (JSON.stringify(newVal) === '{}') {
          _this.close()
        }
      }
      deep: true
    }
  }
}
</script>
