<template>
  <!-- 保温箱追溯 -->
  <div style="overflow-y: auto;">
    <actionBar :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm" @openModel="openModel"
      @searchProtocol="searchProtocol">
    </actionBar>
    <div class="card_content">
      <!-- 表单 -->
      <tables :tableList="tableList" :tableData="tableData"></tables>
      <!-- 分页 -->
      <div v-if="Total">
        <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
          @changeCurrent="changeCurrent">
        </pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getcoolerboxall
} from '@/api/incubator'
import actionBar from '@/components/actionBar'
import tables from '@/components/tables'
import pagination from '@/components/pagination'
import forms from '@/components/forms'
import {
  employee
} from "./retrospect.js";
export default {
  name: 'IncubatorManagement',
  components: {
    actionBar,
    tables,
    pagination,
    forms,
  },
  data() {
    return {
      operateList: [{
        type: 'export',
        colour: 'success',
        title: '导出Excel',
      }],
      formList: [{
        type: 'input',
        label: '名称',
        field: 'name',
        placeholder: '名称',
      }, {
        type: 'input',
        label: 'SN',
        field: 'sn',
        placeholder: 'SN',
      }],
      searchRuleForm: {
        name: '',
        sn: '',
        status: '',
      },
      searchValue: {},
      Pagination: {
        PageIndex: 1,
        PageSize: 10,
      },
      Total: 0,
      tableData: [],
      tableList: [],
      // 是否预冷
      iceColdFlag: false,
      userList: {},
    }
  },
  mounted() {
    const arr = localStorage.getItem('userList')
    this.userList = JSON.parse(arr)
    if (this.userList.dept) {
      this.iceColdFlag = this.userList.dept.isCoolerReleaseCold
    }
    if (!this.iceColdFlag) {
      var tableList = employee()
      this.tableList = removePointById(tableList, ['precoolingTime', 'cold_temperatures', 'cold_spots','precoolingOperator'])
    } else {
      this.tableList = employee()
    }

    function removePointById(arr1, arr2) {
      for (let i = 0; i < arr2.length; i++) {
        for (let j = 0; j < arr1.length; j++) {
          if (arr2[i] == arr1[j].field) {
            let indexs = arr1.indexOf(arr1[j]);
            arr1.splice(indexs, 1);
          }
        }
      }
      return arr1
    }
    this.getList()
  },
  methods: {
    // 搜索
    searchProtocol(value) {
      this.searchValue = value
      this.getList()
    },
    // 获取保温箱列表
    getList() {
      var params = {
        page: this.Pagination.PageIndex,
        pageSize: this.Pagination.PageSize,
        showTemp: true,
        ...this.searchValue
      }
      getcoolerboxall(params).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list
          this.Total = res.data.count
          /* this.timer = setTimeout(() => {
             this.getList();
             clearInterval(this.timer); // 清除定时器
             this.timer = null;
           }, 60000) */
        }
      })
    },
    openModel(type) {
      console.log(type,998);
      
      if (type == 'export') { }
    },
    changeSize(val) {
      this.Pagination.PageSize = val
      this.getList()
    },
    changeCurrent(val) {
      this.Pagination.PageIndex = val
      this.getList()
    },
  }
}
</script>

<style lang="scss" scoped></style>
