diff --git a/App.jsx b/App.jsx index 7a1d6b3..d4c68a2 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': '报关' }; -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 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 blankCustomer = () => ({ id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7), @@ -1697,8 +1697,17 @@ async function loadAll() { 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); } + let customsShippers = CD_DEFAULT_SHIPPERS, customsHs = []; + try { + const v = await storageGet(STORAGE_KEYS.customsShippers); + if (v && v.value) customsShippers = JSON.parse(v.value) || CD_DEFAULT_SHIPPERS; + } catch (e) { if (!e.notFound) failed.push(e.message); } + try { + 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); } if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; } - return { orders, customsDecls, 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, customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, tplPendingIds: tplPending.map(x => x.id), webAssets, webNews, webPackSpecs }; } /* -------------------------------- styles -------------------------------- */ @@ -2227,6 +2236,18 @@ const Styles = () => ( .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-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); } + .cd-tabs button { border: 0; background: none; padding: 8px 14px; font-size: 13.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 2.5px solid transparent; margin-bottom: -1px; } + .cd-tabs button.on { color: var(--ink); border-bottom-color: var(--ink); } + .cd-pick { margin-left: 10px; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 4px; background: var(--panel); color: var(--ink); max-width: 260px; } + .cd-hs-pick { display: flex !important; flex-direction: row !important; gap: 8px; align-items: center; } + .cd-hs-pick select { flex: 1; } + .cd-soft { font-weight: 500; color: var(--ink-soft); } + .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; } + @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); } .cd-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; padding: 16px 18px; } @@ -2873,6 +2894,8 @@ function MainApp({ username, onLogout }) { const [packingLists, setPackingLists] = useState([]); const [orders, setOrders] = useState([]); const [customsDecls, setCustomsDecls] = useState([]); + const [customsShippers, setCustomsShippers] = useState(CD_DEFAULT_SHIPPERS); + const [customsHs, setCustomsHs] = useState([]); const [selectedOrderId, setSelectedOrderId] = useState(null); const [packingSubView, setPackingSubView] = useState('list'); // 'list' | 'editor' const [packingDraft, setPackingDraft] = useState(null); @@ -2944,6 +2967,8 @@ function MainApp({ username, onLogout }) { setPackingLists(data.packingLists); setOrders(Array.isArray(data.orders) ? data.orders : []); setCustomsDecls(Array.isArray(data.customsDecls) ? data.customsDecls : []); + setCustomsShippers(Array.isArray(data.customsShippers) ? data.customsShippers : CD_DEFAULT_SHIPPERS); + setCustomsHs(Array.isArray(data.customsHs) ? data.customsHs : []); setCatalogDocs((data.catalogDocs || []).filter(d => d.fileName)); setJmsLines(data.jmsLines || []); setBackPanelTemplates(data.backPanelTemplates || []); @@ -2994,6 +3019,8 @@ 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.customsShippers, JSON.stringify(customsShippers)).then(() => clearSaveIssue(STORAGE_KEYS.customsShippers)).catch(reportSaveError); }, [customsShippers, 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]); // 侧栏“订单管理”上的数字:到期未处理的订单提醒(每分钟刷新一次) const [ordTick, setOrdTick] = useState(0); @@ -4915,7 +4942,7 @@ function MainApp({ username, onLogout }) { )} {view === 'customs' && ( - + )} {view === 'settings' && ( @@ -5968,14 +5995,17 @@ const CD_TERMS = [['EXW', '7'], ['FOB', '3'], ['CIF', '1'], ['C&F', '2'], ['C&I' const CD_COUNTRIES = ['白俄罗斯', '俄罗斯', '哈萨克斯坦', '乌兹别克斯坦', '吉尔吉斯斯坦', '塔吉克斯坦', '土库曼斯坦', '阿塞拜疆', '亚美尼亚', '格鲁吉亚', '蒙古', '阿联酋', '沙特阿拉伯', '伊拉克', '伊朗', '土耳其', '埃及', '尼日利亚', '肯尼亚', '南非', '委内瑞拉', '印度', '越南', '印度尼西亚', '马来西亚', '泰国', '菲律宾']; const CD_UNITS = ['个', '台', '套', '件', '只', '块', '箱', '千克']; const cdId = (p) => p + '_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6); +// 境内发货人(可在"报关 → 境内发货人"里增删改,默认的那个新建报关时自动填上) +const CD_DEFAULT_SHIPPERS = [{ id: 'cds_jyd', name: '北京金亿达博瑞科技发展有限公司', code: '91110106558542706K', isDefault: true }]; +const cdDefaultShipper = (list) => (list || []).find((x) => x.isDefault) || (list || [])[0] || null; 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) => ({ +const blankCustomsDecl = (prev, shipper) => ({ id: cdId('cd'), date: todayStr(), customerId: '', orderId: '', - shipper: prev ? prev.shipper : '', shipperCode: prev ? prev.shipperCode : '', producerSame: true, producer: '', producerCode: '', + shipper: shipper ? shipper.name : '', shipperCode: shipper ? shipper.code : '', producerSame: true, producer: '', producerCode: '', contractNo: '', tradeCountry: '', packages: '', grossWeight: '', netWeight: '', terms: prev ? prev.terms : 'EXW', items: [blankCdItem()], notes: '', createdAt: new Date().toISOString(), }); @@ -6031,8 +6061,9 @@ function printCustomsDecl(d, customers) { w.document.open(); w.document.write(html); w.document.close(); } -function CustomsPage({ decls, setDecls, customers, orders, notify }) { +function CustomsPage({ decls, setDecls, shipperList, setShipperList, hsList, setHsList, customers, orders, notify }) { const [selId, setSelId] = useState(null); + const [tab, setTab] = useState('decls'); 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))); @@ -6040,7 +6071,7 @@ function CustomsPage({ decls, setDecls, customers, orders, notify }) { 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); + const d = blankCustomsDecl(last, cdDefaultShipper(shipperList)); setDecls((prev) => [...prev, d]); setSelId(d.id); } function duplicate(d) { @@ -6053,13 +6084,23 @@ function CustomsPage({ decls, setDecls, customers, orders, notify }) { 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} notify={notify} />; + customers={customers} orders={orders} shippers={shippers} shipperList={shipperList} hsList={hsList} setHsList={setHsList} notify={notify} />; + const tabs = ( +
+ {[['decls', `报关单(${decls.length})`], ['shippers', `境内发货人(${shipperList.length})`], ['hs', `商品编码库(${hsList.length})`]].map(([k, l]) => ( + + ))} +
+ ); + if (tab === 'shippers') 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))) .sort((a, b) => (b.date || '').localeCompare(a.date || '') || String(b.createdAt).localeCompare(String(a.createdAt))); return ( <> + {tabs}
setQ(e.target.value)} placeholder="搜合同协议号、发货人、客户、商品、HS 编码" />
@@ -6089,7 +6130,7 @@ function CustomsPage({ decls, setDecls, customers, orders, notify }) { ); } -function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, orders, shippers, notify }) { +function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, orders, shippers, shipperList, hsList, setHsList, 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 })] })); @@ -6128,10 +6169,13 @@ 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="选择或手动填写公司全称" /> + {[...new Set([...shipperList.map((x) => x.name), ...shippers])].map((x) => +
生产销售单位 @@ -6178,9 +6222,7 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
- - -