import { mockAccount } from '../../services/api'; Page({ data: { account: mockAccount, capital: '', saving: false, resetting: false, }, onLoad() { const app = getApp(); const acc = app.globalData.account || mockAccount; this.setData({ account: acc, capital: String(acc.total_capital) }); }, onCapitalInput(e: WechatMiniprogram.CustomEvent) { this.setData({ capital: e.detail.value as string }); }, onSaveCapital() { const cap = parseFloat(this.data.capital); if (!cap || cap <= 0) { wx.showToast({ title: '请输入有效金额', icon: 'none' }); return; } this.setData({ saving: true }); setTimeout(() => { const acc = { ...mockAccount, total_capital: cap, current_capital: cap }; getApp().globalData.account = acc; this.setData({ saving: false, account: acc }); wx.showToast({ title: '已保存' }); }, 500); }, onReset() { wx.showModal({ title: '确认重置', content: '将清空所有交易数据,确定吗?', success: (res) => { if (res.confirm) { this.setData({ resetting: true }); setTimeout(() => { const acc = { ...mockAccount, current_capital: mockAccount.total_capital, consecutive_losses: 0, trading_locked_until: null, status: 'tradable' as const }; getApp().globalData.account = acc; this.setData({ resetting: false, account: acc }); wx.showToast({ title: '已重置' }); }, 500); } }, }); }, });