|
|
|
|
@ -1538,8 +1538,8 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
student.name,
|
|
|
|
|
student.email,
|
|
|
|
|
student.name,
|
|
|
|
|
student.email,
|
|
|
|
|
courseInfo,
|
|
|
|
|
student.company || '',
|
|
|
|
|
student.company_position || ''
|
|
|
|
|
@ -1638,22 +1638,22 @@ export default {
|
|
|
|
|
// 课程选择变化处理
|
|
|
|
|
handleCourseChange() {
|
|
|
|
|
// 切换具体课程时,重置分页并刷新
|
|
|
|
|
this.selectedSystemStudents = []
|
|
|
|
|
this.currentPage = 1
|
|
|
|
|
this.loadStudents()
|
|
|
|
|
this.selectedSystemStudents = []
|
|
|
|
|
this.currentPage = 1
|
|
|
|
|
this.loadStudents()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载学员数据
|
|
|
|
|
loadStudents() {
|
|
|
|
|
this.studentsLoading = true
|
|
|
|
|
// 构建与学员列表一致的查询参数
|
|
|
|
|
const params = {
|
|
|
|
|
page: this.currentPage,
|
|
|
|
|
page_size: this.pageSize
|
|
|
|
|
}
|
|
|
|
|
if (this.systemStudentSearch && this.systemStudentSearch.trim()) {
|
|
|
|
|
params.keyword = this.systemStudentSearch.trim()
|
|
|
|
|
}
|
|
|
|
|
const params = {
|
|
|
|
|
page: this.currentPage,
|
|
|
|
|
page_size: this.pageSize
|
|
|
|
|
}
|
|
|
|
|
if (this.systemStudentSearch && this.systemStudentSearch.trim()) {
|
|
|
|
|
params.keyword = this.systemStudentSearch.trim()
|
|
|
|
|
}
|
|
|
|
|
if (this.selectedCourse) {
|
|
|
|
|
params.course_id = this.selectedCourse
|
|
|
|
|
}
|
|
|
|
|
@ -1662,69 +1662,69 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
indexStudy(params).then(res => {
|
|
|
|
|
// 保存当前的选择状态
|
|
|
|
|
const currentSelection = [...this.selectedSystemStudents]
|
|
|
|
|
console.log('保存当前选择状态:', currentSelection.length)
|
|
|
|
|
console.log('当前总选择数组:', this.allSelectedStudents)
|
|
|
|
|
|
|
|
|
|
// 将当前页选择添加到总选择数组,并去重
|
|
|
|
|
if (currentSelection.length > 0) {
|
|
|
|
|
currentSelection.forEach(student => {
|
|
|
|
|
// 检查是否已存在相同ID的学员
|
|
|
|
|
const isDuplicate = this.allSelectedStudents.some(existing => Number(existing.id) === Number(student.id))
|
|
|
|
|
if (!isDuplicate) {
|
|
|
|
|
this.allSelectedStudents.push(student)
|
|
|
|
|
console.log(`✅ 新增学员到总选择: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`❌ 跳过重复学员: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('去重后的总选择数组:', this.allSelectedStudents)
|
|
|
|
|
// 保存当前的选择状态
|
|
|
|
|
const currentSelection = [...this.selectedSystemStudents]
|
|
|
|
|
console.log('保存当前选择状态:', currentSelection.length)
|
|
|
|
|
console.log('当前总选择数组:', this.allSelectedStudents)
|
|
|
|
|
|
|
|
|
|
// 将当前页选择添加到总选择数组,并去重
|
|
|
|
|
if (currentSelection.length > 0) {
|
|
|
|
|
currentSelection.forEach(student => {
|
|
|
|
|
// 检查是否已存在相同ID的学员
|
|
|
|
|
const isDuplicate = this.allSelectedStudents.some(existing => Number(existing.id) === Number(student.id))
|
|
|
|
|
if (!isDuplicate) {
|
|
|
|
|
this.allSelectedStudents.push(student)
|
|
|
|
|
console.log(`✅ 新增学员到总选择: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`❌ 跳过重复学员: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('去重后的总选择数组:', this.allSelectedStudents)
|
|
|
|
|
// 处理API返回的数据(与学员列表一致的结构)
|
|
|
|
|
const listData = res.list && Array.isArray(res.list.data) ? res.list.data : []
|
|
|
|
|
if (Array.isArray(listData)) {
|
|
|
|
|
// 处理API返回的数据,确保包含必要的字段
|
|
|
|
|
// 处理API返回的数据,确保包含必要的字段
|
|
|
|
|
console.log('开始处理学员数据,数量:', listData.length)
|
|
|
|
|
this.students = listData.map(student => {
|
|
|
|
|
// 获取最新的课程信息
|
|
|
|
|
let courseName = ''
|
|
|
|
|
let courseStartDate = ''
|
|
|
|
|
let courseEndDate = ''
|
|
|
|
|
|
|
|
|
|
if (student.course_signs && student.course_signs.length > 0) {
|
|
|
|
|
// 按时间排序,获取最新的一条课程记录
|
|
|
|
|
const sortedSigns = student.course_signs.sort((a, b) => {
|
|
|
|
|
const dateA = new Date(a.created_at || a.createdAt || a.sign_date || 0)
|
|
|
|
|
const dateB = new Date(b.created_at || b.createdAt || b.sign_date || 0)
|
|
|
|
|
return dateB - dateA // 降序排列,最新的在前
|
|
|
|
|
})
|
|
|
|
|
const latestSign = sortedSigns[0]
|
|
|
|
|
|
|
|
|
|
// 从course对象中获取课程信息
|
|
|
|
|
if (latestSign.course && latestSign.course.name) {
|
|
|
|
|
courseName = latestSign.course.name
|
|
|
|
|
courseStartDate = latestSign.course.start_date || ''
|
|
|
|
|
courseEndDate = latestSign.course.end_date || ''
|
|
|
|
|
} else {
|
|
|
|
|
// 备用方案:从sign记录本身获取
|
|
|
|
|
courseName = latestSign.course_name || latestSign.course || latestSign.courseName || ''
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有course_signs,使用备用字段
|
|
|
|
|
courseName = student.course_name || student.course || ''
|
|
|
|
|
}
|
|
|
|
|
// 获取最新的课程信息
|
|
|
|
|
let courseName = ''
|
|
|
|
|
let courseStartDate = ''
|
|
|
|
|
let courseEndDate = ''
|
|
|
|
|
|
|
|
|
|
if (student.course_signs && student.course_signs.length > 0) {
|
|
|
|
|
// 按时间排序,获取最新的一条课程记录
|
|
|
|
|
const sortedSigns = student.course_signs.sort((a, b) => {
|
|
|
|
|
const dateA = new Date(a.created_at || a.createdAt || a.sign_date || 0)
|
|
|
|
|
const dateB = new Date(b.created_at || b.createdAt || b.sign_date || 0)
|
|
|
|
|
return dateB - dateA // 降序排列,最新的在前
|
|
|
|
|
})
|
|
|
|
|
const latestSign = sortedSigns[0]
|
|
|
|
|
|
|
|
|
|
// 从course对象中获取课程信息
|
|
|
|
|
if (latestSign.course && latestSign.course.name) {
|
|
|
|
|
courseName = latestSign.course.name
|
|
|
|
|
courseStartDate = latestSign.course.start_date || ''
|
|
|
|
|
courseEndDate = latestSign.course.end_date || ''
|
|
|
|
|
} else {
|
|
|
|
|
// 备用方案:从sign记录本身获取
|
|
|
|
|
courseName = latestSign.course_name || latestSign.course || latestSign.courseName || ''
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有course_signs,使用备用字段
|
|
|
|
|
courseName = student.course_name || student.course || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: student.id,
|
|
|
|
|
name: student.name || student.real_name || '',
|
|
|
|
|
email: student.email || '-',
|
|
|
|
|
company: student.company_name || student.work_unit || '',
|
|
|
|
|
phone: student.phone || student.mobile || '',
|
|
|
|
|
department: student.department || '',
|
|
|
|
|
courseName: courseName,
|
|
|
|
|
courseStartDate: courseStartDate,
|
|
|
|
|
return {
|
|
|
|
|
id: student.id,
|
|
|
|
|
name: student.name || student.real_name || '',
|
|
|
|
|
email: student.email || '-',
|
|
|
|
|
company: student.company_name || student.work_unit || '',
|
|
|
|
|
phone: student.phone || student.mobile || '',
|
|
|
|
|
department: student.department || '',
|
|
|
|
|
courseName: courseName,
|
|
|
|
|
courseStartDate: courseStartDate,
|
|
|
|
|
courseEndDate: courseEndDate,
|
|
|
|
|
course_signs: student.course_signs || [],
|
|
|
|
|
company_position: student.company_position || ''
|
|
|
|
|
@ -1737,96 +1737,96 @@ export default {
|
|
|
|
|
this.currentPage = res.list.current_page || 1
|
|
|
|
|
this.pageSize = res.list.per_page || this.pageSize
|
|
|
|
|
}
|
|
|
|
|
console.log('数据处理完成,this.students长度:', this.students.length)
|
|
|
|
|
console.log('分页信息更新:', {
|
|
|
|
|
total: this.totalStudents,
|
|
|
|
|
currentPage: this.currentPage,
|
|
|
|
|
pageSize: this.pageSize
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 恢复选择状态
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.selectedSystemStudents = currentSelection
|
|
|
|
|
console.log('已恢复选择状态,数量:', this.selectedSystemStudents.length)
|
|
|
|
|
|
|
|
|
|
// 恢复表格的视觉勾选状态
|
|
|
|
|
console.log('开始恢复表格勾选状态...')
|
|
|
|
|
console.log('当前页学员数据:', this.students.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('当前页选择:', currentSelection.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('总选择数组:', this.allSelectedStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('数据处理完成,this.students长度:', this.students.length)
|
|
|
|
|
console.log('分页信息更新:', {
|
|
|
|
|
total: this.totalStudents,
|
|
|
|
|
currentPage: this.currentPage,
|
|
|
|
|
pageSize: this.pageSize
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 恢复当前页的选择状态
|
|
|
|
|
if (currentSelection.length > 0) {
|
|
|
|
|
currentSelection.forEach(selectedStudent => {
|
|
|
|
|
// 在当前页数据中查找对应的学员
|
|
|
|
|
const studentInCurrentPage = this.students.find(student => Number(student.id) === Number(selectedStudent.id))
|
|
|
|
|
if (studentInCurrentPage) {
|
|
|
|
|
// 使用 Element UI 的方法设置勾选状态
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(studentInCurrentPage, true)
|
|
|
|
|
console.log(`✅ 已勾选学员: ${studentInCurrentPage.name} (ID: ${studentInCurrentPage.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`❌ 未找到学员: ${selectedStudent.name} (ID: ${selectedStudent.id})`)
|
|
|
|
|
// 恢复选择状态
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.selectedSystemStudents = currentSelection
|
|
|
|
|
console.log('已恢复选择状态,数量:', this.selectedSystemStudents.length)
|
|
|
|
|
|
|
|
|
|
// 恢复表格的视觉勾选状态
|
|
|
|
|
console.log('开始恢复表格勾选状态...')
|
|
|
|
|
console.log('当前页学员数据:', this.students.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('当前页选择:', currentSelection.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('总选择数组:', this.allSelectedStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
|
|
|
|
|
// 恢复当前页的选择状态
|
|
|
|
|
if (currentSelection.length > 0) {
|
|
|
|
|
currentSelection.forEach(selectedStudent => {
|
|
|
|
|
// 在当前页数据中查找对应的学员
|
|
|
|
|
const studentInCurrentPage = this.students.find(student => Number(student.id) === Number(selectedStudent.id))
|
|
|
|
|
if (studentInCurrentPage) {
|
|
|
|
|
// 使用 Element UI 的方法设置勾选状态
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(studentInCurrentPage, true)
|
|
|
|
|
console.log(`✅ 已勾选学员: ${studentInCurrentPage.name} (ID: ${studentInCurrentPage.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`❌ 未找到学员: ${selectedStudent.name} (ID: ${selectedStudent.id})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 恢复总选择数组中在当前页显示的选择状态
|
|
|
|
|
this.students.forEach(student => {
|
|
|
|
|
const isInAllSelected = this.allSelectedStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
const isInCurrentSelection = currentSelection.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
|
|
|
|
|
if (isInAllSelected && !isInCurrentSelection) {
|
|
|
|
|
// 这个学员在总选择数组中,但不在当前页选择中,需要勾选
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(student, true)
|
|
|
|
|
console.log(`✅ 从总选择恢复勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 恢复总选择数组中在当前页显示的选择状态
|
|
|
|
|
this.students.forEach(student => {
|
|
|
|
|
const isInAllSelected = this.allSelectedStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
const isInCurrentSelection = currentSelection.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
|
|
|
|
|
if (isInAllSelected && !isInCurrentSelection) {
|
|
|
|
|
// 这个学员在总选择数组中,但不在当前页选择中,需要勾选
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(student, true)
|
|
|
|
|
console.log(`✅ 从总选择恢复勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
console.log('表格勾选状态恢复完成')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log('表格勾选状态恢复完成')
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.students = []
|
|
|
|
|
} else {
|
|
|
|
|
this.students = []
|
|
|
|
|
if (res.list) {
|
|
|
|
|
if (res.list.total !== undefined) this.totalStudents = res.list.total
|
|
|
|
|
if (res.list.current_page !== undefined) this.currentPage = res.list.current_page
|
|
|
|
|
if (res.list.per_page !== undefined) this.pageSize = res.list.per_page
|
|
|
|
|
}
|
|
|
|
|
if (Array.isArray(listData) && listData.length === 0) {
|
|
|
|
|
this.$message.warning('当前页暂无学员数据')
|
|
|
|
|
this.$message.warning('当前页暂无学员数据')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('加载学员数据失败:', error)
|
|
|
|
|
this.$message.error('加载学员数据失败')
|
|
|
|
|
// 加载失败时使用空数组
|
|
|
|
|
this.students = []
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.studentsLoading = false
|
|
|
|
|
|
|
|
|
|
// 恢复之前的选择状态
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
console.log('在finally中恢复选择状态...')
|
|
|
|
|
console.log('当前页学员:', this.students.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('当前页选择:', this.selectedSystemStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('总选择数组:', this.allSelectedStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('加载学员数据失败:', error)
|
|
|
|
|
this.$message.error('加载学员数据失败')
|
|
|
|
|
// 加载失败时使用空数组
|
|
|
|
|
this.students = []
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.studentsLoading = false
|
|
|
|
|
|
|
|
|
|
// 恢复所有应该勾选的学员(包括当前页选择和总选择数组中的)
|
|
|
|
|
this.students.forEach(student => {
|
|
|
|
|
const isInCurrentSelection = this.selectedSystemStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
const isInAllSelected = this.allSelectedStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
// 恢复之前的选择状态
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
console.log('在finally中恢复选择状态...')
|
|
|
|
|
console.log('当前页学员:', this.students.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('当前页选择:', this.selectedSystemStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
console.log('总选择数组:', this.allSelectedStudents.map(s => ({ id: s.id, name: s.name })))
|
|
|
|
|
|
|
|
|
|
if (isInCurrentSelection || isInAllSelected) {
|
|
|
|
|
// 使用 Element UI 的表格方法设置选择状态
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(student, true)
|
|
|
|
|
if (isInCurrentSelection) {
|
|
|
|
|
console.log(`✅ 在finally中恢复当前页勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`✅ 在finally中恢复总选择勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
// 恢复所有应该勾选的学员(包括当前页选择和总选择数组中的)
|
|
|
|
|
this.students.forEach(student => {
|
|
|
|
|
const isInCurrentSelection = this.selectedSystemStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
const isInAllSelected = this.allSelectedStudents.some(selected => Number(selected.id) === Number(student.id))
|
|
|
|
|
|
|
|
|
|
if (isInCurrentSelection || isInAllSelected) {
|
|
|
|
|
// 使用 Element UI 的表格方法设置选择状态
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(student, true)
|
|
|
|
|
if (isInCurrentSelection) {
|
|
|
|
|
console.log(`✅ 在finally中恢复当前页勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`✅ 在finally中恢复总选择勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
console.log('finally中已恢复选择状态')
|
|
|
|
|
})
|
|
|
|
|
console.log('finally中已恢复选择状态')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|