import { mockTaskDetails } from '../../utils/mock-data' import type { TaskDetail, Note } from '../../utils/mock-data' import { sortByTimestamp } from '../../utils/sort' Page({ data: { /** 页面状态 */ pageState: 'loading' as 'loading' | 'empty' | 'normal', /** 任务详情 */ detail: null as TaskDetail | null, /** 排序后的备注列表 */ sortedNotes: [] as Note[], /** 备注弹窗 */ noteModalVisible: false, }, onLoad(options) { const id = options?.id || '' this.loadData(id) }, loadData(id: string) { this.setData({ pageState: 'loading' }) setTimeout(() => { // TODO: 替换为真实 API 调用 const detail = mockTaskDetails.find((t) => t.id === id) || mockTaskDetails[0] if (!detail) { this.setData({ pageState: 'empty' }) return } const sorted = sortByTimestamp(detail.notes || []) as Note[] this.setData({ pageState: 'normal', detail, sortedNotes: sorted, }) }, 500) }, /** 点击"添加备注" */ onAddNote() { this.setData({ noteModalVisible: true }) }, /** 备注弹窗确认 */ onNoteConfirm(e: WechatMiniprogram.CustomEvent) { const { score, content } = e.detail wx.showToast({ title: '备注已保存', icon: 'success' }) this.setData({ noteModalVisible: false }) // 模拟添加到列表 const newNote: Note = { id: `note-${Date.now()}`, content, tagType: 'customer', tagLabel: `客户:${this.data.detail?.customerName || ''}`, createdAt: new Date().toLocaleString('zh-CN', { hour12: false }), } const notes = [newNote, ...this.data.sortedNotes] this.setData({ sortedNotes: notes }) }, /** 备注弹窗取消 */ onNoteCancel() { this.setData({ noteModalVisible: false }) }, /** 放弃任务 */ onAbandon() { wx.showModal({ title: '放弃任务', content: '确定要放弃该客户的维护吗?此操作不可撤销。', confirmColor: '#e34d59', success: (res) => { if (res.confirm) { wx.showToast({ title: '已放弃该客户的维护', icon: 'none' }) setTimeout(() => wx.navigateBack(), 1500) } }, }) }, /** 问问助手 */ onAskAssistant() { const customerId = this.data.detail?.id || '' wx.navigateTo({ url: `/pages/chat/chat?customerId=${customerId}`, fail: () => wx.showToast({ title: '页面跳转失败', icon: 'none' }), }) }, /** 标记完成 */ onMarkComplete() { wx.showToast({ title: '已标记完成', icon: 'success' }) setTimeout(() => wx.navigateBack(), 1500) }, /** 返回 */ onBack() { wx.navigateBack() }, })