DeptPrice.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="points-ranking__wrap">
  3. <div class="points-ranking" ref="DeptPrice"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echarts from 'echarts'
  8. import { post, timerCommon } from './../http/http'
  9. export default {
  10. name: 'DeptPrice',
  11. inject: ['parentDutyId', 'hosId', 'dutyId'],
  12. data () {
  13. return {
  14. sign: 'lastWeek',
  15. timer: null,
  16. myChart: null,
  17. gradeRankingListNum: [],
  18. gradeRankingListName: []
  19. }
  20. },
  21. methods: {
  22. // 画图
  23. draw () {
  24. this.myChart = echarts.init(this.$refs.DeptPrice)
  25. var colorArray = [
  26. {
  27. top: '#6B97BD', // 第一
  28. bottom: '#364C5F'
  29. },
  30. {
  31. top: '#6B97BD', // 第二
  32. bottom: '#364C5F'
  33. },
  34. {
  35. top: '#6AB87D', // 第三
  36. bottom: '#3D7057'
  37. },
  38. {
  39. top: '#A09163', // 第四
  40. bottom: '#504932'
  41. },
  42. {
  43. top: '#6B97BD', // 第五
  44. bottom: '#364C5F'
  45. }
  46. ]
  47. const option = {
  48. tooltip: {
  49. show: false,
  50. formatter: '{b}:{c}'
  51. },
  52. grid: {
  53. left: 28,
  54. top: 0,
  55. bottom: 10,
  56. containLabel: true
  57. },
  58. xAxis: {
  59. type: 'value',
  60. show: false,
  61. position: 'top',
  62. axisTick: {
  63. show: false
  64. },
  65. axisLine: {
  66. show: false,
  67. lineStyle: {
  68. color: '#fff'
  69. }
  70. },
  71. splitLine: {
  72. show: false
  73. }
  74. },
  75. yAxis: [
  76. {
  77. type: 'category',
  78. axisTick: {
  79. show: false,
  80. alignWithLabel: false,
  81. length: 5
  82. },
  83. splitLine: {
  84. // 网格线
  85. show: false
  86. },
  87. inverse: 'true', // 排序
  88. axisLabel: {
  89. margin: 16,
  90. color: 'rgba(255,255,255,0.85)'
  91. },
  92. axisLine: {
  93. show: false,
  94. lineStyle: {
  95. color: '#fff'
  96. }
  97. },
  98. data: this.gradeRankingListName
  99. }
  100. ],
  101. series: [
  102. {
  103. name: 'xxx',
  104. type: 'bar',
  105. label: {
  106. normal: {
  107. show: true,
  108. // position: [300, 0],
  109. position: 'right',
  110. formatter: '{c}',
  111. textStyle: {
  112. color: '#fff'
  113. }
  114. }
  115. },
  116. itemStyle: {
  117. normal: {
  118. show: true,
  119. color: function (params) {
  120. const num = colorArray.length
  121. return {
  122. type: 'linear',
  123. colorStops: [
  124. {
  125. offset: 0,
  126. color: colorArray[params.dataIndex % num].bottom
  127. },
  128. {
  129. offset: 1,
  130. color: colorArray[params.dataIndex % num].top
  131. },
  132. {
  133. offset: 0,
  134. color: colorArray[params.dataIndex % num].bottom
  135. },
  136. {
  137. offset: 1,
  138. color: colorArray[params.dataIndex % num].top
  139. },
  140. {
  141. offset: 0,
  142. color: colorArray[params.dataIndex % num].bottom
  143. },
  144. {
  145. offset: 1,
  146. color: colorArray[params.dataIndex % num].top
  147. },
  148. {
  149. offset: 0,
  150. color: colorArray[params.dataIndex % num].bottom
  151. },
  152. {
  153. offset: 1,
  154. color: colorArray[params.dataIndex % num].top
  155. },
  156. {
  157. offset: 0,
  158. color: colorArray[params.dataIndex % num].bottom
  159. },
  160. {
  161. offset: 1,
  162. color: colorArray[params.dataIndex % num].top
  163. },
  164. {
  165. offset: 0,
  166. color: colorArray[params.dataIndex % num].bottom
  167. },
  168. {
  169. offset: 1,
  170. color: colorArray[params.dataIndex % num].top
  171. }
  172. ]
  173. }
  174. },
  175. barBorderRadius: 70,
  176. borderWidth: 0,
  177. borderColor: '#333'
  178. }
  179. },
  180. barGap: '0%',
  181. barCategoryGap: '70%',
  182. barWidth: 8,
  183. data: this.gradeRankingListNum
  184. }
  185. ]
  186. }
  187. this.myChart.setOption(option)
  188. },
  189. // 获取数据
  190. async getData () {
  191. this.$emit('signEmit', this.sign)
  192. let startTime
  193. let endTime
  194. if (this.sign === 'lastWeek') {
  195. startTime = this.$moment().subtract(1, 'week').startOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss')
  196. endTime = this.$moment().subtract(1, 'week').endOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss')
  197. } else if (this.sign === 'lastMonth') {
  198. startTime = this.$moment().subtract(1, 'month').startOf('month').format('YYYY-MM-DD HH:mm:ss')
  199. endTime = this.$moment().subtract(1, 'month').endOf('month').format('YYYY-MM-DD HH:mm:ss')
  200. }
  201. const result = await post(
  202. '/itsm/report/index',
  203. {
  204. parentDutyId: this.parentDutyId,
  205. hosId: this.hosId,
  206. dutyId: this.dutyId,
  207. startDate: startTime,
  208. endDate: endTime,
  209. type: 'itsmDeptPrice'
  210. }
  211. )
  212. this.gradeRankingListNum = []
  213. this.gradeRankingListName = []
  214. if (result.data.length > 0) {
  215. result.data.forEach(item => {
  216. this.gradeRankingListNum.push(item.price || 0) // 获取到的数据
  217. this.gradeRankingListName.push(item.name || '') // 获取到的名称
  218. })
  219. }
  220. this.draw()
  221. this.polling()
  222. },
  223. // 轮询请求
  224. polling () {
  225. clearTimeout(this.timer)
  226. this.timer = setTimeout(() => {
  227. if (this.sign === 'lastWeek') {
  228. this.sign = 'lastMonth'
  229. } else if (this.sign === 'lastMonth') {
  230. this.sign = 'lastWeek'
  231. }
  232. this.getData()
  233. }, timerCommon)
  234. }
  235. },
  236. mounted () {
  237. this.getData()
  238. },
  239. beforeDestroy () {
  240. clearTimeout(this.timer)
  241. }
  242. }
  243. </script>
  244. <style lang="less" scoped>
  245. .points-ranking__wrap {
  246. height: 3.7rem;
  247. overflow: hidden;
  248. position: relative;
  249. .points-ranking {
  250. width: 100%;
  251. height: 100%;
  252. position: absolute;
  253. left: 0;
  254. top: 0;
  255. }
  256. }
  257. </style>