<template>
  <div>
    <div class="header_title">牧场概况--{{farmName}}
      <div class="right_float" @click="backBtn">返回上一页</div>
    </div>
    <div>
      <div class="box">
        <div class="box_item">
          <p>母猪总存栏</p>
          <p class="number">
            {{boxList.stockToal}}
            <template v-if="boxList.sowTotalStockValue !== 0">
              <i :class="['icon', boxList.sowTotalStockType ? '' : 'icon_red']"></i>
              <span v-if="boxList.sowTotalStockType" class="icon_green">+{{boxList.sowTotalStockValue}}</span>
              <span v-else class="icon_dev">-{{boxList.sowTotalStockValue}}</span>
            </template>
          </p>
        </div>
        <div class="box_item">
          <p>能繁母猪存栏</p>
          <p class="number">{{boxList.sowStock}}</p>
        </div>
        <div class="box_item">
          <p>配怀存栏</p>
          <p class="number">{{boxList.stock1}}</p>
        </div>
        <div class="box_item">
          <p>分娩存栏</p>
          <p class="number">{{boxList.stock2}}</p>
        </div>
        <div class="box_item">
          <p>后备存栏</p>
          <p class="number">{{boxList.stock3}}</p>
        </div>
      </div>
      <!-- 拆分 市 -->
      <div class="form_item">
        <el-form :inline="true" size="mini">
          <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-input style="width: 50px;" v-model="minStockTotal"></el-input>
            &nbsp;至&nbsp;
            <el-input style="width: 50px;" v-model="maxStockTotal"></el-input>
          </el-form-item>
          <el-form-item label="母猪新增:">
            <el-input style="width: 50px;" v-model="minStockNew"></el-input>
            &nbsp;至&nbsp;
            <el-input style="width: 50px;" v-model="maxStockNew"></el-input>
          </el-form-item>
          <el-form-item label="耳标离线:">
            <el-input style="width: 50px;" v-model="minOfflineNo"></el-input>
            &nbsp;至&nbsp;
            <el-input style="width: 50px;" v-model="maxOfflineNo"></el-input>
          </el-form-item>
          <el-form-item label="能繁母猪:">
            <el-input style="width: 50px;" v-model="minSowStock"></el-input>
            &nbsp;至&nbsp;
            <el-input style="width: 50px;" v-model="maxSowStock"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search">查询</el-button>
          </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
              label="时间">
            <template slot-scope="scope">
              <span>{{scope.row.statisticDate.split(' ')[0]}}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="stockTotal"
              label="母猪总存栏">
          </el-table-column>
          <el-table-column
              prop="stockNew"
              label="母猪新增">
          </el-table-column>
          <el-table-column
              prop="offlineNo"
              label="耳标离线">
          </el-table-column>
          <el-table-column
              prop="sowStock"
              label="能繁母猪存栏">
          </el-table-column>
          <el-table-column label="存栏能繁母猪月龄分布">
            <el-table-column
                prop="ratio1"
                label="8月-20月">
            </el-table-column>
            <el-table-column
                prop="ratio2"
                label="20月-32月">
            </el-table-column>
            <el-table-column
                prop="ratio3"
                label="32月-44月">
            </el-table-column>
            <el-table-column
                prop="ratio4"
                label=">44月">
            </el-table-column>
          </el-table-column>
          <el-table-column
              prop="stock1"
              label="配怀存栏">
          </el-table-column>
          <el-table-column
              prop="stock2"
              label="分娩存栏">
          </el-table-column>
          <el-table-column
              prop="stock3"
              label="空怀存栏">
          </el-table-column>
          <el-table-column
              prop="stock4"
              label="后备存栏">
          </el-table-column>
          <el-table-column
              prop="stock5"
              label="公猪存栏">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="jump(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <table-footer
            :totals="totalPages"
            :size="pageSize"
            @sizeChange="sizeChange"
            @pageChange="pageChange"></table-footer>
      </div>
    </div>
  </div>
</template>

