<template>
  <div class="container-box">
    <div class="search-box">
      <el-form
        :inline="true"
        ref="searchForm"
        :model="searchForm"
        class="demo-form-inline"
        label-width="auto"
        size="mini"
      >
        <el-form-item label="养殖场">
          <el-input
            v-model="searchForm.farm"
            placeholder="请输入养殖场"
          ></el-input>
        </el-form-item>

        <el-form-item label="标记编号">
          <el-input
            v-model="searchForm.number"
            placeholder="请输入标记编号"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="success" icon="el-icon-search" @click="searchClick"
            >搜索</el-button
          >
          <el-button type="warning" icon="el-icon-refresh" @click="resetClick"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="list-box">
      <el-table
        :data="tableData"
        style="width: 100%"
        size="mini"
        border
        :header-cell-style="{ textAlign: 'center', color: '#606266' }"
        :cell-style="cellStyle"
      >
        <el-table-column prop="farm" label="养殖场"></el-table-column>
        <el-table-column prop="number" label="标记编号"></el-table-column>
        <el-table-column prop="age" label="月龄"></el-table-column>
        <el-table-column prop="result" label="检测结果"></el-table-column>
        <el-table-column label="详情">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="detailClick(scope.row)"
              class="detail-btn"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="page-box">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="form.page"
          :page-size="form.pagesize"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchForm: {
        farm: '',
        number: ''
      },
      tableData: [
        {
          id: 1,
          farm: '若尔盖',
          number: '82010000990',
          age: '6',
          result: '携带'
        },
        {
          id: 2,
          farm: '若尔盖',
          number: '82010000991',
          age: '6',
          result: '未携带'
        },
        {
          id: 3,
          farm: '若尔盖',
          number: '82010000992',
          age: '6',
          result: '携带'
        },
        {
          id: 4,
          farm: '若尔盖',
          number: '82010000993',
          age: '6',
          result: '未携带'
        },
        {
          id: 5,
          farm: '若尔盖',
          number: '82010000994',
          age: '6',
          result: '未携带'
        },
        {
          id: 6,
          farm: '若尔盖',
          number: '82010000995',
          age: '6',
          result: '未携带'
        },
        {
          id: 7,
          farm: '若尔盖',
          number: '82010000996',
          age: '6',
          result: '未携带'
        },
        {
          id: 8,
          farm: '若尔盖',
          number: '82010000997',
          age: '6',
          result: '未携带'
        },
        {
          id: 9,
          farm: '若尔盖',
          number: '82010000973',
          age: '6',
          result: '未携带'
        }
      ],
      form: {
        page: 1,
        pagesize: 20
      },
      total: 9
    }
  },
  methods: {
    // 搜索
    searchClick() {},
    // 重置
    resetClick() {
      for (const key in this.searchForm) {
        this.searchForm[key] = ''
      }
    },
    // 条
    handleSizeChange(val) {
      this.form.pagesize = parseInt(val)
    },
    // 页
    handleCurrentChange(val) {
      this.form.page = parseInt(val)
    },
    // 当监测结果为 已携带 的状态，加上背景色,字体颜色
    cellStyle({ row, column, rowIndex, columnIndex }) {
      // 注意，这里返回的是一个对象
      if (row.result == '携带' && column.label == '检测结果') {
        return 'background:#d9001b;textAlign: center;color:#fff;'
      } else {
        return 'textAlign: center'
      }
    },
    // 查看
    detailClick() {
      window.open(
        'https://smart-1259258654.cos.ap-guangzhou.myqcloud.com/pdf/99715011920%E7%89%9B%E9%81%97%E4%BC%A0%E7%97%85%E5%9F%BA%E5%9B%A0%E6%A3%80%E6%B5%8B%E6%8A%A5%E5%91%8A.pdf'
      )
    }
  }
}
</script>

<style lang="less" scoped>
.container-box {
  min-height: calc(100vh - 84px);
  padding: 15px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .search-box {
    background: #fff;
    border-radius: 6px;
    padding: 10px 15px;
    margin-bottom: 25px;
  }
  .list-box {
    flex: 1;
    background: #fff;
    border-radius: 6px;
    padding: 10px 15px;
    .detail-btn {
      color: #67c23a;
    }
    .page-box {
      margin-top: 10px;
    }
  }
}
.el-form-item {
  margin-bottom: 0px;
  margin-right: 20px;
}
// table
/deep/.el-table th.el-table__cell {
  background-color: #f5f7fa;
}
/deep/ .cell {
  font-weight: normal;
}
</style>