From b76ddef16fd95171fd17e81bd287c904724a2a7a Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 19 Aug 2025 16:50:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=A7=E5=93=81=E7=AE=A1=E7=90=86:?= =?UTF-8?q?=20=E5=AF=BC=E5=87=BA:=20`=E5=AF=BC=E6=B8=B8`,=20`=E6=99=AF?= =?UTF-8?q?=E7=82=B9`:=20=E6=97=BA=E5=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useProductsQuotationFormat.js | 45 +++++++- src/views/products/Print/AgencyContract.jsx | 107 +++++++++++++------- src/views/products/Print/AgencyPreview.jsx | 35 ++++--- 3 files changed, 133 insertions(+), 54 deletions(-) diff --git a/src/hooks/useProductsQuotationFormat.js b/src/hooks/useProductsQuotationFormat.js index ed8321b..a61a249 100644 --- a/src/hooks/useProductsQuotationFormat.js +++ b/src/hooks/useProductsQuotationFormat.js @@ -257,8 +257,46 @@ export const splitTable_Season = (chunkData) => { const { quote_chunk } = pitem; // const bySeason = groupBy(pitem.quotation, (ele) => ele.quote_season); const rowSeason = Object.keys(quote_chunk).reduce((accp, _s) => { - const bySeasonValue = groupBy(quote_chunk[_s], (ele) => ['adult_cost', 'child_cost'].map((k) => ele[k]).join('@')); - // console.log('---- bySeasonValue', bySeasonValue); + const bySeasonValue = groupBy(quote_chunk[_s], (ele) => ['adult_cost', 'child_cost', 'group_size_min', 'group_size_max', 'unit_id'].map((k) => ele[k]).join('@')); + // console.log('---- bySeasonValue', _s, bySeasonValue); + + const byDate = groupBy(quote_chunk[_s], (ele) => `${ele.use_dates_start}~${ele.use_dates_end}`); + // console.log('---- byDate', _s, byDate); + + const subHeader = Object.keys(bySeasonValue).length >= Object.keys(byDate).length ? 'dates' : 'priceValues'; + // console.log('---- subHeader', _s, subHeader); + + let valuesArr = []; + switch (subHeader) { + case 'priceValues': + valuesArr = Object.keys(bySeasonValue).reduce((accv, valKey) => { + const valRows = bySeasonValue[valKey]; + const valRow = pick(valRows[0], ['adult_cost', 'child_cost', 'currency', 'unit_id', 'unit_name', 'group_size_min', 'group_size_max']); + // valRow.dates = valRows.map((v) => pick(v, ['id', 'use_dates_end', 'use_dates_start'])); + valRow.rows = [valRows[0]]; + valRow.originRows = valRows; + valRow.rowKey = valRows.map((v) => v.id).join(','); + valRow.headerDates = valRows.map((v) => pick(v, ['use_dates_end', 'use_dates_start'])); + accv.push(valRow); + return accv; + }, []); + break; + case 'dates': + valuesArr = Object.keys(byDate).reduce((accv, dateKey) => { + const valRows = byDate[dateKey]; + const valRow = pick(valRows[0], ['use_dates_end', 'use_dates_start']); + valRow.rows = valRows; + valRow.originRows = valRows; + valRow.rowKey = valRows.map((v) => v.id).join(','); + valRow.headerDates = [pick(valRows[0], ['use_dates_end', 'use_dates_start'])]; + accv.push(valRow); + return accv; + }, []); + break; + + default: + break; + } const valUnderSeason = Object.keys(bySeasonValue).reduce((accv, valKey) => { const valRows = bySeasonValue[valKey]; @@ -270,9 +308,8 @@ export const splitTable_Season = (chunkData) => { return accv; }, []); - return { ...accp, [_s]: valUnderSeason }; + return { ...accp, [_s]: valUnderSeason, [_s + 'Data']: valuesArr }; }, {}); - // console.log('---- rowSeason', rowSeason); return { info: pitem.info, ...rowSeason, rowKey: pitem.info.id }; }); // console.log('---- tablesQuote', tablesQuote); diff --git a/src/views/products/Print/AgencyContract.jsx b/src/views/products/Print/AgencyContract.jsx index 450e39c..c34f234 100644 --- a/src/views/products/Print/AgencyContract.jsx +++ b/src/views/products/Print/AgencyContract.jsx @@ -940,50 +940,87 @@ export default class AgencyContract { size: 100, type: WidthType.PERCENTAGE, }, - rows: (row?.PS || []).map( - (quoteItem, ii, _arr) => - new TableRow({ - borders: tableBorderInner, - children: [ - new TableCell({ - borders: ii !== _arr.length - 1 ? tableBorderInner : tableBorderInnerR, - width: { size: 2000, type: WidthType.DXA }, - verticalAlign: AlignmentType.CENTER, - children: quoteItem.rows.map( - (d) => + rows: (row?.PSData || []).reduce((accr, quoteItem0, ti, arrt) => { + const _header = new TableRow({ + borders: tableBorderInnerB, + children: [ + new TableCell({ + borders: tableBorderInnerB, + width: { size: 2000, type: WidthType.DXA }, + verticalAlign: AlignmentType.CENTER, + columnSpan: 3, + children: quoteItem0.headerDates + .map((d) => `${d.use_dates_start.replace(`${use_year}.`, '')}~${d.use_dates_end.replace(`${use_year}.`, '')}`) + .map( + (text) => new Paragraph({ - alignment: AlignmentType.LEFT, - text: `${d.use_dates_start.replace(`${use_year}.`, '')}~${d.use_dates_end.replace(`${use_year}.`, '')}`, + text: text, + alignment: AlignmentType.CENTER, }) ), - }), - new TableCell({ - borders: ii !== _arr.length - 1 ? tableBorderInnerB : tableBorderNone, - verticalAlign: AlignmentType.CENTER, - children: [ - new Paragraph({ - text: `${quoteItem.adult_cost}`, - alignment: AlignmentType.LEFT, - }), - ], - }), - ], - }) - ), + }), + ], + }); + const _rows = quoteItem0.rows.map( + (quoteItem, ii, _arr) => + new TableRow({ + borders: ti !== arrt.length - 1 ? tableBorderInnerB : tableBorderNone, + children: [ + new TableCell({ + borders: ti !== arrt.length - 1 ? tableBorderInner : tableBorderInnerR, + width: { size: 2000, type: WidthType.DXA }, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + text: `${formatGroupSize(quoteItem.group_size_min, quoteItem.group_size_max, true)}`, + alignment: AlignmentType.LEFT, + }), + ], + }), + new TableCell({ + borders: ti !== arrt.length - 1 ? tableBorderInner : tableBorderInnerR, + width: { size: 1000, type: WidthType.DXA }, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + text: `${quoteItem.unit_name}`, + alignment: AlignmentType.LEFT, + }), + ], + }), + new TableCell({ + borders: ti !== arrt.length - 1 ? tableBorderInnerB : tableBorderNone, + width: { size: 2400, type: WidthType.DXA }, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + text: `${quoteItem.adult_cost}`, + alignment: AlignmentType.CENTER, + }), + ], + }), + ], + }) + ); + return accr.concat([_header, ..._rows]); + }, []), }), ], }), new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.LEFT, - children: (agencyExtras[row.info?.id] || []).map(extra => new Paragraph({ - children: [ - new TextRun({ - text: `${extra.info.product_title}-${extra.info.product_type_name}`, - bold: true, - }), - ], - })), + children: (agencyExtras[row.info?.id] || []).map( + (extra) => + new Paragraph({ + children: [ + new TextRun({ + text: `${extra.info.product_title}-${extra.info.product_type_name}`, + bold: true, + }), + ], + }) + ), }), ], }) diff --git a/src/views/products/Print/AgencyPreview.jsx b/src/views/products/Print/AgencyPreview.jsx index 058ac92..c702dab 100644 --- a/src/views/products/Print/AgencyPreview.jsx +++ b/src/views/products/Print/AgencyPreview.jsx @@ -583,7 +583,7 @@ const AgencyPreview = ({ params, ...props }) => { <> 旺季
- - + - 成人 儿童
@@ -593,21 +593,26 @@ const AgencyPreview = ({ params, ...props }) => { key: 'PS', width: '9rem', align: 'center', - render: (_, { PS }) => ( -
- {(PS || []).map((ele, pi) => ( -
-
-
- {ele.rows.map((d, di) => ( -
- {d.use_dates_start.replace(`${use_year}.`, '')}~{d.use_dates_end.replace(`${use_year}.`, '')} -
- ))} -
- {ele.adult_cost} - {ele.child_cost} + render: (_, { PSData }) => ( +
+ {(PSData || []).map((ele, pi) => ( +
+
+ {ele.headerDates.map((d, di) => ( +
+ {d.use_dates_start.replace(`${use_year}.`, '')}~{d.use_dates_end.replace(`${use_year}.`, '')} +
+ ))}
+ {ele.rows.map((qrow, qri) => ( +
+ {formatGroupSize(qrow.group_size_min, qrow.group_size_max, true)} + {qrow.unit_name} + {qrow.adult_cost} + {qrow.child_cost} +
+ ))} +
))}