scorpioyq 3 years ago
parent
commit
b161b22533
2 changed files with 96 additions and 10 deletions
  1. 89 3
      src/views/home/component/files_list.vue
  2. 7 7
      src/views/home/files.vue

+ 89 - 3
src/views/home/component/files_list.vue

@@ -35,7 +35,7 @@
         <div class="flex flex-center" style="flex: 3">
           <main-button icon="View" title="详情" width="85" @click="View(item)"/>
           <main-button v-if="item.type === '1'" icon="Download" title="下载" width="85" @click="downFile(item)"/>
-          <!--          <main-button icon="UploadFilled" title="同步" width="85"/>-->
+          <!--          <main-button v-if="item.type === '2'" icon="Upload" title="上传文件" width="85" @click="show = true"/>-->
           <main-button v-if='item.del' icon="Delete" title="删除" width="85" @click="removeFile(item)"/>
         </div>
       </div>
@@ -51,6 +51,14 @@
         :url-list="imgList"
         @close='viewerClose'
     />
+    <el-dialog v-model="show"
+               append-to-body
+               center
+               title="附件上传(可批量)">
+      <uploadFile :data='{type:1,toStatus:0}' :max='20'
+                  @close='show = false'
+                  @success='success'/>
+    </el-dialog>
   </div>
 </template>
 
@@ -59,10 +67,11 @@ import mainButton from '../../../components/main-button.vue'
 import { bytesToSize } from '@/utils/tools.js'
 import { useStore } from '@/store/user.js'
 import permissionStore from '@/store/permission.js'
+import uploadFile from '../../../components/upload-file.vue'
 
 export default {
   name: 'files_list',
-  components: { mainButton },
+  components: { mainButton, uploadFile },
   props: {
     data: Object
   },
@@ -102,10 +111,19 @@ export default {
   },
   data () {
     return {
+      show: false,
       files: [],
       showImage: false,
       imgList: [],
-      query: null
+      query: null,
+      fileList: [],
+      saveCount: 0,
+      libraryList: [],
+      sendParams: {
+        ids: '',
+        ownerId: '',
+        projectId: ''
+      }
     }
   },
   created () {
@@ -134,6 +152,74 @@ export default {
         })
       }
     },
+    success (res) {
+      this.fileList = res.fileList.map(res => {
+        const item = {}
+        item.title = res.response.data.originalFileName
+        item.suffix = res.response.data.suffix
+        item.volume = res.response.data.volume
+        item.fileId = res.response.data.id
+        item.fileFolderId = this.id
+        item.projectId = this.projectId
+        return item
+      })
+      this.fileList.forEach(sub => {
+        this.saveCount++
+        if (['pdf', 'doc'].includes(sub.suffix)) {
+          this.saveLibrary(sub)
+        }
+        if (this.saveCount === this.fileList.length) {
+          this.saveCount = 0
+          this.addFile()
+        }
+      })
+    },
+    saveLibrary (sub) {
+      const data = { category: 4, content: '' }
+      this.$api.common.submit(Object.assign(sub, data)).then(res => {
+        if (res.code === 200) {
+          this.saveCount++
+          this.libraryList.push(res.data.id)
+        } else {
+          this.$message.error(res.msg)
+        }
+      })
+    },
+    addFile () {
+      this.$api.project.fileAdd(this.fileList).then(res => {
+        if (res.code === 200) {
+          this.show = false
+          this.$emit('reFiles')
+          this.$message.success(res.msg)
+          if (this.user.info.type !== 3) {
+            this.$confirm('文件上传成功,是否给业主发送提醒消息?', {
+              confirmButtonText: '确定',
+              cancelButtonText: '取消',
+              type: 'warning'
+            })
+              .then(() => {
+                this.SendMsg()
+              })
+          }
+        } else {
+          this.show = false
+          this.$message.error(res.msg)
+        }
+      })
+    },
+    SendMsg () {
+      this.sendParams.ids = this.fileList.map(e => e.fileId).join(',')
+      this.sendParams.projectId = this.projectId
+      this.$api.project.send(this.sendParams).then(res => {
+        if (res.code === 200) {
+          this.$message.success('消息已经发送成功!')
+          this.$bus.emit('reFolder')
+          this.sendMsg = false
+        } else {
+          this.$message.error(res.msg)
+        }
+      })
+    },
     downFile (item) {
       window.open(item.url, '')
     },

+ 7 - 7
src/views/home/files.vue

@@ -21,8 +21,8 @@ import historical from './component/historical.vue'
 
 export default {
   name: 'files',
-  components: {current, historical},
-  data() {
+  components: { current, historical },
+  data () {
     return {
       id: '',
       fileData: '',
@@ -31,7 +31,7 @@ export default {
 
     }
   },
-  created() {
+  created () {
     this.id = this.$route.query.id
     this.getFileList()
     this.getFolderAll()
@@ -43,8 +43,8 @@ export default {
     })
   },
   methods: {
-    getFileList() {
-      this.$api.project.fileList({folderId: this.id}).then(res => {
+    getFileList () {
+      this.$api.project.fileList({ folderId: this.id }).then(res => {
         if (res.code === 200) {
           this.fileData = res.data
         } else {
@@ -52,8 +52,8 @@ export default {
         }
       })
     },
-    getFolderAll() {
-      this.$api.project.folderListAll({parentId: this.id}).then(res => {
+    getFolderAll () {
+      this.$api.project.folderListAll({ parentId: this.id, type: 1 }).then(res => {
         if (res.code === 200) {
           this.historyFolder = res.data.records.map(e => {
             e.folderName = e.title