Blame view

src/components/incomeOverview/index.vue 8.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
  <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'
e52cf1d6   liuqimichale   添加丹阳
22
    import { incomeAddress, incomeAddressDY } from '../../api/api'
22fb20b3   songchongxian   城市停车运营监控
23
24
25
26
      export default {
        name: "incomeOverview",
        data() {
          return {
74b5bee2   liuqimichale   全局 接口参数
27
            demo:'',//示例
22fb20b3   songchongxian   城市停车运营监控
28
29
30
31
32
33
34
35
36
37
38
39
40
41
            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() {
848073f1   liuqimichale   api 接口封装 收入
42
          this.onLoad()
22fb20b3   songchongxian   城市停车运营监控
43
44
        },
        methods: {
848073f1   liuqimichale   api 接口封装 收入
45
          onLoad() {
e52cf1d6   liuqimichale   添加丹阳
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            // incomeAddress({
            //   orgIds: this.GLOBAL.paramsvariables
            // }).then((response)=>{
            //   let  data = response.data.data
            //   this.incomeTotal = data.totalPay
            //   this.incomeTotal = common.formatNumToStr(Math.round(this.incomeTotal/100))
            //   this.barChartOption.barColor[0].value = Math.round(data.aliPay/100)
            //   this.barChartOption.barColor[1].value = Math.round(data.wxPay/100)
            //   this.barChartOption.barColor[2].value = Math.round(data.otherPay/100)
            //   let barChartOption = this.barChartOption
            //   this.barChart=this.createBar(barChartOption);
            //   window.addEventListener('resize', function() {
            //     this.barChart.resize()
            //   }.bind(this));
            // }).catch((response)=>{
            //   console.log(response);
            // })
  
  
            this.$axios.all(
              [
e86ba720   liuqimichale   地图点击事件
67
                incomeAddress({ orgIds: [10003,10005]}),
1bc516df   liuqimichale   地图点击事件
68
                incomeAddressDY({ orgIds: this.GLOBAL.variables})
e52cf1d6   liuqimichale   添加丹阳
69
70
71
              ]
            )
            .then(this.$axios.spread((acctWX, acctDY) => {
e86ba720   liuqimichale   地图点击事件
72
73
74
              console.log('1')
              console.log(acctWX)
              console.log(acctDY)
e52cf1d6   liuqimichale   添加丹阳
75
76
              let WXdata = acctWX.data.data
              let DYdata = acctDY.data.data
e86ba720   liuqimichale   地图点击事件
77
  
e52cf1d6   liuqimichale   添加丹阳
78
              this.incomeTotal = WXdata.totalPay+DYdata.totalPay
848073f1   liuqimichale   api 接口封装 收入
79
              this.incomeTotal = common.formatNumToStr(Math.round(this.incomeTotal/100))
e52cf1d6   liuqimichale   添加丹阳
80
81
82
83
  
              this.barChartOption.barColor[0].value = Math.round((WXdata.aliPay+DYdata.aliPay)/100)
              this.barChartOption.barColor[1].value = Math.round((WXdata.wxPay+DYdata.wxPay)/100)
              this.barChartOption.barColor[2].value = Math.round((WXdata.otherPay+DYdata.otherPay)/100)
848073f1   liuqimichale   api 接口封装 收入
84
85
86
87
88
              let barChartOption = this.barChartOption
              this.barChart=this.createBar(barChartOption);
              window.addEventListener('resize', function() {
                this.barChart.resize()
              }.bind(this));
e52cf1d6   liuqimichale   添加丹阳
89
90
91
  
            }))
  
22fb20b3   songchongxian   城市停车运营监控
92
93
94
95
          },
          /*
           * 创建收入Bar
           * */
4439edb0   liuqimichale   收入概览
96
97
98
          createBar:function(barChartOption){
            let root=barChartOption;
            console.log(root)
22fb20b3   songchongxian   城市停车运营监控
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
            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>