| | |
| | | const getDeliveryAddress = (data) => |
| | | data?.companyAddress || data?.deliveryAddress || data?.shippingAddress || data?.address || data?.shipAddress || ""; |
| | | |
| | | const getItemProductName = (item, fallback = "") => { |
| | | const name = |
| | | item?.productDescription || |
| | | item?.productName || |
| | | item?.name || |
| | | item?.title || |
| | | item?.goodsName || |
| | | item?.materialName || |
| | | item?.glassName; |
| | | return String(name ?? "").trim() || String(fallback ?? "").trim(); |
| | | }; |
| | | |
| | | const normalizeRequirementText = (value) => { |
| | | const text = String(value ?? "").trim(); |
| | | if (!text) return ""; |
| | |
| | | return pages; |
| | | }; |
| | | |
| | | const renderRows = (items, startIndex) => { |
| | | const renderRows = (items, startIndex, previousProductName, fallbackProductName) => { |
| | | const list = Array.isArray(items) ? items : []; |
| | | if (list.length === 0) { |
| | | return ` |
| | |
| | | </tr> |
| | | `; |
| | | } |
| | | let lastProductName = String(previousProductName ?? "").trim(); |
| | | return list |
| | | .map((item, idx) => { |
| | | const currentProductName = getItemProductName(item, fallbackProductName); |
| | | const shouldRenderProductRow = currentProductName !== lastProductName; |
| | | lastProductName = currentProductName; |
| | | const width = escapeHtml(item?.width); |
| | | const height = escapeHtml(item?.height); |
| | | const sizeText = width || height ? `${width}*${height}` : ""; |
| | | const unitPrice = formatMoney(item?.taxInclusiveUnitPrice || item?.unitPrice); |
| | | const amount = formatMoney(getItemAmount(item)); |
| | | return ` |
| | | ${ |
| | | shouldRenderProductRow |
| | | ? `<tr class="product-row"><td colspan="6" class="left">产品名称: ${escapeHtml(currentProductName)}</td><td colspan="2" class="left">订单编号: ${escapeHtml(item?.salesContractNo || "")}</td></tr>` |
| | | : "" |
| | | } |
| | | <tr> |
| | | <td>${startIndex + idx + 1}</td> |
| | | <td>${escapeHtml(item?.floorCode)}</td> |
| | |
| | | export const printSalesOrder = (orderData) => { |
| | | const data = orderData ?? {}; |
| | | const items = Array.isArray(data.items) ? data.items : []; |
| | | const fallbackProductName = String(data?.productName ?? "").trim(); |
| | | const pageSize = 15; |
| | | const pages = splitItemsByPage(items, pageSize); |
| | | const totalPages = pages.length; |
| | |
| | | .map((pageItems, pageIndex) => { |
| | | const isLastPage = pageIndex === totalPages - 1; |
| | | const startIndex = pageIndex * pageSize; |
| | | const previousProductName = |
| | | startIndex > 0 ? getItemProductName(items[startIndex - 1], fallbackProductName) : ""; |
| | | return ` |
| | | <div class="page"> |
| | | <div class="title-main">${escapeHtml(data.companyName || "鹤壁天沐钢化玻璃厂")}</div> |
| | |
| | | <th>金额</th> |
| | | <th>加工要求</th> |
| | | </tr> |
| | | <tr class="product-row"> |
| | | <td colspan="6" class="left">产品名称: ${escapeHtml(data.productName || items[0]?.productDescription)}</td> |
| | | <td colspan="2" class="left">订单编号: ${escapeHtml(data.salesContractNo)}</td> |
| | | </tr> |
| | | ${renderRows(pageItems, startIndex)} |
| | | ${renderRows(pageItems, startIndex, previousProductName, fallbackProductName)} |
| | | ${ |
| | | isLastPage |
| | | ? ` |