<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="animalCertNo">
        <el-input
          v-model="queryParams.animalCertNo"
          placeholder="请输入检疫证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <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="entranceTime">
        <el-date-picker clearable
          v-model="queryParams.entranceTime"
          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="entranceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entranceTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检疫证号" align="center" prop="animalCertNo" width="180" />
      <el-table-column label="产地" align="center" prop="originPlace" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_origin_type" :value="scope.row.originPlace"/>
        </template>
      </el-table-column>
      <el-table-column label="数量(头)" align="center" width="120">
        <template slot-scope="scope">
          {{ scope.row.illnessDeadAmount + scope.row.illnessDiseaseAmount }}
        </template>
      </el-table-column>
      <el-table-column label="耳标号码" align="center" min-width="180">
        <template slot-scope="scope">
          <span v-for="(item,i) in scope.row.illnessPigsDetail" :key="i">{{ item.eartagNo }}{{ item.eartagNo?";":"" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验检疫情况" align="center" prop="inspectionDetail" min-width="240">
        <template slot-scope="scope">
          <span v-for="(item,i) in scope.row.inspectionDetail" :key="i">{{ item.itemName }}：{{ item.result }}；</span>
        </template>
      </el-table-column>
      <el-table-column label="病死头数" align="center" prop="illnessDeadAmount" width="100"/>
      <el-table-column label="病害头数" align="center" prop="illnessDiseaseAmount" width="100"/>
      <el-table-column label="急宰头数" align="center" prop="snapKillAmount" width="100"/>
      <el-table-column label="不合格产品重量(kg)" align="center" prop="unqualifiedWeight" width="120"/>
      <el-table-column label="无害化处理方式" align="center" prop="dealWay" width="180"/>

    </el-table>

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

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

export default {
  name: "InspectionReport",
  dicts: ['app_origin_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      reportList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        entranceTime: null,
        animalCertNo: null,
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listEntranceReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.reportList.map(item=>{
          item.inspectionDetail = item.inspectionDetail?JSON.parse(item.inspectionDetail):[];
          item.illnessPigsDetail = item.illnessPigsDetail?JSON.parse(item.illnessPigsDetail):[];
        })
        console.log(this.reportList)
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
