CustomerAnalyse.vue 6.63 KB
Newer Older
1
<template>
2
  <CellWrapper title="大客户分析">
潘际乾 committed
3
    <template v-slot:header>
潘际乾 committed
4
      <span class="el-icon-refresh" title="刷新"></span>
潘际乾 committed
5
      <span class="el-icon-more" title="操作"></span>
潘际乾 committed
6 7 8
    </template>

    <div class="chart-container">
9 10 11 12
      <div class="chart-operate">
        <i class="el-icon-arrow-up"></i>
        <i class="el-icon-arrow-down"></i>
      </div>
潘际乾 committed
13 14
      <div class="chartWrapper">
        <div class="chart"></div>
潘际乾 committed
15
      </div>
16
    </div>
潘际乾 committed
17
  </CellWrapper>
18 19 20
</template>

<script>
潘际乾 committed
21
import CellWrapper from "../common/CellWrapper.vue";
22
import * as echarts from "echarts";
23
import { busvolume, finamount, expincome } from "~/service/report";
24 25 26

export default {
  name: "CustomerAnalyse",
潘际乾 committed
27
  components: { CellWrapper },
28
  data() {
潘际乾 committed
29 30
    return {
      echartInstance: null,
31 32
      //componentIndex
      mapping: {
33
        0: "busvol",
34 35 36
        1: "iaefts",
        2: "expben",
      },
37 38 39 40
      category: [],
      seriesData : [] ,
      seriesData1 : [] ,
      seriesData2 : [] ,
潘际乾 committed
41
    };
42 43
  },
  mounted() {
44 45 46
    // 仅在整个视图都被渲染之后才会运行的代码
    this.$nextTick(async() => {
      await this.loadData();
潘际乾 committed
47 48 49 50
      this.loadCharts();
      this.loadChartsBind = this.loadCharts.bind(this);
      window.addEventListener("resize", this.loadChartsBind);
    });
潘际乾 committed
51 52
  },
  methods: {
53
    async loadData() {
54
      //统计 业务量
55
      const volume = await busvolume();
56
      let volumes = Array.from(volume);
57
      //统计 融资量
58
      const amount = await finamount();
59
      let amounts =  Array.from(amount);
60
      //统计 费用收益
61
      const income = await expincome();
62 63
      let incomes = Array.from(income)

64 65 66 67 68 69
      let categoryArr = [];
            //定义 seriesData数组 金额  category数组 客户名
      // let seriesData = [];
      // let seriesData1 = [];
      // let seriesData2 = [];
      
70 71 72 73 74 75 76 77 78 79 80 81 82
      // 优先遍历客户名,方便后续的数组匹配
      // volume.forEach((v) => {
      //   console.log(v.nam1)

      //   category.push(v.nam1);
      //   console.log(category.toString());
      //   console.log(category)
      // });
      
      for (let i = 0; i < volume.length; i++) {
        let v = volume[i].nam1;
        // console.log(typeof v);
        // console.log(volume[i].nam1);
83
        categoryArr.push(v);
84 85 86 87 88

        // console.log(category.toString());
        // console.log(category);
        // console.log(typeof category);
      }
89
      this.category = categoryArr;
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
      //存在bug后续要解决

      // amount.forEach((v) => {
      //   for (let i = 0; i < category.length; i++) {
      //     if (category[i] == v.nam1) {
      //       continue;
      //     } else {
      //       category.push(v.nam1);
      //     }
      //   }
      // });

       //存在bug后续要解决
      // income.forEach((v) => {
      //   for (let i = 0; i < category.length; i++) {
      //     if (category[i] == v.nam1) {
      //       continue;
      //     } else {
      //       category.push(v.nam1);
      //     }
      //   }
      // });
112
      const volumeArr = []
113
      volumes.forEach((v) => {
114 115 116
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
            volumeArr.push(v.amount)
117 118 119 120
            break;
          }
        }
      });
121 122
      this.seriesData = volumeArr;
      const amountArr = []
123
      amounts.forEach((v) => {
124 125 126
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
           amountArr.push(v.amount);
127 128 129 130
            break;
          }
        }
      });
