<!-- 饲养间列表 -->
<template>
  <div>
    <div class="tbbd-list" v-show="!showDetail">
      <div class="tbbd-search">
        <el-form :model="searchForm" ref="searchForm" class="search-area" :inline="true" label-width="88px">
          <el-row>
            <el-col :span="24">
              <!-- 饲养间号 -->
              <el-form-item :label="$t('page.business.study.studyRoom.syjh')" prop="syjh">
                <el-input v-model="searchForm.syjh" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 试验区域 -->
              <el-form-item :label="$t('page.business.study.studyRoom.syqy')" prop="syqy">
                <el-input v-model="searchForm.syqy" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 启用人 -->
              <el-form-item :label="$t('page.business.study.studyRoom.qyr')" prop="qyr">
                <el-input v-model="searchForm.qyr" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 结束人 -->
              <el-form-item :label="$t('page.business.study.studyRoom.jsr')" prop="jsr">
                <el-input v-model="searchForm.jsr" :placeholder="$t('form.placeholderInput')" clearable
                  @keyup.enter.native="search" />
              </el-form-item>
              <!-- 开始时间 -->
              <el-form-item :label="$t('page.business.study.studyRoom.kssj') + '：'">
                <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="search" style="width: 250px;" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="search">{{ $t('form.search') }}</el-button>
                <el-button icon="el-icon-refresh" @click="reset">{{ $t('form.reset') }}</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

      </div>
      <div class="tbbd-content">
        <el-row class="add-box">
          <el-col>
            <el-button type="primary" icon="el-icon-plus" @click="add()" v-hasPermi="['business:studyRoom:add']">{{
              $t('page.business.study.studyRoom.xzqy') }}</el-button>
            <el-button type="primary" @click="handleExport()" v-hasPermi="['business:studyRoom:export']">{{
              $t('form.export') }}</el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="list">
          <el-table-column :label="$t('page.business.study.studyRoom.syjh')" prop="syjh" />
          <el-table-column :label="$t('page.business.study.studyRoom.syqy')" prop="syqy" />
          <el-table-column :label="$t('page.business.study.studyRoom.dwzs')" prop="dwzs" />
          <el-table-column :label="$t('page.business.study.studyRoom.longju')" align="center" prop="lj" />
          <el-table-column :label="$t('page.business.study.studyRoom.kssyyl')" align="center" prop="kssyyl" />
          <el-table-column :label="$t('page.business.study.studyRoom.qyr')" align="center" prop="qyrMc" />
          <el-table-column :label="$t('page.business.study.studyRoom.kssj')" align="center" prop="createTime" />
          <el-table-column :label="$t('page.business.study.studyRoom.jssyyl')" align="center" prop="jssyyl" />
          <el-table-column :label="$t('page.business.study.studyRoom.jsr')" align="center" prop="jsrMc" />
          <el-table-column :label="$t('page.business.study.studyRoom.jssj')" align="center" prop="jssj" />
          <el-table-column :label="$t('page.business.study.studyRoom.zt')" prop="status" align="center" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.zt === 1">{{ $t('page.business.study.studyRoom.syz') }}</span>
              <span v-if="scope.row.zt === 3">{{ $t('page.business.study.studyRoom.yjs') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('form.operate')" align="left" fixed="right" width="200">
            <template slot-scope="scope">
              <el-button type="text" @click="detail(scope.row)" v-hasPermi="['business:studyRoom:ljjl']">{{
                $t('page.business.study.studyRoom.xq') }}</el-button>
              <!-- 笼具记录 -->
              <el-button type="text" @click="ljHistory(scope.row)" v-hasPermi="['business:studyRoom:ljjl']">{{
                $t('page.business.study.studyRoom.ljjl') }}</el-button>
              <!-- 更换笼具 -->
              <el-button type="text" v-if="scope.row.zt === 1" @click="edit(scope.row)"
                v-hasPermi="['business:studyRoom:update']">{{
                  $t('page.business.study.studyRoom.ghlj') }}</el-button>
              <!-- 结束 -->
              <el-button type="text" v-if="scope.row.zt === 1" @click="end(scope.row)"
                v-hasPermi="['business:studyRoom:js']">{{
                  $t('page.business.study.studyRoom.js') }}</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize"
          @pagination="getList" />
      </div>
    </div>
    <!-- 新增 -->
    <Xz key="Xz" ref="Xz" @callback="search" />
    <!-- 更换笼具 -->
    <Bj key="Bj" ref="Bj" @callback="search" />
    <!-- 结束使用 -->
    <Js key="Js" ref="Js" @callback="search" />
    <!-- 笼具更换记录 -->
    <Jl key="Jl" ref="Jl" @callback="search" />
    <!-- 详情 -->
    <Detail key="Detail" ref="Detail" @callback="search"  @close="xqClose" v-show="showDetail"/>
  </div>

</template>

<script>
import { studyRoom_list } from '@/api/business/study/studyRoom'
import Xz from "./syj/Xz";
import Bj from "./syj/Bj";
import Js from "./syj/Js";
import Jl from "./syj/Jl";
import Detail from "./syj/Detail";
import { mapGetters } from 'vuex'
import moment from "moment";
export default {
  name: 'SyjList',
  props: {
    study: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ]),
  },
  watch: {
    study: {
      handler(newVal) {
        this.searchForm.studySn = newVal.sn
        this.searchForm.studyMc = newVal.name
        this.searchForm.studyId = newVal.id
        this.searchForm.studySubjectId = newVal.studySubjectId
        this.leader = newVal.leader
        this.search()
      },
      immediate: true,
      deep: true
    }
  },
  components: { Xz, Bj, Js, Jl, Detail },
  data() {
    return {
      showDetail: false,
      daterange: [],
      daterange: [],
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        studyId: '',
        syjh: '',
        syqy: '',
        qyr: '',
        jsr: '',
        startDate: '',
        endDate: ''
      },
      loading: false,
      total: 0,
      list: [],
      currentRow: null
    }
  },
  created() { },
  methods: {

    search() {
      this.searchForm.pageNum = 1
      this.getList()
    },
    reset() {
      this.resetForm("searchForm")
      this.search()
    },
    getList() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.searchForm.startDate = this.daterange[0] + " 00:00:00"
        this.searchForm.endDate = this.daterange[1] + " 23:59:59"
      } else {
        this.searchForm.startDate = ''
        this.searchForm.endDate = ''
      }
      this.loading = true
      studyRoom_list(this.searchForm).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    add() {
      this.$refs.Xz.show(this.study.id);
    },
    edit(row) {
      this.$refs.Bj.show(row)
    },
    end(row) {
      this.$refs.Js.show(row)
    },
    ljHistory(row) {
      this.$refs.Jl.show(row)
      // this.showDetail = true
      // this.$emit('showDetail', this.showDetail)
      // this.$refs.Xq.show(row)
    },
    detail(row) {
      this.showDetail = true
      this.$emit('showDetail', this.showDetail)
      this.$refs.Detail.show(row)
      // this.showDetail = true
      // this.$emit('showDetail', this.showDetail)
      // this.$refs.Xq.show(row)
    },
    handleExport() {

    },
    xqClose() {
      this.showDetail = false
      this.$emit('showDetail', this.showDetail)
      this.search()
    },
  }
}
</script>
<style lang="scss" scoped>
.tbbd-list {
  .tbbd-search {
    background: #fff;
    padding: 20px;
    margin-bottom: 10px;

    .right-btn {
      text-align: right
    }
  }

  .tbbd-content {
    padding: 20px;
    background: #fff;

    .add-box {
      margin-bottom: 10px;
    }
  }
}
</style>
