const { marketingApi } = require('../../utils/api'); Page({ data: { productName: '', description: '', category: '', target: 'US importers', style: 'professional', results: [], keywords: [], loading: false, activeTab: 'generate', }, onLoad() {}, switchTab(e) { const tab = e.currentTarget.dataset.tab; this.setData({ activeTab: tab }); }, onInput(e) { const field = e.currentTarget.dataset.field; this.setData({ [field]: e.detail.value }); }, onTargetChange(e) { this.setData({ target: e.detail.value }); }, onStyleChange(e) { this.setData({ style: e.detail.value }); }, async generateContent() { const { productName, description, target, style } = this.data; if (!productName || !description) { wx.showToast({ title: '请填写产品信息', icon: 'none' }); return; } this.setData({ loading: true }); try { const result = await marketingApi.generate(productName, description, this.data.category, target, style); this.setData({ results: result.results.filter(r => r.content), loading: false, }); } catch (err) { wx.showToast({ title: err.message || '生成失败', icon: 'none' }); this.setData({ loading: false }); } }, async generateKeywords() { const { productName, description } = this.data; if (!productName || !description) { wx.showToast({ title: '请填写产品信息', icon: 'none' }); return; } this.setData({ loading: true }); try { const result = await marketingApi.getKeywords(productName, description, this.data.category); this.setData({ keywords: result.keywords, loading: false, }); } catch (err) { wx.showToast({ title: err.message || '生成失败', icon: 'none' }); this.setData({ loading: false }); } }, copyText(e) { const text = e.currentTarget.dataset.text; wx.setClipboardData({ data: text, success: () => { wx.showToast({ title: '已复制', icon: 'success' }); }, }); }, clear() { this.setData({ productName: '', description: '', category: '', results: [], keywords: [], }); }, });