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

1267 line
49KB

  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, paddingTop: '3px'}">{{ 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: "#FEC350"
  223. },
  224. {
  225. text: "中度情绪倾向",
  226. count: 1,
  227. percentage: "80",
  228. color: "#F86825"
  229. },
  230. {
  231. text: "重度情绪倾向",
  232. count: 1,
  233. percentage: "80",
  234. color: "#EB1D15"
  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: "#FEC350" },
  247. { days: "3", text: "中度情绪倾向", color: "#F86825" },
  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. "2023-05-21",
  292. "2023-05-25",
  293. "2023-05-28",
  294. "2023-05-24"
  295. ],
  296. // 选中的日历日期
  297. selectDate: '',
  298. uid: '',
  299. advice: '',
  300. surveyTitle: '' || '本周概览',
  301. routeDate: '',
  302. params: {},
  303. isPopup: false,
  304. resultLevel: ''
  305. };
  306. },
  307. computed: {
  308. // 默认折线图配置,echarts 具体配置 见 https://echarts.apache.org/zh/option.html#title
  309. defaultOptions() {
  310. return {
  311. time: {
  312. useUTC: false
  313. },
  314. title: {
  315. text: this.echartsTitle,
  316. left: "1%",
  317. right: 20,
  318. bottom: 20,
  319. top: "3%",
  320. textStyle: {
  321. fontSize: 16,
  322. fontWeight: "bold"
  323. }
  324. },
  325. legend: {
  326. width: "60%",
  327. orient: "horizontal",
  328. right: 'right',
  329. top: "3%",
  330. bottom: "3%",
  331. itemHeight: 10,
  332. itemWidth: 10,
  333. itemGap: 5,
  334. align: 'auto',
  335. selectedMode: false,
  336. data: [
  337. {
  338. name: `轻度${this.emoName}倾向`,
  339. icon: "rect",
  340. itemStyle: {
  341. color: "#FFB481"
  342. },
  343. textStyle: {
  344. fontSize: 12
  345. }
  346. },
  347. {
  348. name: `中度${this.emoName}倾向`,
  349. itemStyle: {
  350. color: "#F86825"
  351. },
  352. icon: "rect",
  353. textStyle: {
  354. fontSize: 12
  355. }
  356. },
  357. {
  358. name: `重度${this.emoName}倾向`,
  359. itemStyle: {
  360. color: "#EB1D15",
  361. },
  362. icon: "rect",
  363. textStyle: {
  364. fontSize: 12
  365. }
  366. },
  367. {
  368. name: `无${this.emoName}倾向`,
  369. icon: "rect",
  370. itemStyle: {
  371. color: "#62BD48"
  372. },
  373. textStyle: {
  374. // 项目遗留问题,新项目不需重新转换文字大小
  375. fontSize: 12
  376. }
  377. },
  378. ],
  379. formatter: function(name) {
  380. // 自定义显示内容
  381. if (name.length > 6) {
  382. return (
  383. name.substring(0, 6) + "\n" + name.substring(6)
  384. );
  385. } else {
  386. return name;
  387. }
  388. }
  389. },
  390. grid: {
  391. show: true,
  392. borderWidth: 1,
  393. top: '20%',
  394. left: '3%',
  395. right: '5%',
  396. bottom: '10%',
  397. containLabel: true
  398. },
  399. xAxis: {
  400. type: "category",
  401. axisLine: {
  402. show: false
  403. },
  404. textStyle: {
  405. fontSize: 13
  406. },
  407. axisTick: {
  408. show: false
  409. },
  410. splitLine: {
  411. show: false,
  412. lineStyle: {
  413. color: "#ddd",
  414. width: 2
  415. }
  416. },
  417. showMinLabel: true, //显示最小值
  418. showMaxLabel: true, //显示最大值
  419. nameLocation: 'center',
  420. /* boundaryGap: ['5%', '5%'], */
  421. axisLabel: {
  422. show: true,
  423. fontSize: 12,
  424. /* padding: [0, -15, -20, 0], */ //表示 [上, 右, 下, 左] 的边距
  425. /* margin: 10, */
  426. /* verticalAlign: "bottom" */
  427. },
  428. data: this.xAxisData
  429. },
  430. dataZoom: [
  431. /* {
  432. type: "inside",
  433. start: 0,
  434. end: 100,
  435. }, */
  436. {
  437. start: 0,
  438. end: 100,
  439. textStyle: {
  440. color: "#FFF",
  441. fontSize: 14
  442. },
  443. show: true,
  444. height: 15,
  445. bottom: 5,
  446. handleStyle: {
  447. borderWidth: 1,
  448. borderCap: "square"
  449. }
  450. }
  451. ],
  452. tooltip: {
  453. trigger: "axis",
  454. textStyle: {
  455. fontSize: 14,
  456. align: "center"
  457. },
  458. formatter: "{b0}" + "</br>" + "{c0}"
  459. },
  460. yAxis: {
  461. type: "value",
  462. max: 100,
  463. min: 0,
  464. interval: 20,
  465. splitNumber : 1,
  466. boundaryGap : [ '20%', '20%' ],
  467. nameTextStyle: {
  468. fontSize: 13
  469. },
  470. alignTicks: true,
  471. axisTick: {
  472. show: true
  473. },
  474. axisLabel: {
  475. show: true,
  476. fontSize: 13,
  477. /* margin: 10 */
  478. },
  479. splitLine: {
  480. show: true,
  481. lineStyle: {
  482. color: "#ddd",
  483. width: 1
  484. }
  485. }
  486. },
  487. series: [
  488. {
  489. name: `无${this.emoName}倾向`,
  490. type: "line",
  491. padding: 5,
  492. data: this.emotionData,
  493. symbol: "circle",
  494. symbolSize: 8, // 拐点圆的大小
  495. areaStyle: {},
  496. itemStyle: {
  497. color: function(params) {
  498. // 动态设置折线图远点颜色
  499. let value = params.data;
  500. let color = '';
  501. if (value <= 40) {
  502. color = "#62BD48";
  503. } else if (value > 40 && value <= 65) {
  504. color = "#FEC350";
  505. } else if (value > 65 && value <= 80) {
  506. color = "#F86825";
  507. } else if (value > 80) {
  508. color = "#EB1D15";
  509. }
  510. return color;
  511. }
  512. }
  513. },
  514. {
  515. name: `轻度${this.emoName}倾向`,
  516. type: "line",
  517. padding: 10,
  518. data: "",
  519. symbol: "circle",
  520. symbolSize: 8, // 拐点圆的大小
  521. },
  522. {
  523. name: `中度${this.emoName}倾向`,
  524. type: "line",
  525. data: ""
  526. },
  527. {
  528. name: `重度${this.emoName}倾向`,
  529. type: "line",
  530. data: ""
  531. }
  532. ]
  533. };
  534. },
  535. imei() {
  536. return this.$store.getters.serialNo;
  537. },
  538. // 饼状图配置
  539. pieOption() {
  540. return {
  541. tooltip: {
  542. trigger: "item",
  543. textStyle: {
  544. fontSize: 14
  545. },
  546. position: "right"
  547. },
  548. legend: {
  549. top: "5%",
  550. left: "center",
  551. show: false
  552. },
  553. series: [
  554. {
  555. type: "pie",
  556. radius: ["40%", "80%"],
  557. avoidLabelOverlap: false,
  558. startAngle: 270, // 设置逆时针渲染
  559. itemStyle: {
  560. borderRadius: 5,
  561. borderColor: "#fff",
  562. borderWidth: 2,
  563. fontSize: 16
  564. },
  565. label: {
  566. show: false,
  567. position: "center",
  568. fontSize: 16
  569. },
  570. emphasis: {
  571. label: {
  572. show: false,
  573. fontSize: 16,
  574. fontWeight: "bold"
  575. }
  576. },
  577. labelLine: {
  578. show: false
  579. },
  580. data: this.pieData
  581. }
  582. ]
  583. };
  584. },
  585. titleLeft() {
  586. let text = this.emoName === 'depression' ? '趋势' : '';
  587. let today = '';
  588. if(this.currentDays !== 0) {
  589. today = '';
  590. } else {
  591. today = this.$dayjs(this.selectDate || this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  592. }
  593. return `${today}${this.emoName}倾向${text}`;
  594. },
  595. // 折线图标题
  596. echartsTitle() {
  597. let today = '';
  598. if(this.currentDays !== 0) {
  599. today = '';
  600. } else {
  601. today = this.$dayjs(this.selectDate || this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  602. }
  603. return `${today}${this.emoName}数据图`;
  604. },
  605. warmTips() {
  606. return `正常连续佩戴手表,每半小时计算一个${this.emoName}分值,睡眠期间不进行计算。`
  607. },
  608. title1() {
  609. return EmotionModel[this.params.name].title1;
  610. },
  611. article1() {
  612. return EmotionModel[this.params.name].article1;
  613. },
  614. title2() {
  615. return EmotionModel[this.params.name].title2;
  616. },
  617. article2() {
  618. return EmotionModel[this.params.name].article2;
  619. },
  620. // 当前情绪颜色
  621. currentColor( ) {
  622. return this.calcResultColor(this.resultLevel) || "#62BD48"
  623. },
  624. },
  625. watch: {
  626. // 监听数据发生变化 初始化各项图表
  627. emotionData: {
  628. handler(n, o) {
  629. this.initEchart();
  630. },
  631. deep: true
  632. },
  633. xAxisData: {
  634. handler(n, o) {
  635. this.initEchart();
  636. },
  637. deep: true
  638. },
  639. pieData: {
  640. handler(n, o) {
  641. this.initPieEchart();
  642. },
  643. deep: true
  644. }
  645. },
  646. created() {
  647. // 读取路由传过来的参数,根据路由传过来的参数判断是哪种情绪
  648. this.loadParams();
  649. this.initEchartText();
  650. this.getPieData();
  651. this.getCalendarData();
  652. this.getPsychologiclData();
  653. },
  654. mounted() {
  655. this.initEchart();
  656. window.document.title = '心理监测';
  657. },
  658. methods: {
  659. loadParams() {
  660. let params = this.$route.query;
  661. if (params) {
  662. this.emoName = EmotionModel[params.name].name;
  663. this.emoType = EmotionModel[params.name].type;
  664. this.uid = params.uid;
  665. this.routeDate = params.date;
  666. this.params = params;
  667. if(params.date) {
  668. 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");
  669. this.defaultDate = new Date(
  670. this.$dayjs(params.date)
  671. .hour(0)
  672. .minute(0)
  673. .second(0)
  674. .format()
  675. );
  676. }
  677. console.log("当前情绪是", EmotionModel[params.name].name);
  678. }
  679. },
  680. // 获取这个月中有数据的日期,控制日历组件的日期样式
  681. getCalendarData() {
  682. let reqUrl = `https://dbmq.rzliot.com/heart/api/Data/GetCalendarData`;
  683. let reqParams = {
  684. uid: this.uid,
  685. month: this.$dayjs(new Date()).format('YYYY-MM')
  686. };
  687. axios.get(reqUrl, {
  688. params: { ...reqParams },
  689. headers: { 'AuthToken': this.$store.getters.ssjlToken }
  690. }).then(res => {
  691. console.log("res", res);
  692. if (res.data) {
  693. let data = res.data.response;
  694. // const mergedArr = [...new Set([...arr1, ...arr2, ...arr3])];
  695. this.highlightDates = [ ...new Set([...data.Depression, ...data.Stress, ...data.Tiredness]) ]
  696. }
  697. })
  698. },
  699. // 获取饼状图数据,TODO 对接接口数据
  700. getPieData() {
  701. this.pieData = [
  702. { value: 12, name: "", itemStyle: { color: "green" } },
  703. { value: 2, name: "", itemStyle: { color: "orange" } },
  704. { value: 1, name: "", itemStyle: { color: "#FFC0CB" } },
  705. { value: 1, name: "", itemStyle: { color: "red" } }
  706. ];
  707. },
  708. // 获取情绪数据
  709. getPsychologiclData(date, startDate, endDate) {
  710. this.$toast.loading({
  711. message: '数据加载中'
  712. });
  713. let reqDate =
  714. date
  715. ? this.$dayjs(date).format("YYYY-MM-DD")
  716. : this.routeDate || this.$dayjs(this.defaultDate).format("YYYY-MM-DD") /* "2023-05-23" */;
  717. let reqParams = {
  718. uid: this.uid,
  719. startDate: startDate || reqDate,
  720. endDate: endDate || reqDate,
  721. type: this.emoType
  722. };
  723. console.log("请求参数", reqParams);
  724. let reqUrl = `https://dbmq.rzliot.com/heart/api/Data/GetHisData`;
  725. axios
  726. .get(reqUrl, {
  727. params: { ...reqParams },
  728. headers: { 'AuthToken': this.$store.getters.ssjlToken }
  729. })
  730. .then(res => {
  731. if (res.data) {
  732. let data = res.data.response;
  733. // 监测次数
  734. this.monitoringCount = data.Count;
  735. this.pieRightList = [];
  736. this.statisticsList = [];
  737. this.emotionList = [];
  738. let None = {
  739. count: data.None,
  740. percentage: this.calcPercentage(
  741. data.None,
  742. data.Count
  743. ),
  744. text: `无${this.emoName}倾向`,
  745. color: "#62BD48"
  746. };
  747. let Mild = {
  748. count: data.Mild,
  749. percentage: this.calcPercentage(
  750. data.Mild,
  751. data.Count
  752. ),
  753. text: `轻度${this.emoName}倾向`,
  754. color: "#FEC350"
  755. };
  756. let Moderate = {
  757. count: data.Moderate,
  758. percentage: this.calcPercentage(
  759. data.Moderate,
  760. data.Count
  761. ),
  762. text: `中度${this.emoName}倾向`,
  763. color: "#F86825"
  764. };
  765. let Severe = {
  766. count: data.Severe,
  767. percentage: this.calcPercentage(
  768. data.Severe,
  769. data.Count
  770. ),
  771. text: `重度${this.emoName}倾向`,
  772. color: "#EB1D15"
  773. };
  774. // 饼状图右边数据
  775. this.pieRightList.push(None);
  776. this.pieRightList.push(Mild);
  777. this.pieRightList.push(Moderate);
  778. this.pieRightList.push(Severe);
  779. this.pieData = this.pieRightList.map(item => {
  780. item.value = item.count;
  781. item.itemStyle = {
  782. color: item.color
  783. };
  784. return item;
  785. });
  786. // 最大,最小和最近值
  787. let Max = {
  788. label: "最大值",
  789. value: data.Max,
  790. time: data.MaxDesc
  791. ? this.currentDays === 0 ? this.$dayjs(data.MaxDesc).format("HH:mm")
  792. : this.$dayjs(data.MaxDesc).format("MM/DD HH:mm")
  793. : ""
  794. };
  795. let Min = {
  796. label: "最小值",
  797. value: data.Min,
  798. time: data.MinDesc
  799. ? this.currentDays === 0 ? this.$dayjs(data.MinDesc).format("HH:mm")
  800. : this.$dayjs(data.MinDesc).format("MM/DD HH:mm")
  801. : ""
  802. };
  803. let Avg = {
  804. label: "平均值",
  805. value: data.Avg,
  806. time: data.AvgDesc
  807. ? this.currentDays === 0 ? this.$dayjs(data.AvgDesc).format("HH:mm")
  808. : this.$dayjs(data.AvgDesc).format("MM/DD HH:mm")
  809. : ""
  810. };
  811. let Current = {
  812. label: "最近值",
  813. value: data.Current,
  814. time: data.CurrentDesc
  815. ? this.currentDays === 0 ? this.$dayjs(data.CurrentDesc).format("HH:mm")
  816. : this.$dayjs(data.CurrentDesc).format("MM/DD HH:mm")
  817. : ""
  818. };
  819. this.statisticsList.push(Max);
  820. this.statisticsList.push(Min);
  821. this.statisticsList.push(Avg);
  822. this.statisticsList.push(Current);
  823. // 周报月报底部显示数据
  824. let NoneDay = {
  825. days: data.NoneDay,
  826. text: `无${this.emoName}倾向`,
  827. color: "#62BD48"
  828. };
  829. let MildDay = {
  830. days: data.MildDay,
  831. text: `轻度${this.emoName}倾向`,
  832. color: "#FEC350"
  833. };
  834. let ModerateDay = {
  835. days: data.ModerateDay,
  836. text: `中度${this.emoName}倾向`,
  837. color: "#F86825"
  838. };
  839. let SevereDay = {
  840. days: data.SevereDay,
  841. text: `重度${this.emoName}倾向`,
  842. color: "#EB1D15"
  843. };
  844. this.emotionList.push(NoneDay);
  845. this.emotionList.push(MildDay);
  846. this.emotionList.push(ModerateDay);
  847. this.emotionList.push(SevereDay);
  848. // 图表数据
  849. this.emotionData = data.ChartDatas.map(item => {
  850. return item.Value;
  851. });
  852. // x轴显示数据
  853. if(this.currentDays === 0) {
  854. // 显示今天数据
  855. this.xAxisData = data.ChartDatas.map(item => {
  856. return this.$dayjs(item.Key.replace(/-/g, "/")).format(
  857. "HH:mm"
  858. );
  859. });
  860. } else {
  861. this.xAxisData = data.ChartDatas.map(item => {
  862. return this.$dayjs(item.Key.replace(/-/g, "/")).format(
  863. "MM/DD"
  864. );
  865. });
  866. }
  867. // 结果解读
  868. this.result = data.Result;
  869. this.resultLevel = data.ResultLevel;
  870. this.advice = data.Advice;
  871. this.$toast.loading({
  872. message: '数据加载完成'
  873. });
  874. }
  875. }).catch(() => {}).finally(() => { this.$toast.clear(); });
  876. },
  877. // 计算百分比
  878. calcPercentage(value, total) {
  879. if (
  880. typeof value !== "number" ||
  881. typeof total !== "number" ||
  882. total === 0
  883. ) {
  884. return 0;
  885. }
  886. return Math.floor((value / total) * 1000) / 10;
  887. },
  888. // 初始化图表的文字内容
  889. initEchartText() {
  890. let text = this.emoName === 'depression' ? '趋势' : '';
  891. let today = this.$dayjs(this.defaultDate).format("YYYY-MM-DD") === this.$dayjs(new Date()).format("YYYY-MM-DD") ? '今天' : '';
  892. this.result = `无${this.emoName}倾向`;
  893. this.defaultSeries = [
  894. {
  895. name: `无${this.emoName}倾向`,
  896. type: "line",
  897. padding: 10,
  898. data: this.emotionData,
  899. symbol: "circle",
  900. symbolSize: 15, // 拐点圆的大小
  901. areaStyle: {},
  902. itemStyle: {
  903. color: function(params) {
  904. // 动态设置折线图远点颜色
  905. this.calcColor(params.data);
  906. /* let value = params.data;
  907. let color = '';
  908. if (value <= 40) {
  909. color = "#62BD48";
  910. } else if (value > 40 && value <= 65) {
  911. color = "#FEC350";
  912. } else if (value > 65 && value <= 80) {
  913. color = "#F86825";
  914. } else if (value > 80) {
  915. color = "#EB1D15";
  916. }
  917. return color; */
  918. }
  919. }
  920. },
  921. {
  922. name: `轻度${this.emoName}倾向`,
  923. type: "line",
  924. padding: 10,
  925. data: "",
  926. symbol: "circle",
  927. symbolSize: 15, // 拐点圆的大小
  928. itemStyle: {
  929. color: function(params) {
  930. // 动态设置折线图远点颜色
  931. }
  932. }
  933. },
  934. {
  935. name: `中度${this.emoName}倾向`,
  936. type: "line",
  937. data: ""
  938. },
  939. {
  940. name: `重度${this.emoName}倾向`,
  941. type: "line",
  942. data: ""
  943. }
  944. ];
  945. this.weekAndMonthSeries = [
  946. {
  947. name: `无${this.emoName}倾向`,
  948. type: "scatter",
  949. data: '',
  950. symbolSize: 15,
  951. symbol: "circle",
  952. itemStyle: {
  953. borderColor: "#6CE463",
  954. color: function(params) {
  955. // 动态设置折线图远点颜色
  956. this.calcColor(params.data);
  957. }
  958. }
  959. },
  960. {
  961. name: `轻度${this.emoName}倾向`,
  962. type: "scatter",
  963. /* data: [60, 60, 50, 60, 59, 60, 60], */
  964. symbol: "path://M9 0h0a9 9 0 0 2 9 9v55a9 9 0 0 2-9 9h0a9 9 0 0 2-9-9v-55a9 9 0 0 2 10-9z",
  965. symbolSize: [60, 60],
  966. symbolKeepAspect: true,
  967. itemStyle: {
  968. borderColor: "#6CE463", // 圆点边框颜色
  969. borderWidth: 0, // 圆点边框宽度
  970. opacity: 0.5,
  971. color: function(params) {
  972. // 动态设置折线图远点颜色
  973. }
  974. }
  975. },
  976. {
  977. name: `中度${this.emoName}倾向`,
  978. data: "",
  979. type: "line"
  980. },
  981. {
  982. name: `重度${this.emoName}倾向`,
  983. data: "",
  984. type: "line"
  985. }
  986. ];
  987. /* this.defaultOptions.series = this.defaultOptions.series.map(
  988. item => {
  989. item.name = item.name.replace("情绪", this.emoName);
  990. return item;
  991. }
  992. ); */
  993. this.pieRightList = this.pieRightList.map(item => {
  994. item.text = item.text.replace("情绪", this.emoName);
  995. return item;
  996. });
  997. },
  998. // 初始化饼状图
  999. initPieEchart() {
  1000. if (
  1001. this.pieEcharts != null &&
  1002. this.pieEcharts != "" &&
  1003. this.pieEcharts != undefined
  1004. ) {
  1005. this.pieEcharts.dispose();
  1006. }
  1007. this.pieEcharts = this.$echarts.init(this.$refs.pieChart);
  1008. this.pieEcharts.setOption(this.pieOption);
  1009. },
  1010. // 格式化日期显示参数
  1011. formatter(day) {
  1012. const month = day.date.getMonth() + 1;
  1013. const date = day.date.getDate();
  1014. const formatDate = this.$dayjs(day.date).format("YYYY-MM-DD");
  1015. const currentDate = this.$dayjs(new Date()).format("YYYY-MM-DD");
  1016. day.className = "custom-calendar";
  1017. if (this.highlightDates.includes(formatDate)) {
  1018. day.className = "highlight-border";
  1019. }else if (formatDate === currentDate) {
  1020. day.text = '今天'
  1021. }
  1022. return day;
  1023. },
  1024. // 返回
  1025. onNavBack() {
  1026. this.params.name = '';
  1027. this.$router.replace({
  1028. name: 'psychologicalMain',
  1029. query: {
  1030. ...this.params
  1031. }
  1032. });
  1033. },
  1034. // 点击日期选择
  1035. onTabClick(value, index) {
  1036. this.current = index;
  1037. this.currentDays = value;
  1038. let currentDate = new Date();
  1039. let leftText = value === 0 ? '今天' : value === 7 ? '7天' : '30天';
  1040. this.surveyTitle = value === 7 ? '本周概览' : '本月概览';
  1041. if (value === 7) {
  1042. this.defaultOptions.xAxis.data = [
  1043. "周一",
  1044. "周二",
  1045. "周三",
  1046. "周四",
  1047. "周五",
  1048. "周六",
  1049. "周日"
  1050. ];
  1051. this.defaultOptions.series = this.weekAndMonthSeries;
  1052. let dateList = this.getPostDate(currentDate, 6, true);
  1053. console.log("dateList", dateList);
  1054. this.getPsychologiclData('', dateList[0], dateList[1]);
  1055. } else if (value === 0) {
  1056. // 今天
  1057. this.defaultOptions.xAxis.data = this.xAxisData;
  1058. this.defaultOptions.series = this.defaultSeries;
  1059. this.defaultOptions.series[0].data = this.emotionData;
  1060. this.getPsychologiclData(this.selectDate ? this.selectDate : this .$dayjs(currentDate).format("YYYY-MM-DD"));
  1061. } else {
  1062. // 30天
  1063. this.defaultOptions.xAxis.data = this.xAxisData;
  1064. this.defaultOptions.series = this.defaultSeries;
  1065. this.defaultOptions.series[0].data = this.emotionData;
  1066. let dateList = this.getCurrentMonthStaAndEnd(currentDate);
  1067. console.log("dateList", dateList);
  1068. this.getPsychologiclData('', dateList[0], dateList[1]);
  1069. }
  1070. },
  1071. getCurrentMonthStaAndEnd(currentDate) {
  1072. let list = [];
  1073. let monthStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1); // 获取本月第一天的日期时间
  1074. let monthEnd = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0, 23, 59, 59); // 获取本月最后一天的日期时间(时间为23:59:59)
  1075. list.push(this.$dayjs(monthStart).format("YYYY-MM-DD"));
  1076. list.push(this.$dayjs(monthEnd).format("YYYY-MM-DD"));
  1077. return list;
  1078. },
  1079. // 获取指定天数的起始日期
  1080. /**
  1081. *
  1082. * @param dateNow :Date类
  1083. * @param intervalDays :间隔天数
  1084. * @param bolPastTime :Boolean,判断在参数date之前,还是之后,
  1085. */
  1086. getPostDate(dateNow,intervalDays,bolPastTime) {
  1087. let oneDayTime = 24 * 60 * 60 * 1000;
  1088. let list = [];
  1089. let lastDay;
  1090. if(bolPastTime == true){
  1091. lastDay = new Date(dateNow.getTime() - intervalDays * oneDayTime);
  1092. list.push(this.formateDate(lastDay));
  1093. list.push(this.formateDate(dateNow));
  1094. }else{
  1095. lastDay = new Date(dateNow.getTime() + intervalDays * oneDayTime);
  1096. list.push(this.formateDate(dateNow));
  1097. list.push(this.formateDate(lastDay));
  1098. }
  1099. return list;
  1100. },
  1101. formateDate(time){
  1102. let year = time.getFullYear();
  1103. let month = time.getMonth() + 1;
  1104. let day = time.getDate();
  1105. if (month < 10) {
  1106. month = '0' + month
  1107. };
  1108. if (day < 10) {
  1109. day = '0' + day
  1110. };
  1111. return year + '-' + month + '-' + day + '';
  1112. },
  1113. // 字体大小转化
  1114. fontChar(res) {
  1115. const clientWidth =
  1116. window.innerWidth ||
  1117. document.documentElement.clientWidth ||
  1118. document.body.clientWidth;
  1119. if (!clientWidth) return;
  1120. let fontSize = clientWidth / 750;
  1121. return res * fontSize;
  1122. },
  1123. // 初始化折线图表
  1124. initEchart() {
  1125. if (
  1126. this.echarts != null &&
  1127. this.echarts != "" &&
  1128. this.echarts != undefined
  1129. ) {
  1130. this.echarts.dispose();
  1131. }
  1132. this.echarts = this.$echarts.init(this.$refs.charts);
  1133. this.echarts.setOption(this.defaultOptions);
  1134. },
  1135. // 点击历史监测,打开日历
  1136. onHistory() {
  1137. this.calendarDialogShow = true;
  1138. },
  1139. // 选择日历具体某一个日期
  1140. onSelect(value) {
  1141. const selectDate = this.$dayjs(value).format("YYYY-MM-DD");
  1142. 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");
  1143. this.calendarDialogShow = false;
  1144. this.selectDate = selectDate;
  1145. this.getPsychologiclData(selectDate);
  1146. },
  1147. // 计算字体显示的颜色
  1148. calcColor(value) {
  1149. let color = "";
  1150. if (value <= 40) {
  1151. color = "#62BD48";
  1152. } else if (value > 40 && value <= 65) {
  1153. color = "#FEC350";
  1154. } else if (value > 65 && value <= 80) {
  1155. color = "#F86825";
  1156. } else if (value > 80) {
  1157. color = "#EB1D15";
  1158. } else {
  1159. color = "";
  1160. }
  1161. return color;
  1162. },
  1163. // 计算结果采用哪种颜色
  1164. calcResultColor(value) {
  1165. let color = "";
  1166. switch(value) {
  1167. case '0':
  1168. color = "#62BD48";
  1169. break;
  1170. case '1':
  1171. color = "#FEC350";
  1172. break;
  1173. case '2':
  1174. color = "#F86825";
  1175. break;
  1176. case '3':
  1177. color = "#EB1D15";
  1178. break;
  1179. }
  1180. return color;
  1181. },
  1182. // 点击帮助
  1183. onHelp() {
  1184. this.isPopup = true;
  1185. },
  1186. // 关闭poup
  1187. onClose() {
  1188. this.isPopup = false;
  1189. }
  1190. }
  1191. };
  1192. </script>
  1193. <style lang="scss">
  1194. .van-nav-bar .van-icon {
  1195. padding-left: 10px;
  1196. }
  1197. .calenddar-dialog {
  1198. overflow: scroll;
  1199. }
  1200. .calendar {
  1201. overflow: scroll;
  1202. .van-calendar {
  1203. height: 350px;
  1204. .van-calendar__header {
  1205. display: none;
  1206. }
  1207. .van-calendar__days .van-calendar__day {
  1208. width: 27px;
  1209. height: 27px;
  1210. margin: 5px;
  1211. font-size: 12px;
  1212. &.custom-calendar {
  1213. width: 27px;
  1214. height: 27px;
  1215. }
  1216. &.highlight-border {
  1217. border: 1px solid #62bd48;
  1218. width: 27px;
  1219. height: 27px;
  1220. border-radius: 50%;
  1221. }
  1222. }
  1223. .van-calendar__selected-day {
  1224. width: 27px;
  1225. height: 27px;
  1226. border-radius: 50%;
  1227. font-size: 12px;
  1228. }
  1229. }
  1230. }
  1231. </style>
  1232. <style scoped lang="scss">
  1233. @import "./index.scss";
  1234. </style>