提交
This commit is contained in:
1 parent
506cc7991a
commit
1dfcc66d2c
269 files changed
+1413333
-55990
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type { Plan, PlanProduct } from '@/api/pl'
|
||||
import type { SlipPlanProduct } from '@/utils/pl-batch-print'
|
||||
import { formatRemarkForSlipHtml } from '@/utils/pl-batch-print'
|
||||
import { getPlSlipSealSrc, type PlSlipCompanyKey } from '@/utils/pl-slip-company'
|
||||
import { applyPdfStableTableCellBorders } from '@/utils/pl-slip-pdf-render'
|
||||
|
||||
/** 送(提)货单打印默认公司信息(可在富文本中修改) */
|
||||
@@ -597,9 +598,9 @@ export const DELIVERY_SLIP_PRINT_CSS = `
|
||||
|
||||
export const DELIVERY_SLIP_STYLE_BLOCK = `<style type="text/css">${DELIVERY_SLIP_PRINT_CSS}</style>`
|
||||
|
||||
/** 生成公司印章 HTML(地址/电话单元格右上角) */
|
||||
export function buildDeliverySlipCompanySealHtml(): string {
|
||||
return `<img class="delivery-slip-seal-img" src="${DELIVERY_SLIP_SEAL_IMAGE_SRC}" alt="印章" style="${DELIVERY_SLIP_SEAL_IMAGE_STYLE}" />`
|
||||
/** 生成公司印章 HTML(地址/电话单元格右上角;云栋用合同同款 yd.png) */
|
||||
export function buildDeliverySlipCompanySealHtml(companyKey: PlSlipCompanyKey = 'shanxia'): string {
|
||||
return `<img class="delivery-slip-seal-img" src="${getPlSlipSealSrc(companyKey)}" alt="印章" style="${DELIVERY_SLIP_SEAL_IMAGE_STYLE}" />`
|
||||
}
|
||||
|
||||
const SEAL_BLOCK = `<div class="delivery-slip-seal-block" style="position:relative;padding:0;${FONT_BODY}${SEAL_BLOCK_LINE_STYLE}">
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/** 运输单据打印:抬头公司(山峡 / 云栋)切换 */
|
||||
|
||||
import ydSealImg from '@/assets/images/yd.png'
|
||||
|
||||
export const PL_SLIP_COMPANY_SHANXIA = '安庆市山峡化工有限公司'
|
||||
export const PL_SLIP_COMPANY_YUNDONG = '安徽云栋化工有限公司'
|
||||
|
||||
export type PlSlipCompanyKey = 'shanxia' | 'yundong'
|
||||
|
||||
export const PL_SLIP_COMPANY_OPTIONS: { label: string; value: PlSlipCompanyKey }[] = [
|
||||
{ label: PL_SLIP_COMPANY_SHANXIA, value: 'shanxia' },
|
||||
{ label: PL_SLIP_COMPANY_YUNDONG, value: 'yundong' }
|
||||
]
|
||||
|
||||
/** 山峡红章(与现有单据 public 路径一致) */
|
||||
export const PL_SLIP_SHANXIA_SEAL_SRC = '/sxshzyz.png'
|
||||
/** 云栋红章(与合同管理 yd.png 一致) */
|
||||
export const PL_SLIP_YUNDONG_SEAL_SRC = ydSealImg as string
|
||||
|
||||
const TITLE_HEADING_SELECTOR =
|
||||
'.inbound-slip-title-heading, .delivery-slip-title-heading, .subpack-slip-title-heading'
|
||||
|
||||
export function getPlSlipCompanyName(key: PlSlipCompanyKey): string {
|
||||
return key === 'yundong' ? PL_SLIP_COMPANY_YUNDONG : PL_SLIP_COMPANY_SHANXIA
|
||||
}
|
||||
|
||||
export function getPlSlipSealSrc(key: PlSlipCompanyKey): string {
|
||||
return key === 'yundong' ? PL_SLIP_YUNDONG_SEAL_SRC : PL_SLIP_SHANXIA_SEAL_SRC
|
||||
}
|
||||
|
||||
function isSlipLogoImg(img: HTMLImageElement): boolean {
|
||||
const alt = (img.getAttribute('alt') || '').trim()
|
||||
if (alt === '印章') return false
|
||||
if (alt === 'logo') return true
|
||||
const src = img.getAttribute('src') || ''
|
||||
if (src.includes('watermask')) return false
|
||||
return src.includes('logo.gif') || /\/logo(\.|$)/.test(src) || src.includes('/logo')
|
||||
}
|
||||
|
||||
function isCompanyTitleText(text: string): boolean {
|
||||
const normalized = text.replace(/\u00a0/g, ' ').replace(/\s+/g, '').trim()
|
||||
if (!normalized) return false
|
||||
if (normalized.includes('入库') || normalized.includes('货单') || normalized.includes('分装')) {
|
||||
return false
|
||||
}
|
||||
return (
|
||||
normalized === PL_SLIP_COMPANY_SHANXIA.replace(/\s+/g, '') ||
|
||||
normalized === PL_SLIP_COMPANY_YUNDONG.replace(/\s+/g, '') ||
|
||||
normalized.includes('山峡化工') ||
|
||||
normalized.includes('云栋化工')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按抬头公司更新单据 HTML:标题公司名、山峡 logo 显隐;可选替换红章图。
|
||||
* 仅本次弹窗预览有效,不改后端默认模板生成逻辑。
|
||||
*/
|
||||
export function applyPlSlipCompanyToHtml(
|
||||
html: string,
|
||||
companyKey: PlSlipCompanyKey,
|
||||
options?: { swapSeal?: boolean }
|
||||
): string {
|
||||
if (!html || typeof document === 'undefined') return html
|
||||
|
||||
const wrap = document.createElement('div')
|
||||
wrap.innerHTML = html
|
||||
const companyName = getPlSlipCompanyName(companyKey)
|
||||
const isYundong = companyKey === 'yundong'
|
||||
|
||||
wrap.querySelectorAll('img').forEach((img) => {
|
||||
if (!isSlipLogoImg(img as HTMLImageElement)) return
|
||||
;(img as HTMLImageElement).style.display = isYundong ? 'none' : ''
|
||||
})
|
||||
|
||||
wrap.querySelectorAll(TITLE_HEADING_SELECTOR).forEach((el) => {
|
||||
const text = (el.textContent || '').trim()
|
||||
if (!isCompanyTitleText(text)) return
|
||||
el.textContent = companyName
|
||||
})
|
||||
|
||||
if (options?.swapSeal) {
|
||||
const sealSrc = getPlSlipSealSrc(companyKey)
|
||||
wrap.querySelectorAll('img[alt="印章"]').forEach((img) => {
|
||||
img.setAttribute('src', sealSrc)
|
||||
})
|
||||
}
|
||||
|
||||
return wrap.innerHTML
|
||||
}
|
||||
Reference in new issue
Block a user