Renew.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="params.name" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc">
  8. <a-form-item :label="$t('db.text_54')" v-bind="formItemLayout">
  9. <a-radio-group v-decorator="['duration', {initialValue: (params.data && params.data.length > 0) ? (params.data[0].duration || '1M') : '1M' }]">
  10. <a-radio-button
  11. :key="item.value"
  12. :value="item.value"
  13. v-for="item in BUY_DURATIONS_OPTIONS">
  14. {{item.label}}</a-radio-button>
  15. </a-radio-group>
  16. </a-form-item>
  17. </a-form>
  18. </div>
  19. <div slot="footer">
  20. <a-button :loading="loading" @click="handleConfirm" type="primary">{{ $t('dialog.ok') }}</a-button>
  21. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  22. </div>
  23. </base-dialog>
  24. </template>
  25. <script>
  26. import { BUY_DURATIONS_OPTIONS } from '../constants/index.js'
  27. import { CreateServerForm } from '@Compute/constants'
  28. import DialogMixin from '@/mixins/dialog'
  29. import WindowsMixin from '@/mixins/windows'
  30. export default {
  31. name: 'RedisRenewDialog',
  32. mixins: [DialogMixin, WindowsMixin],
  33. provide () {
  34. return {
  35. form: this.form,
  36. }
  37. },
  38. data () {
  39. return {
  40. BUY_DURATIONS_OPTIONS,
  41. loading: false,
  42. form: {
  43. fc: this.$form.createForm(this),
  44. },
  45. formItemLayout: {
  46. wrapperCol: { span: CreateServerForm.wrapperCol },
  47. labelCol: { span: CreateServerForm.labelCol },
  48. },
  49. decorators: {
  50. boot_order: [
  51. 'boot_order',
  52. {
  53. rules: [
  54. { required: true, message: this.$t('db.text_148') },
  55. ],
  56. },
  57. ],
  58. },
  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. async handleConfirm () {
  74. this.loading = true
  75. try {
  76. const values = await this.validateForm()
  77. const ids = this.params.data.map(item => item.id)
  78. await this.params.onManager('batchPerformAction', {
  79. id: ids,
  80. steadyStatus: 'running',
  81. managerArgs: {
  82. data: values,
  83. action: 'renew',
  84. },
  85. })
  86. this.loading = false
  87. this.$message.success(this.$t('db.text_149'))
  88. this.cancelDialog()
  89. } catch (error) {
  90. this.loading = false
  91. throw error
  92. }
  93. },
  94. },
  95. }
  96. </script>