Update App.jsx via upload script - 2026-11-17 17:27:41

This commit is contained in:
mike 2026-11-17 17:28:01 +08:00
parent d4a1b20e66
commit 12554eda27
1 changed files with 38 additions and 4 deletions

42
App.jsx
View File

@ -2352,6 +2352,10 @@ const Styles = () => (
.cv-edit { display: grid; gap: 8px; }
@media (max-width: 760px) { .cv-grid { grid-template-columns: 1fr; } }
/* 沟通记录:聊天样式 */
.cv-q-qty { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-soft); white-space: nowrap; font-weight: 500; }
.cv-q-qty .input { width: 76px; height: 28px; font-size: 12.5px; }
.cv-q-chk { width: 16px; height: 16px; accent-color: #0f766e; cursor: pointer; }
.cv-q-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: #e6f6f3; border: 1px solid #99d5cc; font-size: 12.5px; color: #0f5e57; }
.cv-match-btn { background: #0f766e !important; border-color: #0f766e !important; }
.cv-match { border-color: #99d5cc; background: linear-gradient(180deg, #f0fbf8, #fff 60%); }
.cv-match .cv-ai-badge { color: #0f766e; }
@ -3912,6 +3916,18 @@ function MainApp({ username, onLogout }) {
setQuoteDraft(draft);
setQuoteSubView('editor');
}
// 从"AI 匹配产品"一键生成报价单:带上客户、型号、数量,单价留空手动填(以前报过的型号沿用当时的描述)
function createQuoteFromMatch(cust, picks) {
const draft = blankQuote('quote');
draft.number = suggestDocNumber(draft.date, quotes, 'quote');
if (cust) { draft.customerId = cust.id; draft.billToName = billPartyName(cust); }
draft.lineItems = picks.map((p, i) => {
const h = (priceHistory || []).find(x => x.description.split('\n')[0].trim().toUpperCase() === String(p.model).trim().toUpperCase());
return { ...blankLineItem(), id: 'li_' + Date.now() + '_' + i + Math.random().toString(36).slice(2, 5), description: h ? h.description : p.model, quantity: p.qty || '', rate: '' };
});
setQuoteDraft(draft); setQuoteSubView('editor'); setView('quotes');
notify(`已生成报价单草稿(${picks.length} 项),请填写单价后保存`);
}
function startEditQuote(q) {
setQuoteDraft({ ...q, lineItems: q.lineItems.map(li => ({ ...li })) });
setQuoteSubView('editor');
@ -4411,6 +4427,7 @@ function MainApp({ username, onLogout }) {
onToggleOrdered={() => toggleOrdered(selected.id)}
onNotify={notify}
onPatchCustomer={(patch) => setCustomers(prev => prev.map(x => (x.id === selected.id ? { ...x, ...patch } : x)))}
onCreateQuote={(picks) => createQuoteFromMatch(selected, picks)}
attachmentNote={attachmentNote}
setAttachmentNote={setAttachmentNote}
attachmentCategory={attachmentCategory}
@ -7346,7 +7363,7 @@ function CvBlocks({ blocks }) {
}
const cvBlocksSummary = (bl) => { const t = (bl || []).find(b => b.t === 'table'); return t ? `表格 ${t.rows.length} 行 × ${Math.max(...t.rows.map(r => r.reduce((a, c) => a + (c.cs || 1), 0)))} 列` : ''; };
function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
function ConversationPanel({ customer: c, onNotify, onPatchCustomer, onCreateQuote }) {
const custName = String(c.contact || '').replace(/\s*[((].*$/, '').trim() || c.company || '客户';
const [data, setData] = useState(null);
const [from, setFrom] = useState('customer');
@ -7370,6 +7387,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
const [mBusy, setMBusy] = useState(false);
const [mSecs, setMSecs] = useState(0);
const [mOpen, setMOpen] = useState(true);
const [qPick, setQPick] = useState({ at: 0, sel: {}, qty: {} }); // 生成报价单:勾选的型号、每组数量(换了一次匹配结果就重置)
const [ask, setAsk] = useState('');
const [answer, setAnswer] = useState(null);
const [asking, setAsking] = useState(false);
@ -7663,6 +7681,13 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
{/* AI 匹配产品结果 */}
{data && data.match && data.match.result && (() => {
const M = data.match.result;
const gq = (g) => { const m = String(g.qty || '').replace(/,/g, '').match(/\d+(\.\d+)?/); return m ? m[0] : ''; };
const pk = qPick.at === data.match.at ? qPick : { at: data.match.at, sel: {}, qty: {} };
const isSel = (gi, mi) => (pk.sel[`${gi}-${mi}`] !== undefined ? pk.sel[`${gi}-${mi}`] : mi === 0);
const qtyOf = (gi, g) => (pk.qty[gi] !== undefined ? pk.qty[gi] : gq(g));
const setPk = (fn) => setQPick(() => fn(pk));
const picks = [];
(M.groups || []).forEach((g, gi) => (g.matches || []).forEach((m, mi) => { if (isSel(gi, mi)) picks.push({ model: m.model, qty: qtyOf(gi, g), productId: m.productId }); }));
const fitCls = (f) => (/^符合/.test(f || '') ? 'f-h' : /基本/.test(f || '') ? 'f-m' : 'f-l');
const stale = items.filter(x => (x.createdAt || 0) > data.match.at || (x.updatedAt || 0) > data.match.at).length;
return (
@ -7677,10 +7702,13 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
{M.summary && <p className="cv-sum">{M.summary}</p>}
{(M.groups || []).map((g, gi) => (
<div key={gi} className="cv-mg">
<div className="cv-mg-h"><b>{g.need}</b>{g.qty ? <span>× {g.qty}</span> : null}</div>
<div className="cv-mg-h"><b>{g.need}</b>{g.qty ? <span>× {g.qty}</span> : null}
{(g.matches || []).length > 0 && onCreateQuote && <label className="cv-q-qty">报价数量 <input className="input" inputMode="numeric" value={qtyOf(gi, g)} onChange={e => { const v = e.target.value; setPk(p => ({ ...p, qty: { ...p.qty, [gi]: v } })); }} /></label>}
</div>
{(g.matches || []).length === 0 ? <div className="cv-mg-none">产品库里没有合适的型号{g.noMatch ? `:${g.noMatch}` : ''}</div> : (g.matches || []).map((m, mi) => (
<div key={mi} className="cv-mm">
<div className="cv-mm-h">
{onCreateQuote && <input type="checkbox" className="cv-q-chk" title="加入报价单" checked={isSel(gi, mi)} onChange={e => { const v = e.target.checked; setPk(p => ({ ...p, sel: { ...p.sel, [`${gi}-${mi}`]: v } })); }} />}
<span className={`cv-fit ${fitCls(m.fit)}`}>{m.fit || '接近'}</span>
<b>{m.model}</b>
<small>{[m.type || m.category, m.power].filter(Boolean).join(' · ')}</small>
@ -7698,6 +7726,12 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
{Array.isArray(M.questions) && M.questions.length > 0 && (
<div className="cv-grid" style={{ gridTemplateColumns: '1fr' }}><div className="warn"><h4>还需要跟客户确认</h4><ul>{M.questions.map((x, k) => <li key={k}>{x}</li>)}</ul></div></div>
)}
{onCreateQuote && (
<div className="cv-q-bar">
<span>勾选要报价的型号(默认每项需求的第一个),数量可以改</span>
<button className="btn btn-sm btn-primary" disabled={!picks.length} onClick={() => onCreateQuote(picks)}><FileText size={13} />一键生成报价单({picks.length} 项)</button>
</div>
)}
<div className="cv-ai-meta" style={{ marginTop: 8 }}>匹配结果只根据产品库里录入的参数;没录入的参数会列在"需确认"里,报价前请人工核对。</div>
</>)}
</div>
@ -7860,7 +7894,7 @@ function CustomerDetail({
attachmentFileNames, onPickAttachment, uploading, fileInputKey, onUploadAttachment, onDeleteAttachment, onMoveAttachment,
onCreateFolder, onRenameFolder, onDeleteFolder,
fileDragActive, onFileDragOver, onFileDragLeave, onFileDrop,
onNotify, onPatchCustomer,
onNotify, onPatchCustomer, onCreateQuote,
}) {
const lt = localTimeInfo(c.country, now);
const preferred = c.preferredContacts || [];
@ -7956,7 +7990,7 @@ function CustomerDetail({
{c.notes && <div className="field"><span className="field-label">客户背景信息调查</span><div style={{ fontSize: 12.5, whiteSpace: 'pre-wrap' }}>{c.notes}</div></div>}
<ConversationPanel customer={c} onNotify={onNotify || (() => {})} onPatchCustomer={onPatchCustomer} />
<ConversationPanel customer={c} onNotify={onNotify || (() => {})} onPatchCustomer={onPatchCustomer} onCreateQuote={onCreateQuote} />
<div className="field">
<span className="field-label">客户文件管理</span>