DeleteDeviceDialog.vue 5.28 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
<template>
  <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
</template>

<script>
import UserCommands from '../../../commands/UserCommands'
import CommandExecuteContext from '../../../commands/CommandExecuteContext'
import DeviceService from '@/domain/services/DeviceService.js'
import LinkService from '@/domain/services/LinkService'
import PortService from '@/domain/services/PortListService.js'
import HelperUtil from '../../../utils/HelperUtil'

export default {
  props: ['command'],

  components: {
    CommandExecuteContext
  },

  data: function () {
    return {
      deleteList: this.command.target,
      // 级联删除链路
      linkList: [],
      // 级联删除接入业务portList
      portList: [],
      deviceList: [],

      // 命令
      commandContext: {},

      confirmFlag: {
        confirm: false
      }
    }
  },
  methods: {
    close () {
      this.command.done()
    },

    open () {
      let _this = this
      _this.InfoTip.conformTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.DELETE_CONFIRM)
      ).then(() => {
        this.deleteDevicePro()
      }).catch(() => {
        this.command.done()
      })
    },
    // 删除设备
    deleteDevice () {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      _this.getAllLinkInit(() => {
        _this.getAllPort(() => {
          _this.getAllDevice(() => {
            DeviceService.deleteDeviceAndLinks(_this.deleteList, _this.deviceList, _this.linkList, _this.portList).then(result => {
              _this.Loading.closeLoading(loadingInstance)
              _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.DELETE_CODE))
              _this.close()
            }).catch(err => {
              //   console.log("删除失败");
              _this.Loading.closeLoading(loadingInstance)
              _this.InfoTip.errorTip(_this, err)
              _this.close()
            })
          })
        })
      })
    },

    // 删除设备    需求修改: 删除设备时,后台进行链路与接入业务的级联删除操作
    deleteDevicePro () {
      let _this = this
      let loadingInstance = _this.Loading.openLoading()
      DeviceService.batchDeleteDevice(_this.deleteList).then(result => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.DELETE_CODE))
        _this.close()
      }).catch(err => {
        _this.Loading.closeLoading(loadingInstance)
        _this.InfoTip.errorTip(_this, err)
        _this.close()
      })
    },
    /**
       * @Description  :获取全部port信息
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2018/12/7 14:06
       */
    getAllPort: function (mutator = () => {}) {
      let _this = this
      PortService.getAllPortList().then(result => {
        _this.portList = Object.values(result)
        mutator()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    /**
       * @Description  :获取全部device信息
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2018/12/7 14:06
       */
    getAllDevice: function (mutator = () => {}) {
      let _this = this
      DeviceService.getAllDeviceCollection().then(result => {
        _this.deviceList = result
        mutator()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    // 删除port
    deletePort (delLinkList) {
      let _this = this
      PortService.batchDeletePortList(JSON.stringify(delLinkList)).then(result => {
        // 成功
        _this.command.done()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
        _this.command.done()
      })
    },
    /**
       * @Description  :获取全部link信息
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2018/12/7 14:06
       */
    getAllLinkInit: function (mutation = () => {}) {
      let _this = this
      // 为了测试其他先注释了
      LinkService.getAllLinkCollection().then(result => {
        // 成功
        _this.linkList = Object.values(result)
        mutation()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
      })
    },
    // 删除link
    deleteLink (delLinkList) {
      let _this = this
      LinkService.batchLinkDelete(JSON.stringify(delLinkList)).then(result => {
        // 成功
        _this.command.done()
      }).catch(err => {
        _this.InfoTip.errorTip(_this, err)
        // 失败
        _this.command.done()
      })
    }
  },

  watch: {
    commandContext (newVal, oldVal) {
      let _this = this
      if (_this.confirmFlag.confirm) {
        this.open()
        this.confirmFlag.confirm = false
      } else {
        if (JSON.stringify(newVal) === '{}') {
          _this.close()
        }
      }
      deep: true
    }
  },

  computed: {
    confirmUserCommand () {
      this.confirmFlag.confirm = false
      return UserCommands.confirmUserCommand(this.commandContext, this.confirmFlag)
    }
  },
  created () {
    this.confirmUserCommand.execute()
    this.getAllPort()
  }
}
</script>