left-2.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div id="left-2">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__fadeInDown">
  5. <el-col :span="24" class="one">
  6. <el-col :span="24" class="one_1" @click.native="toPath()"> 精神障碍患者统计 </el-col>
  7. <el-col :span="24" class="one_2">
  8. <div id="echarts4" class="canvas" style="width: 100%; height: 10vw"></div>
  9. </el-col>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import { EventBus } from '../eventBus';
  17. // 引入基本模板
  18. let echarts = require('echarts/lib/echarts');
  19. // 引入柱状图组件
  20. require('echarts/lib/chart/bar');
  21. // 引入提示框和title组件
  22. require('echarts/lib/component/tooltip');
  23. require('echarts/lib/component/title');
  24. echarts = require('echarts');
  25. import { mapState, createNamespacedHelpers } from 'vuex';
  26. const { mapActions } = createNamespacedHelpers('statistics');
  27. export default {
  28. name: 'left-2',
  29. props: {},
  30. components: {},
  31. data: function () {
  32. return {
  33. list: [
  34. { name: '2017', value: 20 },
  35. { name: '2018', value: 70 },
  36. { name: '2019', value: 150 },
  37. { name: '2020', value: 360 },
  38. { name: '2021', value: 15 },
  39. { name: '2022', value: 251 },
  40. ],
  41. chart: undefined,
  42. };
  43. },
  44. created() {
  45. // this.search();
  46. },
  47. mounted() {
  48. this.init();
  49. },
  50. methods: {
  51. ...mapActions(['right1']),
  52. async search() {
  53. const res = await this.right1();
  54. if (this.$checkRes(res)) {
  55. let value = res.data;
  56. this.changeData(value);
  57. }
  58. },
  59. // 更换chart数据
  60. changeData(value) {
  61. if (!this.chart) return;
  62. let option = this.getOption(value);
  63. this.chart.setOption(option);
  64. },
  65. // 组织chart的数据函数
  66. getOption(data) {
  67. let two = data.map((i) => i.name);
  68. let thr = data.map((i) => i.value);
  69. let option;
  70. option = {
  71. tooltip: {},
  72. xAxis: {
  73. type: 'category',
  74. data: two,
  75. axisLabel: {
  76. interval: 0, //横轴信息全部显示
  77. textStyle: { color: '#ffffff' },
  78. },
  79. },
  80. yAxis: {
  81. type: 'value',
  82. axisLabel: {
  83. interval: 0, //横轴信息全部显示
  84. textStyle: { color: '#ffffff' },
  85. },
  86. },
  87. series: [
  88. {
  89. data: thr,
  90. type: 'line',
  91. symbol: 'triangle',
  92. symbolSize: 20,
  93. lineStyle: { color: '#5470C6', width: 4, type: 'dashed' },
  94. itemStyle: { borderWidth: 3, borderColor: '#EE6666', color: 'yellow' },
  95. },
  96. ],
  97. };
  98. return option;
  99. },
  100. init() {
  101. var chartDom = document.getElementById('echarts4');
  102. var myChart = echarts.init(chartDom);
  103. myChart.on('click', (params) => {
  104. console.log('1');
  105. });
  106. this.chart = myChart;
  107. this.search();
  108. },
  109. toPath() {
  110. this.$router.push('/guardian/patient');
  111. },
  112. },
  113. computed: {
  114. ...mapState(['user']),
  115. },
  116. metaInfo() {
  117. return { title: this.$route.meta.title };
  118. },
  119. watch: {
  120. test: {
  121. deep: true,
  122. immediate: true,
  123. handler(val) {},
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. .main {
  130. .one {
  131. .one_1 {
  132. color: #000000;
  133. font-size: 3vmin;
  134. font-weight: 700;
  135. position: relative;
  136. border-bottom: 2px solid #2441a9;
  137. line-height: 2.96875vw;
  138. text-align: left;
  139. }
  140. .one_1::before {
  141. background: #2441a9;
  142. border-radius: 50%;
  143. content: '';
  144. width: 6px;
  145. height: 6px;
  146. position: absolute;
  147. right: -2px;
  148. bottom: -4px;
  149. z-index: 1;
  150. visibility: visible;
  151. }
  152. .one_1:hover {
  153. cursor: pointer;
  154. color: #66b1ff;
  155. }
  156. .one_2 {
  157. background: #2441a9;
  158. }
  159. }
  160. }
  161. .canvas {
  162. /deep/canvas {
  163. width: 18vw !important;
  164. // min-height: 5vw !important;
  165. max-height: 10vw !important;
  166. }
  167. }
  168. </style>