From 9697dfd0004335bab3bf5626425eab3130a55ec6 Mon Sep 17 00:00:00 2001
From: zhangxiaoxu <819527061@qq.com>
Date: 星期三, 17 六月 2026 17:53:16 +0800
Subject: [PATCH] 根据时间段查询发运和煤种

---
 pages/home/home.vue |  253 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 237 insertions(+), 16 deletions(-)

diff --git a/pages/home/home.vue b/pages/home/home.vue
index 2e7ff38..d6d7bb4 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -86,12 +86,19 @@
         </view>
       </view>
       <!-- 鐓ょ鍙戣繍鎯呭喌 -->
-      <view class="shoukuan-group" v-if="coalTongjiTemp && coalTongjiTemp.length > 0">
+      <view class="shoukuan-group" v-if="coalLoaded || coalLoading">
         <view class="currentDay-box">
           <combined-title title="鐓ょ鍙戣繍鎯呭喌">
           </combined-title>
+          <view class="date-pick-box" @click="openCoalCalendar">
+            <text class="date-pick-text">{{coalRangeText}}</text>
+            <image class="date-pick-icon" src="@/static/home/dateIcon.png"></image>
+          </view>
         </view>
-        <view class="shoukuan-box">
+        <view class="block-loading" v-if="coalLoading">
+          <u-loading-icon mode="circle" color="#1987FF" size="40"></u-loading-icon>
+        </view>
+        <view class="shoukuan-box" v-if="coalLoaded && !coalLoading">
           <view class="coalFayun-total">
             <view class="total-block">
               <view class="num">{{d2Sum || 0}}</view>
@@ -159,13 +166,20 @@
         </view>
       </view>
       <!-- 鍒嗗鎴风叅绉嶅彂杩愭儏鍐� -->
-      <view class="shoukuan-group" v-if="kehuTongjiTemp && kehuTongjiTemp.length > 0">
+      <view class="shoukuan-group" v-if="kehuLoaded || kehuLoading">
         <view class="currentDay-box">
           <combined-title title="鍒嗗鎴风叅绉嶅彂杩愭儏鍐�">
           </combined-title>
+          <view class="date-pick-box" @click="openKehuCalendar">
+            <text class="date-pick-text">{{kehuRangeText}}</text>
+            <image class="date-pick-icon" src="@/static/home/dateIcon.png"></image>
+          </view>
         </view>
 
-        <view class="shoukuan-box">
+        <view class="block-loading" v-if="kehuLoading">
+          <u-loading-icon mode="circle" color="#1987FF" size="40"></u-loading-icon>
+        </view>
+        <view class="shoukuan-box" v-if="kehuLoaded && !kehuLoading">
           <div class="shoukuan-box-inside">
             <view class="shoukuan-main" v-for="(item,index) in kehuTongji" :key="index">
               <view class="shoukuan-line">
@@ -182,7 +196,7 @@
               </view>
               <view class="shoukuan-line">
                 <view class="name">璐﹀锛�</view>
-                <view class="text1">{{item.ledgerName}}</view>
+                <view class="text1">{{item.ledgerName || ''}}</view>
               </view>
 <!--              <view class="coalTongji-box">
                 <view class="shoukuan-line kehu-block">
@@ -551,6 +565,42 @@
 		</view>
 		<u-gap height="60" bgColor="#eeeeee"></u-gap>
 
