更新报告详情页面

This commit is contained in:
green 2025-11-23 12:32:46 +08:00
parent 90227161a2
commit 3429a8bb27

View File

@ -68,9 +68,9 @@
</el-table>
</div>
<!-- 答题详情量表类型报告 -->
<el-divider v-if="sourceType === 'assessment' && reportForm.assessmentId" content-position="left">答题详情</el-divider>
<div v-if="sourceType === 'assessment' && reportForm.assessmentId" class="answer-detail-section">
<!-- 答题详情量表和问卷类型报告 -->
<el-divider v-if="(sourceType === 'assessment' && reportForm.assessmentId) || (sourceType === 'questionnaire' && reportForm.answerId)" content-position="left">答题详情</el-divider>
<div v-if="(sourceType === 'assessment' && reportForm.assessmentId) || (sourceType === 'questionnaire' && reportForm.answerId)" class="answer-detail-section">
<el-button type="primary" icon="el-icon-document" @click="handleViewAnswers" :loading="answerDetailLoading">
查看答题详情
</el-button>
@ -114,13 +114,21 @@
<el-dialog title="答题详情" :visible.sync="answerDetailOpen" width="80%" append-to-body>
<div v-loading="answerDetailLoading">
<el-descriptions :column="2" border style="margin-bottom: 20px;">
<el-descriptions-item label="测评ID">{{ reportForm.assessmentId }}</el-descriptions-item>
<el-descriptions-item v-if="sourceType === 'assessment'" label="测评ID">{{ reportForm.assessmentId }}</el-descriptions-item>
<el-descriptions-item v-if="sourceType === 'questionnaire'" label="答题ID">{{ reportForm.answerId }}</el-descriptions-item>
<el-descriptions-item label="报告ID">{{ reportForm.reportId }}</el-descriptions-item>
<el-descriptions-item v-if="sourceType === 'assessment'" label="被测评人">{{ assessmentInfo.assesseeName || '-' }}</el-descriptions-item>
<el-descriptions-item v-if="sourceType === 'questionnaire'" label="答题人">{{ questionnaireInfo.respondentName || '-' }}</el-descriptions-item>
<el-descriptions-item label="提交时间">
<span v-if="assessmentInfo.submitTime">{{ parseTime(assessmentInfo.submitTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
<span v-if="sourceType === 'assessment' && assessmentInfo.submitTime">{{ parseTime(assessmentInfo.submitTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
<span v-else-if="sourceType === 'questionnaire' && questionnaireInfo.submitTime">{{ parseTime(questionnaireInfo.submitTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
<span v-else>-</span>
</el-descriptions-item>
<el-descriptions-item label="总分">
<span v-if="sourceType === 'assessment'">{{ assessmentInfo.totalScore || '-' }}</span>
<span v-else-if="sourceType === 'questionnaire'">{{ questionnaireInfo.totalScore || '-' }}</span>
<span v-else>-</span>
</el-descriptions-item>
<el-descriptions-item label="总分">{{ assessmentInfo.totalScore || '-' }}</el-descriptions-item>
<el-descriptions-item label="答题数量">{{ answerDetailList.length }} </el-descriptions-item>
</el-descriptions>
@ -131,9 +139,13 @@
<el-table-column label="题目内容" prop="itemContent" min-width="200" :show-overflow-tooltip="true" />
<el-table-column label="题目类型" prop="itemType" width="100" align="center">
<template slot-scope="scope">
<el-tag v-if="scope.row.itemType === 'single'" type="primary" size="small">单选</el-tag>
<el-tag v-else-if="scope.row.itemType === 'multiple'" type="success" size="small">多选</el-tag>
<el-tag v-if="scope.row.itemType === 'single' || scope.row.itemType === 'radio'" type="primary" size="small">单选</el-tag>
<el-tag v-else-if="scope.row.itemType === 'multiple' || scope.row.itemType === 'checkbox'" type="success" size="small">多选</el-tag>
<el-tag v-else-if="scope.row.itemType === 'matrix'" type="warning" size="small">矩阵</el-tag>
<el-tag v-else-if="scope.row.itemType === 'text'" type="info" size="small">简答题</el-tag>
<el-tag v-else-if="scope.row.itemType === 'textarea'" type="warning" size="small">问答题</el-tag>
<el-tag v-else-if="scope.row.itemType === 'essay'" type="danger" size="small">作文题</el-tag>
<el-tag v-else-if="scope.row.itemType === 'input'" type="" size="small">填空题</el-tag>
<span v-else>{{ scope.row.itemType }}</span>
</template>
</el-table-column>
@ -180,7 +192,9 @@
<script>
import { getReport, getReportByAssessmentId, updateReportWithType } from "@/api/psychology/report";
import { getQuestionnaireRankList } from "@/api/psychology/questionnaireAnswer";
import { getQuestionnaireRankList, getQuestionnaireAnswer, getAnswerDetails } from "@/api/psychology/questionnaireAnswer";
import { getQuestionnaireItems } from "@/api/psychology/questionnaireAnswer";
import { listQuestionnaireOption } from "@/api/psychology/questionnaireOption";
import { getAssessmentAnswers, getAssessmentItems, getAssessment } from "@/api/psychology/assessment";
import { listOption } from "@/api/psychology/option";
import request from '@/utils/request';
@ -216,7 +230,8 @@ export default {
answerDetailOpen: false,
answerDetailLoading: false,
answerDetailList: [],
assessmentInfo: {}
assessmentInfo: {},
questionnaireInfo: {}
};
},
created() {
@ -502,11 +517,26 @@ export default {
},
/** 查看答题详情 */
handleViewAnswers() {
if (!this.reportForm.assessmentId) {
this.$modal.msgWarning("无法获取测评ID");
//
if (this.sourceType === 'assessment') {
if (!this.reportForm.assessmentId) {
this.$modal.msgWarning("无法获取测评ID");
return;
}
this.loadAssessmentAnswers();
} else if (this.sourceType === 'questionnaire') {
if (!this.reportForm.answerId) {
this.$modal.msgWarning("无法获取答题ID");
return;
}
this.loadQuestionnaireAnswers();
} else {
this.$modal.msgWarning("未知的报告类型");
return;
}
},
/** 加载量表答题详情 */
loadAssessmentAnswers() {
this.answerDetailOpen = true;
this.answerDetailLoading = true;
this.answerDetailList = [];
@ -603,6 +633,126 @@ export default {
this.$modal.msgError("获取答题详情失败");
this.answerDetailLoading = false;
});
},
/** 加载问卷答题详情 */
loadQuestionnaireAnswers() {
this.answerDetailOpen = true;
this.answerDetailLoading = true;
this.answerDetailList = [];
//
Promise.all([
getQuestionnaireAnswer(this.reportForm.answerId),
getAnswerDetails(this.reportForm.answerId)
]).then(([answerRes, detailsRes]) => {
const answer = answerRes.data || {};
const details = detailsRes.data || [];
this.questionnaireInfo = answer;
if (!answer.questionnaireId) {
this.$modal.msgError("无法获取问卷ID");
this.answerDetailLoading = false;
return;
}
//
getQuestionnaireItems(answer.questionnaireId).then(itemsRes => {
const items = itemsRes.data || [];
// itemIdkey
const itemMap = {};
items.forEach(item => {
itemMap[item.itemId] = item;
});
// itemIdkey
const detailMap = {};
details.forEach(detail => {
detailMap[detail.itemId] = detail;
});
//
const optionPromises = items.map(item => {
return listQuestionnaireOption(item.itemId).then(optionRes => {
return {
itemId: item.itemId,
options: optionRes.data || []
};
}).catch(() => {
return {
itemId: item.itemId,
options: []
};
});
});
Promise.all(optionPromises).then(optionResults => {
//
const optionMap = {};
optionResults.forEach(result => {
optionMap[result.itemId] = result.options;
});
//
this.answerDetailList = items.map(item => {
const detail = detailMap[item.itemId] || {};
const options = optionMap[item.itemId] || [];
//
let answerDisplay = '-';
if (detail.optionId) {
//
const option = options.find(opt => opt.optionId === detail.optionId);
if (option) {
answerDisplay = `${option.optionCode}. ${option.optionContent}`;
} else {
answerDisplay = `选项ID: ${detail.optionId}`;
}
} else if (detail.optionIds) {
//
const optionIdArray = detail.optionIds.split(',').map(id => id.trim());
const selectedOptions = options.filter(opt => optionIdArray.includes(String(opt.optionId)));
if (selectedOptions.length > 0) {
answerDisplay = selectedOptions.map(opt => `${opt.optionCode}. ${opt.optionContent}`).join('; ');
} else {
answerDisplay = `选项IDs: ${detail.optionIds}`;
}
} else if (detail.answerText) {
//
answerDisplay = detail.answerText;
}
return {
itemId: item.itemId,
itemNumber: item.itemNumber,
itemContent: item.itemContent,
itemType: item.itemType,
answerDisplay: answerDisplay,
answerScore: detail.answerScore,
detailId: detail.detailId,
optionId: detail.optionId,
optionIds: detail.optionIds,
answerText: detail.answerText
};
});
this.answerDetailLoading = false;
}).catch(error => {
console.error('获取选项信息失败:', error);
this.$modal.msgError("获取选项信息失败");
this.answerDetailLoading = false;
});
}).catch(error => {
console.error('获取题目列表失败:', error);
this.$modal.msgError("获取题目列表失败");
this.answerDetailLoading = false;
});
}).catch(error => {
console.error('获取答题详情失败:', error);
this.$modal.msgError("获取答题详情失败");
this.answerDetailLoading = false;
});
}
}
};