This commit is contained in:
zhouwentao 2026-01-24 19:39:47 +08:00
parent 738e969a98
commit 796bb6b2f6
1 changed files with 52 additions and 18 deletions

View File

@ -125,6 +125,7 @@ const modalMajors = ref<MajorDetail[]>([])
// 选课/志愿相关状态 // 选课/志愿相关状态
const selectedMajorCodes = ref<string[]>([]) // 存储已选的专业Code,数组顺序即为志愿顺序 const selectedMajorCodes = ref<string[]>([]) // 存储已选的专业Code,数组顺序即为志愿顺序
const batchMap = ref<Record<string, string>>({}) // 存储每个 schoolCode_majorCode_enrollmentCode 对应的批次名称 (提前批/本科批/专科批)
const showSaveConfirm = ref(false) // 控制气泡确认框显示 const showSaveConfirm = ref(false) // 控制气泡确认框显示
const isSaving = ref(false) // 保存接口Loading状态 const isSaving = ref(false) // 保存接口Loading状态
@ -300,10 +301,13 @@ function toggleMajor(major: any) {
if (index > -1) { if (index > -1) {
// 已存在,移除 // 已存在,移除
selectedMajorCodes.value.splice(index, 1) selectedMajorCodes.value.splice(index, 1)
delete batchMap.value[fullCode]
} }
else { else {
// 不存在,加入 // 不存在,加入
selectedMajorCodes.value.push(fullCode) selectedMajorCodes.value.push(fullCode)
// 统一批次标识
batchMap.value[fullCode] = major.batch === '本科' ? '本科批' : (major.batch === '专科' || major.batch === '高职高专' ? '专科批' : '提前批')
} }
} }
@ -311,9 +315,14 @@ function toggleMajor(major: any) {
function getVolunteerBtnText(major: any) { function getVolunteerBtnText(major: any) {
if (!currentSchool.value) return '加入志愿单' if (!currentSchool.value) return '加入志愿单'
const fullCode = `${currentSchool.value.schoolCode}_${major.code}_${major.enrollmentCode || currentSchool.value.enrollmentCode}` const fullCode = `${currentSchool.value.schoolCode}_${major.code}_${major.enrollmentCode || currentSchool.value.enrollmentCode}`
const index = selectedMajorCodes.value.indexOf(fullCode) const indexInAll = selectedMajorCodes.value.indexOf(fullCode)
if (index > -1) {
return `志愿 ${index + 1}` if (indexInAll > -1) {
// 独立计算该批次的序号
const currentBatch = batchMap.value[fullCode]
const batchCodes = selectedMajorCodes.value.filter(code => batchMap.value[code] === currentBatch)
const indexInBatch = batchCodes.indexOf(fullCode)
return `志愿 ${indexInBatch + 1}`
} }
return '加入志愿单' return '加入志愿单'
} }
@ -331,17 +340,18 @@ async function fetchVolunteerDetail() {
Object.keys(res.items).forEach(batch => { Object.keys(res.items).forEach(batch => {
const items = res.items[batch].map(item => ({...item, batchName: batch})) const items = res.items[batch].map(item => ({...item, batchName: batch}))
allItems.push(...items) allItems.push(...items)
// 更新 Tab 计数
const tab = volunteerTabs.value.find((t: any) => t.key === batch)
if (tab) {
tab.count = res.items[batch].length
}
}) })
myVolunteers.value = allItems myVolunteers.value = allItems
// 备份原始数据用于变动对比 // 备份原始数据用于变动对比
originalVolunteers.value = JSON.parse(JSON.stringify(allItems)) originalVolunteers.value = JSON.parse(JSON.stringify(allItems))
// 初始化 batchMap
batchMap.value = {}
myVolunteers.value.forEach(v => {
const fullCode = `${v.schoolCode}_${v.majorCode}_${v.enrollmentCode}`
batchMap.value[fullCode] = (v as any).batchName
})
} }
} catch (error) { } catch (error) {
console.error('获取志愿详情失败:', error) console.error('获取志愿详情失败:', error)
@ -358,6 +368,15 @@ const filteredVolunteers = computed(() => {
return myVolunteers.value.filter(v => (v as any).batchName === volunteerCurrentTab.value) return myVolunteers.value.filter(v => (v as any).batchName === volunteerCurrentTab.value)
}) })
/**
* 监听志愿列表变化,自动更新页签计数
*/
watch(myVolunteers, (newVal) => {
volunteerTabs.value.forEach((tab: any) => {
tab.count = newVal.filter(v => (v as any).batchName === tab.key).length
})
}, { deep: true })
/** /**
* 是否修改了志愿列表(拖拽排序或删除) * 是否修改了志愿列表(拖拽排序或删除)
*/ */
@ -515,9 +534,24 @@ function handleDragEnd() {
// 这里可以调用保存接口 API // 这里可以调用保存接口 API
} }
function removeVolunteer(index: number) { function removeVolunteer(vol: VolunteerItem) {
// index 是在 myVolunteers 中的索引 const realIndex = myVolunteers.value.findIndex(v => v.id === vol.id)
myVolunteers.value.splice(index, 1) if (realIndex > -1) {
const item = myVolunteers.value[realIndex]
const fullCode = `${item.schoolCode}_${item.majorCode}_${item.enrollmentCode}`
// 1. 从列表删除
myVolunteers.value.splice(realIndex, 1)
// 2. 从已选代码中删除 (回显逻辑依赖此)
const codeIndex = selectedMajorCodes.value.indexOf(fullCode)
if (codeIndex > -1) {
selectedMajorCodes.value.splice(codeIndex, 1)
}
// 3. 从批次映射中删除
delete batchMap.value[fullCode]
}
} }
function handleCreatePlan() { function handleCreatePlan() {
@ -922,13 +956,13 @@ function deletePlan(planId: string) {
<div> <div>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<h2 class="text-2xl text-slate-800 font-bold"> <h2 class="text-2xl text-slate-800 font-bold">
{{ volunteerPlans.find(p => p.id === activePlanId)?.name || '未命名方案' }} {{ currentVolunteerInfo?.volunteerName || '未命名方案' }}
</h2> </h2>
<span class="border border-orange-100 rounded bg-orange-50 px-2 py-0.5 text-xs text-orange-500"> <span class="border border-orange-100 rounded bg-orange-50 px-2 py-0.5 text-xs text-orange-500">
{{ volunteerPlans.find(p => p.id === activePlanId)?.tag || '手动' }} {{ volunteerPlans.find(p => p.id === activePlanId)?.tag || '手动' }}
</span> </span>
</div> </div>
<p class="mt-2 text-sm text-slate-500"> <p class="mt-2 text-left text-sm text-slate-500">
拖拽左侧手柄可调整顺序,共 <span class="text-blue-600 font-bold">{{ myVolunteers.length }}</span> 个志愿 拖拽左侧手柄可调整顺序,共 <span class="text-blue-600 font-bold">{{ myVolunteers.length }}</span> 个志愿
</p> </p>
</div> </div>
@ -1111,12 +1145,12 @@ function deletePlan(planId: string) {
<!-- 分数/概率 --> <!-- 分数/概率 -->
<td class="border-r border-slate-200 p-4 text-center"> <td class="border-r border-slate-200 p-4 text-center">
<div class="text-lg text-blue-600 font-bold"> <div class="text-lg font-bold">
{{ vol.enrollProbability }}% {{ vol.enrollProbability }}%
</div> </div>
<div class="mt-1 text-xs text-slate-500"> <!-- <div class="mt-1 text-xs text-slate-500">
排名 {{ vol.indexs }} 排名 {{ vol.indexs }}
</div> </div> -->
<div <div
class="mt-1 inline-block border rounded px-2 py-0.5 text-xs" class="mt-1 inline-block border rounded px-2 py-0.5 text-xs"
:class="getStatusColor(getProbabilityLabel(vol.enrollProbability))" :class="getStatusColor(getProbabilityLabel(vol.enrollProbability))"
@ -1137,7 +1171,7 @@ function deletePlan(planId: string) {
<button <button
class="rounded-full p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-700" class="rounded-full p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-700"
title="移除此志愿" title="移除此志愿"
@click="removeVolunteer(index)" @click="removeVolunteer(vol)"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24"