| | |
| | | <!-- src/views/case/assessment/components/OrganAssessmentForm.vue --> |
| | | <template> |
| | | <div class="organ-assessment-form"> |
| | | <el-form :model="organData" label-width="120px"> |
| | | <el-form :model="formData" label-width="120px"> |
| | | <el-form-item label="功能状态"> |
| | | <el-select v-model="organData.functionStatus" :disabled="readonly"> |
| | | <el-select v-model="formData.functionStatus"> |
| | | <el-option label="正常" value="1" /> |
| | | <el-option label="轻度异常" value="2" /> |
| | | <el-option label="重度异常" value="3" /> |
| | | <el-option label="无法评估" value="4" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="评估意见"> |
| | | <el-input |
| | | type="textarea" |
| | | v-model="organData.assessmentOpinion" |
| | | v-model="formData.assessmentOpinion" |
| | | :rows="4" |
| | | :disabled="readonly" |
| | | placeholder="请输入评估意见" |
| | | /> |
| | | </el-form-item> |
| | | |
| | | <!-- 附件上传区域 --> |
| | | <el-form-item label="相关附件"> |
| | | <div class="attachment-section"> |
| | | <div class="attachment-header"> |
| | | <i class="el-icon-paperclip"></i> |
| | | <span class="attachment-title">附件上传</span> |
| | | <span class="attachment-tip" |
| | | >支持上传检验报告单等文件 (最多{{ attachmentLimit }}个)</span |
| | | > |
| | | </div> |
| | | |
| | | <!-- 使用 UploadAttachment 组件 --> |
| | | <UploadAttachment |
| | | ref="uploadAttachment" |
| | | :file-list="attachmentFileList" |
| | | :limit="attachmentLimit" |
| | | :accept="attachmentAccept" |
| | | :multiple="true" |
| | | @change="handleAttachmentChange" |
| | | @upload-success="handleUploadSuccess" |
| | | @upload-error="handleUploadError" |
| | | @remove="handleAttachmentRemove" |
| | | /> |
| | | |
| | | <!-- 附件列表 --> |
| | | <div |
| | | class="attachment-list" |
| | | v-if="formData.attachments && formData.attachments.length > 0" |
| | | > |
| | | <div class="list-title"> |
| | | 已上传附件 ({{ formData.attachments.length }}) |
| | | </div> |
| | | <el-table |
| | | :data="formData.attachments" |
| | | style="width: 100%" |
| | | size="small" |
| | | > |
| | | <el-table-column label="文件名" min-width="200"> |
| | | <template slot-scope="scope"> |
| | | <i |
| | | class="el-icon-document" |
| | | :style="{ color: getFileIconColor(scope.row.fileName) }" |
| | | ></i> |
| | | <span class="file-name">{{ scope.row.fileName }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="文件类型" width="100"> |
| | | <template slot-scope="scope"> |
| | | <el-tag |
| | | :type="getFileTagType(scope.row.fileName)" |
| | | size="small" |
| | | > |
| | | {{ getFileTypeText(scope.row.fileName) }} |
| | | </el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="上传时间" width="160"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ formatDateTime(scope.row.uploadTime) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="文件大小" width="100"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ formatFileSize(scope.row.fileSize) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="操作" width="266" fixed="right"> |
| | | <template slot-scope="scope"> |
| | | <el-button |
| | | size="mini" |
| | | type="primary" |
| | | @click="handlePreview(scope.row)" |
| | | :disabled="!isPreviewable(scope.row.fileName)" |
| | | > |
| | | 预览 |
| | | </el-button> |
| | | <el-button |
| | | size="mini" |
| | | type="success" |
| | | @click="handleDownload(scope.row)" |
| | | > |
| | | 下载 |
| | | </el-button> |
| | | <el-button |
| | | v-if="!readonly" |
| | | size="mini" |
| | | type="danger" |
| | | @click="handleRemoveAttachment(scope.$index)" |
| | | > |
| | | 删除 |
| | | </el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | | |
| | | <el-form-item v-if="!readonly"> |
| | | <el-button type="primary" @click="handleSave">保存评估</el-button> |
| | | <el-button type="primary" @click="handleSave">评估完成</el-button> |
| | | <el-button @click="handleCancel">取消</el-button> |
| | | <el-button |
| | | type="danger" |
| | | size="small" |
| | | @click="handleDelete" |
| | | icon="el-icon-delete" |
| | | > |
| | | 删除此评估 |
| | | </el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <!-- 文件预览弹窗 --> |
| | | <FilePreviewDialog |
| | | :visible="previewVisible" |
| | | :file="currentPreviewFile" |
| | | @close="previewVisible = false" |
| | | @download="handleDownload" |
| | | /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import UploadAttachment from "@/components/UploadAttachment"; |
| | | import FilePreviewDialog from "@/components/FilePreviewDialog"; |
| | | import dayjs from "dayjs"; |
| | | |
| | | export default { |
| | | name: "OrganAssessmentForm", |
| | | components: { |
| | | UploadAttachment, |
| | | FilePreviewDialog |
| | | }, |
| | | props: { |
| | | organData: { |
| | | type: Object, |
| | | default: () => ({}) |
| | | }, |
| | | assessmentIndex: { |
| | | type: Number, |
| | | default: 0 |
| | | }, |
| | | readonly: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | // 添加用户信息props |
| | | currentUser: { |
| | | type: Object, |
| | | default: () => ({ |
| | | name: "评估员" |
| | | }) |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | // 表单数据 |
| | | formData: { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | attachments: [] |
| | | }, |
| | | // 预览相关 |
| | | previewVisible: false, |
| | | currentPreviewFile: null, |
| | | // 附件相关配置 |
| | | attachmentLimit: 10, |
| | | attachmentAccept: |
| | | ".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt", |
| | | attachmentFileList: [], |
| | | // 原始评估数据 |
| | | currentAssessment: null |
| | | }; |
| | | }, |
| | | watch: { |
| | | organData: { |
| | | handler() { |
| | | this.initData(); |
| | | }, |
| | | deep: true, |
| | | immediate: true |
| | | }, |
| | | // 深度监听表单数据变化 |
| | | formData: { |
| | | handler(newVal) { |
| | | this.$emit("update-assessment", { |
| | | organData: this.organData, |
| | | assessmentData: newVal, |
| | | assessmentIndex: this.assessmentIndex |
| | | }); |
| | | }, |
| | | deep: true |
| | | } |
| | | }, |
| | | created() { |
| | | this.initData(); |
| | | }, |
| | | methods: { |
| | | // 初始化数据 |
| | | initData() { |
| | | if (!this.organData || !this.organData.assesscontent) { |
| | | this.formData = { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | attachments: [] |
| | | }; |
| | | this.attachmentFileList = []; |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | const assessData = |
| | | typeof this.organData.assesscontent === "string" |
| | | ? JSON.parse(this.organData.assesscontent) |
| | | : this.organData.assesscontent; |
| | | |
| | | if ( |
| | | Array.isArray(assessData) && |
| | | assessData.length > this.assessmentIndex |
| | | ) { |
| | | this.currentAssessment = assessData[this.assessmentIndex]; |
| | | |
| | | // 深拷贝数据,避免修改原始数据 |
| | | const assessmentCopy = JSON.parse( |
| | | JSON.stringify(this.currentAssessment) |
| | | ); |
| | | |
| | | this.formData = { |
| | | functionStatus: assessmentCopy.functionStatus || "", |
| | | assessmentOpinion: assessmentCopy.assessmentOpinion || "", |
| | | attachments: Array.isArray(assessmentCopy.attachments) |
| | | ? [...assessmentCopy.attachments] |
| | | : [] |
| | | }; |
| | | |
| | | // 初始化附件文件列表 |
| | | this.attachmentFileList = this.formData.attachments.map(item => ({ |
| | | uid: item.id || Math.random(), |
| | | name: item.fileName, |
| | | fileSize: item.fileSize, |
| | | url: item.path || item.fileUrl, |
| | | uploadTime: item.uploadTime, |
| | | status: "success" |
| | | })); |
| | | } else { |
| | | console.log("评估索引超出范围或数据为空"); |
| | | this.resetForm(); |
| | | } |
| | | } catch (error) { |
| | | console.error("初始化数据失败:", error); |
| | | this.resetForm(); |
| | | } |
| | | }, |
| | | |
| | | // 重置表单 |
| | | resetForm() { |
| | | this.formData = { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | attachments: [] |
| | | }; |
| | | this.attachmentFileList = []; |
| | | }, |
| | | |
| | | // 保存评估 |
| | | handleSave() { |
| | | this.$emit('save', { |
| | | ...this.organData, |
| | | assessmentTime: new Date().toISOString(), |
| | | assessor: '当前用户' |
| | | // 验证必要字段 |
| | | if (!this.formData.functionStatus) { |
| | | this.$message.warning("请选择功能状态"); |
| | | return; |
| | | } |
| | | |
| | | if (!this.formData.assessmentOpinion) { |
| | | this.$message.warning("请输入评估意见"); |
| | | return; |
| | | } |
| | | |
| | | // 准备保存的数据 |
| | | const saveData = { |
| | | functionStatus: this.formData.functionStatus, |
| | | assessmentOpinion: this.formData.assessmentOpinion, |
| | | attachments: Array.isArray(this.formData.attachments) |
| | | ? [...this.formData.attachments] |
| | | : [] |
| | | }; |
| | | |
| | | // 添加评估者和评估时间 |
| | | const assessmentData = { |
| | | ...saveData, |
| | | assessor: this.currentUser.name, |
| | | assessmentTime: new Date().toISOString() |
| | | }; |
| | | |
| | | console.log("发送保存请求:", assessmentData); |
| | | |
| | | this.$emit("save-assessment", { |
| | | organData: this.organData, |
| | | assessmentData: assessmentData, |
| | | assessmentIndex: this.assessmentIndex |
| | | }); |
| | | }, |
| | | |
| | | handleCancel() { |
| | | this.$emit('cancel'); |
| | | this.$emit("cancel"); |
| | | }, |
| | | |
| | | handleDelete() { |
| | | this.$confirm("确认删除此评估记录吗?", "确认删除", { |
| | | confirmButtonText: "确定", |
| | | cancelButtonText: "取消", |
| | | type: "warning" |
| | | }) |
| | | .then(() => { |
| | | this.$emit("delete-assessment", { |
| | | organData: this.organData, |
| | | assessmentIndex: this.assessmentIndex |
| | | }); |
| | | }) |
| | | .catch(() => { |
| | | this.$message.info("已取消删除"); |
| | | }); |
| | | }, |
| | | |
| | | /** 附件变化处理 */ |
| | | handleAttachmentChange(fileList) { |
| | | this.attachmentFileList = fileList; |
| | | }, |
| | | |
| | | /** 附件移除处理 */ |
| | | handleAttachmentRemove(file) { |
| | | if (file.url) { |
| | | const index = this.formData.attachments.findIndex( |
| | | item => item.path === file.url || item.fileUrl === file.url |
| | | ); |
| | | if (index > -1) { |
| | | this.formData.attachments.splice(index, 1); |
| | | this.$message.success("附件删除成功"); |
| | | } |
| | | } |
| | | }, |
| | | |
| | | /** 手动删除附件 */ |
| | | handleRemoveAttachment(index) { |
| | | this.formData.attachments.splice(index, 1); |
| | | this.attachmentFileList.splice(index, 1); |
| | | this.$message.success("附件删除成功"); |
| | | }, |
| | | |
| | | /** 上传成功处理 */ |
| | | handleUploadSuccess({ file, fileList, response }) { |
| | | if (response.code === 200) { |
| | | console.log(response, "上传数据"); |
| | | |
| | | const attachmentObj = { |
| | | fileName: file.name, |
| | | path: response.fileUrl || file.url, |
| | | fileUrl: response.fileUrl || file.url, |
| | | fileType: this.getFileExtension(file.name), |
| | | fileSize: file.size, |
| | | uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss") |
| | | }; |
| | | |
| | | console.log("添加上传的附件:", attachmentObj); |
| | | |
| | | // 确保 attachments 是数组 |
| | | if (!Array.isArray(this.formData.attachments)) { |
| | | this.formData.attachments = []; |
| | | } |
| | | |
| | | this.formData.attachments.push(attachmentObj); |
| | | |
| | | // 更新文件列表 |
| | | this.attachmentFileList = fileList; |
| | | |
| | | this.$message.success("文件上传成功"); |
| | | } |
| | | }, |
| | | |
| | | /** 上传错误处理 */ |
| | | handleUploadError({ file, fileList, error }) { |
| | | console.error("附件上传失败:", error); |
| | | this.$message.error("文件上传失败,请重试"); |
| | | }, |
| | | |
| | | /** 文件预览 */ |
| | | handlePreview(file) { |
| | | this.currentPreviewFile = { |
| | | fileName: file.fileName, |
| | | fileUrl: file.path || file.fileUrl, |
| | | fileType: this.getFileType(file.fileName) |
| | | }; |
| | | this.previewVisible = true; |
| | | }, |
| | | |
| | | /** 文件下载 */ |
| | | handleDownload(file) { |
| | | const fileUrl = file.path || file.fileUrl; |
| | | const fileName = file.fileName; |
| | | |
| | | if (fileUrl) { |
| | | const link = document.createElement("a"); |
| | | link.href = fileUrl; |
| | | link.download = fileName; |
| | | link.style.display = "none"; |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | this.$message.success("开始下载文件"); |
| | | } else { |
| | | this.$message.warning("文件路径不存在,无法下载"); |
| | | } |
| | | }, |
| | | |
| | | /** 获取文件类型 */ |
| | | getFileType(fileName) { |
| | | if (!fileName) return "other"; |
| | | |
| | | const extension = fileName |
| | | .split(".") |
| | | .pop() |
| | | .toLowerCase(); |
| | | const imageTypes = ["jpg", "jpeg", "png", "gif", "bmp", "webp"]; |
| | | const pdfTypes = ["pdf"]; |
| | | const officeTypes = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"]; |
| | | |
| | | if (imageTypes.includes(extension)) return "image"; |
| | | if (pdfTypes.includes(extension)) return "pdf"; |
| | | if (officeTypes.includes(extension)) return "office"; |
| | | return "other"; |
| | | }, |
| | | |
| | | /** 获取文件图标颜色 */ |
| | | getFileIconColor(fileName) { |
| | | const type = this.getFileType(fileName); |
| | | const colorMap = { |
| | | image: "#67C23A", |
| | | pdf: "#F56C6C", |
| | | office: "#409EFF", |
| | | other: "#909399" |
| | | }; |
| | | return colorMap[type] || "#909399"; |
| | | }, |
| | | |
| | | /** 获取文件标签类型 */ |
| | | getFileTagType(fileName) { |
| | | const type = this.getFileType(fileName); |
| | | const typeMap = { |
| | | image: "success", |
| | | pdf: "danger", |
| | | office: "primary", |
| | | other: "info" |
| | | }; |
| | | return typeMap[type] || "info"; |
| | | }, |
| | | |
| | | /** 获取文件类型文本 */ |
| | | getFileTypeText(fileName) { |
| | | const type = this.getFileType(fileName); |
| | | const textMap = { |
| | | image: "图片", |
| | | pdf: "PDF", |
| | | office: "文档", |
| | | other: "其他" |
| | | }; |
| | | return textMap[type] || "未知"; |
| | | }, |
| | | |
| | | /** 检查是否可预览 */ |
| | | isPreviewable(fileName) { |
| | | const type = this.getFileType(fileName); |
| | | return ["image", "pdf"].includes(type); |
| | | }, |
| | | |
| | | /** 获取文件扩展名 */ |
| | | getFileExtension(filename) { |
| | | return filename |
| | | .split(".") |
| | | .pop() |
| | | .toLowerCase(); |
| | | }, |
| | | |
| | | /** 格式化文件大小 */ |
| | | formatFileSize(bytes) { |
| | | if (!bytes || bytes === 0) return "0 B"; |
| | | const k = 1024; |
| | | const sizes = ["B", "KB", "MB", "GB"]; |
| | | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| | | return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; |
| | | }, |
| | | |
| | | /** 日期时间格式化 */ |
| | | formatDateTime(dateTime) { |
| | | if (!dateTime) return ""; |
| | | |
| | | try { |
| | | const date = new Date(dateTime); |
| | | if (isNaN(date.getTime())) return dateTime; |
| | | |
| | | const year = date.getFullYear(); |
| | | const month = String(date.getMonth() + 1).padStart(2, "0"); |
| | | const day = String(date.getDate()).padStart(2, "0"); |
| | | const hours = String(date.getHours()).padStart(2, "0"); |
| | | const minutes = String(date.getMinutes()).padStart(2, "0"); |
| | | |
| | | return `${year}-${month}-${day} ${hours}:${minutes}`; |
| | | } catch (error) { |
| | | return dateTime; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .organ-assessment-form { |
| | | padding: 20px; |
| | | } |
| | | |
| | | .attachment-section { |
| | | border: 1px solid #ebeef5; |
| | | border-radius: 4px; |
| | | padding: 15px; |
| | | background: #fafafa; |
| | | } |
| | | |
| | | .attachment-header { |
| | | display: flex; |
| | | align-items: center; |
| | | margin-bottom: 16px; |
| | | padding-bottom: 8px; |
| | | border-bottom: 1px solid #ebeef5; |
| | | } |
| | | |
| | | .attachment-title { |
| | | font-weight: bold; |
| | | margin: 0 8px; |
| | | color: #303133; |
| | | } |
| | | |
| | | .attachment-tip { |
| | | font-size: 12px; |
| | | color: #909399; |
| | | margin-left: auto; |
| | | } |
| | | |
| | | .attachment-list { |
| | | margin-top: 16px; |
| | | } |
| | | |
| | | .list-title { |
| | | font-weight: bold; |
| | | margin-bottom: 12px; |
| | | color: #303133; |
| | | font-size: 14px; |
| | | } |
| | | |
| | | .file-name { |
| | | font-size: 13px; |
| | | margin-left: 8px; |
| | | } |
| | | |
| | | ::v-deep .el-upload__tip { |
| | | font-size: 12px; |
| | | color: #909399; |
| | | margin-top: 8px; |
| | | } |
| | | |
| | | ::v-deep .el-table .cell { |
| | | padding: 8px 12px; |
| | | } |
| | | |
| | | ::v-deep .el-button--mini { |
| | | padding: 5px 10px; |
| | | font-size: 12px; |
| | | } |
| | | </style> |