diff --git a/pages/personal/personal.js b/pages/personal/personal.js index 2ccfd8c..e2c4256 100644 --- a/pages/personal/personal.js +++ b/pages/personal/personal.js @@ -22,6 +22,11 @@ Page({ feedbackContent: '', canSubmit: false, isSubmitting: false, + + // 反馈类型相关 + feedbackTypes: [], // 反馈类型列表 + currentFeedbackType: '', // 当前选中的反馈类型 + selectedFeedbackTypeLabel: '', // 当前选中的反馈类型名称 // 编辑相关 newNickname: '', @@ -40,12 +45,68 @@ Page({ isUpdatingNickname: false, // 消息数字 - totalToday: 0 + totalToday: 0, + + // 文本域焦点 + textareaFocus: false }, onLoad() { this.gettoday() + this.getfwpj() + }, + + // 反馈建议和服务评价 + getfwpj() { + http.fkfw({ + data: { + dictType: 'feedback_type' + }, + success: res => { + console.log('获取反馈类型成功', res) + if (res.code === 200 && res.rows && res.rows.length > 0) { + this.setData({ + feedbackTypes: res.rows, + // 默认选中第一个 + currentFeedbackType: res.rows[0].dictValue, + selectedFeedbackTypeLabel: res.rows[0].dictLabel + }) + } else { + // 如果没有获取到数据,设置默认值 + this.setDefaultFeedbackTypes() + } + }, + fail: err => { + console.error('获取反馈类型失败', err) + // 失败时设置默认值 + this.setDefaultFeedbackTypes() + } + }) + }, + + // 设置默认反馈类型 + setDefaultFeedbackTypes() { + const defaultTypes = [ + { dictValue: '1', dictLabel: '功能建议' }, + { dictValue: '2', dictLabel: '体验反馈' }, + { dictValue: '3', dictLabel: '问题反馈' }, + { dictValue: '4', dictLabel: '其他' } + ] + this.setData({ + feedbackTypes: defaultTypes, + currentFeedbackType: '1', + selectedFeedbackTypeLabel: '功能建议' + }) + }, + // 选择反馈类型 + selectFeedbackType(e) { + const type = e.currentTarget.dataset.type + const label = e.currentTarget.dataset.label + this.setData({ + currentFeedbackType: type, + selectedFeedbackTypeLabel: label + }) }, onShow() { @@ -56,7 +117,6 @@ Page({ this.gettoday() }, - // 获取用户信息 getUserInfo() { http.UserInfo({ @@ -71,11 +131,9 @@ Page({ }) // 更新缓存 wx.setStorageSync('userInfo', res.data) - }, fail: (err) => { console.error('获取用户信息失败:', err) - } }) }, @@ -107,9 +165,7 @@ Page({ return } - const { - avatarUrl - } = e.detail + const { avatarUrl } = e.detail if (!avatarUrl) { this.showToast('选择头像失败') return @@ -133,47 +189,47 @@ Page({ filePath: avatarUrl, name: 'file', success: (uploadRes) => { - - const result = JSON.parse(uploadRes.data) - console.log('上传结果', result) - - if (result && result.fileName) { - // 获取上传后的文件路径 - const uploadedFilePath = result.fileName - this.setData({ - avatarUrl: uploadedFilePath, - }) - - // 更新缓存中的用户信息 - const cachedUserInfo = wx.getStorageSync('userInfo') || {} - if (!cachedUserInfo.user) { - cachedUserInfo.user = {} - } - cachedUserInfo.user.avatar = uploadedFilePath - wx.setStorageSync('userInfo', cachedUserInfo) - // 更新头像的API - http.revise({ - data: { - avatar: uploadedFilePath - }, - success: (res) => { - console.log('头像更新成功') - wx.hideLoading() - this.showToast('头像更新成功') - // 4. 重新获取用户信息以确保数据同步 - setTimeout(() => { - this.getUserInfo() - }, 500) - }, - fail: (err) => { - console.error('头像更新失败:', err) - wx.hideLoading() - this.showToast('头像保存失败,请重试') - } - }) - } else { - throw new Error('上传失败:返回数据格式错误') + const result = JSON.parse(uploadRes.data) + console.log('上传结果', result) + + if (result && result.fileName) { + // 获取上传后的文件路径 + const uploadedFilePath = result.fileName + this.setData({ + avatarUrl: uploadedFilePath, + }) + + // 更新缓存中的用户信息 + const cachedUserInfo = wx.getStorageSync('userInfo') || {} + if (!cachedUserInfo.user) { + cachedUserInfo.user = {} } + cachedUserInfo.user.avatar = uploadedFilePath + wx.setStorageSync('userInfo', cachedUserInfo) + + // 更新头像的API + http.revise({ + data: { + avatar: uploadedFilePath + }, + success: (res) => { + console.log('头像更新成功') + wx.hideLoading() + this.showToast('头像更新成功') + // 4. 重新获取用户信息以确保数据同步 + setTimeout(() => { + this.getUserInfo() + }, 500) + }, + fail: (err) => { + console.error('头像更新失败:', err) + wx.hideLoading() + this.showToast('头像保存失败,请重试') + } + }) + } else { + throw new Error('上传失败:返回数据格式错误') + } }, fail: (err) => { wx.hideLoading() @@ -303,6 +359,8 @@ Page({ // 显示反馈弹窗 showFeedback() { + // 刷新反馈类型数据 + this.getfwpj() this.setData({ showFeedbackModal: true, feedbackContent: '', @@ -322,7 +380,7 @@ Page({ // 反馈内容输入 onFeedbackInput(e) { const content = e.detail.value - const canSubmit = content.trim().length > 0 + const canSubmit = content.trim().length > 0 && this.data.currentFeedbackType this.setData({ feedbackContent: content, @@ -333,19 +391,26 @@ Page({ // 提交反馈 submitFeedback() { if (!this.data.canSubmit || this.data.isSubmitting) return + const content = this.data.feedbackContent.trim() if (content.length < 5) { this.showToast('请填写详细的反馈内容') return } + if (!this.data.currentFeedbackType) { + this.showToast('请选择反馈类型') + return + } + this.setData({ isSubmitting: true }) http.feedback({ data: { - content: content + content: content, + feedbackType: this.data.currentFeedbackType // 添加反馈类型字段 }, success: res => { if (res.code == 200) { @@ -356,7 +421,10 @@ Page({ this.setData({ isSubmitting: false, showFeedbackModal: false, - textareaFocus: false + textareaFocus: false, + feedbackContent: '', + currentFeedbackType: this.data.feedbackTypes.length > 0 ? this.data.feedbackTypes[0].dictValue : '', + selectedFeedbackTypeLabel: this.data.feedbackTypes.length > 0 ? this.data.feedbackTypes[0].dictLabel : '' }) }, fail: (err) => { @@ -411,11 +479,11 @@ Page({ onPullDownRefresh() { this.getUserInfo() this.gettoday() // 刷新消息数 + this.getfwpj() // 刷新反馈类型 setTimeout(() => { wx.stopPullDownRefresh() this.showToast('刷新成功') }, 1000) - }, - + } }) \ No newline at end of file diff --git a/pages/personal/personal.wxml b/pages/personal/personal.wxml index eaa4275..e505a0a 100644 --- a/pages/personal/personal.wxml +++ b/pages/personal/personal.wxml @@ -1,6 +1,6 @@ - - + +