|
|
|
|
@ -649,9 +649,12 @@
|
|
|
|
|
clearable
|
|
|
|
|
@keyup.enter="searchStudents">
|
|
|
|
|
</el-input>
|
|
|
|
|
<el-select v-model="selectedCourseType" placeholder="请选择课程" clearable style="width: 200px;" @change="handleCourseTypeChange">
|
|
|
|
|
<el-option v-for="item in courseTypesList" :key="item.id" :label="item.name" :value="item.id">
|
|
|
|
|
<el-select v-model="selectedCourse" placeholder="请选择具体课程" clearable style="width: 200px;" @change="handleCourseChange">
|
|
|
|
|
<el-option v-for="item in courseList" :key="item.id" :label="item.name" :value="item.id">
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
<el-select v-model="selectedStatus" placeholder="审核状态" clearable style="width: 160px;">
|
|
|
|
|
<el-option v-for="item in apply_status_list" :key="item.id" :label="item.value" :value="item.id"></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
<el-button
|
|
|
|
|
type="primary"
|
|
|
|
|
@ -673,8 +676,31 @@
|
|
|
|
|
<el-table-column type="selection" width="55"></el-table-column>
|
|
|
|
|
<el-table-column prop="name" label="姓名" width="120"></el-table-column>
|
|
|
|
|
<el-table-column prop="email" label="邮箱" min-width="200"></el-table-column>
|
|
|
|
|
<el-table-column prop="courseName" label="课程名称" min-width="150"></el-table-column>
|
|
|
|
|
<el-table-column label="课程名称" min-width="200">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<div v-for="(item, index) in scope.row.course_signs" :key="index">
|
|
|
|
|
<div v-if="item.course" style="margin-bottom: 5px;">
|
|
|
|
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
|
|
|
|
<div>
|
|
|
|
|
{{item.course.year?item.course.year:''}}{{item.course.type_detail?item.course.type_detail.name+' | ':''}}{{item.course.name}}
|
|
|
|
|
</div>
|
|
|
|
|
<template v-for="state in apply_status_list">
|
|
|
|
|
<el-tag
|
|
|
|
|
v-if="item.status===state.id"
|
|
|
|
|
:key="state.id"
|
|
|
|
|
:type="state.type"
|
|
|
|
|
size="mini"
|
|
|
|
|
style="margin-left: 10px;">
|
|
|
|
|
{{state.value}}
|
|
|
|
|
</el-tag>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column prop="company" label="公司" min-width="150"></el-table-column>
|
|
|
|
|
<el-table-column prop="company_position" label="职务" min-width="120"></el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
<!-- 分页组件 -->
|
|
|
|
|
@ -718,10 +744,12 @@
|
|
|
|
|
import { saveEmailTemplate, getEmailTemplateList, deleteEmailTemplate } from '@/api/email/index'
|
|
|
|
|
import { uploadEmailRecord } from '@/api/email/index'
|
|
|
|
|
import { saveEmailRecord, getEmailRecordList, sendEmail } from '@/api/email/index'
|
|
|
|
|
import { index as getCourseList } from '@/api/course/index'
|
|
|
|
|
|
|
|
|
|
import { indexStudy } from '@/api/student/index.js'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'EmailManagement',
|
|
|
|
|
mixins: [require('@/mixin/selectMixin.js').default],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
activeTab: 'templates',
|
|
|
|
|
@ -774,8 +802,9 @@ export default {
|
|
|
|
|
|
|
|
|
|
// 系统数据导出相关
|
|
|
|
|
systemStudentSearch: '',
|
|
|
|
|
selectedCourseType: '', // 选中的课程
|
|
|
|
|
courseTypesList: [], // 课程列表
|
|
|
|
|
selectedCourse: '', // 选中的具体课程
|
|
|
|
|
courseList: [], // 具体课程列表
|
|
|
|
|
selectedStatus: '', // 审核状态筛选
|
|
|
|
|
selectedSystemStudents: [], // 当前页的选择
|
|
|
|
|
allSelectedStudents: [], // 总的选择对象数组,保存所有分页中的选择
|
|
|
|
|
studentsLoading: false,
|
|
|
|
|
@ -1439,8 +1468,9 @@ export default {
|
|
|
|
|
this.selectedSystemStudents = [] // 清空当前页选择
|
|
|
|
|
this.allSelectedStudents = [] // 清空总选择数组
|
|
|
|
|
this.systemStudentSearch = '' // 清空搜索关键词
|
|
|
|
|
this.selectedCourseType = '' // 清空课程选择
|
|
|
|
|
this.loadCourseTypes() // 加载课程列表
|
|
|
|
|
this.selectedCourse = '' // 清空具体课程选择
|
|
|
|
|
this.courseList = [] // 清空课程列表
|
|
|
|
|
this.loadCourses() // 加载课程列表
|
|
|
|
|
this.loadStudents() // 加载数据
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -1487,13 +1517,34 @@ export default {
|
|
|
|
|
|
|
|
|
|
// 准备Excel数据
|
|
|
|
|
const excelData = [
|
|
|
|
|
['姓名', '邮箱', '课程名称', '公司'],
|
|
|
|
|
...uniqueSelections.map(student => [
|
|
|
|
|
student.name,
|
|
|
|
|
student.email,
|
|
|
|
|
student.courseName || '',
|
|
|
|
|
student.company || ''
|
|
|
|
|
])
|
|
|
|
|
['姓名', '邮箱', '课程名称', '公司', '职务'],
|
|
|
|
|
...uniqueSelections.map(student => {
|
|
|
|
|
// 构建课程名称和状态字符串
|
|
|
|
|
let courseInfo = ''
|
|
|
|
|
if (student.course_signs && student.course_signs.length > 0) {
|
|
|
|
|
const courseStrings = student.course_signs.map(item => {
|
|
|
|
|
if (item.course) {
|
|
|
|
|
const courseName = `${item.course.year || ''}${item.course.type_detail ? item.course.type_detail.name + ' | ' : ''}${item.course.name}`
|
|
|
|
|
// 查找对应的审核状态
|
|
|
|
|
const statusItem = this.apply_status_list.find(state => state.id === item.status)
|
|
|
|
|
const statusText = statusItem ? statusItem.value : '未知状态'
|
|
|
|
|
return `${courseName} (${statusText})`
|
|
|
|
|
}
|
|
|
|
|
return ''
|
|
|
|
|
}).filter(text => text) // 过滤空字符串
|
|
|
|
|
courseInfo = courseStrings.join('\n')
|
|
|
|
|
} else {
|
|
|
|
|
courseInfo = student.courseName || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
student.name,
|
|
|
|
|
student.email,
|
|
|
|
|
courseInfo,
|
|
|
|
|
student.company || '',
|
|
|
|
|
student.company_position || ''
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
// 创建工作簿
|
|
|
|
|
@ -1505,7 +1556,8 @@ export default {
|
|
|
|
|
{ wch: 15 }, // 姓名
|
|
|
|
|
{ wch: 25 }, // 邮箱
|
|
|
|
|
{ wch: 20 }, // 课程名称
|
|
|
|
|
{ wch: 20 } // 公司
|
|
|
|
|
{ wch: 20 }, // 公司
|
|
|
|
|
{ wch: 12 } // 职务
|
|
|
|
|
]
|
|
|
|
|
worksheet['!cols'] = colWidths
|
|
|
|
|
|
|
|
|
|
@ -1581,244 +1633,200 @@ export default {
|
|
|
|
|
this.$message.success(`已在控制台打印 ${uniqueSelections.length} 条数据(去重后,包含所有分页选择)`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载课程列表
|
|
|
|
|
loadCourseTypes() {
|
|
|
|
|
getCourseList({
|
|
|
|
|
page: 1,
|
|
|
|
|
page_size: 999,
|
|
|
|
|
sort_name: 'id',
|
|
|
|
|
sort_type: 'ASC'
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.courseTypesList = res.data
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('加载课程列表失败:', error)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 课程选择变化处理
|
|
|
|
|
handleCourseTypeChange(courseId) {
|
|
|
|
|
if (courseId) {
|
|
|
|
|
// 找到选中的课程
|
|
|
|
|
const selectedCourse = this.courseTypesList.find(course => course.id === courseId)
|
|
|
|
|
if (selectedCourse) {
|
|
|
|
|
// 将课程名称赋值给搜索框
|
|
|
|
|
this.systemStudentSearch = selectedCourse.name
|
|
|
|
|
// 清空当前页选择
|
|
|
|
|
this.selectedSystemStudents = []
|
|
|
|
|
// 重置分页到第一页
|
|
|
|
|
this.currentPage = 1
|
|
|
|
|
// 调用loadStudents进行搜索
|
|
|
|
|
this.loadStudents()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 清空课程选择时,清空搜索框
|
|
|
|
|
this.systemStudentSearch = ''
|
|
|
|
|
// 清空当前页选择
|
|
|
|
|
this.selectedSystemStudents = []
|
|
|
|
|
// 重置分页到第一页
|
|
|
|
|
this.currentPage = 1
|
|
|
|
|
// 重新加载学员数据
|
|
|
|
|
this.loadStudents()
|
|
|
|
|
}
|
|
|
|
|
handleCourseChange() {
|
|
|
|
|
// 切换具体课程时,重置分页并刷新
|
|
|
|
|
this.selectedSystemStudents = []
|
|
|
|
|
this.currentPage = 1
|
|
|
|
|
this.loadStudents()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载学员数据
|
|
|
|
|
loadStudents() {
|
|
|
|
|
this.studentsLoading = true
|
|
|
|
|
// 调用API获取学员数据
|
|
|
|
|
import('@/api/student/index').then(({ index }) => {
|
|
|
|
|
// 构建查询参数
|
|
|
|
|
const params = {
|
|
|
|
|
has_course: 1,
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
if (this.selectedStatus !== '' && this.selectedStatus !== null) {
|
|
|
|
|
params.status = this.selectedStatus
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
indexStudy(params).then(res => {
|
|
|
|
|
// 保存当前的选择状态
|
|
|
|
|
const currentSelection = [...this.selectedSystemStudents]
|
|
|
|
|
console.log('保存当前选择状态:', currentSelection.length)
|
|
|
|
|
console.log('当前总选择数组:', this.allSelectedStudents)
|
|
|
|
|
|
|
|
|
|
// 添加课程筛选参数
|
|
|
|
|
if (this.selectedCourseType) {
|
|
|
|
|
params.course_id = this.selectedCourseType
|
|
|
|
|
// 将当前页选择添加到总选择数组,并去重
|
|
|
|
|
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})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index(params, false).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)
|
|
|
|
|
// 处理API返回的数据(与学员列表一致的结构)
|
|
|
|
|
const listData = res.list && Array.isArray(res.list.data) ? res.list.data : []
|
|
|
|
|
if (Array.isArray(listData)) {
|
|
|
|
|
// 处理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 || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 || ''
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 更新分页信息(来自 res.list)
|
|
|
|
|
if (res.list) {
|
|
|
|
|
this.totalStudents = res.list.total || 0
|
|
|
|
|
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
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('去重后的总选择数组:', this.allSelectedStudents)
|
|
|
|
|
// 处理API返回的数据
|
|
|
|
|
console.log('API响应数据:', res) // 调试信息
|
|
|
|
|
console.log('res.data类型:', typeof res.data, '长度:', res.data ? res.data.length : 'undefined')
|
|
|
|
|
if (res.data) {
|
|
|
|
|
// 处理API返回的数据,确保包含必要的字段
|
|
|
|
|
console.log('开始处理学员数据,数量:', res.data.length)
|
|
|
|
|
this.students = res.data.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 || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 恢复选择状态
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.selectedSystemStudents = currentSelection
|
|
|
|
|
console.log('已恢复选择状态,数量:', this.selectedSystemStudents.length)
|
|
|
|
|
|
|
|
|
|
// 更新分页信息
|
|
|
|
|
this.totalStudents = res.total || 0
|
|
|
|
|
this.currentPage = res.current_page || 1
|
|
|
|
|
this.pageSize = res.per_page || 20
|
|
|
|
|
console.log('数据处理完成,this.students长度:', this.students.length)
|
|
|
|
|
console.log('分页信息更新:', {
|
|
|
|
|
total: this.totalStudents,
|
|
|
|
|
currentPage: this.currentPage,
|
|
|
|
|
pageSize: this.pageSize
|
|
|
|
|
})
|
|
|
|
|
// 恢复表格的视觉勾选状态
|
|
|
|
|
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 })))
|
|
|
|
|
|
|
|
|
|
// 恢复选择状态
|
|
|
|
|
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})`)
|
|
|
|
|
// 恢复当前页的选择状态
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
console.log('表格勾选状态恢复完成')
|
|
|
|
|
if (isInAllSelected && !isInCurrentSelection) {
|
|
|
|
|
// 这个学员在总选择数组中,但不在当前页选择中,需要勾选
|
|
|
|
|
this.$refs.systemStudentTable.toggleRowSelection(student, true)
|
|
|
|
|
console.log(`✅ 从总选择恢复勾选: ${student.name} (ID: ${student.id})`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.students = []
|
|
|
|
|
// 即使没有数据,也要保持分页信息
|
|
|
|
|
if (res.total !== undefined) {
|
|
|
|
|
this.totalStudents = res.total
|
|
|
|
|
}
|
|
|
|
|
if (res.current_page !== undefined) {
|
|
|
|
|
this.currentPage = res.current_page
|
|
|
|
|
}
|
|
|
|
|
if (res.per_page !== undefined) {
|
|
|
|
|
this.pageSize = res.per_page
|
|
|
|
|
}
|
|
|
|
|
// 只有在真正没有数据时才显示警告
|
|
|
|
|
if (res.data && res.data.length === 0) {
|
|
|
|
|
this.$message.warning('当前页暂无学员数据')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('表格勾选状态恢复完成')
|
|
|
|
|
})
|
|
|
|
|
} 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
|
|
|
|
|
}
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('加载学员数据失败:', error)
|
|
|
|
|
this.$message.error('加载学员数据失败')
|
|
|
|
|
// 加载失败时使用空数组
|
|
|
|
|
this.students = []
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.studentsLoading = false
|
|
|
|
|
if (Array.isArray(listData) && listData.length === 0) {
|
|
|
|
|
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 })))
|
|
|
|
|
|
|
|
|
|
// 恢复之前的选择状态
|
|
|
|
|
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 })))
|
|
|
|
|
// 恢复所有应该勾选的学员(包括当前页选择和总选择数组中的)
|
|
|
|
|
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.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})`)
|
|
|
|
|
}
|
|
|
|
|
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中已恢复选择状态')
|
|
|
|
|
})
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('导入API模块失败:', error)
|
|
|
|
|
this.$message.error('系统模块加载失败')
|
|
|
|
|
this.students = []
|
|
|
|
|
this.studentsLoading = false
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -1828,6 +1836,7 @@ export default {
|
|
|
|
|
this.currentPage = 1 // 重置分页到第一页
|
|
|
|
|
this.selectedSystemStudents = [] // 清空当前页选择
|
|
|
|
|
this.allSelectedStudents = [] // 清空总选择数组
|
|
|
|
|
this.selectedCourse = '' // 清空具体课程选择
|
|
|
|
|
this.loadStudents() // 执行搜索
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -1861,6 +1870,21 @@ export default {
|
|
|
|
|
document.body.removeChild(link)
|
|
|
|
|
|
|
|
|
|
this.$message.success(`已导出 ${this.recipients.length} 个收件人数据`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载具体课程列表
|
|
|
|
|
loadCourses() {
|
|
|
|
|
// 直接加载所有课程列表
|
|
|
|
|
import('@/api/course/index').then(({ index }) => {
|
|
|
|
|
index({
|
|
|
|
|
page: 1,
|
|
|
|
|
page_size: 999
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.courseList = res.data || []
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.error('加载课程列表失败:', error)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|