TimeUtilization.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="time-utilization" ref="TimeUtilization"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. import { post, timer4 } from './../http/http'
  7. export default {
  8. name: 'TimeUtilization',
  9. inject: ['hospitalId'],
  10. data () {
  11. return {
  12. timer: null,
  13. myChart: null,
  14. groupWorkRatioName: [],
  15. groupWorkRatioNum: []
  16. }
  17. },
  18. methods: {
  19. // 画图
  20. draw () {
  21. this.myChart = echarts.init(this.$refs.TimeUtilization)
  22. const option = {
  23. title: {
  24. text: '时间利用率(%)',
  25. top: 5,
  26. left: 15,
  27. textStyle: {
  28. color: '#d4d6d7',
  29. fontSize: 12
  30. }
  31. },
  32. grid: {
  33. left: '10%',
  34. top: '20%',
  35. bottom: '20%',
  36. right: '5%'
  37. },
  38. xAxis: {
  39. data: this.groupWorkRatioName,
  40. axisTick: {
  41. show: false
  42. },
  43. axisLine: {
  44. lineStyle: {
  45. color: '#709cc2'
  46. }
  47. },
  48. axisLabel: {
  49. textStyle: {
  50. color: '#d4d6d7',
  51. fontSize: 12
  52. }
  53. }
  54. },
  55. yAxis: [
  56. {
  57. max: 1,
  58. min: 0,
  59. interval: 0.25,
  60. axisTick: {
  61. show: false
  62. },
  63. axisLine: {
  64. lineStyle: {
  65. color: '#709cc2'
  66. }
  67. },
  68. axisLabel: {
  69. formatter (value) {
  70. return value * 100
  71. },
  72. textStyle: {
  73. color: '#d4d6d7',
  74. fontSize: 12
  75. }
  76. },
  77. splitArea: {
  78. areaStyle: {
  79. color: 'rgba(255,255,255,.5)'
  80. }
  81. },
  82. splitLine: {
  83. show: true,
  84. lineStyle: {
  85. color: 'rgba(255, 255, 255, 0.1)',
  86. type: 'dashed'
  87. }
  88. }
  89. }
  90. ],
  91. series: [
  92. {
  93. name: 'hill',
  94. type: 'bar',
  95. barCategoryGap: '0%',
  96. barWidth: 24,
  97. symbol:
  98. 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
  99. label: {
  100. show: false,
  101. position: 'top',
  102. distance: 0,
  103. color: '#70c2ab',
  104. fontWeight: 'bold',
  105. fontSize: 12
  106. },
  107. itemStyle: {
  108. normal: {
  109. color: {
  110. type: 'linear',
  111. x: 0,
  112. y: 0,
  113. x2: 0,
  114. y2: 1,
  115. colorStops: [
  116. {
  117. offset: 0,
  118. color: 'rgba(112,194,130, .8)' // 0% 处的颜色
  119. },
  120. {
  121. offset: 1,
  122. color: 'rgba(112,194,130, .1)' // 100% 处的颜色
  123. }
  124. ],
  125. global: false // 缺省为 false
  126. }
  127. },
  128. emphasis: {
  129. opacity: 1
  130. }
  131. },
  132. data: this.groupWorkRatioNum,
  133. z: 10
  134. }
  135. ]
  136. }
  137. this.myChart.setOption(option)
  138. },
  139. // 获取数据
  140. async getData () {
  141. const srartTime = this.$moment()
  142. .subtract(29, 'days')
  143. .format('YYYY-MM-DD') // 近三十天
  144. const endTime = this.$moment().format('YYYY-MM-DD') // 今天
  145. const result = await post(
  146. `/largeScreen/getData/groupWorkRatio/${this.hospitalId}`,
  147. { srartTime, endTime }
  148. )
  149. this.groupWorkRatioNum = []
  150. this.groupWorkRatioName = []
  151. if (result.groutWorkRatio.length > 5) {
  152. result.groutWorkRatio = result.groutWorkRatio.slice(0, 5)
  153. }
  154. result.groutWorkRatio.forEach(item => {
  155. this.groupWorkRatioNum.push(item[1] / 100) // 获取到的数据
  156. this.groupWorkRatioName.push(item[2]) // 获取到的名称
  157. })
  158. this.draw()
  159. this.polling()
  160. },
  161. // 轮询请求
  162. polling () {
  163. clearTimeout(this.timer)
  164. this.timer = setTimeout(() => {
  165. this.getData()
  166. }, timer4)
  167. }
  168. },
  169. mounted () {
  170. this.getData()
  171. },
  172. beforeDestroy () {
  173. clearTimeout(this.timer)
  174. }
  175. }
  176. </script>
  177. <style lang="less">
  178. .time-utilization{
  179. height: 2.1375rem;
  180. margin: 0 auto;
  181. }
  182. </style>