lizhenhao 2 anni fa
parent
commit
6b9dae43ff

+ 1 - 0
src/api/sys/OSSService.js

@@ -35,6 +35,7 @@ export default class OSSSerive {
     return request({
       url: '/oss/file/downLoadAttach',
       method: 'get',
+      responseType: 'blob',
       params: {file: url}
     })
   }

+ 39 - 34
src/views/modules/sys/project/AssessForm.vue

@@ -307,7 +307,7 @@
                      :file-list="filesArra2">
             <el-button type="info" size="mini">点击上传</el-button>
           </el-upload>
-          <div style="height: calc(100% - 80px);">
+          <div style="height: calc(100% - 80px);margin-top: 30px">
           <vxe-table
             style="margin-left: 5em"
             border="inner"
@@ -329,16 +329,17 @@
             <vxe-column type="seq" width="40"></vxe-column>
             <vxe-column title="文件名称" field="name">
               <template slot-scope="scope">
-                <div v-if="ifName(scope.row) === true">
-                  <el-image
-                    style="width: 100px; height: 100px"
-                    :src="getsrc(scope.row)"
-                    :preview-src-list="srcList">
-                  </el-image>
-                </div>
-                <div v-else>
-                  <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
-                </div>
+<!--                <div v-if="ifName(scope.row) === true">-->
+<!--                  <el-image-->
+<!--                    style="width: 100px; height: 100px"-->
+<!--                    :src="src"-->
+<!--                    :preview-src-list="srcList" lazy>-->
+<!--                  </el-image>-->
+<!--                </div>-->
+<!--                <div v-else>-->
+<!--                  <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>-->
+<!--                </div>-->
+                <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
               </template>
             </vxe-column>
             <vxe-column title="创建人" field="createBy"></vxe-column>
@@ -346,8 +347,8 @@
 <!--            <vxe-column title="文件描述" field="description"></vxe-column>-->
             <vxe-column title="操作" width="200px" fixed="right" align="center">
               <template  slot-scope="scope">
-                <el-button type="text"  icon="el-icon-delete" size="small" @click="deleteMsgById(scope.row, scope.$rowIndex)">删除</el-button>
                 <el-button type="text"  icon="el-icon-edit" size="small" @click="toHref(scope.row)">下载</el-button>
+                <el-button type="text"  icon="el-icon-delete" size="small" @click="deleteMsgById(scope.row, scope.$rowIndex)">删除</el-button>
               </template>
             </vxe-column>
           </vxe-table>
@@ -434,7 +435,8 @@
         isFlag: true,
         showViewer: false, // 显示查看器
         url: '',
-        rowurl: ''
+        rowurl: '',
+        src: ''
       }
     },
     components: { ElImageViewer },
