This commit is contained in:
zlwu committed 2026-08-17 15:25:28 +08:00
1 parent 6b2147aa46
commit 8558d9439e
31 files changed
+596719 -4174

No files matched your search

@@ -1843,6 +1843,8 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
const subtotal = parseFloat(String(product.subtotal || 0));
const taxAmount = parseFloat(String(product.taxAmount || 0));
const beforeTax = subtotal - taxAmount;
const taxRateNum = Number(product.taxRate);
const taxRateText = Number.isFinite(taxRateNum) ? `${taxRateNum}%` : '0%';
const pricingCells = isFrameworkContract
? '<td colspan="4" style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">随行就市</td>'
@@ -1859,13 +1861,14 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${formatBrandForPrint(product.brandMode, product.brandName)}</td>
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${getUnitLabel(product.unit)}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; overflow: hidden; word-break: break-all;">${product.quantity || 0}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${taxRateText}</td>
${pricingCells}
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${product.packageSpec || ''}</td>
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${product.remark || ''}</td>
</tr>`;
})
.join('') ||
'<tr><td colspan="11" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">暂无产品信息</td></tr>';
'<tr><td colspan="12" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">暂无产品信息</td></tr>';
// 定义替换映射表
const getSettlementClauseContent = (): string =>
@@ -1931,9 +1934,17 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
<th style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 8%;">品牌</th>`
)
}
// 旧模板表头无「税率」时,在「用量」后插入
if (!/用量(?:(吨))?<\/th>[\s\S]{0,200}?税率<\/th>/i.test(result)) {
result = result.replace(
/(<th[^>]*>\s*用量(?:(吨))?\s*<\/th>)/i,
`$1
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 5%;">税率</th>`
)
}
// 合计区(11 列):第 1 行左右对半运费/桶押金;第 2 行合计;第 3 行提示
// 合计区(12 列):第 1 行左右对半运费/桶押金;第 2 行合计;第 3 行提示
const freightRaw = Number(contractData.freight);
const freightAmount = Number.isFinite(freightRaw) && freightRaw > 0 ? freightRaw : 0;
const depositRaw = Number(contractData.barrelDeposit);
@@ -1953,14 +1964,14 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
<td colspan="2" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">运费(元)</td>
<td colspan="4" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${freightText}</td>
<td colspan="2" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">桶押金(元)</td>
<td colspan="3" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${barrelDepositText}</td>
<td colspan="4" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${barrelDepositText}</td>
</tr>
<tr style="background-color: #fff; font-weight: bold;">
<td colspan="2" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">合计(人民币)</td>
<td colspan="9" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${totalWithExtrasText}</td>
<td colspan="10" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${totalWithExtrasText}</td>
</tr>
<tr>
<td colspan="11" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 11px; background-color: #fff;">
<td colspan="12" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 11px; background-color: #fff;">
${tipRowText}
</td>
</tr>
@@ -2234,6 +2245,8 @@ const generateContractTemplate = (contractData: ContractVO | undefined): string
const subtotal = parseFloat(String(product.subtotal || 0));
const taxAmount = parseFloat(String(product.taxAmount || 0));
const beforeTax = subtotal - taxAmount;
const taxRateNum = Number(product.taxRate);
const taxRateText = Number.isFinite(taxRateNum) ? `${taxRateNum}%` : '0%';
return `
<tr>
@@ -2242,6 +2255,7 @@ const generateContractTemplate = (contractData: ContractVO | undefined): string
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${formatBrandForPrint(product.brandMode, product.brandName)}</td>
<td style="padding: 4px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${getUnitLabel(product.unit)}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; overflow: hidden; word-break: break-all;">${product.quantity || 0}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px;">${taxRateText}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; overflow: hidden; word-break: break-all;">${formatNumber(product.price)}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: right; font-size: 12px; overflow: hidden; word-break: break-all;">${formatNumber(beforeTax)}</td>
<td style="padding: 4px 3px; border: 0.3px solid #000; text-align: right; font-size: 12px; overflow: hidden; word-break: break-all;">${formatNumber(taxAmount)}</td>
@@ -2251,7 +2265,7 @@ const generateContractTemplate = (contractData: ContractVO | undefined): string
</tr>`;
})
.join('') ||
'<tr><td colspan="11" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">暂无产品信息</td></tr>';
'<tr><td colspan="12" style="padding: 5px 6px; border: 0.3px solid #000; text-align: center; font-size: 12px;">暂无产品信息</td></tr>';
return `
<div style="width: 210mm; margin: 0 auto; padding: 0 15mm 20mm 15mm; font-family: '宋体', SimSun, serif; line-height: 1.6; box-sizing: border-box;">
@@ -2295,13 +2309,14 @@ const generateContractTemplate = (contractData: ContractVO | undefined): string
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 6%;">规格</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 6%;">品牌</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 5%;">单位</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 10%;">用量</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 7%;">用量</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 5%;">税率</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 12%;">含税单价(元)</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 12%;">未含税金额(元)</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 10%;">税费(元)</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 12%;">含税金额(元)</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 7%;">包装规格</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 10%;">备注</th>
<th style="padding: 5px 3px; border: 0.3px solid #000; text-align: center; font-size: 12px; width: 8%;">备注</th>
</tr>
</thead>
<tbody>
@@ -2453,9 +2468,9 @@ const handleSaveTemplate = async () => {
);
const totalRowHtml = totalRowMatch ? totalRowMatch[0] : '';
// 3. 提取提示行(兼容一票制 / 客户自提文案,以及 colspan 10/11)
// 3. 提取提示行(兼容一票制 / 客户自提文案,以及 colspan 10/11/12)
const tipRowMatch = templateWithPlaceholders.match(
/<tr>[\s\S]*?<td colspan="1[01]"[\s\S]*?结算以实际到货吨位为准[\s\S]*?<\/td>[\s\S]*?<\/tr>/
/<tr>[\s\S]*?<td colspan="1[012]"[\s\S]*?结算以实际到货吨位为准[\s\S]*?<\/td>[\s\S]*?<\/tr>/
);
const tipRowHtml = tipRowMatch ? tipRowMatch[0] : '';
@@ -2480,7 +2495,7 @@ const handleSaveTemplate = async () => {
// 替换提示行(兼容旧一票制与客户自提提示)
if (tipRowHtml) {
const tipRowPattern =
/<tr>[\s\S]*?<td colspan="1[01]"[\s\S]*?>含税、(?:含运费|客户自提)[\s\S]*?<\/tr>/;
/<tr>[\s\S]*?<td colspan="1[012]"[\s\S]*?>含税、(?:含运费|客户自提)[\s\S]*?<\/tr>/;
if (tipRowPattern.test(finalTemplate)) {
finalTemplate = finalTemplate.replace(tipRowPattern, tipRowHtml);
}