From 0a251e40e30e7c8a96d71b3b9b6c459d4dfa4b22 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 08 七月 2026 23:04:45 +0800
Subject: [PATCH] 暂存

---
 src/views/qualityManagement/rawMaterialInspection/components/filesDia.vue |  203 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 202 insertions(+), 1 deletions(-)

diff --git a/src/views/qualityManagement/rawMaterialInspection/components/filesDia.vue b/src/views/qualityManagement/rawMaterialInspection/components/filesDia.vue
index e573db8..5bb666a 100644
--- a/src/views/qualityManagement/rawMaterialInspection/components/filesDia.vue
+++ b/src/views/qualityManagement/rawMaterialInspection/components/filesDia.vue
@@ -1,9 +1,210 @@
 <template>
-  <div></div>
+  <div>
+    <el-dialog
+        v-model="dialogFormVisible"
+        title="涓婁紶闄勪欢"
+        width="50%"
+        @close="closeDia"
+    >
+      <div style="margin-bottom: 10px;text-align: right">
+        <el-upload
+            v-model:file-list="fileList"
+            class="upload-demo"
+            :action="uploadUrl"
+            :on-success="handleUploadSuccess"
+            :on-error="handleUploadError"
+            name="files"
+            :show-file-list="false"
+            :headers="headers"
+            style="display: inline;margin-right: 10px"
+        >
+          <el-button type="primary">涓婁紶闄勪欢</el-button>
+        </el-upload>
+        <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>
+      </div>
+      <PIMTable
+          rowKey="id"
+          :column="tableColumn"
+          :tableData="tableData"
+          :page="page"
+          :tableLoading="tableLoading"
+          :isSelection="true"
+          @selection-change="handleSelectionChange"
+          @pagination="paginationSearch"
+          height="500"
+      >
+      </PIMTable>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button @click="closeDia">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
+		<filePreview ref="filePreviewRef" />
+  </div>
 </template>
 
 <script setup>
+import {ref} from "vue";
+import filePreview from '@/components/filePreview/index.vue'
+import {ElMessageBox} from "element-plus";
+import {getToken} from "@/utils/auth.js";
+import {
+  createAttachment,
+  deleteAttachment,
+  attachmentList
+} from "@/api/basicData/storageAttachment.js";
+const { proxy } = getCurrentInstance()
+const emit = defineEmits(['close'])
 
+const dialogFormVisible = ref(false);
+const currentId = ref('')
+const selectedRows = ref([]);
+const tableColumn = ref([
+  {
+    label: "鏂囦欢鍚嶇О",
+    prop: "name",
+  },
+  {
+    dataType: "action",
+    label: "鎿嶄綔",
+    align: "center",
+    operation: [
+      {
+        name: "涓嬭浇",
+        type: "text",
+        clickFun: (row) => {
+          downLoadFile(row);
+        },
+      },
+			{
+				name: "棰勮",
+				type: "text",
+				clickFun: (row) => {
+					lookFile(row);
+				},
+			}
+    ],
+  },
+]);
+const page = reactive({
+	current: 1,
+	size: 100,
+	total: 0,
+});
+const tableData = ref([]);
+const fileList = ref([]);
+const tableLoading = ref(false);
+const filePreviewRef = ref()
+const headers = ref({
+  Authorization: "Bearer " + getToken(),
+});
+const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 涓婁紶鐨勬湇鍔″櫒鍦板潃
+
+// 鎵撳紑寮规
+const openDialog = (row) => {
+  dialogFormVisible.value = true;
+  currentId.value = row.id;
+  getList()
+}
+const paginationSearch = (obj) => {
+	page.current = obj.page;
+	page.size = obj.limit;
+	getList();
+};
+const getList = () => {
+  attachmentList({recordId: currentId.value, recordType: 'quality_inspect'}).then(res => {
+    tableData.value = (res.data || []).map(item => ({
+      ...item,
+      name: item.originalFilename || item.name
+    }));
+    page.total = res.data ? res.data.length : 0;
+  })
+}
+// 琛ㄦ牸閫夋嫨鏁版嵁
+const handleSelectionChange = (selection) => {
+  selectedRows.value = selection;
+};
+
+// 鍏抽棴寮规
+const closeDia = () => {
+  dialogFormVisible.value = false;
+  emit('close')
+};
+let pendingFiles = [];
+let uploadTimer = null;
+
+// 涓婁紶鎴愬姛澶勭悊
+function handleUploadSuccess(res, file) {
+  // 濡傛灉涓婁紶鎴愬姛
+  if (res.code == 200 && res.data && res.data.length > 0) {
+    const newFiles = res.data.map(item => ({
+      ...item,
+      name: item.originalFilename || item.name
+    }));
+    
+    pendingFiles = [...pendingFiles, ...newFiles];
+    
+    // 闃叉姈澶勭悊锛岄伩鍏嶅鏂囦欢鍚屾椂涓婁紶瀵艰嚧鍒楄〃琚鐩�
+    if (uploadTimer) clearTimeout(uploadTimer);
+    uploadTimer = setTimeout(() => {
+      const mergedFiles = [...(tableData.value || []), ...pendingFiles];
+      const storageAttachmentDTO = {
+        recordType: 'quality_inspect',
+        recordId: currentId.value,
+        application: "file",
+        storageBlobDTOs: mergedFiles
+      };
+      createAttachment(storageAttachmentDTO).then(r => {
+        proxy.$modal.msgSuccess("鏂囦欢涓婁紶鎴愬姛");
+        getList()
+      }).catch(() => {
+        proxy.$modal.msgError("鏂囦欢涓婁紶澶辫触");
+      }).finally(() => {
+        pendingFiles = []; // 閲嶇疆
+      });
+    }, 500);
+  } else {
+    proxy.$modal.msgError("鏂囦欢涓婁紶澶辫触");
+  }
+}
+// 涓婁紶澶辫触澶勭悊
+function handleUploadError() {
+  proxy.$modal.msgError("鏂囦欢涓婁紶澶辫触");
+}
+// 涓嬭浇闄勪欢
+const downLoadFile = (row) => {
+	proxy.$download.byUrl(row.url, row.originalFilename);
+}
+// 棰勮闄勪欢
+const lookFile = (row) => {
+	filePreviewRef.value.open(row.url)
+}
+// 鍒犻櫎
+const handleDelete = () => {
+  let ids = [];
+  if (selectedRows.value.length > 0) {
+    ids = selectedRows.value.map((item) => item.storageAttachmentId);
+  } else {
+    proxy.$modal.msgWarning("璇烽�夋嫨鏁版嵁");
+    return;
+  }
+  ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚垹闄わ紝鏄惁纭鍒犻櫎锛�", "瀵煎嚭", {
+    confirmButtonText: "纭",
+    cancelButtonText: "鍙栨秷",
+    type: "warning",
+  }).then(() => {
+    deleteAttachment(ids).then((res) => {
+      proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+      getList();
+    });
+  }).catch(() => {
+    proxy.$modal.msg("宸插彇娑�");
+  });
+};
+defineExpose({
+  openDialog,
+});
 </script>
 
 <style scoped>

--
Gitblit v1.9.3