<!-- 采集记录页面 -->
<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline='true'>
        <el-form-item label="检验车间">
          <el-select v-model="searchForm.deptNo" filterable clearable style="width:150px" collapse-tags
            @clear='clearSelect' @change="selectClass" size="small">
            <el-option v-for="item in sectionNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验班组">
          <el-select v-model="searchForm.sectionNo" filterable clearable style="width:150px" collapse-tags size="small">
            <el-option v-for="item in sectionClassType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='样品类型'>
          <el-select v-model="searchForm.sampleTypeCode" clearable filterable collapse-tags size="small"
            style="width:150px;" placeholder="请选择">
            <el-option v-for="item in sampleTypeNameType" :key="item.baseCode" :label="item.baseName"
              :value="item.baseCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input v-model="searchForm.matName" @keyup.enter.native="searchData()" size="small" placeholder="请输入物料名称"
            style="width:150px"></el-input>
        </el-form-item>
        <el-form-item label="样号">
          <el-input v-model="searchForm.sampleNo" @keyup.enter.native="searchData()" size="small" placeholder="请输入样号"
            style="width:150px"></el-input>
        </el-form-item>
        <el-form-item label="测试时间">
          <el-date-picker v-model="searchForm.entrTime[0]" value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="开始日期" size="mini" style="width: 180px"
            :default-time="'00:00:00'">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="searchForm.entrTime[1]" value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="结束日期" size="mini" style="width: 180px"
            :default-time="'23:59:59'">
          </el-date-picker>
          <!-- <el-date-picker
           v-model="searchForm.entrTime"
           type="daterange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:270px"
           format="yyyy-MM-dd HH:mm:ss"
           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>
    <el-row>
      <el-col :span='12'>
        <div class="common-title-div">
          <div class="common-title-name">
            <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png' />
            任务信息
          </div>
          <div>
            <el-button icon="el-icon-back" type="danger" :loading='backDataLoading'
              v-privilege="activeMenu + 'backData'" size="mini" @click="backData">回退</el-button>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table v-loading="tableLoading" ref="dataTable" border :height="mainHeight" highlight-current-row
            @selection-change="handleSelectionChange" :data="tableData" :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 type="selection" width="50" align="center"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="60" align="center" prop="stateFlagName"
              label="状态"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="150" align="center" prop="matName"
              label="样品名称"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="130" align='center' prop="sampleNo"
              label="样品编号"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="150" align='center' prop="testItemName"
              label="测试项目"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="90" align='center' prop="createMan"
              label="测试人"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="100" align='center' prop="eqpName"
              label="测试设备"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="100" align="center" prop="createTime"
              label="测试时间"></el-table-column>
            <el-table-column show-overflow-tooltip sortable min-width="80" align="center" prop="stdName"
              label="环境配置"></el-table-column>
            <!-- <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="stateFlagName" label="状态" min-width="80"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="id" label="编号" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="planCompanyName" label="委托单位"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="planDeptName" label="委托车间"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="entrTime1" label="委托日期" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="entrTypeName" label="委托类型"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="matClassName" label="物料分类"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="matName" label="物料名称"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="testTypeName" label="检验类型" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="smpDeliName" label="取样频次"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpDeptName" label="取样车间"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpSectionName" label="取样班组"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="pointName" label="取样地点"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyName" label="分析项目"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="companyName" label="检验单位" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="deptName" label="检验车间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="sectionName" label="检验班组" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="spec" label="规格" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="memo" label="备注" align="center"></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" size="mini"
            layout="total, sizes, prev, pager, next, jumper" :total="total_main" background></el-pagination>
        </div>
      </el-col>
      <el-col :span='12'>
        <el-row>
          <el-col>
            <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 class="common-table-div" style="margin-bottom:0;margin-top:0">
              <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="searchFollow2" :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="anlyItemName" label="分析项目"
                  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="anlyValue" label="报出值"
                  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="reviseValue" label="修约值"
                  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="dasValue" label="采集值"
                  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="cptValue" label="计算值"
                  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="isAlarm" label="超差预警显示"
                  min-width="100"></el-table-column>

                <!-- <template v-for="col in cols">
	              <el-table-column
                  :prop="col.prop" :show-overflow-tooltip="true" min-width="100" align='center' :key="col.prop" :label="col.label">
                </el-table-column>
	            </template> -->
              </el-table>
            </div>
            <!-- <div class="common-foot-style">
              <el-pagination
                @size-change="handleSizeChangeMain2"
                @current-change="handleCurrentChangeMain2"
                :current-page="pageIndex2"
                :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> -->
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col>
            <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 class="common-table-div" style="margin-bottom:0;margin-top:0">
              <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="collIdD" label="采集项目编号"  min-width="100"></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="anlyValue" label="报出值"  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="dasValue" label="采集值"  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="cptValue" label="计算值"  min-width="100"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable align="center" prop="reviseValue" label="修约值"  min-width="100"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination
                @size-change="handleSizeChangeMain3"
                @current-change="handleCurrentChangeMain3"
                :current-page="pageIndex3"
                :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>
          </el-col>
        </el-row> -->
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { getCookie, formatDate } from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
export default {
  data() {
    return {
      searchForm: {
        deptNo: '',
        sectionNo: '',
        sampleTypeCode: '',
        matName: '',
        sampleNo: '',
        entrTime: '',
        type:''
      },
      sectionClassType: [],
      facilityType: [],
      companyNameType: [],
      sectionNameType: [],
      eqpType: [],
      theight: 0,
      mainHeight: 0,
      theight2: 0,
      theight3: 0,
      tableLoading1: false,
      tableLoading: false,
      tableLoading2: false,
      tableLoading3: false,
      backDataLoading: false,
      multipleSelection: [],
      sampleTypeNameType: [],
      cols: [],
      tableData1: [],
      tableData: [],
      tableData2: [],
      tableData3: [],
      pageIndex: 1,
      pageSize: 100,
      total_main: 0,
      icoreFilterFlag: true,
      activeMenu: ''
    }
  },
  created() {
    this.theight = window.innerHeight - 220 < 249 ? 249 : window.innerHeight - 220;
    this.mainHeight = this.theight <= 249 ? this.theight + 100 : window.innerHeight - 180
    this.searchForm.entrTime = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted() {
    console.log('testManagement:',this.$route.query.type)
    this.searchForm.type = this.$route.query.type  || '';
    // this.axios.post('pass/baseManagement/v1/limsbaseposts/queryLimsBasePostList',{sectionNo: this.sectionNo}, {individualType: 'json'}).then(res =>{
    //   this.jobType = res.data
    // })
    this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll", {}, { individualType: "json" }).then((response) => {
      this.companyNameType = response.data;
      this.selectDepartment('F31300000')
    });
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4801 }, { individualType: 'json' }).then(res => {
      this.sampleTypeNameType = res.data
    })
    this.getCompany();
    // this.searchData()
  },
  methods: {
    //根据选中的部门名称，查询班组名称
    selectClass(val) {
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
          this.searchForm.sectionNo = ''
        }
      });
    },
    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;
    },
    selectDepartment(val) {
      this.sectionNameType = []
      // this.pointNameType = []
      this.companyNameType.find(item => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList
        }
      })
    },
    clearSelect() {
      this.searchForm.sectionNo = ''
    },
    //回退
    backData() {
      if (this.multipleSelection.length < 1) {
        this.$message.warning('请先勾选要回退的数据')
      }
      let flag = this.multipleSelection[0].stateFlag
      for (let item of this.multipleSelection) {
        if (item.stateFlag != flag) {
          this.$message.warning('请选择同一状态的数据')
          return
        }
      }
      this.backDataLoading = true
      this.axios.post('pass/testManagement/v1/limsdatacollects/updatestate', this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
        this.backDataLoading = false
      }).catch(err => {
        this.backDataLoading = false
        this.$message.error(err.message)
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    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.deptNo = ''
      this.searchForm.sampleNo = ''
      this.searchForm.sectionNo = ''
      this.searchForm.sampleTypeCode = ''
      this.searchForm.jobs = ''
      this.searchForm.matName = ''
      this.searchForm.entrTime = [this.getYNM(new Date()) + ' 00:00:00', this.getYNM(new Date()) + ' 23:59:59']
      this.searchData()
    },
    searchData() {
      this.pageIndex = 1
      this.pageSize = 100
      this.DataMain()
    },
    DataMain() {
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.entrTime) {
        startTime = ''
        endTime = ''
      } else {
        startTime = this.searchForm.entrTime[0]
        endTime = this.searchForm.entrTime[1]
      }
      let obj = {
        object: {
          // 'deptNo':this.searchForm.deptNo,
          // 'sectionNo':this.searchForm.sectionNo,
          testPostCode: this.searchForm.jobs,
          sampleTypeCode: this.searchForm.sampleTypeCode,
          matName: this.searchForm.matName,
          validFlag: '1'
        },
        // 'list':[0], // 已接任务、未处理状态
        list2: [484003], // 测试分析模块
        // mode:this.searchForm.sampleNo,
        startTime: startTime,
        endTime: endTime,
        pageIndex: this.pageIndex,
        pageSize: this.pageSize,
        deptName:this.searchForm.type
      }
      this.tableLoading = true;
      this.axios.post('pass/testManagement/v1/limssampletests/queryLimsSampleTestPage', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData = res.data.list
          this.total_main = res.data.total
          this.tableData.forEach(item => {
            item.stateFlagName = item.stateFlag === '0' ? '编辑' : item.stateFlag === '3' ? '提交' : ''
            item.entrTime1 = formatDate(item.entrTime, 'yyyy-MM-dd')
          })
          if (this.tableData.length > 0) {
            // this.$refs.dataTable.setCurrentRow(this.tableData[0])
            this.searchFollow(this.tableData[0])
          }
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading = false;
      }).catch(err => {
        this.tableLoading = false;
        this.$message.error(err.message)
      })
    },
    //点击主表信息，查询子表
    searchFollow(row) {
      this.tableLoading2 = true;
      // var obj = JSON.stringify(row);
      this.axios.post('pass/testManagement/v1/limssampletestds/queryLimsSampleTestDList?stId=' + row.stId, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData2 = res.data
          let data = res.data
          this.cols = data
          // if (this.tableData2.length > 0) {
          //   this.$refs.dataTable2.setCurrentRow(this.tableData2[0])
          //   this.searchBottom(this.tableData2[0])
          // }
          // console.log(this.tableData2[0])
          // if(this.tableData2[0] != null){
          //   this.searchFollow2(this.tableData2[0])
          // }
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading2 = false;
      }).catch(err => {
        this.tableLoading2 = false;
        this.$message.error(err.message)
      })
    }, searchFollow2(row) { //查询原始记录
      this.tableLoading2 = true;
      this.axios.post('pass/testManagement/v1/limssampletestds/queryLimsSampleTestDByEntrId', { srId: row.srId, testItemNo: row.testItemNo }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading2 = false;
      }).catch(err => {
        this.tableLoading2 = false;
        this.$message.error(err.message)
      })
    },
    // searchBottom(row){
    //   this.tableLoading2 = true;
    //   this.axios.post('pass/testManagement/v1/limsdatacollectds/queryLimsDataCollectD',{collId:row.collId},{individualType: 'json'}).then(res =>{
    //     if (res.code == 0 || res.code == 200) {
    //       this.tableData2 = res.data
    //     }else{
    //       this.$message.error(res.message)
    //     }
    //     this.tableLoading2 = false;
    //   }).catch(err =>{
    //     this.tableLoading2 = false;
    //     this.$message.error(err.message)
    //   })
    // },
    handleSizeChangeMain(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.DataMain();
    },
    handleSizeChangeMain2(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.searchFollow();
    },
    handleSizeChangeMain3(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.searchFollow3();
    },
    handleCurrentChangeMain(pageIndex) {
      this.pageIndex = pageIndex;
      this.DataMain();
    },
    tableHeaderCellStyle() {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 2) {
        if (row.stateFlag == '3') {
          return 'error-green';
        }
      }
    },
  }
}
</script>
<style scoped></style>
