Blame view

src/components/incomeOverview/index.vue 7.48 KB
22fb20b3   songchongxian   城市停车运营监控
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  <template>
    <div class="app-incomeBox">
      <div class="theme-card">
        <div class="title"><span>收入概况</span> </div>
        <div class="content">
          <!--<div class="lineChart"></div>-->
          <div class="topBox eleVerHorCenter-flex">
            <span class="eleText">总计</span>
            <div class="eleMarginLeft" v-html="incomeTotal"></div>
          </div>
          <div class="bottomBox eleVerHorCenter-flex">
            <div class="incomeBar"></div>
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
    import common from '../../api/common';
    import echarts from 'echarts'
      export default {
        name: "incomeOverview",
        data() {
          return {
74b5bee2   liuqimichale   全局 接口参数
26
            demo:'',//示例
22fb20b3   songchongxian   城市停车运营监控
27
28
29
30
31
32
33
34
35
36
37
38
39
40
            incomeTotal:"",//总收入
            barChart: {},//柱状图
            barChartOption:{
              name:['支付宝', '微信', '其它'],
              barColor:[
                {name:"支付宝",from:"#2772F4",to:"#00CAFE",value:1683,color:'#01AEFE'},//color y轴颜色、value值
                {name:"微信",from:"#02C202",to:"#51EC51",value:234,color:'#06C406'},
                {name:"其它",from:"#FD8811",to:"#FFAB00",value:123,color:'#FFAB00'}
              ],//柱子颜色
              textColor:['#01AEFE', '#06C406', '#FFAB00'],//name颜色
            }
          }
        },
        mounted() {
f0fb6d92   liuqimichale   收入
41
          this.axios.post('urban/intelligence/income/queryIncomeStaByOrgIds',{
74b5bee2   liuqimichale   全局 接口参数
42
            orgIds: this.GLOBAL.paramsvariables
f0fb6d92   liuqimichale   收入
43
44
          }).then((response)=>{
            let  data = response.data.data
4439edb0   liuqimichale   收入概览
45
            this.incomeTotal = data.totalPay
f0fb6d92   liuqimichale   收入
46
            this.incomeTotal = common.formatNumToStr(this.incomeTotal)
4439edb0   liuqimichale   收入概览
47
48
49
50
51
52
53
54
            this.barChartOption.barColor[0].value = data.aliPay
            this.barChartOption.barColor[1].value = data.wxPay
            this.barChartOption.barColor[2].value = data.otherPay
            let barChartOption = this.barChartOption
            this.barChart=this.createBar(barChartOption);
            window.addEventListener('resize', function() {
              this.barChart.resize()
            }.bind(this));
f0fb6d92   liuqimichale   收入
55
56
57
58
          }).catch((response)=>{
            console.log(response);
          })
  
22fb20b3   songchongxian   城市停车运营监控
59
60
61
62
63
          //this.createLine();
          //debugger;
          //总收入
          this.incomeTotal=this.formatNumToStr();
          //收入Bar
4439edb0   liuqimichale   收入概览
64
  
22fb20b3   songchongxian   城市停车运营监控
65
66
67
68
69
70
71
72
73
74
75
        },
        methods: {
          /*
          * 格式化收入总数
          * */
          formatNumToStr:function(){
            return common.formatNumToStr(this.$options.data().demo);
          },
          /*
           * 创建收入Bar
           * */
4439edb0   liuqimichale   收入概览
76
77
78
          createBar:function(barChartOption){
            let root=barChartOption;
            console.log(root)
22fb20b3   songchongxian   城市停车运营监控
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
            let barChart = echarts.init(document.querySelector('.app-incomeBox .incomeBar'));
            const rightYdata=this._formatterValue(root.barColor);
            const seriesData=this._seriesData(root.barColor);
            var option={
  //            grid: {
  //              left: '0%',right: '0%',
  //              bottom: '-15%', top: '0%',
  //              containLabel: true
  //            },
              grid: {
                top: 0,left: 0,
                right: 0,bottom: -25,
                containLabel: true
              },
              title:{show:false},
              xAxis: {
                show: false,//尽管显示false,但仍然占用空间containLabel为true的话[echarts bug]
                nameGap:0
              },
              yAxis: [{
                show: true,
                data: root.name,//['支付宝', '微信', '其它'],
                inverse: true,
                axisLine: {show: false},
                splitLine: {show: false},
                axisTick: {show: false },
                axisLabel: {color: this._formatterLabel}
              }, {
                show: true,inverse: true,
                data: rightYdata,//右侧Y轴值
                axisLabel: {
                  textStyle: {fontSize: 12,color: this._formatterLabel},
                },
                axisLine: { show: false },
                splitLine: { show: false},
                axisTick: {show: false},
              }],
              series: [{
                name: '条',
                type: 'bar',
                yAxisIndex: 0,
                data: seriesData,//百分比
                barWidth: '40%',
                itemStyle: {
                  normal: {
                    barBorderRadius: 0,
                    color: this._formatterBarColor,
                  }
                },
                label: {
                  normal: {show: false}
                },
              }, {
                name: '框',
                type: 'bar',
                yAxisIndex: 1,
                barGap: '-100%',
                data: [100, 100, 100],
                barWidth: '40%',
                itemStyle: {
                  normal: {
                    color: 'none',
                    borderColor: '#157ADB',
                    borderWidth: 0.5,
                    //barBorderRadius: 15,
                  }
                }
              }, ]
            };
            barChart.setOption(option);
            return barChart;
          },
          //格式化Y轴
          _formatterLabel: function (val, index) {
            var color = "";
            var root=this.$options.data().barChartOption;
            switch (val) {
              case '支付宝':
                color = root.textColor[0];
                break;
              case '微信':
                color = root.textColor[1];
                break;
              default:
                color = root.textColor[2];
                break;
            }
            return color;
          },
          _formatterBarColor: function (params) {
            var tmpObj={};
            var root=this.$options.data().barChartOption;
            switch (params.name) {
              case '支付宝':
                // code
                tmpObj = {
                  colorStops: [{
                    offset: 0,
                    color: root.barColor[0].from // 0% 处的颜色
                  }, {
                    offset: 1,
                    color: root.barColor[0].to // 100% 处的颜色
                  }]
                };
                break;
              case '微信':
                // code
                tmpObj = {
                  colorStops: [{
                    offset: 0,color: root.barColor[1].from // 0% 处的颜色
                  }, {
                    offset: 1, color: root.barColor[1].to // 100% 处的颜色
                  }]
                };
                break;
              default://其它
                tmpObj = {
                  colorStops: [{
                    offset: 0, color: root.barColor[2].from // 0% 处的颜色
                  }, {
                    offset: 1,color: root.barColor[2].to // 100% 处的颜色
                  }]
                };
                break;
              // code
            }
            return tmpObj;
          },
          _formatterValue:function(val){
            let tmpObj=[];
            for(let i=0;i<val.length;i++){
              tmpObj.push({value:val[i].value,textStyle:{color:val[i].color}});
            }
            return tmpObj;
          },
          //格式化series值[占比]
          _seriesData:function(val){
            var  tmpData=[];
            for(let i=0;i<val.length;i++){
              var tmpv=(val[i].value/(val[0].value+val[1].value+val[2].value))*100;
              tmpData.push(Math.round(tmpv*100)/100);
            }
            return tmpData;
          }
        },
  
      }
  </script>
  
  <style scoped  lang="scss">
    .app-incomeBox {
      width: 100%;
    .theme-card{
      height: 100%;
    }
    .incomeBar{
      position: absolute;
      margin: 0 auto;
      top:0;
      bottom: 0;
      left:0;
      width: 100%;
      height: 100%;
    }
    /*.incomeBar>div, .incomeBar canvas{*/
      /*height: 100% !important;*/
    /*}*/
  
    }
  </style>