fix: 科室变成下拉列表
This commit is contained in:
@@ -98,13 +98,44 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col v-if="canManageInstitution" :span="8">
|
<el-col v-if="canManageInstitution" :span="8">
|
||||||
<el-form-item label="机构ID">
|
<el-form-item label="机构">
|
||||||
<el-input-number v-model="draftForm.institution_id" :min="1" :precision="0" :controls="false" placeholder="缺省落创建者机构" />
|
<el-select
|
||||||
|
v-model="draftForm.institution_id"
|
||||||
|
:loading="loadingInstitutions"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择机构"
|
||||||
|
@change="handleInstitutionChange"
|
||||||
|
@visible-change="handleInstitutionVisibleChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in institutionOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="institutionOptionLabel(item)"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8">
|
<el-col :span="8">
|
||||||
<el-form-item label="科室名称">
|
<el-form-item label="科室">
|
||||||
<el-input v-model="draftForm.department_name" placeholder="请输入科室名称" />
|
<el-select
|
||||||
|
v-model="draftForm.department_id"
|
||||||
|
:disabled="canManageInstitution && !draftForm.institution_id"
|
||||||
|
:loading="loadingDepartments"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择科室"
|
||||||
|
@change="handleDepartmentChange"
|
||||||
|
@visible-change="handleDepartmentVisibleChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in departmentOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8">
|
<el-col :span="8">
|
||||||
@@ -245,6 +276,7 @@ import {
|
|||||||
type CreateCaseDraftPayload,
|
type CreateCaseDraftPayload,
|
||||||
type DraftCaseType
|
type DraftCaseType
|
||||||
} from '@/api/cases'
|
} from '@/api/cases'
|
||||||
|
import { fetchInstitutionList, fetchMyDepartments, type DepartmentOption, type InstitutionOption } from '@/api/users'
|
||||||
import { useAppStore } from '@/stores/app'
|
import { useAppStore } from '@/stores/app'
|
||||||
|
|
||||||
interface ScoringRuleForm {
|
interface ScoringRuleForm {
|
||||||
@@ -272,6 +304,7 @@ interface CaseDraftForm {
|
|||||||
title: string
|
title: string
|
||||||
case_type: DraftCaseType
|
case_type: DraftCaseType
|
||||||
institution_id?: number
|
institution_id?: number
|
||||||
|
department_id?: number
|
||||||
department_name: string
|
department_name: string
|
||||||
difficulty: string
|
difficulty: string
|
||||||
chief_complaint: string
|
chief_complaint: string
|
||||||
@@ -299,6 +332,10 @@ const draftFormRef = ref<FormInstance>()
|
|||||||
const generating = ref(false)
|
const generating = ref(false)
|
||||||
const savingDraft = ref(false)
|
const savingDraft = ref(false)
|
||||||
const result = ref<AiGenerateCaseResult | null>(null)
|
const result = ref<AiGenerateCaseResult | null>(null)
|
||||||
|
const institutionOptions = ref<InstitutionOption[]>([])
|
||||||
|
const departmentOptions = ref<DepartmentOption[]>([])
|
||||||
|
const loadingInstitutions = ref(false)
|
||||||
|
const loadingDepartments = ref(false)
|
||||||
|
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
case_type: 'traditional' as DraftCaseType,
|
case_type: 'traditional' as DraftCaseType,
|
||||||
@@ -309,6 +346,7 @@ const draftForm = reactive<CaseDraftForm>({
|
|||||||
title: '',
|
title: '',
|
||||||
case_type: 'traditional',
|
case_type: 'traditional',
|
||||||
institution_id: undefined,
|
institution_id: undefined,
|
||||||
|
department_id: undefined,
|
||||||
department_name: '',
|
department_name: '',
|
||||||
difficulty: '',
|
difficulty: '',
|
||||||
chief_complaint: '',
|
chief_complaint: '',
|
||||||
@@ -449,6 +487,7 @@ function resetDraftForm() {
|
|||||||
draftForm.title = ''
|
draftForm.title = ''
|
||||||
draftForm.case_type = 'traditional'
|
draftForm.case_type = 'traditional'
|
||||||
draftForm.institution_id = undefined
|
draftForm.institution_id = undefined
|
||||||
|
draftForm.department_id = undefined
|
||||||
draftForm.department_name = ''
|
draftForm.department_name = ''
|
||||||
draftForm.difficulty = ''
|
draftForm.difficulty = ''
|
||||||
draftForm.chief_complaint = ''
|
draftForm.chief_complaint = ''
|
||||||
@@ -478,6 +517,85 @@ function removeExamItem(index: number) {
|
|||||||
draftForm.exam_items.splice(index, 1)
|
draftForm.exam_items.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadInstitutionOptions() {
|
||||||
|
if (!appStore.token || !canManageInstitution.value || loadingInstitutions.value || institutionOptions.value.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadingInstitutions.value = true
|
||||||
|
institutionOptions.value = await fetchInstitutionList(appStore.token)
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '获取机构列表失败')
|
||||||
|
} finally {
|
||||||
|
loadingInstitutions.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadDepartmentOptions(institutionId?: number) {
|
||||||
|
if (!appStore.token || loadingDepartments.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (canManageInstitution.value && !institutionId) {
|
||||||
|
departmentOptions.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadingDepartments.value = true
|
||||||
|
departmentOptions.value = await fetchMyDepartments(appStore.token, institutionId)
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '获取科室列表失败')
|
||||||
|
} finally {
|
||||||
|
loadingDepartments.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInstitutionVisibleChange(visible: boolean) {
|
||||||
|
if (visible) {
|
||||||
|
loadInstitutionOptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDepartmentVisibleChange(visible: boolean) {
|
||||||
|
if (visible) {
|
||||||
|
loadDepartmentOptions(draftForm.institution_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInstitutionChange() {
|
||||||
|
draftForm.department_id = undefined
|
||||||
|
draftForm.department_name = ''
|
||||||
|
loadDepartmentOptions(draftForm.institution_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDepartmentChange(value?: number) {
|
||||||
|
draftForm.department_name = getDepartmentName(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncDepartmentSelectionByName() {
|
||||||
|
if (draftForm.department_id || !draftForm.department_name.trim()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const matched = departmentOptions.value.find(item => item.name === draftForm.department_name.trim())
|
||||||
|
if (matched) {
|
||||||
|
draftForm.department_id = matched.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDepartmentName(value?: number) {
|
||||||
|
if (!value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return departmentOptions.value.find(item => item.id === value)?.name || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function institutionOptionLabel(item: InstitutionOption) {
|
||||||
|
return item.code ? `${item.name} (${item.code})` : item.name
|
||||||
|
}
|
||||||
|
|
||||||
function buildDraftPayload(): CreateCaseDraftPayload {
|
function buildDraftPayload(): CreateCaseDraftPayload {
|
||||||
const structure = buildCaseStructure()
|
const structure = buildCaseStructure()
|
||||||
const scoringRules = normalizeScoringRules()
|
const scoringRules = normalizeScoringRules()
|
||||||
@@ -490,6 +608,7 @@ function buildDraftPayload(): CreateCaseDraftPayload {
|
|||||||
|
|
||||||
payload[draftForm.case_type] = structure
|
payload[draftForm.case_type] = structure
|
||||||
if (canManageInstitution.value && draftForm.institution_id) payload.institution_id = draftForm.institution_id
|
if (canManageInstitution.value && draftForm.institution_id) payload.institution_id = draftForm.institution_id
|
||||||
|
if (draftForm.department_id) payload.department_id = draftForm.department_id
|
||||||
if (draftForm.department_name.trim()) payload.department_name = draftForm.department_name.trim()
|
if (draftForm.department_name.trim()) payload.department_name = draftForm.department_name.trim()
|
||||||
if (draftForm.difficulty.trim()) payload.difficulty = draftForm.difficulty.trim()
|
if (draftForm.difficulty.trim()) payload.difficulty = draftForm.difficulty.trim()
|
||||||
if (draftForm.chief_complaint.trim()) payload.chief_complaint = draftForm.chief_complaint.trim()
|
if (draftForm.chief_complaint.trim()) payload.chief_complaint = draftForm.chief_complaint.trim()
|
||||||
@@ -609,6 +728,8 @@ function fillDraftFormFromGenerated(generatedResult: AiGenerateCaseResult) {
|
|||||||
|
|
||||||
draftForm.case_type = caseType
|
draftForm.case_type = caseType
|
||||||
draftForm.title = getGeneratedString(record, ['title', 'name', 'case_title', 'caseTitle'])
|
draftForm.title = getGeneratedString(record, ['title', 'name', 'case_title', 'caseTitle'])
|
||||||
|
draftForm.institution_id = getGeneratedNumber(record, ['institution_id', 'institutionId']) ?? undefined
|
||||||
|
draftForm.department_id = getGeneratedNumber(record, ['department_id', 'departmentId']) ?? undefined
|
||||||
draftForm.department_name = getGeneratedString(record, ['department_name', 'departmentName'])
|
draftForm.department_name = getGeneratedString(record, ['department_name', 'departmentName'])
|
||||||
draftForm.difficulty = getGeneratedString(record, ['difficulty'])
|
draftForm.difficulty = getGeneratedString(record, ['difficulty'])
|
||||||
draftForm.chief_complaint = getGeneratedString(record, ['chief_complaint', 'chiefComplaint'])
|
draftForm.chief_complaint = getGeneratedString(record, ['chief_complaint', 'chiefComplaint'])
|
||||||
@@ -646,6 +767,7 @@ function fillDraftFormFromGenerated(generatedResult: AiGenerateCaseResult) {
|
|||||||
: [{ dimension: '', score_weight: 1, ai_auto_score: true, scoring_standard: '' }]
|
: [{ dimension: '', score_weight: 1, ai_auto_score: true, scoring_standard: '' }]
|
||||||
draftForm.exam_items = examItems
|
draftForm.exam_items = examItems
|
||||||
draftFormRef.value?.clearValidate()
|
draftFormRef.value?.clearValidate()
|
||||||
|
loadDepartmentOptions(draftForm.institution_id).then(syncDepartmentSelectionByName)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTextList(value: string): string[] {
|
function parseTextList(value: string): string[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user