浏览代码

已购套餐 校验单次最多只能导出3个月的数据

chenrui 4 年之前
父节点
当前提交
fb89fc487d
共有 2 个文件被更改,包括 35 次插入28 次删除
  1. 24 0
      src/libs/tools.js
  2. 11 28
      src/views/SetmealSales/PurchasedSetmeal.vue

+ 24 - 0
src/libs/tools.js

@@ -173,6 +173,30 @@ export const formatSubmitDate = (val, type) => {
     else return _year + '-' + _montn + '-' + _day
   }
 }
+
+// 判断两个时间段是否相差m个月  time1,time2均为日期类型,time1为前时间,time2为后时间
+export const completeDate = function (times1, times2, m) {
+  const time1 = new Date(times1)
+  const time2 = new Date(times2)
+  var diffyear = time2.getFullYear() - time1.getFullYear()
+  var diffmonth = diffyear * 12 + time2.getMonth() - time1.getMonth()
+  if (diffmonth < 0) {
+    return false
+  }
+  var diffDay = time2.getDate() - time1.getDate()
+  if (diffmonth < m || (diffmonth == m && diffDay <= 0)) {
+    if (diffmonth == m && diffDay == 0) {
+      var timeA = time1.getHours() * 3600 + 60 * time1.getMinutes() + time1.getSeconds()
+      var timeB = time2.getHours() * 3600 + 60 * time2.getMinutes() + time2.getSeconds()
+      if (timeB - timeA > 0) {
+        return false
+      }
+    }
+    return true
+  }
+  return false
+}
+
 // 正则验证车牌,验证通过返回true,不通过返回false
 export const isLicensePlate = function (str) {
   return /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(str)

+ 11 - 28
src/views/SetmealSales/PurchasedSetmeal.vue

@@ -85,6 +85,7 @@
 <script>
 import { STable, VSelect } from '@/components'
 import getDate from '@/libs/getDate.js'
+import { completeDate } from '@/libs/tools.js'
 import {
   itemList,
   storeList,
@@ -148,7 +149,6 @@ export default {
           }
         })
       }
-      // nowBeginDate: '' //  下单时间 当前操作的开始时间
     }
   },
   methods: {
@@ -160,28 +160,8 @@ export default {
     },
     // 不可选日期
     disabledDate (date, dateStrings) {
-      // if (this.nowBeginDate) { //  有下单时间开始时间时
-      //   const bVal = this.getThreeMonthsAfter(this.nowBeginDate, -3) //  三个月前时间戳
-      //   const eVal = this.getThreeMonthsAfter(this.nowBeginDate, 3) //  三个月后时间戳
-      //   if (Date.now() < eVal) { //  当前日期距起始日期不足三个月
-      //     return date && date.valueOf() < bVal || date && date.valueOf() > Date.now()
-      //   } else {
-      //     return date && date.valueOf() < bVal || date && date.valueOf() > eVal
-      //   }
-      // } else {
-      //   return date && date.valueOf() > Date.now()
-      // }
       return date && date.valueOf() > Date.now()
     },
-    //  获取month个月后的时间戳
-    // getThreeMonthsAfter (dtstr, month) {
-    //   var s = dtstr.split('-')
-    //   var yy = parseInt(s[0])
-    //   var mm = parseInt(s[1])
-    //   var dd = parseInt(s[2])
-    //   var dt = new Date(yy, mm + Number(month) - 1, dd)
-    //   return dt.valueOf()
-    // },
     //  购买套餐
     goBuy () {
       this.$router.push({ path: '/SetmealSales/BuySetmeal' })
@@ -273,7 +253,7 @@ export default {
     },
     // 导出
     handleExport () {
-      this.loading = true
+      // this.loading = true
       const params = {
         beginDate: this.searchForm.beginDate == null ? getDate.getToday().starttime : this.searchForm.beginDate,
         endDate: this.searchForm.endDate == null ? getDate.getToday().endtime : this.searchForm.endDate,
@@ -283,12 +263,15 @@ export default {
         customerMobile: this.searchForm.customerMobile,
         orderStatus: this.searchForm.orderStatus
       }
-      console.log(params, '---导出提交数据')
-      // exportOrder(params).then(res => {
-      //   console.log(res)
-      //   this.loading = false
-      //   this.download(res)
-      // })
+      if (!completeDate(params.beginDate, params.endDate, 3)) {
+        this.$message.error('单次最多只能导出3个月的数据,请缩小查询区间后再进行导出!')
+        return
+      }
+      exportOrder(params).then(res => {
+        console.log(res)
+        this.loading = false
+        this.download(res)
+      })
     },
     download (data) {
       if (!data) {