diff --git a/src/pages/simulate.vue b/src/pages/simulate.vue index 71902fd..1e107fd 100644 --- a/src/pages/simulate.vue +++ b/src/pages/simulate.vue @@ -125,6 +125,7 @@ const modalMajors = ref([]) // 选课/志愿相关状态 const selectedMajorCodes = ref([]) // 存储已选的专业Code,数组顺序即为志愿顺序 +const batchMap = ref>({}) // 存储每个 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) {

- {{ volunteerPlans.find(p => p.id === activePlanId)?.name || '未命名方案' }} + {{ currentVolunteerInfo?.volunteerName || '未命名方案' }}

{{ volunteerPlans.find(p => p.id === activePlanId)?.tag || '手动' }}
-

+

拖拽左侧手柄可调整顺序,共 {{ myVolunteers.length }} 个志愿

@@ -1111,12 +1145,12 @@ function deletePlan(planId: string) { -
+
{{ vol.enrollProbability }}%
-
+