particulars.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <template>
  2. <div class="page-particulars">
  3. <div class="page-particulars-header">
  4. <h2 class="page-particulars-title">项目明细</h2>
  5. <div class="page-particulars-actions">
  6. <button
  7. type="button"
  8. class="page-particulars-btn is-outline"
  9. @click="onExportWord"
  10. >
  11. 导出Word
  12. </button>
  13. <button type="button" class="page-particulars-btn is-primary" @click="goCreateProject">
  14. <icon-svg name="project_add" size="16px" />
  15. <span>新增项目</span>
  16. </button>
  17. </div>
  18. </div>
  19. <div class="page-particulars-panel">
  20. <div class="page-particulars-panel-header">
  21. <div class="page-particulars-panel-left">
  22. <div class="page-particulars-panel-title">项目列表</div>
  23. <div class="page-particulars-legend">
  24. <span
  25. v-for="item in tableLegend"
  26. :key="item.key"
  27. class="page-particulars-legend-item"
  28. >
  29. <i
  30. class="page-particulars-legend-dot"
  31. :class="`is-${item.key}`"
  32. ></i>
  33. {{ item.label }}
  34. </span>
  35. </div>
  36. </div>
  37. <el-select v-model="listFilter" size="small" style="width: 120px">
  38. <el-option
  39. v-for="opt in listFilterOptions"
  40. :key="opt.value"
  41. :label="opt.label"
  42. :value="opt.value"
  43. />
  44. </el-select>
  45. </div>
  46. <div class="page-particulars-table-scroll">
  47. <table class="page-particulars-table">
  48. <thead>
  49. <tr>
  50. <th rowspan="2" class="col-name">项目名称</th>
  51. <th rowspan="2" class="col-risk">环境风险</th>
  52. <th colspan="4" class="group-feasibility group-title">可行性研究</th>
  53. <th colspan="4" class="group-basic group-title">基础设计</th>
  54. <th colspan="4" class="group-detail group-title">详细设计/建造安装</th>
  55. <th rowspan="2" class="col-action">操作</th>
  56. </tr>
  57. <tr>
  58. <th
  59. v-for="col in phaseSubColumns"
  60. :key="`f-${col.key}`"
  61. class="group-feasibility"
  62. >
  63. {{ col.label }}
  64. </th>
  65. <th
  66. v-for="col in phaseSubColumns"
  67. :key="`b-${col.key}`"
  68. class="group-basic"
  69. >
  70. {{ col.label }}
  71. </th>
  72. <th
  73. v-for="col in phaseSubColumns"
  74. :key="`d-${col.key}`"
  75. class="group-detail"
  76. >
  77. {{ col.label }}
  78. </th>
  79. </tr>
  80. </thead>
  81. <tbody>
  82. <template v-for="(row, rowIndex) in tableRows" :key="rowIndex">
  83. <tr v-if="row.isGap" class="page-particulars-gap-row">
  84. <td colspan="15"></td>
  85. </tr>
  86. <tr v-else>
  87. <td
  88. v-if="row.isFirst"
  89. class="col-name"
  90. :rowspan="row.rowspan"
  91. >
  92. {{ row.project.name }}
  93. </td>
  94. <td
  95. v-if="row.isFirst"
  96. class="col-risk"
  97. :rowspan="row.rowspan"
  98. >
  99. {{ row.project.risk }}
  100. </td>
  101. <td class="phase-cell">{{ row.feasibility?.name || "—" }}</td>
  102. <td
  103. class="phase-cell"
  104. :class="dateClass(row.feasibility?.planStatus, row.feasibility?.planTime)"
  105. >
  106. {{ formatDate(row.feasibility?.planTime) }}
  107. </td>
  108. <td
  109. class="phase-cell"
  110. :class="dateClass(row.feasibility?.actualStatus, row.feasibility?.actualTime)"
  111. >
  112. {{ formatDate(row.feasibility?.actualTime) }}
  113. </td>
  114. <td class="phase-cell">{{ row.feasibility?.unit || "—" }}</td>
  115. <td class="phase-cell">{{ row.basic?.name || "—" }}</td>
  116. <td
  117. class="phase-cell"
  118. :class="dateClass(row.basic?.planStatus, row.basic?.planTime)"
  119. >
  120. {{ formatDate(row.basic?.planTime) }}
  121. </td>
  122. <td
  123. class="phase-cell"
  124. :class="dateClass(row.basic?.actualStatus, row.basic?.actualTime)"
  125. >
  126. {{ formatDate(row.basic?.actualTime) }}
  127. </td>
  128. <td class="phase-cell">{{ row.basic?.unit || "—" }}</td>
  129. <td class="phase-cell">{{ row.detail?.name || "—" }}</td>
  130. <td
  131. class="phase-cell"
  132. :class="dateClass(row.detail?.planStatus, row.detail?.planTime)"
  133. >
  134. {{ formatDate(row.detail?.planTime) }}
  135. </td>
  136. <td
  137. class="phase-cell"
  138. :class="dateClass(row.detail?.actualStatus, row.detail?.actualTime)"
  139. >
  140. {{ formatDate(row.detail?.actualTime) }}
  141. </td>
  142. <td class="phase-cell">{{ row.detail?.unit || "—" }}</td>
  143. <td
  144. v-if="row.isFirst"
  145. class="col-action"
  146. :rowspan="row.rowspan"
  147. >
  148. <div class="page-particulars-ops">
  149. <button
  150. type="button"
  151. class="page-particulars-op-btn"
  152. @click="goProjectDetail(row.project)"
  153. >
  154. <icon-svg name="edit_blue" size="16px" />
  155. <span>明细</span>
  156. </button>
  157. <button
  158. type="button"
  159. class="page-particulars-op-btn"
  160. @click="goProjectProgress(row.project)"
  161. >
  162. <icon-svg name="edit_blue" size="16px" />
  163. <span>进展</span>
  164. </button>
  165. </div>
  166. </td>
  167. </tr>
  168. </template>
  169. </tbody>
  170. </table>
  171. </div>
  172. </div>
  173. </div>
  174. </template>
  175. <script setup>
  176. import { computed, onMounted, ref, watch } from "vue";
  177. import { useRouter } from "vue-router";
  178. import { ElMessage } from "element-plus";
  179. import { getDetailList, exportDetailWord } from "@/api/project";
  180. defineOptions({
  181. name: "ProjectParticulars",
  182. });
  183. const router = useRouter();
  184. const tableLegend = [
  185. { key: "warning", label: "预警" },
  186. { key: "delay", label: "滞后" },
  187. ];
  188. const listFilter = ref("all");
  189. const listFilterOptions = [
  190. { label: "全部", value: "all" },
  191. { label: "预警", value: "warning" },
  192. { label: "滞后", value: "delay" },
  193. ];
  194. const STATUS_FILTER_MAP = {
  195. all: 0,
  196. warning: 1,
  197. delay: 2,
  198. };
  199. const PHASE_KEY_MAP = {
  200. 1: "feasibility",
  201. 3: "basic",
  202. 5: "detail",
  203. };
  204. const phaseSubColumns = [
  205. { key: "name", label: "报告名称" },
  206. { key: "planTime", label: "计划完成时间" },
  207. { key: "actualTime", label: "实际完成时间" },
  208. { key: "unit", label: "报告编制单位" },
  209. ];
  210. const projectList = ref([]);
  211. const mapNodeTone = (status) => {
  212. const value = Number(status);
  213. if (value === 3) return "warning";
  214. if (value === 4) return "delay";
  215. return "";
  216. };
  217. const mapPhaseRows = (phase) => {
  218. const rows = [];
  219. (phase?.reports || []).forEach((report) => {
  220. const nodes = report.nodes || [];
  221. if (!nodes.length) {
  222. rows.push({
  223. name: report.reportName || "",
  224. planTime: "",
  225. actualTime: "",
  226. unit: "",
  227. });
  228. return;
  229. }
  230. nodes.forEach((node) => {
  231. const tone = mapNodeTone(node.status);
  232. rows.push({
  233. name: report.reportName || "",
  234. planTime: node.plannedEndDate || "",
  235. actualTime: node.actualEndDate || "",
  236. unit: node.reportUnit || "",
  237. planStatus: tone,
  238. actualStatus: tone,
  239. });
  240. });
  241. });
  242. return rows;
  243. };
  244. const mapProjectList = (list = []) =>
  245. list.map((item) => {
  246. const project = {
  247. id: item.id,
  248. name: item.projectName || "",
  249. risk: item.environmentalRisk || "",
  250. feasibility: [],
  251. basic: [],
  252. detail: [],
  253. };
  254. (item.phases || []).forEach((phase) => {
  255. const key = PHASE_KEY_MAP[Number(phase.phaseId)];
  256. if (!key) return;
  257. project[key] = mapPhaseRows(phase);
  258. });
  259. return project;
  260. });
  261. const loadDetailList = async () => {
  262. try {
  263. const status = STATUS_FILTER_MAP[listFilter.value] ?? 0;
  264. const res = await getDetailList(status);
  265. if (res?.code !== 200) {
  266. ElMessage.error(res?.msg || "获取项目明细失败");
  267. projectList.value = [];
  268. return;
  269. }
  270. projectList.value = mapProjectList(
  271. Array.isArray(res.data) ? res.data : []
  272. );
  273. } catch (error) {
  274. console.error(error);
  275. projectList.value = [];
  276. ElMessage.error("获取项目明细失败,请稍后重试");
  277. }
  278. };
  279. const getProjectRowCount = (project) =>
  280. Math.max(
  281. project.feasibility?.length || 0,
  282. project.basic?.length || 0,
  283. project.detail?.length || 0,
  284. 1
  285. );
  286. const tableRows = computed(() => {
  287. const rows = [];
  288. projectList.value.forEach((project) => {
  289. rows.push({ isGap: true });
  290. const rowspan = getProjectRowCount(project);
  291. for (let i = 0; i < rowspan; i += 1) {
  292. rows.push({
  293. project,
  294. isFirst: i === 0,
  295. rowspan,
  296. feasibility: project.feasibility[i] || null,
  297. basic: project.basic[i] || null,
  298. detail: project.detail[i] || null,
  299. });
  300. }
  301. });
  302. return rows;
  303. });
  304. const formatDate = (value) => value || "—";
  305. const dateClass = (status, value) => {
  306. if (!value) return "";
  307. if (status === "warning") return "is-warning";
  308. if (status === "delay") return "is-delay";
  309. return "";
  310. };
  311. const onExportWord = async () => {
  312. try {
  313. const res = await exportDetailWord();
  314. const cd = res.headers?.["content-disposition"] || "";
  315. const m = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(cd);
  316. const fileName = m ? decodeURIComponent(m[1]) : "项目明细.docx";
  317. const url = URL.createObjectURL(new Blob([res.data]));
  318. const a = document.createElement("a");
  319. a.href = url;
  320. a.download = fileName;
  321. document.body.appendChild(a);
  322. a.click();
  323. document.body.removeChild(a);
  324. URL.revokeObjectURL(url);
  325. } catch (error) {
  326. console.error(error);
  327. ElMessage.error("导出Word失败,请稍后重试");
  328. }
  329. };
  330. const goCreateProject = () => {
  331. router.push({
  332. name: "projectDetail",
  333. query: {
  334. from: "particulars",
  335. mode: "create",
  336. },
  337. });
  338. };
  339. const goProjectDetail = (project) => {
  340. if (project?.id == null) return;
  341. router.push({
  342. name: "projectDetail",
  343. query: {
  344. from: "particulars",
  345. projectId: String(project.id),
  346. },
  347. });
  348. };
  349. const goProjectProgress = (project) => {
  350. if (project?.id == null) return;
  351. router.push({
  352. name: "projectProgress",
  353. query: {
  354. projectId: String(project.id),
  355. },
  356. });
  357. };
  358. watch(listFilter, () => {
  359. loadDetailList();
  360. });
  361. onMounted(() => {
  362. loadDetailList();
  363. });
  364. </script>
  365. <style scoped lang="scss">
  366. .page-particulars {
  367. box-sizing: border-box;
  368. display: flex;
  369. flex-direction: column;
  370. gap: 16px;
  371. width: 100%;
  372. height: 100%;
  373. min-height: 0;
  374. padding: 24px;
  375. overflow: hidden;
  376. background: #f3f7fc;
  377. }
  378. .page-particulars-header {
  379. display: flex;
  380. flex-shrink: 0;
  381. align-items: center;
  382. justify-content: space-between;
  383. gap: 16px;
  384. }
  385. .page-particulars-title {
  386. margin: 0;
  387. font-family: PingFang SC, PingFang SC;
  388. font-weight: 600;
  389. font-size: 18px;
  390. color: #16213a;
  391. line-height: 25px;
  392. text-align: left;
  393. }
  394. .page-particulars-actions {
  395. display: flex;
  396. align-items: center;
  397. gap: 24px;
  398. }
  399. .page-particulars-btn {
  400. display: inline-flex;
  401. align-items: center;
  402. padding: 6px 16px;
  403. font-family: PingFang SC, PingFang SC;
  404. font-weight: 500;
  405. font-size: 14px;
  406. line-height: 20px;
  407. text-align: left;
  408. border-radius: 2px;
  409. box-shadow: 0px 4px 10px 0px rgba(35, 130, 231, 0.2);
  410. cursor: pointer;
  411. &.is-outline {
  412. color: #2382e7;
  413. background: #ffffff;
  414. border: 1px solid #2382e7;
  415. &:hover {
  416. border-color: #2382e7;
  417. }
  418. }
  419. &.is-primary {
  420. gap: 4px;
  421. color: #ffffff;
  422. background: #2382e7;
  423. border: 1px solid #2382e7;
  424. &:hover {
  425. border-color: #2382e7;
  426. }
  427. }
  428. }
  429. .page-particulars-panel {
  430. box-sizing: border-box;
  431. display: flex;
  432. flex-direction: column;
  433. flex: 1;
  434. min-height: 0;
  435. gap: 14px;
  436. padding: 16px;
  437. overflow: hidden;
  438. background: #ffffff;
  439. border-radius: 4px;
  440. }
  441. .page-particulars-panel-header {
  442. display: flex;
  443. flex-shrink: 0;
  444. align-items: center;
  445. justify-content: space-between;
  446. gap: 16px;
  447. }
  448. .page-particulars-panel-left {
  449. display: flex;
  450. align-items: center;
  451. gap: 16px;
  452. min-width: 0;
  453. }
  454. .page-particulars-panel-title {
  455. position: relative;
  456. padding-left: 10px;
  457. font-family: PingFang SC, PingFang SC;
  458. font-weight: 600;
  459. font-size: 14px;
  460. color: #16213a;
  461. line-height: 20px;
  462. &::before {
  463. position: absolute;
  464. top: 50%;
  465. left: 0;
  466. width: 4px;
  467. height: 14px;
  468. background: #2382e7;
  469. border-radius: 0 2px 2px 0;
  470. transform: translateY(-50%);
  471. content: "";
  472. }
  473. }
  474. .page-particulars-legend {
  475. display: flex;
  476. align-items: center;
  477. gap: 12px;
  478. }
  479. .page-particulars-legend-item {
  480. display: inline-flex;
  481. align-items: center;
  482. gap: 4px;
  483. font-size: 14px;
  484. color: #9aa5b8;
  485. line-height: 20px;
  486. white-space: nowrap;
  487. }
  488. .page-particulars-legend-dot {
  489. width: 6px;
  490. height: 6px;
  491. border-radius: 50%;
  492. background: #d0d5dd;
  493. &.is-warning {
  494. background: #ff8e38;
  495. }
  496. &.is-delay {
  497. background: #f54848;
  498. }
  499. }
  500. .page-particulars-table-scroll {
  501. flex: 1;
  502. width: 100%;
  503. min-height: 0;
  504. overflow: auto;
  505. scrollbar-width: none;
  506. -ms-overflow-style: none;
  507. &::-webkit-scrollbar {
  508. width: 0;
  509. height: 0;
  510. display: none;
  511. }
  512. }
  513. .page-particulars-table {
  514. width: max-content;
  515. min-width: 100%;
  516. border-collapse: separate;
  517. border-spacing: 0;
  518. table-layout: auto;
  519. font-size: 13px;
  520. color: #16213a;
  521. th,
  522. td {
  523. box-sizing: border-box;
  524. padding: 10px 12px;
  525. border: 1px solid #dfe3e7;
  526. text-align: left;
  527. vertical-align: middle;
  528. background: #ffffff;
  529. }
  530. th {
  531. font-family: PingFang SC, PingFang SC;
  532. font-weight: 400;
  533. font-size: 14px;
  534. color: #58657c;
  535. background: #edf1f6;
  536. white-space: nowrap;
  537. word-break: keep-all;
  538. }
  539. .group-feasibility {
  540. background: #e8f3fc;
  541. }
  542. .group-basic {
  543. background: #e9f7ef;
  544. }
  545. .group-detail {
  546. background: #eef0fb;
  547. }
  548. .group-title {
  549. text-align: center;
  550. }
  551. .phase-cell {
  552. white-space: nowrap;
  553. word-break: keep-all;
  554. overflow: hidden;
  555. }
  556. .col-name,
  557. .col-action {
  558. position: sticky;
  559. z-index: 2;
  560. }
  561. th.col-name,
  562. th.col-action {
  563. z-index: 4;
  564. background: #edf1f6;
  565. }
  566. td.col-name,
  567. td.col-action {
  568. background: #ffffff;
  569. }
  570. .col-name {
  571. left: 0;
  572. width: 140px;
  573. min-width: 140px;
  574. box-shadow: 2px 0 6px rgba(22, 33, 58, 0.08);
  575. }
  576. .col-risk {
  577. width: 140px;
  578. min-width: 140px;
  579. max-width: 140px;
  580. white-space: normal;
  581. word-break: break-word;
  582. }
  583. .col-action {
  584. right: 0;
  585. width: 100px;
  586. min-width: 100px;
  587. box-shadow: -2px 0 6px rgba(22, 33, 58, 0.08);
  588. }
  589. td.is-warning {
  590. color: #ff8e38;
  591. }
  592. td.is-delay {
  593. color: #f54848;
  594. }
  595. .page-particulars-gap-row td {
  596. height: 16px;
  597. padding: 0;
  598. border: none;
  599. background: transparent;
  600. }
  601. }
  602. .page-particulars-ops {
  603. display: flex;
  604. flex-direction: column;
  605. align-items: flex-start;
  606. gap: 8px;
  607. }
  608. .page-particulars-op-btn {
  609. display: inline-flex;
  610. align-items: center;
  611. gap: 4px;
  612. padding: 0;
  613. font-family: PingFang SC, PingFang SC;
  614. font-size: 13px;
  615. color: #2382e7;
  616. line-height: 18px;
  617. background: transparent;
  618. border: none;
  619. cursor: pointer;
  620. &:hover {
  621. border-color: transparent;
  622. }
  623. }
  624. </style>