天波h5前端应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.3KB

  1. <template>
  2. <div class="psychological-main-container">
  3. <van-nav-bar title="今日情绪" :border="true" @click-left="onNavBack">
  4. <template #left>
  5. <div v-show="isShowLeft" class="nav-bar-title">
  6. <van-icon name="arrow-left" size="23"/><span>返回</span>
  7. </div>
  8. </template>
  9. <template #title>
  10. <span>今日情绪</span>
  11. </template>
  12. </van-nav-bar>
  13. <div class="main">
  14. <div class="list">
  15. <div v-for="(item,index) in healhtList" :key="index" :class="['item', item.class]" @click="onClick(item)">
  16. <p class="health-value" :style="{ color: calcColor(item.value) }">
  17. {{ item.value || '--' }}
  18. </p>
  19. <p class="health-name">
  20. {{ item.name || '--'}}
  21. </p>
  22. <div class="health-result">
  23. <div :class="['left', item.class]">
  24. <p class="result">
  25. {{ item.result || '暂无数据'}}
  26. </p>
  27. </div>
  28. <div class="right">
  29. <!-- img -->
  30. <img :src="item.img" alt="">
  31. </div>
  32. </div>
  33. <div class="health-time">
  34. <p class="time">{{ item.time || '--' }}</p>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import axios from "axios";
  43. import { isNotNull} from "@/utils/index";
  44. export default {
  45. name: 'psychologicalMain',
  46. data(){
  47. return {
  48. healhtList: [
  49. /* { value: 40, name: '抑郁倾向', class: 'depression',result: '无抑郁倾向', time: '17:52', img: require('@/assets/img/regardless.png') },
  50. { value: 55, name: '压力', class: 'stress', result: '轻度压力', time: '17:52', img: require('@/assets/img/regardless.png') },
  51. { value: 75, name: '疲劳', class: 'tiredness', result: '中度疲劳', time: '17:52', img: require('@/assets/img/moderate.png') }, */
  52. ],
  53. uid: '',
  54. routeDate: '',
  55. params: {}
  56. }
  57. },
  58. computed: {
  59. isShowLeft() {
  60. return isNotNull(this.$route.query.fromUrl);
  61. }
  62. },
  63. created() {
  64. this.loadParams();
  65. this.getHomeData();
  66. },
  67. mounted() {
  68. window.document.title = '心理监测';
  69. },
  70. methods: {
  71. loadParams() {
  72. let params = this.$route.query;
  73. if (params) {
  74. this.uid = params.uid;
  75. this.routeDate = params.date;
  76. this.params = params;
  77. this.$store.commit('ssjlToken', params.accessToken);
  78. }
  79. },
  80. getHomeData() {
  81. this.$toast.loading('数据加载中');
  82. console.log("this.$store.getters.ssjlToken", this.$store.getters.ssjlToken);
  83. let reqUrl = `https://dbmq.rzliot.com/heart/api/Data/GetHomeData`;
  84. let reqParams = {
  85. uid: this.uid,
  86. date: this.routeDate || this.$dayjs(new Date()).format('YYYY-MM-DD')
  87. };
  88. axios.get(reqUrl, {
  89. params: { ...reqParams },
  90. headers: { 'AccessToken': this.$store.getters.ssjlToken }
  91. }).then(res => {
  92. console.log("res", res);
  93. const data = res.data.response;
  94. this.healhtList = [
  95. // 抑郁
  96. { value: data.DepScore, name: '抑郁倾向', class: 'depression', result: data.DepDesc, time: data.DepMeasureTime ? this.$dayjs(data.DepMeasureTime).format('HH:mm'): '', level: data.DepLevel, img: data.DepScore ? this.calcImg(data.DepLevel, 'depression') : ''},
  97. // 压力
  98. { value: data.StressScore, name: '压力', class: 'stress', result: data.StressDesc, time: data.StressMeasureTime ? this.$dayjs(data.StressMeasureTime).format('HH:mm') : '', level: data.StressLevel, img: data.StressScore ? this.calcImg(data.StressLevel, 'stress') : ''},
  99. // 疲劳
  100. { value: data.TirScore, name: '疲劳', class: 'tiredness', result: data.TirDesc, time: data.TirMeasureTime ? this.$dayjs(data.TirMeasureTime).format('HH:mm') : '', level: data.TirLevel, img: data.TirScore ? this.calcImg(data.TirLevel, 'tiredness') : '' },
  101. ];
  102. this.$toast.success('数据加载完成');
  103. }).catch(() =>{}).finally(() => { this.$toast.clear() })
  104. },
  105. onClick(item) {
  106. this.params.name = item.class;
  107. this.$router.replace({
  108. name: 'psychological',
  109. query: {
  110. name: item.class,
  111. uid: this.uid,
  112. date: this.routeDate,
  113. ...this.params
  114. }
  115. })
  116. },
  117. onNavBack() {
  118. if(this.isShowLeft) {
  119. window.location.href = `${this.$route.query.fromUrl}/#/device`;
  120. } else {
  121. this.$router.go(-1);
  122. }
  123. },
  124. // 计算表情
  125. calcImg(level, name) {
  126. let imgUrl = '';
  127. /* imgUrl = require(`@/assets/img/psychological/${name}_${level}.png`); */
  128. let numLevel = Number(level);
  129. console.log(`@/assets/img/psychological/${name}_${numLevel}.png`);
  130. imgUrl = require(`@/assets/img/psychological/${name}_${numLevel + 1}.png`);
  131. /* switch(level) {
  132. case '0':
  133. imgUrl = require(`@/assets/img/psychological/${name}_${numLevel + 1}.png`);
  134. break;
  135. case '1':
  136. imgUrl = require('@/assets/img/regardless.png');
  137. break;
  138. case '2':
  139. imgUrl = require('@/assets/img/moderate.png');
  140. break;
  141. case '3':
  142. imgUrl = require('@/assets/img/moderate.png');
  143. break;
  144. } */
  145. return imgUrl;
  146. },
  147. // 计算颜色
  148. calcColor(value) {
  149. let color = "";
  150. if (value <= 40) {
  151. color = "#62BD48";
  152. } else if (value > 40 && value <= 65) {
  153. color = "#FEC350";
  154. } else if (value > 65 && value <= 80) {
  155. color = "#F86825";
  156. } else if (value > 80) {
  157. color = "#EB1D15";
  158. } else {
  159. color = "";
  160. }
  161. return color;
  162. }
  163. }
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. @import "./index.scss";
  168. </style>