From b973bcee308e99b5fd8a69640f11069e810346f4 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期二, 27 一月 2026 16:37:55 +0800
Subject: [PATCH] 采购台账重构

---
 src/pages/equipmentManagement/upkeep/fileList.vue |  562 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 562 insertions(+), 0 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/fileList.vue b/src/pages/equipmentManagement/upkeep/fileList.vue
new file mode 100644
index 0000000..b4d4b7f
--- /dev/null
+++ b/src/pages/equipmentManagement/upkeep/fileList.vue
@@ -0,0 +1,562 @@
+<template>
+  <view class="file-list-page">
+    <!-- 椤甸潰澶撮儴 -->
+    <PageHeader title="闄勪欢绠$悊"
+                @back="goBack" />
+    <!-- 闄勪欢鍒楄〃 -->
+    <view class="file-list-container">
+      <view v-if="fileList.length > 0"
+            class="file-list">
+        <view v-for="(file, index) in fileList"
+              :key="file.id || index"
+              class="file-item">
+          <!-- 鏂囦欢鍥炬爣 -->
+          <!-- <view class="file-icon"
+                :class="getFileIconClass(file.fileType)">
+            <up-icon :name="getFileIcon(file.fileType)"
+                     size="24"
+                     color="#ffffff" />
+          </view> -->
+          <!-- 鏂囦欢淇℃伅 -->
+          <view class="file-info">
+            <text class="file-name">{{ file.name }}</text>
+            <!-- <text class="file-meta">{{ formatFileSize(file.fileSize) }} 路 {{ file.uploadTime || file.createTime }}</text> -->
+          </view>
+          <!-- 鎿嶄綔鎸夐挳 -->
+          <view class="file-actions">
+            <!-- <u-button size="small"
+                      type="primary"
+                      plain
+                      @click="previewFile(file)">棰勮</u-button> -->
+            <u-button size="small"
+                      type="info"
+                      plain
+                      @click="downloadFile(file)">涓嬭浇骞堕瑙�</u-button>
+            <u-button size="small"
+                      type="error"
+                      plain
+                      @click="confirmDelete(file, index)">鍒犻櫎</u-button>
+          </view>
+        </view>
+      </view>
+      <!-- 绌虹姸鎬� -->
+      <view v-else
+            class="empty-state">
+        <up-icon name="document"
+                 size="64"
+                 color="#c0c4cc" />
+        <text class="empty-text">鏆傛棤闄勪欢</text>
+      </view>
+    </view>
+    <!-- <a rel="nofollow"
+       id="downloadLink"
+       href="#"
+       style="display:none;">涓嬭浇鏂囨湰鏂囦欢</a> -->
+    <!-- 涓婁紶鎸夐挳 -->
+    <view class="upload-button"
+          @click="chooseFile">
+      <up-icon name="plus"
+               size="24"
+               color="#ffffff" />
+      <text class="upload-text">涓婁紶闄勪欢</text>
+    </view>
+  </view>
+</template>
+
+<script setup>
+  import { ref, onMounted } from "vue";
+  import PageHeader from "@/components/PageHeader.vue";
+  import config from "@/config";
+  import { getToken } from "@/utils/auth";
+  // import { saveAs } from "file-saver";
+  import {
+    listMaintenanceTaskFiles,
+    addMaintenanceTaskFile,
+    delMaintenanceTaskFile,
+  } from "@/api/equipmentManagement/upkeep";
+  import { blobValidate } from "@/utils/ruoyi";
+
+  // 闄勪欢鍒楄〃
+  const fileList = ref([]);
+
+  // 杩斿洖涓婁竴椤�
+  const goBack = () => {
+    uni.navigateBack();
+  };
+  // const request = axios.create({
+  //   baseURL: "URL.com",
+  //   adapter: axiosAdapterUniapp,
+  // });
+  // 鑾峰彇鏂囦欢鍥炬爣
+  const getFileIcon = fileType => {
+    const iconMap = {
+      doc: "document",
+      docx: "document",
+      xls: "grid",
+      xlsx: "grid",
+      pdf: "document",
+      ppt: "copy",
+      pptx: "copy",
+      txt: "document",
+      jpg: "image",
+      jpeg: "image",
+      png: "image",
+      gif: "image",
+      zip: "folder",
+      rar: "folder",
+    };
+    return iconMap[fileType.toLowerCase()] || "document";
+  };
+
+  // 鑾峰彇鏂囦欢鍥炬爣鏍峰紡绫�
+  const getFileIconClass = fileType => {
+    const colorMap = {
+      doc: "blue",
+      docx: "blue",
+      xls: "green",
+      xlsx: "green",
+      pdf: "red",
+      ppt: "orange",
+      pptx: "orange",
+      txt: "gray",
+      jpg: "purple",
+      jpeg: "purple",
+      png: "purple",
+      gif: "purple",
+      zip: "yellow",
+      rar: "yellow",
+    };
+    return colorMap[fileType.toLowerCase()] || "gray";
+  };
+
+  // 鏍煎紡鍖栨枃浠跺ぇ灏�
+  const formatFileSize = bytes => {
+    if (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];
+  };
+
+  // 閫夋嫨鏂囦欢
+  const chooseFile = () => {
+    uni.chooseImage({
+      count: 9,
+      sizeType: ["original", "compressed"],
+      sourceType: ["album", "camera"],
+      success: res => {
+        console.log(res, "閫夋嫨鍥剧墖鎴愬姛");
+        uploadFiles(res.tempFiles);
+      },
+      fail: err => {
+        console.error("閫夋嫨鍥剧墖澶辫触:", err);
+        showToast("閫夋嫨鏂囦欢澶辫触");
+      },
+    });
+    // uni.chooseFile({
+    //   count: 9,
+    //   extension: [
+    //     ".doc",
+    //     ".docx",
+    //     ".xls",
+    //     ".xlsx",
+    //     ".pdf",
+    //     ".ppt",
+    //     ".pptx",
+    //     ".txt",
+    //     ".jpg",
+    //     ".jpeg",
+    //     ".png",
+    //     ".gif",
+    //     ".zip",
+    //     ".rar",
+    //   ],
+    //   success: res => {
+    //     console.log(res, "閫夋嫨鏂囦欢鎴愬姛");
+    //     uploadFiles(res.tempFiles);
+    //   },
+    //   fail: err => {
+    //     showToast("閫夋嫨鏂囦欢澶辫触");
+    //   },
+    // });
+  };
+
+  // 涓婁紶鏂囦欢
+  const uploadFiles = tempFiles => {
+    console.log(tempFiles, "涓婁紶鏂囦欢1");
+    tempFiles.forEach((tempFile, index) => {
+      // 鏄剧ず涓婁紶涓彁绀�
+      uni.showLoading({
+        title: "涓婁紶涓�...",
+        mask: true,
+      });
+      console.log(tempFile, "涓婁紶鏂囦欢2");
+      // 1. 鐩存帴浣跨敤 uni.uploadFile 涓婁紶鏂囦欢
+      uni.uploadFile({
+        url: config.baseUrl + "/file/upload",
+        filePath: tempFile.path,
+        name: "file",
+        header: {
+          Authorization: "Bearer " + getToken(),
+        },
+        success: uploadRes => {
+          uni.hideLoading();
+          console.log(uploadRes, "涓婁紶鏂囦欢3");
+
+          try {
+            const res = JSON.parse(uploadRes.data);
+            console.log(res, "涓婁紶鏂囦欢4");
+            if (res.code === 200) {
+              // 2. 鎻愬彇鏂囦欢淇℃伅
+              const fileName = tempFile.name
+                ? tempFile.name
+                : tempFile.path.split("/").pop();
+              // const fileType = fileName.split(".").pop();
+              // 3. 鏋勯�犱繚瀛樻枃浠朵俊鎭殑鍙傛暟
+              const saveData = {
+                name: fileName,
+                deviceMaintenanceId: upkeepId.value,
+                url: res.data.tempPath || "",
+              };
+              console.log(saveData, "淇濆瓨鏂囦欢淇℃伅鍙傛暟");
+              // 4. 璋冪敤 addRuleFile 鎺ュ彛淇濆瓨鏂囦欢淇℃伅
+              addMaintenanceTaskFile(saveData)
+                .then(addRes => {
+                  if (addRes.code === 200) {
+                    // 5. 娣诲姞鍒版枃浠跺垪琛�
+                    const newFile = {
+                      ...addRes.data,
+                      uploadTime: new Date().toLocaleString(),
+                    };
+                    // fileList.value.push(newFile);
+                    getFileList();
+                    showToast("涓婁紶鎴愬姛");
+                  } else {
+                    showToast("淇濆瓨鏂囦欢淇℃伅澶辫触");
+                  }
+                })
+                .catch(err => {
+                  console.error("淇濆瓨鏂囦欢淇℃伅澶辫触:", err);
+                  showToast("淇濆瓨鏂囦欢淇℃伅澶辫触");
+                });
+            } else {
+              showToast("鏂囦欢涓婁紶澶辫触");
+            }
+          } catch (e) {
+            console.error("瑙f瀽涓婁紶缁撴灉澶辫触:", e);
+            showToast("涓婁紶澶辫触");
+          }
+        },
+        fail: err => {
+          uni.hideLoading();
+          console.error("涓婁紶澶辫触:", err);
+          showToast("涓婁紶澶辫触");
+        },
+      });
+    });
+  };
+  // 涓嬭浇鏂囦欢
+  const downloadFile = file => {
+    var url =
+      config.baseUrl +
+      "/common/download?fileName=" +
+      encodeURIComponent(file.url) +
+      "&delete=true";
+    console.log(url, "url");
+
+    uni
+      .downloadFile({
+        url: url,
+        responseType: "blob",
+        header: { Authorization: "Bearer " + getToken() },
+      })
+      .then(res => {
+        let osType = uni.getStorageSync("deviceInfo").osName;
+        let filePath = res.tempFilePath;
+        if (osType === "ios") {
+          uni.openDocument({
+            filePath: filePath,
+            showMenu: true,
+            success: res => {},
+            fail: err => {
+              console.log("uni.openDocument--fail");
+              reject(err);
+            },
+          });
+        } else {
+          uni.saveFile({
+            tempFilePath: filePath,
+            success: fileRes => {
+              uni.showToast({
+                icon: "none",
+                mask: true,
+                title:
+                  "鏂囦欢宸蹭繚瀛橈細Android/data/uni.UNI720216F/apps/__UNI__720216F/" +
+                  fileRes.savedFilePath, //淇濆瓨璺緞
+                duration: 3000,
+              });
+              setTimeout(() => {
+                //鎵撳紑鏂囨。鏌ョ湅
+                uni.openDocument({
+                  filePath: fileRes.savedFilePath,
+                  success: function (res) {},
+                });
+              }, 1000);
+            },
+            fail: err => {
+              console.log("uni.save--fail");
+              reject(err);
+            },
+          });
+        }
+        // const isBlob = blobValidate(res.data);
+        // if (isBlob) {
+        //   const blob = new Blob([res.data], { type: "text/plain" });
+        //   const url = URL.createObjectURL(blob);
+        //   const downloadLink = document.getElementById("downloadLink");
+        //   downloadLink.href = url;
+        //   downloadLink.download = file.name;
+        //   downloadLink.click();
+        //   showToast("涓嬭浇鎴愬姛");
+        // } else {
+        //   showToast("涓嬭浇澶辫触");
+        // }
+      })
+      .catch(err => {
+        console.error("涓嬭浇澶辫触:", err);
+        showToast("涓嬭浇澶辫触");
+      });
+  };
+
+  // 纭鍒犻櫎
+  const confirmDelete = (file, index) => {
+    uni.showModal({
+      title: "鍒犻櫎纭",
+      content: `纭畾瑕佸垹闄ら檮浠� "${file.name}" 鍚楋紵`,
+      success: res => {
+        if (res.confirm) {
+          deleteFile(file.id, index);
+        }
+      },
+    });
+  };
+
+  // 鍒犻櫎鏂囦欢
+  const deleteFile = (fileId, index) => {
+    uni.showLoading({
+      title: "鍒犻櫎涓�...",
+      mask: true,
+    });
+
+    delMaintenanceTaskFile([fileId])
+      .then(res => {
+        uni.hideLoading();
+        if (res.code === 200) {
+          // fileList.value.splice(index, 1);
+          getFileList();
+          showToast("鍒犻櫎鎴愬姛");
+        } else {
+          showToast("鍒犻櫎澶辫触");
+        }
+      })
+      .catch(err => {
+        uni.hideLoading();
+        showToast("鍒犻櫎澶辫触");
+      });
+  };
+
+  // 鏄剧ず鎻愮ず
+  const showToast = message => {
+    uni.showToast({
+      title: message,
+      icon: "none",
+    });
+  };
+  const rulesRegulationsManagementId = ref("");
+  const upkeepId = ref("");
+  // 椤甸潰鍔犺浇鏃�
+  onMounted(() => {
+    // 浠� API 鑾峰彇闄勪欢鍒楄〃
+
+    // 浠庢湰鍦板瓨鍌ㄨ幏鍙� rulesRegulationsManagementId
+    rulesRegulationsManagementId.value = uni.getStorageSync(
+      "rulesRegulationsManagement"
+    );
+    upkeepId.value = uni.getStorageSync("upkeepId");
+    getFileList();
+  });
+
+  // 鑾峰彇闄勪欢鍒楄〃
+  const getFileList = () => {
+    uni.showLoading({
+      title: "鍔犺浇涓�...",
+      mask: true,
+    });
+
+    listMaintenanceTaskFiles({
+      current: 1,
+      size: 100,
+      deviceMaintenanceId: upkeepId.value,
+      rulesRegulationsManagementId: upkeepId.value,
+    })
+      .then(res => {
+        uni.hideLoading();
+        if (res.code === 200) {
+          fileList.value = res.data.records || [];
+        } else {
+          showToast("鑾峰彇闄勪欢鍒楄〃澶辫触");
+        }
+      })
+      .catch(err => {
+        uni.hideLoading();
+        showToast("鑾峰彇闄勪欢鍒楄〃澶辫触");
+      });
+  };
+</script>
+
+<style scoped lang="scss">
+  @import "../../../styles/sales-common.scss";
+
+  .file-list-page {
+    min-height: 100vh;
+    background: #f8f9fa;
+    padding-bottom: 100rpx;
+  }
+
+  .file-list-container {
+    padding: 20rpx;
+  }
+
+  .file-list {
+    background: #ffffff;
+    border-radius: 8rpx;
+    overflow: hidden;
+    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
+  }
+
+  .file-item {
+    display: flex;
+    align-items: center;
+    padding: 20rpx;
+    border-bottom: 1rpx solid #f0f0f0;
+
+    &:last-child {
+      border-bottom: none;
+    }
+  }
+
+  .file-icon {
+    width: 56rpx;
+    height: 56rpx;
+    border-radius: 8rpx;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    margin-right: 20rpx;
+
+    &.blue {
+      background: #409eff;
+    }
+
+    &.green {
+      background: #67c23a;
+    }
+
+    &.red {
+      background: #f56c6c;
+    }
+
+    &.orange {
+      background: #e6a23c;
+    }
+
+    &.gray {
+      background: #909399;
+    }
+
+    &.purple {
+      background: #909399;
+    }
+
+    &.yellow {
+      background: #e6a23c;
+    }
+  }
+
+  .file-info {
+    flex: 1;
+    min-width: 0;
+  }
+
+  .file-name {
+    display: block;
+    font-size: 16px;
+    color: #303133;
+    margin-bottom: 8rpx;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+  }
+
+  .file-meta {
+    display: block;
+    font-size: 12px;
+    color: #909399;
+  }
+
+  .file-actions {
+    display: flex;
+    gap: 12rpx;
+  }
+
+  .empty-state {
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+    padding: 100rpx 0;
+    background: #ffffff;
+    border-radius: 8rpx;
+    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
+  }
+
+  .empty-text {
+    font-size: 14px;
+    color: #909399;
+    margin-top: 20rpx;
+  }
+
+  .upload-button {
+    position: fixed;
+    bottom: 40rpx;
+    right: 40rpx;
+    width: 130rpx;
+    height: 130rpx;
+    border-radius: 50%;
+    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    align-items: center;
+    box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.4);
+    z-index: 1000;
+  }
+
+  .upload-text {
+    font-size: 10px;
+    color: #ffffff;
+    margin-top: 4rpx;
+  }
+
+  .upload-progress {
+    padding: 40rpx 0;
+  }
+
+  .upload-progress-text {
+    display: block;
+    text-align: center;
+    margin-top: 20rpx;
+    font-size: 14px;
+    color: #606266;
+  }
+</style>
\ No newline at end of file

--
Gitblit v1.9.3