From 45680b99ccdfb0d323088c57c237e0bc714a8e0b Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期五, 13 三月 2026 09:21:32 +0800
Subject: [PATCH] 青岛opo维护

---
 src/views/business/maintain/components/UrineRoutinePanel.vue |  324 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 303 insertions(+), 21 deletions(-)

diff --git a/src/views/business/maintain/components/UrineRoutinePanel.vue b/src/views/business/maintain/components/UrineRoutinePanel.vue
index 541158f..e482237 100644
--- a/src/views/business/maintain/components/UrineRoutinePanel.vue
+++ b/src/views/business/maintain/components/UrineRoutinePanel.vue
@@ -144,12 +144,80 @@
           >鏀寔涓婁紶灏垮父瑙勬楠屾姤鍛婂崟绛夋枃浠� (鏈�澶�10涓�)</span
         >
       </div>
-      <upload-attachment
-        :file-list="attachments"
+
+      <!-- 浣跨敤 UploadAttachment 缁勪欢 -->
+      <UploadAttachment
+        ref="uploadAttachment"
+        :file-list="attachmentFileList"
+        :limit="attachmentLimit"
+        :accept="attachmentAccept"
+        :multiple="true"
         @change="handleAttachmentChange"
-        :limit="10"
-        :accept="'.pdf,.jpg,.jpeg,.png,.doc,.docx'"
+        @upload-success="handleUploadSuccess"
+        @upload-error="handleUploadError"
+        @remove="handleAttachmentRemove"
       />
+
+      <!-- 闄勪欢鍒楄〃灞曠ず -->
+      <div class="attachment-list" v-if="attachments && attachments.length > 0">
+        <div class="list-title">宸蹭笂浼犻檮浠� ({{ attachments.length }})</div>
+        <el-table :data="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
+                v-if="isEditing"
+                size="mini"
+                type="success"
+                @click="handleDownload(scope.row)"
+              >
+                涓嬭浇
+              </el-button>
+              <el-button
+                v-if="isEditing"
+                size="mini"
+                type="danger"
+                @click="handleRemoveAttachment(scope.$index)"
+              >
+                鍒犻櫎
+              </el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+      </div>
     </div>
 
     <!-- 鍒楃紪杈戝璇濇 -->
@@ -212,23 +280,33 @@
         </el-button>
       </span>
     </el-dialog>
+
+    <!-- 鏂囦欢棰勮寮圭獥 -->
+    <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: "UrineRoutinePanel",
   components: {
-    UploadAttachment
+    UploadAttachment,
+    FilePreviewDialog
   },
   props: {
     isEditing: {
       type: Boolean,
       default: false
     },
-    // 淇敼涓� Object 绫诲瀷锛屾敮鎸佸鏉傛暟鎹粨鏋�
     initialData: {
       type: Object,
       default: () => ({})
@@ -253,12 +331,21 @@
       tableKey: 0,
       tableLoading: false,
       saveLoading: false,
-      // 鍐呴儴鏁版嵁鐘舵��
       internalData: {},
       columnRules: {
         date: [{ required: true, message: "璇烽�夋嫨鏃ユ湡", trigger: "change" }],
         time: [{ required: true, message: "璇烽�夋嫨鏃堕棿", trigger: "change" }]
-      }
+      },
+
+      // 棰勮鐩稿叧
+      previewVisible: false,
+      currentPreviewFile: null,
+
+      // 闄勪欢鐩稿叧閰嶇疆
+      attachmentLimit: 10,
+      attachmentAccept:
+        ".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt",
+      attachmentFileList: []
     };
   },
   computed: {
@@ -279,11 +366,9 @@
     }
   },
   watch: {
-    // 鐩戝惉 initialData 鍙樺寲锛岀‘淇濇暟鎹纭帴鏀�
     initialData: {
       handler(newData) {
         console.log(newData);
-
         if (newData && Object.keys(newData).length > 0) {
           this.internalData = { ...newData };
           this.initFromExternalData();
@@ -308,12 +393,26 @@
       },
       deep: true,
       immediate: true
+    },
+    // 鐩戝惉闄勪欢鏁版嵁鍙樺寲
+    attachments: {
+      handler(newAttachments) {
+        this.attachmentFileList = newAttachments.map(item => ({
+          uid: item.id || Math.random(),
+          name: item.fileName,
+          fileSize: item.fileSize,
+          url: item.path || item.fileUrl,
+          uploadTime: item.uploadTime,
+          status: "success"
+        }));
+      },
+      deep: true
     }
   },
   methods: {
     // 浠庡閮ㄦ暟鎹垵濮嬪寲缁勪欢
     initFromExternalData() {
-      console.log(this.internalData,'this.internalData');
+      console.log(this.internalData, "this.internalData");
 
       if (this.internalData.data && this.internalData.columns) {
         this.tableData = this.internalData.data.map(item => ({
@@ -323,7 +422,6 @@
         }));
         this.dynamicColumns = [...this.internalData.columns];
       } else {
-        // 濡傛灉娌℃湁澶栭儴鏁版嵁锛屼娇鐢ㄧ粍浠堕粯璁ゅ垵濮嬪寲
         this.initTableData();
       }
 
@@ -337,7 +435,6 @@
     initTableData() {
       const medicalItems = this.getMedicalItems();
 
-      // 濡傛灉娌℃湁鍔ㄦ�佸垪锛屽垵濮嬪寲榛樿鍒�
       if (this.dynamicColumns.length === 0) {
         this.dynamicColumns = [
           {
@@ -501,7 +598,6 @@
         this.saveLoading = true;
 
         if (this.editingColumnIndex !== null) {
-          // 缂栬緫鐜版湁鍒�
           const column = this.dynamicColumns[this.editingColumnIndex];
           column.label = `${this.columnForm.date}\n${this.columnForm.time}`;
           column.date = this.columnForm.date;
@@ -509,7 +605,6 @@
           column.remark = this.columnForm.remark;
           this.$message.success("鏃堕棿鐐逛慨鏀规垚鍔�");
         } else {
-          // 鏂板鍒�
           const newColumn = {
             label: `${this.columnForm.date}\n${this.columnForm.time}`,
             key: `time${Date.now()}`,
@@ -530,6 +625,7 @@
         this.columnDialogVisible = false;
         this.saveLoading = false;
         this.tableKey += 1;
+        this.saveData();
       });
     },
 
@@ -546,6 +642,7 @@
           });
           this.columnDialogVisible = false;
           this.tableKey += 1;
+          this.saveData();
           this.$message.success("鏃堕棿鐐瑰垹闄ゆ垚鍔�");
         });
       }
@@ -569,12 +666,181 @@
       this.saveData();
     },
 