@@ -445,31 +447,34 @@
       this.projectService = new ProjectService()
     },
     methods: {
-      async getsrc (row) {
-        console.log('rrrr', row)
-        if (row.id === null || row.id === undefined || row.id === '') {
-          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
-            return data.data
-          })
-        } else {
-          return row.url
-        }
-      },
-      ifName (row) {
-        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
-        if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
-          return true
-        } else {
-          return false
-        }
-      },
+      // async getsrc (row) {
+      //   if (row.id === null || row.id === undefined || row.id === '') {
+      //     await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
+      //       return data.data
+      //     })
+      //   } else {
+      //     return row.url
+      //   }
+      // },
+      // async ifName (row) {
+      //   let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+      //   if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
+      //     return true
+      //   } else {
+      //     return false
+      //   }
+      // },
       async toHref (row) {
         let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
         if (suffix === 'pdf' || suffix === 'txt') {
           if (row.id === null || row.id === undefined || row.id === '') {
-            this.ossService.downLoadAttach(row.raw.url)
+            this.ossService.downLoadAttach(row.raw.url).then((res) => {
+              this.$utils.download(res.data, '项目导入模板')
+            })
           } else {
-            this.ossService.downLoadAttach(row.url)
+            this.ossService.downLoadAttach(row.url).then((res) => {
+              this.$utils.download(res.data, '项目导入模板')
+            })
           }
           return
         }
@@ -589,7 +594,7 @@
             console.log(this.dataListNew)
             this.inputForm.workAttachments = []
             this.dataListNew.forEach((item) => {
-              if (item.id === null || item.id === undefined || item.id === '' ){
+              if (item.id === null || item.id === undefined || item.id === '') {
                 item.url = item.raw.url
               }
               item.attachmentFlag = 'projectRecords'

+ 231 - 2
src/views/modules/sys/project/ConsultationForm.vue

@@ -297,6 +297,71 @@
           </el-col>
 
         </el-row>
+        <el-upload ref="upload" style="display: inline-block; margin-left: 5em; :show-header='status'" action=""
+                   :limit="999" :http-request="httpRequest"
+                   multiple
+                   :on-exceed="(files, fileList) =>{
+                      $message.warning(`当前限制选择 999 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
+                     }"
+                   :on-remove="handleRemove"
+                   :show-file-list="false"
+                   :on-change="changes"
+                   :file-list="filesArra2">
+          <el-button type="info" size="mini">点击上传</el-button>
+        </el-upload>
+        <div style="height: calc(100% - 80px);margin-top: 30px">
+          <vxe-table
+            style="margin-left: 5em"
+            border="inner"
+            auto-resize
+            resizable
+            height="500px"
+            :loading="loading"
+            size="small"
+            ref="projectTable"
+            show-header-overflow
+            show-overflow
+            highlight-hover-row
+            :menu-config="{}"
+            :print-config="{}"
+            @sort-change="sortChangeHandle"
+            :sort-config="{remote:true}"
+            :data="dataListNew"
+            :checkbox-config="{}">
+            <vxe-column type="seq" width="40"></vxe-column>
+            <vxe-column title="文件名称" field="name">
+              <template slot-scope="scope">
+                <!--                <div v-if="ifName(scope.row) === true">-->
+                <!--                  <el-image-->
+                <!--                    style="width: 100px; height: 100px"-->
+                <!--                    :src="src"-->
+                <!--                    :preview-src-list="srcList" lazy>-->
+                <!--                  </el-image>-->
+                <!--                </div>-->
+                <!--                <div v-else>-->
+                <!--                  <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>-->
+                <!--                </div>-->
+                <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
+              </template>
+            </vxe-column>
+            <vxe-column title="创建人" field="createBy"></vxe-column>
+            <vxe-column title="创建时间" field="createDate"></vxe-column>
+            <!--            <vxe-column title="文件描述" field="description"></vxe-column>-->
+            <vxe-column title="操作" width="200px" fixed="right" align="center">
+              <template  slot-scope="scope">
+                <el-button type="text"  icon="el-icon-edit" size="small" @click="toHref(scope.row)">下载</el-button>
+                <el-button type="text"  icon="el-icon-delete" size="small" @click="deleteMsgById(scope.row, scope.$rowIndex)">删除</el-button>
+              </template>
+            </vxe-column>
+          </vxe-table>
+        </div>
+
+      </el-form>
+      <el-image-viewer
+        v-if="showViewer"
+        :on-close="closeViewer"
+        :url-list="[url]"
+        zIndex="9999"/>
       </el-form>
       <span slot="footer" class="dialog-footer">
       <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
@@ -308,9 +373,18 @@
 
 <script>
   import ProjectService from '@/api/sys/ProjectService'
+  import OSSSerive, {
+    httpRequest,
+    handleRemove,
+    fileName
+  } from '@/api/sys/OSSService'
+  import moment from 'moment'
+  import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
   export default {
     data () {
       return {
+        dataList: [],
+        dataListNew: [],
         title: '',
         method: '',
         visible: false,
@@ -355,16 +429,76 @@
           assessBaseMessage: '',
           invoiceMessage: '',
           isCommissionReimbursement: '',
-          itemType: ''
-        }
+          itemType: '',
+          workAttachments: []
+        },
+        filesArra2: [],
+        fileList: [],
+        isFlag: true,
+        showViewer: false, // 显示查看器
+        url: '',
+        rowurl: '',
+        src: ''
       }
     },
+    components: { ElImageViewer },
     projectService: null,
+    ossService: null,
     created () {
+      this.ossService = new OSSSerive()
       this.projectService = new ProjectService()
     },
     methods: {
+      async toHref (row) {
+        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+        if (suffix === 'pdf' || suffix === 'txt') {
+          if (row.id === null || row.id === undefined || row.id === '') {
+            this.ossService.downLoadAttach(row.raw.url).then((res) => {
+              this.$utils.download(res.data, '项目导入模板')
+            })
+          } else {
+            this.ossService.downLoadAttach(row.url).then((res) => {
+              this.$utils.download(res.data, '项目导入模板')
+            })
+          }
+          return
+        }
+        console.log('rr', row)
+        const link = document.createElement('a')
+        link.setAttribute('download', row.name)
+        link.setAttribute('target', '_blank')
+        if (row.id === null || row.id === undefined || row.id === '') {
+          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
+            link.setAttribute('href', data.data)
+            link.click()
+          })
+        } else {
+          link.setAttribute('href', row.temporaryUrl)
+          link.click()
+        }
+      },
+      onPreview (url) {
+        this.url = url
+        this.showViewer = true
+      },
+      // 关闭查看器
+      closeViewer () {
+        this.url = ''
+        this.showViewer = false
+      },
       init (method, id) {
+        this.dataList = []
+        this.dataListNew = []
+        this.ossService.findFileList(id).then(({data}) => {
+          data.forEach((item) => {
+            item.name = item.attachmentName
+            // item.createBy = item.createBy
+            // item.createDate = item.createDate
+            // item.description = item.description
+            this.dataList.push(item)
+            this.dataListNew.push(item)
+          })
+        })
         this.method = method
         this.inputForm = {
           customerName: '',
@@ -419,6 +553,7 @@
         this.visible = true
         this.loading = false
         this.$nextTick(() => {
+          this.$refs.upload.clearFiles()
           this.$refs.inputForm.resetFields()
           if (method === 'edit' || method === 'view') { // 修改或者查看
             this.loading = true
@@ -440,6 +575,18 @@
           if (valid) {
             this.loading = true
             this.inputForm.itemType = '2'
+            console.log(this.dataListNew)
+            this.inputForm.workAttachments = []
+            this.dataListNew.forEach((item) => {
+              if (item.id === null || item.id === undefined || item.id === '') {
+                item.url = item.raw.url
+              }
+              item.attachmentFlag = 'projectRecords'
+              item.fileSize = item.size
+              item.attachmentName = item.name
+              this.inputForm.workAttachments.push(item)
+            })
+            console.log('workAttachments', this.inputForm.workAttachments)
             this.projectService.save(this.inputForm).then(({data}) => {
               this.close()
               this.$message.success(data)
@@ -454,6 +601,88 @@
       close () {
         this.$refs.inputForm.resetFields()
         this.visible = false
+      },
+      httpRequest (file) {
+        httpRequest(file, fileName(file), 'projectRecords')
+      },
+      handleRemove () {
+        this.fileList = handleRemove()
+      },
+      changes (file, fileList) {
+        console.log('file', file)
+        console.log('22', fileList)
+        this.dataListNew = []
+        this.dataList.forEach((item) => {
+          this.dataListNew.push(item)
+        })
+        fileList.forEach((item) => {
+          item.createDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
+          item.createBy = this.$store.state.user.name
+          this.dataListNew.push(item)
+        })
+        console.log('11', this.dataList)
+        console.log('33', this.dataListNew)
+        const isLt2M = file.size / 1024 / 1024 < 300
+        if (isLt2M === false) {
+          this.$message.error('文件大小不能超过 ' + 300 + 'M !')
+          this.fileList = []
+          this.filesArra2 = []
+        } else {
+          // if (exnameFix(file, '1') === false) {
+          //   this.fileList = []
+          //   this.filesArra2 = []
+          // }
+        }
+      },
+      async showFile (row) {
+        console.log('row', row)
+        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+        if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
+          if (row.url !== null && row.url !== undefined && row.url !== '') {
+            this.onPreview(row.url)
+            return
+          } else {
+            await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
+              this.onPreview(data.data)
+            })
+            return
+          }
+        }
+        if (row.url !== null && row.url !== undefined && row.url !== '') {
+          if (suffix === 'pdf') {
+            window.open('https://view.xdocin.com/xdoc?_xdoc=' + row.url, '_blank')
+          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
+            window.open('http://ow365.cn/?i=25008&furl=' + row.url, '_blank')
+          } else {
+            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + row.url, '_blank')
+          }
+        } else if (row.raw.url !== null && row.raw.url !== undefined && row.raw.url !== '') {
+          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
+            this.rowurl = data.data
+          })
+          if (suffix === 'pdf') {
+            window.open('https://view.xdocin.com/xdoc?_xdoc=' + this.rowurl, '_blank')
+          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
+            window.open('http://ow365.cn/?i=25008&furl=' + this.rowurl, '_blank')
+          } else {
+            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + this.rowurl, '_blank')
+          }
+        }
+      },
+      // 排序
+      sortChangeHandle (column) {
+        this.orders = []
+        if (column.order != null) {
+          this.orders.push({column: this.$utils.toLine(column.prop), asc: column.order === 'ascending'})
+        }
+        this.refreshList()
+      },
+      deleteMsgById (row, index) {
+        console.log(index)
+        this.dataListNew.splice(index, 1)
+        if (row.id !== null && row.id !== '' && row.id !== undefined) {
+          this.ossService.deleteMsgById(row.id)
+        }
       }
     }
   }