const app = getApp(); Page({ data: { requirementTypes: [ { value: 'new_feature', label: '新功能需求' }, { value: 'cooperation', label: '合作需求' }, { value: 'advertising', label: '广告投放' }, { value: 'miniapp_dev', label: '小程序开发' }, { value: 'software_custom', label: '软件定制' }, { value: 'other', label: '其他需求' } ], selectedType: '', // 选中的需求类型 title: '', // 需求标题 description: '', // 功能描述 contactInfo: '', // 联系方式(微信号) submitButtonDisabled: false, // 提交按钮是否禁用 showTypeSelector: false // 是否显示类型选择器 }, onLoad: function(e) { }, onShow: function() { var t = this; t.resetData(); app.getCurrentTabbar(2, this); app.checkUpdateVersion(); app.getUserInfo().then(() => { console.log('获取用户信息完成'); }).catch(error => { console.error('获取用户信息失败:', error); }).finally(() => { console.log('getUserInfo调用完成'); }); }, resetData: function() { // 重置页面数据为默认值 this.setData({ selectedType: '', title: '', description: '', contactInfo: '', submitButtonDisabled: false, showTypeSelector: false }); }, // 显示需求类型选择器 showTypeSelector() { this.setData({ showTypeSelector: true }); }, // 隐藏需求类型选择器 hideTypeSelector() { this.setData({ showTypeSelector: false }); }, // 选择需求类型 selectType(e) { const type = e.currentTarget.dataset.type; const label = e.currentTarget.dataset.label; this.setData({ selectedType: type, selectedTypeLabel: label, showTypeSelector: false }); }, // 处理标题输入 onTitleInput(e) { this.setData({ title: e.detail.value }); }, // 处理描述输入 onDescriptionInput(e) { this.setData({ description: e.detail.value }); }, // 处理联系方式输入 onContactInput(e) { this.setData({ contactInfo: e.detail.value }); }, // 验证表单 validateForm() { const { selectedType, description, contactInfo } = this.data; if (!selectedType) { wx.showToast({ title: '请选择需求类型', icon: 'none' }); return false; } if (!description.trim()) { wx.showToast({ title: '请填写功能描述', icon: 'none' }); return false; } if (!contactInfo.trim()) { wx.showToast({ title: '请填写微信号', icon: 'none' }); return false; } return true; }, // 提交需求 submitRequirement() { if (!this.validateForm()) { return; } // 禁用提交按钮 this.setData({ submitButtonDisabled: true }); wx.showLoading({ title: '正在提交...', }); const { selectedType, title, description, contactInfo } = this.data; // 调用后端需求提交接口 app.apiRequest({ url: '/myapp/submit_requirement/', method: 'POST', data: { openid: wx.getStorageSync('openid'), nickname: wx.getStorageSync('uuid'), requirement_type: selectedType, title: title, description: description, contact_info: contactInfo, wechat_id: contactInfo // 使用同一个值作为微信号 }, success: (res) => { wx.hideLoading(); this.setData({ submitButtonDisabled: false }); if (res.data.success) { wx.showModal({ title: "提交成功", content: res.data.message || "需求提交成功,我们会尽快处理您的需求", showCancel: false, confirmText: "确定", success: () => { // 重置表单 this.resetData(); } }); } else { wx.showToast({ title: res.data.error || '提交失败,请稍后重试', icon: 'none' }); } }, fail: (err) => { wx.hideLoading(); this.setData({ submitButtonDisabled: false }); console.error('请求失败:', err); // 处理常见错误 if (err.statusCode === 400) { wx.showToast({ title: '请检查填写信息', icon: 'none' }); } else if (err.statusCode === 404) { wx.showToast({ title: '用户信息异常,请重新登录', icon: 'none' }); } else { wx.showToast({ title: '网络异常,请稍后重试', icon: 'none' }); } } }); }, // 清空表单 clearForm() { wx.showModal({ title: "提示", content: "确定要清空所有内容吗?", success: (res) => { if (res.confirm) { this.resetData(); wx.showToast({ title: '已清空内容', icon: 'none' }); } } }); } });