+    <!-- 鐓ょ鍙戣繍鎯呭喌 鏃堕棿娈甸�夋嫨 -->
+    <u-calendar
+        :key="'coal-' + coalCalendarKey"
+        rowHeight="100"
+        :show="coalCalendarShow"
+        mode="range"
+        :defaultDate="coalDefaultDate"
+        :minDate="minDateTimestamp"
+        :maxDate="maxDateTimestamp"
+        :monthNum="calendarMonthNum"
+        allowSameDay
+        title="閫夋嫨鏃堕棿娈�"
+        startText="寮�濮�"
+        endText="缁撴潫"
+        @confirm="coalCalendarConfirm"
+        @close="coalCalendarShow = false"
+    ></u-calendar>
+
+    <!-- 鍒嗗鎴风叅绉嶅彂杩愭儏鍐� 鏃堕棿娈甸�夋嫨 -->
+    <u-calendar
+        :key="'kehu-' + kehuCalendarKey"
+        rowHeight="100"
+        :show="kehuCalendarShow"
+        mode="range"
+        :defaultDate="kehuDefaultDate"
+        :minDate="minDateTimestamp"
+        :maxDate="maxDateTimestamp"
+        :monthNum="calendarMonthNum"
+        allowSameDay
+        title="閫夋嫨鏃堕棿娈�"
+        startText="寮�濮�"
+        endText="缁撴潫"
+        @confirm="kehuCalendarConfirm"
+        @close="kehuCalendarShow = false"
+    ></u-calendar>
+
     <view class="passWord-main-box">
       <u-popup :show="passShow"
                :closeable="true"
