489 lines
14 KiB
JavaScript
Raw Normal View History

const app = getApp()
import Notify from '@vant/weapp/notify/notify';
import {
getStaff,
selectReservationByIdRq,
addStaff
} from "../../../../api/meeting/meetingRoom.js"
Page({
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
rId: '',
checkUser: [],
// staffMusicList: [{
// id: 1,
// name: '张三',
// isSelect: false
// }],
staffMusicList: [],
// staffServeList: [{
// id: 4,
// name: '赵六',
// isSelect: false
// }],
staffServeList: [],
serviceCheckAll: false,
musicCheckAll: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let _this = this
let rId = options.rId
2025-06-17 23:30:12 +08:00
// 从本地缓存获取会务人员总数信息
let staffCountInfo = wx.getStorageSync('meeting_staff_count_' + rId);
if (staffCountInfo && staffCountInfo.totalStaffCount > 0) {
console.log('从本地缓存获取会务人员总数:', staffCountInfo.totalStaffCount);
}
// 从本地缓存获取选择状态
let staffStatus = wx.getStorageSync('staffStatus_' + rId);
if (staffStatus) {
// 计算已选人员总数
const musicCount = staffStatus.musicIds ? staffStatus.musicIds.length : 0;
const serviceCount = staffStatus.serviceIds ? staffStatus.serviceIds.length : 0;
const totalCount = musicCount + serviceCount;
if (totalCount > 0) {
console.log('从本地缓存状态获取会务人员总数:', totalCount);
// 更新缓存中的会务人员总数
wx.setStorageSync('meeting_staff_count_' + rId, {
totalStaffCount: totalCount,
timestamp: new Date().getTime()
});
}
}
// console.log(ser)
_this.setData({
rId: rId
})
// 获取数据
_this.getData()
},
// 获取数据
getData() {
let _this = this
let id = _this.data.rId
2025-06-13 16:44:29 +08:00
// 显示加载中提示
wx.showLoading({
title: '加载中...',
mask: true
});
// 获取预约信息
selectReservationByIdRq({
id: id
}).then(res => {
console.log('预约信息:', res)
2025-06-13 16:44:29 +08:00
// 初始化数组
let musicStaffArr = [] // 音控组人员ID
let serviceStaffArr = [] // 会务服务组人员ID
let staff = res.waiters || []
// 清晰记录每个waiter的类型和ID便于调试
console.log('服务器返回的会务人员:', staff.map(item => ({id: item.userId, type: item.type})));
// 分别存储音控组和会务服务组的人员ID
for (let i = 0; i < staff.length; i++) {
// 类型1为音控组
if (staff[i].type === '1' || staff[i].type === 1) {
musicStaffArr.push(staff[i].userId)
}
// 类型3为会务服务组
else if (staff[i].type === '3' || staff[i].type === 3) {
serviceStaffArr.push(staff[i].userId)
}
}
2025-06-13 16:44:29 +08:00
getStaff().then(resStaff => {
2025-06-13 16:44:29 +08:00
wx.hideLoading();
console.log('会务人员列表:', resStaff)
let musicList = []
let serveList = []
2025-06-13 16:08:45 +08:00
2025-06-13 16:44:29 +08:00
// 检查服务器返回的已选择人员
let hasMusicStaff = musicStaffArr.length > 0
let hasServiceStaff = serviceStaffArr.length > 0
// 处理音控组数据
if (resStaff.voiceWaiter && resStaff.voiceWaiter.length > 0) {
for (let i = 0; i < resStaff.voiceWaiter.length; i++) {
let eachObj = resStaff.voiceWaiter[i]
// 判断该人员是否已被选择
let isSel = musicStaffArr.includes(eachObj.id)
musicList.push({
id: eachObj.id,
name: eachObj.username,
isSelect: isSel
})
}
}
2025-06-13 16:44:29 +08:00
// 处理会务服务组数据
if (resStaff.serveWaiter && resStaff.serveWaiter.length > 0) {
for (let i = 0; i < resStaff.serveWaiter.length; i++) {
let eachObj = resStaff.serveWaiter[i]
// 判断该人员是否已被选择
let isSel = serviceStaffArr.includes(eachObj.id)
serveList.push({
id: eachObj.id,
name: eachObj.username,
isSelect: isSel
})
}
}
2025-06-13 16:08:45 +08:00
2025-06-13 16:44:29 +08:00
// 重新检查选择状态,以确保准确性
hasMusicStaff = musicList.some(item => item.isSelect);
hasServiceStaff = serveList.some(item => item.isSelect);
// 计算全选状态
const musicCheckAll = musicList.length > 0 && musicList.every(item => item.isSelect);
const serviceCheckAll = serveList.length > 0 && serveList.every(item => item.isSelect);
console.log('音控组选择状态:', hasMusicStaff, '音控组IDs:', musicStaffArr);
console.log('会务服务组选择状态:', hasServiceStaff, '会务服务组IDs:', serviceStaffArr);
2025-06-13 16:08:45 +08:00
// 保存初始状态到本地存储
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff,
2025-06-13 16:44:29 +08:00
hasServiceStaff,
musicIds: musicStaffArr,
serviceIds: serviceStaffArr,
timestamp: new Date().getTime()
2025-06-13 16:08:45 +08:00
});
_this.setData({
staffServeList: serveList,
2025-06-13 16:44:29 +08:00
staffMusicList: musicList,
musicCheckAll: musicCheckAll,
serviceCheckAll: serviceCheckAll
})
2025-06-13 16:44:29 +08:00
}).catch(err => {
wx.hideLoading();
console.error('获取会务人员列表失败:', err);
Notify({
type: 'danger',
message: '获取会务人员列表失败'
});
});
}).catch(err => {
wx.hideLoading();
console.error('获取预约信息失败:', err);
Notify({
type: 'danger',
message: '获取预约信息失败'
});
});
},
2025-06-13 16:44:29 +08:00
// 音控组全选
checkMusicAll() {
let _this = this
let checkStatus = !_this.data.musicCheckAll // 直接取反更可靠
// 更新所有音控组成员的选择状态
let staffMusicList = _this.data.staffMusicList.map(item => {
item.isSelect = checkStatus
return item
})
_this.setData({
staffMusicList,
musicCheckAll: checkStatus
})
// 更新本地存储状态
let hasServiceStaff = _this.data.staffServeList.some(item => item.isSelect);
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff: checkStatus,
hasServiceStaff
});
console.log('音控组全选状态更新为:', checkStatus);
},
// 会务服务组全选
checkServiceAll() {
let _this = this
let checkStatus = !_this.data.serviceCheckAll // 直接取反更可靠
// 更新所有会务服务组成员的选择状态
let staffServeList = _this.data.staffServeList.map(item => {
item.isSelect = checkStatus
return item
})
_this.setData({
staffServeList,
serviceCheckAll: checkStatus
})
// 更新本地存储状态
let hasMusicStaff = _this.data.staffMusicList.some(item => item.isSelect);
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff,
hasServiceStaff: checkStatus
});
console.log('会务服务组全选状态更新为:', checkStatus);
},
// 单个选择框点击
checkBoxClick(e) {
let _this = this
console.log('checkBoxClick', e)
// get param
let id = e.target.dataset.id
let type = e.target.dataset.type
2025-06-13 16:44:29 +08:00
if (type === 'music') {
2025-06-13 16:44:29 +08:00
// 音控组成员选择
let staffMusicList = _this.data.staffMusicList.map(item => {
if (item.id == id) {
item.isSelect = !item.isSelect
}
return item
})
2025-06-13 16:44:29 +08:00
// 检查是否需要更新全选状态
const allSelected = staffMusicList.length > 0 && staffMusicList.every(item => item.isSelect);
const noneSelected = staffMusicList.every(item => !item.isSelect);
_this.setData({
2025-06-13 16:44:29 +08:00
staffMusicList,
musicCheckAll: allSelected
})
2025-06-13 16:44:29 +08:00
// 检查音控组选择状态
let hasMusicStaff = staffMusicList.some(item => item.isSelect);
// 获取会务服务组选择状态
let hasServiceStaff = _this.data.staffServeList.some(item => item.isSelect);
// 更新本地存储
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff,
hasServiceStaff
});
console.log('音控组选择状态:', hasMusicStaff, '全选状态:', allSelected);
} else if (type === 'serve' || type === 'service') {
// 会务服务组成员选择 (支持两种数据类型值)
let staffServeList = _this.data.staffServeList.map(item => {
if (item.id == id) {
item.isSelect = !item.isSelect
}
return item
})
2025-06-13 16:44:29 +08:00
// 检查是否需要更新全选状态
const allSelected = staffServeList.length > 0 && staffServeList.every(item => item.isSelect);
const noneSelected = staffServeList.every(item => !item.isSelect);
_this.setData({
2025-06-13 16:44:29 +08:00
staffServeList,
serviceCheckAll: allSelected
})
2025-06-13 16:44:29 +08:00
// 检查会务服务组选择状态
let hasServiceStaff = staffServeList.some(item => item.isSelect);
// 获取音控组选择状态
let hasMusicStaff = _this.data.staffMusicList.some(item => item.isSelect);
// 更新本地存储
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff,
hasServiceStaff
});
console.log('会务服务组选择状态:', hasServiceStaff, '全选状态:', allSelected);
}
},
2025-06-17 23:30:12 +08:00
// 提交
submit() {
2025-06-17 23:30:12 +08:00
let _this = this
let rId = _this.data.rId
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
// 收集已选择的人员
let checkUser = []
let musicList = _this.data.staffMusicList
let serveList = _this.data.staffServeList
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
// 音控组选择的人员
let musicSelectedCount = 0
let musicStaffIds = []
for (let i = 0; i < musicList.length; i++) {
if (musicList[i].isSelect) {
musicSelectedCount++
musicStaffIds.push(musicList[i].id)
checkUser.push({
userId: musicList[i].id,
type: 1
})
}
}
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
// 会务服务组选择的人员
let serviceSelectedCount = 0
let serviceStaffIds = []
for (let i = 0; i < serveList.length; i++) {
if (serveList[i].isSelect) {
serviceSelectedCount++
serviceStaffIds.push(serveList[i].id)
checkUser.push({
userId: serveList[i].id,
type: 3
})
}
2025-06-17 23:30:12 +08:00
}
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
// 判断是否有选择,至少需要选择一个音控组人员和一个会务服务组人员
if (musicSelectedCount < 1) {
return Notify({
type: 'danger',
message: '请至少选择一个音控组人员'
});
}
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
if (serviceSelectedCount < 1) {
return Notify({
type: 'danger',
message: '请至少选择一个会务服务组人员'
});
}
2025-06-13 16:08:45 +08:00
2025-06-17 23:30:12 +08:00
// 处理提交数据为字符串格式
const musicIdsStr = musicStaffIds.join(',');
const serviceIdsStr = serviceStaffIds.join(',');
2025-06-13 16:44:29 +08:00
2025-06-17 23:30:12 +08:00
console.log('提交选择的会务人员:', {
音控组: musicIdsStr,
会务服务组: serviceIdsStr
2025-06-13 16:44:29 +08:00
});
2025-06-17 23:30:12 +08:00
// 显示加载提示
wx.showLoading({
title: '提交中...',
mask: true
});
// 保存当前会务负责人状态到本地存储,包含详细信息
const hasMusicStaff = musicSelectedCount > 0;
const hasServiceStaff = serviceSelectedCount > 0;
2025-06-13 16:08:45 +08:00
wx.setStorageSync('staffStatus_' + _this.data.rId, {
hasMusicStaff,
2025-06-13 16:44:29 +08:00
hasServiceStaff,
2025-06-17 23:30:12 +08:00
musicIds: musicStaffIds,
serviceIds: serviceStaffIds,
2025-06-13 16:44:29 +08:00
timestamp: new Date().getTime()
2025-06-13 16:08:45 +08:00
});
2025-06-17 23:30:12 +08:00
// 保存实际选择的总人数到本地缓存
const totalStaffCount = musicSelectedCount + serviceSelectedCount;
wx.setStorageSync('meeting_staff_count_' + _this.data.rId, {
totalStaffCount: totalStaffCount,
timestamp: new Date().getTime()
2025-06-13 16:44:29 +08:00
});
2025-06-17 23:30:12 +08:00
// 提交到服务器 - 使用正确的参数格式
addStaff({
2025-06-17 23:30:12 +08:00
id: rId,
voiceWaiter: musicIdsStr, // 音控组 - 使用逗号分隔的字符串
serveWaiter: serviceIdsStr // 会务服务组 - 使用逗号分隔的字符串
}).then(res => {
2025-06-13 16:44:29 +08:00
wx.hideLoading();
2025-06-17 23:30:12 +08:00
console.log('提交会务负责人成功:', res);
2025-06-13 16:08:45 +08:00
2025-06-17 23:30:12 +08:00
// 设置标记表示会务负责人页面有更新approve页面需要刷新通知状态
wx.setStorageSync('staffPage_updated', {
meetingId: rId,
totalCount: totalStaffCount,
hasMusicStaff,
hasServiceStaff,
timestamp: new Date().getTime()
});
Notify({
type: 'success',
message: '设置成功',
onClose: () => {
2025-06-13 16:44:29 +08:00
wx.navigateBack();
2025-06-17 23:30:12 +08:00
}
});
2025-06-13 16:44:29 +08:00
}).catch(err => {
wx.hideLoading();
2025-06-17 23:30:12 +08:00
console.error('提交会务负责人失败:', err);
2025-06-13 16:44:29 +08:00
Notify({
type: 'danger',
2025-06-17 23:30:12 +08:00
message: '设置失败'
2025-06-13 16:44:29 +08:00
});
});
},
2025-06-13 16:44:29 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})