Explorar o código

试验自检更改附件接口对接

duy %!s(int64=2) %!d(string=hai) anos
pai
achega
299ab9e640

+ 8 - 0
src/api/modules/tentative/detect/test.js

@@ -145,4 +145,12 @@ export default {
             params: form
         }, msg);
     },
+ //自检记录附件修改接口:
+    async updateAncillaryDocument(form, msg = true) {
+        return httpApi({
+            url: '/api/blade-business/detection/self/update-ancillary-documents',
+            method: 'post',
+            data: form
+        }, msg);
+    },
 }

+ 91 - 90
src/views/tentative/detect/components/HcDragUpload.vue

@@ -1,20 +1,13 @@
 <template>
-    <el-upload ref="uploadRef" class="hc-upload-border approach" drag :action="action" :headers="getTokenHeader()" :data="uploadData" :accept="accept" :disabled="uploadDisabled" :limit="1" :show-file-list="false"
-               :before-upload="beforeUpload" :on-exceed="uploadExceed" :on-progress="uploadprogress" :on-success="uploadSuccess" :on-error="uploadError" :on-change="uploadChange" :auto-upload="false">
-
-        <div class="hc-upload-loading upload-file-info" v-loading="uploadDisabled" element-loading-text="上传中...">
-            <template v-if="uploadFileInfo?.name">
-                <HcIcon name="file-text" class="upload-file-icon"/>
-                <div class="upload-file-name">{{uploadFileInfo?.name}}</div>
-            </template>
-            <template v-else>
-                <HcIcon name="upload-cloud" class="upload-icon"/>
-                <div class="el-upload__text">拖动文件到这里 或 <em>点击这里选择文件</em> 并上传</div>
-            </template>
+    <el-upload class="hc-upload-border" drag :action="action" :headers="getTokenHeader()" :data="uploadData" :accept="accept" :file-list="fileListData"  :disabled="uploadDisabled"
+               :on-preview="uploadPreview"  :on-success="uploadSuccess" :on-exceed="uploadExceed" :on-error="uploadError" :before-upload="beforeUpload"
+               :on-progress="uploadprogress" :limit="1"  ref="upload">
+        <div class="hc-upload-loading" v-loading="uploadDisabled" :element-loading-text="loadingText">
+            <HcIcon name="backup" ui="text-5xl mt-4"/>
+            <div class="el-upload__text">拖动文件到这里 或 <em>点击这里选择文件</em> 并上传</div>
         </div>
-
         <template #tip>
-            <div class="el-upload__tip">允许格式:excel, 文件大小 小于 60MB</div>
+            <div class="el-upload__tip" style="font-size: 14px;">允许格式:jpg/png/pdf/excel/word, 文件大小 小于 60MB</div>
         </template>
     </el-upload>
 </template>
@@ -22,131 +15,139 @@
 <script setup>
 import {ref,watch,onMounted} from "vue";
 import {getTokenHeader} from '~src/api/request/header';
-import {getObjValue, isSize} from "vue-utils-plus"
-import {genFileId} from "element-plus";
+import wbsApi from "~api/data-fill/wbs"
+import {isSize} from "vue-utils-plus"
+import { genFileId } from 'element-plus'
 const props = defineProps({
+    fileList: {
+        type: Array,
+        default: () => ([])
+    },
     datas: {
         type: Object,
         default: () => ({})
     },
+  
 })
 
 //变量
-const uploadRef = ref(null)
 const uploadData = ref(props.datas)
-const uploadFileInfo = ref({})
-const uploadDisabled = ref(false)
+const fileListData = ref(props.fileList);
 
-const action = '/api/blade-manager/exceltab/add-buss-file';
-const accept = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel';
+const action = '/api/blade-resource/oss/endpoint/put-file-attach';
+const accept = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+const uploadDisabled = ref(false)
 
 //监听
 watch(() => [
+    props.fileList,
     props.datas,
-], ([datas]) => {
+    
+], ([fileList, datas]) => {
     uploadData.value = datas
+    fileListData.value = fileList
+  
 })
 
