SetAdditionalWiresDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('network.additional_wires.set') }}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc">
  6. <a-form-item :label="$t('network.text_571')" v-bind="formItemLayout">
  7. <a-radio-group v-decorator="decorators.type">
  8. <a-radio-button value="auto">{{ $t('network.additional_wires.type.auto') }}</a-radio-button>
  9. <a-radio-button value="manual">{{ $t('network.additional_wires.type.manual') }}</a-radio-button>
  10. </a-radio-group>
  11. </a-form-item>
  12. <a-form-item v-bind="formItemLayoutWithOutLabel" v-if="form.fd.type === 'manual'">
  13. <base-select
  14. resource="wires"
  15. v-decorator="decorators.wires"
  16. :selectProps="{ 'placeholder': $t('network.text_572'), mode: 'multiple' }"
  17. remote
  18. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  19. :params="wireParams"
  20. :mapper="wireMapper" />
  21. </a-form-item>
  22. </a-form>
  23. </div>
  24. <div slot="footer">
  25. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  26. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  27. </div>
  28. </base-dialog>
  29. </template>
  30. <script>
  31. import { PROVIDER_MAP } from '@/constants'
  32. import DialogMixin from '@/mixins/dialog'
  33. import WindowsMixin from '@/mixins/windows'
  34. export default {
  35. name: 'SetAdditionalWiresDialog',
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. const currentData = this.params.currentData
  39. const additionalWires = currentData.additional_wires && currentData.additional_wires.map(item => item.wire_id)
  40. return {
  41. loading: false,
  42. form: {
  43. fc: this.$form.createForm(this, {
  44. onValuesChange: (props, values) => {
  45. Object.keys(values).forEach((key) => {
  46. this.$set(this.form.fd, key, values[key])
  47. })
  48. },
  49. }),
  50. fd: {},
  51. },
  52. decorators: {
  53. type: [
  54. 'type',
  55. {
  56. initialValue: 'auto',
  57. },
  58. ],
  59. wires: [
  60. 'wires',
  61. {
  62. initialValue: additionalWires,
  63. rules: [
  64. { required: true, message: this.$t('network.text_572') },
  65. ],
  66. },
  67. ],
  68. },
  69. formItemLayout: {
  70. wrapperCol: {
  71. span: 19,
  72. },
  73. labelCol: {
  74. span: 5,
  75. },
  76. },
  77. formItemLayoutWithOutLabel: {
  78. wrapperCol: {
  79. span: 19,
  80. offset: 5,
  81. },
  82. },
  83. wireParams: {
  84. scope: this.$store.getters.scope,
  85. provider: PROVIDER_MAP.VMware.key,
  86. limit: 20,
  87. },
  88. }
  89. },
  90. methods: {
  91. wireMapper (list) {
  92. if (list && list.length > 0) {
  93. return list.filter(item => {
  94. const wid = this.params.currentData.wire_id
  95. return item.id !== wid
  96. })
  97. }
  98. return []
  99. },
  100. async doSubmit (values) {
  101. const id = this.params.currentData.id
  102. const params = {}
  103. if (values.type === 'manual') {
  104. params.wire_ids = values.wires
  105. }
  106. await new this.$Manager('networks').performAction({
  107. id,
  108. action: 'sync-additional-wires',
  109. data: params,
  110. })
  111. },
  112. async handleConfirm () {
  113. this.loading = true
  114. try {
  115. const values = await this.form.fc.validateFields()
  116. this.doSubmit(values)
  117. this.cancelDialog()
  118. this.$message.success(this.$t('common.success'))
  119. this.params.success && this.params.success()
  120. } catch (error) {
  121. throw error
  122. } finally {
  123. this.loading = false
  124. }
  125. },
  126. },
  127. }
  128. </script>