<template>
  <div>
    <div class="table">
      <el-table border stripe :data="data" highlight-current-row>
        <el-table-column
          type="index"
          align="center"
          label="序号"
          width="50px"
        />
        <el-table-column prop="checkPerson" label="检查类型" align="center" />
        <el-table-column prop="checkTime" label="最后记录时间" align="center" />
        <el-table-column prop="recordStatus" label="状态" align="center"
          >
          <template slot-scope="scope">
            <div

              disable-transitions
              >{{(scope.row.recordStatus ==''|| scope.row.recordStatus ==null) ? '进行中' : '已完成'}}</div
            >
          </template>
        </el-table-column>

        <el-table-column
          prop="anomalousStatus"
          :formatter="formatterColumn"
          label="有无异常"
          align="center"
          >
          <template slot-scope="scope">
            <div
              >{{ scope.row.anomalousStatus== '1'?'有': '无' }}  </div
            >
          </template>
        </el-table-column>
        <el-table-column prop="checkList" label="异常项" align="center" >
          <template slot-scope="scope">
            <div

              disable-transitions
              >{{ scope.row.waterAbnormal== '1'?'水分检测异常': '' }} {{ scope.row.grainAbnormal== '1'?'粮情异常': ''}} {{scope.row.pestAbnormal == '1'?'虫害异常': ''}} </div
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="operation"
          label="操作"
          align="center"
          width="200px"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button size="mini" @click="add(2, scope.$index, scope.row)"
              >新增</el-button
            >
            <el-button size="mini" @click="moreRecords(scope.$index, scope.row)"
              >更多记录</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
// 引入接口
import { getNewGrainInfo } from "@/api/grainCheck/index"
export default {
  name: "NewGrain",
  data() {
    return {
      activeName: "NewGrain",
      // 最新粮情数据
       abnormalItems:[],
      data: [],

      newGrainData: [
        {
          checkPerson: "保管员每周检查粮情",
          checkTime: "",
          recordStatus: "进行中",
          anomalousStatus: "1",
          checkList: "虫害异常、水分检测异常、粮情异常",
          id: 1
        },
      ],
      tindex: ""
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.activeName = this.$route.name
  },
  /*   mounted() {
    this.activeName = this.$route.name

  }, */
  methods: {
    //获取最新粮情
    getList() {
      let data = {
        pageIndex: 1,
        pageSize: 20
      }
      getNewGrainInfo(data)
        .then(res => {
          console.log(res)
          this.data = res.data
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 状态改成图标
    formatterColumn(row, column) {
      switch (row.isAbnormal) {
        case "0":
          return "无"
          break
        case "1":
          return "有"
          break
      }
    },
    // 新增按钮
    add(type, index, row) {
      this.$router.push({
        path: "/grainCheck/addNewGrain",
        query: { type: type, pid: row.id, data: row }
      })
    },
    // 更多记录
    moreRecords(index, row) {
      this.$router.push({ path: "allGrain" })
      // console.log(scope.$index, scope.row)
    },
    handleClick(tab, event) {
      console.log(tab, event)
      this.$router.push(tab.name)
    }
  }
}
</script>
