<template>
  <!-- 温湿度监控 -->
  <div class="card_humitureSupervision">
    <div class="humiture_left">
      <span class="humit_title">温湿度记录</span>
      <div class="item_humiture" v-for="(item,index) in humitureList" :key="index" @click="gethumiture(item)">
        <div class="card_supervision">
          <span class="supervision_title" :style="{color:(item.flag ? '#409EFF' : '')}">【{{item.title}}】</span>
          <span class="supervision_title" :style="{color:(item.flag ? '#409EFF' : '')}">{{item.startTime}}</span>
          <span class="supervision_title" :style="{color:(item.flag ? '#409EFF' : '')}">{{item.endTime}}</span>
        </div>
      </div>
    </div>
    <div class="humiture_right">
      <div style="padding: 10px;">
       <!-- <div class="card_checkbox" v-if="probeList.length > 0">
          <el-checkbox-group v-model="checkList" @change="handleCheckedCitiesChange">
            <el-checkbox v-for="items in probeList" :key="items.T_id"
              :label="items.T_id">{{ items.T_name }}</el-checkbox>
          </el-checkbox-group>
        </div> -->
        <!-- 表单 -->
        <tables :suspension="true" :tableList="tableList" :tableData="tableData"></tables>
        <!-- 分页 -->
        <div v-if="Total">
          <pagination :total="Total" :currentPage="Pagination.page" @changeSize="changeSize"
            @changeCurrent="changeCurrent">
          </pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    waybillTaskData,
  } from '@/api/waybillLogistics'
  import tables from '@/components/tables'
  import pagination from '@/components/pagination'
  import {
    employee,
  } from "./humiture.js";
  export default {
    name: 'humitureSupervision',
    components: {
      tables,
      pagination,
    },
    props: {
      // 温湿度列表
      humitureList: {
        type: Array,
        default: () => [],
      },
      // 探头列表
      probeList: {
        type: Array,
        default: () => [],
      },
      waybillNo: {
        type: String,
        default: () => '',
      }
    },
    data() {
      return {
        tableData: [],
        tableList: employee(),
        Pagination: {
          page: 1,
          pageSize: 10,
        },
        Total: 0,
        checkList: [],
        taskId: null,
        tIds: [],
      }
    },
    methods: {
      selectType() {
        if (this.humitureList.length > 0) {
          this.humitureList[0].flag = true
          this.taskId = this.humitureList[0].id
        }
      },
      // 反选探头数据
      inverseData() {
        if (this.probeList.length > 0) {
          this.tIds = []
          const tId = []
          this.probeList.forEach(item => {
            tId.push(item.T_id)
          })
          this.tIds = tId
          this.checkList = tId
          this.getList()
        }
      },
      handleCheckedCitiesChange() {
        this.tIds = []
        this.tIds = this.checkList

        function methods1(arr) {
          return Array.from(new Set(arr));
        }
        this.tIds = methods1(this.tIds)
        this.getList()
      },
      // 选择类型
      gethumiture(value) {
        this.checkList = []
        this.humitureList.forEach(item => {
          if (item.id == value.id) {
            item.flag = true
            this.taskId = item.id
          } else {
            item.flag = false
          }
        })
        this.$forceUpdate()
        this.$emit('selectiveRecord', value)
      },
      // 获取温湿度记录列表
      getList() {
        let params = {
          t_ids: this.tIds,
          taskId: this.taskId,
          waybillNo: this.waybillNo,
          ...this.Pagination
        }
        waybillTaskData(params).then(res => {
          if (res.code == 200) {
            this.tableData = res.data.list
            this.Total = res.data.count
          }
        })
      },
      changeSize(val) {
        this.Pagination.pageSize = val
        this.getList()
      },
      changeCurrent(val) {
        this.Pagination.page = val
        this.getList()
      },
    }
  }
</script>

<style lang="scss">
  .card_humitureSupervision {
    display: flex;
    border: 1px solid #E4E7ED;
  }

  .humiture_left {
    width: 200px;
    flex: none;
    height: 100%;
    margin-bottom: 15px;
  }

  .humiture_right {
    flex: 1;
    border-left: 1px solid #E4E7ED;
  }

  .card_checkbox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid #E4E7ED;
  }

  .humit_title {
    display: flex;
    padding: 10px 14px 10px 14px;
    font-size: 16px;
    font-weight: 600;
    line-height: 33px;
    border-bottom: 1px solid #E4E7ED;
  }

  .item_humiture {
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0px 10px;
    margin-top: 10px;
  }

  .card_supervision {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    margin-left: 10px;
  }

  .supervision_title {
    font-size: 14px;
  }
</style>
