Jelajahi Sumber

fix:添加删除功能

ly 11 bulan lalu
induk
melakukan
56eec48cd9

+ 9 - 0
src/api/business/production/onceWorkOrder.js

@@ -66,6 +66,15 @@ export function uploadFiles(workOrderId,fileEntity){
     data: {"workOrderId":workOrderId,"sysFileStorage":fileEntity},
   })
 }
+export function delFile(id){
+  request.defaults.baseURL = '/ezhizao-yzbh-production'
+  return request({
+    url: '/business/onceWorkOrder/delFile',
+    method: 'post',
+    data: id
+  })
+}
+
 export function FileList(query){
   request.defaults.baseURL = '/ezhizao-yzbh-production'
   return request({

+ 69 - 28
src/views/business/production/onceWork/resultDialog.vue

@@ -36,7 +36,7 @@
                 <el-image :src="`${baseUrl}${o.fileUrl}`" class="image" style="max-width: 100%; height: 200px"
                           :preview-teleported="true" fit="contain" :preview-src-list="preList" :initial-index="index"
                 />
-
+                <Delete @click="deleteCol(o.id,o.fileUrl)" style="width: 130px; height: 20px;" />
               </el-card>
             </el-col>
           </el-row>
@@ -46,13 +46,14 @@
       <div ref="uploadDiv" v-else>
         <el-form-item v-if="handlerId === useUserStore().user.userId">
           <el-upload
-              v-if="formHidden !==3 "
+
               v-show="uploadHidden"
               ref="upload"
               class="upload-demo"
               style="flex: auto;"
               drag
               action=""
+              :on-change="handleOnChange"
               accept=".jpg,.jpeg,.png,.gif,.webp"
               v-model:file-list="fileList"
               :multiple="true"
@@ -100,7 +101,7 @@ import {defineProps, getCurrentInstance, reactive, toRefs} from "vue";
 import useUserStore from "@/store/modules/user";
 import {
   updateRecordStatus,
-  FileList,uploadFiles
+  FileList,uploadFiles,delFile
 } from "@/api/business/production/onceWorkOrder";
 import {Delete, UploadFilled} from "@element-plus/icons-vue";
 const { proxy } = getCurrentInstance();
@@ -176,23 +177,23 @@ const sumbitForm = reactive<Tform>({
   resultStatus:null
 });
 const httpRequest = (parm) => {
-  let fileEntity:Ifile = {};
-  const formData2 = new FormData();
-  formData2.append("file", parm.file);
-
-  uploadFile(formData2).then((res:any) => {
-    if (res.code === 200) {
-      fileEntity.fileName = res.newFileName;
-      fileEntity.url = res.url;
-      fileEntity.originalFileName = res.originalFilename;
-      fileEntity.fileUrl = res.fileName;
-    }
-    fileEntityList.value.push(fileEntity);
-  }).then(() => {
-    proxy.$refs['upload'].clearFiles();
-  }).catch(() => {
-    proxy.$refs['upload'].clearFiles();
-  })
+  // let fileEntity:Ifile = {};
+  // const formData2 = new FormData();
+  // formData2.append("file", parm.file);
+  //
+  // uploadFile(formData2).then((res:any) => {
+  //   if (res.code === 200) {
+  //     fileEntity.fileName = res.newFileName;
+  //     fileEntity.url = res.url;
+  //     fileEntity.originalFileName = res.originalFilename;
+  //     fileEntity.fileUrl = res.fileName;
+  //   }
+  //   fileEntityList.value.push(fileEntity);
+  // }).then(() => {
+  //   proxy.$refs['upload'].clearFiles();
+  // }).catch(() => {
+  //   proxy.$refs['upload'].clearFiles();
+  // })
 }
 function openView(id,status,userId,resultStatus,view){
   outerVisible.value = true;
@@ -208,6 +209,7 @@ function openView(id,status,userId,resultStatus,view){
   fileEntity.originalFileName = null;
   fileEntity.fileUrl = null;
   handlerId.value = userId;
+  fileList.value = [];
   filesTable.value = null;
   pasteList.value =[];
   preList.value = [];
@@ -239,6 +241,13 @@ const onsumbit = () => {
         })
       })
     })
+    if(fileList.value.length > 0){
+      proxy.$refs['upload'].submit()
+    }if(pasteList.value.length > 0) {
+      //uploadFiles(workOrderId.value,fileEntityList)
+    }
+    getList.value();
+    outerVisible.value = false;
   }else{
     proxy.$alert(
         "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
@@ -247,13 +256,7 @@ const onsumbit = () => {
         { dangerouslyUseHTMLString: true }
     );
   }
-  if(fileList.value.length > 0){
-    proxy.$refs['upload'].submit()
-  }if(pasteList.value.length > 0) {
-   //uploadFiles(workOrderId.value,fileEntityList)
-  }
-  getList.value();
-  outerVisible.value = false;
+
 }
 function handleBeforeUpload(file) {
   //const formData = new FormData();
@@ -288,16 +291,54 @@ const handlePase = (e)=>{
   uploadHidden.value = false;
 }
 const handleEnter = ()=>{
-  fileIpt.value.focus();
+  if(fileList.value !== null){
+    fileIpt.value.focus();
+  }
   //document.getElementsByClassName("resultDiv")[0].click();
 }
 const deleteCol = (id,fileUrl)=>{
+  fullscreenLoading.value = true;
   fileEntityList.value = fileEntityList.value.filter((file:Ifile)=>{
      return file.fileUrl !== fileUrl
   })
   viewList.value = viewList.value.filter((file)=>{
     return !file.includes(fileUrl);
   })
+  filesTable.value = filesTable.value.filter((file:Ifile)=>{
+    if(file.fileUrl == fileUrl){
+      if(file.id !== null){
+        delFile(file.id).then(()=>{
+          FileList({"masterTableName":"biz_work_order_record","masterId":workOrderId.value}).then((response) => {
+            filesTable.value = response.data
+            filesTable.value.forEach((file)=>{
+              preList.value.push(baseUrl+file.fileUrl)
+            })
+          })
+        })
+      }
+    }
+    return file.fileUrl !== fileUrl
+  })
+  fullscreenLoading.value = false;
+}
+const handleOnChange = (e)=>{
+  if(e.status ==="ready"){
+      const formData2 = new FormData();
+      formData2.append("file", e.raw);
+      uploadFile(formData2).then((res:any) => {
+        let fileEntity:Ifile = {};
+        if (res.code === 200) {
+          fileEntity.id = res.id;
+          fileEntity.fileName = res.newFileName;
+          fileEntity.url = res.url;
+          fileEntity.originalFileName = res.originalFilename;
+          fileEntity.fileUrl = res.fileName;
+        }
+        viewList.value.push(`${baseUrl}+${res.url}`);
+        fileEntityList.value.push(fileEntity);
+      })
+    uploadHidden.value = false;
+  }
 }
 defineExpose({
   openView,