BindEip.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1179')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('network.text_714')" :count="params.data.length" :action="$t('compute.text_1179')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" hideRequiredMark>
  8. <eip-config
  9. hidden-none-type
  10. :decorators="decorators.eipConfig"
  11. :eip-params="eipParams"
  12. :hypervisor="hypervisor"
  13. :cloud-env="params.data[0].cloud_env"
  14. :form="form"
  15. :formItemLayout="formItemLayout"
  16. :show-new="eipBindNew" />
  17. </a-form>
  18. </div>
  19. <div slot="footer">
  20. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  21. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  22. </div>
  23. </base-dialog>
  24. </template>
  25. <script>
  26. import EipConfig from '@Compute/sections/EipConfig'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. export default {
  30. name: 'LbBindEipDialog',
  31. components: {
  32. EipConfig,
  33. },
  34. mixins: [DialogMixin, WindowsMixin],
  35. data () {
  36. return {
  37. loading: false,
  38. form: {
  39. fc: this.$form.createForm(this),
  40. },
  41. decorators: {
  42. eipConfig: {
  43. type: [
  44. 'type',
  45. {
  46. initialValue: this.params.data[0].brand === 'OneCloud' ? 'new' : 'bind',
  47. },
  48. ],
  49. charge_type: [
  50. 'charge_type',
  51. {
  52. initialValue: 'bandwidth',
  53. },
  54. ],
  55. bgp_type: [
  56. 'bgp_type',
  57. {
  58. initialValue: '',
  59. },
  60. ],
  61. bandwidth: [
  62. 'bandwidth',
  63. {
  64. initialValue: 30,
  65. validateFirst: true,
  66. },
  67. ],
  68. eip: [
  69. 'eip',
  70. {
  71. rules: [
  72. { required: true, message: this.$t('compute.text_145'), trigger: 'change' },
  73. ],
  74. },
  75. ],
  76. },
  77. },
  78. formItemLayout: {
  79. wrapperCol: {
  80. span: 20,
  81. },
  82. labelCol: {
  83. span: 4,
  84. },
  85. },
  86. }
  87. },
  88. computed: {
  89. eipParams () {
  90. return {
  91. usable_eip_for_associate_type: 'loadbalancer',
  92. usable_eip_for_associate_id: this.params.data[0].id,
  93. scope: this.$store.getters.scope,
  94. }
  95. },
  96. eipBindNew () {
  97. return this.params.data[0].brand === 'OneCloud'
  98. },
  99. columns () {
  100. const fields = ['name', 'vpc', 'address']
  101. return this.params.columns.filter(item => {
  102. const { field } = item
  103. return fields.indexOf(field) > -1
  104. })
  105. },
  106. },
  107. methods: {
  108. doCreateEip (ids, values) {
  109. return this.params.onManager('batchPerformAction', {
  110. id: ids,
  111. managerArgs: {
  112. action: 'create-eip',
  113. data: {
  114. charge_type: values.charge_type,
  115. bandwidth: values.bandwidth,
  116. bgp_type: values.bgp_type,
  117. },
  118. },
  119. })
  120. },
  121. doBindEip (ids, values) {
  122. return this.params.onManager('batchPerformAction', {
  123. id: ids,
  124. steadyStatus: ['enabled'],
  125. managerArgs: {
  126. action: 'associate-eip',
  127. data: {
  128. eip_id: values.eip,
  129. },
  130. },
  131. })
  132. },
  133. async handleConfirm () {
  134. this.loading = true
  135. try {
  136. const values = await this.form.fc.validateFields()
  137. const ids = this.params.data.map(item => item.id)
  138. if (values.type === 'new') {
  139. await this.doCreateEip(ids, values)
  140. }
  141. if (values.type === 'bind') {
  142. await this.doBindEip(ids, values)
  143. }
  144. this.cancelDialog()
  145. } finally {
  146. this.loading = false
  147. }
  148. },
  149. },
  150. }
  151. </script>