Update.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('network.text_220')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.eip')" :count="params.data.length" :action="$t('network.text_220')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('network.text_195')" v-bind="formItemLayout">
  10. <a-input-number v-if="isOneCloud" style="width: 120px" :precision="0" :min="1" v-decorator="decorators.bandwidth" />
  11. <a-tooltip v-else placement="top" :title="$t('network.eip.text_725', [maxBandwidth])">
  12. <a-input-number style="width: 120px" :precision="0" :min="1" :max="200" v-decorator="decorators.bandwidth" />
  13. </a-tooltip>
  14. <span class="ml-2">Mbps</span>
  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: 'EipUpdateDialog',
  29. mixins: [DialogMixin, WindowsMixin],
  30. data () {
  31. return {
  32. loading: false,
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. decorators: {
  37. bandwidth: [
  38. 'bandwidth',
  39. {
  40. initialValue: this.params.data[0].bandwidth || 30,
  41. },
  42. ],
  43. },
  44. formItemLayout: {
  45. wrapperCol: {
  46. span: 21,
  47. },
  48. labelCol: {
  49. span: 3,
  50. },
  51. },
  52. }
  53. },
  54. computed: {
  55. isOneCloud () {
  56. return this.params.data[0].provider === 'OneCloud'
  57. },
  58. maxBandwidth () {
  59. const eipItem = this.params.data[0]
  60. let maxBandwidth = 200
  61. const isBandwidth = eipItem.charge_type === 'bandwidth'
  62. if (eipItem.provider === 'Huawei') {
  63. maxBandwidth = isBandwidth ? 2000 : 300
  64. }
  65. if (eipItem.provider === 'Aliyun') {
  66. maxBandwidth = 500
  67. }
  68. return maxBandwidth
  69. },
  70. },
  71. methods: {
  72. doUpdate (data) {
  73. return this.params.onManager('performAction', {
  74. id: data.id,
  75. managerArgs: {
  76. action: 'change-bandwidth',
  77. data,
  78. },
  79. })
  80. },
  81. async handleConfirm () {
  82. this.loading = true
  83. try {
  84. let values = await this.form.fc.validateFields()
  85. values = {
  86. ...values,
  87. id: this.params.data[0].id,
  88. }
  89. await this.doUpdate(values)
  90. this.loading = false
  91. this.cancelDialog()
  92. } catch (error) {
  93. this.loading = false
  94. }
  95. },
  96. },
  97. }
  98. </script>