<template>
  <div class="app-container">
    <el-row>
      <el-form :model="query" :inline="true" label-width="auto">
        <el-form-item label="开始日期">
          <el-date-picker
            v-model="query.beginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开始日期"/>
        </el-form-item>
        <el-form-item label="结束日期">
          <el-date-picker
            v-model="query.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束日期"/>
        </el-form-item>
        <el-button type="primary" icon="el-icon-edit">统计</el-button>
        <el-button type="primary" icon="el-icon-refresh-right" @click="clearDate">清空</el-button>
        <el-button type="primary" icon="el-icon-document">报表</el-button>
      </el-form>
    </el-row>
    <el-row>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane name="list">
          <span slot="label"><i class="el-icon-s-fold"/> 列表模式</span>
          <source-statis-list :list="list"/>
        </el-tab-pane>
        <el-tab-pane name="chart">
          <span slot="label"><i class="el-icon-s-data"/> 图表模式</span>
          <source-statis-chart :list="list"/>
        </el-tab-pane>
      </el-tabs>
    </el-row>
  </div>
</template>

<script>
import SourceStatisList from './sourceStatisList'
import SourceStatisChart from './sourceStatisChart'

export default {
  name: 'SourceStatis',
  components: { SourceStatisList, SourceStatisChart },
  data() {
    return {
      activeName: 'list', // 默认tab
      dialogVisible: false,
      query: {
        beginDate: '',
        endDate: ''
      },
      list: [
        {
          sourceName: '渣土车辆管理',
          upNum: 516,
          eventNum: 516,
          partNum: 0
        },
        {
          sourceName: '终端-普通上报',
          upNum: 44302,
          eventNum: 41270,
          partNum: 3032
        },
        {
          sourceName: '视频监控',
          upNum: 22267,
          eventNum: 22267,
          partNum: 0
        }
      ]
    }
  },
  mounted() {

  },
  methods: {
    clearDate() {
      this.query.beginDate = ''
      this.query.endDate = ''
    },
    handleClick(tab, event) {
      this.activeName = tab.name
      if (tab.name === 'chart') {
        setTimeout(() => {
          tab.$children[0].chart.resize()
        }, 50)
      }
    }
  }
}
</script>

<style scoped>
</style>
