浏览代码

默认日期

QuKatie 3 年之前
父节点
当前提交
f09414e573
共有 2 个文件被更改,包括 38 次插入4 次删除
  1. 25 1
      src/util/date.js
  2. 13 3
      src/views/exportTrade/customerInquiry/index.vue

+ 25 - 1
src/util/date.js

@@ -43,9 +43,33 @@ export function dateFormat(date, format) {
       if (new RegExp("(" + k + ")").test(format))
         format = format.replace(RegExp.$1,
           RegExp.$1.length === 1 ? o[k] :
-            ("00" + o[k]).substr(("" + o[k]).length));
+          ("00" + o[k]).substr(("" + o[k]).length));
     return format;
   }
   return '';
 
 }
+/**
+ * 获取上月第一天和下月最后一天
+ * type 1为 [yyyy-MM-dd,yyyy-MM-dd]
+ * type 2为 [yyyy-MM-dd 00:00:00,yyyy-MM-dd 23:59:59]
+ * type为空默认2
+ */
+export function defaultDate(type) {
+  type = type ? type : 2
+  const date = new Date();
+  const startDate = new Date(date.getFullYear(), date.getMonth() - 1, 1);
+  const endDate = new Date(date.getFullYear(), date.getMonth() + 2, 0);
+  console.log(dateFormat(startDate, "yyyy-MM-dd"))
+  if (type == 1) {
+    return [
+      dateFormat(startDate, "yyyy-MM-dd"),
+      dateFormat(endDate, "yyyy-MM-dd")
+    ];
+  } else {
+    return [
+      dateFormat(startDate, "yyyy-MM-dd") + " 00:00:00",
+      dateFormat(endDate, "yyyy-MM-dd") + " 23:59:59"
+    ];
+  }
+}

+ 13 - 3
src/views/exportTrade/customerInquiry/index.vue

@@ -15,6 +15,7 @@
         @on-load="onLoad"
         :table-loading="loading"
         @saveColumn="saveColumn"
+        :cell-style="cellStyle"
       >
         <template slot="portOfLoadSearch">
           <port-info v-model="search.portOfLoad" />
@@ -87,6 +88,7 @@
 import option from "./config/mainList.json";
 import { getList, remove } from "@/api/basicData/customerInquiry";
 import detailPage from "./detailsPage.vue";
+import { defaultDate } from "@/util/date";
 export default {
   name: "customerInformation",
   data() {
@@ -115,6 +117,7 @@ export default {
   },
   components: { detailPage },
   async created() {
+    this.search.businesDate=defaultDate()
     /**
      * 已定义全局方法,直接使用,getColumnData获取列数据,参数传值(表格名称,引入的本地JSON的数据定义的名称)
      * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
@@ -142,6 +145,9 @@ export default {
     });
   },
   methods: {
+    cellStyle() {
+      return "padding:0;height:40px;";
+    },
     //删除列表后面的删除按钮触发触发(row, index, done)
     rowDel(row, index, done) {
       this.$confirm("确定删除数据?", {
@@ -192,15 +198,19 @@ export default {
       this.page.pageSize = val;
     },
     onLoad(page, params) {
+      if (this.search.businesDate.length>0) {
+        params={
+          orderStartDate:this.search.businesDate[0],
+          orderEndDate:this.search.businesDate[1],
+        }
+      }
       this.loading = true;
       getList(page.currentPage, page.pageSize, params)
         .then(res => {
           this.dataList = res.data.data.records ? res.data.data.records : [];
           this.page.total = res.data.data.total;
           if (this.page.total) {
-            this.option.height = window.innerHeight - 380;
-          } else {
-            this.option.height = window.innerHeight - 305;
+            this.option.height = window.innerHeight - 420;
           }
         })
         .finally(() => {