Update App.jsx via upload script - 2026-11-17 10:54:16
This commit is contained in:
parent
9321c01ca7
commit
524d932b03
287
App.jsx
287
App.jsx
|
|
@ -5,7 +5,7 @@ import {
|
|||
Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users,
|
||||
Package, Layers, Zap, Tag, Inbox, Paperclip,
|
||||
Menu, LogOut, GripVertical, BookOpen, FileText, FolderTree, Lock, Sparkles, Printer, Image as ImageIcon,
|
||||
ShieldCheck, Settings2, Boxes, Download, Wifi, Radio, QrCode, Folder, FolderPlus, Factory, UploadCloud, ClipboardList, MessageCircle, CalendarDays, MapPin, Wrench, Hash, Send, Languages
|
||||
ShieldCheck, Settings2, Boxes, Download, Wifi, Radio, QrCode, Folder, FolderPlus, Factory, UploadCloud, ClipboardList, MessageCircle, CalendarDays, MapPin, Wrench, Hash, Send, Languages, Landmark
|
||||
} from 'lucide-react';
|
||||
import { MicUploadPage } from './mic-upload/MicUploadPage';
|
||||
import { ImageToolPage } from './mic-upload/ImageToolPage';
|
||||
|
|
@ -253,8 +253,8 @@ const COUNTRIES = [
|
|||
|
||||
const COUNTRY_BY_NAME = Object.fromEntries(COUNTRIES.map(c => [c.name, c]));
|
||||
|
||||
const SAVE_KEY_LABEL = { 'crm:customers': '客户', 'crm:products': '产品', 'crm:quotes': '报价单', 'crm:sellerProfiles': '卖方信息', 'crm:certifications': '授权', 'crm:productCategories': '产品分组', 'crm:packingLists': '箱单', 'crm:catalogDocs': '产品目录', 'crm:jmsLines': 'Just My Socks', 'crm:backPanelTemplates': '后板图模板', 'crm:suppliers': '供应商', 'crm:webDetailTemplates': '模板', 'crm:webAssets': '网站图片', 'crm:webNews': '新闻 / 动态', 'crm:webPackSpecs': 'Packing List' };
|
||||
const STORAGE_KEYS = { customers: 'crm:customers', products: 'crm:products', quotes: 'crm:quotes', sellerProfiles: 'crm:sellerProfiles', certifications: 'crm:certifications', productCategories: 'crm:productCategories', packingLists: 'crm:packingLists', catalogDocs: 'crm:catalogDocs', jmsLines: 'crm:jmsLines', backPanelTemplates: 'crm:backPanelTemplates', suppliers: 'crm:suppliers', webDetailTemplates: 'crm:webDetailTemplates', webAssets: 'crm:webAssets', webNews: 'crm:webNews', webPackSpecs: 'crm:webPackSpecs', orders: 'crm:orders' };
|
||||
const SAVE_KEY_LABEL = { 'crm:customers': '客户', 'crm:products': '产品', 'crm:quotes': '报价单', 'crm:sellerProfiles': '卖方信息', 'crm:certifications': '授权', 'crm:productCategories': '产品分组', 'crm:packingLists': '箱单', 'crm:catalogDocs': '产品目录', 'crm:jmsLines': 'Just My Socks', 'crm:backPanelTemplates': '后板图模板', 'crm:suppliers': '供应商', 'crm:webDetailTemplates': '模板', 'crm:webAssets': '网站图片', 'crm:webNews': '新闻 / 动态', 'crm:webPackSpecs': 'Packing List', 'crm:customsDecls': '报关' };
|
||||
const STORAGE_KEYS = { customers: 'crm:customers', products: 'crm:products', quotes: 'crm:quotes', sellerProfiles: 'crm:sellerProfiles', certifications: 'crm:certifications', productCategories: 'crm:productCategories', packingLists: 'crm:packingLists', catalogDocs: 'crm:catalogDocs', jmsLines: 'crm:jmsLines', backPanelTemplates: 'crm:backPanelTemplates', suppliers: 'crm:suppliers', webDetailTemplates: 'crm:webDetailTemplates', webAssets: 'crm:webAssets', webNews: 'crm:webNews', webPackSpecs: 'crm:webPackSpecs', orders: 'crm:orders', customsDecls: 'crm:customsDecls' };
|
||||
|
||||
const blankCustomer = () => ({
|
||||
id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7),
|
||||
|
|
@ -1692,8 +1692,13 @@ async function loadAll() {
|
|||
const od = await storageGet(STORAGE_KEYS.orders);
|
||||
if (od && od.value) orders = JSON.parse(od.value) || [];
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let customsDecls = [];
|
||||
try {
|
||||
const cdv = await storageGet(STORAGE_KEYS.customsDecls);
|
||||
if (cdv && cdv.value) customsDecls = JSON.parse(cdv.value) || [];
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; }
|
||||
return { orders, customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, tplPendingIds: tplPending.map(x => x.id), webAssets, webNews, webPackSpecs };
|
||||
return { orders, customsDecls, customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, tplPendingIds: tplPending.map(x => x.id), webAssets, webNews, webPackSpecs };
|
||||
}
|
||||
|
||||
/* -------------------------------- styles -------------------------------- */
|
||||
|
|
@ -2221,6 +2226,24 @@ const Styles = () => (
|
|||
.visit-pdf { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 150px; height: 120px; border: 1px solid #f5b5ac; border-radius: 8px; background: #fef1ef; color: #b42318; text-decoration: none; font-weight: 700; }
|
||||
.visit-pdf small { font-weight: 500; color: #b42318; }
|
||||
@media (max-width: 760px) { .visit-card { grid-template-columns: 1fr; } .visit-when { border-right: 0; border-bottom: 1px dashed var(--line); padding: 0 0 10px; } }
|
||||
/* 报关 */
|
||||
.cd-search { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--panel); color: var(--ink-soft); height: 34px; min-width: 300px; }
|
||||
.cd-search input { border: 0; outline: 0; background: transparent; flex: 1; font-size: 13px; color: var(--ink); }
|
||||
.cd-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; padding: 16px 18px; }
|
||||
.cd-grid .field, .cd-item-body .field { margin: 0; }
|
||||
.cd-span2 { grid-column: span 2; } .cd-span3 { grid-column: 1 / -1; }
|
||||
.cd-check { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-weight: 500; color: var(--ink-soft); cursor: pointer; }
|
||||
.cd-sync { min-height: 38px; display: flex; align-items: center; padding: 0 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); font-size: 13.5px; font-weight: 600; }
|
||||
.cd-sync i { font-weight: 400; color: var(--ink-soft); }
|
||||
.cd-row2 { display: flex; gap: 6px; } .cd-row2 .input { min-width: 0; }
|
||||
.cd-hint { font-weight: 500; color: #b54708; margin-left: 6px; }
|
||||
.cd-item { display: grid; grid-template-columns: 34px 1fr; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
|
||||
.cd-item-no { display: flex; flex-direction: column; align-items: center; gap: 2px; }
|
||||
.cd-item-no b { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; margin-bottom: 4px; }
|
||||
.cd-item-no .btn { padding: 2px 6px; min-height: 0; }
|
||||
.cd-item-body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; }
|
||||
.cd-total { min-height: 38px; display: flex; align-items: center; font-weight: 700; font-size: 13.5px; }
|
||||
@media (max-width: 860px) { .cd-grid, .cd-item-body { grid-template-columns: 1fr; } .cd-span2 { grid-column: auto; } }
|
||||
/* 沟通记录 */
|
||||
.cv-wrap { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--panel); margin-top: 6px; }
|
||||
.cv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
|
||||
|
|
@ -2649,6 +2672,7 @@ const STANDALONE_NAV = [
|
|||
{ id: 'catalog', label: '产品目录', icon: BookOpen },
|
||||
{ id: 'quotes', label: '报价单', icon: FileText },
|
||||
{ id: 'packing', label: '箱单', icon: Boxes },
|
||||
{ id: 'customs', label: '报关', icon: Landmark },
|
||||
{ id: 'settings', label: '设置', icon: SettingsIcon },
|
||||
];
|
||||
function viewTitle(view) {
|
||||
|
|
@ -2848,6 +2872,7 @@ function MainApp({ username, onLogout }) {
|
|||
const [pdfExporting, setPdfExporting] = useState(false);
|
||||
const [packingLists, setPackingLists] = useState([]);
|
||||
const [orders, setOrders] = useState([]);
|
||||
const [customsDecls, setCustomsDecls] = useState([]);
|
||||
const [selectedOrderId, setSelectedOrderId] = useState(null);
|
||||
const [packingSubView, setPackingSubView] = useState('list'); // 'list' | 'editor'
|
||||
const [packingDraft, setPackingDraft] = useState(null);
|
||||
|
|
@ -2918,6 +2943,7 @@ function MainApp({ username, onLogout }) {
|
|||
setCertifications(data.certifications);
|
||||
setPackingLists(data.packingLists);
|
||||
setOrders(Array.isArray(data.orders) ? data.orders : []);
|
||||
setCustomsDecls(Array.isArray(data.customsDecls) ? data.customsDecls : []);
|
||||
setCatalogDocs((data.catalogDocs || []).filter(d => d.fileName));
|
||||
setJmsLines(data.jmsLines || []);
|
||||
setBackPanelTemplates(data.backPanelTemplates || []);
|
||||
|
|
@ -2968,6 +2994,7 @@ function MainApp({ username, onLogout }) {
|
|||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).then(() => clearSaveIssue(STORAGE_KEYS.webAssets)).catch(reportSaveError); }, [webAssets, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).then(() => clearSaveIssue(STORAGE_KEYS.webNews)).catch(reportSaveError); }, [webNews, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.orders, JSON.stringify(orders)).then(() => clearSaveIssue(STORAGE_KEYS.orders)).catch(reportSaveError); }, [orders, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customsDecls, JSON.stringify(customsDecls)).then(() => clearSaveIssue(STORAGE_KEYS.customsDecls)).catch(reportSaveError); }, [customsDecls, loaded]);
|
||||
// 侧栏“订单管理”上的数字:到期未处理的订单提醒(每分钟刷新一次)
|
||||
const [ordTick, setOrdTick] = useState(0);
|
||||
useEffect(() => { const t = setInterval(() => setOrdTick(x => x + 1), 60000); return () => clearInterval(t); }, []);
|
||||
|
|
@ -4887,6 +4914,10 @@ function MainApp({ username, onLogout }) {
|
|||
/>
|
||||
)}
|
||||
|
||||
{view === 'customs' && (
|
||||
<CustomsPage decls={customsDecls} setDecls={setCustomsDecls} customers={customers} orders={orders} notify={notify} />
|
||||
)}
|
||||
|
||||
{view === 'settings' && (
|
||||
<>
|
||||
<div className="panel section-gap">
|
||||
|
|
@ -5931,6 +5962,254 @@ function OrderDetail({ order: o, update, onDelete, customers, quotes, products,
|
|||
}
|
||||
|
||||
/* ---- 订单列表 + 详情 ---- */
|
||||
// ===== 报关:出口报关单草单(境内发货人 / 合同协议号 / 贸易国 / 件数 / 毛重 / 净重 / 成交方式 + 商品明细),可打印给报关行核对 =====
|
||||
const CD_CURRENCIES = [{ id: 'USD', label: '美元' }, { id: 'CNY', label: '人民币' }, { id: 'RUB', label: '俄罗斯卢布' }];
|
||||
const CD_TERMS = [['EXW', '7'], ['FOB', '3'], ['CIF', '1'], ['C&F', '2'], ['C&I', '4'], ['市场价', '5'], ['垫仓', '6']];
|
||||
const CD_COUNTRIES = ['白俄罗斯', '俄罗斯', '哈萨克斯坦', '乌兹别克斯坦', '吉尔吉斯斯坦', '塔吉克斯坦', '土库曼斯坦', '阿塞拜疆', '亚美尼亚', '格鲁吉亚', '蒙古', '阿联酋', '沙特阿拉伯', '伊拉克', '伊朗', '土耳其', '埃及', '尼日利亚', '肯尼亚', '南非', '委内瑞拉', '印度', '越南', '印度尼西亚', '马来西亚', '泰国', '菲律宾'];
|
||||
const CD_UNITS = ['个', '台', '套', '件', '只', '块', '箱', '千克'];
|
||||
const cdId = (p) => p + '_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
|
||||
const blankCdItem = (prev = {}) => ({
|
||||
id: cdId('cdi'), hsCode: prev.hsCode || '', name: '', spec: '',
|
||||
qty: '', unit: prev.unit || '个', kg: '', qty2: '', unit2: prev.unit2 || '台',
|
||||
unitPrice: '', currency: prev.currency || 'USD', origin: prev.origin || '中国', dest: prev.dest || '', source: prev.source || '',
|
||||
});
|
||||
const blankCustomsDecl = (prev) => ({
|
||||
id: cdId('cd'), date: todayStr(), customerId: '', orderId: '',
|
||||
shipper: prev ? prev.shipper : '', shipperCode: prev ? prev.shipperCode : '', producerSame: true, producer: '', producerCode: '',
|
||||
contractNo: '', tradeCountry: '', packages: '', grossWeight: '', netWeight: '', terms: prev ? prev.terms : 'EXW',
|
||||
items: [blankCdItem()], notes: '', createdAt: new Date().toISOString(),
|
||||
});
|
||||
const cdNum = (v) => { const n = parseFloat(String(v ?? '').replace(/,/g, '')); return Number.isFinite(n) ? n : 0; };
|
||||
const cdFmt = (n, d = 2) => (Number.isFinite(n) ? n : 0).toLocaleString('en-US', { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
const cdTotal = (it) => cdNum(it.qty) * cdNum(it.unitPrice);
|
||||
const cdCurLabel = (id) => (CD_CURRENCIES.find((c) => c.id === id) || {}).label || id;
|
||||
function cdSums(d) {
|
||||
const by = {};
|
||||
for (const it of d.items || []) { if (!it.qty && !it.unitPrice) continue; by[it.currency] = (by[it.currency] || 0) + cdTotal(it); }
|
||||
const kg = (d.items || []).reduce((s, it) => s + cdNum(it.kg), 0);
|
||||
return { by, kg };
|
||||
}
|
||||
const cdProducer = (d) => (d.producerSame ? { name: d.shipper, code: d.shipperCode } : { name: d.producer, code: d.producerCode });
|
||||
|
||||
// 打印:按海关出口报关单的样子排一份草单(仅供核对)
|
||||
function printCustomsDecl(d, customers) {
|
||||
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])).replace(/\n/g, '<br>');
|
||||
const cust = customers.find((c) => c.id === d.customerId);
|
||||
const pr = cdProducer(d);
|
||||
const term = CD_TERMS.find((t) => t[0] === d.terms);
|
||||
const cell = (label, code, val) => `<td><div class="l">${esc(label)}${code ? ` <span>(${esc(code)})</span>` : ''}</div><div class="v">${esc(val) || ' '}</div></td>`;
|
||||
const rows = (d.items || []).filter((it) => it.name || it.hsCode || it.qty).map((it, i) => `
|
||||
<tr><td class="c">${i + 1}</td><td class="m">${esc(it.hsCode)}</td>
|
||||
<td><b>${esc(it.name)}</b><div class="spec">${esc(it.spec)}</div></td>
|
||||
<td class="r">${it.qty ? `${esc(it.qty)}${esc(it.unit)}` : ''}${it.kg ? `<br>${esc(it.kg)}千克` : ''}${it.qty2 ? `<br>${esc(it.qty2)}${esc(it.unit2)}` : ''}</td>
|
||||
<td class="r">${it.unitPrice ? cdFmt(cdNum(it.unitPrice), 4) : ''}<br>${it.qty && it.unitPrice ? cdFmt(cdTotal(it)) : ''}<br>${esc(cdCurLabel(it.currency))}</td>
|
||||
<td class="c">${esc(it.origin)}</td><td class="c">${esc(it.dest || d.tradeCountry)}</td><td class="c">${esc(it.source)}</td></tr>`).join('');
|
||||
const s = cdSums(d);
|
||||
const html = `<!doctype html><html><head><meta charset="utf-8"><title>报关草单 ${esc(d.contractNo)}</title><style>
|
||||
@page{size:A4;margin:12mm}*{box-sizing:border-box}body{font-family:"Microsoft YaHei","PingFang SC","Noto Sans SC",sans-serif;font-size:11px;color:#111;margin:0}
|
||||
h1{text-align:center;font-size:17px;margin:0 0 2px}.sub{text-align:center;color:#666;margin-bottom:8px}
|
||||
table{width:100%;border-collapse:collapse}td,th{border:1px solid #444;padding:3px 5px;vertical-align:top}
|
||||
.l{font-size:9.5px;color:#444}.l span{color:#888}.v{font-size:12px;font-weight:600;min-height:15px}
|
||||
th{background:#eee;font-size:10.5px}.c{text-align:center}.r{text-align:right;white-space:nowrap}.m{font-family:Consolas,monospace}
|
||||
.spec{font-size:10.5px;color:#333;word-break:break-all}.tot{margin-top:6px;text-align:right;font-weight:700}
|
||||
.note{margin-top:8px;font-size:10px;color:#555}
|
||||
</style></head><body>
|
||||
<h1>中华人民共和国海关出口货物报关单</h1><div class="sub">草单 · 仅供核对用 · ${esc(d.date)}</div>
|
||||
<table>
|
||||
<tr>${cell('境内发货人', d.shipperCode, d.shipper)}${cell('境外收货人', '', cust ? (cust.company || cust.contact) : '')}${cell('生产销售单位', pr.code, pr.name)}</tr>
|
||||
<tr>${cell('合同协议号', '', d.contractNo)}${cell('贸易国(地区)', '', d.tradeCountry)}${cell('成交方式', term ? term[1] : '', d.terms)}</tr>
|
||||
<tr>${cell('件数', '', d.packages)}${cell('毛重(千克)', '', d.grossWeight)}${cell('净重(千克)', '', d.netWeight)}</tr>
|
||||
${d.notes ? `<tr><td colspan="3"><div class="l">标记唛码及备注</div><div class="v" style="font-weight:400">${esc(d.notes)}</div></td></tr>` : ''}
|
||||
</table>
|
||||
<table style="margin-top:8px"><thead><tr><th style="width:30px">项号</th><th style="width:78px">商品编号</th><th>商品名称及规格型号</th><th style="width:70px">数量及单位</th><th style="width:92px">单价/总价/币制</th><th style="width:56px">原产国(地区)</th><th style="width:64px">最终目的国(地区)</th><th style="width:64px">境内货源地</th></tr></thead>
|
||||
<tbody>${rows}</tbody></table>
|
||||
<div class="tot">${Object.entries(s.by).map(([c, v]) => `合计 ${cdFmt(v)} ${esc(cdCurLabel(c))}`).join(' ')}${s.kg ? ` · 法定数量合计 ${cdFmt(s.kg, 1)} 千克` : ''}</div>
|
||||
<div class="note">本草单由客户档案系统生成,仅供与报关行核对,以海关正式报关单为准。</div>
|
||||
<script>window.onload=function(){setTimeout(function(){window.print()},200)}<\/script></body></html>`;
|
||||
const w = window.open('', '_blank');
|
||||
if (!w) { alert('浏览器拦截了弹出窗口,请允许本网站弹出窗口后再试'); return; }
|
||||
w.document.open(); w.document.write(html); w.document.close();
|
||||
}
|
||||
|
||||
function CustomsPage({ decls, setDecls, customers, orders, notify }) {
|
||||
const [selId, setSelId] = useState(null);
|
||||
const [q, setQ] = useState('');
|
||||
const custName = (id) => { const c = customers.find((x) => x.id === id); return c ? (c.company || c.contact || '') : ''; };
|
||||
const update = (id, patch) => setDecls((prev) => prev.map((d) => (d.id === id ? { ...d, ...(typeof patch === 'function' ? patch(d) : patch), updatedAt: new Date().toISOString() } : d)));
|
||||
const sel = decls.find((d) => d.id === selId) || null;
|
||||
const shippers = [...new Set(decls.map((d) => d.shipper).filter(Boolean))];
|
||||
function create() {
|
||||
const last = [...decls].sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))[0];
|
||||
const d = blankCustomsDecl(last);
|
||||
setDecls((prev) => [...prev, d]); setSelId(d.id);
|
||||
}
|
||||
function duplicate(d) {
|
||||
const c = { ...JSON.parse(JSON.stringify(d)), id: cdId('cd'), date: todayStr(), contractNo: '', createdAt: new Date().toISOString(), updatedAt: '' };
|
||||
c.items = c.items.map((it) => ({ ...it, id: cdId('cdi') }));
|
||||
setDecls((prev) => [...prev, c]); setSelId(c.id); notify('已复制,请修改合同协议号等信息');
|
||||
}
|
||||
function remove(d) {
|
||||
if (!window.confirm(`确定删除这份报关资料${d.contractNo ? `(${d.contractNo})` : ''}?此操作不可恢复。`)) return;
|
||||
setDecls((prev) => prev.filter((x) => x.id !== d.id)); setSelId(null); notify('已删除');
|
||||
}
|
||||
if (sel) return <CustomsEditor d={sel} update={(p) => update(sel.id, p)} onBack={() => setSelId(null)} onDelete={() => remove(sel)} onDuplicate={() => duplicate(sel)}
|
||||
customers={customers} orders={orders} shippers={shippers} notify={notify} />;
|
||||
|
||||
const s0 = q.trim().toLowerCase();
|
||||
const list = decls.filter((d) => !s0 || [d.contractNo, d.shipper, d.tradeCountry, custName(d.customerId), ...(d.items || []).flatMap((it) => [it.name, it.hsCode, it.spec])].some((x) => String(x || '').toLowerCase().includes(s0)))
|
||||
.sort((a, b) => (b.date || '').localeCompare(a.date || '') || String(b.createdAt).localeCompare(String(a.createdAt)));
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 14, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
<button className="btn btn-primary" onClick={create}><Plus size={14} />新建报关</button>
|
||||
<div className="cd-search"><Search size={13} /><input value={q} onChange={(e) => setQ(e.target.value)} placeholder="搜合同协议号、发货人、客户、商品、HS 编码" /></div>
|
||||
</div>
|
||||
<div className="panel">
|
||||
<div className="panel-body">
|
||||
{decls.length === 0 ? (
|
||||
<div className="empty-state"><Landmark size={28} />暂无报关资料,点击上方"新建报关"录入一份</div>
|
||||
) : list.length === 0 ? <div className="empty-state">没有匹配的报关资料</div> : list.map((d) => {
|
||||
const s = cdSums(d); const n = (d.items || []).filter((it) => it.name || it.hsCode).length;
|
||||
return (
|
||||
<div key={d.id} className="row" style={{ cursor: 'pointer' }} onClick={() => setSelId(d.id)}>
|
||||
<span className="badge badge-region" style={{ flexShrink: 0 }}>报关</span>
|
||||
<div className="row-main">
|
||||
<div className="row-title">{d.contractNo || '(无合同协议号)'} · {d.shipper || '(未填境内发货人)'}{d.tradeCountry ? ` → ${d.tradeCountry}` : ''}</div>
|
||||
<div className="row-sub">{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('')}</div>
|
||||
</div>
|
||||
<button className="btn btn-sm" onClick={(e) => { e.stopPropagation(); printCustomsDecl(d, customers); }}><Printer size={12} />打印</button>
|
||||
<button className="btn btn-sm" onClick={(e) => { e.stopPropagation(); duplicate(d); }}><Copy size={12} />复制</button>
|
||||
<button className="btn btn-sm btn-ghost btn-danger" onClick={(e) => { e.stopPropagation(); remove(d); }}><Trash2 size={13} /></button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, orders, shippers, notify }) {
|
||||
const set = (p) => update(p);
|
||||
const setItem = (id, p) => update((x) => ({ items: x.items.map((it) => (it.id === id ? { ...it, ...p } : it)) }));
|
||||
const addItem = () => update((x) => ({ items: [...x.items, blankCdItem({ ...x.items[x.items.length - 1], dest: (x.items[x.items.length - 1] || {}).dest })] }));
|
||||
const dupItem = (it) => update((x) => { const i = x.items.findIndex((y) => y.id === it.id); const c = { ...it, id: cdId('cdi') }; const items = [...x.items]; items.splice(i + 1, 0, c); return { items }; });
|
||||
const delItem = (it) => update((x) => ({ items: x.items.length > 1 ? x.items.filter((y) => y.id !== it.id) : [blankCdItem()] }));
|
||||
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 custOrders = orders.filter((o) => !d.customerId || o.customerId === d.customerId);
|
||||
function pickCustomer(id) {
|
||||
const c = customers.find((x) => x.id === id);
|
||||
set({ customerId: id, ...(c && c.country && !d.tradeCountry ? { tradeCountry: c.country } : {}) });
|
||||
}
|
||||
function fromOrder(id) {
|
||||
const o = orders.find((x) => x.id === id); if (!o) return;
|
||||
const items = (o.items || []).filter((it) => it.name || it.hsCode).map((it) => ({ ...blankCdItem({ currency: ['USD', 'CNY', 'RUB'].includes(o.currency) ? o.currency : 'USD', origin: '中国' }), hsCode: it.hsCode || '', name: it.name || '', spec: it.declareElements || '', qty: it.qty || '', unitPrice: it.unitPrice || '' }));
|
||||
if (!items.length) { notify('这个订单还没有产品'); return; }
|
||||
const hasItems = d.items.some((it) => it.name || it.hsCode || it.qty);
|
||||
if (hasItems && !window.confirm(`用订单 ${o.number || ''} 的 ${items.length} 项产品替换当前的商品明细?`)) { set({ orderId: id }); return; }
|
||||
set({ orderId: id, customerId: d.customerId || o.customerId || '', contractNo: d.contractNo || o.number || '', items });
|
||||
notify(`已带入 ${items.length} 项产品(HS 编码、申报要素、数量、单价),请补充法定数量和单位`);
|
||||
}
|
||||
const pr = cdProducer(d);
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 14, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
<button className="btn btn-sm" onClick={onBack}><ChevronRight size={13} style={{ transform: 'rotate(180deg)' }} />返回列表</button>
|
||||
<span style={{ fontWeight: 700 }}>{d.contractNo || '新报关'}</span>
|
||||
<span style={{ fontSize: 12, color: 'var(--ink-soft)' }}>改动自动保存</span>
|
||||
<div style={{ marginLeft: 'auto', display: 'flex', gap: 8 }}>
|
||||
<button className="btn btn-sm btn-primary" onClick={() => printCustomsDecl(d, customers)}><Printer size={13} />打印报关草单</button>
|
||||
<button className="btn btn-sm" onClick={onDuplicate}><Copy size={12} />复制</button>
|
||||
<button className="btn btn-sm btn-ghost btn-danger" onClick={onDelete}><Trash2 size={13} />删除</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel section-gap">
|
||||
<div className="panel-header"><div className="panel-title">报关信息</div></div>
|
||||
<div className="panel-body cd-grid">
|
||||
<label className="field cd-span2"><span className="field-label">境内发货人</span>
|
||||
<input className="input" list="cd-shippers" value={d.shipper} onChange={(e) => set({ shipper: e.target.value })} placeholder="公司全称,如:深圳兴达时代科技有限公司" />
|
||||
<datalist id="cd-shippers">{shippers.map((x) => <option key={x} value={x} />)}</datalist>
|
||||
</label>
|
||||
<label className="field"><span className="field-label">统一社会信用代码(可选)</span><input className="input crm-mono" value={d.shipperCode} onChange={(e) => set({ shipperCode: e.target.value.toUpperCase() })} placeholder="18 位" /></label>
|
||||
<div className="field cd-span3">
|
||||
<span className="field-label">生产销售单位
|
||||
<label className="cd-check"><input type="checkbox" checked={d.producerSame} onChange={(e) => set({ producerSame: e.target.checked, ...(e.target.checked ? {} : { producer: d.producer || d.shipper, producerCode: d.producerCode || d.shipperCode }) })} />与境内发货人相同(自动同步)</label>
|
||||
</span>
|
||||
{d.producerSame
|
||||
? <div className="cd-sync">{pr.name || <i>填写境内发货人后自动同步</i>}{pr.code ? <span className="crm-mono"> {pr.code}</span> : null}</div>
|
||||
: <div className="cd-row2"><input className="input" value={d.producer} onChange={(e) => set({ producer: e.target.value })} placeholder="生产销售单位全称" /><input className="input crm-mono" value={d.producerCode} onChange={(e) => set({ producerCode: e.target.value.toUpperCase() })} placeholder="统一社会信用代码(可选)" /></div>}
|
||||
</div>
|
||||
<label className="field"><span className="field-label">合同协议号</span><input className="input crm-mono" value={d.contractNo} onChange={(e) => set({ contractNo: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">贸易国(地区)</span>
|
||||
<input className="input" list="cd-countries" value={d.tradeCountry} onChange={(e) => set({ tradeCountry: e.target.value })} placeholder="如:白俄罗斯" />
|
||||
<datalist id="cd-countries">{CD_COUNTRIES.map((x) => <option key={x} value={x} />)}</datalist>
|
||||
</label>
|
||||
<label className="field"><span className="field-label">成交方式</span>
|
||||
<select className="input" value={d.terms} onChange={(e) => set({ terms: e.target.value })}>{CD_TERMS.map(([t, c]) => <option key={t} value={t}>{t}({c})</option>)}</select>
|
||||
</label>
|
||||
<label className="field"><span className="field-label">件数</span><input className="input" inputMode="numeric" value={d.packages} onChange={(e) => set({ packages: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">毛重(千克)</span><input className="input" inputMode="decimal" value={d.grossWeight} onChange={(e) => set({ grossWeight: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">净重(千克){s.kg > 0 && <small className="cd-hint">商品法定数量合计 {cdFmt(s.kg, 1)}{d.netWeight && Math.abs(cdNum(d.netWeight) - s.kg) > 0.05 ? ',和净重不一致' : ''}</small>}</span><input className="input" inputMode="decimal" value={d.netWeight} onChange={(e) => set({ netWeight: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">日期</span><input className="input" type="date" value={d.date} onChange={(e) => set({ date: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">关联客户(可选)</span>
|
||||
<select className="input" value={d.customerId} onChange={(e) => pickCustomer(e.target.value)}><option value="">—</option>{customers.map((c) => <option key={c.id} value={c.id}>{c.company || c.contact}</option>)}</select>
|
||||
</label>
|
||||
<label className="field"><span className="field-label">从订单带入产品(可选)</span>
|
||||
<select className="input" value={d.orderId || ''} onChange={(e) => fromOrder(e.target.value)}><option value="">—</option>{custOrders.map((o) => <option key={o.id} value={o.id}>{o.number || '(无编号)'} · {o.date}</option>)}</select>
|
||||
</label>
|
||||
<label className="field cd-span3"><span className="field-label">标记唛码及备注(可选)</span><textarea className="textarea" rows={2} value={d.notes} onChange={(e) => set({ notes: e.target.value })} /></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel section-gap">
|
||||
<div className="panel-header"><div className="panel-title">商品明细({d.items.length} 项)</div>
|
||||
<div style={{ fontSize: 12.5, fontWeight: 600 }}>{Object.entries(s.by).map(([c, v]) => <span key={c} style={{ marginLeft: 12 }}>合计 {cdFmt(v)} {cdCurLabel(c)}</span>)}</div>
|
||||
</div>
|
||||
<div className="panel-body" style={{ display: 'grid', gap: 10, padding: '14px 16px' }}>
|
||||
{d.items.map((it, i) => (
|
||||
<div key={it.id} className="cd-item">
|
||||
<div className="cd-item-no">
|
||||
<b>{i + 1}</b>
|
||||
<button className="btn btn-sm btn-ghost" title="上移" disabled={i === 0} onClick={() => moveItem(it, -1)}>↑</button>
|
||||
<button className="btn btn-sm btn-ghost" title="下移" disabled={i === d.items.length - 1} onClick={() => moveItem(it, 1)}>↓</button>
|
||||
<button className="btn btn-sm btn-ghost" title="复制这一项" onClick={() => dupItem(it)}><Copy size={12} /></button>
|
||||
<button className="btn btn-sm btn-ghost btn-danger" title="删除" onClick={() => delItem(it)}><Trash2 size={12} /></button>
|
||||
</div>
|
||||
<div className="cd-item-body">
|
||||
<label className="field"><span className="field-label">商品编号(HS)</span><input className="input crm-mono" value={it.hsCode} onChange={(e) => setItem(it.id, { hsCode: e.target.value.replace(/[^\d.]/g, '') })} placeholder="8504401990" /></label>
|
||||
<label className="field cd-span2"><span className="field-label">商品名称</span><input className="input" value={it.name} onChange={(e) => setItem(it.id, { name: e.target.value })} placeholder="如:电源系统" /></label>
|
||||
<label className="field cd-span3"><span className="field-label">规格型号(申报要素)</span><textarea className="textarea crm-mono" rows={2} value={it.spec} onChange={(e) => setItem(it.id, { spec: e.target.value })} placeholder="1|0|稳定输出电压用|直流稳压电源|2kW|+/-10%|义达牌|无型号" /></label>
|
||||
<div className="field"><span className="field-label">成交数量 / 单位</span><div className="cd-row2"><input className="input" inputMode="decimal" value={it.qty} onChange={(e) => setItem(it.id, { qty: e.target.value })} /><UnitInput value={it.unit} onChange={(v) => setItem(it.id, { unit: v })} /></div></div>
|
||||
<label className="field"><span className="field-label">法定第一数量(千克)</span><input className="input" inputMode="decimal" value={it.kg} onChange={(e) => setItem(it.id, { kg: e.target.value })} /></label>
|
||||
<div className="field"><span className="field-label">第二数量 / 单位(可选)</span><div className="cd-row2"><input className="input" inputMode="decimal" value={it.qty2} onChange={(e) => setItem(it.id, { qty2: e.target.value })} /><UnitInput value={it.unit2} onChange={(v) => setItem(it.id, { unit2: v })} /></div></div>
|
||||
<label className="field"><span className="field-label">单价</span><input className="input" inputMode="decimal" value={it.unitPrice} onChange={(e) => setItem(it.id, { unitPrice: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">币制</span>
|
||||
<select className="input" value={it.currency} onChange={(e) => setItem(it.id, { currency: e.target.value })}>{CD_CURRENCIES.map((c) => <option key={c.id} value={c.id}>{c.label}({c.id})</option>)}</select>
|
||||
</label>
|
||||
<div className="field"><span className="field-label">总价(自动)</span><div className="cd-total">{it.qty && it.unitPrice ? `${cdFmt(cdTotal(it))} ${cdCurLabel(it.currency)}` : '—'}</div></div>
|
||||
<label className="field"><span className="field-label">原产国(地区)</span><input className="input" value={it.origin} onChange={(e) => setItem(it.id, { origin: e.target.value })} /></label>
|
||||
<label className="field"><span className="field-label">最终目的国(地区)</span><input className="input" list="cd-countries" value={it.dest} onChange={(e) => setItem(it.id, { dest: e.target.value })} placeholder={d.tradeCountry || '默认同贸易国'} /></label>
|
||||
<label className="field"><span className="field-label">境内货源地</span><input className="input" value={it.source} onChange={(e) => setItem(it.id, { source: e.target.value })} placeholder="如:深圳特区" /></label>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div><button className="btn" onClick={addItem}><Plus size={13} />添加商品</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function UnitInput({ value, onChange }) {
|
||||
return (
|
||||
<>
|
||||
<input className="input" list="cd-units" value={value} onChange={(e) => onChange(e.target.value)} style={{ maxWidth: 80 }} />
|
||||
<datalist id="cd-units">{CD_UNITS.map((u) => <option key={u} value={u} />)}</datalist>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function OrdersPage({ orders, setOrders, customers, quotes, products, suppliers, packingLists, notify, onOpenQuote, onOpenPacking, selectedId, setSelectedId }) {
|
||||
const [q, setQ] = useState('');
|
||||
const [filter, setFilter] = useState('open');
|
||||
|
|
|
|||
Loading…
Reference in New Issue