hiddenTroubleAccountManagement.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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">
  7. <div class="search-table-container">
  8. <header>
  9. <div style="position: relative">
  10. <el-button type="primary" class="search-table-container--button" @click="handleCreate">
  11. 新增隐患
  12. </el-button>
  13. <el-button plain class="search-table-container--button" @click="handleImport">
  14. 导入
  15. </el-button>
  16. <el-button plain class="search-table-container--button" @click="handleDownload">
  17. 导出
  18. </el-button>
  19. </div>
  20. <div class="act-search">
  21. <section class="select-box">
  22. <div class="select-box--item">
  23. <span>关键词:</span>
  24. <el-input
  25. v-model="tableQuery.queryParam.keyword"
  26. placeholder="隐患问题/整改要求等"
  27. class="act-search-input"
  28. />
  29. </div>
  30. <div class="select-box--item">
  31. <span>状态:</span>
  32. <el-select
  33. v-model="tableQuery.queryParam.status"
  34. placeholder="请选择状态"
  35. clearable
  36. >
  37. <el-option label="全部" :value="0" />
  38. <el-option label="待下发" :value="1" />
  39. <el-option label="待整改" :value="2" />
  40. <el-option label="待复查" :value="3" />
  41. <el-option label="已完成" :value="4" />
  42. <el-option label="待入账" :value="5" />
  43. </el-select>
  44. </div>
  45. <div class="select-box--item">
  46. <span>任务来源:</span>
  47. <el-input
  48. v-model="tableQuery.queryParam.taskSource"
  49. placeholder="如:上级检查、院内自查"
  50. class="act-search-input"
  51. clearable
  52. />
  53. </div>
  54. </section>
  55. <section class="search-btn">
  56. <el-button type="primary" @click="handleSearch">查询</el-button>
  57. <el-button @click="handleReset">重置</el-button>
  58. </section>
  59. </div>
  60. </header>
  61. <div class="batch-table">
  62. <BasicTable
  63. ref="basicTableRef"
  64. :tableData="tableData"
  65. :tableConfig="tableConfig"
  66. @update:pageSize="handleSizeChange"
  67. @update:pageNumber="handleCurrentChange"
  68. >
  69. <template #currentNode="scope">
  70. <span>{{ scope.row.currentNode }}</span>
  71. </template>
  72. <template #status="scope">
  73. <span>{{ scope.row.statusName || '-' }}</span>
  74. </template>
  75. <template #action="scope">
  76. <div class="action-container--div" style="justify-content: left">
  77. <!-- 待下发 statusId=1:编辑、删除、查看、下发、扣分 -->
  78. <template v-if="scope.row.statusId === 1">
  79. <ActionButton text="编辑" @click="handleEdit(scope.row.id)" />
  80. <ActionButton
  81. text="删除"
  82. :popconfirm="{ title: '确定要删除?' }"
  83. @confirm="handleDelete(scope.row.id)"
  84. />
  85. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  86. <ActionButton text="下发" @click="handleOpenIssue(scope.row.id)" />
  87. <ActionButton text="扣分" @click="handleOpenDeduct(scope.row.id)" />
  88. </template>
  89. <!-- 待整改 statusId=2:查看、整改、扣分 -->
  90. <template v-else-if="scope.row.statusId === 2">
  91. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  92. <ActionButton text="整改" @click="handleRectify(scope.row.id)" />
  93. <ActionButton text="扣分" @click="handleOpenDeduct(scope.row.id)" />
  94. </template>
  95. <!-- 待复查 statusId=3:查看、复查、扣分 -->
  96. <template v-else-if="scope.row.statusId === 3">
  97. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  98. <ActionButton text="复查" @click="handleReview(scope.row.id)" />
  99. <ActionButton text="扣分" @click="handleOpenDeduct(scope.row.id)" />
  100. </template>
  101. <!-- 已完成 statusId=4:查看、扣分 -->
  102. <template v-else-if="scope.row.statusId === 4">
  103. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  104. <ActionButton text="扣分" @click="handleOpenDeduct(scope.row.id)" />
  105. </template>
  106. <!-- 待入账 statusId=5:编辑、删除、查看、下发、扣分(与待下发一致) -->
  107. <template v-else-if="scope.row.statusId === 5">
  108. <ActionButton text="编辑" @click="handleEdit(scope.row.id)" />
  109. <ActionButton
  110. text="删除"
  111. :popconfirm="{ title: '确定要删除?' }"
  112. @confirm="handleDelete(scope.row.id)"
  113. />
  114. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  115. <ActionButton text="下发" @click="handleOpenIssue(scope.row.id)" />
  116. <ActionButton text="扣分" @click="handleOpenDeduct(scope.row.id)" />
  117. </template>
  118. <!-- 其他状态:无操作 -->
  119. </div>
  120. </template>
  121. </BasicTable>
  122. </div>
  123. </div>
  124. </main>
  125. <BatchImport
  126. v-if="batchImportVisible"
  127. :visible="batchImportVisible"
  128. :import-api-url="importApiUrl"
  129. :template-url="templateUrl"
  130. template-name="下载模板"
  131. :show-template="false"
  132. @close="batchImportVisible = false"
  133. @update="handleUpdate"
  134. />
  135. <!-- 隐患台账下发弹窗 -->
  136. <el-dialog
  137. v-model="showIssueDialog"
  138. title="隐患台账下发"
  139. width="500px"
  140. destroy-on-close
  141. @open="onIssueDialogOpen"
  142. >
  143. <el-form ref="issueFormRef" :model="issueForm" :rules="issueRules" label-width="140px">
  144. <el-form-item label="整改责任部门" prop="rectificationDepartmentId">
  145. <el-cascader
  146. v-model="issueForm.rectificationDepartmentId"
  147. :options="issueDeptTree"
  148. :props="cascaderDeptProp"
  149. :show-all-levels="false"
  150. placeholder="请选择整改责任部门"
  151. filterable
  152. clearable
  153. style="width: 100%"
  154. @change="onIssueDeptChange"
  155. />
  156. </el-form-item>
  157. <el-form-item label="整改负责人" prop="rectificationResponsibleUserId">
  158. <el-select
  159. v-model="issueForm.rectificationResponsibleUserId"
  160. placeholder="选择整改负责人"
  161. filterable
  162. clearable
  163. style="width: 100%"
  164. >
  165. <el-option
  166. v-for="user in issueUserList"
  167. :key="user.id"
  168. :label="user.realname ?? user.username"
  169. :value="user.id"
  170. />
  171. </el-select>
  172. </el-form-item>
  173. </el-form>
  174. <template #footer>
  175. <el-button @click="showIssueDialog = false">取消</el-button>
  176. <el-button type="primary" @click="handleIssueSave">保存</el-button>
  177. </template>
  178. </el-dialog>
  179. <!-- 扣分弹窗 -->
  180. <el-dialog v-model="showDeductDialog" title="扣分记录" width="400px" destroy-on-close @open="onDeductDialogOpen">
  181. <el-form ref="deductFormRef" :model="deductForm" :rules="deductRules" label-width="100px">
  182. <el-form-item label="扣分值" prop="deductionScore">
  183. <el-input-number
  184. v-model="deductForm.deductionScore"
  185. :min="0"
  186. :max="9999"
  187. :precision="0"
  188. placeholder="请输入扣分值(0-9999整数)"
  189. style="width: 100%"
  190. />
  191. </el-form-item>
  192. <el-form-item label="扣分部门">
  193. <el-select
  194. v-model="deductDeptIdsArray"
  195. placeholder="请选择扣分部门,可多选(复用复查人员所属部门)"
  196. clearable
  197. filterable
  198. multiple
  199. collapse-tags
  200. collapse-tags-tooltip
  201. style="width: 100%"
  202. >
  203. <el-option
  204. v-for="d in deductDeptOptions"
  205. :key="d.id"
  206. :label="d.deptName"
  207. :value="d.id"
  208. />
  209. </el-select>
  210. </el-form-item>
  211. </el-form>
  212. <template #footer>
  213. <el-button @click="showDeductDialog = false">取消</el-button>
  214. <el-button type="primary" @click="handleDeductSubmit">确认扣分</el-button>
  215. </template>
  216. </el-dialog>
  217. </div>
  218. </template>
  219. <script setup lang="ts">
  220. import { onMounted, reactive, ref } from 'vue';
  221. import { ElMessage } from 'element-plus';
  222. import BasicTable from '@/components/BasicTable.vue';
  223. import useTableConfig from '@/hooks/useTableConfigHook';
  224. import ActionButton from '@/components/ActionButton.vue';
  225. import { TABLE_OPTIONS, HIDDEN_DANGER_TABLE_COLUMNS } from './configs/tables';
  226. import { useRouter } from 'vue-router';
  227. import type { QueryPageRequest } from '@/types/basic-query';
  228. import {
  229. queryHiddenDangerPage,
  230. deleteHiddenDanger,
  231. exportHiddenDanger,
  232. issueHiddenDanger,
  233. deductHiddenDangerPoints,
  234. type HiddenDangerQueryParam,
  235. type HiddenDangerDeductPointsRequest,
  236. } from '@/api/hiddenDanger';
  237. import { getAllDepartments } from '@/api/auth/dept';
  238. import type { DeptTree } from '@/types/dept/type';
  239. import { queryAvailableUserList } from '@/api/production-safety/responsibility-implementation';
  240. import { downloadByData } from '@/utils/file/download';
  241. import BatchImport from '@/components/batch-import/BatchImport.vue';
  242. import { useGlobSetting } from '@/hooks/setting';
  243. import urlJoin from 'url-join';
  244. const router = useRouter();
  245. // 表格
  246. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  247. const { tableConfig, pagination } = useTableConfig(HIDDEN_DANGER_TABLE_COLUMNS, TABLE_OPTIONS);
  248. const tableData = ref<any[]>([]);
  249. const tableQuery = reactive<QueryPageRequest<HiddenDangerQueryParam>>({
  250. pageNumber: pagination.pageNumber,
  251. pageSize: pagination.pageSize,
  252. queryParam: {
  253. keyword: '',
  254. status: undefined,
  255. taskSource: '',
  256. },
  257. });
  258. const handleSizeChange = (value: number) => {
  259. pagination.pageSize = value;
  260. tableQuery.pageSize = value;
  261. getTableData();
  262. };
  263. const handleCurrentChange = (value: number) => {
  264. pagination.pageNumber = value;
  265. tableQuery.pageNumber = value;
  266. getTableData();
  267. };
  268. async function getTableData() {
  269. tableConfig.loading = true;
  270. try {
  271. const res = await queryHiddenDangerPage(tableQuery);
  272. if (res?.records?.length) {
  273. // 映射返回数据字段到表格字段
  274. tableData.value = res.records.map((item) => ({
  275. id: item.id,
  276. dangerProblem: item.dangerProblem,
  277. reasonName: item.reasonName,
  278. createdAt: item.createdAt,
  279. taskSource: item.taskSource,
  280. rectificationRequirement: item.rectificationRequirement,
  281. typeName: item.typeName,
  282. currentNode: item.currentNode,
  283. statusName: item.statusName,
  284. statusId: item.statusId,
  285. }));
  286. pagination.total = (res as any).totalRow ?? (res as any).total ?? 0;
  287. } else {
  288. tableData.value = [];
  289. pagination.total = 0;
  290. }
  291. } catch (e) {
  292. console.error('获取隐患台账列表失败:', e);
  293. tableData.value = [];
  294. pagination.total = 0;
  295. } finally {
  296. tableConfig.loading = false;
  297. }
  298. }
  299. const handleSearch = () => {
  300. pagination.pageNumber = 1;
  301. tableQuery.pageNumber = 1;
  302. getTableData();
  303. };
  304. const handleReset = () => {
  305. tableQuery.queryParam.keyword = '';
  306. tableQuery.queryParam.status = undefined;
  307. tableQuery.queryParam.taskSource = '';
  308. handleSearch();
  309. };
  310. // 批量导入
  311. const batchImportVisible = ref(false);
  312. const { urlPrefix } = useGlobSetting();
  313. const importApiUrl = ref(urlJoin(urlPrefix, '/productionHiddenDanger/importHiddenDanger'));
  314. const templateUrl = ref('./skyeye-file-upload/sfysecurity/TEMPLATE/import-hidden-danger-template.xlsx');
  315. const handleImport = () => {
  316. batchImportVisible.value = true;
  317. };
  318. const handleUpdate = () => {
  319. batchImportVisible.value = false;
  320. getTableData();
  321. };
  322. const handleDownload = async () => {
  323. try {
  324. const exportParams: HiddenDangerQueryParam = {
  325. keyword: tableQuery.queryParam.keyword || undefined,
  326. status: tableQuery.queryParam.status,
  327. taskSource: tableQuery.queryParam.taskSource || undefined,
  328. };
  329. const response = await exportHiddenDanger(exportParams);
  330. if (response) {
  331. const fileName = `隐患台账_${new Date().toISOString().split('T')[0]}.xlsx`;
  332. downloadByData(response, fileName);
  333. ElMessage.success('导出成功');
  334. }
  335. } catch (e) {
  336. console.error('导出隐患台账失败:', e);
  337. ElMessage.error('导出失败,请重试');
  338. }
  339. };
  340. /** 隐患台账详情页路径(与路由配置一致,避免 name 解析失败) */
  341. const HIDDEN_ACCOUNT_ITEM_PATH = '/work-safety/hidden-trouble-investigation-and-governance/hidden-trouble-account-management-item';
  342. const handleCreate = () => {
  343. router.push({
  344. path: HIDDEN_ACCOUNT_ITEM_PATH,
  345. query: {
  346. operate: 'hidden-trouble-account-create',
  347. },
  348. });
  349. };
  350. const handleEdit = (id: number) => {
  351. router.push({
  352. path: HIDDEN_ACCOUNT_ITEM_PATH,
  353. query: {
  354. id: String(id),
  355. operate: 'hidden-trouble-account-edit',
  356. },
  357. });
  358. };
  359. const handleDelete = async (id: number) => {
  360. try {
  361. await deleteHiddenDanger(id);
  362. ElMessage.success('删除成功');
  363. getTableData();
  364. } catch (e) {
  365. console.error('删除隐患台账失败:', e);
  366. ElMessage.error('删除失败,请重试');
  367. }
  368. };
  369. /** 下发弹窗:点击下发打开弹窗,弹窗内部门用 queryAllDeptTree、负责人用 queryAvailableUserList,点击保存才触发下发接口 */
  370. const showIssueDialog = ref(false);
  371. const issueDangerId = ref<number>(0);
  372. const issueFormRef = ref();
  373. const issueForm = ref({
  374. rectificationDepartmentId: undefined as number | undefined,
  375. rectificationResponsibleUserId: undefined as number | undefined,
  376. rectificationResponsiblePersonName: '' as string,
  377. });
  378. const issueRules = {
  379. rectificationDepartmentId: [{ required: true, message: '请选择整改责任部门', trigger: 'change' }],
  380. rectificationResponsibleUserId: [{ required: true, message: '请选择整改负责人', trigger: 'change' }],
  381. };
  382. /** 下发弹窗部门树,与新增隐患台账复查人员所属部门一致(getAllDepartments 取第一级 children) */
  383. const cascaderDeptProp = {
  384. checkStrictly: true,
  385. expandTrigger: 'hover' as const,
  386. value: 'id',
  387. label: 'deptName',
  388. emitPath: false,
  389. };
  390. const issueDeptTree = ref<DeptTree[]>([]);
  391. const issueUserList = ref<Array<{ id: number; realname?: string; username?: string }>>([]);
  392. const onIssueDialogOpen = async () => {
  393. try {
  394. const [deptRes, userRes] = await Promise.all([
  395. getAllDepartments(),
  396. queryAvailableUserList({ pageNumber: 1, pageSize: 9999, queryParam: {} }),
  397. ]);
  398. const fullTree = (deptRes as DeptTree[]) ?? [];
  399. issueDeptTree.value = Array.isArray(fullTree) && fullTree[0]?.children ? fullTree[0].children : [];
  400. issueUserList.value = (userRes as any)?.records ?? [];
  401. } catch (e) {
  402. console.error('获取部门/用户列表失败:', e);
  403. ElMessage.error('加载部门或负责人列表失败');
  404. issueDeptTree.value = [];
  405. issueUserList.value = [];
  406. }
  407. };
  408. const onIssueDeptChange = () => {
  409. issueForm.value.rectificationResponsibleUserId = undefined;
  410. issueForm.value.rectificationResponsiblePersonName = '';
  411. };
  412. /** 从部门树中根据 id 查找部门名称 */
  413. function findDeptNameById(nodes: DeptTree[] | undefined, id: number): string {
  414. if (!nodes?.length) return '';
  415. for (const n of nodes) {
  416. if (n.id === id) return n.deptName ?? '';
  417. if (n.children?.length) {
  418. const found = findDeptNameById(n.children, id);
  419. if (found) return found;
  420. }
  421. }
  422. return '';
  423. }
  424. const handleOpenIssue = (id: number) => {
  425. issueDangerId.value = id;
  426. issueForm.value = {
  427. rectificationDepartmentId: undefined,
  428. rectificationResponsibleUserId: undefined,
  429. rectificationResponsiblePersonName: '',
  430. };
  431. showIssueDialog.value = true;
  432. };
  433. const handleIssueSave = async () => {
  434. await issueFormRef.value?.validate?.().catch(() => {});
  435. const { rectificationDepartmentId, rectificationResponsibleUserId } = issueForm.value;
  436. if (rectificationDepartmentId == null || rectificationResponsibleUserId == null) {
  437. ElMessage.warning('请选择整改责任部门和整改负责人');
  438. return;
  439. }
  440. const selectedUser = issueUserList.value.find((u) => u.id === rectificationResponsibleUserId);
  441. const personName = selectedUser?.realname ?? selectedUser?.username ?? '';
  442. const deptName = findDeptNameById(issueDeptTree.value, rectificationDepartmentId);
  443. try {
  444. await issueHiddenDanger({
  445. danger_id: issueDangerId.value,
  446. rectification_department_ids: String(rectificationDepartmentId),
  447. rectification_responsible_person: personName,
  448. dept_name: deptName,
  449. rectification_responsible_ids: String(rectificationResponsibleUserId),
  450. });
  451. ElMessage.success('下发成功');
  452. showIssueDialog.value = false;
  453. getTableData();
  454. } catch (e) {
  455. console.error('下发失败:', e);
  456. ElMessage.error('下发失败,请重试');
  457. }
  458. };
  459. /** 整改:跳转详情页进行整改 */
  460. const handleRectify = (id: number) => {
  461. router.push({
  462. path: HIDDEN_ACCOUNT_ITEM_PATH,
  463. query: { id: String(id), operate: 'hidden-trouble-account-rectify', action: 'rectify' },
  464. });
  465. };
  466. /** 复查:跳转复查详情页 */
  467. const handleReview = (id: number) => {
  468. router.push({
  469. path: HIDDEN_ACCOUNT_ITEM_PATH,
  470. query: { id: String(id), operate: 'hidden-trouble-account-review' },
  471. });
  472. };
  473. /** 扣分弹窗(扣分部门复用复查人员所属部门数据源) */
  474. function flattenDeptTreeForDeduct(nodes: DeptTree[] | undefined): Array<{ id: number; deptName: string }> {
  475. if (!nodes?.length) return [];
  476. const list: Array<{ id: number; deptName: string }> = [];
  477. const walk = (items: DeptTree[]) => {
  478. items.forEach((n) => {
  479. if (n.id != null) list.push({ id: n.id, deptName: n.deptName });
  480. if (n.children?.length) walk(n.children);
  481. });
  482. };
  483. walk(nodes);
  484. return list;
  485. }
  486. const showDeductDialog = ref(false);
  487. const deductDangerId = ref<number>(0);
  488. const deductDeptOptions = ref<Array<{ id: number; deptName: string }>>([]);
  489. const deductDeptIdsArray = ref<number[]>([]);
  490. const deductForm = ref<HiddenDangerDeductPointsRequest>({
  491. dangerId: 0,
  492. deductionScore: 0,
  493. });
  494. const deductFormRef = ref();
  495. const deductRules = {
  496. deductionScore: [
  497. { required: true, message: '请输入扣分值', trigger: 'blur' },
  498. { type: 'number', min: 0, max: 9999, message: '扣分值须为0-9999的整数', trigger: 'blur' },
  499. ],
  500. };
  501. const onDeductDialogOpen = async () => {
  502. try {
  503. const deptRes = await getAllDepartments();
  504. const fullTree = (deptRes as DeptTree[]) ?? [];
  505. const tree = Array.isArray(fullTree) && fullTree[0]?.children ? fullTree[0].children : [];
  506. deductDeptOptions.value = flattenDeptTreeForDeduct(tree);
  507. } catch (e) {
  508. console.error('获取部门列表失败:', e);
  509. deductDeptOptions.value = [];
  510. }
  511. };
  512. const handleOpenDeduct = (id: number) => {
  513. deductDangerId.value = id;
  514. deductDeptIdsArray.value = [];
  515. deductForm.value = {
  516. dangerId: id,
  517. deductionScore: 0,
  518. };
  519. showDeductDialog.value = true;
  520. };
  521. const handleDeductSubmit = async () => {
  522. await deductFormRef.value?.validate?.().catch(() => {});
  523. const score = Number(deductForm.value.deductionScore);
  524. if (score < 0 || score > 9999 || !Number.isInteger(score)) {
  525. ElMessage.warning('扣分值须为0-9999的整数');
  526. return;
  527. }
  528. try {
  529. deductForm.value.dangerId = deductDangerId.value;
  530. deductForm.value.department_ids =
  531. deductDeptIdsArray.value.length > 0 ? deductDeptIdsArray.value.join(',') : undefined;
  532. await deductHiddenDangerPoints(deductForm.value);
  533. ElMessage.success('扣分记录成功');
  534. showDeductDialog.value = false;
  535. getTableData();
  536. } catch (e) {
  537. console.error('扣分失败:', e);
  538. ElMessage.error('扣分失败,请重试');
  539. }
  540. };
  541. const handleView = (id: number) => {
  542. router.push({
  543. path: HIDDEN_ACCOUNT_ITEM_PATH,
  544. query: {
  545. id: String(id),
  546. operate: 'hidden-trouble-account-view',
  547. },
  548. });
  549. };
  550. onMounted(() => {
  551. getTableData();
  552. });
  553. </script>
  554. <style scoped lang="scss">
  555. @use '@/styles/page-details-layout.scss' as *;
  556. @use '@/styles/page-main-layout.scss' as *;
  557. @use '@/styles/basic-table-action.scss' as *;
  558. @use '@/views/traffic/violation/style/act-search-table.scss' as *;
  559. </style>