UpdateCommitBound.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="$t('dictionary.blockstorage')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('storage.text_60')" v-if="params.data[0].brand.toLowerCase() !== 'zstack'">
  9. <a-input-number :step="0.1" v-decorator="decorators.commit_bound" :min="0" />
  10. </a-form-item>
  11. </a-form>
  12. </div>
  13. <div slot="footer">
  14. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  15. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  16. </div>
  17. </base-dialog>
  18. </template>
  19. <script>
  20. import { formItemLayout, MEDIUM_TYPES } from '@Storage/constants/index.js'
  21. import { getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  22. import DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'BlockStorageUpdateCommitBoundDialog',
  26. components: {},
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. return {
  30. MEDIUM_TYPES,
  31. loading: false,
  32. formItemLayout,
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. columns: [
  37. getCopyWithContentTableColumn(),
  38. {
  39. field: 'commit_bound',
  40. title: this.$t('storage.text_60'),
  41. formatter: ({ row }) => {
  42. return row.commit_bound ? row.commit_bound.toFixed(1) : '-'
  43. },
  44. },
  45. {
  46. field: 'medium_type',
  47. title: this.$t('storage.text_39'),
  48. formatter: ({ row }) => {
  49. return MEDIUM_TYPES[row.medium_type] || row.medium_type
  50. },
  51. },
  52. ],
  53. }
  54. },
  55. provide () {
  56. return {
  57. form: this.form,
  58. }
  59. },
  60. computed: {
  61. decorators () {
  62. return {
  63. commit_bound: [
  64. 'commit_bound',
  65. {
  66. initialValue: this.params.data[0].commit_bound || 1,
  67. rules: [
  68. { required: true, message: this.$t('storage.text_61') },
  69. ],
  70. },
  71. ],
  72. medium_type: [
  73. 'medium_type',
  74. {
  75. initialValue: this.params.data[0].medium_type,
  76. },
  77. ],
  78. }
  79. },
  80. },
  81. methods: {
  82. validateForm () {
  83. return new Promise((resolve, reject) => {
  84. this.form.fc.validateFields((err, values) => {
  85. if (err) return reject(err)
  86. resolve(values)
  87. })
  88. })
  89. },
  90. async handleConfirm () {
  91. this.loading = true
  92. try {
  93. const values = await this.validateForm()
  94. if (values.commit_bound) {
  95. values.cmtbound = values.commit_bound
  96. Reflect.deleteProperty(values, 'commit_bound')
  97. }
  98. const manager = new this.$Manager('storages', 'v2')
  99. await manager.batchPerformAction({
  100. ids: this.params.data.map(item => item.id),
  101. action: 'set-commit-bound',
  102. data: values,
  103. })
  104. this.cancelDialog()
  105. this.$message.success(this.$t('storage.text_62'))
  106. this.params.refresh()
  107. this.loading = false
  108. } catch (error) {
  109. this.loading = false
  110. throw error
  111. }
  112. },
  113. },
  114. }
  115. </script>