consult.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div>
  3. <el-dialog center append-to-body title="医疗咨询记录统计" :visible.sync="dialogVisible" width="80%" top
  4. :close-on-click-modal="false" :close-on-press-escape="false">
  5. <div class="date-wrap">
  6. <div class="date-label">编制时间:</div>
  7. <el-date-picker v-model="monthValues" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"
  8. align="left" :picker-options="pickerOptions" value-format="yyyy-MM-dd" />
  9. <el-button type="primary" @click="searchData" style="margin-left: 20px;">查询</el-button>
  10. </div>
  11. <div class="chart-wrap">
  12. <div class="chart-item">
  13. <div id="echart3" style="width: 100%; height: 100%"></div>
  14. </div>
  15. <div class="chart-item">
  16. <div id="echart4" style="width: 100%; height: 100%"></div>
  17. </div>
  18. </div>
  19. <div class="chart-wrap">
  20. <div class="chart-item">
  21. <div id="echart6" style="width: 100%; height: 100%"></div>
  22. </div>
  23. </div>
  24. <span slot="footer" class="dialog-footer">
  25. <el-button type="danger" @click="closeDialog">关闭</el-button>
  26. </span>
  27. </el-dialog>
  28. </div>
  29. </template>
  30. <script>
  31. import * as echarts from 'echarts'
  32. export default {
  33. props: {
  34. dialogVisible: {
  35. type: Boolean,
  36. default: false
  37. }
  38. },
  39. data() {
  40. return {
  41. pickerOptions: {
  42. shortcuts: [{
  43. text: '最近一周',
  44. onClick(picker) {
  45. const end = new Date();
  46. const start = new Date();
  47. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  48. picker.$emit('pick', [start, end]);
  49. }
  50. }, {
  51. text: '最近一个月',
  52. onClick(picker) {
  53. const end = new Date();
  54. const start = new Date();
  55. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  56. picker.$emit('pick', [start, end]);
  57. }
  58. }, {
  59. text: '最近三个月',
  60. onClick(picker) {
  61. const end = new Date();
  62. const start = new Date();
  63. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  64. picker.$emit('pick', [start, end]);
  65. }
  66. }]
  67. },
  68. monthValues: [],
  69. diDian: ''
  70. }
  71. },
  72. watch: {
  73. },
  74. mounted() {
  75. const { first = '', second = '' } = this.$store.getters.level || {}
  76. this.diDian = second || first
  77. const today = new Date();
  78. const halfYearAgo = new Date();
  79. halfYearAgo.setMonth(halfYearAgo.getMonth() - 6);
  80. this.monthValues = [this.formatDate(halfYearAgo), this.formatDate(today)]
  81. this.$nextTick(() => {
  82. this.formatData3()
  83. this.getFangshi()
  84. this.getMonths()
  85. })
  86. },
  87. methods: {
  88. searchData() {
  89. this.formatData3()
  90. this.getFangshi()
  91. this.$message.success('查询成功')
  92. },
  93. // 格式化日期为 YYYY-MM-DD
  94. formatDate(date) {
  95. const year = date.getFullYear();
  96. const month = String(date.getMonth() + 1).padStart(2, '0');
  97. const day = String(date.getDate()).padStart(2, '0');
  98. return `${year}-${month}-${day}`;
  99. },
  100. changeDate(value) {
  101. this.formatData3()
  102. this.getFangshi()
  103. },
  104. // 关闭当前窗口
  105. closeDialog(needRefresh) {
  106. this.$emit('update:dialogVisible', false, needRefresh)
  107. },
  108. async formatData3() {
  109. const res = await this.$common.request('query', {
  110. key: 'hqylzxjlzxlxsj',
  111. params: [this.monthValues[0], this.monthValues[1], this.diDian]
  112. })
  113. const { data = [] } = res.variables
  114. var chartDom = document.getElementById('echart3');
  115. var myChart = echarts.init(chartDom);
  116. var option;
  117. option = {
  118. title: {
  119. text: '咨询类型占比',
  120. textStyle: { fontSize: 16 },
  121. left: 'center'
  122. },
  123. tooltip: {
  124. trigger: 'item',
  125. confine: true, // 把提示框限制在图表容器内
  126. extraCssText: 'max-width: 400px; white-space: normal; word-wrap: break-word;',
  127. },
  128. legend: {
  129. orient: 'vertical',
  130. left: 'left',
  131. textStyle: { width: 200, overflow: 'break' }
  132. },
  133. series: [
  134. {
  135. type: 'pie',
  136. radius: '50%',
  137. data,
  138. emphasis: {
  139. itemStyle: {
  140. shadowBlur: 10,
  141. shadowOffsetX: 0,
  142. shadowColor: 'rgba(0, 0, 0, 0.5)'
  143. }
  144. }
  145. }
  146. ]
  147. }
  148. option && myChart.setOption(option);
  149. },
  150. async getFangshi() {
  151. const res = await this.$common.request('query', {
  152. key: 'hqylzxzxkssj',
  153. params: [this.monthValues[0], this.monthValues[1], this.diDian]
  154. })
  155. const { data = [] } = res.variables
  156. var chartDom = document.getElementById('echart4');
  157. var myChart = echarts.init(chartDom);
  158. var option;
  159. option = {
  160. title: {
  161. text: '咨询科室占比',
  162. textStyle: { fontSize: 16 },
  163. left: 'center'
  164. },
  165. tooltip: {
  166. trigger: 'item',
  167. confine: true, // 把提示框限制在图表容器内
  168. extraCssText: 'max-width: 400px; white-space: normal; word-wrap: break-word;',
  169. },
  170. legend: {
  171. orient: 'vertical',
  172. left: 'left',
  173. textStyle: { width: 200, overflow: 'break' }
  174. },
  175. series: [
  176. {
  177. type: 'pie',
  178. radius: '50%',
  179. data,
  180. emphasis: {
  181. itemStyle: {
  182. shadowBlur: 10,
  183. shadowOffsetX: 0,
  184. shadowColor: 'rgba(0, 0, 0, 0.5)'
  185. }
  186. }
  187. }
  188. ]
  189. }
  190. option && myChart.setOption(option);
  191. },
  192. async getMonths() {
  193. const res = await this.$common.request('query', {
  194. key: 'hqylzxjl12ysj',
  195. params: [this.diDian]
  196. })
  197. const { data = [] } = res.variables
  198. let xAxis = []
  199. let yAxis = []
  200. data.forEach(item => {
  201. xAxis.push(item.months)
  202. yAxis.push(item.data_count)
  203. })
  204. var chartDom = document.getElementById('echart6');
  205. var myChart = echarts.init(chartDom);
  206. var option;
  207. option = {
  208. title: {
  209. text: '近12个月趋势',
  210. textStyle: { fontSize: 16 },
  211. left: 'center'
  212. },
  213. tooltip: {
  214. trigger: 'axis'
  215. },
  216. xAxis: {
  217. type: 'category',
  218. axisLabel: {
  219. interval: 0, // 强制显示所有标签
  220. rotate: 30
  221. },
  222. data: xAxis
  223. },
  224. yAxis: {
  225. type: 'value'
  226. },
  227. series: [
  228. {
  229. data: yAxis,
  230. type: 'line'
  231. }
  232. ]
  233. }
  234. option && myChart.setOption(option);
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped lang="scss">
  240. .date-wrap {
  241. padding: 20px;
  242. box-sizing: border-box;
  243. display: flex;
  244. align-items: center;
  245. justify-content: flex-start;
  246. color: #333;
  247. font-size: 16px;
  248. }
  249. .chart-wrap {
  250. display: flex;
  251. align-items: center;
  252. justify-content: flex-start;
  253. padding: 0 20px;
  254. box-sizing: border-box;
  255. .chart-item {
  256. width: 50%;
  257. height: 300px;
  258. margin: 20px 0;
  259. overflow: hidden;
  260. }
  261. }
  262. .dialog-footer {
  263. display: flex;
  264. justify-content: center;
  265. }
  266. </style>