<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.a"
            placeholder="请输入养殖场"
          ></el-input>
        </el-form-item>

        <el-form-item label="标记编号">
          <el-input
            v-model="searchForm.b"
            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" v-if="showtable">
      <el-table
        :data="tableData"
        style="width: 100%"
        size="mini"
        border
        :header-cell-style="{ textAlign: 'center', color: '#606266' }"
        :cell-style="cellStyle"
      >
        <el-table-column prop="a" label="养殖场"></el-table-column>
        <el-table-column prop="b" label="标记编号"></el-table-column>
        <el-table-column prop="c" 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-column prop="e" label="遗传病风险"></el-table-column>
        <el-table-column label="详情">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="report(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="[20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="form.page"
          :page-size="form.pagesize"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <div
      v-loading="loading"
      element-loading-text="加载中"
      v-else
      style="
        width: 100%;
        text-align: center;
        padding: 50px 0px 50px 0px;
        background: white;
      "
    >
      <img
        style="width: 80%"
        src="https://smart-1251449951.cos.ap-guangzhou.myqcloud.com/iot_breed/farm/2024/08/307d7b147050a9475b2580aa1d1ae44476.jpg"
        alt=""
      />
    </div>
    <el-dialog :visible.sync="dialogVisible" width="40%">
      <div style="text-align: center">
        <div class="btmstyle">1</div>
        <div class="textstyle">
          <div>标记编号:213</div>
          <div>养殖场:234</div>
          <div>品种信息:43223</div>
        </div>
        <div
          style="
            text-align: left;
            padding: 30px 0px 18px 14px;
            font-weight: bold;
          "
        >
          11
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="mini">关闭</el-button>
        <el-button type="success" size="mini" @click="dialogVisible = false"
          >下载</el-button
        ><el-button type="success" size="mini" @click="dialogVisible = false"
          >打印</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      showtable: false,
      dialogVisible: true,
      searchForm: {
        a: '',
        b: '',
        c: '',
        d: '',
        e: '',
        f: ''
      },
      tableData: [
        {
          a: '若尔盖',
          b: '82010000990',
          c: '123',
          d: '详情',
          e: '未携带',
          f: '报告'
        },
        {
          a: '若尔盖',
          b: '82010000991',
          c: '100',
          d: '详情',
          e: '未携带'
        },
        {
          a: '若尔盖',
          b: '82010000992',
          c: '96',
          d: '详情',
          e: '携带'
        },
        {
          a: '若尔盖',
          b: '82010000993',
          c: '85',
          d: '详情',
          e: '携带'
        },
        {
          a: '若尔盖',
          b: '82010000994',
          c: '74',
          d: '详情',
          e: '未携带'
        },
        {
          a: '若尔盖',
          b: '82010000995',
          c: '56',
          d: '详情',
          e: '携带'
        },
        {
          a: '若尔盖',
          b: '82010000996',
          c: '58',
          d: '详情',
          e: '未携带'
        },
        {
          a: '若尔盖',
          b: '82010000997',
          c: '98',
          d: '详情',
          e: '携带'
        }
      ],
      form: {
        page: 1,
        pagesize: 20
      },
      total: 8
    }
  },
  methods: {
    detailClick() {
      this.$router.push('/phylogeneticAnalysis/evolutionaryTree')
    },
    report() {
      this.dialogVisible = true
    },
    // 搜索
    searchClick() {
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.showtable = true
      }, 1500)
    },
    // 重置
    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'
      }
    }
  }
}
</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;
}
.btmstyle {
  border-bottom: 2px solid #ebebeb;
  padding-bottom: 26px;
}
.textstyle {
  display: flex;
  padding: 24px;
  border-bottom: 2px solid #ebebeb;
}
.textstyle div {
  margin-right: 15%;
}
// table
/deep/.el-table th.el-table__cell {
  background-color: #f5f7fa;
}
/deep/ .cell {
  font-weight: normal;
}
</style>