<script>
import TableFooter from "../../../components/TableFooter";
import utils from '../../../utils/index';
import {mapState} from "vuex";
export default {
  name: "farm",
  components: {
    TableFooter
  },
  props: ['farmCode', 'farmName'],
  data() {
    return {
      boxList: {},
      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,
      minStockTotal: '',
      maxStockTotal: '',
      minStockNew: '',
      maxStockNew: '',
      minOfflineNo: '',
      maxOfflineNo: '',
      minSowStock: '',
      maxSowStock: '',
      isProvince: false,
    }
  },
  computed: {
    ...mapState(['baseUrl'])
  },
  methods: {
    getDate(val) {
      return utils.timeDate(val);
    },
    getCityCode(val) {
      let len = val.length;
      this.countyCode = val[len - 1];
    },
    // 修改size
    sizeChange(val) {
      this.pageSize = val;
    },
    // 修改页数
    pageChange(val) {
      this.pageNum = val;
    },
    search() {
      // this.init();
      this.onFarm();
    },
    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] || ''])
          ]
      )
    },
    // // 去牧场
    onFarm() {
      let params = {
        farmCode: this.farmCode,
        startTime: this.value2[0],
        endTime: this.value2[1],
        minStockTotal: this.minStockTotal,
        maxStockTotal: this.maxStockTotal,
        minStockNew: this.minStockNew,
        maxStockNew: this.maxStockNew,
        minOfflineNo: this.minOfflineNo,
        maxOfflineNo: this.maxOfflineNo,
        minSowStock: this.minSowStock,
        maxSowStock: this.maxSowStock,
      }
      this.$http({
        url: this.$http.adornUrl(`${this.baseUrl}/manager/dailytabulatedata/list`),
        method: 'get',
        params: this.$http.adornParams(params)
      })
          .then(res => {
            if(res.data.code === 0) {
              this.tableData = res.data.page.list;
            }
            console.log(res);
          })
    },
    // 选择
    // onSelect(row) {
    //   console.log(row);
    //   this.countyCode = row.code;
    //   this.type = row.type;
    //   this.$emit('getCountyCode', {countyCode: this.countyCode, type: this.type});
    //   // if (row.type === 1) {
    //   //   this.initCity();
    //   // } else if (row.type === 2) {
    //   //   this.initCounty();
    //   // }
    // },
    jump(row) {
      this.$router.push({
        path: '/dayData',
        query: {
          farmCode: row.farmCode
        }
      })
    },
    // 统计
    initState() {
      this.$http({
        url: this.$http.adornUrl('http://122.112.224.199:9000/manager/dailytabulatedata/countAllsow'),
        method: 'get',
        params: this.$http.adornParams({farmCode: this.farmCode})
      })
          .then(res => {
            if(res.data.code === 0) {
              this.boxList = res.data.data;
            }
          })
    },
    backBtn() {
      this.$emit('backBtn', 4);
    }
  },
  mounted() {
    this.onFarm();
    this.initState();
  }
}
</script>

<style scoped>
/deep/ .el-form--inline .el-form-item {
  margin-right: 15px;
}
.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: 15px;
}
.box_table {
  width: 100%;
  box-sizing: border-box;
  margin-top: 10px;
  padding-right: 10px;
  /*padding: 10px;*/
}
.icon {
  display: inline-block;
  background-image: url("../../../assets/up.png");
  width: 24px;
  height: 24px;
  background-size: 100% 100%;
}
.icon_red {
  background-image: url("../../../assets/decline.png");
  background-size: 100% 100%;
}
.number {
  font-size: 24px;
  font-weight: 600;
}
.icon_green {
  color: #33FA40;
  font-size: 16px;
}
.icon_dev {
  color: #DA331D;
  font-size: 16px;
}
.header_title {
  height: 40px;
  background-color: #F7F7F7;
  border: 1px solid #ddd;
  line-height: 40px;
  color: #6FA8C8;
  margin-bottom: 10px;
  padding-left: 20px;
  position: relative;
}
.right_float {
  width: 100px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  border: 1px solid #ddd;
  border-radius: 10px;
  position: absolute;
  top: 5px;
  right: 15px;
  cursor: pointer;
}
</style>
