index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <v-card class="pa-5 card-box">
  3. <!-- <div class="mb-3">
  4. <v-btn color="primary" variant="tonal" :disabled="!selected.length" @click="handleAction('all', 0, {})">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  5. <v-btn class="ml-3" color="primary" variant="tonal" :disabled="!selected.length" @click="handleAction('all', 1, {})">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  6. </div> -->
  7. <v-data-table
  8. v-model="selected"
  9. :headers="headers"
  10. :items="items"
  11. hide-default-header
  12. height="70vh"
  13. item-value="id"
  14. >
  15. <template #bottom></template>
  16. <template v-slot:item.actions="{ item }">
  17. <v-btn color="primary" variant="text" @click="handleBinding(item)">{{ $t('enterprise.userManagement.jobBinding') }}</v-btn>
  18. <v-btn v-if="item.status === '1' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 0, item)">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  19. <v-btn v-if="item.status === '0' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 1, item)">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  20. </template>
  21. </v-data-table>
  22. <CtPagination
  23. :total="total"
  24. :page="query.pageNo"
  25. :limit="query.pageSize"
  26. @handleChange="handleChangePage"
  27. ></CtPagination>
  28. </v-card>
  29. <CtDialog :visible="show" :widthType="2" titleClass="text-h6" :title="$t('enterprise.userManagement.selectBinding')" @close="handleClose" @submit="handleSubmit">
  30. <CtForm ref="formPageRef" :items="formItems"></CtForm>
  31. </CtDialog>
  32. </template>
  33. <script setup>
  34. defineOptions({ name: 'system-management-user'})
  35. import { ref } from 'vue'
  36. import { timesTampChange } from '@/utils/date'
  37. import { useI18n } from '@/hooks/web/useI18n'
  38. import { getEnterprisePostPage } from '@/api/recruit/enterprise/system/post'
  39. import { getEnterpriseUserList, systemUserEnable, systemUserDisable, systemUserBindingPost } from '@/api/recruit/enterprise/system/user'
  40. import Confirm from '@/plugins/confirm'
  41. import Snackbar from '@/plugins/snackbar'
  42. const { t } = useI18n()
  43. const show = ref(false)
  44. const total = ref(10)
  45. const items = ref([])
  46. const selected = ref([])
  47. const formPageRef = ref()
  48. const bindQuery = ref({})
  49. const query = ref({
  50. pageNo: 1,
  51. pageSize: 10
  52. })
  53. const postList = ref([])
  54. const headers = [
  55. { title: t('login.username'), key: 'name' },
  56. { title: t('enterprise.userManagement.affiliatedEnterprise'), key: 'enterpriseAnotherName' },
  57. { title: t('enterprise.userManagement.post'), key: 'post.nameCn' },
  58. { title: t('enterprise.userManagement.phone'), key: 'phone' },
  59. { title: t('enterprise.userManagement.email'), key: 'email' },
  60. { title: t('enterprise.userManagement.accountType'), key: 'userType', value: item => item.userType === '1' ? t('enterprise.userManagement.administrators') : t('enterprise.userManagement.regularUser'), sortable: false },
  61. { title: t('enterprise.userManagement.lastLoginTime'), key: 'loginDate', value: item => timesTampChange(item.loginDate), sortable: false },
  62. { title: t('common.actions'), key: 'actions' }
  63. ]
  64. const formItems = ref({
  65. options: [
  66. {
  67. type: 'autocomplete',
  68. key: 'postId',
  69. value: null,
  70. label: '岗位 *',
  71. noAttach: false,
  72. itemText: 'nameCn',
  73. itemValue: 'id',
  74. rules: [v => !!v || '请选择要绑定的岗位'],
  75. items: []
  76. }
  77. ]
  78. })
  79. // 获取企业用户列表
  80. const getData = async () => {
  81. const { list, total: number } = await getEnterpriseUserList(query.value)
  82. items.value = list
  83. total.value = number
  84. // 岗位列表
  85. const res = await getEnterprisePostPage({ pageNo: 1, pageSize: 100 })
  86. postList.value = res.list
  87. }
  88. getData()
  89. const handleChangePage = (e) => {
  90. query.value.pageNo = e
  91. getData()
  92. }
  93. const apiList = [
  94. { api: systemUserEnable, desc: t('enterprise.userManagement.enableAccount') },
  95. { api: systemUserDisable, desc: t('enterprise.userManagement.disableAccount') }
  96. ]
  97. // 启用、禁用账户
  98. const handleAction = (type, index, item) => {
  99. const ids = type ? selected.value : [item.id]
  100. Confirm(t('common.confirmTitle'), apiList[index].desc).then(async () => {
  101. await apiList[index].api(ids)
  102. Snackbar.success(t('common.operationSuccessful'))
  103. selected.value = []
  104. query.value.pageNo = 1
  105. getData()
  106. })
  107. }
  108. // 绑定岗位
  109. const handleBinding = async (item) => {
  110. if (!postList.value.length) {
  111. Snackbar.warning(t('enterprise.userManagement.postNodataToAdd'))
  112. return
  113. }
  114. bindQuery.value.id = item.id
  115. const obj = formItems.value.options.find(e => e.key === 'postId')
  116. obj.items = postList.value
  117. obj.value = item.postId
  118. show.value = true
  119. }
  120. const handleClose = () => {
  121. show.value = false
  122. query.value = {}
  123. }
  124. const handleSubmit = async () => {
  125. const { valid } = await formPageRef.value.formRef.validate()
  126. if (!valid) return
  127. const postId = formItems.value.options.find(e => e.key === 'postId').value
  128. await systemUserBindingPost(bindQuery.value.id, postId)
  129. Snackbar.success(t('common.operationSuccessful'))
  130. handleClose()
  131. getData()
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. :deep(.v-table > .v-table__wrapper > table > thead) {
  136. background-color: #f7f8fa !important
  137. }
  138. :deep(.v-selection-control__input) {
  139. color: #767778
  140. }
  141. </style>