diff --git a/App.jsx b/App.jsx
index 9097419..c8216dc 100644
--- a/App.jsx
+++ b/App.jsx
@@ -2253,6 +2253,9 @@ const Styles = () => (
.cd-ship-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) auto auto; align-items: center; }
.cd-hs-row { grid-template-columns: minmax(0, 1fr) minmax(0, 2.6fr) auto; }
.cd-req { color: #d92d20; }
+ .cd-show-miss .input:invalid, .cd-show-miss .textarea:invalid { border-color: #f04438 !important; background: #fff6f5; }
+ .cd-miss-chip { border: 1px solid #fda29b; background: #fef3f2; color: #b42318; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 3px 10px; cursor: pointer; }
+ .cd-ok-chip { background: #ecfdf3; color: #067647; border: 1px solid #abefc6; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 3px 10px; }
.cd-missing { border-color: #f04438 !important; background: #fff6f5; }
.cd-prev-box { overflow: hidden; display: flex; justify-content: center; }
.cd-prev-box iframe { border: 0; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); transform-origin: top center; flex: none; }
@@ -6055,6 +6058,24 @@ const CD_PREPARER = { name: 'Mike', phone: '15201273157' };
const cdEsc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])).replace(/\n/g, '
');
const cdQty2 = (it) => (String(it.qty2 ?? '').trim() || String(it.qty ?? '').trim()); // 发票数量没单独填就等于成交数量
const cdFileBase = (d) => `预报关单_${String(d.contractNo || d.date || '').replace(/[\\/:*?"<>|\s]+/g, '_')}`;
+// 必填检查:除了"标记唛码及备注"都要填(发票数量不填按成交数量,最终目的国不填按贸易国)
+function cdMissing(d, defs, customers) {
+ const m = []; const e = (v) => !String(v ?? '').trim();
+ const head = [['境内发货人', d.shipper], ['境内发货人的统一社会信用代码', d.shipperCode], ['境外收货人(关联客户)', d.customerId && customers.some((c) => c.id === d.customerId) ? d.customerId : ''],
+ ['合同协议号', d.contractNo], ['贸易国(地区)', d.tradeCountry], ['成交方式', d.terms], ['件数', d.packages], ['毛重', d.grossWeight], ['净重', d.netWeight], ['日期', d.date]];
+ if (!d.producerSame) head.push(['生产销售单位', d.producer], ['生产销售单位的统一社会信用代码', d.producerCode]);
+ for (const [k, v] of head) if (e(v)) m.push(k);
+ const items = (d.items || []).filter((it) => it.name || it.hsCode || it.qty || it.spec || it.unitPrice);
+ if (!items.length) m.push('商品明细(至少一项)');
+ (d.items || []).forEach((it, i) => {
+ if (!items.includes(it)) return;
+ const p = `第 ${i + 1} 项:`;
+ for (const [k, v] of [['商品编号(HS)', it.hsCode], ['商品名称', it.name], ['规格型号(申报要素)', it.spec], ['成交数量', it.qty], ['成交单位', it.unit], ['小计净重', it.kg], ['发票单位', it.unit2], ['单价', it.unitPrice], ['币制', it.currency], ['原产国', it.origin], ['最终目的国', it.dest || d.tradeCountry], ['境内货源地', it.source]]) if (e(v)) m.push(p + k);
+ const def = cdElemDef(defs, it.hsCode);
+ if (def && it.spec) { const vals = cdSplit(it.spec); def.elements.forEach((el, k) => { if (e(vals[k])) m.push(`${p}申报要素"${el.name}"`); }); }
+ });
+ return m;
+}
// 整理成一份结构化数据,HTML 和 Excel 都从这里取
function cdDocData(d, customers, defs) {
const cust = customers.find((c) => c.id === d.customerId);
@@ -6085,33 +6106,38 @@ function cdDocData(d, customers, defs) {
return { head, items, totals, made, notes: d.notes };
}
const CD_DOC_CSS = `
- .cdx{font-family:"Microsoft YaHei","PingFang SC","Noto Sans SC",sans-serif;font-size:11px;color:#111;background:#fff;width:760px;margin:0 auto;padding:18px 16px}
+ .cdx{font-family:"Microsoft YaHei","PingFang SC","Noto Sans SC",sans-serif;font-size:11px;color:#1d2939;background:#fff;width:760px;margin:0 auto;padding:18px 16px}
.cdx *{box-sizing:border-box}
- .cdx h1{text-align:center;font-size:20px;margin:0 0 8px;letter-spacing:4px}
- .cdx .made{background:#fff3b0;border:1.5px solid #f0b400;color:#7a4b00;font-weight:700;font-size:12.5px;text-align:center;padding:7px 10px;border-radius:4px;margin-bottom:10px}
- .cdx table{width:100%;border-collapse:collapse}.cdx td,.cdx th{border:1px solid #444;padding:3px 5px;vertical-align:top}
- .cdx .l{font-size:9.5px;color:#444}.cdx .l span{color:#888}.cdx .v{font-size:12px;font-weight:600;min-height:15px;word-break:break-all}
- .cdx th{background:#eee;font-size:10.5px}.cdx .c{text-align:center}.cdx .r{text-align:right;white-space:nowrap}.cdx .m{font-family:Consolas,monospace}
- .cdx .spec{font-size:10.5px;color:#333;word-break:break-all}.cdx .tot{margin-top:6px;text-align:right;font-weight:700}
- .cdx h2{font-size:13px;margin:16px 0 6px;padding-left:7px;border-left:3px solid #1f4e8c}
- .cdx .el{margin-bottom:8px;page-break-inside:avoid}.cdx .el-h{background:#eef3fa;font-weight:700}
- .cdx .el td.k{width:42%;color:#333;background:#fafafa}.cdx .el td.e{font-weight:600}
- .cdx .note{margin-top:10px;font-size:10px;color:#555}
+ .cdx h1{text-align:center;font-size:21px;margin:0 0 8px;letter-spacing:6px;color:#1f4e8c}
+ .cdx h1:after{content:"";display:block;width:60px;height:3px;background:#2e7dd7;margin:6px auto 0;border-radius:2px}
+ .cdx .made{background:#fff4c2;border:1px solid #f5c542;color:#7a4b00;font-weight:700;font-size:12.5px;text-align:center;padding:7px 10px;border-radius:5px;margin-bottom:10px}
+ .cdx table{width:100%;border-collapse:collapse}.cdx td,.cdx th{border:0.5px solid #b9c6d8;padding:3px 5px;vertical-align:top;font-size:11px;line-height:1.45}
+ .cdx .hd td{background:#f5f8fd}
+ .cdx .l{font-size:9.5px;color:#4a6a96}.cdx .l span{color:#8aa0bd}.cdx .v{font-size:12px;font-weight:600;min-height:15px;word-break:break-all;color:#0f2a4f}
+ .cdx th{background:#2b5f9e;color:#fff;font-size:10.5px;font-weight:600;border-color:#2b5f9e}
+ .cdx .it tbody tr:nth-child(even) td{background:#f7f9fc}
+ .cdx .c{text-align:center}.cdx .r{text-align:right;white-space:nowrap}.cdx .m{font-family:Consolas,monospace;color:#1f4e8c;font-weight:600}
+ .cdx .spec{font-size:10.5px;color:#475467;word-break:break-all}.cdx .cur{color:#b54708;font-weight:600}
+ .cdx .tot{margin-top:6px;text-align:right}.cdx .tot span{display:inline-block;background:#e8f1fd;color:#1f4e8c;font-weight:700;padding:3px 10px;border-radius:10px;margin-left:6px}
+ .cdx h2{font-size:13px;margin:16px 0 6px;padding-left:7px;border-left:3px solid #2e7dd7;color:#1f4e8c}
+ .cdx .el{margin-bottom:8px;page-break-inside:avoid}.cdx .el-h td{background:#e8f1fd;font-weight:700;color:#1f4e8c}
+ .cdx .el td.k{width:42%;color:#4a6a96;background:#fafbfd}.cdx .el td.e{font-weight:600;color:#0f2a4f}
+ .cdx .note{margin-top:10px;font-size:10px;color:#667085}
.cdx tr{page-break-inside:avoid}`;
function cdDocBody(x) {
const cell = ([label, code, val]) => `
${cdEsc(label)}${code ? ` (${cdEsc(code)})` : ''} ${cdEsc(val) || ' '} | `;
const rows = x.items.map((r) => `| ${r.no} | ${cdEsc(r.it.hsCode)} |
${cdEsc(r.it.name)} ${cdEsc(r.it.spec)} |
- ${r.qtyLines.map(cdEsc).join(' ')} | ${r.priceLines.map(cdEsc).join(' ')} |
+ ${r.qtyLines.map(cdEsc).join(' ')} | ${cdEsc(r.priceLines[0])} ${cdEsc(r.priceLines[1])} ${cdEsc(r.priceLines[2])} |
${cdEsc(r.it.origin)} | ${cdEsc(r.dest)} | ${cdEsc(r.it.source)} |
`).join('');
const els = x.items.filter((r) => r.elems.length).map((r) => `| 项号 ${r.no} ${cdEsc(r.it.hsCode)} ${cdEsc(r.it.name)} |
${r.elems.map(([k, v]) => `| ${cdEsc(k)} | ${cdEsc(v) || ' '} |
`).join('')}
`).join('');
return `预报关单
${cdEsc(x.made)}
-
${x.head.map((r) => `${r.map(cell).join('')}
`).join('')}
+ ${x.head.map((r) => `${r.map(cell).join('')}
`).join('')}
${x.notes ? `标记唛码及备注 ${cdEsc(x.notes)} |
` : ''}
- | 项号 | 商品编号 | 商品名称及规格型号 | 数量及单位 | 单价/总价/币制 | 原产国(地区) | 最终目的国(地区) | 境内货源地 |
+ | 项号 | 商品编号 | 商品名称及规格型号 | 数量及单位 | 单价/总价/币制 | 原产国(地区) | 最终目的国(地区) | 境内货源地 |
${rows || '| 还没有商品 |
'}
- ${x.totals ? `${cdEsc(x.totals)}
` : ''}
+ ${x.totals ? `${x.totals.split(' ').map((t) => `${cdEsc(t)}`).join('')}
` : ''}
${els ? `申报要素明细
${els}` : ''}
本预报关单由客户档案系统生成,供与报关行核对,以海关正式报关单为准。
`;
}
@@ -6122,12 +6148,12 @@ async function downloadCustomsPdf(d, customers, defs) {
const html2pdf = mod.default || mod;
const host = document.createElement('div');
host.style.cssText = 'position:fixed;left:-10000px;top:0;background:#fff';
- host.innerHTML = `${cdDocBody(cdDocData(d, customers, defs))}`;
+ host.innerHTML = `${cdDocBody(cdDocData(d, customers, defs))}`;
document.body.appendChild(host);
try {
await html2pdf().set({
margin: [8, 8, 8, 8], filename: `${cdFileBase(d)}.pdf`,
- image: { type: 'jpeg', quality: 0.95 }, html2canvas: { scale: 2, backgroundColor: '#ffffff' },
+ image: { type: 'jpeg', quality: 0.95 }, html2canvas: { scale: 2, backgroundColor: '#ffffff', windowWidth: 760, scrollX: 0, scrollY: 0 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, pagebreak: { mode: ['css'], avoid: ['tr', '.el'] },
}).from(host.querySelector('.cdx')).save();
} finally { host.remove(); }
@@ -6174,14 +6200,14 @@ function downloadCustomsXlsx(d, customers, defs) {
put([]);
put(['项号', '商品编号', '商品名称及规格型号', '数量及单位', '单价/总价/币制', '原产国(地区)', '最终目的国(地区)', '境内货源地'].map((v, i) => [COLS[i], v, 3]), 30);
for (const it of x.items) {
- put([['A', it.no, 7], ['B', it.it.hsCode, 7], ['C', `${it.it.name}\n${it.it.spec || ''}`, 6], ['D', it.qtyLines.join('\n'), 8], ['E', it.priceLines.join('\n'), 8], ['F', it.it.origin, 7], ['G', it.dest, 7], ['H', it.it.source, 7]], 48);
+ put([['A', it.no, 7], ['B', it.it.hsCode, 7], ['C', `${it.it.name}\n${it.it.spec || ''}`, 6], ['D', it.qtyLines.join('\n'), 8], ['E', it.priceLines.join('\n'), 8], ['F', it.it.origin, 7], ['G', it.dest, 7], ['H', it.it.source, 7]], Math.max(48, (2 + Math.ceil(String(it.it.spec || '').length / 26)) * 14));
}
if (x.totals) { put([['A', x.totals, 9]], 20); merge('A', 'H'); }
const withEl = x.items.filter((it) => it.elems.length);
if (withEl.length) {
put([]); put([['A', '申报要素明细', 10]], 22); merge('A', 'H');
for (const it of withEl) {
- put([['A', `项号 ${it.no} ${it.it.hsCode} ${it.it.name}`, 3]], 20); merge('A', 'H');
+ put([['A', `项号 ${it.no} ${it.it.hsCode} ${it.it.name}`, 14]], 20); merge('A', 'H');
for (const [k, v] of it.elems) { put([['A', k, 11], ['D', v, 12]], 18); merge('A', 'C'); merge('D', 'H'); }
}
}
@@ -6209,19 +6235,19 @@ function downloadCustomsXlsx(d, customers, defs) {
${widths.map((w, i) => ``).join('')}
${sheetRows}${merges.length ? `${merges.map((m) => ``).join('')}` : ''}
`;
- const B = '';
+ const B = '';
const xf = (font, fill, border, h, v, wrap) => ``;
const styles = `
-
-
-${B}
+
+
+${B}
-${[
- xf(0, 0, 0), xf(1, 0, 0, 'center', 'center'), xf(2, 2, 2, 'center', 'center', 1), xf(3, 3, 1, 'center', 'center', 1),
- xf(4, 4, 1, 'left', 'top', 1), xf(3, 0, 1, 'left', 'top', 1), xf(0, 0, 1, 'left', 'top', 1), xf(0, 0, 1, 'center', 'top', 1),
- xf(0, 0, 1, 'right', 'top', 1), xf(3, 0, 0, 'right', 'center'), xf(5, 0, 0, 'left', 'center'), xf(0, 4, 1, 'left', 'center', 1),
- xf(3, 0, 1, 'left', 'center', 1), xf(4, 0, 0, 'left', 'top', 1),
+${[
+ xf(0, 0, 0), xf(5, 0, 0, 'center', 'center'), xf(2, 2, 2, 'center', 'center', 1), xf(6, 5, 1, 'center', 'center', 1),
+ xf(4, 6, 1, 'left', 'top', 1), xf(3, 0, 1, 'left', 'top', 1), xf(0, 0, 1, 'left', 'top', 1), xf(0, 0, 1, 'center', 'top', 1),
+ xf(0, 0, 1, 'right', 'top', 1), xf(3, 0, 0, 'right', 'center'), xf(5, 0, 0, 'left', 'center'), xf(4, 6, 1, 'left', 'center', 1),
+ xf(3, 0, 1, 'left', 'center', 1), xf(4, 0, 0, 'left', 'top', 1), xf(5, 7, 1, 'left', 'center'),
].join('')}
`;
const blob = cdZip([
@@ -6311,8 +6337,8 @@ function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, set
{d.contractNo || '(无合同协议号)'} · {d.shipper || '(未填境内发货人)'}{d.tradeCountry ? ` → ${d.tradeCountry}` : ''}
{d.date}{custName(d.customerId) ? ` · ${custName(d.customerId)}` : ''} · {n} 项商品{d.packages ? ` · ${d.packages} 件` : ''}{d.grossWeight ? ` · 毛重 ${d.grossWeight} kg` : ''}{Object.entries(s.by).map(([c, v]) => ` · ${cdFmt(v)} ${cdCurLabel(c)}`).join('')}
-
-
+
+
@@ -6333,11 +6359,14 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
const moveItem = (it, dir) => update((x) => { const items = [...x.items]; const i = items.findIndex((y) => y.id === it.id), j = i + dir; if (j < 0 || j >= items.length) return {}; [items[i], items[j]] = [items[j], items[i]]; return { items }; });
const s = cdSums(d);
const [pdfBusy, setPdfBusy] = useState(false);
- // 发票单位必填:缺的项提醒一下(数量没单独填的按成交数量算)
+ // 除了"标记唛码及备注",其余都必填:缺了就不能下载,并把空着的格子标红
+ const [showMiss, setShowMiss] = useState(false);
+ const missing = cdMissing(d, hsDefs, customers);
const checkReady = () => {
- const miss = d.items.map((it, i) => ((it.name || it.hsCode) && (!String(it.unit2 || '').trim() || !cdQty2(it)) ? i + 1 : 0)).filter(Boolean);
- if (miss.length) return window.confirm(`第 ${miss.join('、')} 项商品的"发票单位"还没填,仍然下载吗?`);
- return true;
+ if (!missing.length) return true;
+ setShowMiss(true);
+ alert(`还有 ${missing.length} 项必填没有填,不能下载:\n\n${missing.slice(0, 15).join('\n')}${missing.length > 15 ? `\n……等 ${missing.length} 项` : ''}\n\n空着的格子已经标红。`);
+ return false;
};
const custOrders = orders.filter((o) => !d.customerId || o.customerId === d.customerId);
function pickCustomer(id) {
@@ -6356,10 +6385,12 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
const pr = cdProducer(d);
return (
<>
+
{d.contractNo || '新报关'}
改动自动保存
+ {missing.length > 0 ?
:
必填项已填完}
@@ -6375,32 +6406,32 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
- { const v = e.target.value; const x = shipperList.find((y) => y.name === v); set({ shipper: v, ...(x ? { shipperCode: x.code } : {}) }); }} placeholder="选择或手动填写公司全称" />
+ { const v = e.target.value; const x = shipperList.find((y) => y.name === v); set({ shipper: v, ...(x ? { shipperCode: x.code } : {}) }); }} placeholder="选择或手动填写公司全称" />
-
+
-
+
-
-
-
-
-
-
-
小计净重(千克) setItem(it.id, { kg: e.target.value })} />
+
+
小计净重(千克) setItem(it.id, { kg: e.target.value })} />
-
单价 setItem(it.id, { unitPrice: e.target.value })} />
+
单价 setItem(it.id, { unitPrice: e.target.value })} />
币制
总价(自动){it.qty && it.unitPrice ? `${cdFmt(cdTotal(it))} ${cdCurLabel(it.currency)}` : '—'}
-
原产国(地区) setItem(it.id, { origin: e.target.value })} />
+
原产国(地区) setItem(it.id, { origin: e.target.value })} />
最终目的国(地区) setItem(it.id, { dest: e.target.value })} placeholder={d.tradeCountry || '默认同贸易国'} />
-
境内货源地 setItem(it.id, { source: e.target.value })} placeholder="如:深圳特区" />
+
境内货源地 setItem(it.id, { source: e.target.value })} placeholder="如:深圳特区" />
))}
@@ -6453,6 +6484,7 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
+
>
);
}
@@ -6521,11 +6553,11 @@ function HsPicker({ it, hsList, setHsList, defs, setDefs, setItem, notify }) {
{canSave && }
商品编号(HS)
- onHs(e.target.value)} placeholder="8507600099" />
+ onHs(e.target.value)} placeholder="8507600099" />
商品名称{sameHs.length > 1 && 这个编码有 {sameHs.length} 个品名:{sameHs.map((x) => x.name).join('、')}}
- onName(e.target.value)} placeholder="如:锂电池" />
+ onName(e.target.value)} placeholder="如:锂电池" />
@@ -6541,13 +6573,13 @@ function HsPicker({ it, hsList, setHsList, defs, setDefs, setItem, notify }) {
{i + 1}{el.name}
{bi ? (
-