天波h5前端应用
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1302 líneas
51KB

  1. <template>
  2. <div class="psychological-container">
  3. <van-nav-bar :title="emoName + '监测'" :border="true" :left-arrow="true" @click-left="onNavBack">
  4. <template #left>
  5. <van-icon name="arrow-left" size="24" style="padding: 0"/>
  6. </template>
  7. </van-nav-bar>
  8. <div class="main">
  9. <div class="top">
  10. <!-- 日期选择 -->
  11. <!-- TODO 后续可做成一个组件,方便调用 -->
  12. <div class="tab-bar">
  13. <div class="date-tab-con">
  14. <div class="date-tab-list">
  15. <div
  16. :class="['date-tab-item', {active: current === index, notClick: false}]"
  17. @click="onTabClick(item.value, index)"
  18. v-for="(item, index) in dateList"
  19. :key="index"
  20. >
  21. <span>{{item.text}}</span>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <!-- 标题 -->
  27. <div class="title">
  28. <div class="title-left">{{ titleLeft }}<van-icon name="question-o" @click="onHelp"/></div>
  29. <div class="title-right" v-show="currentDays === 0">
  30. <p @click="onHistory">历史监测</p>
  31. </div>
  32. </div>
  33. <!-- 日历 -->
  34. <van-dialog
  35. class="calenddar-dialog"
  36. v-model="calendarDialogShow"
  37. :show-confirm-button="false"
  38. :show-cancle-button="false"
  39. :close-on-click-overlay="true"
  40. ref="calenddarDialog"
  41. >
  42. <template #default>
  43. <div class="calendar" ref="calendarCon">
  44. <van-calendar
  45. v-model="calendarShow"
  46. :min-date="minDate"
  47. :max-date="maxDate"
  48. :default-date="defaultDate"
  49. :round="false"
  50. :poppable="false"
  51. color="#62BD48"
  52. :show-confirm="false"
  53. :show-title="false"
  54. :show-subtitle="false"
  55. :formatter="formatter"
  56. @select="onSelect"
  57. />
  58. </div>
  59. </template>
  60. </van-dialog>
  61. <!-- 监测次数 -->
  62. <div class="monitoring-count">
  63. <p>监测次数:{{ monitoringCount || '0' }}次</p>
  64. </div>
  65. <!-- 折线图-非日报 -->
  66. <div class="pie-chart-con">
  67. <div class="pie-chart-left">
  68. <div id="pieChart" ref="pieChart"></div>
  69. </div>
  70. <div class="pie-chart-right">
  71. <div class="list">
  72. <div class="item" v-for="(item, index) in pieRightList" :key="index">
  73. <div class="item-left">
  74. <div class="circle" :style="{backgroundColor: item.color}"></div>
  75. <span class="text">{{ item.text || '--' }}</span>
  76. </div>
  77. <div class="item-right">
  78. <span :style="{color: item.color}">{{ item.count ? item.count + '次' : '0次'}}</span>
  79. <label :style="{color: item.color}">{{ item.percentage ? '(' + item.percentage + '%' + ')' : '(0%)'}}</label>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- 统计 -->
  86. <div class="statistics">
  87. <div class="list">
  88. <div class="item" v-for="(item, index) in statisticsList" :key="index">
  89. <div class="top">
  90. <span>{{ item.label || '--' }}</span>
  91. </div>
  92. <div class="middle">
  93. <span
  94. :style="{ color: calcColor(item.value)}"
  95. >{{ item.value || '--' }}</span>
  96. </div>
  97. <div class="bottom">
  98. <span>{{ item.time || '--' }}</span>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. <!-- 分割线 -->
  105. <div class="line"></div>
  106. <!-- 底部 -->
  107. <div class="bottom">
  108. <div class="echart-container">
  109. <div class="echart" ref="charts"></div>
  110. </div>
  111. <div class="line-gray"></div>
  112. <div class="result" v-if="monitoringCount == ''">
  113. <div class="result-con">
  114. <div class="title ">
  115. <span class="title-no-data">结果解读</span>
  116. <div class="no-data">
  117. <img src="../../../assets/img/no_data_01.png" alt />
  118. <p>暂无数据</p>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="result" v-else>
  124. <div class="result-con reminder" v-show="current === 0 ">
  125. <div class="title">
  126. <span class="title-reminder">结果解读</span>
  127. <p class="title-emo" :style="{color: currentColor}">{{ result }}</p>
  128. <span class="font-28"><!-- 继续保持积极乐观,培养健康的生活习惯,预防消极事件对情绪带来的不良影响。 -->{{ advice }}</span>
  129. </div>
  130. <div class="friendly-reminder" v-if="emoType === 2">
  131. <p :style="{color: currentColor}">友情提示:</p>
  132. <span>如果您发现抑郁倾向分值升高或处于轻度水平,不需要过度紧张,这可能是由正常的情绪波动或者生活习惯(睡眠时间、运动量等)的改变造成的。如果您发现抑郁倾向分值连续7天及以上处于中度或重度水平,建议您寻求家人朋友或心理咨询师的帮助,及早进行干预。</span>
  133. </div>
  134. <div class="warm-reminder">
  135. <p :style="{color: currentColor}">温馨提示:</p>
  136. <span>{{ warmTips }}</span>
  137. </div>
  138. </div>
  139. <div class="result-con" v-show="current > 0">
  140. <div class="title">
  141. <span class="title-text">{{ surveyTitle }}</span>
  142. <div class="mood-list" v-if="emotionList.length > 0">
  143. <div class="item" v-for="(item, index) in emotionList" :key="index">
  144. <p>
  145. <span
  146. :style="{color: item.color}"
  147. class="day"
  148. >{{ item.days }}</span>
  149. <span class="day-text">天</span>
  150. </p>
  151. <p>{{ item.text }}</p>
  152. </div>
  153. </div>
  154. <div class="mood-list-no-data" v-else>
  155. <div class="no-data">
  156. <img src="../../../assets/img/no_data_01.png" alt />
  157. <p>暂无数据</p>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <!-- -->
  164. </div>
  165. </div>
  166. <!-- 弹出层 -->
  167. <van-popup v-model="isPopup">
  168. <div class="popup">
  169. <div class="item science-tips first" v-if="emoType === 2">
  170. <div class="tips"><h5>小科普</h5></div>
  171. <p>抑郁症是一种心理疾病,严重时可发展为精神障碍。然而当我们体会到了痛苦、悲伤、和郁闷等负面情绪,并不意味着我们就是抑郁症。日常的短时的喜、怒、哀、乐,都是正常的情绪变化,然而长期的低落情绪、兴趣缺失等可能会让我们有抑郁的风险。</p>
  172. </div>
  173. <div class="item" >
  174. <h5 v-html="title1"></h5>
  175. <div v-html="article1"></div>
  176. </div>
  177. <div class="item">
  178. <h5 v-html="title2"></h5>
  179. <div v-html="article2"></div>
  180. </div>
  181. <van-button size="large" @click="onClose">返回</van-button>
  182. </div>
  183. </van-popup>
  184. </div>
  185. </template>
  186. <script>
  187. import { EmotionModel } from "@/config/models";
  188. import axios from "axios";
  189. export default {
  190. name: "psychological-monitor",
  191. data() {
  192. return {
  193. // 日期选择标签
  194. dateList: [
  195. { name: "today", text: "今天", value: 0 },
  196. { name: "week", text: "7天", value: 7 },
  197. { name: "month", text: "30天", value: 30 }
  198. ],
  199. current: 0, // 日期选择标签-当前选中的标签
  200. currentDays: 0, //日期选择标签-日期参数
  201. emotionData: [], //情绪数据,TODO 接口对接
  202. echarts: null, //折线图
  203. itemHeight: Number(
  204. ((document.body.clientWidth / 750) * 95).toFixed()
  205. ), // 日历组件item高度
  206. xAxisData: [], //图表x轴展示的数据
  207. monitoringCount: "", //监测次数
  208. pieEcharts: null, //饼状图
  209. pieData: [], //饼状图数据
  210. //饼状图右边数据,TODO 根据接口数据和 模块 重新封装数组
  211. pieRightList: [
  212. /* {
  213. text: "无情绪倾向",
  214. count: 12,
  215. percentage: "80",
  216. color: "#62BD48"
  217. },
  218. {
  219. text: "轻度情绪倾向",
  220. count: 2,
  221. percentage: "80",
  222. color: "#ffde00"
  223. },
  224. {
  225. text: "中度情绪倾向",
  226. count: 1,
  227. percentage: "80",
  228. color: "#ff8a00"
  229. },
  230. {
  231. text: "重度情绪倾向",
  232. count: 1,
  233. percentage: "80",
  234. color: "#d70d0d"
  235. } */
  236. ],
  237. // 情绪状态列表
  238. statisticsList: [
  239. /* { label: "最大值", value: "75", time: "08:15" },
  240. { label: "最小值", value: "40", time: "10:15" },
  241. { label: "最近值", value: "50", time: "18:15" } */
  242. ],
  243. // 周报-情绪计算
  244. emotionList: [
  245. /* { days: "5", text: "无情绪倾向", color: "#62BD48" },
  246. { days: "4", text: "轻度情绪倾向", color: "#ffde00" },
  247. { days: "3", text: "中度情绪倾向", color: "#ff8a00" },
  248. { days: "2", text: "重度情绪倾向", color: "#ACACAC" } */
  249. ],
  250. // 弹窗-日历是否显示
  251. calendarDialogShow: false,
  252. // 日历是否显示,默认为true
  253. calendarShow: true,
  254. // 日历 默认最小可选择日期,默认为最近1个月
  255. minDate: new Date(
  256. this.$dayjs()
  257. .month(this.$dayjs().month() - 1)
  258. .hour(0)
  259. .minute(0)
  260. .second(0)
  261. .format()
  262. ),
  263. // 日历 默认最小可选择日期,默认为当前时间
  264. maxDate: new Date(
  265. this.$dayjs()
  266. .hour(0)
  267. .minute(0)
  268. .second(0)
  269. .format()
  270. ),
  271. // 默认日历日期时间
  272. defaultDate: new Date(
  273. this.$dayjs()
  274. .hour(0)
  275. .minute(0)
  276. .second(0)
  277. .format()
  278. ),
  279. // 路由传过来的情绪参数
  280. emoName: null,
  281. // 默认折线图 Series 配置
  282. defaultSeries: null,
  283. // 非日报折线图 Series 配置
  284. weekAndMonthSeries: null,
  285. // 当前情绪类型
  286. emoType: null,
  287. // 结果解读
  288. result: "",
  289. // 需要高亮的日期数组
  290. highlightDates: [],
  291. // 选中的日历日期
  292. selectDate: '',
  293. uid: '',
  294. // 建议
  295. advice: '',
  296. // 底部天数标题
  297. surveyTitle: '' || '7天概览',
  298. // 路由中的日期
  299. routeDate: '',
  300. // 路由参数
  301. params: {},
  302. // 是否显示帮助
  303. isPopup: false,
  304. // 结果等级
  305. resultLevel: '',
  306. // 轻度级别颜色
  307. mildColor: '#ffde00',
  308. // 中度级别颜色
  309. severeColor: '#ff8a00',
  310. // 重度级别颜色
  311. moderateColor: '#d70d0d',
  312. // 7天和30天最大数据列表
  313. weekAndMonData: [],
  314. };
  315. },
  316. computed: {
  317. // 默认折线图配置,echarts 具体配置 见 https://echarts.apache.org/zh/option.html#title
  318. defaultOptions() {
  319. return {
  320. time: {
  321. useUTC: false
  322. },
  323. title: {
  324. text: this.echartsTitle,
  325. left: 1,
  326. right: 25,
  327. bottom: 20,
  328. top: "3%",
  329. textStyle: {
  330. fontSize: 16,
  331. fontWeight: "bold"
  332. }
  333. },
  334. legend: {
  335. width: "65%",
  336. orient: "horizontal",
  337. right: 'right',
  338. top: 1,
  339. bottom: "1%",
  340. itemHeight: 12,
  341. itemWidth: 12,
  342. itemGap: 10,
  343. align: 'left',
  344. selectedMode: false,
  345. data: [
  346. {
  347. name: `轻度${this.emoName}倾向`,
  348. icon: "rect",
  349. itemStyle: {
  350. color: "#ffde00"
  351. },
  352. textStyle: {
  353. fontSize: 12
  354. }
  355. },
  356. {
  357. name: `中度${this.emoName}倾向`,
  358. itemStyle: {
  359. color: "#ff8a00"
  360. },
  361. icon: "rect",
  362. textStyle: {
  363. fontSize: 12
  364. }
  365. },
  366. {
  367. name: `重度${this.emoName}倾向`,
  368. itemStyle: {
  369. color: "#d70d0d",
  370. },
  371. icon: "rect",
  372. textStyle: {
  373. fontSize: 12
  374. }
  375. },
  376. {
  377. name: `无${this.emoName}倾向`,
  378. icon: "rect",
  379. itemStyle: {
  380. color: "#62BD48"
  381. },
  382. textStyle: {
  383. // 项目遗留问题,新项目不需重新转换文字大小
  384. fontSize: 12
  385. }
  386. },
  387. ],
  388. formatter: function(name) {
  389. // 自定义显示内容
  390. if (name.length > 6) {
  391. return (
  392. name.substring(0, 6) + "\n" + name.substring(6)
  393. );
  394. } else {
  395. return name;
  396. }
  397. }
  398. },
  399. grid: {
  400. show: true,
  401. borderWidth: 1,
  402. top: '20%',
  403. left: '1%',
  404. right: '5%',
  405. bottom: '10%',
  406. containLabel: true
  407. },
  408. xAxis: {
  409. type: "category",
  410. axisLine: {
  411. show: false
  412. },
  413. textStyle: {
  414. fontSize: 10
  415. },
  416. axisTick: {
  417. show: false
  418. },
  419. splitLine: {
  420. show: false,
  421. lineStyle: {
  422. color: "#ddd",
  423. width: 2
  424. }
  425. },
  426. nameLocation: 'center',
  427. axisLabel: {
  428. show: true,
  429. fontSize: 12,
  430. showMinLabel: true, //显示最小值
  431. showMaxLabel: true, //显示最大值
  432. },
  433. data: this.xAxisData
  434. },
  435. dataZoom: [
  436. /* {
  437. type: "inside",
  438. start: 0,
  439. end: 100,
  440. }, */
  441. {
  442. start: 0,
  443. end: 100,
  444. textStyle: {
  445. color: "#FFF",
  446. fontSize: 14
  447. },
  448. show: true,
  449. height: 15,
  450. bottom: 5,
  451. handleStyle: {
  452. borderWidth: 1,
  453. borderCap: "square"
  454. }
  455. }
  456. ],
  457. tooltip: {
  458. trigger: "axis",
  459. textStyle: {
  460. fontSize: 14,
  461. align: "center"
  462. },
  463. formatter: function(params) {
  464. return params[0].marker + params[0].name + '--' + params[0].value + '</br>'
  465. }
  466. },
  467. yAxis: {
  468. type: "value",
  469. max: 100,
  470. min: 0,
  471. interval: 20,
  472. splitNumber : 1,
  473. boundaryGap : [ '5%', '5%' ],
  474. nameTextStyle: {
  475. fontSize: 13
  476. },
  477. alignTicks: true,
  478. axisTick: {
  479. show: true
  480. },
  481. axisLabel: {
  482. show: true,
  483. fontSize: 13,
  484. },
  485. splitLine: {
  486. show: true,
  487. lineStyle: {
  488. color: "#ddd",
  489. width: 1
  490. }
  491. }
  492. },
  493. series: [
  494. {
  495. name: `无${this.emoName}倾向`,
  496. type: "line",
  497. padding: 5,
  498. data: this.emotionData,
  499. symbol: "circle",
  500. symbolSize: 8,
  501. },
  502. {
  503. name: `轻度${this.emoName}倾向`,
  504. type: "line",
  505. data: ""
  506. },
  507. {
  508. name: `中度${this.emoName}倾向`,
  509. type: "line",
  510. data: ""
  511. },
  512. {
  513. name: `重度${this.emoName}倾向`,
  514. type: "line",
  515. data: ""
  516. }
  517. ]
  518. };
  519. },
  520. imei() {
  521. return this.$store.getters.serialNo;
  522. },
  523. // 饼状图配置
  524. pieOption() {
  525. return {
  526. tooltip: {
  527. trigger: "item",
  528. textStyle: {
  529. fontSize: 14
  530. },
  531. position: "right"
  532. },
  533. legend: {
  534. top: "5%",
  535. left: "center",
  536. show: false
  537. },
  538. series: [
  539. {
  540. type: "pie",
  541. radius: ["40%", "80%"],
  542. avoidLabelOverlap: false,
  543. startAngle: 270, // 设置逆时针渲染
  544. itemStyle: {
  545. borderRadius: 5,
  546. borderColor: "#fff",
  547. borderWidth: 2,
  548. fontSize: 16
  549. },
  550. label: {
  551. show: false,
  552. position: "center",
  553. fontSize: 16
  554. },
  555. emphasis: {
  556. label: {
  557. show: false,
  558. fontSize: 16,
  559. fontWeight: "bold"
  560. }
  561. },
  562. labelLine: {
  563. show: false
  564. },
  565. data: this.pieData
  566. }
  567. ]
  568. };
  569. },
  570. titleLeft() {
  571. let text = this.emoName === 'depression' ? '趋势' : '';
  572. let today = '';
  573. if(this.currentDays !== 0) {
  574. today = '';
  575. } else {
  576. today = this.$dayjs(this.selectDate || this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  577. }
  578. return `${today}${this.emoName}倾向${text}`;
  579. },
  580. // 折线图标题
  581. echartsTitle() {
  582. let today = '';
  583. if(this.currentDays !== 0) {
  584. today = '';
  585. } else {
  586. today = this.$dayjs(this.selectDate || this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  587. }
  588. return `${today}${this.emoName}数据图`;
  589. },
  590. warmTips() {
  591. return `正常连续佩戴手表,每半小时计算一个${this.emoName}分值,睡眠期间不进行计算。`
  592. },
  593. title1() {
  594. return EmotionModel[this.params.name].title1;
  595. },
  596. article1() {
  597. return EmotionModel[this.params.name].article1;
  598. },
  599. title2() {
  600. return EmotionModel[this.params.name].title2;
  601. },
  602. article2() {
  603. return EmotionModel[this.params.name].article2;
  604. },
  605. // 当前情绪颜色
  606. currentColor( ) {
  607. return this.calcResultColor(this.resultLevel) || "#62BD48"
  608. },
  609. },
  610. watch: {
  611. // 监听数据发生变化 初始化各项图表
  612. emotionData: {
  613. handler(n, o) {
  614. this.initEchart();
  615. },
  616. deep: true
  617. },
  618. xAxisData: {
  619. handler(n, o) {
  620. this.initEchart();
  621. },
  622. deep: true
  623. },
  624. pieData: {
  625. handler(n, o) {
  626. this.initPieEchart();
  627. },
  628. deep: true
  629. },
  630. },
  631. created() {
  632. // 读取路由传过来的参数,根据路由传过来的参数判断是哪种情绪
  633. this.loadParams();
  634. this.initEchartText();
  635. this.getPieData();
  636. this.getCalendarData();
  637. this.getPsychologiclData();
  638. },
  639. mounted() {
  640. this.initEchart();
  641. window.document.title = '心理监测';
  642. },
  643. methods: {
  644. loadParams() {
  645. let params = this.$route.query;
  646. if (params) {
  647. this.emoName = EmotionModel[params.name].name;
  648. this.emoType = EmotionModel[params.name].type;
  649. this.uid = params.uid;
  650. this.routeDate = params.date;
  651. this.params = params;
  652. if(params.date) {
  653. this.dateList[0].text = this.$dayjs(params.date).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : this.$dayjs(params.date).format("MM-DD");
  654. this.defaultDate = new Date(
  655. this.$dayjs(params.date)
  656. .hour(0)
  657. .minute(0)
  658. .second(0)
  659. .format()
  660. );
  661. }
  662. }
  663. },
  664. // 获取这个月中有数据的日期,控制日历组件的日期样式
  665. getCalendarData() {
  666. let currentDate = new Date();
  667. // 获取最近30天的心情等级日历数据
  668. let dateList = this.getPostDate(currentDate, 30, true);
  669. let reqUrl = `https://dbmq.rzliot.com/auth_heart/api/Data/GetCalendarData`;
  670. let reqParams = {
  671. uid: this.uid,
  672. startDate: dateList[0],
  673. endDate: dateList[1],
  674. };
  675. axios.get(reqUrl, {
  676. params: { ...reqParams },
  677. headers: { 'AccessToken': this.$store.getters.ssjlToken }
  678. }).then(res => {
  679. if (res.data) {
  680. let data = res.data.response;
  681. // const mergedArr = [...new Set([...arr1, ...arr2, ...arr3])];
  682. /* let name = this.params.name.charAt(0).toUpperCase()+ this.params.name.slice(1); */
  683. let currentName = this.params.name;
  684. let list = [];
  685. if(currentName === 'stress') {
  686. list = data.Stress;
  687. } else if(currentName === 'depression') {
  688. list = data.Depression;
  689. } else {
  690. list = data.Tiredness;
  691. }
  692. list = list.map(item =>{
  693. item.Date = this.$dayjs(item.Date.replace(/-/g, "/")).format(
  694. "YYYY/MM/DD"
  695. );
  696. return item;
  697. })
  698. this.highlightDates = [...list];
  699. }
  700. })
  701. },
  702. // 获取饼状图数据,TODO 对接接口数据
  703. getPieData() {
  704. this.pieData = [
  705. { value: 12, name: "", itemStyle: { color: "green" } },
  706. { value: 2, name: "", itemStyle: { color: "orange" } },
  707. { value: 1, name: "", itemStyle: { color: "#FFC0CB" } },
  708. { value: 1, name: "", itemStyle: { color: "red" } }
  709. ];
  710. },
  711. // 获取情绪数据
  712. getPsychologiclData(date, startDate, endDate) {
  713. this.$toast.loading({
  714. message: '数据加载中'
  715. });
  716. let reqDate =
  717. date
  718. ? this.$dayjs(date).format("YYYY-MM-DD")
  719. : this.routeDate || this.$dayjs(this.defaultDate).format("YYYY-MM-DD") /* "2023-05-23" */;
  720. let reqParams = {
  721. uid: this.uid,
  722. startDate: startDate || reqDate,
  723. endDate: endDate || reqDate,
  724. type: this.emoType
  725. };
  726. console.log("请求参数", reqParams);
  727. let reqUrl = `https://dbmq.rzliot.com/auth_heart/api/Data/GetHisData`;
  728. axios
  729. .get(reqUrl, {
  730. params: { ...reqParams },
  731. headers: { 'AccessToken': this.$store.getters.ssjlToken }
  732. })
  733. .then(res => {
  734. if (res.data) {
  735. let data = res.data.response;
  736. // 监测次数
  737. this.monitoringCount = data.Count;
  738. this.pieRightList = [];
  739. this.statisticsList = [];
  740. this.emotionList = [];
  741. let None = {
  742. count: data.None,
  743. percentage: this.calcPercentage(
  744. data.None,
  745. data.Count
  746. ),
  747. text: `无${this.emoName}倾向`,
  748. color: "#62BD48"
  749. };
  750. let Mild = {
  751. count: data.Mild,
  752. percentage: this.calcPercentage(
  753. data.Mild,
  754. data.Count
  755. ),
  756. text: `轻度${this.emoName}倾向`,
  757. color: "#ffde00"
  758. };
  759. let Moderate = {
  760. count: data.Moderate,
  761. percentage: this.calcPercentage(
  762. data.Moderate,
  763. data.Count
  764. ),
  765. text: `中度${this.emoName}倾向`,
  766. color: "#ff8a00"
  767. };
  768. let Severe = {
  769. count: data.Severe,
  770. percentage: this.calcPercentage(
  771. data.Severe,
  772. data.Count
  773. ),
  774. text: `重度${this.emoName}倾向`,
  775. color: "#d70d0d"
  776. };
  777. // 饼状图右边数据
  778. this.pieRightList.push(None);
  779. this.pieRightList.push(Mild);
  780. this.pieRightList.push(Moderate);
  781. this.pieRightList.push(Severe);
  782. this.pieData = this.pieRightList.map(item => {
  783. item.value = item.count;
  784. item.itemStyle = {
  785. color: item.color
  786. };
  787. return item;
  788. });
  789. // 最大,最小和最近值
  790. let Max = {
  791. label: "最大值",
  792. value: data.Max,
  793. time: data.MaxDesc
  794. ? this.currentDays === 0 ? this.$dayjs(data.MaxDesc).format("HH:mm")
  795. : this.$dayjs(data.MaxDesc).format("MM/DD HH:mm")
  796. : ""
  797. };
  798. let Min = {
  799. label: "最小值",
  800. value: data.Min,
  801. time: data.MinDesc
  802. ? this.currentDays === 0 ? this.$dayjs(data.MinDesc).format("HH:mm")
  803. : this.$dayjs(data.MinDesc).format("MM/DD HH:mm")
  804. : ""
  805. };
  806. let Avg = {
  807. label: "平均值",
  808. value: data.Avg,
  809. time: data.AvgDesc
  810. ? this.currentDays === 0 ? this.$dayjs(data.AvgDesc).format("HH:mm")
  811. : this.$dayjs(data.AvgDesc).format("MM/DD HH:mm")
  812. : ""
  813. };
  814. let Current = {
  815. label: "最近值",
  816. value: data.Current,
  817. time: data.CurrentDesc
  818. ? this.currentDays === 0 ? this.$dayjs(data.CurrentDesc).format("HH:mm")
  819. : this.$dayjs(data.CurrentDesc).format("MM/DD HH:mm")
  820. : ""
  821. };
  822. this.statisticsList.push(Max);
  823. this.statisticsList.push(Min);
  824. this.statisticsList.push(Avg);
  825. this.statisticsList.push(Current);
  826. // 周报月报底部显示数据
  827. let NoneDay = {
  828. days: data.NoneDay,
  829. text: `无${this.emoName}倾向`,
  830. color: "#62BD48"
  831. };
  832. let MildDay = {
  833. days: data.MildDay,
  834. text: `轻度${this.emoName}倾向`,
  835. color: "#ffde00"
  836. };
  837. let ModerateDay = {
  838. days: data.ModerateDay,
  839. text: `中度${this.emoName}倾向`,
  840. color: "#ff8a00"
  841. };
  842. let SevereDay = {
  843. days: data.SevereDay,
  844. text: `重度${this.emoName}倾向`,
  845. color: "#d70d0d"
  846. };
  847. this.emotionList.push(NoneDay);
  848. this.emotionList.push(MildDay);
  849. this.emotionList.push(ModerateDay);
  850. this.emotionList.push(SevereDay);
  851. // 图表数据
  852. this.emotionData = data.ChartDatas.map(item => {
  853. return {
  854. value: item.Value,
  855. itemStyle: {
  856. color: this.calcResultColor(item.Level)
  857. }
  858. };
  859. });
  860. // 7天 和 30天柱形图显示
  861. this.weekAndMonData = data.ChartDatas.map((item, index) => {
  862. return {
  863. value: [index, item.MinValue, item.MaxValue],
  864. };
  865. });
  866. // x轴显示数据
  867. if(this.currentDays === 0) {
  868. // 显示今天数据
  869. this.xAxisData = data.ChartDatas.map(item => {
  870. return this.$dayjs(item.Key.replace(/-/g, "/")).format(
  871. "HH:mm"
  872. );
  873. });
  874. } else {
  875. this.xAxisData = data.ChartDatas.map(item => {
  876. return this.$dayjs(item.Key.replace(/-/g, "/")).format(
  877. "MM/DD"
  878. );
  879. });
  880. let emphasisStyle = {
  881. itemStyle: {
  882. shadowBlur: 10,
  883. shadowColor: 'rgba(0,0,0,0.3)'
  884. }
  885. };
  886. let that = this;
  887. // 7天和30天变成柱状图
  888. this.weekAndMonthSeries = [
  889. {
  890. name: '平均值',
  891. type: 'scatter',
  892. symbolSize: 8,
  893. data: this.emotionData,
  894. },
  895. {
  896. name: '',
  897. type: 'custom',
  898. data: this.weekAndMonData,
  899. renderItem: function (params, api) {
  900. var categoryIndex = api.value(0);
  901. var end = api.coord([categoryIndex, api.value(1)]);
  902. var start = api.coord([categoryIndex, api.value(2)]);
  903. var width = 8;
  904. var rectShape = that.$echarts.graphic.clipRectByRect(
  905. {
  906. x: start[0] - width / 2,
  907. y: start[1],
  908. width: 8,
  909. height: end[1] - start[1],
  910. },
  911. {
  912. x: params.coordSys.x,
  913. y: params.coordSys.y,
  914. width: params.coordSys.width,
  915. height: params.coordSys.height,
  916. }
  917. );
  918. if(rectShape) {
  919. rectShape.r = [10]
  920. };
  921. return (
  922. rectShape && {
  923. type: "rect",
  924. shape: rectShape,
  925. style: api.style(),
  926. }
  927. );
  928. },
  929. itemStyle: {
  930. opacity: 0.8,
  931. },
  932. encode: {
  933. y: [1, 2],
  934. x: 0,
  935. },
  936. },
  937. ];
  938. // 点击提示此时为空
  939. this.defaultOptions.tooltip = {
  940. trigger: "axis",
  941. formatter: function(params) {
  942. return params[0].marker + '平均值:' + params[0].name + '--' + params[0].value + '</br>' +
  943. params[1].marker + '最大值:' + params[1].name + '--' + params[1].value[2] + '</br>' +
  944. params[1].marker + '最小值:' + params[1].name + '--' + params[1].value[1];
  945. }
  946. };
  947. this.defaultOptions.series = this.weekAndMonthSeries;
  948. }
  949. // 结果解读
  950. this.result = data.Result;
  951. this.resultLevel = data.ResultLevel;
  952. this.advice = data.Advice;
  953. this.$toast.success({
  954. message: '数据加载完成'
  955. });
  956. }
  957. }).catch(() => {
  958. this.$dialog({
  959. message: '登录过期,请重新进入'
  960. })
  961. }).finally(() => { });
  962. },
  963. // 计算百分比
  964. calcPercentage(value, total) {
  965. if (
  966. typeof value !== "number" ||
  967. typeof total !== "number" ||
  968. total === 0
  969. ) {
  970. return 0;
  971. }
  972. let milValue = value * 1000;
  973. let milTotal = total * 1000;
  974. return Math.round((milValue / milTotal) * 100);
  975. },
  976. // 初始化图表的文字内容
  977. initEchartText() {
  978. let text = this.emoName === 'depression' ? '趋势' : '';
  979. let today = this.$dayjs(this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  980. this.result = `无${this.emoName}倾向`;
  981. this.defaultSeries = [
  982. {
  983. name: ``,
  984. type: "line",
  985. padding: 5,
  986. data: this.emotionData,
  987. symbol: "circle",
  988. symbolSize: 8, // 拐点圆的大小
  989. areaStyle: {},
  990. },
  991. {
  992. name: `轻度${this.emoName}倾向`,
  993. type: "line",
  994. padding: 10,
  995. data: "",
  996. symbol: "circle",
  997. symbolSize: 8, // 拐点圆的大小
  998. },
  999. {
  1000. name: `中度${this.emoName}倾向`,
  1001. type: "line",
  1002. data: ""
  1003. },
  1004. {
  1005. name: `重度${this.emoName}倾向`,
  1006. type: "line",
  1007. data: ""
  1008. }
  1009. ];
  1010. this.pieRightList = this.pieRightList.map(item => {
  1011. item.text = item.text.replace("情绪", this.emoName);
  1012. return item;
  1013. });
  1014. },
  1015. // 初始化饼状图
  1016. initPieEchart() {
  1017. if (
  1018. this.pieEcharts != null &&
  1019. this.pieEcharts != "" &&
  1020. this.pieEcharts != undefined
  1021. ) {
  1022. this.pieEcharts.dispose();
  1023. }
  1024. this.pieEcharts = this.$echarts.init(this.$refs.pieChart);
  1025. this.pieEcharts.setOption(this.pieOption);
  1026. },
  1027. // 格式化日期显示参数
  1028. formatter(day) {
  1029. const month = day.date.getMonth() + 1;
  1030. const date = day.date.getDate();
  1031. const formatDate = this.$dayjs(day.date).format("YYYY/MM/DD");
  1032. const currentDate = this.$dayjs(new Date()).format("YYYY/MM/DD");
  1033. day.className = "custom-calendar";
  1034. for( let h = 0; h < this.highlightDates.length; h ++) {
  1035. if (this.highlightDates[h].Date === formatDate) {
  1036. day.className = `highlight-border ${this.calcResultColor(this.highlightDates[h].SummaryLevel, true)}`;
  1037. } else if (formatDate === currentDate) {
  1038. day.text = '今天'
  1039. }
  1040. }
  1041. return day;
  1042. },
  1043. // 返回
  1044. onNavBack() {
  1045. this.params.name = '';
  1046. this.$router.replace({
  1047. name: 'psychologicalMain',
  1048. query: {
  1049. ...this.params
  1050. }
  1051. });
  1052. },
  1053. // 点击日期选择
  1054. onTabClick(value, index) {
  1055. this.current = index;
  1056. this.currentDays = value;
  1057. let currentDate = new Date();
  1058. let leftText = value === 0 ? '今天' : value === 7 ? '7天' : '30天';
  1059. this.surveyTitle = value === 7 ? '7天概览' : '30天概览';
  1060. if (value === 7) {
  1061. /* this.defaultOptions.xAxis.data = [
  1062. "周一",
  1063. "周二",
  1064. "周三",
  1065. "周四",
  1066. "周五",
  1067. "周六",
  1068. "周日"
  1069. ]; */
  1070. //this.defaultOptions.xAxis.data = this.xAxisData;
  1071. let dateList = this.getPostDate(currentDate, 6, true);
  1072. console.log("dateList", dateList);
  1073. this.getPsychologiclData('', dateList[0], dateList[1]);
  1074. } else if (value === 0) {
  1075. // 今天
  1076. this.defaultOptions.xAxis.data = this.xAxisData;
  1077. this.defaultOptions.series = this.defaultSeries;
  1078. this.defaultOptions.series[0].data = this.emotionData;
  1079. this.getPsychologiclData(this.selectDate ? this.selectDate : this .$dayjs(currentDate).format("YYYY-MM-DD"));
  1080. } else {
  1081. // 30天
  1082. this.defaultOptions.xAxis.data = this.xAxisData;
  1083. this.defaultOptions.series = this.defaultSeries;
  1084. this.defaultOptions.series[0].data = this.emotionData;
  1085. let dateList = this.getPostDate(currentDate, 30, true);
  1086. console.log("dateList", dateList);
  1087. this.getPsychologiclData('', dateList[0], dateList[1]);
  1088. }
  1089. },
  1090. getCurrentMonthStaAndEnd(currentDate) {
  1091. let list = [];
  1092. let monthStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1); // 获取本月第一天的日期时间
  1093. let monthEnd = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0, 23, 59, 59); // 获取本月最后一天的日期时间(时间为23:59:59)
  1094. list.push(this.$dayjs(monthStart).format("YYYY-MM-DD"));
  1095. list.push(this.$dayjs(monthEnd).format("YYYY-MM-DD"));
  1096. return list;
  1097. },
  1098. // 获取指定天数的起始日期
  1099. /**
  1100. *
  1101. * @param dateNow :Date类
  1102. * @param intervalDays :间隔天数
  1103. * @param bolPastTime :Boolean,判断在参数date之前,还是之后,
  1104. */
  1105. getPostDate(dateNow,intervalDays,bolPastTime) {
  1106. let oneDayTime = 24 * 60 * 60 * 1000;
  1107. let list = [];
  1108. let lastDay;
  1109. if(bolPastTime == true){
  1110. lastDay = new Date(dateNow.getTime() - intervalDays * oneDayTime);
  1111. list.push(this.formateDate(lastDay));
  1112. list.push(this.formateDate(dateNow));
  1113. }else{
  1114. lastDay = new Date(dateNow.getTime() + intervalDays * oneDayTime);
  1115. list.push(this.formateDate(dateNow));
  1116. list.push(this.formateDate(lastDay));
  1117. }
  1118. return list;
  1119. },
  1120. formateDate(time){
  1121. let year = time.getFullYear();
  1122. let month = time.getMonth() + 1;
  1123. let day = time.getDate();
  1124. if (month < 10) {
  1125. month = '0' + month
  1126. };
  1127. if (day < 10) {
  1128. day = '0' + day
  1129. };
  1130. return year + '-' + month + '-' + day + '';
  1131. },
  1132. // 字体大小转化
  1133. fontChar(res) {
  1134. const clientWidth =
  1135. window.innerWidth ||
  1136. document.documentElement.clientWidth ||
  1137. document.body.clientWidth;
  1138. if (!clientWidth) return;
  1139. let fontSize = clientWidth / 750;
  1140. return res * fontSize;
  1141. },
  1142. // 初始化折线图表
  1143. initEchart() {
  1144. if (
  1145. this.echarts != null &&
  1146. this.echarts != "" &&
  1147. this.echarts != undefined
  1148. ) {
  1149. this.echarts.dispose();
  1150. }
  1151. this.echarts = this.$echarts.init(this.$refs.charts);
  1152. this.echarts.setOption(this.defaultOptions);
  1153. },
  1154. // 点击历史监测,打开日历
  1155. onHistory() {
  1156. this.calendarDialogShow = true;
  1157. },
  1158. // 选择日历具体某一个日期
  1159. onSelect(value) {
  1160. const selectDate = this.$dayjs(value).format("YYYY-MM-DD");
  1161. this.dateList[0].text = this.$dayjs(value).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : this.$dayjs(value).format("MM-DD");
  1162. this.calendarDialogShow = false;
  1163. this.selectDate = selectDate;
  1164. this.getPsychologiclData(selectDate);
  1165. },
  1166. // 计算字体显示的颜色
  1167. calcColor(value) {
  1168. let color = "";
  1169. if (value <= 40) {
  1170. color = "#62BD48";
  1171. } else if (value > 40 && value <= 65) {
  1172. color = "#ffde00";
  1173. } else if (value > 65 && value <= 80) {
  1174. color = "#ff8a00";
  1175. } else if (value > 80) {
  1176. color = "#d70d0d";
  1177. } else {
  1178. color = "";
  1179. }
  1180. return color;
  1181. },
  1182. // 计算结果采用哪种颜色
  1183. calcResultColor(value, isCallBackClass) {
  1184. let color = "";
  1185. let className = "";
  1186. switch(value) {
  1187. case '0':
  1188. color = "#62BD48";
  1189. className = 'none';
  1190. break;
  1191. case '1':
  1192. color = "#ffde00";
  1193. className = 'mild';
  1194. break;
  1195. case '2':
  1196. color = "#ff8a00";
  1197. className = 'moderate';
  1198. break;
  1199. case '3':
  1200. color = "#d70d0d";
  1201. className = 'severe';
  1202. break;
  1203. }
  1204. return isCallBackClass ? className : color;
  1205. },
  1206. // 点击帮助
  1207. onHelp() {
  1208. this.isPopup = true;
  1209. },
  1210. // 关闭poup
  1211. onClose() {
  1212. this.isPopup = false;
  1213. }
  1214. }
  1215. };
  1216. </script>
  1217. <style lang="scss">
  1218. .van-nav-bar .van-icon {
  1219. padding-left: 10px;
  1220. }
  1221. .calenddar-dialog {
  1222. overflow: scroll;
  1223. }
  1224. .calendar {
  1225. overflow: scroll;
  1226. .van-calendar {
  1227. height: 350px;
  1228. .van-calendar__header {
  1229. display: none;
  1230. }
  1231. .van-calendar__days .van-calendar__day {
  1232. width: 27px;
  1233. height: 27px;
  1234. margin: 5px;
  1235. font-size: 12px;
  1236. &.custom-calendar {
  1237. width: 27px;
  1238. height: 27px;
  1239. }
  1240. &.highlight-border {
  1241. border: 1px solid #62bd48;
  1242. width: 27px;
  1243. height: 27px;
  1244. border-radius: 50%;
  1245. &.none {
  1246. border: 1px solid #62bd48;
  1247. }
  1248. &.mild {
  1249. border: 1px solid #ffde00;
  1250. }
  1251. &.moderate {
  1252. border: 1px solid #ff8a00;
  1253. }
  1254. &.severe {
  1255. border: 1px solid #d70d0d;
  1256. }
  1257. }
  1258. }
  1259. .van-calendar__selected-day {
  1260. width: 27px;
  1261. height: 27px;
  1262. border-radius: 50%;
  1263. font-size: 12px;
  1264. }
  1265. }
  1266. }
  1267. </style>
  1268. <style scoped lang="scss">
  1269. @import "./index.scss";
  1270. </style>