const app = getApp(); const auth = require('../../utils/auth'); const fbSvc = require('../../services/feedback'); Page({ data: { statusBarHeight: 20, content: '', contact: '', count: 0, maxLen: 1000, submitting: false }, onLoad() { this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 }); }, onContentInput(e) { const content = e.detail.value; this.setData({ content, count: content.length }); }, onContactInput(e) { this.setData({ contact: e.detail.value }); }, onSubmit() { const content = (this.data.content || '').trim(); if (!content) { wx.showToast({ title: '请填写留言内容', icon: 'none' }); return; } if (this.data.submitting) return; this.setData({ submitting: true }); wx.showLoading({ title: '提交中…', mask: true }); fbSvc .submit(content, (this.data.contact || '').trim()) .then(() => { wx.hideLoading(); this.setData({ submitting: false, content: '', contact: '', count: 0 }); wx.showModal({ title: '已收到反馈', content: '感谢你的留言,我们会认真查看!', showCancel: false, confirmText: '好的' }); }) .catch((err) => { wx.hideLoading(); this.setData({ submitting: false }); const msg = (err && err.message) || '提交失败,请稍后再试'; wx.showToast({ title: msg, icon: 'none' }); }); } });