From 7045af0881d33da4a690922e58d2e385b2c94711 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Wed, 4 Sep 2024 14:43:29 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BA=A7=E5=93=81=E7=AE=A1=E7=90=86:?= =?UTF-8?q?=20=E5=AF=BC=E5=87=BAdocx:=20+v0903?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/products/Detail/Header.jsx | 2 +- .../products/Print/AgencyContract_v0903.jsx | 234 ++++++++++++++---- 2 files changed, 185 insertions(+), 51 deletions(-) diff --git a/src/views/products/Detail/Header.jsx b/src/views/products/Detail/Header.jsx index 0fe5e40..ed1c218 100644 --- a/src/views/products/Detail/Header.jsx +++ b/src/views/products/Detail/Header.jsx @@ -15,7 +15,7 @@ import VendorSelector from '@/components/VendorSelector'; import AuditStateSelector from '@/components/AuditStateSelector'; import NewProductModal from './NewProductModal'; -import AgencyContract from '../Print/AgencyContract_v3'; +import AgencyContract from '../Print/AgencyContract_v0903'; import { saveAs } from "file-saver"; import { Packer } from "docx"; diff --git a/src/views/products/Print/AgencyContract_v0903.jsx b/src/views/products/Print/AgencyContract_v0903.jsx index 3ce91a0..11b7527 100644 --- a/src/views/products/Print/AgencyContract_v0903.jsx +++ b/src/views/products/Print/AgencyContract_v0903.jsx @@ -22,7 +22,7 @@ import { PositionalTabLeader, } from 'docx'; import dayjs from 'dayjs'; -import { cloneDeep, groupBy, isEmpty, isNotEmpty, sortBy, unique, uniqWith } from '@/utils/commons'; +import { cloneDeep, flush, groupBy, isEmpty, isNotEmpty, sortBy, unique, uniqWith } from '@/utils/commons'; // Shoulder Season 平季; peak season 旺季 const isFullYearOrLonger = (year, startDate, endDate) => { @@ -390,25 +390,34 @@ export default class AgencyContract { ...(isEmpty(agencyProducts['6']) ? [] - : [this.createSubHeading(`综费`, { numbering: { reference: 'products-type', level: 0 } }), this.createTable_6Q(use_year, agencyProducts['6'])]), + : [this.createSubHeading(`综费(元/人/天)`, { numbering: { reference: 'products-type', level: 0 } }), this.createTable_6(use_year, agencyProducts['6'])]), ...(isEmpty(agencyProducts['B']) ? [] - : [this.createSubHeading(`超公里`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_B(use_year, agencyProducts['B'])]), + : [this.createSubHeading(`超公里(元/人)`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_B(use_year, agencyProducts['B'])]), ...(isEmpty(agencyProducts['J']) ? [] - : [this.createSubHeading(`车费`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_JD(use_year, agencyProducts['J'])]), + : [this.createSubHeading(`车费(元/团)`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_JD(use_year, agencyProducts['J'])]), ...(isEmpty(agencyProducts['Q']) ? [] - : [this.createSubHeading(`导游`, { numbering: { reference: 'products-type', level: 0 } }), this.createTable_6Q(use_year, agencyProducts['Q'])]), + : [this.createSubHeading(`导游`, { numbering: { reference: 'products-type', level: 0 } }), this.createTable_Q(use_year, agencyProducts['Q'])]), ...(isEmpty(agencyProducts['7']) ? [] - : [this.createSubHeading(`景点`, { numbering: { reference: 'products-type', level: 0 } }), this.createTable_7(use_year, agencyProducts['7'], agencyExtras)]), + : [ + this.createSubHeading(`景点(默认元/人,部分价格为元/团单独注明)`, { numbering: { reference: 'products-type', level: 0 } }), + this.createTable_7(use_year, agencyProducts['7'], agencyExtras), + ]), ...(isEmpty(agencyProducts['R']) ? [] - : [this.createSubHeading(`餐费`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_R(use_year, agencyProducts['R'], agencyExtras)]), + : [ + this.createSubHeading(`餐费(元/人/餐)`, { numbering: { reference: 'products-type', level: 0 } }), + ...this.createTable_R(use_year, agencyProducts['R'], agencyExtras), + ]), ...(isEmpty(agencyProducts['D']) ? [] - : [this.createSubHeading(`包价线路`, { numbering: { reference: 'products-type', level: 0 } }), ...this.createTable_JD(use_year, agencyProducts['D'])]), + : [ + this.createSubHeading(`包价线路(元/团,部分价格为元/人单独注明)`, { numbering: { reference: 'products-type', level: 0 } }), + ...this.createTable_JD(use_year, agencyProducts['D']), + ]), this.createSubHeading(`公司银行账户`, { numbering: { reference: 'products-type', level: 0 } }), this.createInfo_Bank(), this.createSubHeading(`联系资料`, { numbering: { reference: 'products-type', level: 0 } }), @@ -425,11 +434,10 @@ export default class AgencyContract { /** * 综费 - * 导游 */ - createTable_6Q(use_year, dataList, style = {}) { - const { chunk, SSRange, PSRange } = chunkBy(use_year, dataList, ['quote_season']); - + createTable_6(use_year, dataList, style = {}) { + const { chunk, SSRange, sizeSets } = chunkBy(use_year, dataList, ['quote_season']); + // console.log('\n\n\n6', chunk, '\n',sizeSets); return new Table({ borders: tableBorderNone, width: { @@ -438,9 +446,9 @@ export default class AgencyContract { }, rows: [ new TableRow({ - children: [this.createTableHeader('项目', 30), this.createTableHeader(['平季', ...SSRange], 35), this.createTableHeader(['旺季', ...PSRange], 35)], + children: [this.createTableHeader('项目', 30), this.createTableHeader('人等', 20), this.createTableHeader([...SSRange], 50)], }), - ...chunk.map((row, ri) => this.createDetailRowSeason2(row, ri)).reduce((a, c) => a.concat(c), []), + ...chunk.reduce((acc, row, ri) => acc.concat(this.createDetailRowSizeSS(sizeSets, row, ri)), []), this.createTable_Memo(3), ], @@ -475,20 +483,24 @@ export default class AgencyContract { children: [ this.createTableHeader('超公里项目', 20), this.createTableHeader('往返公里数', 20), - this.createTableHeader(['全年', ...SSRange, ...PSRange], 60, { columnSpan: size.length }), + this.createTableHeader([...SSRange], 60, { columnSpan: size.length }), ], }), new TableRow({ children: [ new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), - ...size.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: `${ss[0]}` })] })), + ...size.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ + // text: `${ss[0]}`, + text: ss[1] === Infinity ? `${ss[0]}人以上` : `${unique(ss.filter((x) => x)).join('-')}人`, + alignment: AlignmentType.CENTER, + })] })), ], }), ...chunk .filter((p) => p.sizeSetsSS === size.map((mr) => mr[0]).join(',')) - .map((row, ri) => this.createDetailRowSize(size, row, ri, { infoCol })) - .reduce((a, c) => a.concat(c), []), + .reduce((acc, row, ri) => acc.concat(this.createDetailRowSize(size, row, ri, { infoCol, withSize: false, defaultUnit: '0' })), []), + // .reduce((a, c) => a.concat(c), []), this.createTable_Memo(2 + size.length), ], @@ -505,7 +517,10 @@ export default class AgencyContract { * 包价线路 */ createTable_JD(use_year, dataList) { - const { dataSource, sizeSets, SSRange, PSRange } = chunkBy(use_year, dataList, ['quote_season', 'quote_size']); + const chunk_By = ['quote_size']; // dataList[0].info.product_type_id === 'J' ? ['quote_size'] : ['quote_season', 'quote_size']; + const showPSCol = false; // dataList[0].info.product_type_id === 'J' ? false : true; + const defaultUnit = '1'; // dataList[0].info.product_type_id === 'J' ? '' : ''; + const { dataSource, sizeSets, SSRange, PSRange } = chunkBy(use_year, dataList, chunk_By); const tableHeader = this.createTableHeader; const tableS = sizeSets.reduce((rt, setItem) => { @@ -519,19 +534,49 @@ export default class AgencyContract { new TableRow({ children: [ tableHeader('项目', 20), - tableHeader(['平季', ...SSRange], 40, { columnSpan: setItem.length }), - tableHeader(['旺季', ...PSRange], 40, { columnSpan: setItem.length }), + tableHeader([...SSRange], 40, { columnSpan: setItem.length }), + showPSCol ? tableHeader(['旺季', ...PSRange], 40, { columnSpan: setItem.length }) : undefined, ], }), new TableRow({ children: [ new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), - ...setItem.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: `${ss[0]}` })] })), - ...setItem.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: `${ss[0]}` })] })), + ...setItem.map( + (ss) => + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + // text: `${ss[0]}`, + text: ss[1] === Infinity ? `${ss[0]}人以上` : `${unique(ss.filter((x) => x)).join('-')}人`, + alignment: AlignmentType.CENTER, + }), + ], + }) + ), + ...(showPSCol + ? setItem.map( + (ss) => + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + // text: `${ss[0]}`, + text: ss[1] === Infinity ? `${ss[0]}人以上` : `${unique(ss.filter((x) => x)).join('-')}人`, + alignment: AlignmentType.CENTER, + }), + ], + }) + ) + : []), ], }), - ...dataSource.filter((p) => p.sizeSetsSS === setItem.map((mr) => mr[0]).join(',')) - .map((row, ri) => this.createDetailRowSize(setItem, row, ri, { withSeason: true })).reduce((a, c) => a.concat(c), []), + ...dataSource + .filter((p) => p.sizeSetsSS === setItem.map((mr) => mr[0]).join(',')) + .reduce((acc, row, ri) => acc.concat(this.createDetailRowSize(setItem, row, ri, { withSize: false, defaultUnit, withSeason: showPSCol })), []), + // .reduce((a, c) => a.concat(c), []), this.createTable_Memo(1 + setItem.length * 2), ], @@ -544,10 +589,26 @@ export default class AgencyContract { } /** * 导游 - * @ignore - * @deprecated */ - createTable_Q(use_year, dataList) {} + createTable_Q(use_year, dataList) { + const { chunk, SSRange, PSRange } = chunkBy(use_year, dataList, ['quote_season']); + + return new Table({ + borders: tableBorderNone, + width: { + size: 100, + type: WidthType.PERCENTAGE, + }, + rows: [ + new TableRow({ + children: [this.createTableHeader('项目', 30), this.createTableHeader(['平季(除去旺季以外的时间)', ...SSRange], 35), this.createTableHeader(['旺季', ...PSRange], 35)], + }), + ...chunk.map((row, ri) => this.createDetailRowSeason2(row, ri, { withSize: false })).reduce((a, c) => a.concat(c), []), + + this.createTable_Memo(3), + ], + }); + } /** * 景点 */ @@ -584,7 +645,7 @@ export default class AgencyContract { // new TextRun({ text: `${extra.info.product_title} ${firstQ.unit_name}`, bold: true }), new TextRun({ text: - `${firstQ.adult_cost}, ${firstQ.group_size_min}-${firstQ.group_size_max}人, ${firstQ.unit_name}` + + `${firstQ.group_size_min}-${firstQ.group_size_max}人, ${firstQ.unit_name}, ${firstQ.adult_cost}` + // + (`, ${firstQ.group_size_min}-${firstQ.group_size_max}人`) (compactBy !== 'dates' ? `, ${date1}~${date2}${otherStr}` : ''), }), @@ -613,7 +674,8 @@ export default class AgencyContract { this.createTableHeader('附加费用', 25), ], }), - ...chunk.map((row, ri) => this.createDetailRowSeason2(row, ri, { extraCol })).reduce((a, c) => a.concat(c), []), + ...chunk.reduce((acc, row, ri) => acc.concat(this.createDetailRowSeason2(row, ri, { withSize: true, defaultUnit: '0', extraCol })), []), + // ...chunk.map((row, ri) => this.createDetailRowSeason2(row, ri, { withSize: true, defaultUnit: '0', extraCol })).reduce((a, c) => a.concat(c), []), this.createTable_Memo(1 + sizeSets.length * 2 + 1), ], @@ -638,6 +700,12 @@ export default class AgencyContract { }); const tableS = sizeSets.reduce((acc, size) => { + const thisChunk = chunk.filter((p) => p.sizeSetsSS === size.map((mr) => mr[0]).join(',')); + const currentChunkExtras = uniqWith(thisChunk.map((p) => p.extras).flat(), (a, b) => a.info.id === b.info.id); + const mergedUniqueExtra = currentChunkExtras.map( + (extra) => new Paragraph({ text: `${extra.info.product_title} ${extra.quotation?.[0]?.adult_cost || ''} ${extra.quotation?.[0]?.unit_name || ''}` }) + ); + const subTable = new Table({ borders: tableBorderNone, width: { @@ -648,20 +716,24 @@ export default class AgencyContract { new TableRow({ children: [ this.createTableHeader('社会餐厅午餐/晚餐', 25), - this.createTableHeader(['价格', ...SSRange, ...PSRange], 50, { columnSpan: size.length }), + this.createTableHeader([...SSRange, ...PSRange], 50, { columnSpan: size.length }), this.createTableHeader('司陪餐补', 25), ], }), new TableRow({ children: [ new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), - ...size.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: `${ss[0]}` })] })), - // new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, rowSpan: dataList.length+1, children: [new Paragraph({ text: '' })] }), - new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), + ...size.map((ss) => new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ + // text: `${ss[0]}`, + text: ss[1] === Infinity ? `${ss[0]}人以上` : `${unique(ss.filter((x) => x)).join('-')}人`, + alignment: AlignmentType.CENTER, + })] })), + new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, rowSpan: thisChunk.length+1, children: mergedUniqueExtra }), // [new Paragraph({ text: `${thisChunk.length+1}` })] + // new TableCell({ borders: tableBorderOne, verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })] }), ], }), - ...chunk.filter((p) => p.sizeSetsSS === size.map((mr) => mr[0]).join(',')) - .map((row, ri) => this.createDetailRowSize(size, row, ri, { withSize: false, extraCol })).reduce((a, c) => a.concat(c), []), + ...thisChunk + .reduce((acc, row, ri) => acc.concat(this.createDetailRowSize(size, row, ri, { withSize: false, })), []), this.createTable_Memo(1 + size.length + 1), ], @@ -678,12 +750,71 @@ export default class AgencyContract { */ createTable_D(use_year, dataList) {} - createDetailRowSize(sizeSets, rowp, ii, { withSeason = false, withSize = true, infoCol = () => {}, extraCol = () => {} } = {}) { + createDetailRowSizeSS = (sizeSets, rowp, ii, { withSeason = false, withSize = true, infoCol = () => {}, extraCol = () => {} } = {}) => { + const thisSizeCol = rowp.sizeSetsSS.split(',').map((min, i, _arr) => [Number(min), _arr[i + 1] ? Number(_arr[i + 1]) - 1 : Infinity]); + const sizeLength = thisSizeCol.length; + const quote_chunk = (rowp.quote_chunk?.SS || []).reduce((acc, cur, i) => { + return { ...acc, [cur.quote_size]: cur.adult_cost }; + }, {}); + + return thisSizeCol.map( + (sizeRow, ri) => + new TableRow({ + children: flush([ + // new TableCell({ + // borders: tableBorderOne, + // rowSpan: 3, + // verticalAlign: AlignmentType.CENTER, + // children: [new Paragraph(String(ii + 1))], + // }), + ...(ri === 0 + ? [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + rowSpan: sizeLength, + children: [ + new Paragraph({ + text: `${rowp?.info?.product_title}`, + alignment: AlignmentType.LEFT, + }), + ], + }), + infoCol(rowp), + ] + : []), + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + text: sizeRow[1] === Infinity ? `${sizeRow[0]}人以上` : `${unique(sizeRow.filter((x) => x)).join('-')}人`, + alignment: AlignmentType.CENTER, + }), + ], + }), + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + text: `${quote_chunk?.[sizeRow.join('-')] || ''}`, + alignment: AlignmentType.CENTER, + }), + ], + }), + extraCol(rowp, ii), + ]), + }) + ); + }; + + createDetailRowSize(sizeSets, rowp, ii, { withSeason = false, withSize = true, infoCol = () => {}, extraCol = () => {}, defaultUnit = '0' } = {}) { const sizeCol = sizeSets.map((ss) => ss.join('-')); return [ new TableRow({ - children: [ + children: flush([ // new TableCell({ // borders: tableBorderOne, // rowSpan: 3, @@ -711,11 +842,11 @@ export default class AgencyContract { ...((withSeason ? rowp.quote_chunk?.['SS']?.[ss] : rowp.quote_chunk[ss]) || []).map( (quoteItem, ii) => new Paragraph({ - alignment: AlignmentType.LEFT, + alignment: AlignmentType.CENTER, text: isEmpty(quoteItem) ? '' - : withSize - ? `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}` + : withSize && String(quoteItem.unit_id)!==defaultUnit + ? `${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}, ${quoteItem.adult_cost}` : `${quoteItem.adult_cost}`, }) ), @@ -734,10 +865,10 @@ export default class AgencyContract { ...(rowp.quote_chunk?.['PS']?.[ss] || []).map( (quoteItem, ii) => new Paragraph({ - alignment: AlignmentType.LEFT, + alignment: AlignmentType.CENTER, // text: `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}${quoteItem.unit_name}`, - text: withSize - ? `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}` + text: withSize && String(quoteItem.unit_id)!==defaultUnit + ? `${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}, ${quoteItem.adult_cost}` : `${quoteItem.adult_cost}`, }) ), @@ -746,11 +877,12 @@ export default class AgencyContract { ) : []), extraCol(rowp, ii), - ], + ]), }), ]; } - createDetailRowSeason2(rowp, ii, { extraCol = () => {} } = {}) { + createDetailRowSeason2(rowp, ii, { withSize = true, defaultUnit = '0', extraCol = () => {} } = {}) { + return [ new TableRow({ children: [ @@ -778,8 +910,9 @@ export default class AgencyContract { ...(rowp.quote_chunk['SS'] || []).map( (quoteItem, ii) => new Paragraph({ - alignment: AlignmentType.LEFT, - text: `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}`, + alignment: AlignmentType.CENTER, + // text: `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}`, + text: (withSize && String(quoteItem.unit_id)!==defaultUnit ? `${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name},` : '') + `${quoteItem.adult_cost}`, }) ), ], @@ -792,8 +925,9 @@ export default class AgencyContract { ...(rowp.quote_chunk['PS'] || []).map( (quoteItem, ii) => new Paragraph({ - alignment: AlignmentType.LEFT, - text: `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}`, + alignment: AlignmentType.CENTER, + // text: `${quoteItem.adult_cost}, ${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name}`, + text: (withSize && String(quoteItem.unit_id)!==defaultUnit ? `${quoteItem.group_size_min}-${quoteItem.group_size_max}人,${quoteItem.unit_name},` : '') + `${quoteItem.adult_cost}`, }) ), ],