index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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') && showBadge"
  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 { checkCompanyEmail } from '@/utils/validate'
  104. import { updateGroupUserAccount } from '@/api/enterprise'
  105. import { getDict } from '@/hooks/web/useDictionaries'
  106. import { getUserAvatar } from '@/utils/avatar'
  107. import { uploadFile } from '@/api/common'
  108. import { getToken } from '@/utils/auth'
  109. const { t } = useI18n()
  110. const showBadge = ref(false) // 性别设置甲方要求已去掉
  111. const total = ref(0)
  112. const loading = ref(false)
  113. const query = ref({
  114. pageSize: 10,
  115. pageNo: 1,
  116. enterpriseId: '',
  117. name: null
  118. })
  119. const tableData = ref([])
  120. const treeData = ref([])
  121. const headers = [
  122. { title: t('login.username'), key: 'name', sortable: false },
  123. { title: t('enterprise.userManagement.affiliatedEnterprise'), key: 'enterpriseAnotherName', sortable: false, value: item => item.enterpriseAnotherName || item.enterpriseName },
  124. { title: t('enterprise.userManagement.post'), key: 'postName', sortable: false },
  125. { title: t('enterprise.userManagement.phone'), key: 'phone', sortable: false },
  126. { title: t('enterprise.userManagement.email'), key: 'email', sortable: false },
  127. { title: t('enterprise.userManagement.accountType'), key: 'userType', value: item => item.userType === '1' ? t('enterprise.userManagement.administrators') : t('enterprise.userManagement.regularUser'), sortable: false },
  128. { title: t('enterprise.userManagement.lastLoginTime'), key: 'loginDate', value: item => timesTampChange(item.loginDate), sortable: false },
  129. { title: t('common.actions'), key: 'actions', sortable: false }
  130. ]
  131. const textItem = ref({
  132. type: 'text',
  133. value: null,
  134. width: 250,
  135. clearable: true,
  136. label: '请输入用户名称搜索'
  137. })
  138. const badgeColor = computed(() => (item) => {
  139. return (item && item.sex) ? (item.sex === '1' ? '#1867c0' : 'error') : 'error'
  140. })
  141. const badgeIcon = computed(() => (item) => {
  142. return (item && item.sex) ? (item.sex === '1' ? 'mdi-gender-male' : 'mdi-gender-female') : 'mdi-gender-female'
  143. })
  144. // 获取用户列表
  145. const getUserList = async () => {
  146. loading.value = true
  147. try {
  148. const { list, total: number } = await getEnterpriseUserList(query.value)
  149. tableData.value = list
  150. total.value = number
  151. } finally {
  152. loading.value = false
  153. }
  154. }
  155. // 获取树形列表
  156. const getTreeData = async () => {
  157. const data = await getEnterpriseTree()
  158. if (!data) return
  159. treeData.value = [data]
  160. query.value.enterpriseId = data.id
  161. // 获取用户列表
  162. getUserList()
  163. }
  164. getTreeData()
  165. // 分页
  166. const handleChangePage = (e) => {
  167. query.value.pageNo = e
  168. getUserList()
  169. }
  170. // 树形click
  171. const handleClick = (e) => {
  172. if (!e.length) return
  173. query.value.enterpriseId = e[0]
  174. getUserList()
  175. }
  176. const apiList = [
  177. { api: systemUserEnable, desc: t('enterprise.userManagement.enableAccount') },
  178. { api: systemUserDisable, desc: t('enterprise.userManagement.disableAccount') }
  179. ]
  180. // 启用、禁用账户
  181. const handleAction = (type, index, item) => {
  182. const ids = [item.id]
  183. Confirm(t('common.confirmTitle'), apiList[index].desc).then(async () => {
  184. await apiList[index].api(ids)
  185. Snackbar.success(t('common.operationSuccessful'))
  186. query.value.pageNo = 1
  187. getUserList()
  188. })
  189. }
  190. // 打开生成邀请链接页面
  191. const handleAdd = (type) => {
  192. if (!getToken(1)) {
  193. window.location.reload()
  194. return
  195. }
  196. // type: 类型(0 邀请同事 | 1 邀请子公司)
  197. window.open(`/recruit/enterprise/systemManagement/groupAccount/invite/${type}`)
  198. }
  199. const formItems = ref({
  200. options: [
  201. {
  202. slotName: 'avatar',
  203. key: 'avatar',
  204. value: null
  205. },
  206. // {
  207. // type: 'ifRadio',
  208. // key: 'sex',
  209. // value: '',
  210. // label: '性别 *',
  211. // width: 90,
  212. // items: []
  213. // },
  214. {
  215. type: 'text',
  216. key: 'name',
  217. value: '',
  218. label: '中文名 *',
  219. rules: [v => !!v || '请填写中文名']
  220. },
  221. {
  222. type: 'phoneNumber',
  223. key: 'phone',
  224. value: '',
  225. clearable: true,
  226. label: '联系手机号 *',
  227. rules: [v => !!v || '请填写联系手机号']
  228. },
  229. {
  230. type: 'text',
  231. key: 'email',
  232. value: '',
  233. label: '电子邮箱 *',
  234. disabled: false,
  235. rules: [
  236. value => {
  237. if (value) return true
  238. return '请输入联系邮箱'
  239. },
  240. value => {
  241. if (checkCompanyEmail(value)) return true
  242. return '请输入正确的电子邮箱'
  243. }
  244. ]
  245. },
  246. {
  247. type: 'text',
  248. key: 'postName',
  249. value: '',
  250. label: '所在岗位'
  251. }
  252. ]
  253. })
  254. getDict('menduner_sex').then(({ data }) => {
  255. data = data?.length && data || []
  256. formItems.value.options.find(e => e.key === 'sex').items = data
  257. })
  258. // 编辑员工信息
  259. const showEdit = ref(false)
  260. const CtFormRef = ref()
  261. const editId = ref(null)
  262. const showIcon = ref(false)
  263. const handleEdit = async (item) => {
  264. formItems.value.options.forEach(e => { e.value = item[e.key] })
  265. editId.value = item.id
  266. showEdit.value = true
  267. }
  268. // 选择文件
  269. const fileInput = ref()
  270. const clicked = ref(false)
  271. const selectPic = ref('')
  272. const isShowCopper = ref(false)
  273. const openFileInput = () => {
  274. if (clicked.value) return
  275. clicked.value = true
  276. fileInput.value.click()
  277. clicked.value = false
  278. }
  279. // 上传头像
  280. const accept = ['jpg', 'png', 'jpeg']
  281. const handleUploadFile = async (e) => {
  282. const file = e.target.files[0]
  283. if (!file) return
  284. const fileType = file.name.split('.')[1]
  285. if (!accept.includes(fileType)) return Snackbar.warning('请上传图片格式文件')
  286. const reader = new FileReader()
  287. reader.readAsDataURL(file)
  288. reader.onload = () => {
  289. selectPic.value = String(reader.result)
  290. isShowCopper.value = true
  291. }
  292. }
  293. const handleHideCopper = (data) => {
  294. isShowCopper.value = false
  295. if (data) {
  296. const { file } = data
  297. if (!file) return
  298. const formData = new FormData()
  299. formData.append('file', file)
  300. formData.append('path', 'img')
  301. uploadFile(formData).then(async ({ data }) => {
  302. if (!data) return
  303. formItems.value.options.find(e => e.key === 'avatar').value = data
  304. })
  305. }
  306. }
  307. // 提交
  308. const handleSubmit = async () => {
  309. const { valid } = await CtFormRef.value.formRef.validate()
  310. if (!valid) return
  311. const obj = {
  312. id: editId.value
  313. }
  314. formItems.value.options.forEach(e => { obj[e.key] = e.value })
  315. if (!obj.sex || obj.sex === '0') return Snackbar.warning('请选择员工性别')
  316. await updateGroupUserAccount(obj)
  317. showEdit.value = false
  318. editId.value = null
  319. Snackbar.success('编辑成功')
  320. getUserList()
  321. }
  322. </script>
  323. <style scoped lang="scss">
  324. .avatarsBox {
  325. height: 80px;
  326. width: 80px;
  327. position: relative;
  328. cursor: pointer;
  329. margin: 0 0 10px 100px;
  330. .img {
  331. width: 100%;
  332. height: 100%;
  333. }
  334. .mdi {
  335. font-size: 42px;
  336. color: #fff;
  337. }
  338. div {
  339. position: absolute;
  340. top: 50%;
  341. left: 50%;
  342. transform: translate(-50%, -50%);
  343. border-radius: 50%;
  344. }
  345. }
  346. .treeTitle {
  347. width: 100%;
  348. max-width: 100%;
  349. white-space: nowrap;
  350. text-overflow: ellipsis;
  351. overflow: hidden;
  352. }
  353. </style>