Update App.jsx via upload script - 2026-11-16 21:59:38

This commit is contained in:
mike 2026-11-16 21:59:59 +08:00
parent 51aa7d8684
commit 232149c692
1 changed files with 337 additions and 0 deletions

337
App.jsx
View File

@ -2220,6 +2220,63 @@ 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; } }
/* 沟通记录 */
.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; }
.cv-add { display: grid; gap: 8px; padding: 12px; border: 1.5px dashed var(--line); border-radius: 10px; background: var(--bg); margin-bottom: 12px; }
.cv-add.drag { border-color: #2563eb; background: #eef4ff; }
.cv-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cv-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.cv-chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--ink); }
.cv-chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.cv-files { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cv-file { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; color: var(--ink); text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-file button { border: 0; background: none; cursor: pointer; padding: 0 0 0 2px; color: var(--ink-soft); display: inline-flex; }
.cv-ai { border: 1px solid #c7d7fe; background: linear-gradient(180deg, #f5f8ff, #fff 60%); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.cv-ai-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cv-ai-badge { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; font-weight: 700; color: #3538cd; }
.cv-stage { font-size: 12px; font-weight: 700; background: #3538cd; color: #fff; padding: 2px 10px; border-radius: 99px; }
.cv-intent { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 99px; }
.cv-intent.i-h { background: #dcfce7; color: #166534; } .cv-intent.i-m { background: #fef3c7; color: #92400e; } .cv-intent.i-l { background: #eef2f7; color: #475467; }
.cv-ai-meta { font-size: 11.5px; color: var(--ink-soft); }
.cv-stale { font-size: 11.5px; font-weight: 600; color: #b42318; background: #fef1ef; padding: 2px 8px; border-radius: 6px; }
.cv-sum { margin: 10px 0 4px; font-size: 13.5px; line-height: 1.6; }
.cv-reason { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 8px; }
.cv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin-top: 8px; }
.cv-ai h4 { margin: 0 0 4px; font-size: 12.5px; color: #3538cd; }
.cv-grid ul, .cv-grid p { margin: 0; font-size: 13px; line-height: 1.55; }
.cv-grid ul { padding-left: 18px; }
.cv-grid .warn h4 { color: #b54708; } .cv-grid .risk h4 { color: #b42318; }
.cv-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cv-tbl td { border-bottom: 1px solid var(--line); padding: 3px 6px 3px 0; vertical-align: top; }
.cv-next { margin-top: 12px; display: grid; gap: 5px; }
.cv-act { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.cv-act small { color: var(--ink-soft); margin-left: auto; white-space: nowrap; }
.cv-pri { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; flex: none; }
.cv-pri.p-h { background: #fee2e2; color: #991b1b; } .cv-pri.p-m { background: #fef3c7; color: #92400e; } .cv-pri.p-l { background: #eef2f7; color: #475467; }
.cv-fu { margin-top: 12px; border-top: 1px dashed #c7d7fe; padding-top: 10px; }
.cv-fu-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.cv-fu-sub { font-size: 12.5px; font-weight: 600; margin: 4px 0; }
.cv-fu-msg { white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.55; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 6px 0; max-height: 320px; overflow: auto; }
.cv-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; }
.cv-tags span { font-size: 11.5px; background: #eef2ff; color: #3538cd; border-radius: 99px; padding: 2px 9px; }
.cv-ask { display: flex; gap: 6px; margin-bottom: 8px; }
.cv-ask .input { flex: 1; }
.cv-answer { font-size: 13px; background: #f5f8ff; border: 1px solid #c7d7fe; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; line-height: 1.55; white-space: pre-wrap; }
.cv-answer b { display: block; font-size: 12px; color: #3538cd; margin-bottom: 2px; }
.cv-filter { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.cv-list { display: grid; gap: 8px; }
.cv-item { border: 1px solid var(--line); border-left: 4px solid; border-radius: 9px; padding: 8px 10px; background: var(--bg); }
.cv-item-h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.cv-item-h small { color: var(--ink-soft); font-size: 11.5px; }
.cv-ch { color: #fff; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 5px; }
.cv-title { font-weight: 600; }
.cv-note { font-size: 11.5px; color: #b54708; margin-top: 4px; }
.cv-text { white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 12.5px; line-height: 1.5; margin: 6px 0 0; color: var(--ink); max-height: 120px; overflow: hidden; }
.cv-text.open { max-height: 480px; overflow: auto; }
.cv-item-f { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.cv-edit { display: grid; gap: 8px; }
@media (max-width: 760px) { .cv-grid { grid-template-columns: 1fr; } }
.brand-vis { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; font-weight: 500; }
.brand-vis button { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; font-size: 11px; padding: 1px 8px; cursor: pointer; color: var(--ink-soft); }
.brand-vis button.on { background: var(--ink); color: #fff; }
@ -3144,6 +3201,7 @@ function MainApp({ username, onLogout }) {
if (!window.confirm('确定删除该客户档案?此操作不可恢复。')) return;
setCustomers(prev => prev.filter(c => c.id !== id));
if (selectedId === id) setSelectedId(null);
fetch(`/api/convos/${id}`, { method: 'DELETE', credentials: 'same-origin' }).catch(() => {}); // 沟通记录一起删
notify('已删除');
}
function togglePreferredContact(id, channel) {
@ -4158,6 +4216,8 @@ function MainApp({ username, onLogout }) {
onTogglePreferred={(channel) => togglePreferredContact(selected.id, channel)}
onToggleVip={() => toggleVip(selected.id)}
onToggleOrdered={() => toggleOrdered(selected.id)}
onNotify={notify}
onPatchCustomer={(patch) => setCustomers(prev => prev.map(x => (x.id === selected.id ? { ...x, ...patch } : x)))}
attachmentNote={attachmentNote}
setAttachmentNote={setAttachmentNote}
attachmentCategory={attachmentCategory}
@ -6191,6 +6251,280 @@ function folderPathLabel(folders, folderId) {
return parts.join(' / ');
}
/* ------------------------------ 客户沟通记录 + AI 分析 ------------------------------ */
// 记录和客户的沟通(邮件、WhatsApp、微信、电话、会议……):粘贴文字,或拖入 WhatsApp 导出(.txt / .zip)、邮件(.eml)、截图(自动识别文字)、PDF、Word。
// 数据存在服务器的 conversations.json(不放进客户列表);AI 分析读这个客户的全部记录,给出总结、阶段、意向、需求、顾虑、下一步和跟进消息草稿。
const CONVO_CH = {
email: { label: '邮件', color: '#2563eb' },
whatsapp: { label: 'WhatsApp', color: '#16a34a' },
wechat: { label: '微信', color: '#15803d' },
phone: { label: '电话', color: '#9333ea' },
meeting: { label: '会议 / 面谈', color: '#c2410c' },
other: { label: '其他', color: '#64748b' },
};
const convoApi = async (method, url, body, isForm) => {
const r = await fetch(url, { method, credentials: 'same-origin', headers: isForm || !body ? undefined : { 'Content-Type': 'application/json' }, body: isForm ? body : body ? JSON.stringify(body) : undefined });
const j = await r.json().catch(() => ({}));
if (!r.ok) throw new Error(j.error || `请求失败(${r.status})`);
return j;
};
const cvToday = () => new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().slice(0, 10);
function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
const [data, setData] = useState(null);
const [adding, setAdding] = useState(false);
const [form, setForm] = useState({ channel: '', date: cvToday(), title: '', text: '', files: [] });
const [saving, setSaving] = useState(false);
const [drag, setDrag] = useState(false);
const [open, setOpen] = useState({});
const [editId, setEditId] = useState(null);
const [edit, setEdit] = useState(null);
const [q, setQ] = useState('');
const [chFilter, setChFilter] = useState('all');
const [aiBusy, setAiBusy] = useState(false);
const [aiSecs, setAiSecs] = useState(0);
const [ask, setAsk] = useState('');
const [answer, setAnswer] = useState(null);
const [asking, setAsking] = useState(false);
const fileRef = useRef(null);
const load = async () => {
try { setData(await convoApi('GET', `/api/convos/${c.id}`)); }
catch (e) { setData({ items: [], analysis: null }); onNotify('读取沟通记录失败:' + e.message); }
};
useEffect(() => { setData(null); setAnswer(null); setAdding(false); setEditId(null); load(); }, [c.id]);
const items = (data && data.items) || [];
const an = data && data.analysis;
const newer = an ? items.filter(x => (x.createdAt || 0) > an.at || (x.updatedAt || 0) > an.at).length : 0;
const addFiles = (list) => setForm(f => ({ ...f, files: [...f.files, ...Array.from(list || [])].slice(0, 10) }));
async function submit() {
if (!form.text.trim() && !form.files.length) { onNotify('请粘贴沟通内容或添加文件'); return; }
const fd = new FormData();
['channel', 'date', 'title', 'text'].forEach(k => fd.append(k, form[k] || ''));
form.files.forEach(f => fd.append('files', f));
setSaving(true);
try {
const j = await convoApi('POST', `/api/convos/${c.id}`, fd, true);
setData(d => ({ ...(d || {}), items: [...((d && d.items) || []), j.item] }));
setForm({ channel: '', date: cvToday(), title: '', text: '', files: [] });
setAdding(false);
onNotify(`已添加:${CONVO_CH[j.item.channel]?.label || ''}${j.item.stats?.messages ? `,${j.item.stats.messages} 条消息` : ''}`);
} catch (e) { onNotify('添加失败:' + e.message); }
finally { setSaving(false); }
}
async function saveEdit() {
try {
const j = await convoApi('PUT', `/api/convos/${c.id}/${editId}`, edit);
setData(d => ({ ...d, items: d.items.map(x => (x.id === editId ? j.item : x)) }));
setEditId(null); onNotify('已保存');
} catch (e) { onNotify('保存失败:' + e.message); }
}
async function del(it) {
if (!window.confirm(`删除这条${CONVO_CH[it.channel]?.label || ''}记录(${it.date}${it.title ? ' · ' + it.title : ''})?附件也会一起删除。`)) return;
try { await convoApi('DELETE', `/api/convos/${c.id}/${it.id}`); setData(d => ({ ...d, items: d.items.filter(x => x.id !== it.id) })); onNotify('已删除'); }
catch (e) { onNotify('删除失败:' + e.message); }
}
async function analyze() {
setAiBusy(true); setAiSecs(0);
const t0 = Date.now(), tick = setInterval(() => setAiSecs(Math.round((Date.now() - t0) / 1000)), 1000);
try {
const { jobId } = await convoApi('POST', `/api/convos/${c.id}/analyze`);
for (;;) {
await new Promise(r => setTimeout(r, 2000));
const j = await convoApi('GET', `/api/ai/jobs/${jobId}`);
if (j.status === 'running') continue;
if (j.status === 'done' && j.data && j.data.analysis) { setData(d => ({ ...d, analysis: j.data.analysis })); onNotify('AI 分析完成'); }
else throw new Error((j.data && j.data.error) || 'AI 分析失败');
break;
}
} catch (e) { onNotify('AI 分析失败:' + e.message); }
finally { clearInterval(tick); setAiBusy(false); }
}
async function doAsk() {
if (!ask.trim()) return;
setAsking(true); setAnswer(null);
try { const j = await convoApi('POST', `/api/convos/${c.id}/ask`, { question: ask.trim() }); setAnswer({ q: ask.trim(), a: j.answer }); }
catch (e) { onNotify('提问失败:' + e.message); }
finally { setAsking(false); }
}
const copy = (t) => { navigator.clipboard.writeText(t).then(() => onNotify('已复制'), () => onNotify('复制失败,请手动选择')); };
const nq = q.trim().toLowerCase();
const shown = [...items]
.filter(x => chFilter === 'all' || x.channel === chFilter)
.filter(x => !nq || [x.title, x.text, ...(x.files || []).map(f => f.name)].some(v => String(v || '').toLowerCase().includes(nq)))
.sort((a, b) => String(b.date).localeCompare(String(a.date)) || (b.createdAt || 0) - (a.createdAt || 0));
const R = an && an.result;
const waDigits = String(c.phone || '').replace(/[^\d]/g, '');
return (
<div className="field cv-wrap">
<div className="cv-head">
<span className="field-label" style={{ margin: 0 }}>沟通记录{items.length ? `(${items.length})` : ''}</span>
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
<button className="btn btn-sm" onClick={() => setAdding(a => !a)}><Plus size={13} />添加沟通记录</button>
<button className="btn btn-sm btn-primary" disabled={!items.length || aiBusy} onClick={analyze} title={items.length ? '' : '先添加沟通记录'}>
<Sparkles size={13} />{aiBusy ? `AI 分析中… ${aiSecs}s` : an ? '重新 AI 分析' : 'AI 分析'}
</button>
</div>
</div>
{adding && (
<div className={`cv-add${drag ? ' drag' : ''}`}
onDragOver={e => { e.preventDefault(); setDrag(true); }} onDragLeave={() => setDrag(false)}
onDrop={e => { e.preventDefault(); setDrag(false); addFiles(e.dataTransfer.files); }}>
<div className="cv-add-row">
<div className="cv-chips">
<button type="button" className={`cv-chip${!form.channel ? ' on' : ''}`} onClick={() => setForm(f => ({ ...f, channel: '' }))}>自动识别</button>
{Object.entries(CONVO_CH).map(([k, v]) => (
<button type="button" key={k} className={`cv-chip${form.channel === k ? ' on' : ''}`} style={form.channel === k ? { background: v.color, borderColor: v.color } : undefined} onClick={() => setForm(f => ({ ...f, channel: k }))}>{v.label}</button>
))}
</div>
<input type="date" className="input" style={{ width: 150 }} value={form.date} onChange={e => setForm(f => ({ ...f, date: e.target.value }))} title="沟通日期(邮件会自动用邮件日期)" />
</div>
<input className="input" placeholder="标题(可选,例如:首次询价 / 报价跟进;邮件会自动用主题)" value={form.title} onChange={e => setForm(f => ({ ...f, title: e.target.value }))} />
<textarea className="textarea" rows={7} value={form.text} onChange={e => setForm(f => ({ ...f, text: e.target.value }))}
placeholder={'把邮件、WhatsApp / 微信聊天、电话或会议记录粘贴到这里…\n\n也可以把文件拖到这个框里:\n· WhatsApp 导出的聊天(.txt 或 .zip):聊天 → ⋮ → 更多 → 导出聊天\n· 邮件文件(.eml):邮箱里"另存为 / 下载原始邮件"\n· 聊天截图(自动识别文字,英文和中文)、PDF、Word(.docx)'} />
<div className="cv-files">
{form.files.map((f, i) => (
<span key={i} className="cv-file"><Paperclip size={11} />{f.name}<button type="button" onClick={() => setForm(x => ({ ...x, files: x.files.filter((_, k) => k !== i) }))}><X size={11} /></button></span>
))}
<button type="button" className="btn btn-sm btn-ghost" onClick={() => fileRef.current && fileRef.current.click()}><Upload size={12} />选择文件</button>
<input ref={fileRef} type="file" multiple hidden accept=".txt,.zip,.eml,.pdf,.docx,.html,.htm,.csv,.md,image/*" onChange={e => { addFiles(e.target.files); e.target.value = ''; }} />
</div>
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end' }}>
<button className="btn btn-sm btn-ghost" onClick={() => setAdding(false)}>取消</button>
<button className="btn btn-sm btn-primary" disabled={saving} onClick={submit}>{saving ? '识别中…' : '保存'}</button>
</div>
</div>
)}
{/* AI 分析结果 */}
{R && (
<div className="cv-ai">
<div className="cv-ai-top">
<span className="cv-ai-badge"><Sparkles size={12} />AI 分析</span>
{R.stage && <span className="cv-stage">{R.stage}</span>}
{R.intent && <span className={`cv-intent i-${R.intent === '高' ? 'h' : R.intent === '中' ? 'm' : 'l'}`}>意向:{R.intent}</span>}
<span className="cv-ai-meta">{new Date(an.at).toLocaleString('zh-CN', { hour12: false })} · 基于 {an.count} 条记录{an.skipped ? `(最早 ${an.skipped} 条太长未放入)` : ''}</span>
{newer > 0 && <span className="cv-stale">有 {newer} 条新记录,建议重新分析</span>}
</div>
{R.summary && <p className="cv-sum">{R.summary}</p>}
{R.intentReason && <div className="cv-reason">{R.intentReason}</div>}
<div className="cv-grid">
{Array.isArray(R.needs) && R.needs.length > 0 && <div><h4>客户需求</h4><ul>{R.needs.map((x, i) => <li key={i}>{x}</li>)}</ul></div>}
{Array.isArray(R.products) && R.products.length > 0 && (
<div><h4>意向产品</h4>
<table className="cv-tbl"><tbody>{R.products.map((p, i) => <tr key={i}><td><b>{p.model}</b></td><td>{p.qty}</td><td>{p.notes}</td></tr>)}</tbody></table>
{onPatchCustomer && <button className="btn btn-sm btn-ghost" style={{ marginTop: 4 }} onClick={() => { onPatchCustomer({ intendedModel: R.products.map(p => p.model).filter(Boolean).join(', '), intendedQty: R.products.map(p => p.qty).filter(Boolean).join(', ') }); onNotify('已填入客户档案的意向型号 / 数量'); }}>填入客户档案的意向型号 / 数量</button>}
</div>
)}
{[['价格 / 付款', R.price], ['时间要求', R.timeline], ['决策人 / 流程', R.decision], ['竞争对手', R.competitors]].filter(x => x[1]).map(([h, v]) => <div key={h}><h4>{h}</h4><p>{v}</p></div>)}
{Array.isArray(R.concerns) && R.concerns.length > 0 && <div><h4>客户顾虑</h4><ul>{R.concerns.map((x, i) => <li key={i}>{x}</li>)}</ul></div>}
{Array.isArray(R.promises) && R.promises.length > 0 && <div className="warn"><h4>我们答应过的事</h4><ul>{R.promises.map((x, i) => <li key={i}>{x}</li>)}</ul></div>}
{Array.isArray(R.risks) && R.risks.length > 0 && <div className="risk"><h4>风险</h4><ul>{R.risks.map((x, i) => <li key={i}>{x}</li>)}</ul></div>}
</div>
{Array.isArray(R.nextActions) && R.nextActions.length > 0 && (
<div className="cv-next"><h4>下一步</h4>
{R.nextActions.map((a, i) => <div key={i} className="cv-act"><span className={`cv-pri p-${a.priority === '高' ? 'h' : a.priority === '中' ? 'm' : 'l'}`}>{a.priority || '—'}</span><span>{a.action}</span>{a.when && <small>{a.when}</small>}</div>)}
</div>
)}
{R.followUp && R.followUp.message && (
<div className="cv-fu">
<div className="cv-fu-h"><h4>跟进消息草稿{R.customerLanguage ? `(${R.customerLanguage})` : ''}</h4>
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
<button className="btn btn-sm" onClick={() => copy((R.followUp.subject ? R.followUp.subject + '\n\n' : '') + R.followUp.message)}><Copy size={12} />复制</button>
{c.email && <a className="btn btn-sm" href={`mailto:${c.email}?subject=${encodeURIComponent(R.followUp.subject || '')}&body=${encodeURIComponent(R.followUp.message)}`}><Mail size={12} />用邮件打开</a>}
{waDigits.length >= 7 && <a className="btn btn-sm" href={`https://wa.me/${waDigits}?text=${encodeURIComponent(R.followUp.message)}`} target="_blank" rel="noreferrer"><MessageCircle size={12} />用 WhatsApp 打开</a>}
</div>
</div>
{R.followUp.subject && <div className="cv-fu-sub">主题:{R.followUp.subject}</div>}
<pre className="cv-fu-msg">{R.followUp.message}</pre>
<small style={{ color: 'var(--ink-soft)' }}>草稿里 [ ] 的地方请自己填(价格、交期等),发出前请检查。</small>
</div>
)}
{Array.isArray(R.tags) && R.tags.length > 0 && <div className="cv-tags">{R.tags.map((t, i) => <span key={i}>{t}</span>)}</div>}
</div>
)}
{/* 问 AI */}
{items.length > 0 && (
<div className="cv-ask">
<input className="input" value={ask} onChange={e => setAsk(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') doAsk(); }} placeholder="问 AI 关于这个客户的沟通,比如:我们上次报的什么价?他要的后备时间是多少?" />
<button className="btn btn-sm" disabled={asking || !ask.trim()} onClick={doAsk}><Sparkles size={12} />{asking ? '思考中…' : '提问'}</button>
</div>
)}
{answer && <div className="cv-answer"><b>问:{answer.q}</b><div>{answer.a}</div></div>}
{/* 记录列表 */}
{items.length > 0 && (
<div className="cv-filter">
<div className="cv-chips">
{[['all', '全部'], ...Object.entries(CONVO_CH).filter(([k]) => items.some(x => x.channel === k)).map(([k, v]) => [k, v.label])].map(([k, l]) => (
<button type="button" key={k} className={`cv-chip${chFilter === k ? ' on' : ''}`} onClick={() => setChFilter(k)}>{l}{k !== 'all' ? ` ${items.filter(x => x.channel === k).length}` : ''}</button>
))}
</div>
<div style={{ position: 'relative', flex: '0 1 240px' }}>
<Search size={13} style={{ position: 'absolute', left: 9, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-soft)' }} />
<input className="input" style={{ paddingLeft: 28 }} value={q} onChange={e => setQ(e.target.value)} placeholder="搜索记录内容" />
</div>
</div>
)}
{data === null ? <div className="row-sub" style={{ padding: '8px 0' }}>加载中…</div>
: items.length === 0 ? <div className="row-sub" style={{ padding: '8px 0' }}>还没有沟通记录。点"添加沟通记录",粘贴邮件或聊天内容,或拖入 WhatsApp 导出文件、邮件、截图。</div>
: shown.length === 0 ? <div className="row-sub" style={{ padding: '8px 0' }}>没有匹配的记录</div>
: (
<div className="cv-list">
{shown.map(it => {
const ch = CONVO_CH[it.channel] || CONVO_CH.other;
const isOpen = !!open[it.id];
const lines = String(it.text || '').split('\n');
return (
<div key={it.id} className="cv-item" style={{ borderLeftColor: ch.color }}>
{editId === it.id ? (
<div className="cv-edit">
<div className="cv-add-row">
<select className="input" style={{ width: 'auto' }} value={edit.channel} onChange={e => setEdit(x => ({ ...x, channel: e.target.value }))}>{Object.entries(CONVO_CH).map(([k, v]) => <option key={k} value={k}>{v.label}</option>)}</select>
<input type="date" className="input" style={{ width: 150 }} value={edit.date} onChange={e => setEdit(x => ({ ...x, date: e.target.value }))} />
<input className="input" style={{ flex: 1 }} value={edit.title} placeholder="标题" onChange={e => setEdit(x => ({ ...x, title: e.target.value }))} />
</div>
<textarea className="textarea" rows={8} value={edit.text} onChange={e => setEdit(x => ({ ...x, text: e.target.value }))} />
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end' }}>
<button className="btn btn-sm btn-ghost" onClick={() => setEditId(null)}>取消</button>
<button className="btn btn-sm btn-primary" onClick={saveEdit}>保存</button>
</div>
</div>
) : (
<>
<div className="cv-item-h">
<span className="cv-ch" style={{ background: ch.color }}>{ch.label}</span>
<b>{it.date}</b>
{it.title && <span className="cv-title">{it.title}</span>}
{it.stats && it.stats.messages ? <small>{it.stats.messages} 条消息{it.stats.people ? ` · ${it.stats.people.map(p => p.n).slice(0, 3).join('、')}` : ''}{it.stats.media ? ` · ${it.stats.media} 个图片/附件未导入` : ''}</small> : null}
<span style={{ marginLeft: 'auto', display: 'flex', gap: 4 }}>
<button className="btn btn-sm btn-ghost" title="编辑" onClick={() => { setEditId(it.id); setEdit({ channel: it.channel, date: it.date, title: it.title || '', text: it.text || '' }); }}><Edit2 size={12} /></button>
<button className="btn btn-sm btn-ghost btn-danger" title="删除" onClick={() => del(it)}><Trash2 size={12} /></button>
</span>
</div>
{(it.notes || []).map((n, i) => <div key={i} className="cv-note">{n}</div>)}
{it.text && <pre className={`cv-text${isOpen ? ' open' : ''}`}>{isOpen ? it.text : lines.slice(0, 5).join('\n')}</pre>}
<div className="cv-item-f">
{lines.length > 5 && <button className="btn btn-sm btn-ghost" onClick={() => setOpen(o => ({ ...o, [it.id]: !isOpen }))}>{isOpen ? '收起' : `展开全部(${lines.length} 行)`}</button>}
{(it.files || []).map(f => <a key={f.stored} className="cv-file" href={`/uploads/${c.id}/${encodeURIComponent(f.stored)}`} target="_blank" rel="noreferrer"><Paperclip size={11} />{f.name}</a>)}
</div>
</>
)}
</div>
);
})}
</div>
)}
</div>
);
}
function CustomerDetail({
customer: c, now, onEdit, onDelete,
onTogglePreferred, onToggleVip, onToggleOrdered,
@ -6198,6 +6532,7 @@ function CustomerDetail({
attachmentFileNames, onPickAttachment, uploading, fileInputKey, onUploadAttachment, onDeleteAttachment, onMoveAttachment,
onCreateFolder, onRenameFolder, onDeleteFolder,
fileDragActive, onFileDragOver, onFileDragLeave, onFileDrop,
onNotify, onPatchCustomer,
}) {
const lt = localTimeInfo(c.country, now);
const preferred = c.preferredContacts || [];
@ -6292,6 +6627,8 @@ 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} />
<div className="field">
<span className="field-label">客户文件管理</span>