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

1400 lines
56KB

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