Update App.jsx via upload script - 2026-11-17 11:09:35
This commit is contained in:
parent
524d932b03
commit
0e552923de
185
App.jsx
185
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' && (
|
||||
<CustomsPage decls={customsDecls} setDecls={setCustomsDecls} customers={customers} orders={orders} notify={notify} />
|
||||
<CustomsPage decls={customsDecls} setDecls={setCustomsDecls} shipperList={customsShippers} setShipperList={setCustomsShippers} hsList={customsHs} setHsList={setCustomsHs} customers={customers} orders={orders} notify={notify} />
|
||||
)}
|
||||
|
||||
{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 <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} />;
|
||||
customers={customers} orders={orders} shippers={shippers} shipperList={shipperList} hsList={hsList} setHsList={setHsList} notify={notify} />;
|
||||
const tabs = (
|
||||
<div className="cd-tabs">
|
||||
{[['decls', `报关单(${decls.length})`], ['shippers', `境内发货人(${shipperList.length})`], ['hs', `商品编码库(${hsList.length})`]].map(([k, l]) => (
|
||||
<button key={k} className={tab === k ? 'on' : ''} onClick={() => setTab(k)}>{l}</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
if (tab === 'shippers') return <>{tabs}<ShipperManager list={shipperList} setList={setShipperList} notify={notify} /></>;
|
||||
if (tab === 'hs') return <>{tabs}<HsManager list={hsList} setList={setHsList} 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 (
|
||||
<>
|
||||
{tabs}
|
||||
<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>
|
||||
|
|
@ -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
|
|||
<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>
|
||||
<div className="field cd-span2"><span className="field-label">境内发货人
|
||||
<select className="cd-pick" value="" onChange={(e) => { const x = shipperList.find((y) => y.id === e.target.value); if (x) set({ shipper: x.name, shipperCode: x.code }); }}>
|
||||
<option value="">从"境内发货人"里选…</option>{shipperList.map((x) => <option key={x.id} value={x.id}>{x.name}</option>)}
|
||||
</select></span>
|
||||
<input className="input" list="cd-shippers" value={d.shipper} onChange={(e) => { const v = e.target.value; const x = shipperList.find((y) => y.name === v); set({ shipper: v, ...(x ? { shipperCode: x.code } : {}) }); }} placeholder="选择或手动填写公司全称" />
|
||||
<datalist id="cd-shippers">{[...new Set([...shipperList.map((x) => x.name), ...shippers])].map((x) => <option key={x} value={x} />)}</datalist>
|
||||
</div>
|
||||
<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">生产销售单位
|
||||
|
|
@ -6178,9 +6222,7 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
|
|||
<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>
|
||||
<HsPicker it={it} hsList={hsList} setHsList={setHsList} setItem={setItem} notify={notify} />
|
||||
<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>
|
||||
|
|
@ -6201,6 +6243,115 @@ function CustomsEditor({ d, update, onBack, onDelete, onDuplicate, customers, or
|
|||
</>
|
||||
);
|
||||
}
|
||||
// 商品编号(HS)+ 商品名称 + 申报要素:从编码库选,或手动填;同一个 HS 编码可以对应多个品名(各自的申报要素)
|
||||
const hsKey = (x) => `${String(x.hsCode || '').trim()}|${String(x.name || '').trim()}`;
|
||||
function HsPicker({ it, hsList, setHsList, setItem, notify }) {
|
||||
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 canSave = it.hsCode.trim() && it.name.trim() && (!entry || (entry.spec || '') !== (it.spec || ''));
|
||||
function onHs(v) {
|
||||
v = v.replace(/[^\d.]/g, '');
|
||||
const m = hsList.filter((x) => x.hsCode === v);
|
||||
const p = { hsCode: v };
|
||||
if (m.length === 1 && !it.name.trim()) { p.name = m[0].name; if (!it.spec.trim()) p.spec = m[0].spec || ''; }
|
||||
setItem(it.id, p);
|
||||
}
|
||||
function onName(v) {
|
||||
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 save() {
|
||||
const rec = { hsCode: it.hsCode.trim(), name: it.name.trim(), spec: it.spec || '' };
|
||||
if (entry) {
|
||||
if (!window.confirm(`更新编码库里"${rec.hsCode} · ${rec.name}"的申报要素?`)) return;
|
||||
setHsList((prev) => prev.map((x) => (x.id === entry.id ? { ...x, spec: rec.spec, updatedAt: new Date().toISOString() } : x)));
|
||||
notify('已更新编码库');
|
||||
} else { setHsList((prev) => [...prev, { id: cdId('hs'), ...rec, createdAt: new Date().toISOString() }]); notify('已存入编码库,以后可以直接选'); }
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div className="field cd-span3 cd-hs-pick">
|
||||
<select className="input" value="" onChange={(e) => { const x = hsList.find((y) => y.id === e.target.value); if (x) setItem(it.id, { hsCode: x.hsCode, name: x.name, spec: x.spec || '' }); }}>
|
||||
<option value="">{hsList.length ? `从商品编码库选择(${hsList.length} 条)…` : '商品编码库还是空的:填好下面的编码和名称后点"存入编码库"'}</option>
|
||||
{sorted.map((x) => <option key={x.id} value={x.id}>{x.hsCode} · {x.name}</option>)}
|
||||
</select>
|
||||
{canSave && <button type="button" className="btn btn-sm" onClick={save}><Save size={12} />{entry ? '更新编码库的申报要素' : '存入编码库'}</button>}
|
||||
</div>
|
||||
<label className="field"><span className="field-label">商品编号(HS)</span>
|
||||
<input className="input crm-mono" list="cd-hs-codes" value={it.hsCode} onChange={(e) => onHs(e.target.value)} placeholder="8504401990" />
|
||||
<datalist id="cd-hs-codes">{[...new Set(hsList.map((x) => x.hsCode))].map((c) => <option key={c} value={c}>{hsList.filter((x) => x.hsCode === c).map((x) => x.name).join(' / ')}</option>)}</datalist>
|
||||
</label>
|
||||
<label className="field cd-span2"><span className="field-label">商品名称{sameHs.length > 1 && <small className="cd-soft"> 这个编码有 {sameHs.length} 个品名:{sameHs.map((x) => x.name).join('、')}</small>}</span>
|
||||
<input className="input" list={`cd-hs-names-${it.id}`} value={it.name} onChange={(e) => onName(e.target.value)} placeholder="如:电源系统" />
|
||||
<datalist id={`cd-hs-names-${it.id}`}>{(sameHs.length ? sameHs : hsList).map((x) => <option key={x.id} value={x.name}>{x.hsCode}</option>)}</datalist>
|
||||
</label>
|
||||
<label className="field cd-span3"><span className="field-label">规格型号(申报要素){entry && (entry.spec || '') !== (it.spec || '') && <small className="cd-hint"> 和编码库里的不一样(只改这一单没关系;要以后都用,点上面"更新编码库")</small>}</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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ShipperManager({ list, setList, notify }) {
|
||||
const upd = (id, p) => setList((prev) => prev.map((x) => (x.id === id ? { ...x, ...p } : x)));
|
||||
const setDefault = (id) => setList((prev) => prev.map((x) => ({ ...x, isDefault: x.id === id })));
|
||||
const add = () => setList((prev) => [...prev, { id: cdId('cds'), name: '', code: '', isDefault: !prev.length }]);
|
||||
const del = (x) => { if (!window.confirm(`删除境内发货人"${x.name || '(未填)'}"?已经录好的报关单不受影响。`)) return; setList((prev) => { const n = prev.filter((y) => y.id !== x.id); if (x.isDefault && n[0]) n[0] = { ...n[0], isDefault: true }; return n; }); };
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header"><div className="panel-title">境内发货人</div><button className="btn btn-sm btn-primary" onClick={add}><Plus size={13} />添加境内发货人</button></div>
|
||||
<div className="panel-body" style={{ padding: '12px 16px', display: 'grid', gap: 8 }}>
|
||||
<div className="cd-note">新建报关时自动填上"默认"的那个;录入报关时也可以从这里选。改动自动保存。</div>
|
||||
{list.length === 0 && <div className="empty-state">还没有境内发货人,点右上角添加</div>}
|
||||
{list.map((x) => (
|
||||
<div key={x.id} className="cd-lib-row cd-ship-row">
|
||||
<input className="input" value={x.name} onChange={(e) => upd(x.id, { name: e.target.value })} placeholder="公司全称" />
|
||||
<input className="input crm-mono" value={x.code} onChange={(e) => upd(x.id, { code: e.target.value.toUpperCase().replace(/\s/g, '') })} placeholder="统一社会信用代码(18 位)" />
|
||||
<label className="cd-check" style={{ margin: 0 }}><input type="radio" checked={!!x.isDefault} onChange={() => setDefault(x.id)} />默认</label>
|
||||
<button className="btn btn-sm btn-ghost btn-danger" onClick={() => del(x)}><Trash2 size={13} /></button>
|
||||
{x.code && x.code.length !== 18 && <small className="cd-hint" style={{ gridColumn: '1 / -1' }}>统一社会信用代码一般是 18 位,现在是 {x.code.length} 位</small>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function HsManager({ list, setList, notify }) {
|
||||
const [q, setQ] = useState('');
|
||||
const upd = (id, p) => setList((prev) => prev.map((x) => (x.id === id ? { ...x, ...p, updatedAt: new Date().toISOString() } : x)));
|
||||
const add = () => { setQ(''); setList((prev) => [{ id: cdId('hs'), hsCode: '', name: '', spec: '', createdAt: new Date().toISOString() }, ...prev]); };
|
||||
const del = (x) => { if (!window.confirm(`从编码库删除"${x.hsCode} · ${x.name}"?已经录好的报关单不受影响。`)) return; setList((prev) => prev.filter((y) => y.id !== x.id)); };
|
||||
const s = q.trim().toLowerCase();
|
||||
const shown = list.filter((x) => !s || [x.hsCode, x.name, x.spec].some((v) => String(v || '').toLowerCase().includes(s)));
|
||||
const dup = new Set(); const seen = new Set();
|
||||
for (const x of list) { const k = hsKey(x); if (x.hsCode && x.name && seen.has(k)) dup.add(k); seen.add(k); }
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header"><div className="panel-title">商品编码库</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<div className="cd-search" style={{ minWidth: 220 }}><Search size={13} /><input value={q} onChange={(e) => setQ(e.target.value)} placeholder="搜编码、品名、申报要素" /></div>
|
||||
<button className="btn btn-sm btn-primary" onClick={add}><Plus size={13} />添加</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="panel-body" style={{ padding: '12px 16px', display: 'grid', gap: 8 }}>
|
||||
<div className="cd-note">一条 = 商品编号(HS)+ 商品名称 + 申报要素。同一个 HS 编码可以有多个品名,各自的申报要素不同。录入报关时选一条就会自动填好这三项(申报要素在报关单里还可以再改)。录报关时填的新编码,也可以在那里点"存入编码库"。</div>
|
||||
{list.length === 0 && <div className="empty-state">编码库还是空的,点右上角"添加",或者在录入报关时点"存入编码库"</div>}
|
||||
{shown.map((x) => (
|
||||
<div key={x.id} className="cd-lib-row cd-hs-row">
|
||||
<input className="input crm-mono" value={x.hsCode} onChange={(e) => upd(x.id, { hsCode: e.target.value.replace(/[^\d.]/g, '') })} placeholder="HS 编码" />
|
||||
<input className="input" value={x.name} onChange={(e) => upd(x.id, { name: e.target.value })} placeholder="商品名称" />
|
||||
<textarea className="textarea crm-mono" rows={2} value={x.spec} onChange={(e) => upd(x.id, { spec: e.target.value })} placeholder="申报要素,如 1|0|稳定输出电压用|直流稳压电源|2kW|+/-10%|义达牌|无型号" />
|
||||
<button className="btn btn-sm btn-ghost btn-danger" onClick={() => del(x)}><Trash2 size={13} /></button>
|
||||
{dup.has(hsKey(x)) && <small className="cd-hint" style={{ gridColumn: '1 / -1' }}>编码和品名都相同的有多条,选的时候容易混,建议删掉一条</small>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UnitInput({ value, onChange }) {
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
Loading…
Reference in New Issue