| | |
| | | <template> |
| | | <div class="organ-assessment-form"> |
| | | <el-form :model="formData" label-width="120px"> |
| | | <!-- 添加评估时间字段 --> |
| | | <el-form-item label="评估时间"> |
| | | <el-date-picker |
| | | v-model="formData.assessmentTime" |
| | | type="datetime" |
| | | placeholder="选择评估时间" |
| | | format="yyyy-MM-dd HH:mm:ss" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | :default-value="new Date()" |
| | | style="width: 100%" |
| | | /> |
| | | </el-form-item> |
| | | |
| | | <!-- 只读模式下显示评估时间 --> |
| | | <el-form-item label="功能状态"> |
| | | <el-select v-model="formData.functionStatus"> |
| | | <el-option label="正常" value="1" /> |
| | |
| | | </el-table-column> |
| | | <el-table-column label="上传时间" width="160"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ formatDateTime(scope.row.uploadTime) }}</span> |
| | | <span>{{ scope.row.uploadTime }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="文件大小" width="100"> |
| | |
| | | formData: { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | assessmentTime: "", // 新增评估时间字段 |
| | | attachments: [] |
| | | }, |
| | | // 预览相关 |
| | |
| | | }, |
| | | created() { |
| | | this.initData(); |
| | | // 如果评估时间为空,设置默认值 |
| | | if (!this.formData.assessmentTime) { |
| | | this.$set( |
| | | this.formData, |
| | | "assessmentTime", |
| | | this.getDefaultAssessmentTime() |
| | | ); |
| | | } |
| | | }, |
| | | methods: { |
| | | // 初始化数据 |
| | |
| | | this.formData = { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | assessmentTime: this.getDefaultAssessmentTime(), |
| | | attachments: [] |
| | | }; |
| | | this.attachmentFileList = []; |
| | |
| | | ) { |
| | | this.currentAssessment = assessData[this.assessmentIndex]; |
| | | |
| | | // 深拷贝数据,避免修改原始数据 |
| | | // 深拷贝数据 |
| | | const assessmentCopy = JSON.parse( |
| | | JSON.stringify(this.currentAssessment) |
| | | ); |
| | | |
| | | // 处理评估时间 |
| | | let assessmentTime = assessmentCopy.assessmentTime; |
| | | |
| | | // 如果时间不是有效的日期字符串,使用默认值 |
| | | if (!this.isValidDate(assessmentTime)) { |
| | | assessmentTime = this.getDefaultAssessmentTime(); |
| | | } else { |
| | | // 确保时间格式正确 |
| | | assessmentTime = this.formatDateForPicker(assessmentTime); |
| | | } |
| | | |
| | | this.formData = { |
| | | functionStatus: assessmentCopy.functionStatus || "", |
| | | assessmentOpinion: assessmentCopy.assessmentOpinion || "", |
| | | assessmentTime: assessmentTime, // 处理后的时间 |
| | | attachments: Array.isArray(assessmentCopy.attachments) |
| | | ? [...assessmentCopy.attachments] |
| | | : [] |
| | |
| | | this.resetForm(); |
| | | } |
| | | }, |
| | | // 验证日期是否有效 |
| | | isValidDate(dateString) { |
| | | if (!dateString) return false; |
| | | |
| | | try { |
| | | const date = new Date(dateString); |
| | | return !isNaN(date.getTime()) && dateString.trim() !== ""; |
| | | } catch (error) { |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | // 为日期选择器格式化日期 |
| | | formatDateForPicker(dateString) { |
| | | if (!dateString) return ""; |
| | | |
| | | try { |
| | | const date = new Date(dateString); |
| | | if (isNaN(date.getTime())) { |
| | | return this.getDefaultAssessmentTime(); |
| | | } |
| | | |
| | | // 格式化为 yyyy-MM-dd HH:mm:ss |
| | | 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"); |
| | | const seconds = String(date.getSeconds()).padStart(2, "0"); |
| | | |
| | | return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | } catch (error) { |
| | | console.error("日期格式化错误:", error); |
| | | return this.getDefaultAssessmentTime(); |
| | | } |
| | | }, |
| | | // 重置表单 |
| | | resetForm() { |
| | | this.formData = { |
| | | functionStatus: "", |
| | | assessmentOpinion: "", |
| | | assessmentTime: this.getDefaultAssessmentTime(), // 设置默认时间 |
| | | attachments: [] |
| | | }; |
| | | this.attachmentFileList = []; |
| | | }, |
| | | // 获取默认评估时间 |
| | | getDefaultAssessmentTime() { |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); |
| | | const month = String(now.getMonth() + 1).padStart(2, "0"); |
| | | const day = String(now.getDate()).padStart(2, "0"); |
| | | const hours = String(now.getHours()).padStart(2, "0"); |
| | | const minutes = String(now.getMinutes()).padStart(2, "0"); |
| | | const seconds = String(now.getSeconds()).padStart(2, "0"); |
| | | |
| | | return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | }, |
| | | // 保存评估 |
| | | handleSave() { |
| | | // 验证必要字段 |
| | |
| | | return; |
| | | } |
| | | |
| | | if (!this.formData.assessmentTime) { |
| | | this.$message.warning("请选择评估时间"); |
| | | return; |
| | | } |
| | | |
| | | // 验证时间格式 |
| | | if (!this.isValidDate(this.formData.assessmentTime)) { |
| | | this.$message.warning("评估时间格式不正确,请重新选择"); |
| | | return; |
| | | } |
| | | |
| | | // 准备保存的数据 |
| | | const saveData = { |
| | | functionStatus: this.formData.functionStatus, |
| | | assessmentOpinion: this.formData.assessmentOpinion, |
| | | assessmentTime: this.formData.assessmentTime, |
| | | attachments: Array.isArray(this.formData.attachments) |
| | | ? [...this.formData.attachments] |
| | | : [] |
| | | }; |
| | | |
| | | // 添加评估者和评估时间 |
| | | // 添加评估者 |
| | | const assessmentData = { |
| | | ...saveData, |
| | | assessor: this.currentUser.name, |
| | | assessmentTime: new Date().toISOString() |
| | | assessor: this.currentUser.name |
| | | }; |
| | | |
| | | console.log("发送保存请求:", assessmentData); |
| | |
| | | assessmentIndex: this.assessmentIndex |
| | | }); |
| | | }, |
| | | |
| | | handleCancel() { |
| | | this.$emit("cancel"); |
| | | }, |
| | |
| | | |
| | | /** 上传成功处理 */ |
| | | handleUploadSuccess({ file, fileList, response }) { |
| | | console.log(response,'response'); |
| | | console.log(response, "response"); |
| | | |
| | | if (response.code === 200) { |
| | | console.log(response, "上传数据"); |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | }; |
| | |
| | | font-size: 13px; |
| | | margin-left: 8px; |
| | | } |
| | | |
| | | .readonly-time { |
| | | font-size: 14px; |
| | | color: #606266; |
| | | font-weight: 500; |
| | | padding: 8px 15px; |
| | | background: #f5f7fa; |
| | | border-radius: 4px; |
| | | display: inline-block; |
| | | min-width: 200px; |
| | | } |
| | | ::v-deep .el-upload__tip { |
| | | font-size: 12px; |
| | | color: #909399; |