| | |
| | | <template> |
| | | <div class="organ-assessment-form"> |
| | | <el-form :model="assessmentData" label-width="120px"> |
| | | <el-form :model="formData" label-width="120px"> |
| | | <el-form-item label="功能状态"> |
| | | <el-select v-model="assessmentData.functionStatus"> |
| | | <el-select v-model="formData.functionStatus"> |
| | | <el-option label="正常" value="1" /> |
| | | <el-option label="轻度异常" value="2" /> |
| | | <el-option label="重度异常" value="3" /> |
| | |
| | | <el-form-item label="评估意见"> |
| | | <el-input |
| | | type="textarea" |
| | | v-model="assessmentData.assessmentOpinion" |
| | | v-model="formData.assessmentOpinion" |
| | | :rows="4" |
| | | placeholder="请输入评估意见" |
| | | /> |
| | |
| | | <!-- 附件列表 --> |
| | | <div |
| | | class="attachment-list" |
| | | v-if=" |
| | | assessmentData.attachments && |
| | | assessmentData.attachments.length > 0 |
| | | " |
| | | v-if="formData.attachments && formData.attachments.length > 0" |
| | | > |
| | | <div class="list-title"> |
| | | 已上传附件 ({{ assessmentData.attachments.length }}) |
| | | 已上传附件 ({{ formData.attachments.length }}) |
| | | </div> |
| | | <el-table |
| | | :data="assessmentData.attachments" |
| | | :data="formData.attachments" |
| | | style="width: 100%" |
| | | size="small" |
| | | > |
| | |
| | | </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="success" |
| | | @click="handleAddAssessment" |
| | | icon="el-icon-plus" |
| | | type="danger" |
| | | size="small" |
| | | @click="handleDelete" |
| | | icon="el-icon-delete" |
| | | > |
| | | 新增评估记录 |
| | | 删除此评估 |
| | | </el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | |
| | | type: Object, |
| | | default: () => ({}) |
| | | }, |
| | | assessmentData: { |
| | | type: Object, |
| | | default: () => ({ |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | attachments: [] |
| | | }) |
| | | }, |
| | | 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: [] |
| | | attachmentFileList: [], |
| | | // 原始评估数据 |
| | | currentAssessment: null |
| | | }; |
| | | }, |
| | | watch: { |
| | | organData: { |
| | | handler(newVal, oldVal) { |
| | | // 只有当附件数据真正发生变化时才初始化 |
| | | if ( |
| | | !oldVal || |
| | | !oldVal.attachments || |
| | | JSON.stringify(newVal.attachments) !== |
| | | JSON.stringify(oldVal.attachments) |
| | | ) { |
| | | this.initAttachmentList(); |
| | | } |
| | | handler() { |
| | | this.initData(); |
| | | }, |
| | | immediate: true, |
| | | 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: { |
| | | /** 初始化附件列表 */ |
| | | initAttachmentList() { |
| | | if (this.organData.attachments && this.organData.attachments.length > 0) { |
| | | this.assessmentData.attachments = [...this.organData.attachments]; |
| | | this.attachmentFileList = this.organData.attachments.map(item => ({ |
| | | uid: item.id || Math.random(), |
| | | name: item.fileName, |
| | | url: item.path || item.fileUrl, |
| | | status: "success" |
| | | })); |
| | | } else { |
| | | this.assessmentData.attachments = []; |
| | | // 初始化数据 |
| | | 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(); |
| | | } |
| | | }, |
| | | handleSave() { |
| | | const saveData = { |
| | | organData: this.organData, |
| | | assessmentData: this.assessmentData, |
| | | assessmentIndex: this.assessmentIndex |
| | | |
| | | // 重置表单 |
| | | resetForm() { |
| | | this.formData = { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | attachments: [] |
| | | }; |
| | | this.$emit("save", saveData); |
| | | this.attachmentFileList = []; |
| | | }, |
| | | |
| | | // 保存评估 |
| | | handleSave() { |
| | | // 验证必要字段 |
| | | 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"); |
| | | }, |
| | | |
| | | handleAddAssessment() { |
| | | this.$emit("add-assessment", { |
| | | organData: this.organData, |
| | | currentIndex: this.assessmentIndex |
| | | }); |
| | | 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.assessmentData.attachments.findIndex( |
| | | const index = this.formData.attachments.findIndex( |
| | | item => item.path === file.url || item.fileUrl === file.url |
| | | ); |
| | | if (index > -1) { |
| | | this.assessmentData.attachments.splice(index, 1); |
| | | this.formData.attachments.splice(index, 1); |
| | | this.$message.success("附件删除成功"); |
| | | } |
| | | } |
| | | }, |
| | | |
| | | /** 手动删除附件 */ |
| | | handleRemoveAttachment(index) { |
| | | this.assessmentData.attachments.splice(index, 1); |
| | | this.formData.attachments.splice(index, 1); |
| | | this.attachmentFileList.splice(index, 1); |
| | | this.$message.success("附件删除成功"); |
| | | }, |
| | | |
| | | /** 上传成功处理 */ |
| | | handleUploadSuccess({ file, fileList, response }) { |
| | | console.log(response); |
| | | |
| | | if (response.code == 200) { |
| | | console.log(1); |
| | | if (response.code === 200) { |
| | | console.log(response, "上传数据"); |
| | | |
| | | const attachmentObj = { |
| | | // id: |
| | | // response.data.fileId || |
| | | // Math.random() |
| | | // .toString(36) |
| | | // .substr(2), |
| | | fileName: file.name, |
| | | path: response.data.fileUrl || file.url, |
| | | fileUrl: response.data.fileUrl || file.url, |
| | | 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"), |
| | | assessmentType: this.assessmentType, |
| | | organType: this.organData.organType |
| | | uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss") |
| | | }; |
| | | console.log(2,attachmentObj); |
| | | |
| | | this.assessmentData.attachments.push(attachmentObj); |
| | | console.log("添加上传的附件:", attachmentObj); |
| | | |
| | | // 确保 attachments 是数组 |
| | | if (!Array.isArray(this.formData.attachments)) { |
| | | this.formData.attachments = []; |
| | | } |
| | | |
| | | this.formData.attachments.push(attachmentObj); |
| | | |
| | | // 更新文件列表 |
| | | this.attachmentFileList = fileList; |
| | | |
| | | this.$message.success("文件上传成功"); |
| | | } |
| | | }, |