feat(pl): add blank HTML renderer for subpack slips
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3ec188666c
commit
dfa033da02
1 file changed
+26
-11
@@ -2098,29 +2098,31 @@ function normalizeSubpackSlipSideLabelsPlaceholder(html: string): string {
|
||||
export function replaceSubpackSlipPlaceholders(
|
||||
htmlContent: string,
|
||||
plan: Plan,
|
||||
ctx?: SubpackSlipRenderContext
|
||||
ctx?: SubpackSlipRenderContext,
|
||||
options?: { blank?: boolean }
|
||||
): string {
|
||||
if (!htmlContent || !plan) return htmlContent
|
||||
|
||||
const orderDate = ctx?.orderDate || formatDateIso()
|
||||
const orderUser = ctx?.orderUser || ''
|
||||
const preparerUser = ctx?.preparerUser || orderUser
|
||||
const blank = Boolean(options?.blank)
|
||||
const orderDate = blank ? '' : ctx?.orderDate || formatDateIso()
|
||||
const orderUser = blank ? '' : ctx?.orderUser || ''
|
||||
const preparerUser = blank ? '' : ctx?.preparerUser || orderUser
|
||||
|
||||
const replacements: Record<string, string> = {
|
||||
'{{companyName}}': SUBPACK_SLIP_DEFAULTS.companyName,
|
||||
'{{subpackSlipNo}}': ctx?.subpackSlipNo || '',
|
||||
'{{subpackSlipNo}}': blank ? '' : ctx?.subpackSlipNo || '',
|
||||
'{{orderDate}}': orderDate,
|
||||
'{{deliveryDate}}': '',
|
||||
'{{orderUser}}': orderUser,
|
||||
'{{preparerUser}}': preparerUser,
|
||||
'{{handlerName}}': '',
|
||||
'{{receivingUnit}}': orderDate,
|
||||
'{{receivingUnit}}': blank ? '' : orderDate,
|
||||
'{{planNo}}': '',
|
||||
'{{receiveContact}}': orderUser,
|
||||
'{{receiveContact}}': blank ? '' : orderUser,
|
||||
'{{driverInfo}}': '',
|
||||
'{{planDateChinese}}': '',
|
||||
'{{productTable}}': buildProductRows(plan.products, ctx),
|
||||
'{{remark}}': formatRemarkForSlipHtml(plan.remark),
|
||||
'{{productTable}}': buildProductRows(blank ? [] : plan.products, ctx),
|
||||
'{{remark}}': blank ? '' : formatRemarkForSlipHtml(plan.remark),
|
||||
'{{remarkExtra}}': '',
|
||||
'{{companyAddress}}': '',
|
||||
'{{companyPhone}}': '',
|
||||
@@ -2164,14 +2166,14 @@ export function replaceSubpackSlipPlaceholders(
|
||||
result = result.split(placeholder).join(value)
|
||||
}
|
||||
|
||||
if (ctx?.subpackSlipNo) {
|
||||
if (!blank && ctx?.subpackSlipNo) {
|
||||
result = result.replace(
|
||||
/(<span class="subpack-slip-slip-no-display"[^>]*>)[\s\S]*?( <\/span>)/g,
|
||||
`$1${ctx.subpackSlipNo}$2`
|
||||
)
|
||||
}
|
||||
|
||||
if (preparerUser) {
|
||||
if (!blank && preparerUser) {
|
||||
result = result.replace(
|
||||
/(<span class="subpack-slip-sign-label">制单人:<\/span>\s*<span class="subpack-slip-sign-value"[^>]*>)[\s\S]*?(<\/span>)/g,
|
||||
`$1${preparerUser}$2`
|
||||
@@ -2181,6 +2183,19 @@ export function replaceSubpackSlipPlaceholders(
|
||||
return result
|
||||
}
|
||||
|
||||
/** 空白分装单 HTML:默认模板 + 业务字段全空(含分装单号)+ 最小空产品行 */
|
||||
export function renderBlankSubpackSlipHtml(): string {
|
||||
const blankPlan = {
|
||||
id: '',
|
||||
planNo: '',
|
||||
products: [],
|
||||
customerName: '',
|
||||
remark: ''
|
||||
} as Plan
|
||||
const html = generateSubpackSlipTemplate(blankPlan)
|
||||
return replaceSubpackSlipPlaceholders(html, blankPlan, undefined, { blank: true })
|
||||
}
|
||||
|
||||
/** 保存模板前:将动态字段还原为占位符 */
|
||||
export function restoreSubpackSlipPlaceholders(template: string, plan: Plan): string {
|
||||
let result = template
|
||||
|
||||
Reference in new issue
Block a user