| | |
| | | return columns || '<td class="route-col"></td>'; |
| | | }; |
| | | |
| | | const renderItems = (items, startIndex, routeNodes, totalCols) => { |
| | | const renderItems = ( |
| | | items, |
| | | startIndex, |
| | | routeNodes, |
| | | totalCols, |
| | | previousProductName, |
| | | fallbackProductName |
| | | ) => { |
| | | const list = Array.isArray(items) ? items : []; |
| | | if (list.length === 0) { |
| | | return `<tr><td colspan="${totalCols}" style="text-align:center;">暂无明细</td></tr>`; |
| | | } |
| | | const routeEmptyCells = renderRouteEmptyCells(routeNodes); |
| | | let lastProductName = String(previousProductName ?? "").trim(); |
| | | return list |
| | | .map( |
| | | (item, index) => ` |
| | | .map((item, index) => { |
| | | const currentProductName = |
| | | String(item?.productDescription ?? "").trim() || fallbackProductName; |
| | | const shouldRenderProductRow = currentProductName !== lastProductName; |
| | | lastProductName = currentProductName; |
| | | return ` |
| | | ${shouldRenderProductRow ? `<tr><td colspan="${totalCols}" class="section-title">产品名称:${escapeHtml(currentProductName)}</td></tr>` : ""} |
| | | <tr> |
| | | <td>${startIndex + index + 1}</td> |
| | | <td class="no-wrap">${escapeHtml(item?.floorCode)}</td> |
| | |
| | | <td class="no-wrap">${escapeHtml(item?.processRequirement)}</td> |
| | | ${routeEmptyCells} |
| | | </tr> |
| | | ` |
| | | ) |
| | | `; |
| | | }) |
| | | .join(""); |
| | | }; |
| | | |
| | |
| | | const data = cardData ?? {}; |
| | | const routeNodes = Array.isArray(data.routeNodes) ? data.routeNodes : []; |
| | | const items = Array.isArray(data.items) ? data.items : []; |
| | | const firstItem = items[0] ?? {}; |
| | | const productName = firstItem.productDescription || ""; |
| | | const fallbackProductName = String(data?.productName ?? "").trim(); |
| | | const totalCols = 6 + Math.max(routeNodes.length, 1); |
| | | const signLabelCols = 2; |
| | | const signBlankCols = Math.max(totalCols - 5 - signLabelCols, 1); |
| | |
| | | .map((pageItems, pageIndex) => { |
| | | const isLastPage = pageIndex === totalPages - 1; |
| | | const startIndex = pageIndex * pageSize; |
| | | const previousProductName = |
| | | startIndex > 0 |
| | | ? String(items[startIndex - 1]?.productDescription ?? "").trim() || |
| | | fallbackProductName |
| | | : ""; |
| | | return ` |
| | | <div class="page"> |
| | | <div class="header"> |
| | |
| | | <tr>${renderRouteRow(routeNodes)}</tr> |
| | | </thead> |
| | | <tbody> |
| | | <tr> |
| | | <td colspan="${totalCols}" class="section-title">产品名称:${escapeHtml(productName)}</td> |
| | | </tr> |
| | | ${renderItems(pageItems, startIndex, routeNodes, totalCols)} |
| | | ${renderItems( |
| | | pageItems, |
| | | startIndex, |
| | | routeNodes, |
| | | totalCols, |
| | | previousProductName, |
| | | fallbackProductName |
| | | )} |
| | | ${ |
| | | isLastPage |
| | | ? `<tr> |