Files
Academic-Affairs-System/web/src/views/StudentStatusChangesView.vue
T

610 lines
36 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { Check, Close, Plus, RefreshRight, Stamp } from '@element-plus/icons-vue'
import http, { apiErrorMessage } from '../api/http'
import { useAuthStore } from '../stores/auth'
type ChangeState =
| 'Submitted'
| 'CounselorApproved'
| 'CollegeApproved'
| 'Approved'
| 'Rejected'
| 'Cancelled'
const auth = useAuthStore()
const { locale, t } = useI18n()
const isStudent = computed(() => auth.user?.roles.includes('Student') ?? false)
const canApplyForStudent = computed(() => (auth.user?.roles ?? []).some(role => ['Counselor', 'CollegeAdmin', 'AcademicAdmin', 'SuperAdmin'].includes(role)))
const canCorrect = computed(() => auth.user?.effectiveDataScope === 'All' && (auth.user.roles ?? []).some(role => ['AcademicAdmin', 'SuperAdmin'].includes(role)))
const changes = ref<any[]>([])
const options = ref<any | null>(null)
const proxyOptions = ref<any | null>(null)
const formOptions = computed(() => proxyApply.value ? proxyOptions.value : options.value)
const proxyApply = ref(false)
const proxyStudentId = ref('')
const studentSearch = ref<any[]>([])
const studentSearchLoading = ref(false)
let studentSearchVersion = 0
const correctionDialog = ref(false)
const correctionStudentId = ref('')
const correctionOptions = ref<any | null>(null)
const correctionForm = reactive({ targetStatus: '', targetClassId: '', reason: '' })
const dischargeDialog = ref(false)
const dischargeForProxy = ref(false)
const dischargeReports = ref<any[]>([])
const dischargeDeadlines = ref<any[]>([])
const dischargeForm = reactive({ dischargeDate: '', notes: '' })
const loading = ref(false)
const applyDialog = ref(false)
const reviewDialog = ref(false)
const selected = ref<any | null>(null)
const reviewApproved = ref(true)
const receivingReview = ref(false)
const applyForm = reactive({ type: '', reason: '', affectedTermId: '', targetClassId: '', serviceStartDate: '', dischargeDate: '' })
const terms = ref<any[]>([])
const classes = ref<any[]>([])
const courseImpact = ref<any[]>([])
const impactLoading = ref(false)
const impactError = ref(false)
const acknowledgeDraftArchive = ref(false)
const archiveDialog = ref(false)
const archivedGrades = ref<any[]>([])
const reviewForm = reactive({ comment: '' })
const page = ref(1)
const total = ref(0)
const actionableTotal = ref(0)
const finishedTotal = ref(0)
const pageSize = 20
watch(() => applyForm.type, type => {
applyForm.targetClassId = ['Demotion', 'ClassTransfer', 'MajorTransfer'].includes(type) ? '' : (formOptions.value?.currentClassId ?? '')
})
const targetClasses = computed(() => classes.value.filter(item => {
if (!item.isEnabled) return false
if (applyForm.type === 'MajorTransfer') return item.majorId !== formOptions.value?.majorId
if (item.majorId !== formOptions.value?.majorId) return false
if (applyForm.type === 'Demotion') return item.grade > formOptions.value?.currentGrade
if (applyForm.type === 'ClassTransfer') return item.grade === formOptions.value?.currentGrade && item.id !== formOptions.value?.currentClassId
return true
}))
const typeLabel = (value: string) => t(`statusChanges.types.${value}`)
const statusLabel = (value: string) => t(`statusChanges.statuses.${value}`)
const stateLabel = (value: string) => t(`statusChanges.states.${value}`)
const passedLabel = (value: boolean | null) => value == null ? '—' : t(value ? 'studentCurriculum.pass' : 'studentCurriculum.fail')
const resultLabel = (value: string | null) => value === 'Pass' ? t('studentCurriculum.pass') : value === 'Fail' ? t('studentCurriculum.fail') : value ?? '—'
const steps = computed(() => ['Submitted', 'CounselorApproved', 'CollegeApproved'].map(state => ({ state, label: t(`statusChanges.steps.${state}`) })))
function dateText(value?: string) {
if (!value) return '—'
return new Intl.DateTimeFormat(locale.value, {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', hour12: false,
}).format(new Date(value))
}
function stageIndex(state: ChangeState) {
if (state === 'Submitted') return 0
if (state === 'CounselorApproved') return 1
if (state === 'CollegeApproved') return 2
if (state === 'Approved') return 3
return -1
}
function stepClass(change: any, index: number) {
const current = stageIndex(change.state)
return {
done: change.state === 'Approved' || current > index,
active: current === index,
stopped: ['Rejected', 'Cancelled'].includes(change.state) && index === Math.max(current, 0),
}
}
function canReview(change: any) {
const roles = auth.user?.roles ?? []
return (
(change.state === 'Submitted' && roles.includes('Counselor')) ||
(change.state === 'CounselorApproved' && roles.includes('CollegeAdmin')) ||
(change.state === 'CollegeApproved' &&
roles.some((role) => ['AcademicAdmin', 'SuperAdmin'].includes(role)))
)
}
function canReviewReceivingCollege(change: any) {
const user = auth.user
return Boolean(user?.roles.includes('CollegeAdmin') && change.type === 'MajorTransfer' &&
change.state === 'CollegeApproved' && !change.receivingCollegeReviewedAt &&
change.originalCollegeId !== change.targetCollegeId &&
(user.effectiveDataScope === 'All' || user.collegeId === change.targetCollegeId))
}
function stateTagType(state: ChangeState) {
if (state === 'Approved') return 'success'
if (state === 'Rejected') return 'danger'
if (state === 'Cancelled') return 'info'
return 'warning'
}
async function load(resetPage = false) {
if (resetPage) page.value = 1
loading.value = true
try {
const requests = [http.get('/student-status-changes', {
params: { page: page.value, pageSize },
})]
if (isStudent.value) requests.push(http.get('/student-status-changes/options'))
const [changeResponse, optionResponse] = await Promise.all(requests)
changes.value = changeResponse.data.items
total.value = changeResponse.data.total
actionableTotal.value = changeResponse.data.actionableTotal
finishedTotal.value = changeResponse.data.finishedTotal
if (optionResponse) options.value = optionResponse.data
if (canApplyForStudent.value) await loadDischargeDeadlines()
if (changes.value.length === 0 && page.value > 1) {
page.value--
await load()
}
} catch (error) {
ElMessage.error(apiErrorMessage(error))
} finally {
loading.value = false
}
}
async function loadDischargeDeadlines() {
try { dischargeDeadlines.value = (await http.get('/student-status-changes/discharge-deadlines')).data }
catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
function openApply(proxy = false) {
proxyApply.value = proxy
proxyStudentId.value = ''
proxyOptions.value = null
studentSearch.value = []
applyForm.type = formOptions.value?.types?.[0] ?? ''
applyForm.reason = ''
applyForm.affectedTermId = terms.value.find(x => x.isCurrent)?.id ?? ''
applyForm.targetClassId = formOptions.value?.currentClassId ?? ''
applyForm.serviceStartDate = ''
applyForm.dischargeDate = formOptions.value?.dischargeDate ?? ''
applyDialog.value = true
}
async function searchStudents(keyword: string) {
const version = ++studentSearchVersion
if (keyword.trim().length < 2) { studentSearch.value = []; studentSearchLoading.value = false; return }
studentSearchLoading.value = true
try {
const result = await http.get('/student-status-changes/students/search', { params: { keyword } })
if (version === studentSearchVersion) studentSearch.value = result.data
} catch (error) { if (version === studentSearchVersion) ElMessage.error(apiErrorMessage(error)) }
finally { if (version === studentSearchVersion) studentSearchLoading.value = false }
}
async function selectProxyStudent(studentId: string) {
proxyOptions.value = null
applyForm.type = ''
if (!studentId) return
try {
const result = await http.get(`/student-status-changes/students/${studentId}/options`)
if (proxyStudentId.value !== studentId) return
proxyOptions.value = result.data
applyForm.type = proxyOptions.value?.types?.[0] ?? ''
applyForm.dischargeDate = proxyOptions.value?.dischargeDate ?? ''
} catch (error) { if (proxyStudentId.value === studentId) ElMessage.error(apiErrorMessage(error)) }
}
async function openDischargeReport(forProxy: boolean) {
dischargeForProxy.value = forProxy
const selectedOptions = forProxy ? proxyOptions.value : options.value
dischargeForm.dischargeDate = selectedOptions?.dischargeDate ?? ''
dischargeForm.notes = ''
const path = forProxy ? `/student-status-changes/students/${proxyStudentId.value}/discharge-reports` : '/student-status-changes/discharge-reports'
try {
dischargeReports.value = (await http.get(path)).data
dischargeDialog.value = true
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function manageDischargeDeadline(row: any) {
proxyStudentId.value = row.studentId
await selectProxyStudent(row.studentId)
if (proxyOptions.value?.requiresDischargeDate) await openDischargeReport(true)
}
async function submitDischargeReport() {
if (!dischargeForm.dischargeDate) { ElMessage.warning(t('statusChangeImpact.dischargeDateRequired')); return }
const path = dischargeForProxy.value ? `/student-status-changes/students/${proxyStudentId.value}/discharge-reports` : '/student-status-changes/discharge-reports'
try {
await http.post(path, dischargeForm)
dischargeDialog.value = false
ElMessage.success(t('statusChangeImpact.dischargeRecorded'))
if (dischargeForProxy.value) {
await selectProxyStudent(proxyStudentId.value)
await loadDischargeDeadlines()
}
else await load()
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
function openCorrection() {
correctionStudentId.value = ''
correctionOptions.value = null
correctionForm.targetStatus = ''
correctionForm.targetClassId = ''
correctionForm.reason = ''
studentSearch.value = []
correctionDialog.value = true
}
async function selectCorrectionStudent(studentId: string) {
correctionOptions.value = null
if (!studentId) return
try {
const result = await http.get(`/student-status-changes/students/${studentId}/options`)
if (correctionStudentId.value !== studentId) return
correctionOptions.value = result.data
correctionForm.targetStatus = correctionOptions.value.status
correctionForm.targetClassId = correctionOptions.value.currentClassId
} catch (error) { if (correctionStudentId.value === studentId) ElMessage.error(apiErrorMessage(error)) }
}
async function submitCorrection() {
if (!correctionStudentId.value || !correctionOptions.value || !correctionForm.targetClassId ||
!correctionForm.targetStatus || correctionForm.reason.trim().length < 10) {
ElMessage.warning(t('statusChangeImpact.correctionRequired'))
return
}
try {
await http.post(`/student-status-changes/students/${correctionStudentId.value}/data-correction`, {
expectedStatus: correctionOptions.value.status,
expectedClassId: correctionOptions.value.currentClassId,
...correctionForm,
})
correctionDialog.value = false
ElMessage.success(t('statusChangeImpact.correctionSaved'))
await load(true)
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function submitApply() {
if (proxyApply.value && (!proxyStudentId.value || !proxyOptions.value || proxyOptions.value.hasPending)) {
ElMessage.warning(t('statusChangeImpact.proxyStudentRequired'))
return
}
if (!applyForm.type || applyForm.reason.trim().length < 10) {
ElMessage.warning(t('statusChanges.messages.invalidApplication'))
return
}
if (!applyForm.affectedTermId) {
ElMessage.warning(t('statusChangeImpact.affectedTermRequired'))
return
}
if (['Resumption', 'Demotion', 'ClassTransfer', 'MajorTransfer'].includes(applyForm.type) && !applyForm.targetClassId) {
ElMessage.warning(t('statusChangeImpact.targetClassRequired'))
return
}
if (applyForm.type === 'Enlistment' && !applyForm.serviceStartDate) {
ElMessage.warning(t('statusChangeImpact.serviceDateRequired'))
return
}
if (applyForm.type === 'Resumption' && formOptions.value?.requiresDischargeDate && !applyForm.dischargeDate) {
ElMessage.warning(t('statusChangeImpact.dischargeDateRequired'))
return
}
try {
const path = proxyApply.value ? `/student-status-changes/students/${proxyStudentId.value}` : '/student-status-changes'
await http.post(path, { ...applyForm, affectedTermId: applyForm.affectedTermId, targetClassId: ['Resumption', 'Demotion', 'ClassTransfer', 'MajorTransfer'].includes(applyForm.type) ? applyForm.targetClassId : null, serviceStartDate: applyForm.type === 'Enlistment' ? applyForm.serviceStartDate : null, dischargeDate: applyForm.type === 'Resumption' && applyForm.dischargeDate ? applyForm.dischargeDate : null })
applyDialog.value = false
ElMessage.success(t('statusChanges.messages.submitted'))
await load(true)
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function cancel(change: any) {
try {
await ElMessageBox.confirm(t('statusChanges.messages.cancelConfirm'), t('statusChanges.messages.cancelTitle'), {
type: 'warning', confirmButtonText: t('statusChanges.confirmCancel'),
})
await http.post(`/student-status-changes/${change.id}/cancel`)
ElMessage.success(t('statusChanges.messages.cancelled'))
await load()
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
async function openReview(change: any, approved: boolean, receiving = false) {
selected.value = change
reviewApproved.value = approved
receivingReview.value = receiving
reviewForm.comment = ''
reviewDialog.value = true
courseImpact.value = []
impactError.value = false
acknowledgeDraftArchive.value = false
if (approved && ['Suspension', 'Withdrawal', 'Enlistment', 'Demotion', 'ClassTransfer', 'MajorTransfer'].includes(change.type)) {
impactLoading.value = true
try {
const response = await http.get(`/student-status-changes/${change.id}/course-impact`)
courseImpact.value = response.data.items
} catch (error) {
impactError.value = true
ElMessage.error(apiErrorMessage(error))
} finally {
impactLoading.value = false
}
}
}
async function submitReview() {
if (!reviewApproved.value && !reviewForm.comment.trim()) {
ElMessage.warning(t('statusChanges.messages.commentRequired'))
return
}
try {
await http.post(`/student-status-changes/${selected.value.id}/${receivingReview.value ? 'receiving-college-review' : 'review'}`, {
approved: reviewApproved.value,
comment: reviewForm.comment,
acknowledgeDraftGradeArchive: acknowledgeDraftArchive.value,
})
reviewDialog.value = false
ElMessage.success(t(reviewApproved.value ? 'statusChanges.messages.approved' : 'statusChanges.messages.rejected'))
await load()
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function showArchivedGrades(change: any) {
try {
archivedGrades.value = (await http.get(`/student-status-changes/${change.id}/archived-grades`)).data
archiveDialog.value = true
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
onMounted(async () => {
if (isStudent.value || canApplyForStudent.value) {
try {
const [termResponse, classResponse] = await Promise.all([http.get('/base-data/terms'), http.get('/base-data/classes')])
terms.value = termResponse.data
classes.value = classResponse.data
}
catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
await load()
})
</script>
<template>
<div class="page-stack status-change-page">
<section class="page-intro">
<div>
<span class="section-kicker">STUDENT RECORD TRANSFER</span>
<h2>{{ t(isStudent ? 'statusChanges.studentTitle' : 'statusChanges.reviewTitle') }}</h2><p>{{ t(isStudent ? 'statusChanges.studentDescription' : 'statusChanges.reviewDescription') }}</p>
</div>
<el-button
v-if="isStudent"
type="primary"
:icon="Plus"
:disabled="options?.hasPending || !options?.types?.length"
@click="openApply(false)"
>{{ t('statusChanges.apply') }}</el-button><el-button v-else :icon="RefreshRight" @click="() => load()">{{ t('statusChanges.refresh') }}</el-button>
<el-button v-if="canApplyForStudent" :icon="Plus" @click="openApply(true)">{{ t('statusChangeImpact.proxyApply') }}</el-button>
<el-button v-if="canCorrect" @click="openCorrection">{{ t('statusChangeImpact.correctionTitle') }}</el-button>
</section>
<section v-if="isStudent && options" class="status-identity">
<div>
<span>CURRENT STUDENT STATUS</span>
<b>{{ statusLabel(options.status) }}</b><p>{{ t(options.hasPending ? 'statusChanges.pendingHint' : 'statusChanges.availableHint') }}</p>
</div>
<div class="status-available">
<span>{{ t('statusChanges.availableTypes') }}</span><strong v-for="type in options.types" :key="type">{{ typeLabel(type) }}</strong><em v-if="!options.types.length">{{ t('statusChanges.noAvailableTypes') }}</em>
<template v-if="options.requiresDischargeDate">
<p v-if="options.dischargeDate">{{ t('statusChangeImpact.retentionUntil', { date: options.retainedUntil }) }}</p>
<p v-if="options.dischargeDate && options.retentionDaysRemaining <= 90">{{ t('statusChangeImpact.retentionReview') }}</p>
<el-button @click="openDischargeReport(false)">{{ t('statusChangeImpact.dischargeReport') }}</el-button>
</template>
</div>
</section>
<section v-if="!isStudent" class="status-review-summary">
<div><span>{{ t('statusChanges.actionable') }}</span><b>{{ actionableTotal }}</b><small>{{ t('statusChanges.itemUnit') }}</small></div><div><span>{{ t('statusChanges.total') }}</span><b>{{ total }}</b><small>{{ t('statusChanges.itemUnit') }}</small></div><div><span>{{ t('statusChanges.finished') }}</span><b>{{ finishedTotal }}</b><small>{{ t('statusChanges.itemUnit') }}</small></div><p>{{ t('statusChanges.securityNote') }}</p>
</section>
<section v-if="canApplyForStudent && dischargeDeadlines.length" class="status-folio-list">
<article>
<h3>{{ t('statusChangeImpact.deadlinesTitle') }}</h3>
<p>{{ t('statusChangeImpact.deadlinesHint') }}</p>
<el-table :data="dischargeDeadlines" max-height="360">
<el-table-column :label="t('statusChangeImpact.proxyStudent')"><template #default="scope">{{ scope.row.studentNumber }} · {{ scope.row.studentName }} · {{ scope.row.className }}</template></el-table-column>
<el-table-column prop="dischargeDate" :label="t('statusChangeImpact.dischargeDate')" />
<el-table-column prop="retainedUntil" :label="t('statusChangeImpact.referenceDate')" />
<el-table-column :label="t('statusChangeImpact.deadlineState')"><template #default="scope"><el-tag :type="scope.row.daysRemaining <= 90 ? 'warning' : 'info'">{{ t(scope.row.daysRemaining <= 90 ? 'statusChangeImpact.deadlineReview' : 'statusChangeImpact.deadlineTracked') }}</el-tag></template></el-table-column>
<el-table-column><template #default="scope"><el-button link @click="manageDischargeDeadline(scope.row)">{{ t('statusChangeImpact.dischargeReport') }}</el-button></template></el-table-column>
</el-table>
</article>
</section>
<section class="status-folio-list" v-loading="loading">
<article v-for="change in changes" :key="change.id" :class="{ actionable: canReview(change) }">
<header>
<div class="folio-number">
<span>APPLICATION FOLIO</span>
<b>{{ change.studentNumber }}</b>
</div>
<div class="folio-person">
<span>{{ change.collegeName }} · {{ change.className }}</span>
<h3>{{ t('statusChanges.applicationTitle', { name: change.name, type: typeLabel(change.type) }) }}</h3><p>{{ t('statusChanges.transition', { from: statusLabel(change.originalStatus), to: statusLabel(change.targetStatus), date: dateText(change.submittedAt) }) }}</p>
</div>
<el-tag :type="stateTagType(change.state)" effect="plain">{{ stateLabel(change.state) }}</el-tag>
</header>
<div class="folio-reason">
<span>{{ t('statusChanges.reason') }}</span>
<p>{{ change.reason }}</p>
<p v-if="change.affectedTermName">{{ t(change.type === 'Resumption' ? 'statusChangeImpact.resumptionTerm' : 'statusChangeImpact.affectedTerm') }}: {{ change.affectedTermName }}</p>
<p v-if="change.targetClassName">{{ t('statusChangeImpact.classTransition') }}: {{ change.originalClassName }} → {{ change.targetClassName }}</p>
<p v-if="change.serviceStartDate">{{ t('statusChangeImpact.serviceDate') }}: {{ change.serviceStartDate }}</p>
<p v-if="change.dischargeDate">{{ t('statusChangeImpact.dischargeDate') }}: {{ change.dischargeDate }}</p>
<p v-if="change.submittedByUserId && change.submittedByUserId !== change.studentUserId">{{ t('statusChangeImpact.proxySubmitted') }} · {{ change.submittedByName || change.submittedByUserId }}</p>
<p v-if="change.type === 'MajorTransfer' && change.originalCollegeId !== change.targetCollegeId">{{ t(change.receivingCollegeReviewedAt ? 'statusChangeImpact.receivingReviewed' : 'statusChangeImpact.receivingPending') }}<span v-if="change.receivingCollegeReviewComment"> · {{ change.receivingCollegeReviewComment }}</span></p>
</div>
<div class="approval-track">
<div v-for="(step, index) in steps" :key="step.state" :class="stepClass(change, index)">
<i><el-icon v-if="stepClass(change, index).done"><Check /></el-icon><span v-else>{{ index + 1 }}</span></i>
<b>{{ step.label }}</b>
<small>{{ t(stepClass(change, index).done ? 'statusChanges.stepPassed' : stepClass(change, index).active ? 'statusChanges.stepActive' : 'statusChanges.stepWaiting') }}</small>
</div>
</div>
<footer>
<div v-if="change.reviewComment" class="review-comment">
<span>{{ t('statusChanges.latestComment') }}</span><b>{{ change.reviewComment }}</b>
</div>
<div v-else class="review-comment"><span>{{ t('statusChanges.processId') }}</span><b>{{ change.id.slice(0, 8).toUpperCase() }}</b></div>
<div class="folio-actions">
<el-button @click="$router.push({ path: '/approvals', query: { progressType: 'StudentStatusChange', progressId: change.id } })">{{ t('approvalProgress.title') }}</el-button>
<el-button v-if="change.state === 'Approved' && change.type !== 'DataCorrection'" @click="showArchivedGrades(change)">{{ t('statusChangeImpact.viewArchivedGrades') }}</el-button>
<el-button v-if="isStudent && change.state === 'Submitted'" type="danger" plain @click="cancel(change)">{{ t('statusChanges.cancelApplication') }}</el-button>
<template v-if="canReview(change)">
<el-button :icon="Close" type="danger" plain @click="openReview(change, false)">{{ t('statusChanges.reject') }}</el-button><el-button :icon="Stamp" type="primary" @click="openReview(change, true)">{{ t('statusChanges.approve') }}</el-button>
</template>
<template v-if="canReviewReceivingCollege(change)">
<el-button type="danger" plain @click="openReview(change, false, true)">{{ t('statusChangeImpact.receivingReject') }}</el-button>
<el-button type="primary" @click="openReview(change, true, true)">{{ t('statusChangeImpact.receivingApprove') }}</el-button>
</template>
</div>
</footer>
</article>
<el-empty v-if="!changes.length && !loading" :description="t(isStudent ? 'statusChanges.emptyStudent' : 'statusChanges.emptyReviewer')" />
<el-pagination
v-if="total > pageSize"
v-model:current-page="page"
:page-size="pageSize"
:total="total"
layout="total, prev, pager, next"
class="table-pagination"
@current-change="() => load()"
/>
</section>
<el-dialog v-model="applyDialog" :title="t('statusChanges.applyTitle')" width="620px">
<el-form label-position="top">
<el-form-item v-if="proxyApply" :label="t('statusChangeImpact.proxyStudent')" required>
<el-select v-model="proxyStudentId" filterable remote clearable :remote-method="searchStudents" :loading="studentSearchLoading" :placeholder="t('statusChangeImpact.proxyStudentHint')" style="width: 100%" @change="selectProxyStudent">
<el-option v-for="item in studentSearch" :key="item.id" :value="item.id" :label="`${item.studentNumber} · ${item.name} · ${item.className}`" />
</el-select>
<small v-if="proxyOptions?.hasPending">{{ t('statusChanges.pendingHint') }}</small>
<template v-if="proxyOptions?.requiresDischargeDate">
<small v-if="proxyOptions.dischargeDate">{{ t('statusChangeImpact.retentionUntil', { date: proxyOptions.retainedUntil }) }}</small>
<el-button @click="openDischargeReport(true)">{{ t('statusChangeImpact.dischargeReport') }}</el-button>
</template>
</el-form-item>
<el-form-item :label="t('statusChanges.type')">
<el-radio-group v-model="applyForm.type">
<el-radio-button v-for="type in formOptions?.types" :key="type" :value="type">{{ typeLabel(type) }}</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item :label="t('statusChanges.reason')"><el-input v-model="applyForm.reason" type="textarea" :rows="6" maxlength="1000" show-word-limit :placeholder="t('statusChanges.reasonPlaceholder')" />
</el-form-item>
<el-form-item :label="t(applyForm.type === 'Resumption' ? 'statusChangeImpact.resumptionTerm' : 'statusChangeImpact.affectedTerm')">
<el-select v-model="applyForm.affectedTermId" :placeholder="t('statusChangeImpact.affectedTermRequired')" style="width: 100%">
<el-option v-for="term in terms" :key="term.id" :label="term.name" :value="term.id" />
</el-select>
<small>{{ t(applyForm.type === 'Resumption' ? 'statusChangeImpact.resumptionTermHint' : ['Demotion', 'ClassTransfer', 'MajorTransfer'].includes(applyForm.type) ? 'statusChangeImpact.demotionTermHint' : 'statusChangeImpact.affectedTermHint') }}</small>
</el-form-item>
<el-form-item v-if="['Resumption', 'Demotion', 'ClassTransfer', 'MajorTransfer'].includes(applyForm.type)" :label="t('statusChangeImpact.targetClass')">
<el-select v-model="applyForm.targetClassId" filterable :placeholder="t('statusChangeImpact.targetClassRequired')" style="width: 100%">
<el-option v-for="item in targetClasses" :key="item.id" :label="`${item.majorName} · ${item.grade} · ${item.name}`" :value="item.id" />
</el-select>
<small>{{ t(applyForm.type === 'MajorTransfer' ? 'statusChangeImpact.majorTransferHint' : 'statusChangeImpact.targetClassHint') }}</small>
</el-form-item>
<el-form-item v-if="applyForm.type === 'Enlistment'" :label="t('statusChangeImpact.serviceDate')">
<el-date-picker v-model="applyForm.serviceStartDate" type="date" value-format="YYYY-MM-DD" />
</el-form-item>
<el-form-item v-if="applyForm.type === 'Resumption' && formOptions?.requiresDischargeDate" :label="t('statusChangeImpact.dischargeDate')">
<el-date-picker v-model="applyForm.dischargeDate" type="date" value-format="YYYY-MM-DD" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="applyDialog = false">{{ t('statusChanges.cancel') }}</el-button><el-button type="primary" @click="submitApply">{{ t('statusChanges.submit') }}</el-button>
</template>
</el-dialog>
<el-dialog v-model="dischargeDialog" :title="t('statusChangeImpact.dischargeReport')" width="620px">
<el-alert :title="t('statusChangeImpact.dischargeReportHint')" type="info" :closable="false" show-icon />
<el-form label-position="top">
<el-form-item :label="t('statusChangeImpact.dischargeDate')" required><el-date-picker v-model="dischargeForm.dischargeDate" type="date" value-format="YYYY-MM-DD" /></el-form-item>
<el-form-item :label="t('statusChangeImpact.dischargeNotes')"><el-input v-model="dischargeForm.notes" type="textarea" maxlength="500" show-word-limit /></el-form-item>
</el-form>
<el-table :data="dischargeReports" max-height="220">
<el-table-column prop="dischargeDate" :label="t('statusChangeImpact.dischargeDate')" />
<el-table-column :label="t('statusChangeImpact.reportedAt')"><template #default="scope">{{ dateText(scope.row.reportedAt) }}</template></el-table-column>
<el-table-column :label="t('statusChangeImpact.reportedBy')"><template #default="scope">{{ scope.row.reportedByName || scope.row.reportedByUserId }}</template></el-table-column>
<el-table-column prop="notes" :label="t('statusChangeImpact.dischargeNotes')" />
</el-table>
<template #footer><el-button @click="dischargeDialog = false">{{ t('statusChanges.cancel') }}</el-button><el-button type="primary" @click="submitDischargeReport">{{ t('statusChangeImpact.recordDischarge') }}</el-button></template>
</el-dialog>
<el-dialog v-model="correctionDialog" :title="t('statusChangeImpact.correctionTitle')" width="620px">
<el-alert :title="t('statusChangeImpact.correctionHint')" type="warning" :closable="false" show-icon />
<el-form label-position="top">
<el-form-item :label="t('statusChangeImpact.proxyStudent')" required>
<el-select v-model="correctionStudentId" filterable remote clearable :remote-method="searchStudents" :loading="studentSearchLoading" :placeholder="t('statusChangeImpact.proxyStudentHint')" style="width: 100%" @change="selectCorrectionStudent">
<el-option v-for="item in studentSearch" :key="item.id" :value="item.id" :label="`${item.studentNumber} · ${item.name} · ${item.className}`" />
</el-select>
</el-form-item>
<template v-if="correctionOptions">
<p>{{ t('statusChangeImpact.correctionCurrent', { status: statusLabel(correctionOptions.status), className: classes.find(x => x.id === correctionOptions.currentClassId)?.name ?? '—' }) }}</p>
<el-form-item :label="t('statusChangeImpact.correctionStatus')">
<el-select v-model="correctionForm.targetStatus"><el-option v-for="status in ['Active', 'Suspended', 'Retained', 'Graduated', 'Withdrawn']" :key="status" :value="status" :label="statusLabel(status)" /></el-select>
</el-form-item>
<el-form-item :label="t('statusChangeImpact.targetClass')">
<el-select v-model="correctionForm.targetClassId" filterable style="width: 100%"><el-option v-for="item in classes.filter(x => x.isEnabled)" :key="item.id" :value="item.id" :label="`${item.collegeName} · ${item.majorName} · ${item.name}`" /></el-select>
</el-form-item>
<el-form-item :label="t('statusChangeImpact.correctionReason')" required><el-input v-model="correctionForm.reason" type="textarea" :rows="4" maxlength="1000" show-word-limit /></el-form-item>
</template>
</el-form>
<template #footer><el-button @click="correctionDialog = false">{{ t('statusChanges.cancel') }}</el-button><el-button type="primary" @click="submitCorrection">{{ t('statusChangeImpact.correctionConfirm') }}</el-button></template>
</el-dialog>
<el-dialog v-model="reviewDialog" :title="t(receivingReview ? (reviewApproved ? 'statusChangeImpact.receivingApprove' : 'statusChangeImpact.receivingReject') : (reviewApproved ? 'statusChanges.approveTitle' : 'statusChanges.rejectTitle'))" width="600px">
<div v-if="selected" class="review-target">
<span>{{ selected.studentNumber }}</span>
<b>{{ t('statusChanges.applicationTitle', { name: selected.name, type: typeLabel(selected.type) }) }}</b>
<p>{{ selected.collegeName }} · {{ selected.className }}</p>
</div>
<el-form label-position="top">
<div v-if="reviewApproved && ['Suspension', 'Withdrawal', 'Enlistment', 'Demotion', 'ClassTransfer', 'MajorTransfer'].includes(selected?.type)" v-loading="impactLoading">
<h4>{{ t('statusChangeImpact.courseImpact') }}</h4>
<p>{{ t('statusChangeImpact.courseImpactHint') }}</p>
<el-table :data="courseImpact" max-height="260">
<el-table-column type="expand">
<template #default="scope">
<div v-if="scope.row.grade" class="grade-impact-detail">
<p>{{ t('statusChangeImpact.gradeSummary', { regular: scope.row.grade.regularScore ?? '—', final: scope.row.grade.finalScore ?? '—', total: scope.row.grade.totalScore ?? '—', exam: t(`studentCurriculum.examStatuses.${scope.row.grade.examStatus}`) }) }}</p>
<p>{{ t('statusChangeImpact.gradeResult', { result: resultLabel(scope.row.grade.result), passed: passedLabel(scope.row.grade.isPassed), point: scope.row.grade.gradePoint ?? '—' }) }}</p>
<p>{{ t('statusChangeImpact.gradeWeights', { method: t(`statusChangeImpact.evaluation.${scope.row.grade.evaluationMethod}`), regular: scope.row.grade.regularWeight, final: scope.row.grade.finalWeight }) }}</p>
<p v-for="item in scope.row.grade.items" :key="item.gradeItemId">{{ item.name }} ({{ item.weight }}%): {{ item.score ?? '—' }}</p>
<p v-if="scope.row.grade.notes">{{ scope.row.grade.notes }}</p>
</div>
</template>
</el-table-column>
<el-table-column prop="termName" :label="t('statusChangeImpact.affectedTerm')" />
<el-table-column prop="taskName" :label="t('statusChangeImpact.course')" />
<el-table-column :label="t('statusChangeImpact.disposition')">
<template #default="scope">{{ t(`statusChangeImpact.impact.${scope.row.disposition}`) }}</template>
</el-table-column>
</el-table>
<el-checkbox v-if="!receivingReview && selected?.state === 'CollegeApproved' && courseImpact.some(x => x.disposition === 'ArchiveDraftGrade')" v-model="acknowledgeDraftArchive">
{{ t('statusChangeImpact.acknowledgeDraftArchive') }}
</el-checkbox>
</div>
<el-form-item :label="t(reviewApproved ? 'statusChanges.optionalComment' : 'statusChanges.requiredReason')">
<el-input v-model="reviewForm.comment" type="textarea" :rows="4" maxlength="500" show-word-limit />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="reviewDialog = false">{{ t('statusChanges.cancel') }}</el-button><el-button :disabled="reviewApproved && (impactLoading || impactError || (selected?.state === 'CollegeApproved' && courseImpact.some(x => x.disposition === 'ReviewRequired')) || (!receivingReview && selected?.state === 'CollegeApproved' && courseImpact.some(x => x.disposition === 'ArchiveDraftGrade') && !acknowledgeDraftArchive))" :type="reviewApproved ? 'primary' : 'danger'" @click="submitReview">{{ t(reviewApproved ? 'statusChanges.confirmApprove' : 'statusChanges.confirmReject') }}</el-button>
</template>
</el-dialog>
<el-dialog v-model="archiveDialog" :title="t('statusChangeImpact.viewArchivedGrades')" width="680px">
<el-empty v-if="!archivedGrades.length" :description="t('statusChangeImpact.noArchivedGrades')" />
<div v-for="entry in archivedGrades" :key="entry.id" class="grade-impact-detail">
<h4>{{ entry.taskName }}</h4>
<p>{{ t('statusChangeImpact.archiveTime', { date: dateText(entry.archivedAt), actor: entry.archivedByUserId }) }}</p>
<p>{{ t('statusChangeImpact.gradeSummary', { regular: entry.snapshot.regularScore ?? '—', final: entry.snapshot.finalScore ?? '—', total: entry.snapshot.totalScore ?? '—', exam: t(`studentCurriculum.examStatuses.${entry.snapshot.examStatus}`) }) }}</p>
<p>{{ t('statusChangeImpact.gradeResult', { result: resultLabel(entry.snapshot.result), passed: passedLabel(entry.snapshot.isPassed), point: entry.snapshot.gradePoint ?? '—' }) }}</p>
<p>{{ t('statusChangeImpact.gradeWeights', { method: t(`statusChangeImpact.evaluation.${entry.snapshot.sheet.evaluationMethod}`), regular: entry.snapshot.sheet.regularWeight, final: entry.snapshot.sheet.finalWeight }) }}</p>
<p v-for="item in entry.snapshot.items" :key="item.gradeItemId">{{ item.name }} ({{ item.weight }}%): {{ item.score ?? '—' }}</p>
<p v-if="entry.snapshot.notes">{{ entry.snapshot.notes }}</p>
</div>
</el-dialog>
</div>
</template>