sports.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="sportsbox y-f" style="padding-top: 0" @click="handleDetail('/pages_watch/healthMonitoring/sports')">
  3. <view class="sportsbox-echart">
  4. <myArcbar ref='myArcbar'></myArcbar>
  5. </view>
  6. <view class="sportsbox-list x-bc">
  7. <view class="sportsbox-item es-pl-52 es-pr-20">
  8. <view class="x-f">
  9. <image class="icon" src="@/static/images/pages_watch/icons/kaluli_icon.png" mode="aspectFill">
  10. </image>
  11. <text>活动热量</text>
  12. </view>
  13. <view class="value">
  14. <text class="num">{{Number(info.calorie || 0)}}</text>
  15. <text>/{{info.targetCalorie}} 千卡</text>
  16. </view>
  17. </view>
  18. <view class="sportsbox-item es-pl-40 es-pr-20">
  19. <view class="x-f">
  20. <image class="icon" src="@/static/images/pages_watch/icons/time_icon.png" mode="aspectFill"></image>
  21. <text>锻炼时长</text>
  22. </view>
  23. <view class="value">
  24. <text class="num">{{Number(info.sport || 0)}}</text>
  25. <text>/{{info.targetSport}} 分钟</text>
  26. </view>
  27. </view>
  28. <view class="sportsbox-item es-pl-52 es-pr-20">
  29. <view class="x-f">
  30. <image class="icon" src="@/static/images/pages_watch/icons/bushu_icon.png" mode="aspectFill">
  31. </image>
  32. <text>今日步数</text>
  33. </view>
  34. <view class="value">
  35. <text class="num">{{Number(info.step || 0)}}</text>
  36. <text>/{{info.targetStep}} 步</text>
  37. </view>
  38. </view>
  39. <view class="sportsbox-item es-pl-40 es-pr-20">
  40. <view class="x-f">
  41. <image class="icon" src="@/static/images/pages_watch/icons/min_icon.png" mode="aspectFill"></image>
  42. <text>活动小时数</text>
  43. </view>
  44. <view class="value">
  45. <text class="num">{{Number(info.activity || 0)}}</text>
  46. <text>/{{info.targetActivity}} 小时</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="sportsbox" style="padding: 30rpx 0">
  52. <view class="x-bc sportstitle" style="padding: 0 30rpx">
  53. <view class="x-f">
  54. <image class="sportsicon" src="@/static/images/pages_watch/icons/sports_record_icon.png"
  55. mode="aspectFill"></image>运动记录
  56. </view>
  57. <view>{{list[activeIndex].name}}<text style="font-weight: 600;font-size: 44rpx;margin: 0 2rpx;">{{calcKilometers}}</text>
  58. <text style="font-weight: 500;font-size: 24rpx;color: #757575;">公里</text>
  59. </view>
  60. </view>
  61. <view class="frequency" style="padding: 0 30rpx">{{list[activeIndex].count}} 次</view>
  62. <view class="sports">
  63. <z-swiper ref="zSwiper" v-model="list" :options="{slidesPerView: 7,centeredSlides: true}" @init="init" @slideChange="onChange">
  64. <z-swiper-item v-for="(item,index) in list" :key="index">
  65. <view class="sportsitem" @click="slideTo(index)">
  66. <image
  67. :class="activeIndex == index ? 'active': activeIndex == index+1 || activeIndex == index-1 ?'next': activeIndex == index+2 || activeIndex == index-2 ?'next2':'sportsitem-img'"
  68. :src="item.icon"
  69. mode="aspectFill"></image>
  70. </view>
  71. </z-swiper-item>
  72. </z-swiper>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import {querySportRecord,querySportData} from '@/api/pages_watch/index.js'
  78. import myArcbar from './myArcbar.vue'
  79. export default {
  80. components: {
  81. myArcbar
  82. },
  83. data() {
  84. return {
  85. deviceId: '',
  86. activeIndex: 3,
  87. info: {
  88. calorie: 0,
  89. targetCalorie: 200,
  90. sport: 0,
  91. targetSport: 30,
  92. step: 0,
  93. targetStep: 5000,
  94. activity: 0,
  95. targetActivity: 1,
  96. },
  97. // 游泳,登山,骑行,跑步,健走,球类,其他运动
  98. list: [
  99. {
  100. name: '游泳',
  101. icon: '/static/images/pages_watch/icons/swim_icon.png',
  102. distance: 0,
  103. count: 0
  104. },
  105. {
  106. name: '登山',
  107. icon: '/static/images/pages_watch/icons/mountaineering_icon.png',
  108. distance: 0,
  109. count: 0
  110. },
  111. {
  112. name: '骑行',
  113. icon: '/static/images/pages_watch/icons/ride_icon.png',
  114. distance: 0,
  115. count: 0
  116. },
  117. {
  118. name: '跑步',
  119. icon: '/static/images/pages_watch/icons/run_icon.png',
  120. distance: 0,
  121. count: 0
  122. },
  123. {
  124. name: '健步走',
  125. icon: '/static/images/pages_watch/icons/walk_icon.png',
  126. distance: 0,
  127. count: 0
  128. },
  129. {
  130. name: '球类',
  131. icon: '/static/images/pages_watch/icons/ball_game_icon.png',
  132. distance: 0,
  133. count: 0
  134. },
  135. {
  136. name: '其他运动',
  137. icon: '/static/images/pages_watch/icons/other_icon.png',
  138. distance: 0,
  139. count: 0
  140. }
  141. ],
  142. chartData: {},
  143. opts: {
  144. color: ["#FD741D", "#FDC925", "#49B9FC", "#6DBF68"],
  145. title: {
  146. name: ''
  147. },
  148. subtitle: {
  149. name: "",
  150. },
  151. extra: {
  152. arcbar: {
  153. radius: 110,
  154. centerX: 0,
  155. centerY: 110,
  156. type: "default",
  157. width: 24,
  158. startAngle: 1,
  159. endAngle: 0,
  160. gap: 2,
  161. direction: "cw",
  162. backgroundColor: "#f5f5f5"
  163. }
  164. }
  165. }
  166. }
  167. },
  168. computed: {
  169. calcKilometers() {
  170. const kilometers = 1; // 1公里
  171. const meters = this.list[this.activeIndex].distance / 1000; // 将公里转换为米
  172. return meters.toFixed(2);
  173. }
  174. },
  175. methods: {
  176. init() {
  177. this.$refs.zSwiper.swiper.slideTo(this.activeIndex, 1000, false);
  178. },
  179. slideTo(index) {
  180. if(this.activeIndex == index) {
  181. // 跳转详情
  182. this.deviceId = uni.getStorageSync('deviceId') || ''
  183. if (this.$isLogin()) {
  184. if (!this.deviceId) {
  185. uni.showToast({
  186. title: "请先绑定设备",
  187. icon: "none"
  188. })
  189. return
  190. }
  191. const title = this.list[this.activeIndex].name
  192. uni.navigateTo({
  193. url: '/pages_watch/healthMonitoring/sportsList?title='+title
  194. })
  195. } else {
  196. this.$showLoginPage()
  197. }
  198. } else {
  199. this.$refs.zSwiper.swiper.slideTo(index, 1000, false);
  200. }
  201. },
  202. onChange(swiper) {
  203. this.activeIndex = swiper.activeIndex
  204. },
  205. getServerData(isFamily) {
  206. this.getData(isFamily)
  207. this.getSportRecord()
  208. },
  209. getData(isFamily) {
  210. querySportData({deviceId: uni.getStorageSync('deviceId') || '',isFamily:isFamily}).then((res) => {
  211. if(res.code == 200) {
  212. this.info = res.data
  213. this.$nextTick(()=>{
  214. this.$refs.myArcbar.initCircle(res.data)
  215. })
  216. }
  217. }).catch((err) => {});
  218. },
  219. getSportRecord() {
  220. querySportRecord({deviceId: uni.getStorageSync('deviceId') || ''}).then((res) => {
  221. if(res.code == 200 &&res.data &&res.data.length > 0) {
  222. let mergedList = this.list.map(item1 => {
  223. let item2 = res.data.find(item2 => item2.type == item1.name);
  224. return item2 ? {...item1, ...item2} : item1;
  225. });
  226. this.list = mergedList
  227. } else {
  228. this.list = this.list.map(item=>({
  229. ...item,
  230. distance: 0,
  231. count: 0
  232. }))
  233. }
  234. }).catch((err) => {});
  235. },
  236. handleDetail(url) {
  237. this.deviceId = uni.getStorageSync('deviceId') || ''
  238. if (this.$isLogin()) {
  239. if (!this.deviceId) {
  240. uni.showToast({
  241. title: "请先绑定设备",
  242. icon: "none"
  243. })
  244. return
  245. }
  246. if (url) {
  247. uni.navigateTo({
  248. url: url
  249. })
  250. } else {
  251. uni.showToast({
  252. title: '功能开发中...',
  253. icon: 'none',
  254. position: 'top',
  255. duration: 2000
  256. })
  257. }
  258. } else {
  259. this.$showLoginPage()
  260. }
  261. },
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .sportsitem {
  267. width: 98rpx;
  268. height: 98rpx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. &-img {
  273. width: 66rpx;
  274. height: 66rpx;
  275. opacity: 0.5;
  276. }
  277. }
  278. .active {
  279. width: 88rpx;
  280. height: 88rpx;
  281. &-img {
  282. opacity: 1;
  283. }
  284. }
  285. .next {
  286. width: 80rpx;
  287. height: 80rpx;
  288. &-img {
  289. opacity: 0.8;
  290. }
  291. }
  292. .next2 {
  293. width: 72rpx;
  294. height: 72rpx;
  295. &-img {
  296. opacity: 0.7;
  297. }
  298. }
  299. .sportsbox {
  300. background: #FFFFFF;
  301. border-radius: 16rpx 16rpx 16rpx 16rpx;
  302. margin-bottom: 16rpx;
  303. padding: 32rpx 0;
  304. .icon {
  305. width: 32rpx;
  306. height: 32rpx;
  307. margin-right: 8rpx;
  308. }
  309. .num {
  310. margin-right: 5rpx;
  311. font-weight: 600;
  312. font-size: 44rpx;
  313. color: #222222;
  314. }
  315. &-echart {
  316. min-height: 264rpx;
  317. }
  318. &-list {
  319. width: 100%;
  320. flex-wrap: wrap;
  321. margin-top: 46rpx;
  322. margin-bottom: -46rpx;
  323. }
  324. &-item {
  325. width: 50%;
  326. box-sizing: border-box;
  327. overflow: hidden;
  328. font-family: PingFang SC, PingFang SC;
  329. font-weight: 500;
  330. font-size: 22rpx;
  331. color: #757575;
  332. // padding: 0 40rpx;
  333. margin-bottom: 46rpx;
  334. .value {
  335. margin-top: 10rpx;
  336. font-weight: 400;
  337. font-size: 26rpx;
  338. color: #999999;
  339. }
  340. }
  341. .sportstitle {
  342. font-family: PingFang SC, PingFang SC;
  343. font-weight: 500;
  344. font-size: 30rpx;
  345. color: #222222;
  346. }
  347. .sportsicon {
  348. width: 40rpx;
  349. height: 40rpx;
  350. margin-right: 16rpx;
  351. }
  352. .frequency {
  353. text-align: right;
  354. margin-top: 6rpx;
  355. font-weight: 500;
  356. font-size: 24rpx;
  357. color: #757575;
  358. }
  359. .sports {
  360. padding-top: 24rpx;
  361. }
  362. }
  363. </style>