<template>
<!-- 增加任务 -->
  <div class="examination">
    <el-dialog :close-on-click-modal='false' @close="closebatch" width='100%' :visible.sync="batchShow" top="0">
      <div slot="title" class="titleBox">
        <i class='el-icon-document' style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">标样记录</span>
      </div>
      <div class="common-title-name" style="padding-bottom: 3px;">
      </div>
      <el-table ref="table13" border :height="theight13" highlight-current-row :data="tableData13"
                :span-method="arraySpanMethod13" @selection-change="searchFollow13"
                :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" width="45" fixed align="center"></el-table-column>
        <el-table-column type="selection" width="45" fixed align="center"></el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="118" fixed align='center' prop="STD_NO" label="标样编号"></el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="118" fixed align='center' prop="SAMPLE_NO" label="中心编号"></el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="125" fixed align="center" prop="MAT_NAME" label="物料名称"></el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="110" fixed align='center' prop="TEST_ITEM_NAME" label="测试项目" ></el-table-column>
        <el-table-column show-overflow-tooltip min-width="180" align="center" prop="ANLY_ITEM_NAME" label="分析项目"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="ANLY_VALUE" label="报出值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="REVISE_VALUE" label="录入值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="DAS_VALUE" label="采集值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="CPT_VALUE" label="计算值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="REVISE_VALUE" label="修约值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="90" align="center" prop="UNIT_NAME" label="单位"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="FORMULA_NAME" label="计算公式" ></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="REVISE_RULE_NAME" label="修约规则"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button icon="el-icon-download" type="goon" size="mini" :loading="tableExportLoading" @click="doExport">导出</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="closebatch">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getCookie } from "@/utils/util.js";
import { cookieUserId, cookieUserName } from "@/config/config.js";
import { exportToExcel } from '../../../utils/utils.js'
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  props: ["showFlag", "Params"],
  data() {
    return {
      batchShow: false,
      theight13:'',
      tableData13:[],
      tableExportLoading: false,
    }
  },
  created(){
    this.theight13 = window.innerHeight -240;
  },
  mounted() {

  },
  methods: {
    // 关闭原始记录页面
    closebatch (){
      this.multipleSelection13 = []
      this.batchShow = false;
      // this.dataMain();
    },
    searchFollow13 (val){
      let dataList = []
      val.forEach(item => {
        dataList.push(item)
      })
      console.log(dataList)
      this.multipleSelection13 = [...dataList];
      // this.multipleSelection13 = val
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        }
      });
      return sums;
    },
    // 导出
    doExport () {
      let tHeader = [];
      let filterVal = [];
      let dataList = [];
      if (this.multipleSelection13.length > 0) {
        dataList = [...this.multipleSelection13]
      } else {
        dataList = [...this.tableData13]
      }
      console.log(this.multipleSelection13)
      tHeader = ['标样编号', '中心编号', '物料名称', '测试项目', '分析项目', '报出值', '录入值', '采集值', '计算值', '修约值', '单位', '计算公式', '修约规则']
      filterVal = ['STD_NO', 'SAMPLE_NO', 'MAT_NAME', 'TEST_ITEM_NAME', 'ANLY_ITEM_NAME', 'ANLY_VALUE', 'REVISE_VALUE', 'DAS_VALUE', 'CPT_VALUE', 'REVISE_VALUE', 'UNIT_NAME', 'FORMULA_NAME', 'REVISE_RULE_NAME']
      exportToExcel(dataList, tHeader, filterVal, '标样记录表', [], [], [])
    },
    arraySpanMethod13 ({ row, column, rowIndex, columnIndex }) {
      let tableData = this.$refs.table13.tableData
      let rowsPan = 1;
      let thisColomnData = row[column['property']];
      let st = row['SAMPLE_NO'];
      if (columnIndex > 1 && columnIndex < 5 && st) {
        if (rowIndex > 0 && st === tableData[rowIndex - 1]['SAMPLE_NO']) {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
        while (tableData[rowIndex + rowsPan] && st === tableData[rowIndex + rowsPan]['SAMPLE_NO']) {
          rowsPan += 1
        }
        return {
          rowspan: rowsPan,
          colspan: 1
        };
      }
    },
  },
  watch: {
    showFlag(arg) {
      this.batchShow = true;
      this.tableData13 = this.Params
    }
  }
};
</script>
<style lang="less">
.customWidth_test {
  width: 1000px !important;
}
</style>
