DeleteLb.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ params.title }}</div>
  4. <div slot="body">
  5. <a-alert v-if="alertProps" v-bind="alertProps" class="mb-2" />
  6. <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="this.params.name" :unit="params.unit" />
  7. <dialog-table v-if="params.columns && params.columns.length" :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form :form="form.fc" hideRequiredMark>
  9. <a-form-item v-if="showDeleteEip" :label="$t('compute.text_1265')" v-bind="formItemLayout" :extra="$t('compute.text_1266')">
  10. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.auto_delete" />
  11. </a-form-item>
  12. </a-form>
  13. </div>
  14. <div slot="footer">
  15. <a-button v-bind="okButtonProps" @click="handleConfirm">{{ $t("dialog.ok") }}</a-button>
  16. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  17. </div>
  18. </base-dialog>
  19. </template>
  20. <script>
  21. import * as R from 'ramda'
  22. import DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'DeleteLbDialog',
  26. mixins: [DialogMixin, WindowsMixin],
  27. data () {
  28. return {
  29. loading: false,
  30. form: {
  31. fc: this.$form.createForm(this),
  32. },
  33. decorators: {
  34. auto_delete: [
  35. 'auto_delete',
  36. {
  37. initialValue: false,
  38. valuePropName: 'checked',
  39. },
  40. ],
  41. },
  42. formItemLayout: {
  43. wrapperCol: {
  44. span: 21,
  45. },
  46. labelCol: {
  47. span: 3,
  48. },
  49. },
  50. }
  51. },
  52. computed: {
  53. alertProps () {
  54. const { alert } = this.params
  55. const data = {
  56. String: { message: alert, type: 'warning' },
  57. Object: alert,
  58. }
  59. const t = R.type(alert)
  60. return data[t] || null
  61. },
  62. okButtonProps () {
  63. const defaultProps = {
  64. type: 'primary',
  65. loading: this.loading,
  66. }
  67. const { okButtonProps } = this.params
  68. if (okButtonProps && R.type(okButtonProps) === 'Object') {
  69. return Object.assign(defaultProps, okButtonProps)
  70. }
  71. return defaultProps
  72. },
  73. idKey () {
  74. return this.params.idKey || 'id'
  75. },
  76. showDeleteEip () {
  77. return this.params.data.some(item => {
  78. return ['OneCloud', 'Huawei'].includes(item.brand) && item.eip_mode === 'elastic_ip'
  79. })
  80. },
  81. },
  82. methods: {
  83. async handleConfirm () {
  84. this.loading = true
  85. try {
  86. const ids = this.params.data.map(item => item[this.idKey])
  87. const values = await this.form.fc.validateFields()
  88. const data = {}
  89. if (values.auto_delete) {
  90. data.delete_eip = true
  91. }
  92. await this.params.onManager('batchDelete', {
  93. id: ids,
  94. managerArgs: { data },
  95. })
  96. this.cancelDialog()
  97. } finally {
  98. this.loading = false
  99. }
  100. },
  101. },
  102. }
  103. </script>