Просмотр исходного кода

修复上传附件和修改附件问题

shaogen1995 4 лет назад
Родитель
Сommit
c84a6f1d7f

+ 21 - 8
src/views/holding/holding0_DiaEdit.vue

@@ -401,7 +401,13 @@ export default {
       disabled: false,
       // 表格数据
       tableData: [],
-      tempData: []
+      tempData: {
+        img: [],
+        video: [],
+        audio: [],
+        model: [],
+        doc: []
+      }
     }
   },
   // 监听属性 类似于data概念
@@ -409,7 +415,10 @@ export default {
   // 监控data中的数据变化
   watch: {
     affixVal (val) {
-      this.getFileList(this.fujianId, val)
+      this.tableData = this.tempData[val]
+      this.tableData.forEach(v => {
+        v.updateTime = v.updateTime.slice(0, 10)
+      })
     }
   },
   // 方法集合
@@ -421,7 +430,7 @@ export default {
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        this.tableData = this.tableData.filter(v => v.name !== val.name)
+        this.tableData = this.tempData[this.affixVal] = this.tempData[this.affixVal].filter(v => v.id !== val.id)
         if (this.temp.length !== 0) {
           this.temp.forEach((v, i) => {
             // eslint-disable-next-line
@@ -452,9 +461,13 @@ export default {
     },
     // 通过id获取附件列表
     async getFileList (myId, myType) {
-      const res = await getFileList(myId, myType)
-      // console.log(6666, res)
-      this.tableData = res.data
+      // 进页面获取所有附件数据
+      this.tempData.img = (await getFileList(myId, 'img')).data
+      this.tempData.video = (await getFileList(myId, 'video')).data
+      this.tempData.audio = (await getFileList(myId, 'audio')).data
+      this.tempData.model = (await getFileList(myId, 'model')).data
+      this.tempData.doc = (await getFileList(myId, 'doc')).data
+      this.tableData = this.tempData.video
       this.tableData.forEach(v => {
         v.updateTime = v.updateTime.slice(0, 10)
       })
@@ -471,8 +484,7 @@ export default {
         else this.ruleForm.fileIds += `,${file.data.fileId}`
         this.temp = this.ruleForm.fileIds.split(',')
         this.$message.success('上传成功')
-        this.tableData.push({ name: file.data.fileName, updateTime: file.timestamp.slice(0, 10), filePath: file.data.filePath })
-        await holdingAdd(this.ruleForm)
+        this.tempData[this.affixVal].push({ name: file.data.fileName, updateTime: file.timestamp.slice(0, 10), filePath: file.data.filePath, id: file.data.fileId })
       }
     },
     handleRemove (file) {
@@ -541,6 +553,7 @@ export default {
     // 点击取消
     cancel () {
       // 把附件变成video
+      // console.log(9999999999, this.ruleForm)
       this.affixVal = 'video'
       this.$emit('update:dialogFormVisible', false)
     }

+ 2 - 2
src/views/holding/holding0_Dialog.vue

@@ -425,8 +425,8 @@ export default {
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        this.tableData = this.tableData.filter(v => v.name !== val.name)
-        this.tempData = this.tempData.filter(v => v.name !== val.name)
+        this.tableData = this.tableData.filter(v => v.id !== val.id)
+        this.tempData = this.tempData.filter(v => v.id !== val.id)
         if (this.temp.length !== 0) {
           this.temp.forEach((v, i) => {
             // eslint-disable-next-line

+ 28 - 14
src/views/holding/holding3_DiaEdit.vue

@@ -303,8 +303,8 @@ import {
   getGoodsNumType,
   getGoodsType,
   detailsById,
-  getFileList
-  // deleteAffix
+  getFileList,
+  deleteAffix
 } from '@/apis/holding'
 export default {
   name: 'holding3_DiaEdit',
@@ -402,7 +402,13 @@ export default {
       disabled: false,
       // 表格数据
       tableData: [],
-      tempData: {}
+      tempData: {
+        img: [],
+        video: [],
+        audio: [],
+        model: [],
+        doc: []
+      }
     }
   },
   // 监听属性 类似于data概念
@@ -410,7 +416,10 @@ export default {
   // 监控data中的数据变化
   watch: {
     affixVal (val) {
-      this.getFileList(this.fujianId, val)
+      this.tableData = this.tempData[val]
+      this.tableData.forEach(v => {
+        v.updateTime = v.updateTime.slice(0, 10)
+      })
     }
   },
   // 方法集合
@@ -422,7 +431,7 @@ export default {
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        this.tableData = this.tableData.filter(v => v.name !== val.name)
+        this.tableData = this.tempData[this.affixVal] = this.tempData[this.affixVal].filter(v => v.id !== val.id)
         if (this.temp.length !== 0) {
           this.temp.forEach((v, i) => {
             // eslint-disable-next-line
@@ -431,7 +440,7 @@ export default {
           // console.log(999, this.temp.join(','))
           this.ruleForm.fileIds = this.temp.join(',')
         }
-        // deleteAffix(val.id)
+        deleteAffix(val.id)
         this.$message({
           type: 'success',
           message: '删除成功!'
@@ -452,17 +461,22 @@ export default {
     },
     // 通过id获取附件列表
     async getFileList (myId, myType) {
-      const res = await getFileList(myId, myType)
+      // 进页面获取所有附件数据
+      this.tempData.img = (await getFileList(myId, 'img')).data
+      this.tempData.video = (await getFileList(myId, 'video')).data
+      this.tempData.audio = (await getFileList(myId, 'audio')).data
+      this.tempData.model = (await getFileList(myId, 'model')).data
+      this.tempData.doc = (await getFileList(myId, 'doc')).data
       // console.log(6666, res)
-      this.tableData = res.data
+      this.tableData = this.tempData.video
       this.tableData.forEach((v, i) => {
         v.updateTime = v.updateTime.slice(0, 10)
       })
-      this.$nextTick(() => {
-        setTimeout(() => {
-          this.tableData = this.tableData.filter(v => this.ruleForm.fileIds.includes(v.id + ''))
-        }, 100)
-      })
+      // this.$nextTick(() => {
+      //   setTimeout(() => {
+      //     this.tableData = this.tableData.filter(v => this.ruleForm.fileIds.includes(v.id + ''))
+      //   }, 100)
+      // })
       // console.log(999999, this.tableData, this.ruleForm.fileIds)
       // 删除没有发送接口,需要自己处理数据
       // this.fileList = [{ name: this.tableData[0].name, url: this.tableData[0].filePath }]
@@ -482,7 +496,7 @@ export default {
         // const b = myDate.getMonth()
         // const c = myDate.getDate()
         // console.log(999, a, b + 1, c)
-        this.tableData.push({ name: file.data.fileName, updateTime: file.timestamp.slice(0, 10), filePath: file.data.filePath, type: this.affixVal })
+        this.tempData[this.affixVal].push({ name: file.data.fileName, updateTime: file.timestamp.slice(0, 10), filePath: file.data.filePath, id: file.data.fileId })
         // await holdingAdd(this.ruleForm)
       }
     },