index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <v-card class="card-box d-flex pa-3" height="80vh">
  3. <v-row no-gutters justify="space-between">
  4. <v-col cols="2">
  5. <v-treeview
  6. :items="treeData"
  7. activatable
  8. color="primary"
  9. item-value="id"
  10. item-title="anotherName"
  11. open-all
  12. open-strategy="single"
  13. @update:activated="handleClick"
  14. @update:opened="handleClick"
  15. ></v-treeview>
  16. </v-col>
  17. <v-divider vertical></v-divider>
  18. <v-col class="ml-10">
  19. <TextInput v-model="query.name" :item="textItem" @change="getUserList"></TextInput>
  20. <v-data-table
  21. :loading="loading"
  22. color="#00897B"
  23. :items="tableData"
  24. :headers="headers"
  25. >
  26. <template v-slot:item.actions="{ item }">
  27. <v-btn color="primary" variant="text" @click="handleBinding(item)">{{ $t('enterprise.userManagement.jobBinding') }}</v-btn>
  28. <v-btn v-if="item.status === '1' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 0, item)">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  29. <v-btn v-if="item.status === '0' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 1, item)">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  30. </template>
  31. <template #bottom>
  32. <CtPagination
  33. v-if="total > 0"
  34. :total="total"
  35. :page="query.pageNo"
  36. :limit="query.pageSize"
  37. @handleChange="handleChangePage"
  38. ></CtPagination>
  39. </template>
  40. </v-data-table>
  41. </v-col>
  42. </v-row>
  43. </v-card>
  44. <CtDialog :visible="show" :widthType="2" titleClass="text-h6" :title="$t('enterprise.userManagement.selectBinding')" @close="handleClose" @submit="handleSubmit">
  45. <CtForm ref="formPageRef" :items="formItems"></CtForm>
  46. </CtDialog>
  47. </template>
  48. <script setup>
  49. defineOptions({ name: 'group-account'})
  50. import { ref } from 'vue'
  51. import { useI18n } from '@/hooks/web/useI18n'
  52. import { timesTampChange } from '@/utils/date'
  53. import { getEnterprisePostPage } from '@/api/recruit/enterprise/system/post'
  54. import { getEnterpriseTree } from '@/api/recruit/enterprise/system/group'
  55. import { getEnterpriseUserList, systemUserEnable, systemUserDisable, systemUserBindingPost } from '@/api/recruit/enterprise/system/user'
  56. import Confirm from '@/plugins/confirm'
  57. import Snackbar from '@/plugins/snackbar'
  58. const { t } = useI18n()
  59. const total = ref(0)
  60. const loading = ref(false)
  61. const query = ref({
  62. pageSize: 10,
  63. pageNo: 1,
  64. enterpriseId: '',
  65. name: null
  66. })
  67. const tableData = ref([])
  68. const treeData = ref([])
  69. const headers = [
  70. { title: t('login.username'), key: 'name' },
  71. { title: t('enterprise.userManagement.affiliatedEnterprise'), key: 'enterpriseAnotherName' },
  72. { title: t('enterprise.userManagement.post'), key: 'post.nameCn' },
  73. { title: t('enterprise.userManagement.phone'), key: 'phone' },
  74. { title: t('enterprise.userManagement.email'), key: 'email' },
  75. { title: t('enterprise.userManagement.accountType'), key: 'userType', value: item => item.userType === '1' ? t('enterprise.userManagement.administrators') : t('enterprise.userManagement.regularUser'), sortable: false },
  76. { title: t('enterprise.userManagement.lastLoginTime'), key: 'loginDate', value: item => timesTampChange(item.loginDate), sortable: false },
  77. { title: t('common.actions'), key: 'actions' }
  78. ]
  79. const textItem = ref({
  80. type: 'text',
  81. value: null,
  82. width: 250,
  83. clearable: true,
  84. label: '请输入用户名称搜索'
  85. })
  86. const show = ref(false)
  87. const formPageRef = ref()
  88. const bindQuery = ref({})
  89. const postList = ref([])
  90. const formItems = ref({
  91. options: [
  92. {
  93. type: 'autocomplete',
  94. key: 'postId',
  95. value: null,
  96. label: '岗位 *',
  97. noAttach: false,
  98. itemText: 'nameCn',
  99. itemValue: 'id',
  100. rules: [v => !!v || '请选择要绑定的岗位'],
  101. items: []
  102. }
  103. ]
  104. })
  105. // 获取用户列表
  106. const getUserList = async () => {
  107. loading.value = true
  108. try {
  109. const { list, total: number } = await getEnterpriseUserList(query.value)
  110. tableData.value = list
  111. total.value = number
  112. } finally {
  113. loading.value = false
  114. }
  115. }
  116. // 获取树形列表
  117. const getTreeData = async () => {
  118. const data = await getEnterpriseTree()
  119. if (!data) return
  120. treeData.value = [data]
  121. query.value.enterpriseId = data.id
  122. // 获取用户列表
  123. getUserList()
  124. }
  125. getTreeData()
  126. // 分页
  127. const handleChangePage = (e) => {
  128. query.value.pageNo = e
  129. getUserList()
  130. }
  131. // 树形click
  132. const handleClick = (e) => {
  133. if (!e.length) return
  134. query.value.enterpriseId = e[0]
  135. getUserList()
  136. }
  137. const getPostList = async () => {
  138. const res = await getEnterprisePostPage({ pageNo: 1, pageSize: 100 })
  139. postList.value = res.list
  140. }
  141. getPostList()
  142. const apiList = [
  143. { api: systemUserEnable, desc: t('enterprise.userManagement.enableAccount') },
  144. { api: systemUserDisable, desc: t('enterprise.userManagement.disableAccount') }
  145. ]
  146. // 启用、禁用账户
  147. const handleAction = (type, index, item) => {
  148. const ids = [item.id]
  149. Confirm(t('common.confirmTitle'), apiList[index].desc).then(async () => {
  150. await apiList[index].api(ids)
  151. Snackbar.success(t('common.operationSuccessful'))
  152. query.value.pageNo = 1
  153. getUserList()
  154. })
  155. }
  156. // 绑定岗位
  157. const handleBinding = async (item) => {
  158. if (!postList.value.length) {
  159. Snackbar.warning(t('enterprise.userManagement.postNodataToAdd'))
  160. return
  161. }
  162. bindQuery.value.id = item.id
  163. const obj = formItems.value.options.find(e => e.key === 'postId')
  164. obj.items = postList.value
  165. obj.value = item.postId
  166. show.value = true
  167. }
  168. const handleClose = () => {
  169. show.value = false
  170. query.value = {}
  171. }
  172. const handleSubmit = async () => {
  173. const { valid } = await formPageRef.value.formRef.validate()
  174. if (!valid) return
  175. const postId = formItems.value.options.find(e => e.key === 'postId').value
  176. await systemUserBindingPost(bindQuery.value.id, postId)
  177. Snackbar.success(t('common.operationSuccessful'))
  178. handleClose()
  179. getUserList()
  180. }
  181. </script>
  182. <style scoped lang="scss">
  183. </style>