131 132
      this.seriesData1 = amountArr;
      const incomeArr = []
133
      incomes.forEach((v) => {
134 135 136
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
            incomeArr.push(v.amount);
137 138 139 140
            break;
          }
        }
      });
141 142 143 144 145 146 147 148 149 150
      this.seriesData2 = incomeArr;
    },
    //加载图标函数
    loadCharts() {
      if (this.echartInstance) {
        this.echartInstance.dispose();
      }
      this.echartInstance = echarts.init(
        this.$el.querySelector(".chart-container .chartWrapper .chart")
      );
151

潘际乾 committed
152 153 154 155 156 157
      const option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
158
        },
潘际乾 committed
159 160
        legend: {
          bottom: "2%",
161
        },
潘际乾 committed
162 163 164 165 166
        grid: {
          left: "1%",
          right: "6%",
          top: "1%",
          containLabel: true,
167
        },
潘际乾 committed
168 169
        xAxis: {
          type: "value",
170
          boundaryGap: ["10%", "20%"],
潘际乾 committed
171 172 173
        },
        yAxis: {
          type: "category",
174
          data: this.category,
潘际乾 committed
175 176 177
        },
        series: [
          {
178
            name: "业务量金额(美元)",
潘际乾 committed
179
            type: "bar",
180
            data: this.seriesData,
潘际乾 committed
181 182
          },
          {
183
            name: "融资量金额(万美元)",
潘际乾 committed
184
            type: "bar",
185
            data: this.seriesData1,
潘际乾 committed
186 187
          },
          {
188
            name: "费用收益金额(千美元)",
潘际乾 committed
189
            type: "bar",
190
            data: this.seriesData2,
潘际乾 committed
191 192 193
          },
        ],
      };
194

潘际乾 committed
195
      this.echartInstance.setOption(option);
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

      //echart on事件来跳转页面
      // this.echartInstance.on(
      //   'click',
      //   function (params) =>{
      //     alert(params.name);
      //     this.$router.push('/taskList')
      // }

      this.echartInstance.on("click", (params) => {
        console.log(params);
        console.log(params.name);

        var name = parseInt(params.name);
        let path = params.componentIndex;

        //  要使用=>函数使内外的this指向一致
        if (path === 0) {
214 215 216 217
          this.$router.push({
            path:"/business/Busvol",
            query:{name: params.name}

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
          });
        } else if (path === 1) {
          //{path:"/xxxpath",query:"id:xxx"} router跳转页面传参业务 接受页面用created(){if(this.$route.query){todo}}
          this.$router.push({
            path:"/business/Iaefts",
            query:{name: params.name}
            });

        } else {
          //{path:"/xxxpath",query:"id:xxx"} router跳转页面传参业务 接受页面用created(){if(this.$route.query){todo}}
          this.$router.push({
           path:"/business/Expben",
           query:{name:params.name}
        });

        }
      });
    },

    destroyed() {
      window.removeEventListener("resize", this.loadChartsBind);
潘际乾 committed
239
    },
潘际乾 committed
240
  },
241 242 243
};
</script>

244
<style>
潘际乾 committed
245 246
.chart-container {
  height: 100%;
潘际乾 committed
247 248 249 250
  display: flex;
  flex-direction: column;
  padding: 0 5px;
}
潘际乾 committed
251
.chart-operate {
252 253 254
  margin-left: 20px;
  height: 20px;
}
潘际乾 committed
255
.chart-operate i {
256 257
  cursor: pointer;
}
潘际乾 committed
258
.chartWrapper {
潘际乾 committed
259 260
  flex: 1;
}
潘际乾 committed
261
.chartWrapper .chart {
潘际乾 committed
262 263
  width: 100%;
  height: 100%;
264 265
  /* 将指针改变为可以跳转 */
  cursor: pointer;
266 267
}
</style>