SwitchWire.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.network')" :count="params.data.length" :action="params.title" />
  6. <dialog-table class="mb-2" :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('network.text_571')">
  9. <base-select
  10. resource="wires"
  11. v-decorator="decorators.wire"
  12. :selectProps="{ 'placeholder': $t('network.text_572') }"
  13. :isDefaultSelect="true"
  14. :params="wireParams" />
  15. </a-form-item>
  16. </a-form>
  17. </div>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import DialogMixin from '@/mixins/dialog'
  26. import WindowsMixin from '@/mixins/windows'
  27. export default {
  28. name: 'NetworkSwitchWireDialog',
  29. mixins: [DialogMixin, WindowsMixin],
  30. data () {
  31. return {
  32. loading: false,
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. decorators: {
  37. wire: [
  38. 'wire',
  39. {
  40. initialValue: this.params.data[0].wire_id,
  41. rules: [
  42. { required: true, message: this.$t('network.text_572') },
  43. ],
  44. },
  45. ],
  46. },
  47. formItemLayout: {
  48. wrapperCol: {
  49. span: 19,
  50. },
  51. labelCol: {
  52. span: 5,
  53. },
  54. },
  55. }
  56. },
  57. computed: {
  58. columns () {
  59. return this.params.columns.filter(item => ['name', 'status', 'wire'].includes(item.field))
  60. },
  61. wireParams () {
  62. const params = {
  63. scope: this.$store.getters.scope,
  64. // brand: this.params.data[0].brand,
  65. vpcId: this.params.data[0].vpc_id,
  66. // zone: this.params.data[0].zone_id,
  67. }
  68. return params
  69. },
  70. },
  71. methods: {
  72. async handleConfirm () {
  73. this.loading = true
  74. try {
  75. const values = await this.form.fc.validateFields()
  76. const ids = this.params.data.map(item => item.id)
  77. if (ids.length > 1) {
  78. await this.params.onManager('batchPerformAction', {
  79. ids,
  80. managerArgs: {
  81. action: 'switch-wire',
  82. data: {
  83. wire_id: values.wire,
  84. },
  85. },
  86. })
  87. } else {
  88. await this.params.onManager('performAction', {
  89. id: ids[0],
  90. managerArgs: {
  91. action: 'switch-wire',
  92. data: {
  93. wire_id: values.wire,
  94. },
  95. },
  96. })
  97. }
  98. this.cancelDialog()
  99. } finally {
  100. this.loading = false
  101. }
  102. },
  103. },
  104. }
  105. </script>