JoinResource.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1215')}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <div slot="message">{{$t('compute.text_1216')}}</div>
  7. </a-alert>
  8. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1215')" />
  9. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  10. <a-form
  11. :form="form.fc">
  12. <a-form-item v-bind="formItemLayout">
  13. <a-checkbox v-decorator="decorators.autoDestroy">{{$t('compute.text_1217')}}</a-checkbox>
  14. </a-form-item>
  15. </a-form>
  16. </div>
  17. <div slot="footer">
  18. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import DialogMixin from '@/mixins/dialog'
  25. import WindowsMixin from '@/mixins/windows'
  26. export default {
  27. name: 'VmJoinResourceDialog',
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. return {
  31. loading: false,
  32. form: {
  33. fc: this.$form.createForm(this),
  34. },
  35. decorators: {
  36. autoDestroy: [
  37. 'autoDestroy',
  38. {
  39. initialValue: true,
  40. },
  41. ],
  42. },
  43. formItemLayout: {
  44. wrapperCol: {
  45. span: 12,
  46. },
  47. },
  48. }
  49. },
  50. methods: {
  51. validateForm () {
  52. return new Promise((resolve, reject) => {
  53. this.form.fc.validateFields((err, values) => {
  54. if (!err) {
  55. resolve(values)
  56. } else {
  57. reject(err)
  58. }
  59. })
  60. })
  61. },
  62. doJoinResourceSubmit (data) {
  63. const selectedIds = this.params.data.map(item => item.id)
  64. return this.params.onManager('batchPerformAction', {
  65. id: selectedIds,
  66. managerArgs: {
  67. action: 'prepaid-recycle',
  68. data: {
  69. auto_delete: data.autoDestroy,
  70. },
  71. },
  72. })
  73. },
  74. async handleConfirm () {
  75. this.loading = true
  76. try {
  77. const values = await this.validateForm()
  78. await this.doJoinResourceSubmit(values)
  79. this.loading = false
  80. this.cancelDialog()
  81. } catch (error) {
  82. this.loading = false
  83. }
  84. },
  85. },
  86. }
  87. </script>