<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="供应商" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="slaughterTime">
        <el-date-picker clearable
          v-model="queryParams.slaughterTime"
          type="date"
            value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
       </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="reportList">
      <el-table-column label="日期" align="center" prop="slaughterTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.slaughterTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="supplierName" width="180" />
      <el-table-column label="肉商" align="center" prop="purchaserName" width="120"/>
      <el-table-column label="数量(头)" align="center" prop="amount" width="120"/>
      <el-table-column label="宰前重量(kg)" align="center" prop="beforeWeight" min-width="100"/>
      <el-table-column label="宰后重量(kg)" align="center" prop="inspectionDetail" width="100">
        <template slot-scope="scope">
          {{ totalWeight(scope.row)}}
        </template>
      </el-table-column>
      <el-table-column label="宰后白条重量(kg)" align="center" prop="sideWeight" width="100"/>
      <el-table-column label="猪头重量(kg)" align="center" prop="headWeight" width="100"/>
      <el-table-column label="红脏重量(kg)" align="center" prop="redWeight" width="100"/>
      <el-table-column label="白脏重量(kg)" align="center" prop="whiteWeight" width="100"/>
      <el-table-column label="肉品品质检验合格证号" align="center" prop="meatCert" width="180"/>
      <el-table-column label="动物检疫合格证号" align="center" prop="animalCert" width="180"/>
      <el-table-column label="销售去向" align="center" prop="salePlace" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_origin_type" :value="scope.row.salePlace"/>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listSlaughterReport } from "@/api/app/dataReport";

export default {
  name: "SlaughterReport",
  dicts: ['app_origin_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      reportList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        slaughterTime: null,
        supplierName: null,
      },
    };
  },
  computed:{

  },
  created() {
    this.getList();
  },
  methods: {
    totalWeight(row){
      let all = row.sideWeight + row.headWeight + row.redWeight+ row.whiteWeight;
      return all!=null?all.toFixed(2):0.00;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listSlaughterReport(this.queryParams).then(response => {
        this.reportList = response.rows;

        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
