<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label="接收日期">
          <el-date-picker v-model="search.times[0]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="开始日期" size="mini" style="width: 140px">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="search.times[1]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="结束日期" size="mini" style="width: 140px">
          </el-date-picker>
          <!-- <el-date-picker
                        v-model="search.times"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        size="small"
                        style="width: 300px"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                    >
                    </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="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row>
      <el-col :span="14">
        <el-tabs v-model="activeName" type="border-card">
          <el-tab-pane label="接收电文" name="first">
            <div class="common-title-div" style="height: auto; margin-top: -10px;">
              <div class="common-title-name" style="width:281px">
                <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
                接收电文信息
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom:0;margin-top:0">
              <el-table id="excelTable" v-loading="dataLoading" ref="dataTable" border @row-click='saveDataMain'
                :height="height_top" highlight-current-row :data="table1" :icore-filter-flag="icoreFilterFlag"
                :cell-class-name="tableRowClassName" :header-cell-style="tableHeaderCellStyle" width='50%'
                @selection-change="selectRow1" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" align="center" width="45"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="30px" prop="validFlag1" label="状态"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="50px" prop="carNo" label="委托编号"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="50px" prop="registerName"
                  label="注册系统名称" align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="matName" label="物料名称"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="createDate" label="接收时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="pageSizeChange" @current-change="pageCurrentChange"
                :current-page="page.pageNum" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="page.totalPage" background>
              </el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="发送电文" name="first1">
            <div class="common-title-div" style="height: auto; margin-top: -10px;">
              <div class="common-title-name" style="width:281px">
                <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
                发送电文信息
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom:0;margin-top:0">
              <el-table id="excelTable2" v-loading="dataLoading" ref="dataTable2" border @row-click='saveDataMain1'
                :height="height_top" highlight-current-row :data="table2" :icore-filter-flag="icoreFilterFlag"
                :cell-class-name="tableRowClassName" :header-cell-style="tableHeaderCellStyle" width='50%'
                @selection-change="selectRow2" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" align="center" width="45"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="30px" prop="validFlag1" label="状态" align="center"></el-table-column> -->
                <el-table-column :show-overflow-tooltip="true" sortable min-width="50px" prop="sampleNo" label="样号"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="matName" label="物料名称"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="createTime" label="创建时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="pageSizeChange1" @current-change="pageCurrentChange1"
                :current-page="page1.pageNum" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="page1.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="page1.totalPage" background>
              </el-pagination>
            </div>
          </el-tab-pane>

        </el-tabs>
      </el-col>
      <el-col :span="10">
        <div class="common-title-div" style="height:65px; margin-top: 13px;">
          <div class="common-title-name">
            <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
            电文信息
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <div><span>{{ this.MessageContent }}</span></div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {
  getCookie,
  formatDate
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data() {
    return {
      search: {
        times: []
      },
      table1: [],
      table2: [],
      activeName: 'first',
      dataLoading: false,
      selectRow1: [],
      selectRow2: [],
      height_top: 0,
      icoreFilterFlag: true,
      clickRow1: {},
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page1: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },

      dataLoading2: false,
      MessageContent: '',
    }
  },
  created() {
    this.height_top = window.innerHeight - 190;
    this.search.times = [this.getYNM(new Date()), this.getYNM(new Date())]
  },
  mounted() {
    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}`;
    },
    searchData() {
      this.mainData()
      this.mainData2()
    },
    mainData() {
      let startTime = ''
      let endTime = ''
      if (!this.search.times) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.search.times[0] + ' 00:00:00'
        endTime = this.search.times[1] + ' 23:59:59'
      }
      let obj = {
        pageIndex: this.page.pageNum,
        pageSize: this.page.pageSize,
        startTime: startTime,
        endTime: endTime
      }
      this.dataLoading = true;
      this.axios.post('pass/baseManagement/v1/iotmsghandles/queryList', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.table1 = res.data.list
          this.page.totalPage = res.data.total
          this.table1.forEach(str => {
            str.validFlag1 = str.validFlag == '1' ? '已接收' : str.validFlag === '2' ? '已生成' : ''
          })
          this.dataLoading = false;
        } else {
          this.dataLoading = false;
          this.$message.error(res.message);
        }
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(res.message);
      });
    },
    mainData2() {
      let startTime = ''
      let endTime = ''
      if (!this.search.times) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.search.times[0] + ' 00:00:00'
        endTime = this.search.times[1] + ' 23:59:59'
      }
      let obj = {
        object: {
          validFlag: '1',
          matName: '',
        },
        pageIndex: this.page1.pageNum,
        pageSize: this.page1.pageSize,
        list: [6],
        startTime: startTime,
        endTime: endTime
      }
      this.dataLoading = true;
      this.axios.post('pass/testManagement/v1/limssamplereleases/queryLimsSampleReleasePage3', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.table2 = res.data.list
          this.page1.totalPage = res.data.total
          // this.table2.forEach(str=>{
          //     str.validFlag1 = str.stateFlag == '5' ? '未发送' : str.stateFlag === '6' ? '已发送' : ''
          // })
          this.dataLoading = false;
        } else {
          this.dataLoading = false;
          this.$message.error(res.message);
        }
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(res.message);
      });
    },
    saveDataMain(row) {
      this.clickRow1 = row;
      this.mainData3();
    },
    saveDataMain1(row) {
      this.MessageContent = row.msgSource;
    },
    mainData3() {
      if (this.clickRow1 == {}) {
        this.$message.warning('未点击电文主信息！')
      }
      this.dataLoading2 = true;
      this.axios.post('pass/baseManagement/v1/iotmsgsources/queryByMsgId', { msgId: this.clickRow1.msgId }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.MessageContent = res.data[0].msgSource
          this.dataLoading2 = false;
        } else {
          this.dataLoading2 = false;
          this.$message.error(res.message);
        }
      }).catch(e => {
        this.dataLoading2 = false;
        this.$message.error(res.message);
      });
    },
    reset() {
      this.search.times = [this.getYNM(new Date()), this.getYNM(new Date())]
    },
    pageSizeChange(size) {
      this.page.pageSize = size;
      this.mainData();
      this.mainData1();
    },
    pageCurrentChange(index) {
      this.page.pageNum = index;
      this.mainData();
      this.mainData1();
    },
    pageSizeChange1(size) {
      this.page1.pageSize = size;
      this.mainData();
      this.mainData1();
    },
    pageCurrentChange1(index) {
      this.page1.pageNum = index;
      this.mainData();
      this.mainData1();
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        }
        if (column.property === "netWgt") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].netWgt ? data[i].netWgt : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    tableRowClassName({
      row, column, rowIndex, columnIndex
    }) {
      if (columnIndex === 2) {
        if (row.validFlag === '2') {
          return 'error-green';
        }
        return '';
      }
    },
    tableHeaderCellStyle() {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
