JointUser.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_452', [$t('dictionary.user')])}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.group')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :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('dictionary.user')">
  11. <a-select
  12. :filterOption="filterOption"
  13. :loading="userLoading"
  14. v-decorator="decorators.users"
  15. mode="multiple"
  16. :placeholder="$t('common_489')">
  17. <a-select-option v-for="item in users" :key="item.id">
  18. {{item.name}}
  19. </a-select-option>
  20. </a-select>
  21. </a-form-item>
  22. </a-form>
  23. </div>
  24. <div slot="footer">
  25. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  26. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  27. </div>
  28. </base-dialog>
  29. </template>
  30. <script>
  31. import DialogMixin from '@/mixins/dialog'
  32. import WindowsMixin from '@/mixins/windows'
  33. export default {
  34. name: 'GroupJoinUserDialog',
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. users: [],
  40. userLoading: false,
  41. form: {
  42. fc: this.$form.createForm(this),
  43. },
  44. decorators: {
  45. users: [
  46. 'users',
  47. {
  48. validateFirst: true,
  49. rules: [
  50. { required: true, message: this.$t('system.text_499') },
  51. ],
  52. },
  53. ],
  54. },
  55. formItemLayout: {
  56. wrapperCol: {
  57. span: 22,
  58. },
  59. labelCol: {
  60. span: 2,
  61. },
  62. },
  63. }
  64. },
  65. created () {
  66. this.fetchUsers()
  67. },
  68. methods: {
  69. filterOption (input, option) {
  70. return (
  71. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  72. )
  73. },
  74. async fetchUsers (query) {
  75. const manager = new this.$Manager('users', 'v1')
  76. this.userLoading = true
  77. try {
  78. const { data } = await manager.list({
  79. params: {
  80. domain_id: this.params.data[0].domain_id,
  81. scope: this.$store.getters.scope,
  82. },
  83. })
  84. this.users = data.data || []
  85. } catch (err) {
  86. throw err
  87. } finally {
  88. this.userLoading = false
  89. }
  90. },
  91. async handleConfirm () {
  92. this.loading = true
  93. try {
  94. const values = await this.form.fc.validateFields()
  95. await new this.$Manager('groups', 'v1').performAction({
  96. id: this.params.data[0].id,
  97. action: 'add-users',
  98. data: {
  99. user: values.users,
  100. },
  101. })
  102. this.params.success()
  103. this.cancelDialog()
  104. } catch (error) {
  105. this.loading = false
  106. throw error
  107. }
  108. },
  109. },
  110. }
  111. </script>