Newer
Older
CloudBrainNew / src / views / socialLive / components / community / population.vue
wangxitong on 29 Apr 2021 2 KB 0429 submit
<!--
 * @Description: 社区人口情况
 * @Author: 王晓颖
 * @Date: 2020-11-23 10:45:08
 -->
<template>
  <chart-layout title="社区人口" @click="getData">
    <div class="block-container">
      <div class="block" style="width:33%">
        <age-bar/>
      </div>
      <div class="block" style="width:28%">
        <!--<sex-pie/>-->
        <!--<nation-pie/>-->
        <transition mode="out-in">
          <component :is="comps2[comp2]" @mouseover.native="stopComps2Change" @mouseout.native="comp2Change"/>
        </transition>
      </div>
      <div class="block" style="width:33%">
        <community-bar/>
      </div>
    </div>
    <corner1 slot="corner"/>
  </chart-layout>
</template>

<script>
import SexPie from './components/sexPie'
import nationPie from './components/nationPie'
import AgeBar from './components/ageBar'
import CommunityBar from './components/communityBar'
export default {
  name: 'population',
  components: {CommunityBar, AgeBar, SexPie, nationPie},
  data () {
    return {
      comp2ChangeTime: 3, // 隐患整体情况组件切换时间
      comp2Timer: null, // 隐患整体情况组件切换计时器
      comp2: 0, // 隐患整体情况当前组件
      comps2: ['sex-pie', 'nation-pie'] // 隐患整体情况组件切换列表
    }
  },
  mounted () {
    this.comp2Change()
  },
  methods: {
    getData () {
      this.$refs.nationPie.getData()
      this.$refs.SexPie.getData()
    },
    // 人口组件切换
    comp2Change () {
      this.comp2Timer = setTimeout(() => {
        const max = this.comps2.length - 1
        if (this.comp2 < max) {
          this.comp2++
        } else {
          this.comp2 = 0
        }
        this.comp2Change()
      }, this.comp2ChangeTime * 1000)
    },
    // 停止切换人口组件
    stopComps2Change () {
      clearInterval(this.comp2Timer)
      this.comp2Timer = null
    }
  },
  beforeDestroy () {
    this.stopComps2Change()
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .block-container{
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 0 0.02rem;
    .block{
      height:100%;
    }
  }
</style>