SetReadOnly.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.read_only')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.cloudaccount')" :count="params.data.length" :action="$t('cloudenv.read_only')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <read-only :form="form" :checked="checked" />
  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. import ReadOnly from '@Cloudenv/views/cloudaccount/components/ReadOnly'
  23. export default {
  24. name: 'CloudaccountSetReadOnlyDialog',
  25. components: {
  26. ReadOnly,
  27. },
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. const data = this.params.data[0]
  31. return {
  32. loading: false,
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. decorators: {
  37. read_only: [
  38. 'read_only',
  39. {
  40. initialValue: data.read_only,
  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. checked () {
  57. return this.params?.data[0]?.read_only || false
  58. },
  59. },
  60. methods: {
  61. validateForm () {
  62. return new Promise((resolve, reject) => {
  63. this.form.fc.validateFields((err, values) => {
  64. if (!err) {
  65. resolve(values)
  66. } else {
  67. reject(err)
  68. }
  69. })
  70. })
  71. },
  72. async handleConfirm () {
  73. this.loading = true
  74. try {
  75. const values = await this.form.fc.validateFields()
  76. const ids = this.params.data.map(item => item.id)
  77. if (ids.length > 1) {
  78. await this.params.onManager('batchUpdate', {
  79. ids,
  80. managerArgs: {
  81. data: values,
  82. },
  83. })
  84. } else {
  85. await this.params.onManager('update', {
  86. id: ids[0],
  87. managerArgs: {
  88. data: values,
  89. },
  90. })
  91. }
  92. this.cancelDialog()
  93. } catch (error) {
  94. throw error
  95. } finally {
  96. this.loading = false
  97. }
  98. },
  99. },
  100. }
  101. </script>