Jelajahi Sumber

导出修改

1004749546@qq.com 4 tahun lalu
induk
melakukan
23305e5264
1 mengubah file dengan 38 tambahan dan 48 penghapusan
  1. 38 48
      src/views/shop/shopOrder.vue

+ 38 - 48
src/views/shop/shopOrder.vue

@@ -40,18 +40,18 @@
           </a-col>
           <a-col :span="18">
             <a-button class="handle-btn btn-right" id="shopOrder-btn-serach" type="primary" @click="$refs.table.refresh(true)">查询</a-button>
-			<a-button class="handle-btn btn-right" type="" id="shopOrder-btn-reset" @click="handleReset">重置</a-button>
+            <a-button class="handle-btn btn-right" type="" id="shopOrder-btn-reset" @click="handleReset">重置</a-button>
             <a-button
               v-if="$hasPermissions('B_orderManage_export')"
               class="export-btn"
               id="shopOrder-btn-export"
               :loading="loading"
               @click="handleExport">导出订单</a-button>
-			<a-button
-			  class="export-btn"
-			  id="shopOrder-btn-exportDetail"
-			  :loading="loadingDetail"
-			  @click="handleOrderExport">导出订单明细</a-button>
+            <a-button
+              class="export-btn"
+              id="shopOrder-btn-exportDetail"
+              :loading="loadingDetail"
+              @click="handleOrderExport">导出订单明细</a-button>
           </a-col>
         </a-row>
       </a-form>
@@ -81,7 +81,7 @@
 import { STable, VSelect } from '@/components'
 import getDate from '@/libs/getDate.js'
 import moment from 'moment'
-import { orderList, orderExport,orderDetailExport } from '@/api/order'
+import { orderList, orderExport, orderDetailExport } from '@/api/order'
 export default {
   name: 'ShopOrder',
   components: { STable, VSelect },
@@ -187,62 +187,52 @@ export default {
       // 判断两个时间段是否相差m个月  第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
       if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 3) {
         this.$message.error('单次最多只能导出3个月的数据,请缩小查询区间后再进行导出!')
-		return
+        return
       }
       this.loading = true
       orderExport(params).then(res => {
         this.loading = false
-        this.download(res)
+        const frname = '订单记录-'
+        this.download(res, frname)
       })
     },
-    download (data) {
+    // 导出订单明细
+    handleOrderExport () {
+      const params = {
+        beginDate: this.queryParam.beginDate == null ? getDate.getToday().starttime : this.queryParam.beginDate,
+        endDate: this.queryParam.endDate == null ? getDate.getToday().endtime : this.queryParam.endDate,
+        customerMobile: this.queryParam.customerMobile,
+        orderSn: this.queryParam.orderSn,
+        orderState: this.queryParam.orderState
+      }
+      if (!params.beginDate && !params.endDate) {
+        this.$message.error('请先选择下单时间后查询并导出!')
+        return
+      }
+      // 判断两个时间段是否相差m个月  第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
+      if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 3) {
+        this.$message.error('仅支持导出最多3个月数据,请先修改下单时间再进行导出!')
+        return
+      }
+      this.loadingDetail = true
+      orderDetailExport(params).then(res => {
+        this.loadingDetail = false
+        const frname = '订单商品明细-'
+        this.download(res, frname)
+      })
+    },
+    download (data, frname) {
       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
+      const fname = frname + a
       link.setAttribute('download', fname + '.xlsx')
       document.body.appendChild(link)
       link.click()
-    },
-		// 导出订单明细
-		handleOrderExport () {
-			const params = {
-				beginDate: this.queryParam.beginDate == null ? getDate.getToday().starttime : this.queryParam.beginDate,
-				endDate: this.queryParam.endDate == null ? getDate.getToday().endtime : this.queryParam.endDate,
-				customerMobile: this.queryParam.customerMobile,
-				orderSn: this.queryParam.orderSn,
-				orderState: this.queryParam.orderState
-			}
-			if (!params.beginDate && !params.endDate) {
-				this.$message.error('请先选择下单时间后查询并导出!')
-				return
-			}
-			// 判断两个时间段是否相差m个月  第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
-			if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 3) {
-				this.$message.error('仅支持导出最多3个月数据,请先修改下单时间再进行导出!')
-				return
-			}
-			this.loadingDetail = true
-			orderDetailExport(params).then(res => {
-				this.loadingDetail = false
-				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()
-		}
+    }
   }
 }
 </script>