index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <v-card class="card-box d-flex pa-3">
  3. <v-row no-gutters justify="space-between">
  4. <v-col cols="2">
  5. <div class="d-flex justify-start pr-3">
  6. <v-btn prepend-icon="mdi-plus" variant="text" density="compact" color="primary" @click="handleAdd(1)">{{ $t('enterprise.userManagement.addBranchOffice') }}</v-btn>
  7. </div>
  8. <v-treeview
  9. :items="treeData"
  10. activatable
  11. color="primary"
  12. item-value="id"
  13. open-all
  14. open-strategy="single"
  15. density="compact"
  16. @update:activated="handleClick"
  17. @update:opened="handleClick"
  18. >
  19. <template v-slot:title="{ item }">
  20. <div class="treeTitle font-size-15">
  21. {{ item.anotherName || item.name }}
  22. <v-tooltip activator="parent" location="end">{{ item.anotherName || item.name }}</v-tooltip>
  23. </div>
  24. </template>
  25. </v-treeview>
  26. </v-col>
  27. <v-divider vertical></v-divider>
  28. <v-col class="ml-10" cols="9">
  29. <div class="d-flex justify-space-between px-3">
  30. <TextInput v-model="query.name" :item="textItem" @change="getUserList"></TextInput>
  31. <v-btn prepend-icon="mdi-plus" color="primary" @click="handleAdd(0)">{{ $t('enterprise.userManagement.inviteNewColleagues') }}</v-btn>
  32. </div>
  33. <CtTable
  34. :items="tableData"
  35. :headers="headers"
  36. :loading="loading"
  37. :elevation="0"
  38. :is-tools="false"
  39. :showPage="true"
  40. :total="total"
  41. :page-info="query"
  42. itemKey="id"
  43. @pageHandleChange="handleChangePage"
  44. >
  45. <template #name="{ item }">
  46. <div class="d-flex align-center">
  47. <v-badge
  48. v-if="item?.sex === '1' || item?.sex === '2'"
  49. bordered
  50. offset-y="6"
  51. :color="badgeColor(item)"
  52. :icon="badgeIcon(item)">
  53. <v-avatar size="40" :image="getUserAvatar(item.avatar, item.sex)"></v-avatar>
  54. </v-badge>
  55. <v-avatar v-else size="40" :image="getUserAvatar(item.avatar, item.sex)"></v-avatar>
  56. <span class="ml-3">{{ item?.name }}</span>
  57. </div>
  58. </template>
  59. <template #actions="{ item }">
  60. <v-btn v-if="item.userType === '0'" color="primary" variant="text" @click="handleEdit(item)">编辑</v-btn>
  61. <v-btn v-if="item.status === '1' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 0, item)">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  62. <v-btn v-if="item.status === '0' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 1, item)">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  63. </template>
  64. </CtTable>
  65. </v-col>
  66. </v-row>
  67. </v-card>
  68. <CtDialog :visible="showEdit" :widthType="2" titleClass="text-h6" title="编辑员工基本信息" @close="showEdit = false; editId = null" @submit="handleSubmit">
  69. <CtForm ref="CtFormRef" class="mt-3" :items="formItems">
  70. <template #avatar="{ item }">
  71. <div style="width: 100%;">
  72. <div class="d-flex">
  73. <div style="color: #7a7a7a;">头像</div>
  74. <div class="avatarsBox" @mouseover="showIcon = true" @mouseleave="showIcon = false">
  75. <v-avatar class="elevation-5" size=80 :image="getUserAvatar(item.value, item.sex)"></v-avatar>
  76. <div v-show="showIcon" @click="openFileInput" v-bind="$attrs" class="mdi mdi-camera-outline">
  77. <input
  78. type="file"
  79. ref="fileInput"
  80. accept="image/png, image/jpg, image/jpeg"
  81. style="display: none;"
  82. @change="handleUploadFile"
  83. />
  84. </div>
  85. </div>
  86. </div>
  87. <div class="text-center color-999 font-size-14 mb-5">*只支持JPG、JPEG、PNG类型的图片</div>
  88. </div>
  89. </template>
  90. </CtForm>
  91. </CtDialog>
  92. <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false"></ImgCropper>
  93. </template>
  94. <script setup>
  95. defineOptions({ name: 'group-account'})
  96. import { ref, computed } from 'vue'
  97. import { useI18n } from '@/hooks/web/useI18n'
  98. import { timesTampChange } from '@/utils/date'
  99. import { getEnterpriseTree } from '@/api/recruit/enterprise/system/group'
  100. import { getEnterpriseUserList, systemUserEnable, systemUserDisable } from '@/api/recruit/enterprise/system/user'
  101. import Confirm from '@/plugins/confirm'
  102. import Snackbar from '@/plugins/snackbar'
  103. import { checkEmail } from '@/utils/validate'
  104. import { updateGroupUserAccount } from '@/api/enterprise'
  105. import { getDict } from '@/hooks/web/useDictionaries'
  106. import { getUserAvatar } from '@/utils/avatar'
  107. import { uploadImage } from '@/api/common'
  108. import { getToken } from '@/utils/auth'
  109. const { t } = useI18n()
  110. const total = ref(0)
  111. const loading = ref(false)
  112. const query = ref({
  113. pageSize: 10,
  114. pageNo: 1,
  115. enterpriseId: '',
  116. name: null
  117. })
  118. const tableData = ref([])
  119. const treeData = ref([])
  120. const headers = [
  121. { title: t('login.username'), key: 'name', sortable: false },
  122. { title: t('enterprise.userManagement.affiliatedEnterprise'), key: 'enterpriseAnotherName', sortable: false, value: item => item.enterpriseAnotherName || item.enterpriseName },
  123. { title: t('enterprise.userManagement.post'), key: 'postName', sortable: false },
  124. { title: t('enterprise.userManagement.phone'), key: 'phone', sortable: false },
  125. { title: t('enterprise.userManagement.email'), key: 'email', sortable: false },
  126. { title: t('enterprise.userManagement.accountType'), key: 'userType', value: item => item.userType === '1' ? t('enterprise.userManagement.administrators') : t('enterprise.userManagement.regularUser'), sortable: false },
  127. { title: t('enterprise.userManagement.lastLoginTime'), key: 'loginDate', value: item => timesTampChange(item.loginDate), sortable: false },
  128. { title: t('common.actions'), key: 'actions', sortable: false }
  129. ]
  130. const textItem = ref({
  131. type: 'text',
  132. value: null,
  133. width: 250,
  134. clearable: true,
  135. label: '请输入用户名称搜索'
  136. })
  137. const badgeColor = computed(() => (item) => {
  138. return (item && item.sex) ? (item.sex === '1' ? '#1867c0' : 'error') : 'error'
  139. })
  140. const badgeIcon = computed(() => (item) => {
  141. return (item && item.sex) ? (item.sex === '1' ? 'mdi-gender-male' : 'mdi-gender-female') : 'mdi-gender-female'
  142. })
  143. // 获取用户列表
  144. const getUserList = async () => {
  145. loading.value = true
  146. try {
  147. const { list, total: number } = await getEnterpriseUserList(query.value)
  148. tableData.value = list
  149. total.value = number
  150. } finally {
  151. loading.value = false
  152. }
  153. }
  154. // 获取树形列表
  155. const getTreeData = async () => {
  156. const data = await getEnterpriseTree()
  157. if (!data) return
  158. treeData.value = [data]
  159. query.value.enterpriseId = data.id
  160. // 获取用户列表
  161. getUserList()
  162. }
  163. getTreeData()
  164. // 分页
  165. const handleChangePage = (e) => {
  166. query.value.pageNo = e
  167. getUserList()
  168. }
  169. // 树形click
  170. const handleClick = (e) => {
  171. if (!e.length) return
  172. query.value.enterpriseId = e[0]
  173. getUserList()
  174. }
  175. const apiList = [
  176. { api: systemUserEnable, desc: t('enterprise.userManagement.enableAccount') },
  177. { api: systemUserDisable, desc: t('enterprise.userManagement.disableAccount') }
  178. ]
  179. // 启用、禁用账户
  180. const handleAction = (type, index, item) => {
  181. const ids = [item.id]
  182. Confirm(t('common.confirmTitle'), apiList[index].desc).then(async () => {
  183. await apiList[index].api(ids)
  184. Snackbar.success(t('common.operationSuccessful'))
  185. query.value.pageNo = 1
  186. getUserList()
  187. })
  188. }
  189. // 打开生成邀请链接页面
  190. const handleAdd = (type) => {
  191. if (!getToken(1)) {
  192. window.location.reload()
  193. return
  194. }
  195. // type: 类型(0 邀请同事 | 1 邀请子公司)
  196. window.open(`/recruit/enterprise/systemManagement/groupAccount/invite/${type}`)
  197. }
  198. const formItems = ref({
  199. options: [
  200. {
  201. slotName: 'avatar',
  202. key: 'avatar',
  203. value: null
  204. },
  205. {
  206. type: 'ifRadio',
  207. key: 'sex',
  208. value: '',
  209. label: '性别 *',
  210. width: 90,
  211. items: []
  212. },
  213. {
  214. type: 'text',
  215. key: 'name',
  216. value: '',
  217. label: '中文名 *',
  218. rules: [v => !!v || '请填写中文名']
  219. },
  220. {
  221. type: 'text',
  222. key: 'phone',
  223. value: '',
  224. label: '联系电话'
  225. },
  226. {
  227. type: 'text',
  228. key: 'email',
  229. value: '',
  230. label: '电子邮箱 *',
  231. disabled: false,
  232. rules: [
  233. value => {
  234. if (value) return true
  235. return '请输入联系邮箱'
  236. },
  237. value => {
  238. if (checkEmail(value)) return true
  239. return '请输入正确的电子邮箱'
  240. }
  241. ]
  242. },
  243. {
  244. type: 'text',
  245. key: 'postName',
  246. value: '',
  247. label: '所在岗位'
  248. }
  249. ]
  250. })
  251. getDict('menduner_sex').then(({ data }) => {
  252. data = data?.length && data || []
  253. formItems.value.options.find(e => e.key === 'sex').items = data
  254. })
  255. // 编辑员工信息
  256. const showEdit = ref(false)
  257. const CtFormRef = ref()
  258. const editId = ref(null)
  259. const showIcon = ref(false)
  260. const handleEdit = async (item) => {
  261. formItems.value.options.forEach(e => { e.value = item[e.key] })
  262. editId.value = item.id
  263. showEdit.value = true
  264. }
  265. // 选择文件
  266. const fileInput = ref()
  267. const clicked = ref(false)
  268. const selectPic = ref('')
  269. const isShowCopper = ref(false)
  270. const openFileInput = () => {
  271. if (clicked.value) return
  272. clicked.value = true
  273. fileInput.value.click()
  274. clicked.value = false
  275. }
  276. // 上传头像
  277. const handleUploadFile = async (e) => {
  278. const file = e.target.files[0]
  279. if (!file) return
  280. const reader = new FileReader()
  281. reader.readAsDataURL(file)
  282. reader.onload = () => {
  283. selectPic.value = String(reader.result)
  284. isShowCopper.value = true
  285. }
  286. }
  287. const handleHideCopper = (data) => {
  288. isShowCopper.value = false
  289. if (data) {
  290. const { file } = data
  291. if (!file) return
  292. const formData = new FormData()
  293. formData.append('file', file)
  294. uploadImage(formData).then(async ({ data }) => {
  295. if (!data) return
  296. formItems.value.options.find(e => e.key === 'avatar').value = data
  297. })
  298. }
  299. }
  300. // 提交
  301. const handleSubmit = async () => {
  302. const { valid } = await CtFormRef.value.formRef.validate()
  303. if (!valid) return
  304. const obj = {
  305. id: editId.value
  306. }
  307. formItems.value.options.forEach(e => { obj[e.key] = e.value })
  308. if (!obj.sex || obj.sex === '0') return Snackbar.warning('请选择员工性别')
  309. await updateGroupUserAccount(obj)
  310. showEdit.value = false
  311. editId.value = null
  312. Snackbar.success('编辑成功')
  313. getUserList()
  314. }
  315. </script>
  316. <style scoped lang="scss">
  317. .avatarsBox {
  318. height: 80px;
  319. width: 80px;
  320. position: relative;
  321. cursor: pointer;
  322. margin: 0 0 10px 100px;
  323. .img {
  324. width: 100%;
  325. height: 100%;
  326. }
  327. .mdi {
  328. font-size: 42px;
  329. color: #fff;
  330. }
  331. div {
  332. position: absolute;
  333. top: 50%;
  334. left: 50%;
  335. transform: translate(-50%, -50%);
  336. border-radius: 50%;
  337. }
  338. }
  339. .treeTitle {
  340. width: 100%;
  341. max-width: 100%;
  342. white-space: nowrap;
  343. text-overflow: ellipsis;
  344. overflow: hidden;
  345. }
  346. </style>