Browse Source

前端代码合并提交

Administrator 2 years ago
parent
commit
c993a1e3dd
2 changed files with 58 additions and 43 deletions
  1. 1 1
      src/config/globle.js
  2. 57 42
      src/views/noCar/mothaccount.vue

+ 1 - 1
src/config/globle.js

@@ -1,3 +1,3 @@
 window.hostUrl = "http://invoice.jkcredit.com:80/";
 //window.hostUrl = "http://127.0.0.1:18081/"
-window.tableHeight =  (document.body.clientHeight*0.6-20);
+window.tableHeight =  (document.body.clientHeight*0.6-20);

+ 57 - 42
src/views/noCar/mothaccount.vue

@@ -79,6 +79,7 @@
     </div>
 </template>
 <script type="text/javascript">
+import CsvExportor from "csv-exportor";
 import FileSaver from "file-saver";
 import XLSX from "xlsx";
       export default {
@@ -157,48 +158,62 @@ import XLSX from "xlsx";
             }
           },
        async     exportExcel() {
-       const loading = this.$loading({
-                             lock: true,
-                             text: '系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...',
-                             spinner: 'el-icon-loading',
-                             background: 'rgba(0, 0, 0, 0.7)'
-                           });
-         let curr = this.current;
-      let pagesize1 = this.pagesize;
-      this.current = 1;
-      this.pagesize = this.total;
-      await this.loadData();
-      // 设置当前日期
-      let time = new Date();
-      let year = time.getFullYear();
-      let month = time.getMonth() + 1;
-      let day = time.getDate();
-      let name = "无车红冲发票查询列表_"+year + "" + month + "" + day;
-      /* generate workbook object from table */
-      //  .table要导出的是哪一个表格
-      var wb = XLSX.utils.table_to_book(document.querySelector(".table"),{ raw: true });
-      this.formartNum(wb);
-      /* get binary string as output */
-      var wbout = XLSX.write(wb, {
-        bookType: "xlsx",
-        bookSST: true,
-        type: "array"
-      });
-      try {
-        //  name+'.xlsx'表示导出的excel表格名字
-        FileSaver.saveAs(
-          new Blob([wbout], { type: "application/octet-stream" }),
-          name + ".xlsx"
-        );
-      } catch (e) {
-        if (typeof console !== "undefined") console.log(e, wbout);
-      }
-       this.current = curr;
-      this.pagesize = pagesize1;
-      this.loadData();
-      loading.close();
-      return wbout;
-    },
+        const loading = this.$loading({
+                              lock: true,
+                              text: '系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...',
+                              spinner: 'el-icon-loading',
+                              background: 'rgba(0, 0, 0, 0.7)'
+                            });
+        const response = await this.$http.post('noCarService/monthAccQueryAll');
+        
+        if (response.data.code === 0) {
+            let recodes = response.data.data;
+            let time = new Date();
+            let year = time.getFullYear();
+            let month = time.getMonth() + 1;
+            let day = time.getDate();
+            let name = "无车月账单_"+year + "" + month + "" + day;
+            let cloums = [
+               {"title":"企业名称","key":"companyName"},
+               {"title":"购方名称","key":"buyerName"},
+               {"title":"购方税号","key":"buyerTaxpayerCode"},
+               {"title":"运单编号","key":"waybillNum"},
+               {"title":"交易id","key":"tradeId"},
+               {"title":"入口站名","key":"enStation"},
+               {"title":"出口站名","key":"exStation"},
+               {"title":"交易时间","key":"exTime"},
+               {"title":"交易金额","key":"fee"},
+            ];
+             this.exportExcelComm(cloums,recodes,name,loading);
+
+        }
+      },
+       formatJson (filterVal, jsonData) {
+            return jsonData.map(v => filterVal.map(j => {
+              if(j =='fee'){
+                  return v[j]/100;
+              }else if(j=='waybillNum' || j=='buyerTaxpayerCode'){
+                 return v[j]+'\t';
+              }else{
+                  return v[j];
+              }
+              
+              }));
+          },
+          // 导出Excel
+          exportExcelComm(columns,list,excelName,loading){
+                  let tHeader = []
+                      let filterVal = []
+                      columns.forEach(item =>{
+                          tHeader.push(item.title)
+                          filterVal.push(item.key)
+                      })
+                     
+                     const data = this.formatJson(filterVal,list);
+                      data.unshift(tHeader);
+                     CsvExportor.downloadCsv(data, { tHeader }, excelName+".csv");
+                      loading.close();
+            }
         }
       };
 </script>