liyg 2 years ago
parent
commit
09680f2b63
1 changed files with 25 additions and 1 deletions
  1. 25 1
      src/views/statisticalReport/components/Ship_dynamic_table.vue

+ 25 - 1
src/views/statisticalReport/components/Ship_dynamic_table.vue

@@ -16,13 +16,17 @@
         <el-button type="primary" class="btn" @click="getPdfs()">
           <i class="el-icon-download"></i>下载PDF
         </el-button>
+         <el-button type="primary" class="btn" @click="getExcel('船舶动态')">
+          <i class="el-icon-download"></i>下载Excel
+        </el-button>
       </div>
-      <table-item :tableData="tableData" :col="col" id="pdfDom"> </table-item>
+      <table-item ref="ship" :tableData="tableData" :col="col" id="pdfDom"> </table-item>
     </div>
   </div>
 </template>
 <script>
 import tableItem from "./tableItem";
+import FileSaver from "file-saver";
 export default {
   name: "TableView",
   components: {
@@ -170,6 +174,26 @@ export default {
           }
         });
     },
+    getExcel(tableTitle) {
+        //let tables = this.$refs.ship;//此处是拿表格document元素,也可以取父div的ref
+        let tables = document.getElementById("pdfDom");
+        let table_book = XLSX.utils.table_to_book(tables);
+        console.log("table_book:",table_book);
+        var table_write = XLSX.write(table_book, {
+            bookType: "xlsx",
+            bookSST: true,
+            type: "array"
+        });
+        try {
+            FileSaver.saveAs(
+                new Blob([table_write], { type: "application/octet-stream" }),
+                tableTitle+".xlsx"
+            );
+        } catch (e) {
+            if (typeof console !== "undefined") console.log(e, table_write);
+        }
+        return table_write;
+    },
     initialization() {
       this.axios.post("/api/v1/tms/selectAllShipDynamaics").then(res => {
         if (res.data.code == "200") {