index.vue 28 KB

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