Browse Source

fix:"优化按月统计功能"

soobin 10 months ago
parent
commit
57d098b566
1 changed files with 17 additions and 26 deletions
  1. 17 26
      src/components/dateSelectList/index.vue

+ 17 - 26
src/components/dateSelectList/index.vue

@@ -24,6 +24,7 @@
         </van-popup>
         <!-- 按月统计 -->
         <van-popup v-model:show="monthDateShow" position="bottom">
+          <!-- 
           <van-picker-group :title="$t('dateSelectList.monthDate')"
             :tabs="[$t('dateSelectList.monthStartDate'), $t('dateSelectList.monthEndDate')]"
             :next-step-text="$t('dateSelectList.nextStep')" @confirm="monthDateConfirm" @cancel="monthDateCancel"
@@ -31,6 +32,9 @@
             <van-date-picker v-model="monthStartDate" :min-date="minDate" :columns-type="monthDateType" />
             <van-date-picker v-model="monthEndDate" :min-date="minDate" :columns-type="monthDateType" />
           </van-picker-group>
+          -->
+          <van-date-picker v-model="monthDate" title="选择年月" :min-date="minDate" :max-date="maxDate" @confirm="monthDateConfirm" @cancel="monthDateCancel"
+            :columns-type="monthDateType" />
         </van-popup>
       </div>
     </div>
@@ -41,7 +45,7 @@
 import { ref } from "vue";
 import dateUtil from "@/utils/dateUtil";
 import { getLoginUser } from "@/common/js/utils";
-import { showToast } from "vant";
+// import { showToast } from "vant";
 import { useI18n } from 'vue-i18n';
 
 
@@ -49,7 +53,8 @@ export default {
   name: "dateSelectList",
   components: {},
   setup(props, { emit }) {
-    const minDate = new Date(2018, 1, 1);
+    const minDate = new Date(2022, 0, 1);
+    const maxDate = new Date();
     const { t } = useI18n();
     const user = getLoginUser();
     // 时间类型
@@ -169,16 +174,16 @@ export default {
             dateUtil.formateDate(endTime, "yyyy-MM-dd") + " 23:59:59";
         } else {
           // 按月统计
-          params.chartType = "year";
-          startTime = new Date(monthStartDate.value[0] + '-' + monthStartDate.value[1] + '-01');
-          endTime = new Date(monthEndDate.value[0] + '-' + monthEndDate.value[1] + '-01');
+          params.chartType = "month";
+          startTime = new Date(monthDate.value[0] + '-' + monthDate.value[1] + '-01');
+          endTime = new Date(monthDate.value[0], monthDate.value[1], 0);
+          // endTime = new Date(monthEndDate.value[0] + '-' + monthEndDate.value[1] + '-01');
           console.log("startTime", startTime);
           console.log("endTime", endTime);
-          endTime.setMonth(endTime.getMonth() + 1);
           params.startDate =
             dateUtil.formateDate(startTime, "yyyy-MM-dd") + " 00:00:00";
           params.endDate =
-            dateUtil.formateDate(endTime, "yyyy-MM-dd") + " 00:00:00";
+            dateUtil.formateDate(endTime, "yyyy-MM-dd") + " 23:59:59";
           timeTypeShow.value = false;
         }
 
@@ -213,33 +218,18 @@ export default {
     const monthDateShow = ref(false);
     const monthStartDate = ref([currentYear, currentMonth]);
     const monthEndDate = ref([currentYear, currentMonth]);
+    const monthDate = ref([currentYear, currentMonth]);
     const monthDateType = ['year', 'month'];
     const monthDateConfirm = () => {
-      console.log('monthStartDate', monthStartDate.value);
-      console.log('monthEndDate', monthEndDate.value);
-      const date1 = new Date(monthStartDate.value[0] + '-' + monthStartDate.value[1] + '-01');
-      const date2 = new Date(monthEndDate.value[0] + '-' + monthEndDate.value[1] + '-01');
-      // 将日期对象转换为毫秒数
-      const time1 = date1.getTime();
-      const time2 = date2.getTime();
-      // 计算时间跨度的绝对值
-      const timeDiff = Math.abs(time1 - time2);
-      // 计算半年的毫秒数(假设半年为 365 天的一半)
-      const halfYearInMilliseconds = 365 * 24 * 60 * 60 * 1000 / 2;
-      if (timeDiff > halfYearInMilliseconds) {
-        showToast(t('dateSelectList.monthTip1'));
-        return;
-      }
-      if (date1 > date2) {
-        showToast(t('dateSelectList.monthTip2'));
-        return;
-      }
+      const date1 = new Date(monthDate.value[0], monthDate.value[1], 0);
+      console.log('date1', date1);
       monthDateShow.value = false;
       outputDate();
     }
     const monthDateCancel = () => { monthDateShow.value = false; }
     return {
       minDate,
+      maxDate,
       timeType,
       timeChange,
       calendarShow,
@@ -254,6 +244,7 @@ export default {
       monthEndDate,
       monthDateConfirm,
       monthDateCancel,
+      monthDate,
     };
   },
 };