天波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.

168 lines
5.9KB

  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. export default {
  44. name: 'psychologicalMain',
  45. data(){
  46. return {
  47. healhtList: [
  48. /* { value: 40, name: '抑郁倾向', class: 'depression',result: '无抑郁倾向', time: '17:52', img: require('@/assets/img/regardless.png') },
  49. { value: 55, name: '压力', class: 'stress', result: '轻度压力', time: '17:52', img: require('@/assets/img/regardless.png') },
  50. { value: 75, name: '疲劳', class: 'tiredness', result: '中度疲劳', time: '17:52', img: require('@/assets/img/moderate.png') }, */
  51. ],
  52. uid: '',
  53. routeDate: '',
  54. params: {}
  55. }
  56. },
  57. computed: {
  58. isShowLeft() {
  59. return this.$route.query.fromUrl !== undefined;
  60. }
  61. },
  62. created() {
  63. this.loadParams();
  64. this.getHomeData();
  65. },
  66. mounted() {
  67. window.document.title = '心理监测';
  68. },
  69. methods: {
  70. loadParams() {
  71. let params = this.$route.query;
  72. if (params) {
  73. this.uid = params.uid;
  74. this.routeDate = params.date;
  75. this.params = params;
  76. }
  77. },
  78. getHomeData() {
  79. this.$toast.loading('数据加载中');
  80. console.log("this.$store.getters.ssjlToken", this.$store.getters.ssjlToken);
  81. let reqUrl = `https://dbmq.rzliot.com/heart/api/Data/GetHomeData`;
  82. let reqParams = {
  83. uid: this.uid,
  84. date: this.routeDate || this.$dayjs(new Date()).format('YYYY-MM-DD')
  85. };
  86. axios.get(reqUrl, {
  87. params: { ...reqParams },
  88. headers: { 'AuthToken': this.$store.getters.ssjlToken }
  89. }).then(res => {
  90. console.log("res", res);
  91. const data = res.data.response;
  92. this.healhtList = [
  93. // 抑郁
  94. { value: data.DepScore, name: '抑郁倾向', class: 'depression', result: data.DepDesc, time: data.DepMeasureTime ? this.$dayjs(data.DepMeasureTime).format('HH:mm'): '', level: data.DepLevel, img: this.calcImg(data.DepLevel) },
  95. // 压力
  96. { value: data.StressScore, name: '压力', class: 'stress', result: data.StressDesc, time: data.StressMeasureTime ? this.$dayjs(data.StressMeasureTime).format('HH:mm') : '', level: data.StressLevel, img: this.calcImg(data.StressLevel) },
  97. // 疲劳
  98. { value: data.TirScore, name: '疲劳', class: 'tiredness', result: data.TirDesc, time: data.TirMeasureTime ? this.$dayjs(data.TirMeasureTime).format('HH:mm') : '', level: data.TirLevel, img: this.calcImg(data.TirLevel) },
  99. ];
  100. this.$toast.success('数据加载完成');
  101. }).catch(() =>{}).finally(() => { this.$toast.clear() })
  102. },
  103. onClick(item) {
  104. this.params.name = item.class;
  105. this.$router.replace({
  106. name: 'psychological',
  107. query: {
  108. name: item.class,
  109. uid: this.uid,
  110. date: this.routeDate,
  111. ...this.params
  112. }
  113. })
  114. },
  115. onNavBack() {
  116. if(this.isShowLeft && this.$route.query.fromUrl !== undefined) {
  117. window.location.href = `${this.$route.query.fromUrl}/#/device`;
  118. } else {
  119. this.$router.go(-1);
  120. }
  121. },
  122. // 计算表情
  123. calcImg(level) {
  124. let imgUrl = '';
  125. switch(level) {
  126. case '0':
  127. imgUrl = require('@/assets/img/regardless.png');
  128. break;
  129. case '1':
  130. imgUrl = require('@/assets/img/regardless.png');
  131. break;
  132. case '2':
  133. imgUrl = require('@/assets/img/moderate.png');
  134. break;
  135. case '3':
  136. imgUrl = require('@/assets/img/moderate.png');
  137. break;
  138. }
  139. return imgUrl;
  140. },
  141. // 计算颜色
  142. calcColor(value) {
  143. let color = "";
  144. if (value <= 40) {
  145. color = "#62BD48";
  146. } else if (value > 40 && value <= 65) {
  147. color = "#FEC350";
  148. } else if (value > 65 && value <= 80) {
  149. color = "#F86825";
  150. } else if (value > 80) {
  151. color = "#EB1D15";
  152. } else {
  153. color = "";
  154. }
  155. return color;
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. @import "./index.scss";
  162. </style>