<template>
  <div>
    <!-- 细菌列表 -->
    <div>
      <div class="mjy" v-show="!showDetail">
        <el-form :model="queryParams" ref="queryForm" class="search-area" :inline="true" label-width="88px">
          <!-- 名称 -->
          <el-form-item :label="$t('page.business.study.cell.mc') + '：'">
            <el-input v-model="queryParams.mc" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 编号 -->
          <el-form-item :label="$t('page.business.study.cell.bh') + '：'">
            <el-input v-model="queryParams.bh" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 来源 -->
          <el-form-item :label="$t('page.business.study.cell.ly') + '：'">
            <el-input v-model="queryParams.ly" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 所属试验 -->
          <el-form-item :label="$t('page.business.study.cell.sssy') + '：'">
            <el-input v-model="queryParams.studyName" clearable @change="handleQuery"
              :placeholder="$t('form.placeholderInput')" />
          </el-form-item>
          <!-- 失效日 -->
          <el-form-item :label="$t('page.business.study.cell.sxr') + '：'">
            <el-date-picker v-model="daterange" class="chat-histogram-daterange" type="daterange" range-separator="-"
              :start-placeholder="$t('form.startDate')" :end-placeholder="$t('form.endDate')" value-format="yyyy-MM-dd"
              @change="handleQuery" style="width: 250px;" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('form.search') }}</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('form.reset') }}</el-button>
          </el-form-item>
        </el-form>


        <el-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.study.cell.mc')" align="left" prop="mc"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.study.cell.bh')" align="center" prop="bh"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.study.cell.tj')" align="center">
            <template slot-scope="scope">
              {{ scope.row.tj }}{{ scope.row.tjdw }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('page.business.study.cell.ly')" align="center" prop="ly"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.study.cell.sxr')" align="center" prop="sxr"
            :show-overflow-tooltip="true" />
          <el-table-column :label="$t('page.business.study.cell.sssy')" align="center" prop="sssy" width="150px" />

          <el-table-column :label="$t('form.operate')" fixed="right" align="center"
            class-name="small-padding fixed-width" width="250px">
            <template slot-scope="scope">
              <!-- 详情 -->
              <el-button type="text" @click="handleCz(scope.row)"                >{{
                  $t('page.business.study.cell.cz') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
      </div>
      <!-- 处置 -->
      <Cz key="Cz" ref="Cz" @callback="handleQuery" />
    </div>
  </div>
</template>

<script>
import { bacteria_studyList } from "@/api/business/bacteria/bacteria"
import Cz from "@/views/business/resource/gsp/comps/gsp/Cz";
import moment from "moment";

export default {
  name: "GspList",
  components: { Cz },
  data() {
    return {
      daterange: [],
      loading: true,
      single: true,
      multiple: true,
      showDetail: false,
      total: 0,
      list: [],
      //勾选列表
      selectList: [],
      //查询条件
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mc: null,
        jyzt: null,
        studyId: null,
        zjzt: null,
        bh: null,
        startDate: null,
        endDate: null,
      },
    }
  },
  created() {
  },
  props: {
    study: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    study: {
      handler(newVal) {
        this.queryParams.studyId = newVal.id
        this.handleQuery()
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    //处置
    handleCzyj(row) {
      this.$refs.Cz.show(row)
    },
    closeXq() {
      this.showDetail = false
      this.$emit('showDetail', this.showDetail)
      this.handleQuery()
    },
    //详情
    handleXq(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Xq.show(row)
    },
    //获取列表
    getList() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.queryParams.startDate = this.daterange[0] + ' 00:00:00'
        this.queryParams.endDate = this.daterange[1] + ' 23:59:59'
      } else {
        this.queryParams.startDate = ''
        this.queryParams.endDate = ''
      }
      this.loading = true
      bacteria_studyList(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    //查询
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    //重置
    resetQuery() {
      this.daterange = []
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.mjy {
  background: #fff;
  padding: 10px 10px;
}
</style>