2025-06-13 16:08:45 +08:00

921 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const app = getApp()
import Dialog from '@vant/weapp/dialog/dialog';
import Notify from '@vant/weapp/notify/notify';
import {
selfFormatTimeYMD,
selfFormatTimeHM,
getWeekday,
getNowDate
} from "../../../../utils/util.js"
import {
selectReservationListByUserIdRq,
selectVisitorInvitationRecordRq,
cancelOrderRq,
approveOrderRq,
approveOrderDel
} from "../../../../api/meeting/meetingRoom.js"
Page({
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
userData: null,
dataChange: false,
tabTitle: '预约记录',
// 预约记录参数
reservationPageNum: 1,
reservationPageSize: 10,
reservationDataList: [],
reservationIsDataAll: false,
search: {
title: {
text: '会议名称',
value: ''
},
status: {
text: '',
value: 5,
option: [{
text: '全部预约',
value: ''
},
{
text: '待审核',
value: 5
},
{
text: '待开始',
value: 7
},
{
text: '已结束',
value: 11
},
{
text: '已取消',
value: 1
},
{
text: '已驳回',
value: 3
}, {
text: '占用',
value: 4
}, {
text: '进行中',
value: 9
},
]
},
sort: {
value: 'start',
option: [{
text: '排序方式',
value: ''
},
{
text: '会议开始时间',
value: 'start'
},
{
text: '创建时间',
value: 'create'
},
]
}
},
showRejectReason: false, // 是否展示弹出层
rejectlId: '', // 驳回预约会议id
rejectReason: '', // 驳回预约原因
beforeReject(action) {
return new Promise(resolve => {
if (action === 'confirm') {
resolve(false)
} else {
resolve(true)
}
});
}, // 弹出层点击确认不关闭,手动关
// 会议重新预约需要参数
editId: '',
showEdit: false,
editAction: [{
name: '重新选择时间、会议室',
type: 1
},
{
name: '重新编辑会议信息',
type: 2
},
],
timeShow: false,
currentDate: new Date().getTime(),
minDate: new Date().getTime(),
maxDate: '',
formatter(type, value) {
if (type === 'year') {
return `${value}`;
}
if (type === 'month') {
return `${value}`;
}
if (type === 'day') {
return `${value}`;
}
return value;
},
// 参与记录参数,不需要
// participatePageNum: 1,
// participatePageSize: 10,
// participateDataList: [],
// participateIsDataAll: false,
},
changeSearchTitle(e) {
this.setData({
['search.title.value']: e.detail,
})
},
searchTitle() {
// 刷新预约数据
this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
})
this.getDataList()
this.selectComponent('#item').toggle()
},
changeSearchStatus(e) {
// 刷新预约数据
this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
['search.status.value']: e.detail
})
// 更新状态文本
const statusOption = this.data.search.status.option;
const selectedOption = statusOption.find(option => option.value === e.detail);
if (selectedOption) {
this.setData({
['search.status.text']: selectedOption.text
});
}
this.getDataList()
},
changeSearchSort(e) {
// 刷新预约数据
this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
['search.sort.value']: e.detail
})
// 更新排序文本
const sortOption = this.data.search.sort.option;
const selectedOption = sortOption.find(option => option.value === e.detail);
if (selectedOption) {
this.setData({
['search.sort.text']: selectedOption.text
});
}
this.getDataList()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 这里opt接收options以处理查看更多
if (options.act == 'show') {
wx.setNavigationBarTitle({
title: '预约记录',
})
this.setData({
'search.status.value': ''
})
}
// 检查是否有URL参数指定状态
if (options && options.status) {
this.setData({
'search.status.value': parseInt(options.status) || 7
});
// 初始化状态文本
const statusOption = this.data.search.status.option;
const selectedOption = statusOption.find(option => option.value === this.data.search.status.value);
if (selectedOption) {
this.setData({
'search.status.text': selectedOption.text
});
}
}
let _this = this;
let userDetail = wx.getStorageSync('user')
_this.setData({
userData: userDetail
})
// 获取两周后时间,默认只能选两周之后,管理员可以选一年后的
const today = new Date()
const newDate = new Date(today)
if (userDetail.roomRole == 5) {
newDate.setFullYear(newDate.getFullYear() + 1)
} else {
newDate.setDate(newDate.getDate() + 14)
}
_this.setData({
maxDate: newDate.getTime()
})
// 获取数据
_this.getDataList()
},
// 获取数据
getDataList() {
// 获取参数
let _this = this;
// 确保每次获取数据时使用最新的用户信息
let currentUserData = wx.getStorageSync('user');
if(currentUserData && (!_this.data.userData || _this.data.userData.roomRole !== currentUserData.roomRole)) {
_this.setData({
userData: currentUserData
});
}
let tabTitle = _this.data.tabTitle
let userId = _this.data.userData.id
let isDataAll = null
let pageNum = null
let pageSize = null
// 预约记录参数,目前只保留预约记录,其余去掉
isDataAll = _this.data.reservationIsDataAll
pageNum = _this.data.reservationPageNum
pageSize = _this.data.reservationPageSize
// 判断数据是否已全部加载
if (isDataAll) {
return;
}
// 传递参数
let param = {
userId,
pageNum,
pageSize
}
_this.getReservationData(param)
},
// 获取预约数据
getReservationData(param) {
let _this = this;
let {
pageNum,
pageSize,
userId
} = param
// 确保使用最新的用户角色
let currentUserData = wx.getStorageSync('user');
let currentRole = currentUserData ? currentUserData.roomRole : _this.data.userData.roomRole;
// 查询数据
selectReservationListByUserIdRq({
role: currentRole, // 使用最新的角色
pageNum,
pageSize,
userId: _this.data.userData.id, // 确保传递用户ID
title: _this.data.search.title.value,
status: _this.data.search.status.value === '' ? null : _this.data.search.status.value,
sort: _this.data.search.sort.value, // 排序
}).then(res => {
console.log('selectReservationListByUserIdRq', res);
// 判断数据是否全部查询
let queryDataList = res.rows;
if (_this.data.reservationDataList.length < res.total) {
// 更新参数
let reservationDataList = _this.data.reservationDataList.concat(_this.formartData(queryDataList));
let reservationPageNum = _this.data.reservationPageNum + 1;
_this.setData({
reservationPageNum,
reservationDataList,
})
// 超过总大小,则加载完成
if (_this.data.reservationDataList.length >= res.total) {
_this.setData({
reservationIsDataAll: true
})
}
} else {
_this.setData({
reservationIsDataAll: true
})
}
})
},
// 获取参与数据,此处不需要
getParticipateData(param) {
let _this = this;
let {
pageNum,
pageSize,
userId
} = param
// 查询数据
selectVisitorInvitationRecordRq({
pageNum,
pageSize,
userId
}).then(res => {
console.log('selectVisitorInvitationRecordRq', res);
// 判断数据是否全部查询
let queryDataList = res.page.records;
if (queryDataList && queryDataList.length > 0) {
// 更新参数
let participateDataList = _this.data.participateDataList.concat(_this.formartData(queryDataList));
let participatePageNum = _this.data.participatePageNum + 1;
_this.setData({
participatePageNum,
participateDataList,
})
} else {
_this.setData({
participateIsDataAll: true
})
}
})
},
// 格式化数据
formartData(queryDataList) {
// 格式化数据
let _this = this;
let userRole = _this.data.userData.roomRole; // 获取用户角色
// 获取当前日期、第二天日期和第三天日期
let nowDate = new Date();
let secondDate = new Date();
secondDate.setDate(nowDate.getDate() + 1);
let thirdDate = new Date();
thirdDate.setDate(nowDate.getDate() + 2);
// 格式化当前日期、第二天日期和第三天日期为YYYY-MM-DD格式
let nowDateStr = selfFormatTimeYMD(nowDate);
let secondDateStr = selfFormatTimeYMD(secondDate);
let thirdDateStr = selfFormatTimeYMD(thirdDate);
return queryDataList.map(item => {
// 会议开始日期
let meetingDateStr = selfFormatTimeYMD(item.start);
// 判断是哪一天
item.isToday = meetingDateStr === nowDateStr;
item.isSecondDay = meetingDateStr === secondDateStr;
item.isThirdDay = meetingDateStr === thirdDateStr;
item.isNowDay = item.isToday; // 保持兼容性
// 添加星期几属性,但不再用于颜色判断
item.weekDay = getWeekday(item.start);
// 完全移除基于星期几的颜色逻辑
// 确保不保留任何可能影响颜色的旧数据
if(item.dateColor) {
delete item.dateColor;
}
item.timeSlot = selfFormatTimeYMD(item.start) + ' '+ getWeekday(item.start) +' ' + selfFormatTimeHM(item.start) + '~' + selfFormatTimeHM(item.end);
// 状态字体颜色
let statusColor = "#FFB119";
// 按钮是否显示
let statusValue = item.status;
let showCancel = false // 显示取消操作
let showEdit = false // 显示编辑操作
let showStaff = false // 显示会务人员
let showApprove = false // 显示审批操作
let statusName = ''
// 预约状态1 取消 3 驳回 4 占用 5 待审核 7 审核通过,待开始 9 进行中 11已结束
if (statusValue == 1) {
// 取消
// 状态字体颜色
statusColor = "#333333"
statusName = '已取消'
}
if (statusValue == 3) {
// 驳回,可以修改
statusColor = "#333333"
statusName = '已驳回'
}
if (statusValue == 4) {
// 占用,仅管理员可以修改
statusName = '已占用'
if (userRole == 5) { // 只有管理员可以编辑和取消占用
showEdit = true
showCancel = true
}
}
if (statusValue == 5) {
// 待审核,管理员可以审批
statusName = '待审核'
if (userRole == 5) { // 只有管理员可以编辑和审批
showEdit = true
showApprove = true
}
}
if (statusValue == 7) {
// 审核通过,管理员可修改
statusName = '待开始'
if (userRole == 5) { // 只有管理员可以取消、编辑和分配会务人员
showCancel = true
showEdit = true
showStaff = true
// 根据会务负责人选择状态设置按钮颜色和提示
try {
// 从本地存储获取会务负责人选择状态
let staffStatus = wx.getStorageSync('staffStatus_' + item.id);
if (staffStatus) {
// 判断音控组和会务服务组选择状态
const hasMusicStaff = staffStatus.hasMusicStaff;
const hasServiceStaff = staffStatus.hasServiceStaff;
if (hasMusicStaff && hasServiceStaff) {
// 音控组和会务服务组都有选择
item.staffBtnType = '';
item.staffTip = '';
// 绿色样式标记
item.isStaffComplete = true;
} else if (!hasMusicStaff && !hasServiceStaff) {
// 音控组和会务服务组都没有选择
item.staffBtnType = 'danger';
item.staffTip = '请选择音控组和会务服务组';
item.isStaffComplete = false;
} else if (hasMusicStaff && !hasServiceStaff) {
// 只选择了音控组
item.staffBtnType = 'warning';
item.staffTip = '请选择会务服务组';
item.isStaffComplete = false;
} else if (!hasMusicStaff && hasServiceStaff) {
// 只选择了会务服务组
item.staffBtnType = 'warning';
item.staffTip = '请选择音控组';
item.isStaffComplete = false;
}
} else {
// 默认状态:黄色按钮(与取消预约按钮一致),提示选择两个组
item.staffBtnType = 'warning';
item.staffTip = '请选择音控组和会务服务组';
item.isStaffComplete = false;
}
} catch (error) {
console.error('获取会务负责人状态失败', error);
}
}
}
if (statusValue == 9) {
// 进行中
statusName = '进行中'
}
if (statusValue == 11) {
// 已结束
statusColor = "#333333"
statusName = '已结束'
}
// 赋值
item.showCancel = showCancel
item.showEdit = showEdit
item.showApprove = showApprove
item.showStaff = showStaff
item.statusName = statusName
// 状态字体颜色
item.statusColor = statusColor;
// 图片
if (item.imgs) {
try {
item.indoorPicUrlFirst = item.imgs[0].url
} catch (error) {
console.log(`JSON error : ${error}`);
}
}
for (let key in item) {
// null设置为空
if (item[key] == null) {
item[key] = ''
}
}
return item
})
},
// 跳转-预约详情
jumpMeetingDetail(e) {
console.log('jumpMeetingDetail', e);
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: "/pages/meeting/reservationRecord/meetingRecord/meetingDetail/meetingDetail?act=approve&id=" + id,
})
},
/**
* 跳转会务负责人页面,选择会务负责人
* @param {}} e
*/
goStaff(e) {
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: "/pages/meeting/meetingRoom/meetingStaff/meetingStaff?rId=" + id,
})
},
/**
* 生命周期函数--监听页面显示
* 添加刷新会务负责人状态按钮显示逻辑
*/
onShow() {
let _this = this;
// 每次页面显示时检查用户角色是否有变化
let currentUserData = wx.getStorageSync('user');
let userRoleChanged = false;
// 检查用户角色是否发生变化
if(_this.data.userData && currentUserData && _this.data.userData.roomRole !== currentUserData.roomRole) {
userRoleChanged = true;
// 更新用户数据
_this.setData({
userData: currentUserData
});
console.log('用户角色已变更,重新加载数据');
}
// 数据是否变化或用户角色变化
if (_this.data.dataChange || userRoleChanged) {
// 刷新数据
_this.setData({
dataChange: false,
// 预约记录参数
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
})
_this.getDataList()
}
},
// 取消预约一系列方法
cancelConfirm(e) {
console.log('cancelConfirm', e);
let status = e.currentTarget.dataset.status
let _this = this;
let id = e.currentTarget.dataset.id
if (status == '4') {
// 占用,占用的取消直接删除
Dialog.confirm({
title: '确认',
message: '取消后不可撤销,是否确认?',
})
.then(() => {
// on confirm
approveOrderDel({
id: id,
}).then(res => {
console.log('delApprove', res)
if (res.code == 0) {
// 刷新预约数据
_this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
showRejectReason: false
})
Notify({
type: 'success',
message: '已取消'
})
_this.getDataList()
} else {
// 危险通知
Notify({
type: 'danger',
message: res.msg
});
}
})
})
.catch(() => {
// on cancel
});
} else {
// 其余的取消,需要输入原因
_this.setData({
cancelId: id,
showCancelReason: true,
cancelReason: ''
})
}
},
onCloseCancel(e) {
let _this = this;
_this.setData({
cancelId: '',
showCancelReason: false,
cancelReason: ''
})
},
onChangeCancelReason(e) {
let _this = this;
_this.setData({
cancelReason: e.detail
})
},
// 取消订单
cancelOrder() {
let _this = this;
let id = _this.data.cancelId
let reason = _this.data.cancelReason
if (id === '') {
return
}
if (reason === '') {
Notify('请输入取消原因!')
return
}
cancelOrderRq({
id: id,
content: reason
}).then(res => {
console.log('cancelOrderRq', res);
if (res.code == 0) {
// 刷新预约数据
_this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
showCancelReason: false
})
_this.getDataList()
} else {
// 危险通知
Notify({
type: 'danger',
message: res.msg
});
}
})
},
editConfirm(e) {
let id = e.currentTarget.dataset.id
this.setData({
editId: id,
showEdit: true
})
},
hideEdit() {
this.setData({
showEdit: false
})
},
editMode(e) {
let _this = this
if (e.detail.type === 1) {
// 重选时间会议室
this.setData({
showEdit: false,
timeShow: true
})
} else {
// 直接跳转
console.log('重新编辑会议基本信息!')
this.setData({
showEdit: false,
})
wx.navigateTo({
url: "/pages/meeting/meetingRoom/meetingOrder/meetingOrder?rId=" + _this.data.editId,
})
}
},
showTimePicker() {
this.setData({
timeShow: true
});
},
hideTimePicker() {
this.setData({
timeShow: false
});
},
// 跳转会议预约页面
goRes(e) {
let _this = this
let date = new Date(e.detail);
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
// IOS不支持-,必须用/
let chooseTime = year + '/' + month + '/' + day + ' 00:00:00'
let chooseTimeStr = new Date(chooseTime).getTime()
// 加入rId参数为预约id用于重新修改
wx.navigateTo({
url: '/pages/meeting/meetingReservation/meetingReservation?rId=' + _this.data.editId + '&time=' + chooseTimeStr,
})
},
pass(e) {
let _this = this;
let id = e.currentTarget.dataset.id
Dialog.confirm({
title: '确认',
message: '是否确认通过会议室申请?',
})
.then(() => {
// on confirm
approveOrderRq({
id: id,
content: '审核通过',
operate: 'PASS'
}).then(res => {
console.log('passOrder', res)
if (res.code == 0) {
// 通知成功
Notify({
type: 'success',
message: '已通过该申请!'
})
// 先提示用户选择会务负责人,再刷新数据
wx.showModal({
title: '会务负责人',
content: '请选择会议的音控组和会务服务组负责人',
confirmText: '去选择',
cancelText: '我知道了',
success(res) {
if (res.confirm) {
// 点击"去选择",跳转到会务负责人页面
wx.navigateTo({
url: "/pages/meeting/meetingRoom/meetingStaff/meetingStaff?rId=" + id,
})
} else {
// 点击"我知道了",只刷新数据
console.log('用户选择稍后设置会务负责人')
// 刷新预约数据
_this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
showRejectReason: false
})
_this.getDataList()
}
}
})
} else {
// 危险通知
Notify({
type: 'danger',
message: res.msg
});
}
})
})
.catch(() => {
// on cancel
});
},
// 驳回预约
rejectConfirm(e) {
console.log('rejectConfirm', e);
let _this = this;
let id = e.currentTarget.dataset.id
_this.setData({
rejectId: id,
showRejectReason: true,
rejectReason: ''
})
},
onCloseReject(e) {
let _this = this;
_this.setData({
rejectId: '',
showRejectReason: false,
rejectReason: ''
})
},
onChangeRejectReason(e) {
let _this = this;
_this.setData({
rejectReason: e.detail
})
},
// 取消订单
rejectOrder() {
let _this = this;
let id = _this.data.rejectId
let reason = _this.data.rejectReason
if (id === '') {
return
}
if (reason === '') {
Notify('请输入驳回原因!')
return
}
// 执行驳回方法
console.log('驳回,原因为' + reason)
approveOrderRq({
id: id,
content: reason,
operate: 'REJECTED'
}).then(res => {
console.log('rejectOrder', res);
if (res.code == 0) {
// 刷新预约数据
_this.setData({
reservationPageNum: 1,
reservationDataList: [],
reservationIsDataAll: false,
showRejectReason: false
})
Notify({
type: 'danger',
message: '已驳回该申请!'
})
_this.getDataList()
} else {
// 危险通知
Notify({
type: 'danger',
message: res.msg
});
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
console.log('onPullDownRefresh', '页面相关事件处理函数--监听用户下拉动作');
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
console.log('onReachBottom', '页面上拉触底事件的处理函数');
let _this = this;
// 获取数据
_this.getDataList()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage(e) {
console.log('onShareAppMessage', e);
let _this = this;
let id = e.target.dataset.id;
let detail = _this.data.reservationDataList.find(item => item.id == id)
//
let param = {
title: detail.title,
path: "/pages/meeting/invite/invite?id=" + id,
imageUrl: app.IMG_NAME + detail.roomContent.indoorPicUrlFirst,
}
console.log('onShareAppMessage', param);
return param;
}
})