<!-- * @Description:车/人通行次数 * @Author: 王晓颖 * @Date: 2020-11-24 15:27:11 --> <template> <single-layout :title="title"> <div style="width: 100%;height:100%;padding:0.1rem" onmouseover.native="stopCompChange" onmouseleave.native="compChange"> <simple-bar-chart :id="options.id" :unit="options.unit" :height="options.height" :xAxisData="options.xAxisData" :seriesData="options.seriesData" /> </div> </single-layout> </template> <script> import SingleLayout from '@/components/layout/singleLayout' import ColorfulHorizontalBarChart from '@/components/barChart/colorfulHorizontalBarChart' import ColorfulBarChart from '@/components/barChart/colorfulBarChart' import SimpleBarChart from '@/components/barChart/simpleBarChart' import {fetchCarCount, fetchPeopleCount} from '@/api/community' import mockData from '../../../../../../static/socialLive.json' export default { name: 'goThroughBar', components: {SimpleBarChart, ColorfulBarChart, ColorfulHorizontalBarChart, SingleLayout}, data () { return { title: '车通行情况', currentComp: 'car', compChangeTime: 10, // 30s切换 compTimer: null, // 切换查询接口定时器 options: { id: 'go-through-bar', height: '100%', width: '100%', unit: '', xAxisData: [ '温馨家园F1-20', '温馨家园F1-9', '温馨家园F1-7', '温馨家园F1-14', '温馨家园F1-2', '金色春城小区', '温馨家园', '碧桂园', '516', '伟创力宿舍' ], // xAxisData: ['', '', '', '', ''], seriesData: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } } }, created () { this.compChange() this.getData() }, methods: { compChange () { this.compTimer = setTimeout(() => { this.currentComp = this.currentComp === 'car' ? 'people' : 'car' this.getData() this.compChange() }, this.compChangeTime * 1000) }, // 停止切换人口组件 stopCompChange () { clearInterval(this.compTimer) this.compTimer = null }, getData () { if (this.currentComp === 'people') { this.title = '人通行情况' this.options.xAxisData = mockData.left.goThrough.barPeople.xAxisData this.options.seriesData = mockData.left.goThrough.barPeople.seriesData } else { this.title = '车辆通行情况' this.options.xAxisData = mockData.left.goThrough.barCar.xAxisData this.options.seriesData = mockData.left.goThrough.barCar.seriesData } // if (this.currentComp === 'people') { // fetchPeopleCount().then(response => { // if (response.code === 200) { // this.title = '人通行情况' // const data = response.data // this.options.xAxisData = data.map(item => { return item.name }) // this.options.seriesData = data.map(item => { return item.value }) // } // }) // } else { // this.title = '车辆通行情况' // // fetchCarCount().then(response => { // // if (response.code === 200) { // // const data = response.data // // this.options.xAxisData = data.map(item => { return item.name }) // // this.options.seriesData = data.map(item => { return item.value }) // // } // // }) // this.options.seriesData = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] // } } }, beforeDestroy () { this.stopCompChange() } } </script> <style rel="stylesheet/scss" lang="scss" scoped> </style>