index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // nova-werun/pages/home/statistics/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. contentHeight2: 0,
  16. contentpadding: 0, //顶部padding高度
  17. active: 0,
  18. //
  19. day: '7',
  20. target: '',
  21. sharList:[]
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. // 计算
  28. const systemInfo = wx.getSystemInfoSync();
  29. const statusBarHeight = systemInfo.statusBarHeight || 0;
  30. const screenHeight = systemInfo.screenHeight || 0;
  31. const custom = wx.getMenuButtonBoundingClientRect();
  32. const customHeight = custom.height + 10 + 2 || 0;
  33. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  34. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  35. const contentHeight = (screenHeight - 50 - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  36. this.setData({
  37. statusBarHeight,
  38. screenHeight,
  39. customHeight,
  40. bottomNavHeight,
  41. contentpadding,
  42. contentHeight
  43. });
  44. this.gettarget()
  45. this.order()
  46. },
  47. /**
  48. * 生命周期函数--监听页面初次渲染完成
  49. */
  50. onReady: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面显示
  54. */
  55. onShow: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload: function () {
  66. },
  67. /**
  68. * 页面相关事件处理函数--监听用户下拉动作
  69. */
  70. onPullDownRefresh: function () {
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage: function () {
  81. },
  82. onChange(event) {
  83. this.setData({
  84. active: event.detail
  85. });
  86. },
  87. changeday() {
  88. if (this.data.day == '7') {
  89. this.setData({
  90. day: '30'
  91. })
  92. } else {
  93. this.setData({
  94. day: '7'
  95. })
  96. }
  97. },
  98. async gettarget() {
  99. const currentUser = Parse.User.current();
  100. let userquery = new Parse.Query('_User');
  101. userquery.equalTo('company', company);
  102. userquery.equalTo('objectId', currentUser.id);
  103. userquery.notEqualTo('isDeleted', true)
  104. let user = await userquery.find();
  105. let num = user.map(item => item.toJSON());
  106. if (num[0].num) {
  107. this.setData({
  108. target: num[0].num
  109. })
  110. console.log('当前步数', this.data.target);
  111. }
  112. },
  113. //获取当天运动数据
  114. async order() {
  115. const currentUser = Parse.User.current();
  116. let ActivityDataquery = new Parse.Query('ActivityData');
  117. ActivityDataquery.equalTo('user', currentUser.id);
  118. ActivityDataquery.equalTo('company', company);
  119. ActivityDataquery.equalTo('type', 'today');
  120. ActivityDataquery.notEqualTo('isDeleted', true);
  121. // 获取今天的日期
  122. const today = new Date();
  123. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  124. const todayEnd = new Date(todayStart);
  125. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  126. // 在查询条件中添加对 createdAt 的限制
  127. ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
  128. ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
  129. ActivityDataquery.include('user');
  130. let r = await ActivityDataquery.find();
  131. let sharList = r.map(item => item.toJSON());
  132. this.setData({
  133. sharList
  134. });
  135. console.log(this.data.sharList);
  136. },
  137. })