<template>
  <div>
    <div class="box">
      <div class="box_item" v-for="item in boxList" :key="item.id">
        <p>{{item.name}}</p>
        <p>{{item.value}}</p>
      </div>
    </div>
    <div class="form_item">
      <el-form :inline="true">
        <el-form-item label="时间:">
          <el-date-picker
              v-model="value2"
              type="datetimerange"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="right">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="母猪存栏:">
          <el-select filterable style="width: 120px;"></el-select>
        </el-form-item>
        <el-form-item label="母猪新增:">
          <el-select filterable  style="width: 120px;"></el-select>
        </el-form-item>
        <el-form-item label="耳标离线:">
          <el-select filterable style="width: 120px;"></el-select>
        </el-form-item>
        <el-form-item label="公猪存栏:">
          <el-select filterable style="width: 120px;"></el-select>
        </el-form-item>
        <el-form-item>
          <el-button>查询</el-button>
        </el-form-item>
        <el-form-item>
          <area-list></area-list>
        </el-form-item>
      </el-form>
    </div>
    <div class="box_table">
      <el-table
          :data="tableData"
          border
          stripe
          :header-cell-style="{'text-align':'center', 'background-color': '#F9FAFC', 'padding': '5px 0', 'color': '#666666'}"
          :cell-style="{'text-align':'center', 'padding': '5px 0'}"
          height="700"
          style="width: 100%;">
        <el-table-column
            prop="date"
            label="时间">
        </el-table-column>
        <el-table-column
            prop="date"
            label="母猪存栏">
        </el-table-column>
        <el-table-column
            prop="date"
            label="耳标离线">
        </el-table-column>
        <el-table-column
            prop="date"
            label="日龄占比 (250-1700)"
            :render-header="renderHeader">
        </el-table-column>
        <el-table-column
            prop="date"
            label="日龄占比 (1000-1700)"
            :render-header="renderHeader">
        </el-table-column>
        <el-table-column
            prop="date"
            label="日龄占比 (1700-2400)"
            :render-header="renderHeader">
        </el-table-column>
        <el-table-column
            prop="date"
            label="日龄占比 (>2400)"
            :render-header="renderHeader">
        </el-table-column>
        <el-table-column
            prop="date"
            label="配怀存栏">
        </el-table-column>
        <el-table-column
            prop="date"
            label="分娩存栏">
        </el-table-column>
        <el-table-column
            prop="date"
            label="后备存栏">
        </el-table-column>
        <el-table-column
            prop="date"
            label="公猪存栏">
        </el-table-column>
      </el-table>
      <table-footer
          :totals="totalPages"
          :size="pageSize"
          @sizeChange="sizeChange"
          @pageChange="pageChange"></table-footer>
    </div>
  </div>
</template>

<script>
import TableFooter from "../../components/TableFooter";
import areaList from "../../components/areaList";
export default {
  name: "Home",
  data() {
    return {
      boxList: [
        {
          id: 1,
          name: '母猪总存栏',
          value: 2500,
        },
        {
          id: 2,
          name: '配怀存栏',
          value: 1689
        },
        {
          id: 3,
          name: '分娩存栏',
          value: 1689
        },
        {
          id: 4,
          name: '后备存栏',
          value: 1689
        },
        {
          id: 5,
          name: '公猪存栏',
          value: 1689
        },
        {
          id: 6,
          name: '预计年出栏量',
          value: 50000
        },
      ],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      value2: '',
      tableData: [],
      totalPages: 0,
      pageNum: 1,
      pageSize: 20,
    }
  },
  components: {
    TableFooter,
    areaList
  },
  methods: {
    // 修改size
    sizeChange(val) {
      this.pageSize = val;
    },
    // 修改页数
    pageChange(val) {
      this.pageNum = val;
    },
    renderHeader(createElement, { column }) {
      const label = column.label
      const labelArr = label.split(' ')
      return createElement(
          'span',     //创建最外层的标签可随意
          [
            createElement('span', {  // 创建第一个元素的标签可随意
              attrs: { type: 'text' }
            },[labelArr[0]] ),
            createElement('div', {  // 创建第二个元素的标签可随意
              attrs: { type: 'text', style: 'font-size:14px' } // 给分割的某个元素单独加样式
            }, [labelArr[1] || ''] )
          ]
      )
    }
  }
}
</script>

<style scoped>
  /deep/ .el-form--inline .el-form-item {
    margin-right: 20px;
  }
  .box{
    width: 100%;
    height: 140px;
    background-color: #F9F9F9;
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 10px;
  }
  .box_item {
    width: 198px;
    height: 78px;
    border: 1px solid #ddd;
    text-align: center;
  }
  .box_item p {
    height: 39px;
    line-height: 39px;
    margin: 0;
  }
  .form_item {
    width: 100%;
    height: 60px;
    background-color: #fff;
    border: 1px solid #ddd;
    box-sizing: border-box;
    padding: 10px;
  }
  .box_table {
    width: 100%;
    box-sizing: border-box;
    margin-top: 10px;
    /*padding: 10px;*/
  }
</style>
