From 524d932b030311e45f647cde0420862483a357f9 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 17 Nov 2026 10:54:37 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-17 10:54:16 --- App.jsx | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 283 insertions(+), 4 deletions(-) diff --git a/App.jsx b/App.jsx index 6f3c717..7a1d6b3 100644 --- a/App.jsx +++ b/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' && ( + + )} + {view === 'settings' && ( <>
@@ -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, '
'); + 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) => `
${esc(label)}${code ? ` (${esc(code)})` : ''}
${esc(val) || ' '}
`; + const rows = (d.items || []).filter((it) => it.name || it.hsCode || it.qty).map((it, i) => ` + ${i + 1}${esc(it.hsCode)} + ${esc(it.name)}
${esc(it.spec)}
+ ${it.qty ? `${esc(it.qty)}${esc(it.unit)}` : ''}${it.kg ? `
${esc(it.kg)}千克` : ''}${it.qty2 ? `
${esc(it.qty2)}${esc(it.unit2)}` : ''} + ${it.unitPrice ? cdFmt(cdNum(it.unitPrice), 4) : ''}
${it.qty && it.unitPrice ? cdFmt(cdTotal(it)) : ''}
${esc(cdCurLabel(it.currency))} + ${esc(it.origin)}${esc(it.dest || d.tradeCountry)}${esc(it.source)}`).join(''); + const s = cdSums(d); + const html = `报关草单 ${esc(d.contractNo)} +

中华人民共和国海关出口货物报关单

草单 · 仅供核对用 · ${esc(d.date)}
+ + ${cell('境内发货人', d.shipperCode, d.shipper)}${cell('境外收货人', '', cust ? (cust.company || cust.contact) : '')}${cell('生产销售单位', pr.code, pr.name)} + ${cell('合同协议号', '', d.contractNo)}${cell('贸易国(地区)', '', d.tradeCountry)}${cell('成交方式', term ? term[1] : '', d.terms)} + ${cell('件数', '', d.packages)}${cell('毛重(千克)', '', d.grossWeight)}${cell('净重(千克)', '', d.netWeight)} + ${d.notes ? `` : ''} +
标记唛码及备注
${esc(d.notes)}
+ + ${rows}
项号商品编号商品名称及规格型号数量及单位单价/总价/币制原产国(地区)最终目的国(地区)境内货源地
+
${Object.entries(s.by).map(([c, v]) => `合计 ${cdFmt(v)} ${esc(cdCurLabel(c))}`).join(' ')}${s.kg ? ` · 法定数量合计 ${cdFmt(s.kg, 1)} 千克` : ''}
+
本草单由客户档案系统生成,仅供与报关行核对,以海关正式报关单为准。
+