Blame view

src/components/Echart/Rose/index.vue 1.89 KB
xiaomiao committed
1 2 3 4 5 6 7 8
<!--
 * @Author: xiaomiao 1158771342@qq.com
 * @Date: 2023-03-09 15:24:53
 * @LastEditors: xiaomiao 1158771342@qq.com
 * @LastEditTime: 2023-03-16 15:58:03
 * @FilePath: \上报\bdcjg-web\src\components\Echart\Rose\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
xiaomiao committed
9 10 11 12 13 14 15
<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
xiaomiao committed
16 17 18 19 20
  import Chart from "./Chart";
  import work from "@/api/work";
  export default {
    data () {
      return {
xiaomiao committed
21
        cdata: [],
xiaomiao committed
22 23 24 25 26 27 28 29 30
        getdata: [],
      };
    },
    components: {
      Chart,
    },
    mounted () {
      this.addhousetotal();
      window.addEventListener("resize", () => {
xiaomiao committed
31
        this.cdata = [];
xiaomiao committed
32 33 34 35 36 37
        this.addhousetotal();
      });

    },
    methods: {
      async addhousetotal () {
xiaomiao committed
38
        if (this.cdata == 0) {
xiaomiao committed
39
          this.cdata = [];
xiaomiao committed
40 41 42
          try {
            let { result: res } = await work.addhousetotal();
            res.map((item) => {
xiaomiao committed
43
              return this.cdata.push({
xiaomiao committed
44 45 46
                name: `${item.fwyt + '(' + item.fwxz})`,
                value: item.mj,
              });
xiaomiao committed
47

xiaomiao committed
48
            });
xiaomiao committed
49 50
            let delarr = this.cdata.sort(this.up)
            this.setadat(delarr)
xiaomiao committed
51

xiaomiao committed
52 53 54
          } catch (error) {
            console.log("error", error);
          }
xiaomiao committed
55
        }
xiaomiao committed
56

xiaomiao committed
57 58 59 60 61

      },
      // 处理数据方法
      setadat (delarr) {

xiaomiao committed
62
        this.cdata = delarr.splice(0, 6);
xiaomiao committed
63 64 65
        let sum = 0
        for (var i = 0; i < delarr.length; i++) {
          sum = sum + delarr[i].value
xiaomiao committed
66
        }
xiaomiao committed
67
        sum = sum.toFixed(2)
xiaomiao committed
68
        this.cdata.push({
xiaomiao committed
69 70 71 72 73 74 75 76 77 78
          name: "其他(其他种类)",
          values: "其他种类",
          value: sum,
        })
      },
      // 排序方法
      up (x, y) { return y.value - x.value }

    }
  };
xiaomiao committed
79 80
</script>

xiaomiao committed
81
<style lang="scss" scoped></style>