@@ -641,7 +691,77 @@
 		},
 		shenqingMenu() {
 			return this.$store.state.shenqingMenu;
-		}
+		},
+    // 褰撳ぉ鏃ユ湡(YYYY-MM-DD)
+    todayStr() {
+      return this.todayDate();
+    },
+    // 榛樿鏃堕棿浣跨敤鐢ㄤ竴澶╃殑鏃ユ湡(YYYY-MM-DD 23:59:59)
+    endTodaydayStr() {  //榛樿鏃堕棿浣跨敤鐢ㄤ竴澶╃殑鏃ユ湡
+      // const date = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
+      const date = new Date(new Date().getTime());
+      const y = date.getFullYear();
+      let m = date.getMonth() + 1;
+      m = m < 10 ? '0' + m : m;
+      let d = date.getDate();
+      d = d < 10 ? '0' + d : d;
+      let time = `${y}-${m}-${d} 23:59:59`
+      return time;
+    },
+    // 榛樿璧峰鏃堕棿(褰撳ぉ 00:00:00)銆傛敞鎰� todayStr 鏄� computed(鍙栧�肩敤 this.todayStr,涓嶈兘鍔犳嫭鍙峰綋鍑芥暟璋�)
+    startTodayStr() {
+      return `${this.todayStr}`;
+    },
+    // 鍙�夋渶鏃╂棩鏈�:褰撳墠鏃ユ湡寰�鍓嶆帹 1 骞�(鍘诲勾鍚屾湀),鍏佽缈诲埌涓婁竴骞寸殑鍘嗗彶鏈堜唤
+    minDateTimestamp() {
+      const d = new Date();
+      d.setFullYear(d.getFullYear() - 1);
+      return d.getTime();
+    },
+    // 鍙�夋渶鏅氭棩鏈�:褰撳墠鏃ユ湡寰�鍚庢帹 1 骞�(鏄庡勾鍚屾湀)(u-calendar 瑕佹眰 maxDate 蹇呴』澶т簬褰撳墠鏃堕棿)
+    maxDateTimestamp() {
+      const d = new Date();
+      d.setFullYear(d.getFullYear() + 1);
+      return d.getTime();
+    },
+    // u-calendar 鏈堜唤婊戝姩鍒楄〃鏈�澶氬睍绀虹殑鏈堟暟銆傛覆鏌撻噺涓庡彲缈昏寖鍥存鐩稿叧(鏈堟暟脳绾�42鏍�):
+    // 璁� 60 鏃剁偣鍑�/鍏抽棴鐨� setData 浼氬崱(绾� 2500 鏍�),鏁呯缉鍒� 25(绾� 1000 鏍�),浠婂ぉ澶ц嚧灞呬腑銆�
+    // 闇�涓� minDate~maxDate 璺ㄥ害涓�鑷�(鍓嶅悗鍚� 1 骞� + 褰撴湀 = 25),鍚﹀垯閮ㄥ垎鏈堜唤缈讳笉鍒�
+    calendarMonthNum() {
+      // 鍓嶅悗鍚� 1 骞�,鍚綋鏈堝叡 25 涓湀;璋冩暣鑼冨洿鏃跺悓姝ユ敼涓婇潰 minDate/maxDate 鐨勫勾鏁�
+      return 25;
+    },
+    // 鐓ょ鍙戣繍鎯呭喌:鏃ユ湡(YYYY-MM-DD)鍖洪棿銆傛棩鍘嗘寜澶╂瘮杈�/楂樹寒銆佹枃鏈洖鏄鹃兘鐢ㄧ函鏃ユ湡,
+    // 鏁呬粠甯︽椂鍒嗙鐨勫瓨鍌ㄥ�奸噷鎴彇鍓� 10 浣�(YYYY-MM-DD);涓虹┖鏃堕粯璁や粖澶�
+    coalDateRange() {
+      const start = (this.coalStartTime || this.todayStr).slice(0, 10);
+      const end = (this.coalEndTime || this.todayStr).slice(0, 10);
+      return [start, end];
+    },
+    // 鐓ょ鍙戣繍鎯呭喌:鍥炴樉鏃堕棿娈垫枃鏈�(浠呮棩鏈�)
+    coalRangeText() {
+      const [start, end] = this.coalDateRange;
+      return start === end ? start : `${start} ~ ${end}`;
+    },
+    // 鐓ょ鍙戣繍鎯呭喌:鏃ュ巻榛樿閫変腑鏃ユ湡(range 妯″紡杩斿洖鏁扮粍,浠呮棩鏈�)
+    coalDefaultDate() {
+      return this.coalDateRange;
+    },
+    // 鍒嗗鎴风叅绉嶅彂杩愭儏鍐�:鏃ユ湡(YYYY-MM-DD)鍖洪棿(鍚� coalDateRange,鍘绘帀鏃跺垎绉�)
+    kehuDateRange() {
+      const start = (this.kehuStartTime || this.todayStr).slice(0, 10);
+      const end = (this.kehuEndTime || this.todayStr).slice(0, 10);
+      return [start, end];
+    },
+    // 鍒嗗鎴风叅绉嶅彂杩愭儏鍐�:鍥炴樉鏃堕棿娈垫枃鏈�(浠呮棩鏈�)
+    kehuRangeText() {
+      const [start, end] = this.kehuDateRange;
+      return start === end ? start : `${start} ~ ${end}`;
+    },
+    // 鍒嗗鎴风叅绉嶅彂杩愭儏鍐�:鏃ュ巻榛樿閫変腑鏃ユ湡(range 妯″紡杩斿洖鏁扮粍,浠呮棩鏈�)
+    kehuDefaultDate() {
+      return this.kehuDateRange;
+    }
 	},
 	data() {
     const validatePass = (rule, value, callback) => {
@@ -832,6 +952,20 @@
       kehuTongji:[], //鐓ょ缁熻
       kehuTongjiTemp:[], //鐓ょ缁熻
       kehuTongjiShowIsMore: false,
+      // 鐓ょ鍙戣繍鎯呭喌 鏃堕棿娈甸�夋嫨
+      coalLoaded: false,    //鏄惁宸叉煡璇㈣繃(鎺у埗鍖哄潡鏄鹃殣)
+      coalLoading: false,   //鍖哄潡鍐呰浆鍦�(鍔犺浇涓�)
+      coalCalendarShow: false,
+      coalCalendarKey: 0,   //姣忔鎵撳紑鑷,寮哄埗 u-calendar 閲嶆柊鎸傝浇,瑙勯伩寰俊 scroll-view 閲嶅鎵撳紑涓嶉噸婊氥�侀粯璁ゅ仠鍦� minDate 鏈堢殑 bug
+      coalStartTime: '',    //寮�濮嬫棩鏈�(YYYY-MM-DD 00:00:00),榛樿褰撳ぉ
+      coalEndTime: '',      //缁撴潫鏃ユ湡(YYYY-MM-DD 23:59:59),榛樿褰撳ぉ
+      // 鍒嗗鎴风叅绉嶅彂杩愭儏鍐� 鏃堕棿娈甸�夋嫨
+      kehuLoaded: false,    //鏄惁宸叉煡璇㈣繃(鎺у埗鍖哄潡鏄鹃殣)
+      kehuLoading: false,   //鍖哄潡鍐呰浆鍦�(鍔犺浇涓�)
+      kehuCalendarShow: false,
+      kehuCalendarKey: 0,   //姣忔鎵撳紑鑷,寮哄埗 u-calendar 閲嶆柊鎸傝浇(鍚� coalCalendarKey)
+      kehuStartTime: '',    //寮�濮嬫棩鏈�(YYYY-MM-DD 00:00:00),榛樿褰撳ぉ
+      kehuEndTime: '',      //缁撴潫鏃ユ湡(YYYY-MM-DD 23:59:59),榛樿褰撳ぉ
       roles:[],
       d2Sum:0,  //鎬昏閲戦
       d1Sum:0,  //鎬昏
@@ -979,6 +1113,17 @@
     handlePwd() {
       this.passShow = true
     },
+    // 鎵撳紑鐓ょ鍙戣繍鎯呭喌 鏃堕棿娈垫棩鍘�:鑷 key 寮哄埗 u-calendar 閲嶆柊鎸傝浇,
+    // 瑙勯伩寰俊绔噸澶嶆墦寮�鏃� scroll-view 鍥� scroll-top 鏈彉鑰屼笉閲嶆粴銆侀粯璁ゅ仠鍦� minDate 鏈堢殑 bug
+    openCoalCalendar() {
+      this.coalCalendarKey++
+      this.coalCalendarShow = true
+    },
+    // 鎵撳紑鍒嗗鎴风叅绉嶅彂杩愭儏鍐� 鏃堕棿娈垫棩鍘�(鍘熺悊鍚� openCoalCalendar)
+    openKehuCalendar() {
+      this.kehuCalendarKey++
+      this.kehuCalendarShow = true
+    },
     handleShouKuanIsMore() {  //褰撴棩鏀舵鎯呭喌
       this.shoukuanIsMore = !this.shoukuanIsMore
     },
@@ -1026,8 +1171,15 @@
       })
     },
     getStatistics1() {  //鎸夌叅绉嶇粺璁�
-      this.$reqGet('getStatistics1').then(res => {
+      console.log('鎸夌叅绉嶇粺璁�------寮�濮嬫椂闂�',this.coalStartTime,this.startTodayStr)
+      console.log('鎸夌叅绉嶇粺璁�------寮�濮嬫椂闂�',this.coalEndTime,this.endTodaydayStr)
+      this.coalLoading = true
+      this.$reqGet('getStatistics1', {
+        startTime: this.coalStartTime || this.startTodayStr,
+        endTime: this.coalEndTime || this.endTodaydayStr
+      }).then(res => {
         if (res.code == 0) {
+          this.coalLoaded = true
           this.coalTongjiTemp = res.data || []
           if(this.coalTongjiTemp && this.coalTongjiTemp.length > 0){
             this.d2Sum = this.coalTongjiTemp[0]?.d2Sum || 0
@@ -1038,22 +1190,63 @@
               this.coalTongji = this.coalTongjiTemp.slice(0,2)
               this.coalShowIsMore = false
             }
+          } else {
+            this.resetCoalStat()
           }
         }
+      }).finally(() => {
+        this.coalLoading = false
       })
     },
+    resetCoalStat() {  //娓呯┖鐓ょ鍙戣繍鎯呭喌缁熻
+      this.coalTongji = []
+      this.coalTongjiTemp = []
+      this.d2Sum = 0
+      this.d1Sum = 0
+      this.lyDSumSum = 0
+      this.dsumSum = 0
+    },
+    // 鐓ょ鍙戣繍鎯呭喌 鏃堕棿娈电‘璁�(寮�濮嬭ˉ 00:00:00銆佺粨鏉熻ˉ 23:59:59)
+    coalCalendarConfirm(e) {
+      this.coalCalendarShow = false
+      const arr = Array.isArray(e) ? e : (e && e.result) || []
+      if (arr.length < 2) return
+      this.coalStartTime = `${arr[0]} 00:00:00`
+      this.coalEndTime = `${arr[arr.length - 1]} 23:59:59`
+      this.getStatistics1()
+    },
     getStatistics2() {  //鎸夊鎴峰彂杩愮粺璁�
-      this.$reqGet('getStatistics2').then(res => {
+      console.log('鍙戣繍缁熻------寮�濮嬫椂闂�',this.kehuStartTime,this.startTodayStr)
+      console.log('鍙戣繍缁熻------寮�濮嬫椂闂�',this.kehuEndTime,this.endTodaydayStr)
+      this.kehuLoading = true
+      this.$reqGet('getStatistics2', {
+        startTime: this.kehuStartTime || this.startTodayStr,
+        endTime: this.kehuEndTime || this.endTodaydayStr
+      }).then(res => {
         if (res.code == 0) {
+          this.kehuLoaded = true
           this.kehuTongjiTemp = res.data || []
           if(this.kehuTongjiTemp && this.kehuTongjiTemp.length > 0){
             if(this.kehuTongjiTemp.length > 0) {
               this.kehuTongji = this.kehuTongjiTemp.slice(0,2)
               this.kehuTongjiShowIsMore = false
             }
+          } else {
+            this.kehuTongji = []
           }
         }
+      }).finally(() => {
+        this.kehuLoading = false
       })
+    },
+    // 鍒嗗鎴风叅绉嶅彂杩愭儏鍐� 鏃堕棿娈电‘璁�(寮�濮嬭ˉ 00:00:00銆佺粨鏉熻ˉ 23:59:59)
+    kehuCalendarConfirm(e) {
+      this.kehuCalendarShow = false
+      const arr = Array.isArray(e) ? e : (e && e.result) || []
+      if (arr.length < 2) return
+      this.kehuStartTime = `${arr[0]} 00:00:00`
+      this.kehuEndTime = `${arr[arr.length - 1]} 23:59:59`
+      this.getStatistics2()
     },
     //浠e姙璇︽儏
     daibanDetail(item) {
@@ -1158,7 +1351,8 @@
 			m = m < 10 ? '0' + m : m;
 			let d = date.getDate();
 			d = d < 10 ? '0' + d : d;
-			const time = y + '-' + m + '-' + d;
+			// const time = y + '-' + m + '-' + d;
+			const time = `${y}-${m}-${d} 00:00:00`;
 			console.log('todayDate---------', time);
 			return time;
 		},
@@ -1423,19 +1617,18 @@
 };
 </script>
 
-
 <style lang="scss" scoped>
 ::v-deep{
   .uni-table-td,.uni-table-th{
     color: #000;
   }
-  .u-popup__content{
-    width: 85%;
-    padding: 40rpx;
-    box-sizing: border-box;
-    border-radius: 10rpx;
-  }
   .passWord-main-box{
+    .u-popup__content{
+      width: 85%;
+      padding: 40rpx;
+      box-sizing: border-box;
+      border-radius: 10rpx;
+    }
     .u-icon__icon{
       font-size: 28rpx!important;
     }
@@ -1815,6 +2008,34 @@
           align-items: baseline;
         }
       }
+      .date-pick-box{
+        position: absolute;
+        right: 20rpx;
+        top: 50%;
+        transform: translateY(-50%);
+        display: flex;
+        align-items: center;
+        max-width: 55%;
+        .date-pick-text{
+          font-size: 26rpx;
+          color: #4b6cfa;
+          white-space: nowrap;
+          overflow: hidden;
+          text-overflow: ellipsis;
+        }
+        .date-pick-icon{
+          width: 32rpx;
+          height: 32rpx;
+          margin-left: 8rpx;
+        }
+      }
+    }
+    .block-loading{
+      width: 100%;
+      padding: 60rpx 0;
+      display: flex;
+      align-items: center;
+      justify-content: center;
     }
     .shoukuan-box{
       width: 100%;

--
Gitblit v1.9.1