"use client" import type React from "react" import { useState, useEffect } from "react" import { Card } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Switch } from "@/components/ui/switch" import { QrCode, X, ChevronDown, Plus, Maximize2, Upload, Download, Settings, Minus } from "lucide-react" import { TooltipProvider } from "@/components/ui/tooltip" import { Table, TableHeader, TableRow, TableHead, TableBody, TableCell } from "@/components/ui/table" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription, } from "@/components/ui/dialog" // 调整场景顺序,确保API获客在最后,并且前三个是最常用的场景 const scenarios = [ { id: "haibao", name: "海报获客", type: "material" }, { id: "order", name: "订单获客", type: "api" }, { id: "douyin", name: "抖音获客", type: "social" }, { id: "xiaohongshu", name: "小红书获客", type: "social" }, { id: "phone", name: "电话获客", type: "social" }, { id: "gongzhonghao", name: "公众号获客", type: "social" }, { id: "weixinqun", name: "微信群获客", type: "social" }, { id: "payment", name: "付款码获客", type: "material" }, { id: "api", name: "API获客", type: "api" }, // API获客放在最后 ] const phoneCallTags = [ { id: "tag-1", name: "咨询", color: "bg-blue-100 text-blue-800" }, { id: "tag-2", name: "投诉", color: "bg-red-100 text-red-800" }, { id: "tag-3", name: "合作", color: "bg-green-100 text-green-800" }, { id: "tag-4", name: "价格", color: "bg-orange-100 text-orange-800" }, { id: "tag-5", name: "售后", color: "bg-purple-100 text-purple-800" }, { id: "tag-6", name: "订单", color: "bg-yellow-100 text-yellow-800" }, { id: "tag-7", name: "物流", color: "bg-teal-100 text-teal-800" }, ] // 不同场景的预设标签 const scenarioTags = { haibao: [ { id: "poster-tag-1", name: "活动推广", color: "bg-blue-100 text-blue-800" }, { id: "poster-tag-2", name: "产品宣传", color: "bg-green-100 text-green-800" }, { id: "poster-tag-3", name: "品牌展示", color: "bg-purple-100 text-purple-800" }, { id: "poster-tag-4", name: "优惠促销", color: "bg-red-100 text-red-800" }, { id: "poster-tag-5", name: "新品发布", color: "bg-orange-100 text-orange-800" }, ], order: [ { id: "order-tag-1", name: "新订单", color: "bg-green-100 text-green-800" }, { id: "order-tag-2", name: "复购客户", color: "bg-blue-100 text-blue-800" }, { id: "order-tag-3", name: "高价值订单", color: "bg-purple-100 text-purple-800" }, { id: "order-tag-4", name: "待付款", color: "bg-yellow-100 text-yellow-800" }, { id: "order-tag-5", name: "已完成", color: "bg-gray-100 text-gray-800" }, ], douyin: [ { id: "douyin-tag-1", name: "短视频", color: "bg-pink-100 text-pink-800" }, { id: "douyin-tag-2", name: "直播", color: "bg-red-100 text-red-800" }, { id: "douyin-tag-3", name: "带货", color: "bg-orange-100 text-orange-800" }, { id: "douyin-tag-4", name: "粉丝互动", color: "bg-blue-100 text-blue-800" }, { id: "douyin-tag-5", name: "热门话题", color: "bg-purple-100 text-purple-800" }, ], xiaohongshu: [ { id: "xhs-tag-1", name: "种草笔记", color: "bg-red-100 text-red-800" }, { id: "xhs-tag-2", name: "美妆", color: "bg-pink-100 text-pink-800" }, { id: "xhs-tag-3", name: "穿搭", color: "bg-purple-100 text-purple-800" }, { id: "xhs-tag-4", name: "生活方式", color: "bg-green-100 text-green-800" }, { id: "xhs-tag-5", name: "好物推荐", color: "bg-orange-100 text-orange-800" }, ], phone: phoneCallTags, gongzhonghao: [ { id: "gzh-tag-1", name: "文章推送", color: "bg-blue-100 text-blue-800" }, { id: "gzh-tag-2", name: "活动通知", color: "bg-green-100 text-green-800" }, { id: "gzh-tag-3", name: "产品介绍", color: "bg-purple-100 text-purple-800" }, { id: "gzh-tag-4", name: "用户服务", color: "bg-orange-100 text-orange-800" }, { id: "gzh-tag-5", name: "品牌故事", color: "bg-gray-100 text-gray-800" }, ], weixinqun: [ { id: "wxq-tag-1", name: "群活动", color: "bg-green-100 text-green-800" }, { id: "wxq-tag-2", name: "产品分享", color: "bg-blue-100 text-blue-800" }, { id: "wxq-tag-3", name: "用户交流", color: "bg-purple-100 text-purple-800" }, { id: "wxq-tag-4", name: "优惠信息", color: "bg-pink-100 text-pink-800" }, { id: "wxq-tag-5", name: "答疑解惑", color: "bg-orange-100 text-orange-800" }, { id: "wxq-tag-6", name: "新人欢迎", color: "bg-yellow-100 text-yellow-800" }, { id: "wxq-tag-7", name: "群规通知", color: "bg-gray-100 text-gray-800" }, { id: "wxq-tag-8", name: "活跃互动", color: "bg-indigo-100 text-indigo-800" }, ], payment: [ { id: "pay-tag-1", name: "扫码支付", color: "bg-green-100 text-green-800" }, { id: "pay-tag-2", name: "线下门店", color: "bg-blue-100 text-blue-800" }, { id: "pay-tag-3", name: "活动收款", color: "bg-purple-100 text-purple-800" }, { id: "pay-tag-4", name: "服务费用", color: "bg-orange-100 text-orange-800" }, { id: "pay-tag-5", name: "会员充值", color: "bg-yellow-100 text-yellow-800" }, ], api: [ { id: "api-tag-1", name: "系统对接", color: "bg-blue-100 text-blue-800" }, { id: "api-tag-2", name: "数据同步", color: "bg-green-100 text-green-800" }, { id: "api-tag-3", name: "自动化", color: "bg-purple-100 text-purple-800" }, { id: "api-tag-4", name: "第三方平台", color: "bg-orange-100 text-orange-800" }, { id: "api-tag-5", name: "实时推送", color: "bg-gray-100 text-gray-800" }, ], } interface BasicSettingsProps { formData: any onChange: (data: any) => void onNext?: () => void } interface Account { id: string nickname: string avatar: string } interface Material { id: string name: string type: string preview: string } const posterTemplates = [ { id: "poster-1", name: "点击领取", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E9%A2%86%E5%8F%961-tipd1HI7da6qooY5NkhxQnXBnT5LGU.gif", }, { id: "poster-2", name: "点击合作", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%90%88%E4%BD%9C-LPlMdgxtvhqCSr4IM1bZFEFDBF3ztI.gif", }, { id: "poster-3", name: "点击咨询", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E5%92%A8%E8%AF%A2-FTiyAMAPop2g9LvjLOLDz0VwPg3KVu.gif", }, { id: "poster-4", name: "点击签到", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E7%AD%BE%E5%88%B0-94TZIkjLldb4P2jTVlI6MkSDg0NbXi.gif", }, { id: "poster-5", name: "点击了解", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E4%BA%86%E8%A7%A3-6GCl7mQVdO4WIiykJyweSubLsTwj71.gif", }, { id: "poster-6", name: "点击报名", preview: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/%E7%82%B9%E5%87%BB%E6%8A%A5%E5%90%8D-Mj0nnva0BiASeDAIhNNaRRAbjPgjEj.gif", }, ] const generateRandomAccounts = (count: number): Account[] => { return Array.from({ length: count }, (_, index) => ({ id: `account-${index + 1}`, nickname: `账号-${Math.random().toString(36).substring(2, 7)}`, avatar: `/placeholder.svg?height=40&width=40&text=${index + 1}`, })) } const generatePosterMaterials = (): Material[] => { return posterTemplates.map((template) => ({ id: template.id, name: template.name, type: "poster", preview: template.preview, })) } export function BasicSettings({ formData, onChange, onNext }: BasicSettingsProps) { const [isAccountDialogOpen, setIsAccountDialogOpen] = useState(false) const [isMaterialDialogOpen, setIsMaterialDialogOpen] = useState(false) const [isQRCodeOpen, setIsQRCodeOpen] = useState(false) const [isPreviewOpen, setIsPreviewOpen] = useState(false) const [isPhoneSettingsOpen, setIsPhoneSettingsOpen] = useState(false) const [previewImage, setPreviewImage] = useState("") const [accounts] = useState(generateRandomAccounts(50)) const [materials] = useState(generatePosterMaterials()) const [selectedAccounts, setSelectedAccounts] = useState( formData.accounts?.length > 0 ? formData.accounts : [], ) const [selectedMaterials, setSelectedMaterials] = useState( formData.materials?.length > 0 ? formData.materials : [], ) const [showAllScenarios, setShowAllScenarios] = useState(false) const [isImportDialogOpen, setIsImportDialogOpen] = useState(false) const [importedTags, setImportedTags] = useState< Array<{ phone: string wechat: string source?: string orderAmount?: number orderDate?: string }> >(formData.importedTags || []) const [selectedScenarioTags, setSelectedScenarioTags] = useState(formData.scenarioTags || []) const [customTagInput, setCustomTagInput] = useState("") const [customTags, setCustomTags] = useState>( formData.customTags || [], ) // 初始化电话获客设置 const [phoneSettings, setPhoneSettings] = useState({ autoAdd: formData.phoneSettings?.autoAdd ?? true, speechToText: formData.phoneSettings?.speechToText ?? true, questionExtraction: formData.phoneSettings?.questionExtraction ?? true, }) const [selectedPhoneTags, setSelectedPhoneTags] = useState(formData.phoneTags || []) const [phoneCallType, setPhoneCallType] = useState(formData.phoneCallType || "both") // 处理标签选择 const handleTagToggle = (tagId: string) => { const newTags = selectedPhoneTags.includes(tagId) ? selectedPhoneTags.filter((id) => id !== tagId) : [...selectedPhoneTags, tagId] setSelectedPhoneTags(newTags) onChange({ ...formData, phoneTags: newTags }) } // 处理通话类型选择 const handleCallTypeChange = (type: string) => { setPhoneCallType(type) onChange({ ...formData, phoneCallType: type }) } // 初始化时,如果没有选择场景,默认选择海报获客 useEffect(() => { if (!formData.scenario) { onChange({ ...formData, scenario: "haibao" }) } if (!formData.planName) { if (formData.materials?.length > 0) { const today = new Date().toLocaleDateString("zh-CN").replace(/\//g, "") onChange({ ...formData, planName: `海报${today}` }) } else { onChange({ ...formData, planName: "场景" }) } } }, [formData, onChange]) const handleScenarioSelect = (scenarioId: string) => { // 如果选择了电话获客,更新计划名称 if (scenarioId === "phone") { const today = new Date().toLocaleDateString("zh-CN").replace(/\//g, "") onChange({ ...formData, scenario: scenarioId, planName: `电话获客${today}` }) } else { onChange({ ...formData, scenario: scenarioId }) } } // 处理场景标签选择 const handleScenarioTagToggle = (tagId: string) => { const newTags = selectedScenarioTags.includes(tagId) ? selectedScenarioTags.filter((id) => id !== tagId) : [...selectedScenarioTags, tagId] setSelectedScenarioTags(newTags) onChange({ ...formData, scenarioTags: newTags }) } // 添加自定义标签 const handleAddCustomTag = () => { if (!customTagInput.trim()) return const colors = [ "bg-blue-100 text-blue-800", "bg-green-100 text-green-800", "bg-purple-100 text-purple-800", "bg-red-100 text-red-800", "bg-orange-100 text-orange-800", "bg-yellow-100 text-yellow-800", "bg-gray-100 text-gray-800", "bg-pink-100 text-pink-800", ] const newTag = { id: `custom-${Date.now()}`, name: customTagInput.trim(), color: colors[Math.floor(Math.random() * colors.length)], } const updatedCustomTags = [...customTags, newTag] setCustomTags(updatedCustomTags) setCustomTagInput("") onChange({ ...formData, customTags: updatedCustomTags }) } // 删除自定义标签 const handleRemoveCustomTag = (tagId: string) => { const updatedCustomTags = customTags.filter((tag) => tag.id !== tagId) setCustomTags(updatedCustomTags) onChange({ ...formData, customTags: updatedCustomTags }) // 同时从选中标签中移除 const updatedSelectedTags = selectedScenarioTags.filter((id) => id !== tagId) setSelectedScenarioTags(updatedSelectedTags) onChange({ ...formData, scenarioTags: updatedSelectedTags, customTags: updatedCustomTags }) } const handleAccountSelect = (account: Account) => { const updatedAccounts = [...selectedAccounts, account] setSelectedAccounts(updatedAccounts) onChange({ ...formData, accounts: updatedAccounts }) } const handleMaterialSelect = (material: Material) => { const updatedMaterials = [material] setSelectedMaterials(updatedMaterials) onChange({ ...formData, materials: updatedMaterials }) setIsMaterialDialogOpen(false) // 更新计划名称 const today = new Date().toLocaleDateString("zh-CN").replace(/\//g, "") onChange({ ...formData, planName: `海报${today}`, materials: updatedMaterials }) } const handleRemoveAccount = (accountId: string) => { const updatedAccounts = selectedAccounts.filter((a) => a.id !== accountId) setSelectedAccounts(updatedAccounts) onChange({ ...formData, accounts: updatedAccounts }) } const handleRemoveMaterial = (materialId: string) => { const updatedMaterials = selectedMaterials.filter((m) => m.id !== materialId) setSelectedMaterials(updatedMaterials) onChange({ ...formData, materials: updatedMaterials }) } const handlePreviewImage = (imageUrl: string) => { setPreviewImage(imageUrl) setIsPreviewOpen(true) } // 只显示前三个场景,其他的需要点击展开 const displayedScenarios = showAllScenarios ? scenarios : scenarios.slice(0, 3) const handleFileImport = (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (file) { const reader = new FileReader() reader.onload = (e) => { try { const content = e.target?.result as string const rows = content.split("\n").filter((row) => row.trim()) const tags = rows.slice(1).map((row) => { const [phone, wechat, source, orderAmount, orderDate] = row.split(",") return { phone: phone.trim(), wechat: wechat.trim(), source: source?.trim(), orderAmount: orderAmount ? Number(orderAmount) : undefined, orderDate: orderDate?.trim(), } }) setImportedTags(tags) onChange({ ...formData, importedTags: tags }) } catch (error) { console.error("导入失败:", error) } } reader.readAsText(file) } } const handleDownloadTemplate = () => { const template = "电话号码,微信号,来源,订单金额,下单日期\n13800138000,wxid_123,抖音,99.00,2024-03-03" const blob = new Blob([template], { type: "text/csv" }) const url = window.URL.createObjectURL(blob) const a = document.createElement("a") a.href = url a.download = "订单导入模板.csv" document.body.appendChild(a) a.click() document.body.removeChild(a) window.URL.revokeObjectURL(url) } // 处理电话获客设置更新 const handlePhoneSettingsUpdate = () => { onChange({ ...formData, phoneSettings }) setIsPhoneSettingsOpen(false) } return (
{displayedScenarios.map((scenario) => ( ))}
{!showAllScenarios && ( )}
onChange({ ...formData, planName: e.target.value })} placeholder="请输入计划名称" className="mt-2" />
{/* 场景标签选择 */} {formData.scenario && (
{/* 预设标签 */}
{(scenarioTags[formData.scenario as keyof typeof scenarioTags] || []).map((tag) => (
handleScenarioTagToggle(tag.id)} > {tag.name}
))}
{/* 自定义标签 */} {customTags.length > 0 && (
{customTags.map((tag) => (
handleScenarioTagToggle(tag.id)} > {tag.name}
))}
)} {/* 添加自定义标签 */}
setCustomTagInput(e.target.value)} placeholder="输入自定义标签名称" className="flex-1" maxLength={8} onKeyPress={(e) => { if (e.key === "Enter") { handleAddCustomTag() } }} />
{selectedScenarioTags.length > 0 && (
已选择 {selectedScenarioTags.length} 个标签
)}
)} {formData.scenario && ( <> {scenarios.find((s) => s.id === formData.scenario)?.type === "social" && formData.scenario !== "phone" && (
{selectedAccounts.length > 0 && (
{selectedAccounts.map((account) => (
{account.nickname} {account.nickname}
))}
)}
)} {/* 电话获客特殊设置 */} {formData.scenario === "phone" && (
自动添加客户
{phoneSettings.autoAdd ? "已开启" : "已关闭"}
语音转文字
{phoneSettings.speechToText ? "已开启" : "已关闭"}
问题提取
{phoneSettings.questionExtraction ? "已开启" : "已关闭"}

提示:电话获客功能将自动记录来电信息,并根据设置执行相应操作

)} {formData.scenario === "phone" && ( <> {/* 添加电话通话类型选择 */}
handleCallTypeChange(phoneCallType === "inbound" ? "both" : "outbound")} >
发起外呼
主动向客户发起电话
handleCallTypeChange(phoneCallType === "outbound" ? "both" : "inbound")} >
接收来电
接听客户的来电
{/* 添加标签功能 */}
{phoneCallTags.map((tag) => (
handleTagToggle(tag.id)} > {tag.name}
))}
)} {scenarios.find((s) => s.id === formData.scenario)?.type === "material" && (
{/* 海报展示区域 */}
{materials.map((material) => (
m.id === material.id) ? "ring-2 ring-blue-600" : "hover:ring-2 hover:ring-blue-600" }`} onClick={() => handleMaterialSelect(material)} > {material.name}
{material.name}
))}
{selectedMaterials.length > 0 && (
{selectedMaterials[0].name} handlePreviewImage(selectedMaterials[0].preview)} />
)}
)} {scenarios.find((s) => s.id === formData.scenario)?.id === "order" && (
{importedTags.length > 0 && (

已导入 {importedTags.length} 条数据

电话号码 微信号 来源 订单金额 {importedTags.slice(0, 5).map((tag, index) => ( {tag.phone} {tag.wechat} {tag.source} {tag.orderAmount} ))} {importedTags.length > 5 && ( 还有 {importedTags.length - 5} 条数据未显示 )}
)}
)} {formData.scenario === "weixinqun" && ( <>
自动欢迎新成员
新成员入群时自动发送欢迎消息
onChange({ ...formData, autoWelcome: checked })} />
群活跃度监控
监控群聊活跃度并自动互动
onChange({ ...formData, activityMonitor: checked })} />
{formData.syncCount || 3} 条内容到群
建议每日推送3-5条内容,避免过度打扰群成员
{["上午 9:00-12:00", "下午 14:00-17:00", "晚上 19:00-21:00"].map((time, index) => (
{ const currentTimes = formData.pushTimes || [] const newTimes = currentTimes.includes(index) ? currentTimes.filter((t: number) => t !== index) : [...currentTimes, index] onChange({ ...formData, pushTimes: newTimes }) }} > {time}
))}
)} )}
onChange({ ...formData, enabled: checked })} />
{/* 账号选择对话框 */} 选择账号
{accounts.map((account) => (
handleAccountSelect(account)} > {account.nickname} {selectedAccounts.find((a) => a.id === account.id) && (
)}
))}
{/* 二维码对话框 */} 绑定账号
二维码

请用相应的APP扫码

{/* 图片预览对话框 */} 海报预览
预览
{/* 电话获客设置对话框 */} 电话获客设置 配置电话获客的自动化功能,提高获客效率

来电后自动将客户添加为微信好友

推荐:开启此功能可提高转化率约30%

setPhoneSettings({ ...phoneSettings, autoAdd: checked })} className="data-[state=checked]:bg-blue-600" />

自动将通话内容转换为文字记录

支持普通话、粤语等多种方言识别

setPhoneSettings({ ...phoneSettings, speechToText: checked })} className="data-[state=checked]:bg-blue-600" />

自动从通话中提取客户的首句问题

AI智能识别客户意图,提高回复精准度

setPhoneSettings({ ...phoneSettings, questionExtraction: checked })} className="data-[state=checked]:bg-blue-600" />
{/* 订单导入对话框 */} 导入订单标签
电话号码 微信号 来源 订单金额 下单日期 {importedTags.map((tag, index) => ( {tag.phone} {tag.wechat} {tag.source} {tag.orderAmount} {tag.orderDate} ))}
) }