<!-- 采集记录页面 -->
<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true" @submit.native.prevent ref="searchForm" :model="searchForm"
        class="demo-form-inline sui-search-form">
        <el-form-item label='设备类型 ' prop="eqpTypeCode">
          <el-select v-model="searchForm.eqpTypeCode" @change='selectFaclity' clearable @clear='cleareqpName' filterable
            collapse-tags size="small" style="width:150px;" placeholder="">
            <el-option v-for="item in facilityType" :key="item.baseCode" :label="item.baseName" :value="item.baseCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='设备名称' prop="eqpNo">
          <el-select v-model="searchForm.eqpNo" clearable filterable collapse-tags size="small" style="width:200px;"
            placeholder="">
            <el-option v-for="item in eqpType" :key="item.eqpNo" :label="item.eqpName + ` (${item.memo})`"
              :value="item.eqpNo">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采集日期">
          <el-date-picker v-model="searchForm.times[0]" value-format="yyyy-MM-dd HH:mm:ss" format="" type="datetime"
            placeholder="开始日期" size="mini" style="width: 180px" :default-time="'00:00:00'">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="searchForm.times[1]" value-format="yyyy-MM-dd HH:mm:ss" format="" type="datetime"
            placeholder="结束日期" size="mini" style="width: 180px" :default-time="'23:59:59'">
          </el-date-picker>
          <!-- <el-date-picker
           v-model="searchForm.times"
           type="datetimerange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:350px"
           format=""
           value-format="yyyy-MM-dd HH:mm:ss"
           :default-time="['00:00:00', '23:59:59']">
          </el-date-picker> -->
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="resetData">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png' />
        样品信息
      </div>
      <div>
      </div>
    </div>
    <div>
      <!-- class="common-table-div" -->
      <el-table v-loading="tableLoading2" ref="dataTable2" border :height="theight" highlight-current-row
        :data="tableData2" :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
        @row-click="searchFollow" :cell-class-name="tableRowClassName" :summary-method="getSummaries2" show-summary>
        <el-table-column type="index" label="NO" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="stateFlag" label="状态"
          min-width="80"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="CREATE_TIME" label="采集日期"
          min-width="140"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="EQP_NAME" label="采集设备"
          min-width="100"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="POINT_NAME" label="采集位置"
          min-width="100"></el-table-column>
        <el-table-column v-for="(item, index) in columList" :prop="item" :key="index" :label="item" width="140">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="memo" label="备注"
          min-width="100"></el-table-column>
      </el-table>
      <div class="common-foot-style">
        <el-pagination @size-change="handleSizeChangeMain" @current-change="handleCurrentChangeMain"
          :current-page="pageIndex" :page-sizes="[10, 20, 30, 40, 100, 200]" :page-size="pageSize" size="mini"
          layout="total, sizes, prev, pager, next, jumper" :total="total_main" background></el-pagination>
      </div>
    </div>
    <!-- <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png' />
        项目信息
      </div>
      <div>
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="tableLoading3"  border :height="theight" highlight-current-row  :data="tableData3" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries2" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="collItemName" label="采集项目名称"  min-width="100"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="anlyItemName" label="分析项目名称"  min-width="100"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="testValue" label="采集值"  min-width="100"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="unitName" label="值单位" min-width="100"></el-table-column>
      </el-table>
    </div> -->
    <!-- <div class="common-foot-style">
      <el-pagination
        @size-change="handleSizeChangeMain"
        @current-change="handleCurrentChangeMain"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 30, 40, 100 , 200]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total_main"
        size="mini"
        background
      ></el-pagination>
    </div> -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchForm: {
        eqpTypeCode: '',
        eqpNo: '',
        times: ''
      },
      facilityType: [],
      eqpType: [],
      theight: 0,
      theight2: 0,
      theight3: 0,
      tableLoading1: false,
      tableLoading2: false,
      tableLoading3: false,
      tableData1: [],
      tableData2: [],
      tableData3: [],
      pageIndex: 1,
      pageSize: 100,
      total_main: 0,
      icoreFilterFlag: true,
      rules: {
        eqpTypeCode: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
        eqpNo: [{ required: true, message: '请选择设备名称', trigger: 'change' }]
      },
      columList: []
    }
  },
  created() {
    // window.innerHeight / 2 - 110 < 249 ? 249 :
    this.theight = window.innerHeight - 170;
    this.searchForm.times = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
  },
  mounted() {
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4808 }, { individualType: 'json' }).then(res => {
      this.facilityType = res.data
    })
    this.searchData()
  },
  methods: {
    getYNM(date) {
      let year = date.getFullYear().toString();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      return `${year}-${month}-${day}`;
    },
    getSummaries2(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } else if (column.property === "quantity") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].quantity ? data[i].quantity : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "factweight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].factweight ? data[i].factweight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    cleareqpName(val) {
      this.searchForm.eqpNo = ''
    },
    selectFaclity(val) {
      this.eqpType = []
      this.searchForm.eqpNo = ''
      if (!val) {
        return
      }
      this.axios.post('pass/baseManagement/v1/limslrceqpinfos/queryeqpName', { eqpTypeCode: val }, { individualType: 'json' }).then(res => {
        this.eqpType = res.data;
      })
    },
    resetData() {
      this.searchForm.eqpTypeCode = ''
      this.searchForm.eqpNo = ''
      this.searchForm.times = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
      this.searchData()
    },
    searchData() {
      this.pageIndex = 1
      this.pageSize = 100
      this.getDataList()
    },
    getDataList() {
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.times) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.searchForm.times[0]
        endTime = this.searchForm.times[1]
      }
      let obj = {
        object: {
          eqpTypeCode: this.searchForm.eqpTypeCode,
          eqpNo: this.searchForm.eqpNo,
        },
        startTime: startTime,
        endTime: endTime,
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      }
      if (obj.object.eqpNo && obj.startTime && obj.endTime) {
        this.tableLoading2 = true;
        this.axios.post('pass/testManagement/v1/limsdatacollects/collectionRecord', obj, { individualType: 'json' }).then(res => {
          console.log(res);
          if (res.code == 0 || res.code == 200) {
            this.columList = res.data.columnList
            this.tableData2 = res.data.data.list
            this.tableData2.forEach(item => {
              item.stateFlag = item.STATE_FLAG == 1 ? '已读' : item.STATE_FLAG == 0 ? '未读' : ''
            })
          }
          this.total_main = res.data.data.total
          this.tableLoading2 = false;
        }).catch(err => {
          this.tableLoading2 = false;
          this.$message.error(err.message)
        })
      } else {
        //console.log("请选择时间段")
        this.$message.warning('请选择设备名称和时间段')
      }
    },
    //点击主表信息，查询子表
    searchFollow(row) {
      this.tableLoading3 = true;
      this.axios.post('pass/testManagement/v1/limsdataparseds/querylimsDataPase', { psId: row.psId }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading3 = false;
      }).catch(err => {
        this.tableLoading3 = false;
        this.$message.error(err.message)
      })
    },
    handleSizeChangeMain(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.getDataList();
    },
    handleCurrentChangeMain(pageIndex) {
      this.pageIndex = pageIndex;
      this.getDataList();
    },
    tableHeaderCellStyle() {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        if (row.stateFlag == '1') {
          return 'error-green';
        }
      }
    },
  }
}
</script>
<style scoped></style>
