index.vue 5.3 KB

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