safetyOrganizationSystemManagement.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <div class="safety-platform-container">
  3. <header class="safety-platform-container__header">
  4. <div class="breadcrumb-title"> 安全组织体系管理 </div>
  5. </header>
  6. <main class="safety-platform-container__main flex">
  7. <div class="nav">
  8. <el-button type="primary" :icon="Plus" @click="addTeam('parent')"> 添加组织</el-button>
  9. <div class="collapse-wrapper">
  10. <!-- 组织树v-model="activeName"-->
  11. <el-collapse accordion v-if="fetchSafetyOrganizationList.length > 0">
  12. <CollapseItem
  13. v-for="item in fetchSafetyOrganizationList"
  14. :key="item.id"
  15. :data="item"
  16. :level="level"
  17. @click-node="querySafetyTeamData"
  18. @create-node="handleCreateSafetySystem"
  19. @edit-node="handleEditSafetySystem"
  20. @delete-node="handleDelSafetySystem"
  21. />
  22. </el-collapse>
  23. <div v-else>
  24. <el-empty description="未添加组织" />
  25. </div>
  26. </div>
  27. <!-- 添加、编辑组织弹窗 -->
  28. <AddSafetySystem
  29. v-model:visible="addSafetySystemVisible"
  30. :data="addSafetyOrganizationSystemFormData"
  31. @confirmAddSafetySystem="confirmAddSafetySystemCallback"
  32. />
  33. </div>
  34. <div class="search-table-container table-content">
  35. <!-- 架构图 -->
  36. <OrgChart :treeData="treeData" @node-click="handleNodeClick" />
  37. <TeamDetailDrawer ref="teamDetailDrawerRef" :selected-team-id="selectedTeamId" />
  38. <div class="text-right mb-4">
  39. <el-button @click="toStaff"> 编辑 </el-button>
  40. </div>
  41. </div>
  42. </main>
  43. <!-- <BatchImport
  44. v-if="batchImportVisible"
  45. :visible="batchImportVisible"
  46. :import-api-url="importApiUrl"
  47. :template-url="templateUrl"
  48. template-name="安全组织体系管理导入模版"
  49. :show-template="true"
  50. @close="batchImportVisible = false"
  51. @update="handleUpdate"
  52. /> -->
  53. </div>
  54. </template>
  55. <script setup lang="ts">
  56. import { onMounted, reactive, ref, provide } from 'vue';
  57. import { ElMessage, ElMessageBox } from 'element-plus';
  58. import BasicTable from '@/components/BasicTable.vue';
  59. import useTableConfig from '@/hooks/useTableConfigHook';
  60. import { TABLE_OPTIONS, TABLE_COLUMNS } from './configs/tables';
  61. import { useRouter } from 'vue-router';
  62. import type { QueryPageRequest } from '@/types/basic-query';
  63. import {
  64. getSafetySystemList,
  65. addSafetySystem,
  66. updateSafetySystem,
  67. deleteSafetySystem,
  68. fetchTableList,
  69. delEmployee,
  70. exportSafetyOrganizationSystemManagement
  71. } from '@/api/safety-organization-management';
  72. // import { downloadByData } from '@/utils/file/download';
  73. // import BatchImport from '@/components/batch-import/BatchImport.vue';
  74. // import { useGlobSetting } from '@/hooks/setting';
  75. // import urlJoin from 'url-join';
  76. import AddSafetySystem from './components/addSafetySystem.vue';
  77. import {
  78. Delete,
  79. Edit,
  80. Plus,
  81. } from '@element-plus/icons-vue'
  82. import OrgChart from './components/orgChart.vue';
  83. import CollapseItem from './components/collapseItem.vue'
  84. import TeamDetailDrawer from './components/TeamDetailDrawer.vue';
  85. const position = ref('left')
  86. const router = useRouter();
  87. // 表格
  88. // const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  89. const { tableConfig, pagination } = useTableConfig(TABLE_COLUMNS, TABLE_OPTIONS);
  90. const tableData = ref<any[]>([]);
  91. const fetchSafetyOrganizationList = ref<any[]>([]);
  92. const activeName = ref('');
  93. // 给组件递归时使用
  94. // provide('activeName', activeName)
  95. const level = ref(1)
  96. // 日期范围(用于日期选择器)
  97. const dateRange = ref<[string, string] | string>('');
  98. const tableQuery = reactive<QueryPageRequest<any>>({
  99. pageNumber: pagination.pageNumber,
  100. pageSize: pagination.pageSize,
  101. queryParam: {
  102. classifyName: '',
  103. keyword: '',
  104. status: '',
  105. startTime: '',
  106. endTime: '',
  107. },
  108. });
  109. type OrganizationTreeType = {
  110. id: string;
  111. data: { name: string };
  112. children?: OrganizationTreeType[];
  113. };
  114. const treeData = ref<OrganizationTreeType>({
  115. id: 'root',
  116. data: { name: '请添加组织' },
  117. children: [],
  118. });
  119. // const handlerEdit = ()=>{
  120. // router.push({name: 'securityOrganizationalStructure'})
  121. // }
  122. // const handleSizeChange = (value: number) => {
  123. // pagination.pageSize = value;
  124. // tableQuery.pageSize = value;
  125. // getTableData();
  126. // };
  127. // const handleCurrentChange = (value: number) => {
  128. // pagination.pageNumber = value;
  129. // tableQuery.pageNumber = value;
  130. // getTableData();
  131. // };
  132. const teamDetailDrawerRef = ref<InstanceType<typeof TeamDetailDrawer>>();
  133. const selectedTeamId = ref<number | null>(null);
  134. const handleNodeClick = (nodeData: any) => {
  135. const id = nodeData?.id?.replace('org-', '')
  136. console.log(nodeData, 'canshu')
  137. selectedTeamId.value = Number(id);
  138. teamDetailDrawerRef.value?.drawerShow();
  139. };
  140. // async function getTableData() {
  141. // tableConfig.loading = true;
  142. // try {
  143. // const res = await fetchTableList(tableQuery);
  144. // if (res) {
  145. // tableData.value = res.records
  146. // pagination.total = res.totalRow;
  147. // }
  148. // } catch (e) {
  149. // console.error('获取列表失败:', e);
  150. // tableData.value = [];
  151. // pagination.total = 0;
  152. // } finally {
  153. // tableConfig.loading = false;
  154. // }
  155. // }
  156. interface addSafetyOrganizationSystemFormDataType {
  157. type: String;
  158. orgName?: String;
  159. orgId?: String | number;
  160. action?: String;
  161. parentid?: String | number;
  162. }
  163. const addSafetySystemVisible = ref(false);
  164. const addSafetyOrganizationSystemFormData = ref<addSafetyOrganizationSystemFormDataType>({
  165. type: '',
  166. orgName: '',
  167. orgId: '',
  168. action: '',
  169. parentid: '',
  170. });
  171. /**
  172. * 递归给树形结构添加 id 、data 、children 字段
  173. * @param {Array} tree 原始树形数组
  174. * @returns 格式化后的标准树结构
  175. */
  176. const formatTreeData = (tree)=> {
  177. if (!tree || !Array.isArray(tree)) return [];
  178. return tree.map(item => {
  179. // 给每一层节点都加上 id 和 data
  180. const formattedItem = {
  181. children: item.children || [],
  182. id: `org-${item.orgId}`,
  183. data: {
  184. name: item.orgName
  185. }
  186. };
  187. // 递归处理子节点
  188. if (formattedItem.children && formattedItem.children.length > 0) {
  189. formattedItem.children = formatTreeData(formattedItem.children);
  190. }
  191. return formattedItem;
  192. });
  193. }
  194. function convertData(leaderTeams): OrganizationTreeType {
  195. return {
  196. id: `org-${leaderTeams.orgId}`,
  197. data: {
  198. name: leaderTeams.orgName
  199. },
  200. children: leaderTeams.children?.map((child) => convertData(child)),
  201. };
  202. }
  203. // 获取组织列表
  204. const fetchSafetyOrganizationTeamList = async () => {
  205. try {
  206. const res = await getSafetySystemList();
  207. fetchSafetyOrganizationList.value = res;
  208. // 默认选择第一个组织
  209. if(res[0].orgId){
  210. treeNodePreview(res[0])
  211. activeName.value = String(res[0].orgId)
  212. tableQuery.queryParam.classifyName = res[0].orgId
  213. }
  214. } catch (error) {
  215. ElMessage.error('获取组织列表失败');
  216. }
  217. };
  218. // 给架构图赋值
  219. const treeNodePreview = (data)=>{
  220. let TreeNode = convertData(data)
  221. treeData.value = TreeNode
  222. }
  223. // 一级新增
  224. const addTeam = (type) => {
  225. addSafetyOrganizationSystemFormData.value = {
  226. type,
  227. action: 'add',
  228. };
  229. addSafetySystemVisible.value = true;
  230. };
  231. // 子级新增
  232. const handleCreateSafetySystem = async (type, value) => {
  233. // console.log('新增参数--',type, value)
  234. addSafetyOrganizationSystemFormData.value = {
  235. type:'children',
  236. action: 'add',
  237. orgName: value.orgName,
  238. orgId: value.orgId,
  239. };
  240. addSafetySystemVisible.value = true;
  241. // 打开某一个
  242. // activeName.value = value.orgId;
  243. };
  244. // 编辑
  245. const handleEditSafetySystem = (type, value, parentid) => {
  246. // console.log('编辑参数--', type, value, parentid)
  247. addSafetySystemVisible.value = true;
  248. addSafetyOrganizationSystemFormData.value = {
  249. type,
  250. action: 'edit',
  251. orgName: value.orgName,
  252. orgId: value.orgId,
  253. parentid,
  254. };
  255. };
  256. // 删除
  257. const handleDelSafetySystem = async (type, value) => {
  258. // console.log('删除', type, value)
  259. ElMessageBox.confirm('确认删除该组织吗?', '警告', { type: 'warning' }).then(async () => {
  260. try {
  261. if(value.children.length > 0){
  262. ElMessage.error('当前一级组织存在子级数据,无法删除,请先删除子级组织')
  263. return
  264. }
  265. await deleteSafetySystem(value.orgId);
  266. ElMessage.success('删除成功');
  267. // 刷新组织列表
  268. fetchSafetyOrganizationTeamList();
  269. } catch (error) {
  270. ElMessage.error(error || '删除失败');
  271. }
  272. });
  273. };
  274. // 查询
  275. const querySafetyTeamData = (value) => {
  276. // console.log('查询', value);
  277. tableQuery.queryParam.classifyName = value.orgId;
  278. activeName.value = String(value.orgId)
  279. treeNodePreview(value)
  280. };
  281. // 定义组织数据类型
  282. interface SafetySystemFormData {
  283. value: string; // 输入的组织名称
  284. action: 'add' | 'edit'; // 操作类型:新增或编辑
  285. orgId?: string | number; // 组织ID(编辑时必传)
  286. parentid?: string | number; // 父组织ID(新增子组织时必传)
  287. type?: 'children' | 'parent'; // 组织类型(子组织或根组织)
  288. }
  289. // 保存弹窗回调
  290. const confirmAddSafetySystemCallback = async (formData: SafetySystemFormData) => {
  291. try {
  292. if (!formData.value?.trim()) {
  293. ElMessage.warning('请输入有效的组织名称!');
  294. return;
  295. }
  296. // 新增时,传orgName(组织名称)、parentid(父组织ID)
  297. // 编辑时,传当前ID和orgName
  298. const requestData = {
  299. orgName: formData.value.trim(),
  300. id: formData.action === 'edit' ? formData.orgId : undefined,
  301. // 第一级不需要传parentid
  302. parentid: formData.action === 'add' ? formData.parentid : undefined,
  303. };
  304. console.log(formData, '参数--formData')
  305. if (formData.action === 'add') {
  306. if (formData.type === 'children' && formData.orgId) {
  307. requestData.parentid = formData.orgId;
  308. }
  309. await addSafetySystem(requestData);
  310. ElMessage.success('新增组织成功!');
  311. } else {
  312. // 如果是子类,补充父级ID
  313. if (formData.type === 'children' && formData.parentid) {
  314. requestData.parentid = formData.parentid;
  315. }
  316. await updateSafetySystem(requestData);
  317. ElMessage.success('编辑组织成功!');
  318. }
  319. // 刷新列表
  320. fetchSafetyOrganizationTeamList();
  321. } catch (error) {
  322. console.error('操作失败:', error);
  323. ElMessage.error(formData.action === 'add' ? '新增组织失败!' : '编辑组织失败!');
  324. }
  325. };
  326. const toStaff = ()=>{
  327. router.push({name: 'securityOrganizationalStructure', query: {id: tableQuery.queryParam.classifyName}})
  328. }
  329. // 时间查询
  330. // const onchangeDateRange = () => {
  331. // if (dateRange.value && Array.isArray(dateRange.value) && dateRange.value.length === 2) {
  332. // tableQuery.queryParam.startTime = dateRange.value[0] || '';
  333. // tableQuery.queryParam.endTime = dateRange.value[1] || '';
  334. // } else {
  335. // tableQuery.queryParam.startTime = '';
  336. // tableQuery.queryParam.endTime = '';
  337. // }
  338. // getTableData();
  339. // };
  340. // const handleSearch = () => {
  341. // pagination.pageNumber = 1;
  342. // tableQuery.pageNumber = 1;
  343. // getTableData();
  344. // };
  345. // const handleReset = () => {
  346. // pagination.pageNumber = 1;
  347. // tableQuery.queryParam = {
  348. // classifyName: '',
  349. // keyword: '',
  350. // status: '', // 重置为默认启用状态
  351. // startTime: '',
  352. // endTime: '',
  353. // };
  354. // dateRange.value = '';
  355. // handleSearch();
  356. // };
  357. // 批量导入
  358. // const batchImportVisible = ref(false);
  359. // const { urlPrefix } = useGlobSetting();
  360. // const importApiUrl = ref(urlJoin(urlPrefix, '/safetyorguser/importSafetyOrgUser'));
  361. // const templateUrl = ref('./skyeye-file-upload/sfysecurity/TEMPLATE/安全组织体系管理导入模版.xlsx');
  362. // const handleImport = () => {
  363. // batchImportVisible.value = true;
  364. // };
  365. // const handleUpdate = () => {
  366. // batchImportVisible.value = false;
  367. // getTableData();
  368. // };
  369. // const handleDownload = async () => {
  370. // try {
  371. // const response = await exportSafetyOrganizationSystemManagement(tableQuery.queryParam);
  372. // if (response) {
  373. // const fileName = `安全组织体系管理_${new Date().toISOString().split('T')[0]}.xlsx`;
  374. // downloadByData(response, fileName);
  375. // ElMessage.success('导出成功');
  376. // }
  377. // } catch (e) {
  378. // console.error('导出安全组织体系管理失败:', e);
  379. // ElMessage.error('导出失败,请重试');
  380. // }
  381. // };
  382. // const handleCreate = () => {
  383. // router.push({
  384. // name: 'SafetyOrganizationSystemManagementItem',
  385. // query: {
  386. // operate: 'employee-create',
  387. // },
  388. // });
  389. // };
  390. // const handleEdit = (id: number) => {
  391. // router.push({
  392. // name: 'SafetyOrganizationSystemManagementItem',
  393. // query: {
  394. // id,
  395. // operate: 'employee-edit',
  396. // },
  397. // });
  398. // };
  399. // const handleDelete = async (id: number) => {
  400. // try {
  401. // await delEmployee(id);
  402. // ElMessage.success('删除成功');
  403. // getTableData();
  404. // } catch (e) {
  405. // console.error('删除员工失败:', e);
  406. // ElMessage.error('删除失败,请重试');
  407. // }
  408. // };
  409. // const handleView = (id: number) => {
  410. // router.push({
  411. // name: 'SafetyOrganizationSystemManagementItem',
  412. // query: {
  413. // id,
  414. // operate: 'employee-view',
  415. // },
  416. // });
  417. // };
  418. onMounted(() => {
  419. fetchSafetyOrganizationTeamList();
  420. // getTableData();
  421. });
  422. </script>
  423. <style scoped lang="scss">
  424. @use '@/styles/page-details-layout.scss' as *;
  425. @use '@/styles/page-main-layout.scss' as *;
  426. @use '@/styles/basic-table-action.scss' as *;
  427. @use '@/views/traffic/violation/style/act-search-table.scss' as *;
  428. .text-right{
  429. text-align: right;
  430. }
  431. .mb-4{
  432. margin-bottom: 12px;
  433. }
  434. .nav {
  435. flex: 0 0 300px;
  436. margin-right: 15px;
  437. padding-right: 15px;
  438. border-right: 1px solid #eee;
  439. :deep(.collapse-title) {
  440. flex: 1 0 90%;
  441. order: 1;
  442. .el-collapse-item__header {
  443. flex: 1 0 auto;
  444. order: -1;
  445. }
  446. }
  447. .collapse-wrapper {
  448. margin-top: 10px;
  449. .title-wrapper {
  450. display: flex;
  451. justify-content: space-between;
  452. align-items: center;
  453. width: 100%;
  454. .handler {
  455. flex: 1;
  456. display: flex;
  457. justify-content: flex-end;
  458. align-items: center;
  459. padding-right: 15px;
  460. }
  461. }
  462. .collapse-item-content {
  463. ul {
  464. padding-left: 40px;
  465. li {
  466. display: flex;
  467. justify-content: space-between;
  468. align-items: center;
  469. width: 100%;
  470. padding: 6px 0;
  471. border-bottom: 1px solid #eeeeeed1;
  472. span {
  473. cursor: pointer;
  474. }
  475. }
  476. }
  477. }
  478. }
  479. }
  480. </style>