Browse Source

home-statistics page

邹能昇 3 months ago
parent
commit
03570a514c

+ 92 - 41
nova-werun/pages/home/statistics/index.js

@@ -1,46 +1,52 @@
 // nova-werun/pages/home/statistics/index.js
+const Parse = getApp().Parse;
+const company = getApp().globalData.company;
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-            //屏幕高度
-            statusBarHeight: 0, // 状态栏高度
-            screenHeight: 0, // 屏幕高度
-            customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
-            bottomNavHeight: 0, // 底部导航栏高度
-            contentHeight: 0, // 可用内容高度
-            contentHeight2: 0,
-            contentpadding: 0, //顶部padding高度
-
-            active: 0,
-            //
-            day:'7'
+        //屏幕高度
+        statusBarHeight: 0, // 状态栏高度
+        screenHeight: 0, // 屏幕高度
+        customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
+        bottomNavHeight: 0, // 底部导航栏高度
+        contentHeight: 0, // 可用内容高度
+        contentHeight2: 0,
+        contentpadding: 0, //顶部padding高度
+
+        active: 0,
+        //
+        day: '7',
+        target: '',
+        sharList:[]
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-                // 计算
-                const systemInfo = wx.getSystemInfoSync();
-                const statusBarHeight = systemInfo.statusBarHeight || 0;
-                const screenHeight = systemInfo.screenHeight || 0;
-                const custom = wx.getMenuButtonBoundingClientRect();
-                const customHeight = custom.height + 10 + 2 || 0;
-                const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
-        
-                const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
-                const contentHeight = (screenHeight -50- bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
-                this.setData({
-                    statusBarHeight,
-                    screenHeight,
-                    customHeight,
-                    bottomNavHeight,
-                    contentpadding,
-                    contentHeight
-                });
+        // 计算
+        const systemInfo = wx.getSystemInfoSync();
+        const statusBarHeight = systemInfo.statusBarHeight || 0;
+        const screenHeight = systemInfo.screenHeight || 0;
+        const custom = wx.getMenuButtonBoundingClientRect();
+        const customHeight = custom.height + 10 + 2 || 0;
+        const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
+
+        const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
+        const contentHeight = (screenHeight - 50 - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
+        this.setData({
+            statusBarHeight,
+            screenHeight,
+            customHeight,
+            bottomNavHeight,
+            contentpadding,
+            contentHeight
+        });
+        this.gettarget()
+        this.order()
     },
 
     /**
@@ -92,17 +98,62 @@ Page({
 
     },
     onChange(event) {
-        this.setData({ active: event.detail });
-      },
-      changeday(){
-          if(this.data.day=='7'){
-              this.setData({
-                  day:'30'
-              })
-          }else{
+        this.setData({
+            active: event.detail
+        });
+    },
+    changeday() {
+        if (this.data.day == '7') {
+            this.setData({
+                day: '30'
+            })
+        } else {
+            this.setData({
+                day: '7'
+            })
+        }
+    },
+    async gettarget() {
+        const currentUser = Parse.User.current();
+        let userquery = new Parse.Query('_User');
+        userquery.equalTo('company', company);
+        userquery.equalTo('objectId', currentUser.id);
+        userquery.notEqualTo('isDeleted', true)
+        let user = await userquery.find();
+        let num = user.map(item => item.toJSON());
+        if (num[0].num) {
             this.setData({
-                day:'7'
+                target: num[0].num
             })
-          }
-      }
+            console.log('当前步数', this.data.target);
+        }
+    },
+        //获取当天运动数据
+        async order() {
+            const currentUser = Parse.User.current();
+            let ActivityDataquery = new Parse.Query('ActivityData');
+            ActivityDataquery.equalTo('user', currentUser.id);
+            ActivityDataquery.equalTo('company', company);
+            ActivityDataquery.equalTo('type', 'today');
+            ActivityDataquery.notEqualTo('isDeleted', true);
+    
+            // 获取今天的日期
+            const today = new Date();
+            const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
+            const todayEnd = new Date(todayStart);
+            todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
+    
+            // 在查询条件中添加对 createdAt 的限制
+            ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
+            ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
+            ActivityDataquery.include('user');
+    
+            let r = await ActivityDataquery.find();
+            let sharList = r.map(item => item.toJSON());
+    
+            this.setData({
+                sharList
+            });
+            console.log(this.data.sharList);
+        },
 })

+ 4 - 4
nova-werun/pages/home/statistics/index.wxml

@@ -3,7 +3,7 @@
 <view class="all" style="height: {{contentHeight}}rpx;" wx:if="{{active==0}}">
     <view class="number">
         <view class="num">
-            <view class="num-num">666</view>
+            <view class="num-num">{{sharList[0].burnCalories}}</view>
             <view class="num-text">
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/f1p6rn032449318.png?imageView2/1/w/200/h/200"></image>
                 卡路里
@@ -11,7 +11,7 @@
         </view>
         <view class="num">
             <view class="num-num">
-                56
+                {{sharList[0].sportDate}}
                 <view class="numtext">分钟</view>
             </view>
             <view class="num-text">
@@ -20,7 +20,7 @@
             </view>
         </view>
         <view class="num">
-            <view class="num-num">5.5</view>
+            <view class="num-num">{{sharList[0].distance}}</view>
             <view class="num-text">
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/i12ut1032603507.png?imageView2/1/w/200/h/200"></image>
                 公里
@@ -34,7 +34,7 @@
                 <view class="step-num">18000</view>
                 <view class="objective">
                     <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/q12pc1114226514.png?imageView2/1/w/200/h/200" alt="" />
-                    <view class="ob-num">目标:200000</view>
+                    <view class="ob-num">目标:{{target}}</view>
                 </view>
                 <view class="achieve">93% 已完成</view>
             </view>