diff --git a/App.jsx b/App.jsx index d4c68a2..23e2490 100644 --- a/App.jsx +++ b/App.jsx @@ -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', 'crm:customsDecls': '报关', 'crm:customsShippers': '境内发货人', 'crm:customsHs': '商品编码库' }; -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', customsShippers: 'crm:customsShippers', customsHs: 'crm:customsHs' }; +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': '报关', 'crm:customsShippers': '境内发货人', 'crm:customsHs': '商品编码库', 'crm:customsHsDefs': '申报要素名称' }; +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', customsShippers: 'crm:customsShippers', customsHs: 'crm:customsHs', customsHsDefs: 'crm:customsHsDefs' }; const blankCustomer = () => ({ id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7), @@ -1706,8 +1706,13 @@ async function loadAll() { const v = await storageGet(STORAGE_KEYS.customsHs); if (v && v.value) customsHs = JSON.parse(v.value) || []; } catch (e) { if (!e.notFound) failed.push(e.message); } + let customsHsDefs = CD_DEFAULT_HS_DEFS; + try { + const v = await storageGet(STORAGE_KEYS.customsHsDefs); + if (v && v.value) customsHsDefs = JSON.parse(v.value) || CD_DEFAULT_HS_DEFS; + } 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, customsDecls, customsShippers, customsHs, customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, tplPendingIds: tplPending.map(x => x.id), webAssets, webNews, webPackSpecs }; + return { orders, customsDecls, customsShippers, customsHs, customsHsDefs, customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, tplPendingIds: tplPending.map(x => x.id), webAssets, webNews, webPackSpecs }; } /* -------------------------------- styles -------------------------------- */ @@ -2246,7 +2251,24 @@ const Styles = () => ( .cd-note { font-size: 12.5px; color: var(--ink-soft); line-height: 1.6; } .cd-lib-row { display: grid; gap: 8px; align-items: start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); } .cd-ship-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) auto auto; align-items: center; } - .cd-hs-row { grid-template-columns: 130px minmax(0, 1fr) minmax(0, 2.2fr) auto; } + .cd-hs-row { grid-template-columns: minmax(0, 1fr) minmax(0, 2.6fr) auto; } + .cd-link { border: 0; background: none; color: #2563eb; cursor: pointer; font-size: 12px; margin-left: 10px; padding: 0; font-weight: 500; } + .cd-elems { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); } + .cd-elem { display: grid; grid-template-columns: minmax(150px, 46%) 1fr; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--line); } + .cd-elem:nth-child(odd) { border-right: 1px solid var(--line); } + .cd-elem .input { height: 32px; } + .cd-elem.empty .cd-elem-n { color: #b54708; } + .cd-elem-n { font-size: 12.5px; display: flex; gap: 6px; align-items: baseline; line-height: 1.35; } + .cd-elem-n i { font-style: normal; font-size: 11px; font-weight: 700; color: var(--ink-soft); min-width: 14px; } + .cd-names { border: 1px dashed var(--line); border-radius: 9px; padding: 10px 12px; background: var(--panel); } + .cd-code { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; background: var(--bg); } + .cd-code-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); } + .cd-code-h b { font-size: 15px; color: var(--ink); } + .cd-def { display: grid; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; } + .cd-def-r { display: grid; grid-template-columns: minmax(180px, 34%) 1fr; gap: 10px; align-items: center; min-height: 30px; } + .cd-def-r .input { height: 30px; font-size: 12.5px; } + @media (max-width: 860px) { .cd-elems { grid-template-columns: 1fr; } .cd-elem:nth-child(odd) { border-right: 0; } } + @media (max-width: 860px) { .cd-ship-row, .cd-hs-row { grid-template-columns: 1fr; } } .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); } @@ -2896,6 +2918,7 @@ function MainApp({ username, onLogout }) { const [customsDecls, setCustomsDecls] = useState([]); const [customsShippers, setCustomsShippers] = useState(CD_DEFAULT_SHIPPERS); const [customsHs, setCustomsHs] = useState([]); + const [customsHsDefs, setCustomsHsDefs] = useState(CD_DEFAULT_HS_DEFS); const [selectedOrderId, setSelectedOrderId] = useState(null); const [packingSubView, setPackingSubView] = useState('list'); // 'list' | 'editor' const [packingDraft, setPackingDraft] = useState(null); @@ -2969,6 +2992,7 @@ function MainApp({ username, onLogout }) { setCustomsDecls(Array.isArray(data.customsDecls) ? data.customsDecls : []); setCustomsShippers(Array.isArray(data.customsShippers) ? data.customsShippers : CD_DEFAULT_SHIPPERS); setCustomsHs(Array.isArray(data.customsHs) ? data.customsHs : []); + setCustomsHsDefs(Array.isArray(data.customsHsDefs) ? data.customsHsDefs : CD_DEFAULT_HS_DEFS); setCatalogDocs((data.catalogDocs || []).filter(d => d.fileName)); setJmsLines(data.jmsLines || []); setBackPanelTemplates(data.backPanelTemplates || []); @@ -3020,6 +3044,7 @@ function MainApp({ username, onLogout }) { 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.customsShippers, JSON.stringify(customsShippers)).then(() => clearSaveIssue(STORAGE_KEYS.customsShippers)).catch(reportSaveError); }, [customsShippers, loaded]); + useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customsHsDefs, JSON.stringify(customsHsDefs)).then(() => clearSaveIssue(STORAGE_KEYS.customsHsDefs)).catch(reportSaveError); }, [customsHsDefs, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customsHs, JSON.stringify(customsHs)).then(() => clearSaveIssue(STORAGE_KEYS.customsHs)).catch(reportSaveError); }, [customsHs, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customsDecls, JSON.stringify(customsDecls)).then(() => clearSaveIssue(STORAGE_KEYS.customsDecls)).catch(reportSaveError); }, [customsDecls, loaded]); // 侧栏“订单管理”上的数字:到期未处理的订单提醒(每分钟刷新一次) @@ -4942,7 +4967,7 @@ function MainApp({ username, onLogout }) { )} {view === 'customs' && ( - + )} {view === 'settings' && ( @@ -6061,7 +6086,7 @@ function printCustomsDecl(d, customers) { w.document.open(); w.document.write(html); w.document.close(); } -function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, setHsList, customers, orders, notify }) { +function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, setHsList, hsDefs, setHsDefs, customers, orders, notify }) { const [selId, setSelId] = useState(null); const [tab, setTab] = useState('decls'); const [q, setQ] = useState(''); @@ -6084,16 +6109,16 @@ function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, set setDecls((prev) => prev.filter((x) => x.id !== d.id)); setSelId(null); notify('已删除'); } if (sel) return update(sel.id, p)} onBack={() => setSelId(null)} onDelete={() => remove(sel)} onDuplicate={() => duplicate(sel)} - customers={customers} orders={orders} shippers={shippers} shipperList={shipperList} hsList={hsList} setHsList={setHsList} notify={notify} />; + customers={customers} orders={orders} shippers={shippers} shipperList={shipperList} hsList={hsList} setHsList={setHsList} hsDefs={hsDefs} setHsDefs={setHsDefs} notify={notify} />; const tabs = (
- {[['decls', `报关单(${decls.length})`], ['shippers', `境内发货人(${shipperList.length})`], ['hs', `商品编码库(${hsList.length})`]].map(([k, l]) => ( + {[['decls', `报关单(${decls.length})`], ['shippers', `境内发货人(${shipperList.length})`], ['hs', `商品编码库(${new Set([...hsList.map((x) => x.hsCode), ...hsDefs.map((x) => x.hsCode)]).size})`]].map(([k, l]) => ( ))}
); if (tab === 'shippers') return <>{tabs}; - if (tab === 'hs') return <>{tabs}; + if (tab === 'hs') return <>{tabs}; 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))) @@ -6130,7 +6155,7 @@ function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, set ); } -function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, orders, shippers, shipperList, hsList, setHsList, notify }) { +function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, orders, shippers, shipperList, hsList, setHsList, hsDefs, setHsDefs, 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 })] })); @@ -6222,7 +6247,7 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
- +
成交数量 / 单位
setItem(it.id, { qty: e.target.value })} /> setItem(it.id, { unit: v })} />
第二数量 / 单位(可选)
setItem(it.id, { qty2: e.target.value })} /> setItem(it.id, { unit2: v })} />
@@ -6244,12 +6269,27 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or ); } // 商品编号(HS)+ 商品名称 + 申报要素:从编码库选,或手动填;同一个 HS 编码可以对应多个品名(各自的申报要素) +// 每个 HS 编码可以设置"要素名称"(品牌类型、出口享惠情况、用途……):选了编码就逐项填写,自动用"|"拼成规格型号(申报要素) const hsKey = (x) => `${String(x.hsCode || '').trim()}|${String(x.name || '').trim()}`; -function HsPicker({ it, hsList, setHsList, setItem, notify }) { +// 所有编码通用的前两项,海关有固定的代码 +const CD_ELEM_BUILTIN = { + '品牌类型': [['0', '无品牌'], ['1', '境内自主品牌'], ['2', '境内收购品牌'], ['3', '境外品牌(贴牌生产)'], ['4', '境外品牌(其他)']], + '出口享惠情况': [['0', '出口货物在最终目的国(地区)不享受优惠关税'], ['1', '出口货物在最终目的国(地区)享受优惠关税'], ['2', '不能确定在最终目的国(地区)是否享受优惠关税']], +}; +const CD_DEFAULT_HS_DEFS = [ + { id: 'hsd_8507600099', hsCode: '8507600099', elements: ['品牌类型', '出口享惠情况', '用途', '电极材质(铅酸、镍镉、镍铁、镍氢、锂离子等)', '比能量', '品牌(中文或外文名称)', '型号', '容量', '是否含汞', '额定电压'].map((name) => ({ name, opts: [] })) }, +]; +const cdSplit = (spec) => String(spec || '').split('|'); +const cdElemDef = (defs, hs) => (defs || []).find((x) => x.hsCode === String(hs || '').trim()) || null; + +function HsPicker({ it, hsList, setHsList, defs, setDefs, setItem, notify }) { + const [editNames, setEditNames] = useState(false); const sorted = [...hsList].sort((a, b) => String(a.hsCode).localeCompare(String(b.hsCode)) || String(a.name).localeCompare(String(b.name), 'zh')); const sameHs = hsList.filter((x) => x.hsCode === it.hsCode.trim()); const entry = hsList.find((x) => hsKey(x) === hsKey(it)); + const def = cdElemDef(defs, it.hsCode); const canSave = it.hsCode.trim() && it.name.trim() && (!entry || (entry.spec || '') !== (it.spec || '')); + const parts = cdSplit(it.spec); function onHs(v) { v = v.replace(/[^\d.]/g, ''); const m = hsList.filter((x) => x.hsCode === v); @@ -6261,6 +6301,20 @@ function HsPicker({ it, hsList, setHsList, setItem, notify }) { const m = hsList.find((x) => x.name === v.trim() && (!it.hsCode.trim() || x.hsCode === it.hsCode.trim())); setItem(it.id, { name: v, ...(m ? { hsCode: it.hsCode.trim() || m.hsCode, ...(!it.spec.trim() || hsList.some((x) => x.spec === it.spec) ? { spec: m.spec || '' } : {}) } : {}) }); } + function setPart(i, v) { + const arr = cdSplit(it.spec); + const n = Math.max(arr.length, def.elements.length); + while (arr.length < n) arr.push(''); + arr[i] = String(v).replace(/\|/g, '/'); + while (arr.length > def.elements.length && arr[arr.length - 1] === '') arr.pop(); + setItem(it.id, { spec: arr.every((x) => x === '') ? '' : arr.join('|') }); + } + // 填过的值记下来,下次直接选 + function learn(i, v) { + v = String(v || '').trim(); if (!v || !def) return; + const el = def.elements[i]; if (!el || CD_ELEM_BUILTIN[el.name] || (el.opts || []).includes(v)) return; + setDefs((prev) => prev.map((d) => (d.id === def.id ? { ...d, elements: d.elements.map((e, k) => (k === i ? { ...e, opts: [v, ...(e.opts || [])].slice(0, 40) } : e)) } : d))); + } function save() { const rec = { hsCode: it.hsCode.trim(), name: it.name.trim(), spec: it.spec || '' }; if (entry) { @@ -6279,20 +6333,77 @@ function HsPicker({ it, hsList, setHsList, setItem, notify }) { {canSave && }
-