UpdateHotPluggable.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.edit') }}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc"
  7. v-bind="formItemLayout">
  8. <a-form-item :label="$t('compute.pci.hot_pluggable')" :extra="$t('compute.pci.hot_pluggable.tips')">
  9. <a-switch v-decorator="decorators.hot_pluggable" :checked-children="$t('table.title.on')" :un-checked-children="$t('table.title.off')" />
  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 DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'UpdateHotPluggableDialog',
  24. mixins: [DialogMixin, WindowsMixin],
  25. data () {
  26. const initHotPluggable = this.params.data[0].hot_pluggable
  27. return {
  28. loading: false,
  29. form: {
  30. fc: this.$form.createForm(this),
  31. },
  32. decorators: {
  33. hot_pluggable: [
  34. 'hot_pluggable',
  35. {
  36. initialValue: initHotPluggable,
  37. valuePropName: 'checked',
  38. },
  39. ],
  40. },
  41. formItemLayout: {
  42. wrapperCol: {
  43. span: 20,
  44. },
  45. labelCol: {
  46. span: 4,
  47. },
  48. },
  49. }
  50. },
  51. created () {
  52. this.bizManager = new this.$Manager('isolated_device_models')
  53. },
  54. methods: {
  55. doSubmit (data) {
  56. return this.bizManager.update({
  57. id: this.params.data[0].id,
  58. data,
  59. })
  60. },
  61. async handleConfirm () {
  62. this.loading = true
  63. const { validateFields } = this.form.fc
  64. try {
  65. this.loading = true
  66. const values = await validateFields()
  67. const data = {
  68. hot_pluggable: values.hot_pluggable,
  69. }
  70. await this.doSubmit(data)
  71. this.loading = false
  72. this.cancelDialog()
  73. this.$message.success(this.$t('common.success'))
  74. this.params.refresh && this.params.refresh()
  75. } catch (error) {
  76. this.$message.error(this.$t('common.failed'))
  77. throw error
  78. } finally {
  79. this.loading = false
  80. }
  81. },
  82. },
  83. }
  84. </script>