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

65 66 67 68 69 70
      let categoryArr = [];
            //定义 seriesData数组 金额  category数组 客户名
      // let seriesData = [];
      // let seriesData1 = [];
      // let seriesData2 = [];
      
71 72 73 74 75 76 77 78 79 80 81 82 83
      // 优先遍历客户名,方便后续的数组匹配
      // 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);
84
        categoryArr.push(v);
85 86 87 88 89

        // console.log(category.toString());
        // console.log(category);
        // console.log(typeof category);
      }
90
      this.category = categoryArr;
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
      //存在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);
      //     }
      //   }
      // });
113
      const volumeArr = []
114
      volumes.forEach((v) => {
115 116 117
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
            volumeArr.push(v.amount)
118 119 120 121
            break;
          }
        }
      });
122 123
      this.seriesData = volumeArr;
      const amountArr = []
124
      amounts.forEach((v) => {
125 126 127
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
           amountArr.push(v.amount);
128 129 130 131
            break;
          }
        }
      });
132 133
      this.seriesData1 = amountArr;
      const incomeArr = []
134
      incomes.forEach((v) => {
135 136 137
        for (let i = 0; i < categoryArr.length; i++) {
          if (categoryArr[i] == v.nam1) {
            incomeArr.push(v.amount);
138 139 140 141
            break;
          }
        }
      });
142 143 144 145 146 147 148 149 150 151
      this.seriesData2 = incomeArr;
    },
    //加载图标函数
    loadCharts() {
      if (this.echartInstance) {
        this.echartInstance.dispose();
      }
      this.echartInstance = echarts.init(
        this.$el.querySelector(".chart-container .chartWrapper .chart")
      );
152

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

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

      //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) {
215 216 217 218
          this.$router.push({
            path:"/business/Busvol",
            query:{name: params.name}

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
          });
        } 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
240
    },
潘际乾 committed
241
  },
242 243 244
};
</script>

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