123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <template>
- <div class="points-ranking__wrap">
- <div class="points-ranking" ref="DeptPrice"></div>
- </div>
- </template>
- <script>
- import echarts from 'echarts'
- import { post, timerCommon } from './../http/http'
- export default {
- name: 'DeptPrice',
- inject: ['parentDutyId', 'hosId', 'dutyId'],
- data () {
- return {
- sign: 'lastWeek',
- timer: null,
- myChart: null,
- gradeRankingListNum: [],
- gradeRankingListName: []
- }
- },
- methods: {
- // 画图
- draw () {
- this.myChart = echarts.init(this.$refs.DeptPrice)
- var colorArray = [
- {
- top: '#6B97BD', // 第一
- bottom: '#364C5F'
- },
- {
- top: '#6B97BD', // 第二
- bottom: '#364C5F'
- },
- {
- top: '#6AB87D', // 第三
- bottom: '#3D7057'
- },
- {
- top: '#A09163', // 第四
- bottom: '#504932'
- },
- {
- top: '#6B97BD', // 第五
- bottom: '#364C5F'
- }
- ]
- const option = {
- tooltip: {
- show: false,
- formatter: '{b}:{c}'
- },
- grid: {
- left: 28,
- top: 0,
- bottom: 10,
- containLabel: true
- },
- xAxis: {
- type: 'value',
- show: false,
- position: 'top',
- axisTick: {
- show: false
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#fff'
- }
- },
- splitLine: {
- show: false
- }
- },
- yAxis: [
- {
- type: 'category',
- axisTick: {
- show: false,
- alignWithLabel: false,
- length: 5
- },
- splitLine: {
- // 网格线
- show: false
- },
- inverse: 'true', // 排序
- axisLabel: {
- margin: 16,
- color: 'rgba(255,255,255,0.85)'
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#fff'
- }
- },
- data: this.gradeRankingListName
- }
- ],
- series: [
- {
- name: 'xxx',
- type: 'bar',
- label: {
- normal: {
- show: true,
- // position: [300, 0],
- position: 'right',
- formatter: '{c}',
- textStyle: {
- color: '#fff'
- }
- }
- },
- itemStyle: {
- normal: {
- show: true,
- color: function (params) {
- const num = colorArray.length
- return {
- type: 'linear',
- colorStops: [
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- },
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- },
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- },
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- },
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- },
- {
- offset: 0,
- color: colorArray[params.dataIndex % num].bottom
- },
- {
- offset: 1,
- color: colorArray[params.dataIndex % num].top
- }
- ]
- }
- },
- barBorderRadius: 70,
- borderWidth: 0,
- borderColor: '#333'
- }
- },
- barGap: '0%',
- barCategoryGap: '70%',
- barWidth: 8,
- data: this.gradeRankingListNum
- }
- ]
- }
- this.myChart.setOption(option)
- },
- // 获取数据
- async getData () {
- this.$emit('signEmit', this.sign)
- let startTime
- let endTime
- if (this.sign === 'lastWeek') {
- startTime = this.$moment().subtract(1, 'week').startOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss')
- endTime = this.$moment().subtract(1, 'week').endOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss')
- } else if (this.sign === 'lastMonth') {
- startTime = this.$moment().subtract(1, 'month').startOf('month').format('YYYY-MM-DD HH:mm:ss')
- endTime = this.$moment().subtract(1, 'month').endOf('month').format('YYYY-MM-DD HH:mm:ss')
- }
- const result = await post(
- '/itsm/report/index',
- {
- parentDutyId: this.parentDutyId,
- hosId: this.hosId,
- dutyId: this.dutyId,
- startDate: startTime,
- endDate: endTime,
- type: 'itsmDeptPrice'
- }
- )
- this.gradeRankingListNum = []
- this.gradeRankingListName = []
- if (result.data.length > 0) {
- result.data.forEach(item => {
- this.gradeRankingListNum.push(item.price || 0) // 获取到的数据
- this.gradeRankingListName.push(item.name || '') // 获取到的名称
- })
- }
- this.draw()
- this.polling()
- },
- // 轮询请求
- polling () {
- clearTimeout(this.timer)
- this.timer = setTimeout(() => {
- if (this.sign === 'lastWeek') {
- this.sign = 'lastMonth'
- } else if (this.sign === 'lastMonth') {
- this.sign = 'lastWeek'
- }
- this.getData()
- }, timerCommon)
- }
- },
- mounted () {
- this.getData()
- },
- beforeDestroy () {
- clearTimeout(this.timer)
- }
- }
- </script>
- <style lang="less" scoped>
- .points-ranking__wrap {
- height: 3.7rem;
- overflow: hidden;
- position: relative;
- .points-ranking {
- width: 100%;
- height: 100%;
- position: absolute;
- left: 0;
- top: 0;
- }
- }
- </style>
|