CloneSkuUpdateDialog.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_983')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.sku')" :count="params.data.length" :action="$t('compute.text_983')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('compute.text_1051')" v-bind="formItemLayout">
  10. <a-input-number :min="1" v-decorator="decorators.cpu_core_count" />{{$t('compute.text_167')}}</a-form-item>
  11. <a-form-item :label="$t('compute.text_1052')" v-bind="formItemLayout">
  12. <a-input-number :min="1" v-decorator="decorators.memory_size_mb" /> GB
  13. </a-form-item>
  14. </a-form>
  15. </div>
  16. <div slot="footer">
  17. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  18. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  19. </div>
  20. </base-dialog>
  21. </template>
  22. <script>
  23. import DialogMixin from '@/mixins/dialog'
  24. import WindowsMixin from '@/mixins/windows'
  25. export default {
  26. name: 'CloneSkuUpdateDialog',
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. return {
  30. loading: false,
  31. form: {
  32. fc: this.$form.createForm(this),
  33. },
  34. decorators: {
  35. cpu_core_count: [
  36. 'cpu_core_count',
  37. {
  38. initialValue: this.params.data[0].cpu_core_count,
  39. },
  40. ],
  41. memory_size_mb: [
  42. 'memory_size_mb',
  43. {
  44. initialValue: this.params.data[0].memory_size_mb / 1024,
  45. },
  46. ],
  47. },
  48. formItemLayout: {
  49. wrapperCol: {
  50. span: 21,
  51. },
  52. labelCol: {
  53. span: 3,
  54. },
  55. },
  56. }
  57. },
  58. methods: {
  59. validateForm () {
  60. return new Promise((resolve, reject) => {
  61. this.form.fc.validateFields((err, values) => {
  62. if (!err) {
  63. resolve(values)
  64. } else {
  65. reject(err)
  66. }
  67. })
  68. })
  69. },
  70. doCreate (data) {
  71. return this.params.onManager('create', {
  72. managerArgs: {
  73. data,
  74. },
  75. })
  76. },
  77. async handleConfirm () {
  78. this.loading = true
  79. try {
  80. let values = await this.validateForm()
  81. values = {
  82. ...values,
  83. memory_size_mb: values.memory_size_mb * 1024,
  84. brand: this.params.data[0].brand,
  85. }
  86. this.loading = true
  87. await this.doCreate(values)
  88. this.loading = false
  89. this.cancelDialog()
  90. } catch (error) {
  91. this.loading = false
  92. }
  93. },
  94. },
  95. }
  96. </script>