index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template>
  2. <div class="h-full flex flex-col teamstyle overflow-hidden temaClass">
  3. <!-- 头部 -->
  4. <div class="bg-white flex justify-between team-header">
  5. <div class="flex items-center">
  6. <el-link type="primary" class="text-nowrap mr-20" :icon="CirclePlusFilled"
  7. @click="dialogFromCli('addDeptDialogVisible')">创建部门</el-link>
  8. <el-link class="text-nowrap textFont textFont mr-10" type="primary" :icon="Edit"
  9. @click="updateDepartment('addDeptDialogVisible')">{{ deptListItem.label || '全部人员' }}</el-link>
  10. <span class="textSpan textFont">共 0 人</span>
  11. </div>
  12. <div class="teamForm flex items-center">
  13. <el-input v-model="teamForm.keyword" style="max-width: 650px" size="default" placeholder="请输入姓名搜索" class="mr-6"
  14. clearable @clear="getTableData()" @keyup.enter.native="getTableData()">
  15. <template #prepend>
  16. <el-select v-model="teamForm.matchingType" style="width: 80px">
  17. <el-option label="姓名" :value="0" />
  18. <el-option label="电话" :value="1" />
  19. <el-option label="工号" :value="2" />
  20. </el-select>
  21. </template>
  22. <template #append>
  23. <el-button :icon="Search" @click="getTableData()" />
  24. </template>
  25. </el-input>
  26. <div class="formItem mr-6 flex items-center">
  27. <div class="text-nowrap">状态:</div>
  28. <el-select v-model="teamForm.status" placeholder="请选择" size="default" style="width: 100px"
  29. @change="getTableData()">
  30. <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value" />
  31. </el-select>
  32. </div>
  33. <div class="formItem mr-6 flex items-center">
  34. <div class="text-nowrap">角色:</div>
  35. <el-select v-model="teamForm.roleId" placeholder="请选择" size="default" style="width: 150px" clearable
  36. @change="getTableData()">
  37. <el-option v-for="item in roleList" :key="item.id" :label="item.rolename" :value="item.id" />
  38. </el-select>
  39. </div>
  40. <el-dropdown>
  41. <el-button type="primary">
  42. 更多操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
  43. </el-button>
  44. <template #dropdown>
  45. <el-dropdown-menu>
  46. <el-dropdown-item @click="addPersone(false)" v-permission="['teamAdd']">添加人员</el-dropdown-item>
  47. <el-dropdown-item @click="transitionOperation('exportUser', '')" v-permission="['teamExport']">导出人员</el-dropdown-item>
  48. <el-dropdown-item @click="transitionOperation('importUser', '')" v-permission="['teamImport']">批量导入</el-dropdown-item>
  49. </el-dropdown-menu>
  50. </template>
  51. </el-dropdown>
  52. </div>
  53. </div>
  54. <!-- 内容 -->
  55. <div class="flex-1 flex">
  56. <div class="p-4 w-80 pr-0">
  57. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  58. <div class="flex-1 overflow-y-auto const-left">
  59. <el-tree style="max-width: 600px" :data="deptList" :props="treeProps" @node-click="treeNode">
  60. <template #default="{ node, data }">
  61. <div class="flex justify-between treeContent">
  62. <div class="custom-tree-node" @mouseleave="mouseleave(data,$event)" @mouseover="mouseover(data,$event)">
  63. <div class="treeLabel"><TextTranslation translationTypes="departmentName" :translationValue="node.label"></TextTranslation></div>
  64. <div class="treeIcon nodeEle" id="treeIcon" v-if="data.id > 0">
  65. <el-link type="primary" :icon="CirclePlus" :underline="false" @click.stop="dialogFromCli('addDeptDialogVisible', data, true)"></el-link>
  66. <el-link type="primary" :icon="Delete" :underline="false" style="margin-left: 6px;" @click.stop="deteleDept(data)"></el-link>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. </el-tree>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="flex-1 p-4 overflow-auto">
  76. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col overflow-hidden pt-2 pl-2 pr-2">
  77. <div class="flex-1">
  78. <el-table ref="multipleTableRef" :data="tableData" v-loading="loadingFrom.tableLoading"
  79. @selection-change="changeBatch" style="width: 100%;height: calc(100vh - 204px);">
  80. <el-table-column type="selection" width="55" />
  81. <el-table-column label="姓名" property="name" width="150">
  82. <template #default="scope">
  83. <TextTranslation translationTypes="userName" :translationValue="scope.row.name"></TextTranslation>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="手机" property="phone"></el-table-column>
  87. <el-table-column label="工号" property="jobNumber"></el-table-column>
  88. <el-table-column label="部门" property="departmentName">
  89. <template #default="scope">
  90. <TextTranslation translationTypes="departmentName" :translationValue="scope.row.departmentName"></TextTranslation>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="角色" property="roleName"></el-table-column>
  94. <el-table-column label="创建时间" property="createTime"></el-table-column>
  95. <el-table-column label="操作" width="200" fixed="right">
  96. <template #default="scope">
  97. <el-button :size="'small'" @click="resetPwd(scope.row)">重置</el-button>
  98. <el-button type="primary" :size="'small'" @click="addPersone(scope.row)">编辑</el-button>
  99. <el-button :size="'small'" @click="transitionOperation('disable', scope.row)"
  100. v-if="scope.row.isActive == 1">停用</el-button>
  101. <el-button type="success" :size="'small'" @click="enableUser(scope.row)"
  102. v-if="scope.row.isActive == 0">启用</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </div>
  107. <div class="flex justify-between pb-2 pt-2 pl-3 pr-3">
  108. <div class="flex">
  109. <el-button size="default" @click="changeBatch(false)"
  110. :disabled="batchTableData.length == 0">取消</el-button>
  111. <el-dropdown class="ml-3">
  112. <el-button type="primary">
  113. 更多操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
  114. </el-button>
  115. <template #dropdown>
  116. <el-dropdown-menu>
  117. <el-dropdown-item @click="batchItem('批量修改部门', 'dept', deptList)"
  118. :disabled="batchTableData.length == 0">批量修改部门</el-dropdown-item>
  119. <el-dropdown-item @click="batchItem('批量修改角色', 'role', roleList)"
  120. :disabled="batchTableData.length == 0">批量修改角色</el-dropdown-item>
  121. <el-dropdown-item @click="batchEnableItem"
  122. :disabled="batchTableData.length == 0">批量启用员工</el-dropdown-item>
  123. </el-dropdown-menu>
  124. </template>
  125. </el-dropdown>
  126. </div>
  127. <div class="pr-4">
  128. <el-pagination layout="total, prev, pager, next, sizes" :total="totalTable" :page-size="teamForm.pageSize"
  129. @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <!-- 新增部门 -->
  136. <el-dialog v-model="dialogFrom.addDeptDialogVisible" width="600" :show-close="false" :before-close="handleClose">
  137. <template #header="{ close, titleId, titleClass }">
  138. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  139. <h4 :id="titleId">{{ deptListItem.label || '创建部门' }}</h4>
  140. <div class="flex">
  141. <el-button @click="dialogFrom.addDeptDialogVisible = false">取消</el-button>
  142. <el-button type="primary" @click="createDepartment(deptRuleFormRef)"
  143. v-bind:loading="loadingFrom.deptDialogVisibleLoading">
  144. 确定
  145. </el-button>
  146. </div>
  147. </div>
  148. </template>
  149. <div class="pt-5">
  150. <el-form ref="deptRuleFormRef" style="max-width: 500px" :model="deptForm" :rules="deptRules" label-width="140px"
  151. size="large" status-icon>
  152. <el-form-item label="部门名称" prop="name">
  153. <el-input v-model="deptForm.name" placeholder="请输入部门名称" clearable />
  154. </el-form-item>
  155. <el-form-item label="主要负责人">
  156. <!-- <el-select v-model="deptForm.managerId" placeholder="请选择" style="width: 100%" clearable>
  157. <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
  158. </el-select> -->
  159. <personnel-search v-model="deptForm.managerId" :size="''" placeholder="请选择"></personnel-search>
  160. </el-form-item>
  161. <el-form-item label="其他负责人">
  162. <!-- <el-select v-model="deptForm.otherManagerIds" placeholder="请选择" style="width: 100%" multiple clearable>
  163. <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
  164. </el-select> -->
  165. <personnel-search v-model="deptForm.otherManagerIds" :size="''" multiple placeholder="请选择"></personnel-search>
  166. </el-form-item>
  167. </el-form>
  168. </div>
  169. </el-dialog>
  170. <!-- 停用 -->
  171. <el-dialog v-model="dialogFrom.resignationVisible" width="600" :show-close="false" :before-close="handleClose">
  172. <template #header="{ close, titleId, titleClass }">
  173. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  174. <h4 :id="titleId">离职停用员工</h4>
  175. <div class="flex">
  176. <el-button @click="dialogFrom.resignationVisible = false">取消</el-button>
  177. <el-button type="primary" @click="resignation" v-bind:loading="loadingFrom.resignationLoading">
  178. 确定
  179. </el-button>
  180. </div>
  181. </div>
  182. </template>
  183. <div class="pt-4 pb-2">
  184. <div class="flex items-center justify-center">
  185. <div class="pr-2">员工离职日期:</div>
  186. <el-date-picker v-model="resignationDate" type="date" placeholder="请选择日期" value-format="YYYY-MM-DD"
  187. :clearable="false" />
  188. </div>
  189. </div>
  190. </el-dialog>
  191. <!-- 导出人员列表 -->
  192. <el-dialog v-model="dialogFrom.exportUserVisible" width="600" :show-close="false" :before-close="handleClose">
  193. <template #header="{ close, titleId, titleClass }">
  194. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  195. <h4 :id="titleId">导出人员列表</h4>
  196. <div class="flex">
  197. <el-button @click="dialogFrom.exportUserVisible = false">取消</el-button>
  198. <el-button type="primary" @click="exportUser" v-bind:loading="loadingFrom.exportUserLoading">
  199. 导出
  200. </el-button>
  201. </div>
  202. </div>
  203. </template>
  204. <div class="pt-4 pb-2">
  205. <div class="flex items-center justify-center">
  206. <div class="pr-2">导出:</div>
  207. <el-radio-group v-model="exportRadio" class="ml-4">
  208. <el-radio value="1" size="large">全部人员</el-radio>
  209. <el-radio value="0" size="large">仅在职人员</el-radio>
  210. </el-radio-group>
  211. </div>
  212. </div>
  213. </el-dialog>
  214. <!-- 人员导入 -->
  215. <el-dialog v-model="dialogFrom.importVisible" width="680" :show-close="false" top="10vh">
  216. <template #header="{ close, titleId, titleClass }">
  217. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  218. <h4 :id="titleId">人员批量导入</h4>
  219. <div class="flex">
  220. <el-button class="mr-3" @click="dialogFrom.importVisible = false">取消</el-button>
  221. <el-upload ref="importUserRef" class="upload-demo" :limit="1" :show-file-list="false" accept=".xlsx"
  222. :http-request="importUser">
  223. <el-button type="primary" :loading="loadingFrom.importLoading">导入</el-button>
  224. </el-upload>
  225. </div>
  226. </div>
  227. </template>
  228. <div class="p-8">
  229. <div class="ml-4 mr-4">
  230. <div class="flex items-center">1、点击下载 <el-link type="primary"
  231. @click="downloadFile('/upload/人员导入模板.xlsx', '人员导入模板.xlsx')">人员导入模板.xlsx</el-link></div>
  232. <div class="mt-4">2、填写excel模板,并上传</div>
  233. </div>
  234. </div>
  235. </el-dialog>
  236. <!-- 新增人员 -->
  237. <AddPersonnelModal :data="{
  238. addPersonnelDialogVisible: dialogFrom.addPersonnelDialogVisible,
  239. deptList: deptListUntreated,
  240. roleList: roleList,
  241. personnelFromData: personnelFromData
  242. }" @closeModal="closeModal" @personnelModalConfirm="personnelModalConfirm" />
  243. <!-- 批量操作 -->
  244. <BatchOperation :batchData="visibleData" :batchNode="batchTableData" :visibleText="allText.batchText"
  245. :popup="visibleType" :batchOperationVisible="dialogFrom.batchOperationVisible" @close="closeModal" />
  246. </div>
  247. </template>
  248. <script lang="ts" setup>
  249. import { ref, reactive, onMounted, onBeforeMount, inject } from 'vue';
  250. import { UploadRequestOptions, dayjs } from 'element-plus'
  251. import { Search, CirclePlusFilled, Edit, CirclePlus, Delete } from '@element-plus/icons-vue'
  252. import { FormInstance, FormRules, ElMessageBox } from 'element-plus'
  253. import { useStore } from '@/store/index'
  254. import { GET_DATA_LIST, DETELE_DEPT, MOD, GET_USERINFO, GET_ROUTELIST, DEACTIVEUSER, SETACTIVE, GET_DEPTLIST, BACTHSERROLE, GET_USERLIST, GET_ADDDEPT, ADD_USER, SETRESETPWD, EXPOERTUSER } from './api'
  255. import { post, uploadFile } from "@/utils/request";
  256. import { getFromValue, updateDepTreeData, resetFromValue, confirmAction, downloadFile } from '@/utils/tools'
  257. import personnelSearch from '@/components/translationComponent/personnelSearch/personnelSearch.vue';
  258. // 导入页面
  259. import AddPersonnelModal from './module/AddPersonnelModal.vue'
  260. import BatchOperation from './module/BatchOperation.vue'
  261. import { formatDate } from '@/utils/times';
  262. import { URL_IMPORTTHREAD } from '../thread/constant';
  263. const { getFunctionList, getUserInfoVal } = useStore()
  264. const globalPopup = inject<GlobalPopup>('globalPopup')
  265. // 定义类型
  266. interface deptRuleForm { // 部门表单类型
  267. name: string,
  268. id: string | number,
  269. parentId: string | number,
  270. managerId: string | number,
  271. otherManagerIds: string[] | number[],
  272. }
  273. // 固定数据
  274. const stateOptions = [{ value: '3', label: '全部' }, { value: '1', label: '在职' }, { value: '0', label: '停用' }]
  275. // ref
  276. const importUserRef = ref<any>()
  277. // 定义变量
  278. const transitiondata = ref<any>() // 过度数据(针对二次弹窗)
  279. const pagePermission: any = ref([]) // 功能权限
  280. const loadingFrom = reactive({ // 所有加载状态
  281. tableLoading: false,
  282. deptDialogVisibleLoading: false,
  283. resignationLoading: false,
  284. exportUserLoading: false,
  285. importLoading: false
  286. })
  287. const dialogFrom: any = reactive({ // 所有弹窗状态
  288. addDeptDialogVisible: false,
  289. addPersonnelDialogVisible: false,
  290. batchOperationVisible: false,
  291. resignationVisible: false,
  292. exportUserVisible: false,
  293. importVisible: false,
  294. });
  295. const allText = reactive({
  296. batchText: '批量操作'
  297. })
  298. const visibleType = ref<batchOperationType>('dept') // 弹窗类型
  299. const visibleData = ref<any>([]) // 批量弹窗数据源
  300. const totalTable = ref(0) // 表格总数
  301. const tableData: any = ref([]) // 表格数据
  302. const roleList: any = ref([]) // 角色列表
  303. const userList: any = ref([]) // 用户列表
  304. const deptList: any = ref([]) // 部门数据
  305. const batchTableData: any = ref([]) // 批量数据
  306. const multipleTableRef: any = ref()
  307. const deptListUntreated: any = ref([]) // 部门数据(未处理)
  308. const deptListItem: any = ref({}) // 选中的部门数据
  309. const personnelFromData = ref({}) // 人员表单数据
  310. const resignationDate = ref(formatDate(new Date())) // 员工离职日期
  311. const exportRadio = ref('1') // 导出人员列表
  312. const teamForm = reactive({ // 筛选条件表单
  313. matchingType: 0,
  314. keyword: '',
  315. status: '3',
  316. pageIndex: 1,
  317. pageSize: 20,
  318. roleId: '',
  319. onlyDirect: '',
  320. departmentId: '-1',
  321. });
  322. const deptRuleFormRef = ref<FormInstance>() // 表单实例
  323. const deptForm = reactive<deptRuleForm>({ // 部门表单
  324. name: '',
  325. id: '',
  326. parentId: '',
  327. managerId: '',
  328. otherManagerIds: [],
  329. })
  330. const treeProps = { // 部门树配置
  331. children: 'children',
  332. label: 'label',
  333. }
  334. // 定义校验规则
  335. const deptRules = reactive<FormRules<typeof deptForm>>({ // 部门表单校验规则
  336. name: [{ required: true, trigger: 'blur', message: '请输入部门名称' }]
  337. })
  338. // 定义方法
  339. async function importUser(param: UploadRequestOptions) {
  340. loadingFrom.importLoading = true
  341. const formData = new FormData();
  342. formData.append('file', param.file)
  343. const res = await uploadFile(URL_IMPORTTHREAD, formData).finally(() => {
  344. importUserRef.value.clearFiles()
  345. loadingFrom.importLoading = false
  346. })
  347. loadingFrom.importLoading = false
  348. if (res.code == 'ok') {
  349. globalPopup?.showSuccess('导入成功' || '')
  350. closeModal('importVisible')
  351. getTableData()
  352. return
  353. }
  354. globalPopup?.showError(res.msg || '')
  355. }
  356. function exportUser() {
  357. loadingFrom.exportUserLoading = true
  358. post(EXPOERTUSER, { containInvalid: exportRadio.value }).then((res) => {
  359. downloadFile(`${res.data}`, '人员列表.xlsx')
  360. globalPopup?.showSuccess('导出成功')
  361. closeModal('exportUserVisible')
  362. }).finally(() => {
  363. loadingFrom.exportUserLoading = false
  364. })
  365. }
  366. function enableUser(row: any) {
  367. const id = row.id
  368. post(SETACTIVE, { id, isActive: 1 }).then(() => {
  369. globalPopup?.showSuccess('启用成功')
  370. getTableData()
  371. })
  372. }
  373. function resignation() {
  374. const id = transitiondata.value.id || ''
  375. loadingFrom.resignationLoading = true
  376. post(DEACTIVEUSER, { id, inactiveDate: resignationDate.value }).then(() => {
  377. globalPopup?.showSuccess('停用成功')
  378. getTableData()
  379. closeModal('resignationVisible')
  380. }).finally(() => {
  381. loadingFrom.resignationLoading = false
  382. })
  383. }
  384. function resetPwd(row: any) {
  385. const userId = row.id
  386. confirmAction(`确定要为${row.name}重置密码吗?`, '重置密码').then(() => {
  387. post(SETRESETPWD, { userId }).then(() => {
  388. globalPopup?.showSuccess('密码已重置为000000,请通知员工及时修改')
  389. }).catch((err) => {
  390. globalPopup?.showError(err.msg)
  391. })
  392. })
  393. }
  394. function batchEnableItem() {
  395. const userIds = batchTableData.value.map((item: any) => item.id)
  396. post(BACTHSERROLE, { ids: JSON.stringify(userIds), isActive: 1 }).then(() => {
  397. globalPopup?.showSuccess('操作成功')
  398. changeBatch(false)
  399. getTableData()
  400. }).catch((err) => {
  401. globalPopup?.showError(err.msg)
  402. })
  403. }
  404. function changeBatch(flag: boolean = true) {
  405. if (flag) {
  406. batchTableData.value = multipleTableRef.value && multipleTableRef.value.getSelectionRows()
  407. } else {
  408. batchTableData.value = []
  409. multipleTableRef.value && multipleTableRef.value.clearSelection()
  410. }
  411. }
  412. function addPersone(item: any) {
  413. console.log(item)
  414. if (!item) {
  415. personnelFromData.value = {}
  416. dialogFrom.addPersonnelDialogVisible = true
  417. return
  418. }
  419. post(GET_USERINFO, { userId: item.id }).then(res => {
  420. const { id, name, phone, jobNumber, roleId, departmentCascade, departmentId, inductionDate } = res.data
  421. let newData = {
  422. id, name, phone, jobNumber, roleId,
  423. // departmentId: departmentCascade && departmentCascade.split(',').map(Number).reverse(),
  424. departmentId: departmentId,
  425. inductionDate
  426. }
  427. personnelFromData.value = newData
  428. dialogFrom.addPersonnelDialogVisible = true
  429. })
  430. }
  431. async function personnelModalConfirm(data: any, modelType: string) {
  432. post(ADD_USER, { ...data }).then(res => {
  433. if (res.code != 'ok') {
  434. dialogFrom[modelType] = false
  435. globalPopup?.showError(res.msg)
  436. return
  437. }
  438. dialogFrom[modelType] = false
  439. globalPopup?.showSuccess('添加成功')
  440. getTableData()
  441. }).catch(_err => {
  442. dialogFrom[modelType] = false
  443. })
  444. }
  445. function createDepartment(formEl: FormInstance | undefined) {
  446. if (!formEl) return
  447. let data = getFromValue(deptForm)
  448. console.log(data, '<==== 对应的数据')
  449. return
  450. loadingFrom.deptDialogVisibleLoading = true
  451. post(GET_ADDDEPT, { ...deptForm, otherManagerIds: data.otherManagerIds && data.otherManagerIds.join(',') }).then(res => {
  452. if (res.code != 'ok') {
  453. loadingFrom.deptDialogVisibleLoading = false
  454. globalPopup?.showError(res.msg)
  455. return
  456. }
  457. loadingFrom.deptDialogVisibleLoading = false
  458. globalPopup?.showSuccess('创建成功')
  459. getDeptList()
  460. dialogFrom.addDeptDialogVisible = false
  461. }).catch(_err => {
  462. loadingFrom.deptDialogVisibleLoading = false
  463. })
  464. }
  465. function updateDepartment(type: string) {
  466. if (!deptListItem.value.id || deptListItem.value.id <= 0) return
  467. const { id, label, parentId, managerId, otherManagerIds } = deptListItem.value
  468. console.log(deptListItem.value)
  469. let data = { id, name: label, parentId, managerId, otherManagerIds }
  470. Object.assign(deptForm, data)
  471. dialogFrom[type] = true
  472. }
  473. function treeNode(item: any) {
  474. deptListItem.value = item
  475. teamForm.departmentId = item.id
  476. getTableData()
  477. }
  478. function deteleDept(data: any) {
  479. console.log(data)
  480. ElMessageBox.confirm(
  481. `确定删除【${data.label}】部门吗?`, '',
  482. {
  483. confirmButtonText: '确定',
  484. cancelButtonText: '取消',
  485. type: 'warning',
  486. }
  487. )
  488. .then(() => {
  489. post(DETELE_DEPT, { id: data.id }).then(res => {
  490. if (res.code != 'ok') {
  491. globalPopup?.showError(res.msg)
  492. return
  493. }
  494. globalPopup?.showSuccess('删除成功')
  495. getDeptList()
  496. })
  497. })
  498. }
  499. function getTableData() {
  500. loadingFrom.tableLoading = true
  501. post(GET_DATA_LIST, { ...teamForm }).then(res => {
  502. if (res.code != 'ok') {
  503. loadingFrom.tableLoading = false
  504. globalPopup?.showError(res.msg)
  505. return
  506. }
  507. loadingFrom.tableLoading = false
  508. totalTable.value = res.data.total
  509. tableData.value = res.data.records
  510. }).catch(_err => {
  511. loadingFrom.tableLoading = false
  512. })
  513. }
  514. function getRoleList() {
  515. const companyId = getUserInfoVal('companyId') || ''
  516. post(GET_ROUTELIST, { companyId }).then(res => {
  517. if (res.code != 'ok') {
  518. globalPopup?.showError(res.msg)
  519. return
  520. }
  521. roleList.value = res.data
  522. })
  523. }
  524. function getDeptList() {
  525. post(GET_DEPTLIST, {}).then(res => {
  526. if (res.code != 'ok') {
  527. globalPopup?.showError(res.msg)
  528. return
  529. }
  530. deptListUntreated.value = updateDepTreeData(res.data, false)
  531. deptList.value = updateDepTreeData(res.data, true)
  532. })
  533. }
  534. function getUserList() {
  535. post(GET_USERLIST, {}).then(res => {
  536. if (res.code != 'ok') {
  537. globalPopup?.showError(res.msg)
  538. return
  539. }
  540. userList.value = res.data
  541. })
  542. }
  543. function mouseleave(data: any, $event: Event) {
  544. if (data.id <= 0) return;
  545. const target = $event.currentTarget as HTMLElement;
  546. const iconElement = target.querySelector('#treeIcon');
  547. if (iconElement) {
  548. iconElement.setAttribute("class", "treeIcon nodeEle");
  549. }
  550. }
  551. function mouseover(data: any, $event: MouseEvent) {
  552. if (data.id <= 0) return;
  553. const target = $event.currentTarget as HTMLElement;
  554. const iconElement = target.querySelector('#treeIcon');
  555. if (iconElement) {
  556. iconElement.setAttribute("class", "treeIcon");
  557. }
  558. }
  559. function dialogFromCli(type: string, data: any = {}, flag: boolean = false) {
  560. resetDialog()
  561. if (flag) {
  562. const { id } = data
  563. deptForm.parentId = id
  564. }
  565. dialogFrom[type] = true
  566. }
  567. function handleSizeChange(val: number) {
  568. teamForm.pageIndex = 1
  569. teamForm.pageSize = val
  570. getTableData()
  571. }
  572. function handleCurrentChange(val: number) {
  573. teamForm.pageIndex = val
  574. getTableData()
  575. }
  576. function resetDialog() {
  577. let newDeptForm = resetFromValue(deptForm)
  578. Object.assign(deptForm, newDeptForm)
  579. }
  580. function batchItem(text: string, type: batchOperationType, data: any) {
  581. allText.batchText = text,
  582. visibleType.value = type
  583. visibleData.value = data
  584. dialogFrom.batchOperationVisible = true
  585. }
  586. function handleClose(done: any) {
  587. done()
  588. }
  589. function transitionOperation(type: string, data: any) {
  590. if (type == 'disable') { // 停用
  591. resignationDate.value = formatDate(new Date())
  592. console.log(resignationDate.value, '<==== 离职')
  593. dialogFrom.resignationVisible = true
  594. } else if (type == 'exportUser') { // 导出
  595. exportRadio.value = '1'
  596. dialogFrom.exportUserVisible = true
  597. } else if (type == 'importUser') { // 导入
  598. dialogFrom.importVisible = true
  599. }
  600. transitiondata.value = data
  601. }
  602. function closeModal(modelType: string, flag: boolean = false) {
  603. dialogFrom[modelType] = false
  604. if (flag) {
  605. changeBatch(false)
  606. getTableData()
  607. }
  608. }
  609. onBeforeMount(() => {
  610. pagePermission.value = getFunctionList(MOD)
  611. })
  612. onMounted(() => {
  613. getRoleList()
  614. getUserList()
  615. getTableData()
  616. getDeptList()
  617. });
  618. </script>
  619. <style lang="scss" scoped>
  620. .teamstyle {
  621. .team-header {
  622. padding: 0.75rem 1.25rem;
  623. box-sizing: border-box
  624. }
  625. .textFont {
  626. font-size: 16px;
  627. }
  628. .textSpan {
  629. color: $fontGray;
  630. }
  631. }
  632. .const-left {
  633. padding: 0.75rem 0;
  634. .treeContent {
  635. width: 87%;
  636. .custom-tree-node {
  637. display: flex;
  638. align-items: center;
  639. justify-content: space-between;
  640. width: 100%;
  641. }
  642. .treeLabel {
  643. width: 80%;
  644. white-space: nowrap;
  645. overflow: hidden;
  646. text-overflow: ellipsis;
  647. }
  648. .treeIcon {
  649. display: flex;
  650. align-items: center;
  651. justify-self: flex-end;
  652. }
  653. .nodeEle {
  654. display: none;
  655. }
  656. }
  657. }
  658. .operation {
  659. cursor: pointer;
  660. }
  661. </style>
  662. <style>
  663. .temaClass .el-tree-node {
  664. padding: 4px 0;
  665. }
  666. </style>