sportsList.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <view class="container">
  3. <view class="headcon">
  4. <view class="headcon-title">{{this.type}}总览</view>
  5. <view class="headcon-info x-bc">
  6. <view class="headcon-item y-f">
  7. <view class="headcon-num" style="font-size: 72rpx;">{{distanceTotal||0}}</view>
  8. <view>{{this.type}}(公里)</view>
  9. </view>
  10. <view class="headcon-item border y-f">
  11. <view class="headcon-num">{{timeTotal || 0}}</view>
  12. <view>时长(小时)</view>
  13. </view>
  14. <view class="headcon-item y-f">
  15. <view class="headcon-num">{{countTotal||0}}</view>
  16. <view>次数(次)</view>
  17. </view>
  18. </view>
  19. </view>
  20. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  21. <view class="list">
  22. <view v-for="(item, key, index) in list" :key="index">
  23. <view class="list-title">
  24. <view>{{key.replace('-','年') + '月'}}</view>
  25. <view class="list-title-txt">{{this.type}}{{_mouthTotal('distance',item)}}公里 运动 {{_mouthTotal('time',item)}}小时 运动{{item.length}}次 消耗{{_mouthTotal('calorie',item)}}千卡</view>
  26. </view>
  27. <view class="list-box">
  28. <view class="list-item border-line x-bc" v-for="(it,i) in item" :key="i">
  29. <image :src="typeoption[type]" mode="aspectFill"></image>
  30. <view class="list-item-r">
  31. <view class="x-bc">
  32. <text>{{type}}</text>
  33. <text>{{it.createTime.substring(5,16)}}</text>
  34. </view>
  35. <view class="right-info x-f">
  36. <view class="right-item"><text style="font-weight: 500;font-size: 40rpx;color: #222222;">{{it.distance}}</text>公里</view>
  37. <text class="right-item">{{_seconds(it.time || 0)}}</text>
  38. <text class="right-item">{{_seconds(it.speed || 0,1)}} /公里</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </mescroll-body>
  46. </view>
  47. </template>
  48. <script>
  49. import {sportDataByType} from "@/api/pages_watch/healthMonitoring.js"
  50. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  51. export default {
  52. mixins: [MescrollMixin],
  53. data() {
  54. return {
  55. mescroll:null,
  56. downOption: { //下拉刷新
  57. use:true,
  58. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  59. },
  60. upOption: {
  61. onScroll:false,
  62. use: true, // 是否启用上拉加载; 默认true
  63. page: {
  64. pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  65. size: 10 // 每页数据的数量,默认10
  66. },
  67. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  68. textNoMore:"已经到底了",
  69. empty: {
  70. icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
  71. tip: '暂无数据'
  72. }
  73. },
  74. dataList: [],
  75. type: '',
  76. typeoption: {
  77. '游泳': '/static/images/pages_watch/icons/swim_icon.png',
  78. '登山': '/static/images/pages_watch/icons/mountaineering_icon.png',
  79. '骑行': '/static/images/pages_watch/icons/ride_icon.png',
  80. '跑步': '/static/images/pages_watch/icons/run_icon.png',
  81. '健步走': '/static/images/pages_watch/icons/walk_icon.png',
  82. '球类': '/static/images/pages_watch/icons/ball_game_icon.png',
  83. '其他运动': '/static/images/pages_watch/icons/other_icon.png',
  84. },
  85. countTotal: 0,
  86. distanceTotal: 0,
  87. timeTotal: 0,
  88. list: []
  89. }
  90. },
  91. computed: {
  92. _seconds() {
  93. return (totalSeconds,type)=> {
  94. let hours = Math.floor(totalSeconds / 3600);
  95. let minutes = Math.floor((totalSeconds % 3600) / 60);
  96. let seconds = totalSeconds % 60;
  97. hours = hours.toString().padStart(2, '0');
  98. minutes = minutes.toString().padStart(2, '0');
  99. seconds = seconds.toString().padStart(2, '0');
  100. if(type == 1) {
  101. return hours+':'+minutes+'´'+seconds+'´´';
  102. } else {
  103. return hours+':'+minutes+':'+seconds;
  104. }
  105. }
  106. },
  107. _mouthTotal() {
  108. return (type,list)=> {
  109. if(type == 'distance') {
  110. return list.reduce((acc, obj) => { return acc + Number(obj.distance || 0)}, 0);
  111. } else if(type == 'time') {
  112. const s = list.reduce((acc, obj) => { return acc + Number(obj.time || 0)}, 0)
  113. return (s / 3600).toFixed(2)
  114. } else if(type == 'calorie') {
  115. return list.reduce((acc, obj) => { return acc + Number(obj.calorie || 0)}, 0);
  116. } else {
  117. return 0
  118. }
  119. }
  120. }
  121. },
  122. onLoad(option) {
  123. this.type = option.title || ''
  124. uni.setNavigationBarTitle({
  125. title: option.title || '运动',
  126. });
  127. },
  128. methods: {
  129. mescrollInit(mescroll) {
  130. this.mescroll = mescroll;
  131. },
  132. /*下拉刷新的回调 */
  133. downCallback(mescroll) {
  134. mescroll.resetUpScroll()
  135. },
  136. upCallback(page) {
  137. //联网加载数据
  138. var that = this;
  139. var data = {
  140. deviceId: uni.getStorageSync("deviceId") || '',
  141. type: this.type,
  142. pageNum: page.num,
  143. pageSize: page.size
  144. };
  145. sportDataByType(data).then(res => {
  146. this.countTotal = res.data.countTotal
  147. this.distanceTotal = res.data.distanceTotal
  148. this.timeTotal = res.data.timeTotal
  149. if(res.code==200){
  150. //设置列表数据
  151. if (page.num == 1) {
  152. that.dataList = res.data.list;
  153. } else {
  154. that.dataList = that.dataList.concat(res.data.list);
  155. }
  156. this.resetData(that.dataList)
  157. that.mescroll.endBySize(res.data.list.length, res.data.total);
  158. }else{
  159. uni.showToast({
  160. icon:'none',
  161. title: "请求失败",
  162. });
  163. that.dataList = null;
  164. this.list = []
  165. that.mescroll.endErr();
  166. }
  167. });
  168. },
  169. resetData(array) {
  170. this.list = array.reduce((acc, obj) => {
  171. const [year, month] = obj.createTime.split(' ')[0].split('-');
  172. const date = obj.createTime.split(' ')[0];
  173. if (!acc[`${year}-${month}`]) {
  174. acc[`${year}-${month}`] = [];
  175. }
  176. // if (!acc[`${year}-${month}`][date]) {
  177. // acc[`${year}-${month}`][date] = [];
  178. // }
  179. acc[`${year}-${month}`].push(obj);
  180. return acc;
  181. }, {});
  182. console.log(this.list)
  183. },
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .container {
  189. padding: 24rpx;
  190. font-family: PingFang SC, PingFang SC;
  191. font-weight: 400;
  192. font-size: 24rpx;
  193. color: #757575;
  194. .headcon {
  195. padding: 32rpx 24rpx;
  196. background: #FFFFFF;
  197. border-radius: 16rpx 16rpx 16rpx 16rpx;
  198. &-title {
  199. font-weight: 500;
  200. font-size: 36rpx;
  201. color: #222222;
  202. }
  203. &-info {
  204. align-items: flex-end !important;
  205. }
  206. &-item {
  207. flex: 1;
  208. }
  209. &-num {
  210. padding: 10rpx 0;
  211. font-weight: 500;
  212. font-size: 48rpx;
  213. color: #333333;
  214. }
  215. }
  216. .border {
  217. position: relative;
  218. &::after {
  219. content: "";
  220. height: 88rpx;
  221. width: 0;
  222. border-left: 2rpx solid #ECECEC;
  223. position: absolute;
  224. left: 0;
  225. bottom: 0;
  226. }
  227. &::before {
  228. content: "";
  229. height: 88rpx;
  230. width: 0;
  231. border-right: 2rpx solid #ECECEC;
  232. position: absolute;
  233. right: 0;
  234. bottom: 0;
  235. }
  236. }
  237. }
  238. .list {
  239. padding-bottom: calc(var(--window-bottom) + 24rpx);
  240. &-title {
  241. padding: 24rpx 0;
  242. font-weight: 500;
  243. font-size: 30rpx;
  244. color: #333333;
  245. }
  246. &-title-txt {
  247. margin-top: 4rpx;
  248. font-family: PingFang SC, PingFang SC;
  249. font-weight: 400;
  250. font-size: 24rpx;
  251. color: #757575;
  252. }
  253. &-box{
  254. padding: 0 24rpx;
  255. background: #FFFFFF;
  256. border-radius: 16rpx 16rpx 16rpx 16rpx;
  257. overflow: hidden;
  258. }
  259. &-item {
  260. padding: 32rpx 0;
  261. image {
  262. width: 72rpx;
  263. height: 72rpx;
  264. flex-shrink: 0;
  265. margin-right: 18rpx;
  266. }
  267. &-r {
  268. flex: 1;
  269. overflow: hidden;
  270. }
  271. }
  272. .right-info {
  273. align-items: baseline !important;
  274. margin: 0 -32rpx -20rpx 0;
  275. flex-wrap: wrap;
  276. }
  277. .right-item {
  278. margin: 0 32rpx 20rpx 0;
  279. }
  280. }
  281. </style>