Browse Source

销售列表导出功能

chenrui 3 năm trước cách đây
mục cha
commit
836097ba54
2 tập tin đã thay đổi với 59 bổ sung5 xóa
  1. 11 2
      src/api/sales.js
  2. 48 3
      src/views/salesManagement/salesQuery/list.vue

+ 11 - 2
src/api/sales.js

@@ -134,7 +134,7 @@ export const supperCodeByVin = (params) => {
 // 销售 详情  打印
 export const salesDetailPrint = params => {
   return axios.request({
-    url: `sales/print/${params.sn}/${params.type}`,
+    url: `/sales/print/${params.sn}/${params.type}`,
     method: 'get',
     responseType: 'blob'
   })
@@ -142,8 +142,17 @@ export const salesDetailPrint = params => {
 // 销售 详情  导出
 export const salesDetailExport = params => {
   return axios.request({
-    url: `sales/excel/${params.sn}`,
+    url: `/sales/excel/${params.sn}`,
     method: 'get',
     responseType: 'blob'
   })
 }
+// 销售 列表  导出
+export const salesExport = params => {
+  return axios.request({
+    url: `/sales/exportWithDetail`,
+    data: params,
+    method: 'post',
+    responseType: 'blob'
+  })
+}

+ 48 - 3
src/views/salesManagement/salesQuery/list.vue

@@ -61,8 +61,15 @@
             <a-col :md="6" :sm="24">
               <span class="table-page-search-submitButtons">
                 <a-button type="primary" :disabled="disabled" @click="$refs.table.refresh(true)">查询</a-button>
-                <a-button style="margin-left: 8px" :disabled="disabled" @click="resetSearchForm()">重置</a-button>
-                <a @click="advanced=!advanced" style="margin-left: 8px">
+                <a-button style="margin-left: 5px" :disabled="disabled" @click="resetSearchForm()">重置</a-button>
+                <a-button
+                  type="primary"
+                  class="button-warning"
+                  @click="handleExport"
+                  :disabled="disabled"
+                  :loading="exportLoading"
+                  id="salesManagementList-export">导出</a-button>
+                <a @click="advanced=!advanced" style="margin-left: 5px">
                   {{ advanced ? '收起' : '展开' }}
                   <a-icon :type="advanced ? 'up' : 'down'"/>
                 </a>
@@ -168,10 +175,11 @@
 </template>
 
 <script>
+import moment from 'moment'
 import { STable, VSelect } from '@/components'
 import chooseCustomModal from './chooseCustomModal.vue'
 import auditModal from '@/views/common/auditModal.vue'
-import { salesList, salesDel, salesWriteAudit, salesWriteStockOut, salesCount } from '@/api/sales'
+import { salesList, salesDel, salesWriteAudit, salesWriteStockOut, salesCount, salesExport } from '@/api/sales'
 import { settleStyleQueryAll } from '@/api/settleStyle'
 import rangeDate from '@/views/common/rangeDate.vue'
 import custList from '@/views/common/custList.vue'
@@ -184,6 +192,7 @@ export default {
       tableHeight: 0,
       advanced: true, // 高级搜索 展开/关闭
       disabled: false, //  查询、重置按钮是否可操作
+      exportLoading: false, // 导出loading
       openModal: false, // 选择客户弹框是否显示
       settleStyleList: [], // 收款方式
       // 查询参数
@@ -359,6 +368,42 @@ export default {
       this.$refs.custList.resetForm()
       this.$refs.table.refresh(true)
     },
+    //  导出
+    handleExport () {
+      const _this = this
+      const params = this.queryParam
+      this.exportLoading = true
+      _this.spinning = true
+      salesExport(params).then(res => {
+        this.exportLoading = false
+        _this.spinning = false
+        if (res.type == 'application/json') {
+          var reader = new FileReader()
+          reader.addEventListener('loadend', function () {
+            const obj = JSON.parse(reader.result)
+            _this.$notification.error({
+              message: '提示',
+              description: obj.message
+            })
+          })
+          reader.readAsText(res)
+        } else {
+          this.download(res)
+        }
+      })
+    },
+    download (data) {
+      if (!data) { return }
+      const url = window.URL.createObjectURL(new Blob([data]))
+      const link = document.createElement('a')
+      link.style.display = 'none'
+      link.href = url
+      const a = moment().format('YYYYMMDDHHmmss')
+      const fname = '销售列表' + a
+      link.setAttribute('download', fname + '.xlsx')
+      document.body.appendChild(link)
+      link.click()
+    },
     // 获取收款方式
     getSettleStyle () {
       settleStyleQueryAll().then(res => {