+    /** 闄勪欢鍙樺寲澶勭悊 */
     handleAttachmentChange(fileList) {
-      this.attachments = fileList;
-      this.$emit("attachment-change", {
-        type: "urine_routine",
-        attachments: fileList
-      });
+      this.attachmentFileList = fileList;
+    },
+
+    /** 闄勪欢绉婚櫎澶勭悊 */
+    handleAttachmentRemove(file) {
+      if (file.url) {
+        const index = this.attachments.findIndex(
+          item => item.path === file.url || item.fileUrl === file.url
+        );
+        if (index > -1) {
+          this.attachments.splice(index, 1);
+          this.saveData();
+          this.$message.success("闄勪欢鍒犻櫎鎴愬姛");
+        }
+      }
+    },
+
+    /** 涓婁紶鎴愬姛澶勭悊 */
+    handleUploadSuccess({ file, fileList, response }) {
+      if (response.code === 200) {
+        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")
+        };
+
+        if (!Array.isArray(this.attachments)) {
+          this.attachments = [];
+        }
+
+        this.attachments.push(attachmentObj);
+        this.attachmentFileList = fileList;
+        this.saveData();
+        this.$message.success("鏂囦欢涓婁紶鎴愬姛");
+      }
+    },
+
+    /** 涓婁紶閿欒澶勭悊 */
+    handleUploadError({ file, fileList, error }) {
+      console.error("闄勪欢涓婁紶澶辫触:", error);
+      this.$message.error("鏂囦欢涓婁紶澶辫触锛岃閲嶈瘯");
+    },
+
+    /** 鎵嬪姩鍒犻櫎闄勪欢 */
+    handleRemoveAttachment(index) {
+      this.attachments.splice(index, 1);
+      this.attachmentFileList.splice(index, 1);
+      this.saveData();
+      this.$message.success("闄勪欢鍒犻櫎鎴愬姛");
+    },
+
+    /** 鏂囦欢棰勮 */
+    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;
+      }
     },
 
     forceTableLayout() {
@@ -605,7 +871,6 @@
     }
   },
   mounted() {
-    // 纭繚缁勪欢姝g‘鎸傝浇鍚庡垵濮嬪寲鏁版嵁
     this.$nextTick(() => {
       if (Object.keys(this.internalData).length === 0) {
         this.initTableData();
@@ -744,6 +1009,7 @@
   font-size: 14px;
 }
 
+/* 闄勪欢涓婁紶鍖哄煙鏍峰紡浼樺寲 */
 .attachment-section {
   margin-top: 24px;
   padding: 20px;
@@ -769,6 +1035,22 @@
   color: #909399;
 }
 
+.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;
+}
+
 /* 鍝嶅簲寮忚璁� */
 @media (max-width: 768px) {
   .medical-panel {

--
Gitblit v1.9.3