sports.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar fixed :border="false" :backgroundColor="`rgba(255,255,255,${opacity})`" title="活动"
  4. :statusBar="true" left-icon="left" @clickLeft="back"></uni-nav-bar>
  5. <image class="page-bg" src="@/static/images/pages_watch/images/blood_oxygen_top_bg.png" mode="widthFix"></image>
  6. <view class="container-body">
  7. <dateTimePicker :from="'sports'" @onChange="onChangeTime" />
  8. <!-- 活动趋势 -->
  9. <view class="box">
  10. <view class="box-title y-f">
  11. <view :style="{visibility: loading ? 'hidden':'visible'}">{{chooseItem.day}}</view>
  12. <view class="box-titlenum"><text>{{loading ? 0: chooseItem.distance}}</text>公里</view>
  13. </view>
  14. <view class="echartbox">
  15. <qiun-data-charts v-show="!isEmpty" type="column" :opts="opts" :chartData="chartData"
  16. :tooltipFormat="tooltipFormat" @getIndex="getIndex" />
  17. <myEmpty v-show="isEmpty" style="padding: 40rpx 0 0 0;"></myEmpty>
  18. </view>
  19. <view class="sportsbox-list x-bc">
  20. <view class="sportsbox-item es-pl-20 es-pr-20">
  21. <view class="x-f">
  22. <image class="icon" src="@/static/images/pages_watch/icons/kaluli_icon.png" mode="aspectFill"></image>
  23. <text>活动热量</text>
  24. </view>
  25. <view class="value">
  26. <text class="num">{{chooseItem.calorie}}</text>
  27. <text>千卡</text>
  28. </view>
  29. </view>
  30. <view class="sportsbox-item es-pl-20 es-pr-20">
  31. <view class="x-f">
  32. <image class="icon" src="@/static/images/pages_watch/icons/time_icon.png" mode="aspectFill"></image>
  33. <text>锻炼时长</text>
  34. </view>
  35. <view class="value">
  36. <text class="num">{{secondsToHoursAndMinutes(chooseItem.time)}}</text>
  37. </view>
  38. </view>
  39. <view class="sportsbox-item es-pl-20 es-pr-20">
  40. <view class="x-f">
  41. <image class="icon" src="@/static/images/pages_watch/icons/speed_icon.png" mode="aspectFill"></image>
  42. <text>平均速度</text>
  43. </view>
  44. <view class="value">
  45. <text class="num">{{chooseItem.speed}}</text>
  46. <text>公里/小时</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import myEmpty from "@/pages_watch/components/myEmpty/myEmpty.vue"
  56. import dateTimePicker from "@/pages_watch/components/dateTimePicker/dateTimePicker.vue"
  57. import {
  58. spInfo,
  59. spCount,
  60. sportDataByDate
  61. } from "@/api/pages_watch/healthMonitoring.js";
  62. export default {
  63. components: {
  64. myEmpty,
  65. dateTimePicker
  66. },
  67. data() {
  68. return {
  69. tooltipFormat: 'sportTooltip',
  70. opacity: 0,
  71. loading: false,
  72. isEmpty: false,
  73. list: [],
  74. chartData: {},
  75. week: ['周一','周二','周三','周四','周五','周六','周日'],
  76. times: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],
  77. weekDay: [],
  78. chooseItem: {
  79. day: '',
  80. calorie: 0,
  81. distance: 0,
  82. speed: 0,
  83. time: 0,
  84. },
  85. opts: {
  86. padding: [15, 0, 15, 0],
  87. enableScroll: false,
  88. dataLabel: false,
  89. legend: {
  90. show: false
  91. },
  92. xAxis: {
  93. disableGrid: true,
  94. fontSize: 12,
  95. axisLine: false,
  96. fontColor: '#ccc',
  97. labelCount: 7,
  98. },
  99. yAxis: {
  100. gridType: "dash",
  101. dashLength: 2,
  102. data: [{
  103. fontColor: '#ccc',
  104. min: 0,
  105. axisLine: false,
  106. fontSize: 12,
  107. }]
  108. },
  109. extra: {
  110. tooltip: {
  111. gridType: "dash",
  112. showArrow: false,
  113. legendShow: true,
  114. legendShape: "circle"
  115. },
  116. column: {
  117. type: "group",
  118. width: 12,
  119. barBorderRadius: [4, 4, 0, 0],
  120. }
  121. }
  122. }
  123. }
  124. },
  125. methods: {
  126. back() {
  127. uni.navigateBack({
  128. delta: 1
  129. })
  130. },
  131. secondsToHoursAndMinutes(totalSeconds) {
  132. let hours = Math.floor(totalSeconds / 3600);
  133. let minutes = Math.floor((totalSeconds % 3600) / 60);
  134. let seconds = totalSeconds % 60;
  135. hours = hours.toString().padStart(2, '0');
  136. minutes = minutes.toString().padStart(2, '0');
  137. seconds = seconds.toString().padStart(2, '0');
  138. return hours+':'+minutes+':'+seconds;
  139. },
  140. getDates(startDate, endDate) {
  141. const dates = [];
  142. const currentDate = new Date(startDate);
  143. endDate = new Date(endDate);
  144. while (currentDate <= endDate) {
  145. dates.push(this.$timeFormat(currentDate,'yyyy-mm-dd'));
  146. currentDate.setDate(currentDate.getDate() + 1);
  147. }
  148. return dates;
  149. },
  150. onChangeTime(time) {
  151. const param = {
  152. startTime: this.$timeFormat(time[0], 'yyyy/mm/dd hh:MM:ss'),
  153. endTime: this.$timeFormat(time[1], 'yyyy/mm/dd hh:MM:ss'),
  154. deviceId: uni.getStorageSync("deviceId") || ""
  155. }
  156. this.tooltipFormat = time[3] == 1 ? 'sportweekTooltip' : 'sportTooltip'
  157. const startDate = time[0].split(' ')[0];
  158. const endDate = time[1].split(' ')[0]
  159. this.weekDay = this.getDates(startDate,endDate)
  160. this.getServerData(param)
  161. },
  162. getServerData(param) {
  163. this.loading = true
  164. sportDataByDate(param).then((res) => {
  165. this.loading = false
  166. this.isEmpty = !(res.data && res.data.length > 0)
  167. this.list = res.data && res.data.length > 0 ? res.data : []
  168. if (res.code == 200 && res.data) {
  169. const categories = this.tooltipFormat == 'sportweekTooltip' ? this.week : this.times
  170. let chartData = {
  171. categories: categories,
  172. series: [{
  173. name: "活动",
  174. data: res.data.map(item => ({
  175. value: item.distance,
  176. color: "#52D087"
  177. }))
  178. }]
  179. }
  180. this.opts.xAxis.labelCount = this.tooltipFormat == 'sportweekTooltip' ? '' : 9
  181. this.chartData = JSON.parse(JSON.stringify(chartData));
  182. this.chooseItem = {
  183. day: this.tooltipFormat == 'sportweekTooltip' ? `${this.weekDay[0]}至${this.weekDay[0]}` : `${this.weekDay[0]}`,
  184. calorie: res.calorieTotal,
  185. distance: res.distanceTotal,
  186. speed: res.speedTotal,
  187. time: res.timeTotal,
  188. }
  189. }
  190. }).catch((err) => {
  191. this.loading = false
  192. });
  193. },
  194. getIndex(e) {
  195. if(e.currentIndex.index < 0) return;
  196. let index = e.currentIndex.index
  197. this.chooseItem = {
  198. day: this.tooltipFormat == 'sportweekTooltip' ? this.weekDay[index] : `${this.weekDay[0]} ${index}-${[index+1]}点`,
  199. calorie: this.list[index].calorie,
  200. distance: this.list[index].distance,
  201. speed: this.list[index].speed,
  202. time: this.list[index].time,
  203. }
  204. }
  205. },
  206. onPageScroll(e) {
  207. if (e.scrollTop <= 44) {
  208. this.opacity = e.scrollTop / 44 * 1
  209. } else if (e.scrollTop > 44) {
  210. this.opacity = 1
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. @mixin u-flex($flexD, $alignI, $justifyC) {
  217. display: flex;
  218. flex-direction: $flexD;
  219. align-items: $alignI;
  220. justify-content: $justifyC;
  221. }
  222. .container {
  223. padding: 0 24rpx;
  224. position: relative;
  225. }
  226. .sportsbox {
  227. &-list {
  228. width: 100%;
  229. flex-wrap: wrap;
  230. margin-bottom: -46rpx;
  231. }
  232. &-item {
  233. width: 50%;
  234. box-sizing: border-box;
  235. overflow: hidden;
  236. font-family: PingFang SC, PingFang SC;
  237. font-weight: 500;
  238. font-size: 22rpx;
  239. color: #757575;
  240. margin-bottom: 46rpx;
  241. .icon {
  242. width: 32rpx;
  243. height: 32rpx;
  244. margin-right: 8rpx;
  245. }
  246. .num {
  247. margin-right: 5rpx;
  248. font-weight: 600;
  249. font-size: 44rpx;
  250. color: #222222;
  251. }
  252. .value {
  253. margin-top: 10rpx;
  254. font-weight: 400;
  255. font-size: 26rpx;
  256. color: #999999;
  257. }
  258. }
  259. .sportstitle {
  260. font-family: PingFang SC, PingFang SC;
  261. font-weight: 500;
  262. font-size: 30rpx;
  263. color: #222222;
  264. }
  265. .sportsicon {
  266. width: 40rpx;
  267. height: 40rpx;
  268. margin-right: 16rpx;
  269. }
  270. .frequency {
  271. text-align: right;
  272. margin-top: 6rpx;
  273. font-weight: 500;
  274. font-size: 24rpx;
  275. color: #757575;
  276. }
  277. .sports {
  278. padding: 24rpx 0;
  279. }
  280. }
  281. .page-bg {
  282. width: 100%;
  283. height: auto;
  284. position: absolute;
  285. top: 0;
  286. left: 0;
  287. }
  288. .container-body {
  289. position: relative;
  290. z-index: 1;
  291. padding-bottom: 24rpx;
  292. }
  293. .box-title {
  294. font-family: PingFang SC, PingFang SC;
  295. font-weight: 400;
  296. font-size: 28rpx;
  297. color: #757575;
  298. }
  299. .box-titlenum {
  300. align-items: flex-end !important;
  301. text {
  302. font-family: PingFang SC;
  303. font-weight: 500;
  304. font-size: 104rpx;
  305. color: #333333;
  306. }
  307. }
  308. .box {
  309. padding: 24rpx;
  310. margin-bottom: 20rpx;
  311. box-sizing: border-box;
  312. background: #FFFFFF;
  313. border-radius: 16rpx 16rpx 16rpx 16rpx;
  314. }
  315. .echartbox {
  316. height: 520rpx;
  317. width: 100%;
  318. }
  319. </style>