ResourceRenewFee.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1232')}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <div slot="message">{{$t('compute.text_1390')}}</div>
  7. </a-alert>
  8. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1232')" />
  9. <dialog-table :data="params.data" :columns="columns" />
  10. <a-form
  11. :form="form.fc">
  12. <a-form-item :label="$t('compute.text_1233')" v-bind="formItemLayout">
  13. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.autoRenew" />
  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: 'VmResourceRenewFeeDialog',
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. const autoRenew = this.params.data[0].auto_renew
  31. return {
  32. loading: false,
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. decorators: {
  37. autoRenew: [
  38. 'autoRenew',
  39. {
  40. initialValue: autoRenew,
  41. valuePropName: 'checked',
  42. },
  43. ],
  44. },
  45. formItemLayout: {
  46. wrapperCol: {
  47. span: 21,
  48. },
  49. labelCol: {
  50. span: 3,
  51. },
  52. },
  53. }
  54. },
  55. computed: {
  56. columns () {
  57. const showFields = ['name', 'billing_type', 'brand']
  58. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  59. },
  60. },
  61. methods: {
  62. validateForm () {
  63. return new Promise((resolve, reject) => {
  64. this.form.fc.validateFields((err, values) => {
  65. if (!err) {
  66. resolve(values)
  67. } else {
  68. reject(err)
  69. }
  70. })
  71. })
  72. },
  73. doResourceRenewFeeSubmit (data) {
  74. const selectedIds = this.params.data.map(item => item.id)
  75. return new this.$Manager('servers', 'v2').batchPerformAction({
  76. ids: selectedIds,
  77. action: 'set-auto-renew',
  78. data: {
  79. auto_renew: data.autoRenew,
  80. },
  81. })
  82. },
  83. async handleConfirm () {
  84. this.loading = true
  85. try {
  86. const values = await this.validateForm()
  87. await this.doResourceRenewFeeSubmit(values)
  88. this.loading = false
  89. this.params.refresh()
  90. this.cancelDialog()
  91. } catch (error) {
  92. this.loading = false
  93. }
  94. },
  95. },
  96. }
  97. </script>