Sfoglia il codice sorgente

Merge branch 'test'

jinx 3 anni fa
parent
commit
7565f6b863
1 ha cambiato i file con 23 aggiunte e 11 eliminazioni
  1. 23 11
      src/page/invoice/index.vue

+ 23 - 11
src/page/invoice/index.vue

@@ -227,6 +227,7 @@ export default {
 
   data () {
     return {
+      status: 0,
       dialogVisible: false,
       fileVal: '',
       tableHeader,
@@ -452,14 +453,14 @@ export default {
     },
     _exportExcelForOrder () {
       let date1, date2, userName, expressNum, orderNum
-      this.date1 = this.searchDate ? this.searchDate[0] : null
-      this.date2 = this.searchDate ? this.searchDate[1] : null
-      date1 = this.date1 ? (this.date1 + ' 00:00:00') : null
-      date2 = this.date2 ? (this.date2 + ' 23:59:59') : null
+      this.date1 = this.searchDate ? this.searchDate[0] : ''
+      this.date2 = this.searchDate ? this.searchDate[1] : ''
+      date1 = this.date1 ? (this.date1 + ' 00:00:00') : ''
+      date2 = this.date2 ? (this.date2 + ' 23:59:59') : ''
 
-      this.userName = userName = this.searchPhone || null
-      this.expressNum = expressNum = this.searchExpressNum || null
-      this.orderNum = orderNum = this.searchOrderNumber || null
+      this.userName = userName = this.searchPhone || ''
+      this.expressNum = expressNum = this.searchExpressNum || ''
+      this.orderNum = orderNum = this.searchOrderNumber || ''
 
       let data = {
         'type': this.status,
@@ -478,14 +479,25 @@ export default {
       }).then(async () => {
         let exec = await this.$http({
           methods: 'get',
-          params: data,
-          url: '/manager/order/export',
+          url: `/manager/order/export?type=${this.status}&startDate=${date1}&endDate=${date2}&orderSn=${orderNum}&phoneNum=${this.userName}&expressNum=${expressNum}`,
           responseType: 'arraybuffer'
         })
+
         try {
           let blob = new Blob([exec], {type: 'application/vnd.ms-excel'})
-          let url = URL.createObjectURL(blob)
-          location.href = url
+          let href = URL.createObjectURL(blob)
+          console.log(href)
+          // location.href = url
+
+          // 谷歌浏览器 创建a标签 添加download属性下载
+          const downloadElement = document.createElement('a')
+          downloadElement.href = href
+          downloadElement.target = '_blank'
+          downloadElement.download = new Date().getTime() + '.xls'
+          document.body.appendChild(downloadElement)
+          downloadElement.click() // 点击下载
+          document.body.removeChild(downloadElement) // 下载完成移除元素
+          window.URL.revokeObjectURL(href) // 释放掉blob对象
         } catch (e) {
           console.error(e)
         }