+//渲染完成
+onMounted(()=> {
+    beforeFileNum.value = 0
+    finishFileNum.value = 0
+    errorFileNum.value = 0
+})
 
 //事件
-const emit = defineEmits(['progress', 'finished', 'change'])
+const emit = defineEmits(['change'])
 
 //上传前
+const beforeFileNum = ref(0)
 const beforeUpload = async (file) => {
     if (isSize(file?.size,60)) {
+        beforeFileNum.value ++;
         return true;
     } else {
         window?.$message?.warning('文件大小, 不能过60M!');
         return false;
     }
 }
-
+const upload=ref('')
 //超出限制时
 const uploadExceed = (files) => {
-    uploadRef.value?.clearFiles()
-    const file = files[0]
-    file.uid = genFileId()
-    uploadRef.value?.handleStart(file)
+     
+    window?.$message?.warning('只能上传一个文件,请删除原文件再上传');
+  
+//   const file = files[0] 
+//   file.uid = genFileId()
+//   upload.value.handleStart(file)
 }
 
 //上传中
+const loadingText = ref('上传中...')
 const uploadprogress = () => {
+    loadingText.value = '上传中...'
     uploadDisabled.value = true
-    emit('progress', true)
 }
 
 //上传完成
-const uploadSuccess = (res) => {
+const finishFileNum = ref(0)
+// const uploadSuccess = () => {
+//     finishFileNum.value ++;
+//     if (beforeFileNum.value === finishFileNum.value) {
+//         uploadDisabled.value = false
+//         emit('change', {type: 'success'})
+//     }
+// }
+//上传完成
+const uploadSuccess = ({code, data}) => {
     uploadDisabled.value = false
     emit('progress', false)
-    emit('finished', {
-        type: 'success',
-        data: getObjValue(res?.data)
-    })
+    if (code === 200) {
+        window?.$message?.success('上传成功');
+        emit('finished', data)
+    } else {
+        window?.$message?.error('上传失败');
+    }
 }
 
-//上传失败
-const uploadError = (res) => {
-    uploadDisabled.value = false
-    emit('progress', false)
-    emit('finished', {
-        type: 'error',
-        data: getObjValue(res?.data)
-    })
-    window?.$message?.error('导入失败');
-}
 
-//文件改变时
-const uploadChange = (file) => {
-    console.log(file)
-    uploadFileInfo.value = file
-    emit('change', file)
+//上传失败
+const errorFileNum = ref(0)
+const uploadError = () => {
+    errorFileNum.value ++;
+    window?.$message?.error('上传失败');
+    const num = finishFileNum.value + errorFileNum.value;
+    if (beforeFileNum.value === num) {
+        uploadDisabled.value = false
+        emit('change', {type: 'success'})
+    }
 }
 
-const submit = () => {
-    uploadRef.value?.submit()
+//预览
+const uploadPreview = ({url}) => {
+    if (url) {
+        window.open(url, '_blank')
+    }
 }
 
-const clearFiles = () => {
-    uploadRef.value?.clearFiles()
+//删除文件
+const delUploadData = async ({id}) => {
+    loadingText.value = '删除中...'
+    uploadDisabled.value = true
+    const {error, code} = await wbsApi.removeBussFile({
+        ids: id
+    })
+    uploadDisabled.value = false
+    if (!error && code === 200) {
+        window?.$message?.success('删除成功')
+        return true
+    } else {
+        return false
+    }
 }
 
-// 暴露出去
-defineExpose({
-    submit,
-    clearFiles
-})
-</script>
-
-<style lang="scss">
-.hc-upload-border.approach {
-    .el-upload-dragger {
-        padding: 24px;
-    }
-    .hc-upload-loading.upload-file-info {
-        .hc-icon-i {
-            font-size: 40px;
-        }
-        .upload-icon {
-            color: var(--el-text-color-placeholder);
-        }
-        .upload-file-icon {
-            color: var(--el-color-primary-light-5);
-        }
-        .el-upload__text {
-            margin-top: 10px;
-        }
-        .upload-file-name {
-            margin-top: 10px;
-            font-size: 14px;
-            text-align: center;
-            color: var(--el-color-primary);
-        }
-    }
-    .el-upload__tip {
-        font-size: 14px;
-        margin-top: 16px;
-        color: var(--el-text-color-placeholder);
+const uploadRemove = () => {
+    if(fileListData.value.length <= 0) {
+        emit('change', {type: 'del'})
     }
 }
-</style>
+</script>

+ 84 - 12
src/views/tentative/detect/test.vue

@@ -114,7 +114,7 @@
                     </template>
                     <template #action="{row}">
                         <HcTooltip keys="tentative_detect_test_annex">
-                            <el-button type="primary" size="small" plain @click="viewAttachmentModalClick(row)">附件</el-button>
+                            <el-button type="primary" size="small" plain   @click="viewAttachmentModalClick(row)">附件</el-button>
                         </HcTooltip>
                         <HcTooltip keys="tentative_detect_test_info">
                             <el-button type="primary" size="small" plain @click="samplingRecordModalClick(row)">样品信息</el-button>
@@ -128,25 +128,27 @@
         </div>
 
         <!--查看附件-->
-        <HcDialog :show="viewAttachmentModal" title="查看附件" widths="70rem" :footer="false" isTable @close="viewAttachmentModalClose">
+        <HcDialog :show="viewAttachmentModal" title="查看附件" widths="100rem" :footer="false" isTable @close="viewAttachmentModalClose">
             <template #extra>
                 <HcNewSwitch :datas="tabTypeTab" :keys="tabTypeKey" @change="tabTypeChange"/>
             </template>
             <div class="hc-switch-tab-content" v-loading="viewAttachmentLoading">
                 <div class="h-full w-full flex">
                     <div class="pdf-file-list-box">
-                        <template v-for="item in viewAttachmentData">
-                            <div class="file-item cur">文件名称1.pdf</div>
+                        <template v-for="item in viewAttachmentData" >
+                            <div class="file-item" :class="[item.isCheck ? 'cur' : '']"  @click="viewCurFile(item)">{{item.name||''}}</div>
                         </template>
-                        <div class="file-item">文件名称2.pdf</div>
+                        <!-- <div class="file-item">文件名称2.pdf</div>
                         <div class="file-item">文件名称3.pdf</div>
                         <div class="file-item">文件名称4.pdf</div>
-                        <div class="file-item">文件名称5.pdf</div>
+                        <div class="file-item">文件名称5.pdf</div> -->
                     </div>
-                    <!--iframe allow="display-capture" width='100%' height='100%' frameborder='1' :src="attachmentPdfUrl" v-if="attachmentPdfUrl"/-->
-                    <div class="hc-no-table-form">
+                   <!-- <iframe width='80%' height='100%' frameborder='1' :src="attachmentPdfUrl" v-if="attachmentPdfUrl"/> -->
+                    <div class="hc-no-table-form" >
                         <div class="table-form-no">
-                            <HcDragUpload/>
+                            <HcDragUpload  @progress="uploadprogress" @finished="uploadFinished" :datas="uploadData"  :fileList="fileListData" v-if="listuploadref==='1'"/>
+                             <HcDragUpload  @progress="uploadprogress" @finished="uploadFinished" :datas="uploadData"  :fileList="fileListData" v-if="listuploadref==='2'"/>
+                             <HcDragUpload  @progress="uploadprogress" @finished="uploadFinished" :datas="uploadData"  :fileList="fileListData" v-if="listuploadref==='3'"/>
                         </div>
                     </div>
                 </div>
@@ -504,20 +506,27 @@ const viewAttachmentModal = ref(false)
 const viewAttachmentLoading = ref(false)
 const viewAttachmentData = ref([])
 const viewAttachmentModalClick = async ({id}) => {
-    viewAttachmentModal.value = true
     viewAttachmentLoading.value = true
     const { error, code, data } = await dataApi.ancillaryDocumentsList({id: id})
     //处理数据
     viewAttachmentLoading.value = false
     if (!error && code === 200) {
         viewAttachmentData.value = getArrValue(data)
+        if ( viewAttachmentData.value.length<1) {
+             window.$message?.warning('该条记录不存在附件')
+        }else{
+             viewAttachmentModal.value = true
+             viewCurFile( viewAttachmentData.value[0])
+        }
+       
     } else {
         viewAttachmentData.value = []
+         
     }
 }
 
 const attachmentPdfUrl = ref('')
-
+const curFileData =ref ({})
 //类型tab数据和相关处理
 const tabTypeKey = ref('productionCertificate')
 const tabTypeTab = ref([
@@ -527,11 +536,73 @@ const tabTypeTab = ref([
 ]);
 const tabTypeChange = (item) => {
     tabTypeKey.value = item?.key
+    viewCurFile(curFileData.value)
 }
 
 //关闭查看附件
 const viewAttachmentModalClose = () => {
     viewAttachmentModal.value = false
+     curFileData.value=''
+     attachmentPdfUrl.value=''
+}
+const uploadData = ref({})
+const fileListData=ref([])
+const listuploadref=ref('1')
+//查看当前文件pdf
+const viewCurFile = (item) => {
+    curFileData.value=item
+    viewAttachmentData.value.forEach((ele)=>{
+        if (ele.name===item.name) {
+            ele.isCheck=true
+        }else{
+            ele.isCheck=false
+        }
+    })
+    if(tabTypeKey.value=='productionCertificate'&&item.productionCertificate.length>0){
+        let arr=[]
+        arr.push({name:item.productionCertificate,url:item.productionCertificate})
+        fileListData.value =getArrValue(arr)
+        listuploadref.value='1'
+    }else if(tabTypeKey.value=='qualityInspectionReport'&&item.qualityInspectionReport.length>0){
+         let arr=[]
+         arr.push({name:item.qualityInspectionReport,url:item.qualityInspectionReport})
+         fileListData.value =getArrValue(arr)
+         listuploadref.value='2'
+    }else if(tabTypeKey.value=='otherAccessories'&&item.otherAccessories.length>0){
+          let arr=[]
+        arr.push({name:item.otherAccessories,url:item.otherAccessories})
+         fileListData.value =getArrValue(arr)
+         listuploadref.value='3'
+    }else{
+         attachmentPdfUrl.value=''
+    }      
+}
+
+//上传进度
+const uploadprogress = (res) => {
+ console.log('进度');
+}
+
+const productionCertificatefile=ref('')
+const qualityInspectionReportfile=ref('')
+const otherAccessoriesfile=ref('')
+//上传完成
+const uploadFinished = async(res) => {
+    if(tabTypeKey.value=='productionCertificate'){
+        productionCertificatefile.value =res
+    } else if (tabTypeKey.value=='qualityInspectionReport') {
+        qualityInspectionReportfile.value=res
+    }else{
+        otherAccessoriesfile.value=res
+    }
+ 
+    const { error, code, data } = await dataApi.updateAncillaryDocument(
+        {
+            id:curFileData.value.id,
+            productionCertificate:productionCertificatefile.value.link,
+            qualityInspectionReport:qualityInspectionReportfile.value.link,
+            otherAccessories:otherAccessoriesfile.value.link
+        })
 }
 
 //样品信息数据
@@ -600,9 +671,10 @@ const onmousedown = () => {
         overflow-y: auto;
         height: 100%;
         flex: 1;
+       
         .file-item {
             position: relative;
-            cursor: default;
+            cursor: pointer;
             padding: 6px 10px;
             &:hover {
                 color: var(--el-color-primary);