<!-- 人员登记详情 --> <script name="RegisterDetail" lang="ts" setup> import { Refresh } from '@element-plus/icons-vue' import RegisterBasic from './component/basic.vue' import RegisterEducation from './component/education.vue' import RegisterAuthorize from './component/authorize.vue' import RegisterResume from './component/resume.vue' import RegisterVerifier from './component/verifier.vue' import RegisterTrainning from './component/trainning.vue' import type { IStaffBasicInfo } from './person-regitster' import { exportFile } from '@/utils/exportUtils' import { exportStaffDetail } from '@/api/resource/register' // 定义变量 const route = useRoute() const router = useRouter() const title = ref<string>('') const type = ref<string>('') const radioItems = ref([ { name: '基本信息', value: 'register-basic' }, { name: '教育科研', value: 'register-education' }, { name: '授权信息', value: 'register-authorize' }, { name: '人员证书', value: 'register-verifier' }, { name: '训练情况', value: 'register-trainning' }, ]) const current = ref<string>('') const currentLabel = ref<string>('') const staffId = ref<string>('') const staffDetail = ref<IStaffBasicInfo>() // 子组件的引用 const refRegisterBasic = ref() const refRegisterEducation = ref() const refRegisterAuthorize = ref() const refRegisterVerifier = ref() const refRegisterTrain = ref() // 逻辑 const printToWord = () => { exportStaffDetail({ id: staffId.value, pdf: false }).then((res) => { exportFile(res.data, `人员基本信息-${staffDetail.value?.staffName}-${staffDetail.value?.staffNo}.doc`) }) } const printToPDF = () => { exportStaffDetail({ id: staffId.value, pdf: true }).then((res) => { exportFile(res.data, `人员基本信息-${staffDetail.value?.staffName}-${staffDetail.value?.staffNo}.pdf`) }) } // 关闭 const resetForm = () => { sessionStorage.removeItem('staffBasicInfo') router.go(-1) } // 保存 const saveForm = () => { switch (current.value) { case 'register-basic': refRegisterBasic.value.saveBasicForm() break default: break } } // 弹窗初始化 const initDialog = (params: any) => { type.value = params.type current.value = radioItems.value[0].value currentLabel.value = radioItems.value[0].name switch (params.type) { case 'create' : title.value = '人员登记(新增)' break case 'update': title.value = '人员登记(编辑)' staffId.value = params.id // 调用子组件的方法 refRegisterBasic.value.getStaffBasicById(staffId.value) break case 'detail': title.value = '人员登记(详情)' staffId.value = params.id staffDetail.value = JSON.parse(sessionStorage.getItem('staffBasicInfo')!) // 调用子组件的方法 refRegisterBasic.value.getStaffBasicById(staffId.value) // 从标准库-详情-开展的检定或校准项目页面跳转过来,需要展示人员证书tab页 if (params.fromPage === 'standardDetailProject') { currentLabel.value = radioItems.value[3].name current.value = radioItems.value[3].value } break default: title.value = '' break } } const getStaffId = (id: string) => { staffId.value = id } const radioChangeHandler = (newVal: string | number | boolean) => { const radioTarget = radioItems.value.filter(item => item.name === newVal) if (radioTarget.length > 0) { currentLabel.value = radioTarget[0].name current.value = radioTarget[0].value } else { currentLabel.value = radioItems.value[0].name current.value = radioItems.value[0].value } } const refreshData = () => { switch (current.value) { case 'register-basic': refRegisterBasic.value.reloadStaffBasic(staffId.value) break case 'register-education': refRegisterEducation.value.getEducationListByStaffId(staffId.value) refRegisterEducation.value.getAbilityListByStaffId(staffId.value) refRegisterEducation.value.getProjectListByStaffId(staffId.value) break case 'register-authorize': refRegisterAuthorize.value.getAuthorizeListByStaffId(staffId.value) break case 'register-verifier': refRegisterVerifier.value.getVerifierListByStaffId(staffId.value) break case 'register-trainning': refRegisterTrain.value.getTrainningListByStaffId(staffId.value) break } } const eduFileChangeHandler = (filename: string) => { refRegisterBasic.value.setEducationFile(filename) } onMounted(() => { initDialog(route.query) }) </script> <template> <app-container style="overflow: hidden;"> <detail-page :title="`${title}`"> <template #btns> <template v-if="type === 'detail'"> <el-button type="primary" @click="printToWord()"> 导出Word </el-button> <el-button type="primary" @click="printToPDF()"> 导出PDF </el-button> </template> <el-button v-if="type !== 'detail' && current === 'register-basic'" type="primary" @click="saveForm()"> 保存 </el-button> <el-button type="info" @click="resetForm()"> 关闭 </el-button> </template> <div style="font-size: 0;"> <el-radio-group v-model="currentLabel" style="margin-bottom: 20px;" @change="radioChangeHandler"> <el-radio-button v-for="item in radioItems" :key="item.value" :label="item.name" :disabled="staffId === ''" /> </el-radio-group> <el-button :icon="Refresh" circle style="float: right;" @click="refreshData" /> </div> <register-basic v-show="current === 'register-basic'" ref="refRegisterBasic" :operation="type" @after-add-basic="getStaffId" @return-to-list="resetForm" /> <register-education v-show="current === 'register-education'" ref="refRegisterEducation" :operation="type" :staff-id="staffId" @education-file-changed="eduFileChangeHandler" /> <register-authorize v-show="current === 'register-authorize'" ref="refRegisterAuthorize" :operation="type" :staff-id="staffId" /> <register-verifier v-show="current === 'register-verifier'" ref="refRegisterVerifier" :operation="type" :staff-id="staffId" /> <register-trainning v-show="current === 'register-trainning'" ref="refRegisterTrain" :operation="type" :staff-id="staffId" /> </detail-page> </app-container> </template>