|
|
@ -23,6 +23,11 @@ Page({ |
|
|
canSubmit: false, |
|
|
canSubmit: false, |
|
|
isSubmitting: false, |
|
|
isSubmitting: false, |
|
|
|
|
|
|
|
|
|
|
|
// 反馈类型相关
|
|
|
|
|
|
feedbackTypes: [], // 反馈类型列表
|
|
|
|
|
|
currentFeedbackType: '', // 当前选中的反馈类型
|
|
|
|
|
|
selectedFeedbackTypeLabel: '', // 当前选中的反馈类型名称
|
|
|
|
|
|
|
|
|
// 编辑相关
|
|
|
// 编辑相关
|
|
|
newNickname: '', |
|
|
newNickname: '', |
|
|
|
|
|
|
|
|
@ -40,12 +45,68 @@ Page({ |
|
|
isUpdatingNickname: false, |
|
|
isUpdatingNickname: false, |
|
|
|
|
|
|
|
|
// 消息数字
|
|
|
// 消息数字
|
|
|
totalToday: 0 |
|
|
|
|
|
|
|
|
totalToday: 0, |
|
|
|
|
|
|
|
|
|
|
|
// 文本域焦点
|
|
|
|
|
|
textareaFocus: false |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onLoad() { |
|
|
onLoad() { |
|
|
this.gettoday() |
|
|
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() { |
|
|
onShow() { |
|
|
@ -56,7 +117,6 @@ Page({ |
|
|
this.gettoday() |
|
|
this.gettoday() |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
// 获取用户信息
|
|
|
getUserInfo() { |
|
|
getUserInfo() { |
|
|
http.UserInfo({ |
|
|
http.UserInfo({ |
|
|
@ -71,11 +131,9 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
// 更新缓存
|
|
|
// 更新缓存
|
|
|
wx.setStorageSync('userInfo', res.data) |
|
|
wx.setStorageSync('userInfo', res.data) |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
fail: (err) => { |
|
|
fail: (err) => { |
|
|
console.error('获取用户信息失败:', err) |
|
|
console.error('获取用户信息失败:', err) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
@ -107,9 +165,7 @@ Page({ |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
avatarUrl |
|
|
|
|
|
} = e.detail |
|
|
|
|
|
|
|
|
const { avatarUrl } = e.detail |
|
|
if (!avatarUrl) { |
|
|
if (!avatarUrl) { |
|
|
this.showToast('选择头像失败') |
|
|
this.showToast('选择头像失败') |
|
|
return |
|
|
return |
|
|
@ -133,47 +189,47 @@ Page({ |
|
|
filePath: avatarUrl, |
|
|
filePath: avatarUrl, |
|
|
name: 'file', |
|
|
name: 'file', |
|
|
success: (uploadRes) => { |
|
|
success: (uploadRes) => { |
|
|
|
|
|
const result = JSON.parse(uploadRes.data) |
|
|
|
|
|
console.log('上传结果', result) |
|
|
|
|
|
|
|
|
const result = JSON.parse(uploadRes.data) |
|
|
|
|
|
console.log('上传结果', result) |
|
|
|
|
|
|
|
|
|
|
|
if (result && result.fileName) { |
|
|
|
|
|
// 获取上传后的文件路径
|
|
|
|
|
|
const uploadedFilePath = result.fileName |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
avatarUrl: uploadedFilePath, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
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 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) => { |
|
|
fail: (err) => { |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
@ -303,6 +359,8 @@ Page({ |
|
|
|
|
|
|
|
|
// 显示反馈弹窗
|
|
|
// 显示反馈弹窗
|
|
|
showFeedback() { |
|
|
showFeedback() { |
|
|
|
|
|
// 刷新反馈类型数据
|
|
|
|
|
|
this.getfwpj() |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
showFeedbackModal: true, |
|
|
showFeedbackModal: true, |
|
|
feedbackContent: '', |
|
|
feedbackContent: '', |
|
|
@ -322,7 +380,7 @@ Page({ |
|
|
// 反馈内容输入
|
|
|
// 反馈内容输入
|
|
|
onFeedbackInput(e) { |
|
|
onFeedbackInput(e) { |
|
|
const content = e.detail.value |
|
|
const content = e.detail.value |
|
|
const canSubmit = content.trim().length > 0 |
|
|
|
|
|
|
|
|
const canSubmit = content.trim().length > 0 && this.data.currentFeedbackType |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
feedbackContent: content, |
|
|
feedbackContent: content, |
|
|
@ -333,19 +391,26 @@ Page({ |
|
|
// 提交反馈
|
|
|
// 提交反馈
|
|
|
submitFeedback() { |
|
|
submitFeedback() { |
|
|
if (!this.data.canSubmit || this.data.isSubmitting) return |
|
|
if (!this.data.canSubmit || this.data.isSubmitting) return |
|
|
|
|
|
|
|
|
const content = this.data.feedbackContent.trim() |
|
|
const content = this.data.feedbackContent.trim() |
|
|
if (content.length < 5) { |
|
|
if (content.length < 5) { |
|
|
this.showToast('请填写详细的反馈内容') |
|
|
this.showToast('请填写详细的反馈内容') |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!this.data.currentFeedbackType) { |
|
|
|
|
|
this.showToast('请选择反馈类型') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
isSubmitting: true |
|
|
isSubmitting: true |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
http.feedback({ |
|
|
http.feedback({ |
|
|
data: { |
|
|
data: { |
|
|
content: content |
|
|
|
|
|
|
|
|
content: content, |
|
|
|
|
|
feedbackType: this.data.currentFeedbackType // 添加反馈类型字段
|
|
|
}, |
|
|
}, |
|
|
success: res => { |
|
|
success: res => { |
|
|
if (res.code == 200) { |
|
|
if (res.code == 200) { |
|
|
@ -356,7 +421,10 @@ Page({ |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
isSubmitting: false, |
|
|
isSubmitting: false, |
|
|
showFeedbackModal: 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) => { |
|
|
fail: (err) => { |
|
|
@ -411,11 +479,11 @@ Page({ |
|
|
onPullDownRefresh() { |
|
|
onPullDownRefresh() { |
|
|
this.getUserInfo() |
|
|
this.getUserInfo() |
|
|
this.gettoday() // 刷新消息数
|
|
|
this.gettoday() // 刷新消息数
|
|
|
|
|
|
this.getfwpj() // 刷新反馈类型
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
wx.stopPullDownRefresh() |
|
|
wx.stopPullDownRefresh() |
|
|
this.showToast('刷新成功') |
|
|
this.showToast('刷新成功') |
|
|
}, 1000) |
|
|
}, 1000) |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
}) |
|
|
}) |