index.vue 2.05 KB
<!--
 * @Author: xiaomiao 1158771342@qq.com
 * @Date: 2023-03-09 15:24:53
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-07-04 15:28:36
 * @FilePath: \上报\bdcjg-web\src\components\Echart\Rose\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
  import Chart from "./Chart";
  import work from "@/api/work";
  export default {
    data () {
      return {
        timer: null,
        cdata: [],
        getdata: [],
      };
    },
    components: {
      Chart,
    },
    created () {
      this.addhousetotal()
      this.timer = setInterval(() => {
        this.addhousetotal()
      }, 10000) // 10s
    },
    mounted () {
      window.addEventListener("resize", () => {
        this.cdata = [];
        this.addhousetotal();
      });
    },
    methods: {
      async addhousetotal () {
        if (this.cdata == 0) {
          this.cdata = [];
          try {
            let { result: res } = await work.qxmrjrsb();
            console.log(res, 'resres');
            res.map((item) => {
              return this.cdata.push({
                name: item.areaName,
                value: item.jrl,
              });

            });
            // let delarr = this.cdata.sort(this.up)
            // this.setadat(delarr)

          } catch (error) {
            console.log("error", error);
          }
        }
      },
      // 处理数据方法
      setadat (delarr) {
        this.cdata = delarr.splice(0, 6);
        let sum = 0
        for (var i = 0; i < delarr.length; i++) {
          sum = sum + delarr[i].value
        }
        sum = sum.toFixed(2)
        this.cdata.push({
          name: "其他(其他种类)",
          values: "其他种类",
          value: sum,
        })
      },
      // 排序方法
      up (x, y) { return y.value - x.value }
    },
    destroyed () {
      clearInterval(this.timer)
    }
  }
</script>