SetUser.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('cloudenv.cloudgroup_single_action1') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.cloudgroup')" :count="params.data.length" :action="$t('cloudenv.cloudgroup_single_action1')" />
  6. <dialog-table class="mb-2" :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('cloudenv.coludgroup_text001')">
  11. <list-select
  12. v-decorator="decorators.clouduser_ids"
  13. :listProps="clouduserSelectProps"
  14. :formatter="row => `${row.name} / ${row.cloudaccount || ''}`"
  15. :dialog-params="{ mask: false, width: 900, title: $t('rules.clouduser') }" />
  16. </a-form-item>
  17. </a-form>
  18. </div>
  19. <div slot="footer">
  20. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $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 get from 'lodash/get'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. import ListSelect from '@/sections/ListSelect'
  30. import { getNameFilter } from '@/utils/common/tableFilter'
  31. import { getStatusTableColumn } from '@/utils/common/tableColumn'
  32. export default {
  33. name: 'CloudgroupSetUserDialog',
  34. components: {
  35. ListSelect,
  36. },
  37. mixins: [DialogMixin, WindowsMixin],
  38. data () {
  39. return {
  40. loading: false,
  41. form: {
  42. fc: this.$form.createForm(this),
  43. fi: {
  44. generate_name: '',
  45. },
  46. },
  47. decorators: {
  48. clouduser_ids: [
  49. 'clouduser_ids',
  50. {
  51. validateFirst: true,
  52. initialValue: get(this.params.data[0], 'cloudusers', []).map(item => item.id),
  53. rules: [
  54. { required: true, message: this.$t('common.select') },
  55. ],
  56. },
  57. ],
  58. },
  59. clouduserSelectProps: {
  60. list: this.$list.createList(this, {
  61. resource: 'cloudusers',
  62. apiVersion: 'v1',
  63. getParams: () => {
  64. return {
  65. scope: this.$store.getters.scope,
  66. manager_id: this.params.data[0].manager_id,
  67. cloudaccount_id: this.params.data[0].cloudaccount_id,
  68. }
  69. },
  70. filterOptions: {
  71. name: getNameFilter(),
  72. },
  73. }),
  74. columns: [
  75. {
  76. field: 'name',
  77. title: this.$t('table.title.name'),
  78. showOverflow: 'title',
  79. },
  80. getStatusTableColumn({ statusModule: 'clouduser' }),
  81. {
  82. field: 'cloudaccount',
  83. title: this.$t('dictionary.cloudaccount'),
  84. showOverflow: 'title',
  85. },
  86. ],
  87. },
  88. formItemLayout: {
  89. wrapperCol: {
  90. span: 21,
  91. },
  92. labelCol: {
  93. span: 3,
  94. },
  95. },
  96. }
  97. },
  98. computed: {
  99. paramClouduserIds () {
  100. return this.params.data[0] && this.params.data[0].cloudusers && this.params.data[0].cloudusers.map(item => item.id)
  101. },
  102. },
  103. watch: {
  104. paramClouduserIds (val) {
  105. if (val && val.length) {
  106. this.form.fc.setFieldsValue({
  107. clouduser_ids: val,
  108. })
  109. } else {
  110. this.form.fc.setFieldsValue({
  111. clouduser_ids: [],
  112. })
  113. }
  114. },
  115. },
  116. methods: {
  117. async handleConfirm () {
  118. this.loading = true
  119. try {
  120. const values = await this.form.fc.validateFields()
  121. await this.params.onManager('performAction', {
  122. steadyStatus: ['available'],
  123. id: this.params.data[0].id,
  124. managerArgs: {
  125. action: 'set-users',
  126. data: {
  127. ...values,
  128. provider: this.params.data[0].provider,
  129. },
  130. },
  131. })
  132. this.cancelDialog()
  133. this.$bus.$emit('CloudgroupSidepageClouduserListRefresh')
  134. } finally {
  135. this.loading = false
  136. }
  137. },
  138. },
  139. }
  140. </script>