Commit 615a98ed by Jaxon

fix(workspace): 修复服务中心通知弹窗路由跳转后this指向问题

修复checkServiceNotice方法中异步回调内this指向错误,导致路由跳转后无法正确更新页面状态的问题。通过引入that变量保存当前this引用,确保在wx.showModal回调中能正确访问页面实例。
1 parent 89a4f8eb
...@@ -132,6 +132,7 @@ Page({ ...@@ -132,6 +132,7 @@ Page({
}, },
async checkServiceNotice() { async checkServiceNotice() {
const that = this;
for (let serviceCenterEnum of noticeSort) { for (let serviceCenterEnum of noticeSort) {
const { data } = await getCompanyNoticeList({ const { data } = await getCompanyNoticeList({
pageNum: 1, pageNum: 1,
...@@ -144,7 +145,7 @@ Page({ ...@@ -144,7 +145,7 @@ Page({
}); });
let index = this.data.storeManagementMenus.findIndex((e) => e.name === "服务中心"); let index = this.data.storeManagementMenus.findIndex((e) => e.name === "服务中心");
this.setData({ that.setData({
[`storeManagementMenus[${index}].tipsNum`]: data?.total || 0, [`storeManagementMenus[${index}].tipsNum`]: data?.total || 0,
}); });
...@@ -155,7 +156,7 @@ Page({ ...@@ -155,7 +156,7 @@ Page({
// 根据类型取到对应的值 // 根据类型取到对应的值
const { message, ...dialogParams } = dialogOptions[serviceCenterEnum][noticeItem.reminderType || 1]; const { message, ...dialogParams } = dialogOptions[serviceCenterEnum][noticeItem.reminderType || 1];
this.setData({ that.setData({
isShowingModal: true, isShowingModal: true,
}); });
wx.showModal({ wx.showModal({
...@@ -164,10 +165,10 @@ Page({ ...@@ -164,10 +165,10 @@ Page({
showCancel: false, showCancel: false,
confirmText: dialogParams.confirmButtonText, confirmText: dialogParams.confirmButtonText,
success: function (res) { success: function (res) {
wx.$router.go("packageWorkspace.companyNoticeDetail", { id: noticeItem.id }); that.setData({
this.setData({
isShowingModal: false, isShowingModal: false,
}); });
wx.$router.go("packageWorkspace.companyNoticeDetail", { id: noticeItem.id });
}, },
}); });
break; break;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!