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 batchMap = ref<Record<string, string>>({}) // schoolCode_majorCode_enrollmentCode (//)
const showSaveConfirm = ref(false) //
const isSaving = ref(false) // Loading
@ -300,10 +301,13 @@ function toggleMajor(major: any) {
if (index > -1) {
//
selectedMajorCodes.value.splice(index, 1)
delete batchMap.value[fullCode]
}
else {
//
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) {
if (!currentSchool.value) return '加入志愿单'
const fullCode = `${currentSchool.value.schoolCode}_${major.code}_${major.enrollmentCode || currentSchool.value.enrollmentCode}`
const index = selectedMajorCodes.value.indexOf(fullCode)
if (index > -1) {
return `志愿 ${index + 1}`
const indexInAll = selectedMajorCodes.value.indexOf(fullCode)
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 '加入志愿单'
}
@ -331,17 +340,18 @@ async function fetchVolunteerDetail() {
Object.keys(res.items).forEach(batch => {
const items = res.items[batch].map(item => ({...item, batchName: batch}))
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
//
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) {
console.error('获取志愿详情失败:', error)
@ -358,6 +368,15 @@ const filteredVolunteers = computed(() => {
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
}
function removeVolunteer(index: number) {
// index myVolunteers
myVolunteers.value.splice(index, 1)
function removeVolunteer(vol: VolunteerItem) {
const realIndex = myVolunteers.value.findIndex(v => v.id === vol.id)
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() {
@ -922,13 +956,13 @@ function deletePlan(planId: string) {
<div>
<div class="flex items-center gap-3">
<h2 class="text-2xl text-slate-800 font-bold">
{{ volunteerPlans.find(p => p.id === activePlanId)?.name || '未命名方案' }}
{{ currentVolunteerInfo?.volunteerName || '未命名方案' }}
</h2>
<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 || '手动' }}
</span>
</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> 个志愿
</p>
</div>
@ -1111,12 +1145,12 @@ function deletePlan(planId: string) {
<!-- 分数/概率 -->
<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 }}%
</div>
<div class="mt-1 text-xs text-slate-500">
<!-- <div class="mt-1 text-xs text-slate-500">
排名 {{ vol.indexs }}
</div>
</div> -->
<div
class="mt-1 inline-block border rounded px-2 py-0.5 text-xs"
:class="getStatusColor(getProbabilityLabel(vol.enrollProbability))"
@ -1137,7 +1171,7 @@ function deletePlan(planId: string) {
<button
class="rounded-full p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-700"
title="移除此志愿"
@click="removeVolunteer(index)"
@click="removeVolunteer(vol)"
>
<svg
xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24"