ResourceFee.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1117')}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <div slot="message">{{$t('compute.text_1389')}}</div>
  7. </a-alert>
  8. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1117')" />
  9. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  10. <a-form
  11. :form="form.fc">
  12. <a-form-item :label="$t('compute.text_1230')" v-bind="formItemLayout">
  13. <a-radio-group v-decorator="decorators.buyDuration">
  14. <a-radio-button
  15. v-for="i in options.buyDurations"
  16. :key="i.value"
  17. :value="i.value">
  18. {{ i.label }}
  19. </a-radio-button>
  20. </a-radio-group>
  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 { BUY_DURATIONS_OPTIONS as buyDurations } from '@Compute/constants'
  32. import DialogMixin from '@/mixins/dialog'
  33. import WindowsMixin from '@/mixins/windows'
  34. export default {
  35. name: 'VmResourceFeeDialog',
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. loading: false,
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. decorators: {
  44. buyDuration: [
  45. 'buyDuration',
  46. {
  47. rules: [
  48. { required: true, message: this.$t('compute.text_1231'), trigger: 'change' },
  49. ],
  50. initialValue: '1M',
  51. },
  52. ],
  53. },
  54. options: {
  55. buyDurations,
  56. },
  57. formItemLayout: {
  58. wrapperCol: {
  59. span: 21,
  60. },
  61. labelCol: {
  62. span: 3,
  63. },
  64. },
  65. }
  66. },
  67. methods: {
  68. validateForm () {
  69. return new Promise((resolve, reject) => {
  70. this.form.fc.validateFields((err, values) => {
  71. if (!err) {
  72. resolve(values)
  73. } else {
  74. reject(err)
  75. }
  76. })
  77. })
  78. },
  79. doResourceFeeSubmit (data) {
  80. const selectedIds = this.params.data.map(item => item.id)
  81. return new this.$Manager('servers').batchPerformAction({
  82. ids: selectedIds,
  83. action: 'renew',
  84. data: {
  85. duration: data.buyDuration,
  86. },
  87. })
  88. },
  89. async handleConfirm () {
  90. this.loading = true
  91. try {
  92. const values = await this.validateForm()
  93. await this.doResourceFeeSubmit(values)
  94. this.loading = false
  95. this.cancelDialog()
  96. } catch (error) {
  97. this.loading = false
  98. }
  99. },
  100. },
  101. }
  102. </script>