diff --git a/src/hooks/useProductsQuotationFormat.js b/src/hooks/useProductsQuotationFormat.js index 4a50c50..254daf7 100644 --- a/src/hooks/useProductsQuotationFormat.js +++ b/src/hooks/useProductsQuotationFormat.js @@ -356,10 +356,11 @@ export const splitTable_R = (use_year, dataSource, retTableOnly = true) => { return retTableOnly ? tables : { ...chunked, tables }; }; -export const splitTable_8 = (use_year, dataSource) => { +export const splitTable_8 = (use_year, dataSource, retTableOnly = true) => { const chunked = chunkBy(use_year, dataSource); // console.log(chunked); - return addCityRow4Split(splitTable_SizeSets(chunked)); + const tables = addCityRow4Split(splitTable_SizeSets(chunked)); + return retTableOnly ? tables : { ...chunked, tables }; }; export const splitTable_6 = (use_year, dataSource, retTableOnly = true) => { diff --git a/src/hooks/useProductsSets.js b/src/hooks/useProductsSets.js index 850fca9..4f5e334 100644 --- a/src/hooks/useProductsSets.js +++ b/src/hooks/useProductsSets.js @@ -70,6 +70,9 @@ export const useProductsTypesMapVal = (value) => { return stateMapVal; }; +/** + * 价格的审核状态 + */ export const useProductsAuditStates = () => { const [types, setTypes] = useState([]); const { t, i18n } = useTranslation(); @@ -153,7 +156,7 @@ export const useNewProductRecord = () => { 'lastedit_changed': '', 'create_date': '', 'created_by': '', - 'edit_status': 2, + 'edit_status': 2, // 信息的审核状态 1已发布,2已审核 'sort_order': '', 'sub_type_D': '', // 包价类型, 值保存在`item_type`字段中 'item_type': '', // 产品子类型的值 diff --git a/src/views/products/Print/AgencyContract.jsx b/src/views/products/Print/AgencyContract.jsx index c34f234..3b40a07 100644 --- a/src/views/products/Print/AgencyContract.jsx +++ b/src/views/products/Print/AgencyContract.jsx @@ -19,9 +19,14 @@ import { TextRun, WidthType, } from 'docx' -import { splitTable_6, splitTable_7, splitTable_B, splitTable_D, splitTable_J, splitTable_Q, splitTable_R } from '@/hooks/useProductsQuotationFormat'; +import { splitTable_6, splitTable_7, splitTable_B, splitTable_D, splitTable_J, splitTable_Q, splitTable_R, splitTable_8 } from '@/hooks/useProductsQuotationFormat'; import { formatGroupSize } from '@/hooks/useProductsSets' +const unitMap = { + '0': '人', + '1': '团', +} + const DOC_TITLE = '地接合同' const pageMargins = { top: `15mm`, @@ -283,7 +288,15 @@ export default class AgencyContract { this.createSubHeading(`餐费(元/人/餐)`, { numbering: { reference: 'products-type', level: 0 }, }), - ...this.createTable_R(use_year, agencyProducts['R'], agencyExtras), + ...this.createTable_R(use_year, agencyProducts['R']), + ]), + ...(isEmpty(agencyProducts['8']) + ? [] + : [ + this.createSubHeading(`附加项目(元/团,部分价格为元/人单独注明)`, { + numbering: { reference: 'products-type', level: 0 }, + }), + ...this.createTable_8(use_year, agencyProducts['8']), ]), ...(isEmpty(agencyProducts['D']) ? [] @@ -317,6 +330,7 @@ export default class AgencyContract { */ createTable_6(use_year, dataList, style = {}) { const { tables, SSRange } = splitTable_6(use_year, dataList, false); + const defaultUnit = '0'; const table2Rows = tables.reduce((acc, {info, SS}) => { return acc.concat(SS.map((v, i) => ({...v, info, rowSpan: i===0 ? SS.length : 0}))); @@ -370,7 +384,21 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ - text: `${row.adult_cost ?? ''}`, + // text: `${row.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.adult_cost ?? ''}`, + }), + ...(row?.adult_cost && row?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.unit_name || ''}`, + text: `/${unitMap[row?.unit_id] || row?.unit_name || ''}`, + // break: 1, + }), + ] + : []), + ], alignment: AlignmentType.CENTER, }), ], @@ -388,7 +416,9 @@ export default class AgencyContract { */ createTable_B(use_year, dataList) { // console.log('*********************************************************************************************'); - const { tables, SSRange } = splitTable_B(use_year, dataList, false); + const { tables, SSRange, PSRange } = splitTable_B(use_year, dataList, false); + const defaultUnit = '0'; + const showRangeCol = PSRange.length > 0; const tableS = tables.reduce((acc, { cols, data }) => { const subTable = new Table({ @@ -401,8 +431,9 @@ export default class AgencyContract { new TableRow({ children: [ this.createTableHeader('超公里项目', 20), - this.createTableHeader('往返公里数', 20), - this.createTableHeader([...SSRange], 60, { + this.createTableHeader('往返公里数', 15), + ...(showRangeCol ? [this.createTableHeader('', 15)] : []), + this.createTableHeader([...SSRange], 65, { columnSpan: cols.length, }), ], @@ -419,6 +450,15 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [new Paragraph({ text: '' })], }), + ...(showRangeCol + ? [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: '时段', alignment: 'center' })], + }), + ] + : []), ...cols.map( (ss) => new TableCell({ @@ -430,41 +470,90 @@ export default class AgencyContract { alignment: AlignmentType.CENTER, }), ], - }), + }) ), ], }), - ...data.map((row, ri) => new TableRow({ - children: [ - row.info?.isCityRow ? this.createTableHeader(row.info?.product_title || '', 20) : new TableCell({ - borders: tableBorderOne, - verticalAlign: AlignmentType.CENTER, - children: [new Paragraph({ text: row.info?.product_title || '' })], - }), - new TableCell({ - borders: tableBorderOne, - verticalAlign: AlignmentType.CENTER, - children: [new Paragraph({ text: `${row.info?.km ?? ''}`, alignment: AlignmentType.CENTER, })], - }), - ...cols.map( - (ss) => - new TableCell({ - borders: tableBorderOne, - verticalAlign: AlignmentType.CENTER, - children: [ - new Paragraph({ - text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, - alignment: AlignmentType.CENTER, - }), - ], - }), - ), - ], - })), + ...data.map( + (row, ri) => + new TableRow({ + children: [ + ...(row.rowSpan > 0 + ? row.info?.isCityRow + ? [ + this.createTableHeader(row.info?.product_title || '', 20), + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: '' })], + }), + ] + : [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: row.info?.product_title || '' })], + rowSpan: row.rowSpan, + }), + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: `${row.info?.km ?? ''}`, alignment: AlignmentType.CENTER })], + rowSpan: row.rowSpan, + }), + ] + : []), + ...(showRangeCol + ? [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + ...(row.quote_season === 'SS' + ? row.rowSpan > 1 + ? ['平季', '(除特殊时段外)'].map((str) => new Paragraph({ text: str, alignment: AlignmentType.LEFT })) + : [new Paragraph({ text: '' })] + : ['特殊时段', `${row.use_dates_start.replace(`${use_year}.`, '')}~${row.use_dates_end.replace(`${use_year}.`, '')}`].map( + (str) => new Paragraph({ text: str, alignment: AlignmentType.LEFT }) + )), + ], + }), + ] + : []), + ...cols.map( + (ss) => + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + // text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + }), + ...(row?.[formatGroupSize(...ss)]?.adult_cost && row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + break: 1, + }), + ] + : []), + ], + alignment: AlignmentType.CENTER, + }), + ], + }) + ), + ], + }) + ), - this.createTable_Memo(2 + cols.length, this.#remarkList['B'].Memo.split(`\n`)), + this.createTable_Memo(2 + cols.length + (showRangeCol ? 1 : 0), this.#remarkList['B'].Memo.split(`\n`)), ], - }) + }); acc.push(subTable); acc.push(new Paragraph({ text: `` })) // 多表格之间分隔一行 return acc @@ -477,7 +566,7 @@ export default class AgencyContract { */ createTable_J(use_year, dataList) { const { tables, SSRange, PSRange, } = splitTable_J(use_year, dataList, false); - // const defaultUnit = '1' + const defaultUnit = '1' const showRangeCol = PSRange.length > 0; const tableS = tables.reduce((acc, { cols, data }) => { @@ -564,7 +653,21 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ - text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + // text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + }), + ...(row?.[formatGroupSize(...ss)]?.adult_cost && row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + break: 1, + }), + ] + : []), + ], alignment: AlignmentType.CENTER, }), ], @@ -591,7 +694,7 @@ export default class AgencyContract { const { tables, SSRange, PSRange } = splitTable_D(use_year, dataList, false); // console.log('DDDD', tables, SSRange, PSRange); - // const defaultUnit = '1' + const defaultUnit = '1' const showRangeCol = PSRange.length > 0; // 显示时段列 // console.log(sizeSets, dataSource) @@ -681,7 +784,28 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ - text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + // text: row?.[formatGroupSize(...ss)]?.adult_cost + // ? `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}` + + // (row.info?.isCityRow !== true && // && text + // row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + // ? // ? ` /${row?.[formatGroupSize(...ss)]?.unit_name || ''}` + // ` /${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || ''}` + // : '') + // : '', + children: [ + new TextRun({ + text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + }), + ...(row?.[formatGroupSize(...ss)]?.adult_cost && row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + break: 1, + }), + ] + : []), + ], alignment: AlignmentType.CENTER, }), ], @@ -706,6 +830,7 @@ export default class AgencyContract { */ createTable_Q(use_year, dataList) { const tables = splitTable_Q(use_year, dataList, false); + const defaultUnit = '1' // console.log('QQQ', tables); return new Table({ @@ -738,7 +863,24 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: (row?.SS || []).length <= 1 - ? [new Paragraph({ text: `${row?.SS?.[0]?.adult_cost ?? ''}`, alignment: AlignmentType.CENTER })] + ? [new Paragraph({ + // text: `${row?.SS?.[0]?.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.SS?.[0]?.adult_cost ?? ''}`, + }), + ...(row?.SS?.[0].adult_cost && row?.SS?.[0]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.SS?.[0]?.unit_id] || row?.SS?.[0]?.unit_name || ''}`, + // break: 1, + }), + ] + : []), + ], + alignment: AlignmentType.CENTER + })] : [ new Table({ borders: tableBorderNone, @@ -764,6 +906,7 @@ export default class AgencyContract { }), new TableCell({ borders: ii !== _arr.length - 1 ? tableBorderInner : tableBorderInnerR, + width: { size: 1200, type: WidthType.DXA }, verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ @@ -808,7 +951,8 @@ export default class AgencyContract { children: [ new TableCell({ borders: ii !== _arr.length - 1 ? tableBorderInner : tableBorderInnerR, - width: { size: 2400, type: WidthType.DXA }, + // width: { size: 1800, type: WidthType.DXA }, + width: { size: 60, type: WidthType.PERCENTAGE }, verticalAlign: AlignmentType.CENTER, children: quoteItem.rows.map(d => new Paragraph({ alignment: AlignmentType.LEFT, text: `${d.use_dates_start.replace(`${use_year}.`, '')}~${d.use_dates_end.replace(`${use_year}.`, '')}` })), }), @@ -817,8 +961,22 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ - text: `${quoteItem.adult_cost}`, - alignment: AlignmentType.LEFT, + // text: `${quoteItem.adult_cost}`, + children: [ + new TextRun({ + text: `${quoteItem.adult_cost ?? ''}`, + }), + ...(quoteItem.adult_cost && quoteItem?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[quoteItem?.unit_id] || quoteItem?.unit_name || ''}`, + // break: 1, + }), + ] + : []), + ], + alignment: AlignmentType.CENTER, }), ], }), @@ -841,6 +999,7 @@ export default class AgencyContract { */ createTable_7(use_year, dataList, agencyExtras) { const tables = splitTable_7(use_year, dataList, false); + const defaultUnit = '0'; return new Table({ borders: tableBorderNone, @@ -874,7 +1033,7 @@ export default class AgencyContract { children: (row?.SS || []).length === 0 ? [new Paragraph({ text: '', alignment: AlignmentType.CENTER })] - : (row?.SS || []).length === 1 && row?.SS?.[0]?.unit_id === '0' + : (row?.SS || []).length === 1 && row?.SS?.[0]?.unit_id === defaultUnit ? [new Paragraph({ text: `${row?.SS?.[0]?.adult_cost ?? ''}`, alignment: AlignmentType.CENTER })] : [ new Table({ @@ -917,7 +1076,7 @@ export default class AgencyContract { children: [ new Paragraph({ text: `${quoteItem.adult_cost}`, - alignment: AlignmentType.LEFT, + alignment: AlignmentType.CENTER, }), ], }), @@ -1015,7 +1174,7 @@ export default class AgencyContract { new Paragraph({ children: [ new TextRun({ - text: `${extra.info.product_title}-${extra.info.product_type_name}`, + text: `${extra.info.product_title}-${extra.info.product_type_name_txt}`, bold: true, }), ], @@ -1034,8 +1193,9 @@ export default class AgencyContract { /** * 餐费 */ - createTable_R(use_year, dataList, agencyExtras) { + createTable_R(use_year, dataList) { const { tables, SSRange, PSRange } = splitTable_R(use_year, dataList, false); + const defaultUnit = '0'; // console.log('RRRRRR', tables); const tableS = tables.reduce((acc, { cols, data }) => { @@ -1101,7 +1261,21 @@ export default class AgencyContract { verticalAlign: AlignmentType.CENTER, children: [ new Paragraph({ - text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + // text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + }), + ...(row?.[formatGroupSize(...ss)]?.adult_cost && row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + break: 1, + }), + ] + : []), + ], alignment: AlignmentType.CENTER, }), ], @@ -1121,6 +1295,131 @@ export default class AgencyContract { return tableS } + /** + * 附加项目 + */ + createTable_8(use_year, dataList) { + const { tables, SSRange, PSRange, } = splitTable_8(use_year, dataList, false); + const defaultUnit = '1' + const showRangeCol = PSRange.length > 0; + + const tableS = tables.reduce((acc, { cols, data }) => { + const subTable = new Table({ + borders: tableBorderNone, + width: { + size: 100, + type: WidthType.PERCENTAGE, + }, + rows: [ + new TableRow({ + children: [ + this.createTableHeader('附加项目', 20), + ...(showRangeCol ? [this.createTableHeader('', 15)] : []), + this.createTableHeader([...SSRange], 65, { columnSpan: cols.length }), + ], + }), + //人数区间行 + new TableRow({ + children: [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: '' })], + }), + ...(showRangeCol ? [new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: '时段', alignment: 'center' })], + })]: []), + ...cols.map((ss) => { + return new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + width: { size: 2000, type: WidthType.DXA }, + children: [ + new Paragraph({ + text: formatGroupSize(...ss, true), + alignment: AlignmentType.CENTER, + }), + ], + }); + }), + ], + }), + //动态生成数据行 + ...data.map( + (row, ri) => + new TableRow({ + children: [ + ...(row.rowSpan > 0 + ? [ + row.info?.isCityRow + ? this.createTableHeader(row.info?.product_title || '', 20) + : new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [new Paragraph({ text: row.info?.product_title || '' })], + rowSpan: row.rowSpan, + }), + ] + : []), + ...(showRangeCol + ? [ + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + ...(row.quote_season === 'SS' + ? row.rowSpan > 1 + ? ['平季', '(除特殊时段外)'].map((str) => new Paragraph({ text: str, alignment: AlignmentType.LEFT })) + : [new Paragraph({ text: '' })] + : ['特殊时段', `${row.use_dates_start.replace(`${use_year}.`, '')}~${row.use_dates_end.replace(`${use_year}.`, '')}`].map( + (str) => new Paragraph({ text: str, alignment: AlignmentType.LEFT }) + )), + ], + }), + ] + : []), + ...cols.map( + (ss) => + new TableCell({ + borders: tableBorderOne, + verticalAlign: AlignmentType.CENTER, + children: [ + new Paragraph({ + // text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + children: [ + new TextRun({ + text: `${row?.[formatGroupSize(...ss)]?.adult_cost ?? ''}`, + }), + ...(row?.[formatGroupSize(...ss)]?.adult_cost && row?.[formatGroupSize(...ss)]?.unit_id !== defaultUnit + ? [ + new TextRun({ + // text: `/${row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + text: `/${unitMap[row?.[formatGroupSize(...ss)]?.unit_id] || row?.[formatGroupSize(...ss)]?.unit_name || ''}`, + break: 1, + }), + ] + : []), + ], + alignment: AlignmentType.CENTER, + }), + ], + }) + ), + ], + }) + ), + //备注行 + this.createTable_Memo(1 + cols.length + (showRangeCol ? 1 : 0), (this.#remarkList?.['8']?.Memo || '').split(`\n`)), + ], + }); + acc.push(subTable) + acc.push(new Paragraph({ text: `` })) + return acc + }, []) + return tableS + } createTable_Memo(columnSpan, remarkContent = []) { return new TableRow({ children: [ diff --git a/src/views/products/Print/AgencyPreview.jsx b/src/views/products/Print/AgencyPreview.jsx index 294df6b..78d5771 100644 --- a/src/views/products/Print/AgencyPreview.jsx +++ b/src/views/products/Print/AgencyPreview.jsx @@ -3,7 +3,7 @@ import { useParams, Link } from 'react-router-dom'; import { Button, Drawer, Card, Table } from 'antd'; import { useTranslation } from 'react-i18next'; import useProductsStore, { getAgencyAllExtrasAction } from '@/stores/Products/Index'; -import { useProductsTypes, formatGroupSize } from '@/hooks/useProductsSets'; +import { useProductsTypes, formatGroupSize, useProductsTypesMapVal } from '@/hooks/useProductsSets'; import { chunkBy, splitTable_6, splitTable_7, splitTable_8, splitTable_B, splitTable_D, splitTable_J, splitTable_Q, splitTable_R } from '@/hooks/useProductsQuotationFormat'; import { groupBy, isNotEmpty } from '@/utils/commons'; import useAuthStore from '@/stores/Auth'; @@ -20,6 +20,8 @@ const AgencyPreview = ({ params, ...props }) => { const [agencyProducts] = useProductsStore((state) => [state.agencyProducts]); const [setEditingProduct] = useProductsStore((state) => [state.setEditingProduct]); + const productsTypesMapVal = useProductsTypesMapVal(); + const [previewMode, setPreviewMode] = useState(false); const [tables, setTables] = useState([]); const [extras, setExtras] = useState([]); @@ -121,14 +123,68 @@ const AgencyPreview = ({ params, ...props }) => { render: (_, r) =>