379 lines
9.9 KiB
JavaScript
Raw Normal View History

2024-08-19 15:32:53 +08:00
const app = getApp()
2024-08-19 14:16:18 +08:00
2024-08-19 15:32:53 +08:00
import {
repairRemindListRq,
repairRemindReadRq,
repairRemindClearRq,
repairRemindRemoveRq
2024-08-19 15:32:53 +08:00
} from "../../../api/repair/repair.js"
2024-08-19 14:16:18 +08:00
import Dialog from '@vant/weapp/dialog/dialog';
import Notify from '@vant/weapp/notify/notify';
2024-08-19 15:32:53 +08:00
Page({
2024-08-19 14:16:18 +08:00
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
// info
info: {
pageNum: 1,
pageSize: 10,
dataList: [],
isDataAll: false,
2024-08-19 15:32:53 +08:00
},
checkedId: {},
showEdit: false
},
openEdit() {
this.setData({
showEdit: true,
checkedId: {}
})
},
cancelEdit() {
this.setData({
showEdit: false,
checkedId: {}
})
},
removeChecked() {
this.setData({
showEdit: true
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
// 获取数据
getDataList() {
let _this = this;
// 获取参数
let pageNum = null
let pageSize = null
let type = null
let isDataAll = null
let info = _this.data.info
//
pageNum = info.pageNum
pageSize = info.pageSize
isDataAll = info.isDataAll
// 判断数据是否已全部加载
if (isDataAll) {
return;
}
// 传递参数
let param = {
pageNum,
pageSize,
}
// 查询数据
repairRemindListRq(param).then(res => {
console.log('repairRemindListRq', res);
let dataList = res.rows
2025-06-17 23:30:12 +08:00
console.log("列表"+dataList);
let isDataAll = false
if (pageNum * pageSize >= res.total) {
isDataAll = true
}
//
info.dataList = info.dataList.concat(_this.formartData(dataList))
info.pageNum = info.pageNum + 1
info.isDataAll = isDataAll
_this.setData({
info
})
})
},
// 格式化数据
formartData(dataList) {
2024-08-19 15:32:53 +08:00
// 格式化数据
return dataList.map(item => {
return item;
})
},
jumpInfoDetail(e) {
if (this.data.showEdit) {
// 编辑模式下不可跳转
return
}
console.log('detail', e);
let id = e.currentTarget.dataset.obj.id
let repairId = e.currentTarget.dataset.obj.repairId
let title = e.currentTarget.dataset.obj.content
let url = `/pages/reportRepair/assign/detail/detail?id=${repairId}`
if ((title.includes('你收到工单') && title.includes('请尽快处理')) || title.includes('已经超时,黄灯告警') || title.includes('已经严重超时,红灯告警')) {
// 此处为维修单要跳转到case
url = `/pages/reportRepair/repair/case/case?id=${repairId}`
}
// 会议工单处理
if ((title.includes('您收到会议预约') && title.includes('待审核')) || (title.includes('会议预约') && title.includes('已取消'))) {
// 此处为管理员收到的会议审核
url = "/pages/meeting/reservationRecord/meetingRecord/meetingDetail/meetingDetail?act=approve&id=" + repairId
}
if (title.includes('您的会议预约') && (title.includes('被驳回') || title.includes('已被管理员修改') || title.includes('已审核通过') || title.includes('即将开始'))) {
// 此处为预约人收到的会议预约
url = "/pages/meeting/reservationRecord/meetingRecord/meetingDetail/meetingDetail?id=" + repairId
}
if (title.includes('会议预约') && title.includes('指定您为会务负责人')) {
// 此处为管理员收到的会议审核
url = "/pages/meeting/reservationRecord/meetingRecord/meetingDetail/meetingDetail?act=serve&id=" + repairId
}
2025-06-17 23:30:12 +08:00
// 处理会议预约相关的消息通知
let isMeetingNotification = title.includes('会议预约') || title.includes('会务负责人');
let userId = wx.getStorageSync('user') ? wx.getStorageSync('user').id : '';
// 判断用户角色:音控人员或会务服务人员
let userRole = wx.getStorageSync('user') ? wx.getStorageSync('user').roomRole : '';
let isStaffUser = userRole === '2' || userRole === '3'; // 2表示音控人员3表示会务服务人员
console.log('处理消息通知:', {
id: id,
repairId: repairId,
isMeetingNotification: isMeetingNotification,
userId: userId,
userRole: userRole,
isStaffUser: isStaffUser,
title: title
});
// 调用API标记通知为已读
repairRemindReadRq({
id
}).then(res => {
2025-06-17 23:30:12 +08:00
console.log('标记通知已读成功:', res);
// 如果是会议相关通知,更新本地通知状态缓存
if (isMeetingNotification && repairId) {
// 更新本地已读通知缓存
let notificationKey = 'notification_' + repairId;
let notificationInfo = wx.getStorageSync(notificationKey) || {};
// 更新已读状态
notificationInfo.isRead = true;
// 如果有用户ID记录已读用户
if (userId) {
notificationInfo.readUsers = notificationInfo.readUsers || [];
if (!notificationInfo.readUsers.includes(userId)) {
notificationInfo.readUsers.push(userId);
}
}
// 记录用户角色
if (isStaffUser) {
notificationInfo.staffReadUsers = notificationInfo.staffReadUsers || [];
if (!notificationInfo.staffReadUsers.includes(userId)) {
notificationInfo.staffReadUsers.push(userId);
}
// 记录具体角色类型
notificationInfo.userRoles = notificationInfo.userRoles || {};
notificationInfo.userRoles[userId] = userRole;
}
// 更新已读时间
notificationInfo.readTime = new Date().getTime();
// 保存到本地缓存
wx.setStorageSync(notificationKey, notificationInfo);
console.log('更新本地通知缓存:', notificationKey, notificationInfo);
// 广播通知状态更新事件使approve页面能够更新通知状态
const notificationData = {
meetingId: repairId,
notificationId: id,
isRead: true,
userId: userId,
userRole: userRole,
isStaffUser: isStaffUser,
timestamp: new Date().getTime()
};
// 保存到本地存储
wx.setStorageSync('meeting_notification_updated', notificationData);
// 尝试通过全局事件触发通知更新
const app = getApp();
if (app && app.triggerNotificationStatusChange) {
app.triggerNotificationStatusChange(notificationData);
console.log('已触发全局通知状态更新事件');
}
// 发布页面全局事件,确保所有打开的页面都能收到通知
if (wx.canIUse('eventChannel')) {
const eventChannel = this.getOpenerEventChannel();
if (eventChannel) {
try {
eventChannel.emit('notificationStatusUpdated', notificationData);
console.log('发送页面事件通知成功');
} catch (err) {
console.error('发送页面事件通知失败:', err);
}
}
}
}
// 跳转到相应页面
wx.navigateTo({
url: url,
2025-06-17 23:30:12 +08:00
});
}).catch(err => {
console.error('标记通知已读失败:', err);
// 出错时仍然跳转
wx.navigateTo({
url: url,
});
});
},
changeCheck(e) {
console.log(e)
let id = e.currentTarget.dataset.obj.id
let _this = this
let _checkedId = `checkedId[${id}]`
_this.setData({
[_checkedId]: e.detail
})
},
removeChecked() {
let _this = this
let _idArr = _this.data.checkedId
let _idStr = ''
for (let key in _idArr) {
// console.log(_idArr[key])
if(_idArr[key]) {
_idStr += key + ','
}
}
if (_idStr != '') {
_idStr = _idStr.slice(0, -1)
} else {
Notify('请至少勾选一条消息!')
return
}
// console.log(_idStr)
Dialog.confirm({
title: '请确认',
message: '是否删除选中的消息?',
})
.then(() => {
repairRemindRemoveRq({
2024-08-29 10:13:53 +08:00
ids:_idStr
}).then(res => {
// 重新加载列表
_this.setData({
info: {
pageNum: 1,
pageSize: 10,
dataList: [],
isDataAll: false,
},
checkedId: {}
})
// 重新加载
_this.getDataList()
})
})
.catch(() => {
// on cancel
})
},
removeAll() {
let _this = this
// 确认
Dialog.confirm({
title: '请确认',
message: '您即将清空消息列表,是否确认?',
})
.then(() => {
repairRemindClearRq({}).then(res => {
// 清空消息后,重新加载
_this.setData({
2024-08-19 15:32:53 +08:00
info: {
pageNum: 1,
pageSize: 10,
dataList: [],
isDataAll: false,
2024-08-19 15:32:53 +08:00
}
})
// 重新加载
_this.getDataList()
2024-08-19 15:32:53 +08:00
})
})
.catch(() => {
// on cancel
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
let _this = this;
_this.setData({
info: {
pageNum: 1,
pageSize: 10,
dataList: [],
isDataAll: false,
}
})
//
_this.getDataList()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
console.log('onReachBottom', '页面上拉触底事件的处理函数');
let _this = this;
// 获取数据
_this.getDataList()
},
2024-08-19 15:32:53 +08:00
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
2024-08-19 15:32:53 +08:00
}
2024-08-19 14:16:18 +08:00
})