<!-- 分析室-接样 -->
<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline='true'>
        <el-form-item label="检验车间">
          <el-select
            v-model="search.deptNo"
            filterable
            clearable
            :disabled='disFlag'
            style="width:140px;"
            @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="search.sectionNo"
            filterable
            clearable
            style="width:140px;"
            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-input v-model="search.matName" @keyup.enter.native="searchData()" size="small" placeholder="请输入查询内容" style="width: 150px;"></el-input>
        </el-form-item>
        <el-form-item label='样号'>
          <el-input v-model="search.sampleNo" @keyup.enter.native="searchData()" size="small" placeholder="请输入样号查询" style="width: 150px;"></el-input>
        </el-form-item>
        <el-form-item label='样品类型'>
          <el-select v-model="search.sampleTypeCode" clearable filterable collapse-tags size="small" style="width:100px;" 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-date-picker
          @change='searchData'
           v-model="search.createTime"
           type="datetimerange"
           range-separator="至"
           :picker-options="pickerOptions"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:300px"
           format="yyyy-MM-dd HH:mm"
           value-format="yyyy-MM-dd HH:mm"
           :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="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-tabs type="border-card" v-model="activeName">
      <el-tab-pane label="待接样" name="first">
        <span slot="label">待接样<el-badge :max="10" :hidden='page.totalPage == 0' style="margin-top:-18px" :value="page.totalPage"></el-badge></span>
        <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>
            <el-form :inline='true' @submit.native.prevent>

              <el-form-item>
                <el-button icon="el-icon-check" type="goon" size="mini" :loading='sampleLoading' v-privilege="activeMenu + 'receive'" @click="samplingData">接样</el-button>
                <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-privilege="activeMenu + 'returnSample'" @click="sampleWithdrawalData">退样</el-button>
              </el-form-item>
              <el-form-item>
                <el-input v-model="values" ref="autoInput" size='mini' style="width：200px" @input="autoSubmit()" clearable :disabled='inputLoading' placeholder="扫码接样"></el-input>
              </el-form-item>
            </el-form>
          </div>

        </div>
        <div class="common-table-div">
           <el-table id="excelTable" v-loading="dataLoading" ref="dataTable" border :height="height_top" highlight-current-row @selection-change="handleRow" :data="table.list" :icore-filter-flag="icoreFilterFlag"
           :header-cell-style="tableHeaderCellStyle" @row-dblclick='showCell' :row-class-name="tableRowName"  :summary-method="getSummaries" show-summary>
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop='stateFlagName' label="状态" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="sndTime" 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="140px" prop="sampleNo" label="样品号" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sampleNum" label="样品数量" align="center">
              <template slot-scope="{row}">
                <el-input type='number' v-if="row.index === tabClickIndex" @blur="saveCell" v-model="row.sampleNum" @keyup.enter.native="saveCell" size="small" style="width: 100%;"></el-input>
                <span v-else>{{row.sampleNum}}</span>
              </template>
            </el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sampleWgt" label="样品重量" align="center">
              <template slot-scope="{row}">
                <el-input type='number' v-if="row.index === tabClickIndex" @blur="saveCell" v-model="row.sampleWgt" @keyup.enter.native="saveCell" size="small" style="width: 100%;"></el-input>
                <span v-else>{{row.sampleWgt}}</span>
              </template>
            </el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="suppName" label="发货单位" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="acceptName" label="收货单位" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="itemTypeName" label="项目类型" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
            <!-- <el-table-column sortable width="140px" prop="batchNo" label="批次号" align="center"></el-table-column> -->
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sndMan" 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-column sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="createTime" label="创建时间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="updateMan" label="修改人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="updateTime" label="修改时间" align="center"></el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
            <el-pagination v-loading="dataLoading" @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="second">
        <span slot="label">已接样<el-badge :max="10" :hidden='page2.totalPage == 0' style="margin-top:-18px" :value="page2.totalPage"></el-badge></span>
        <div class="common-title-div" style="padding-top:0px">
          <div class="common-title-name" style="margin-right:10px;width:130px;padding-top:10px">
            <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
            已接样信息
          </div>
          <div style="width: 260px;padding-top:10px">
            <el-form :inline='true' @submit.native.prevent>
              <el-form-item label="扫码接样">
                <el-input v-model="values" ref="autoInput" size='mini' style="width：200px" @input="autoSubmit()" clearable :disabled='inputLoading'></el-input>
              </el-form-item>
            </el-form>
          </div>
          <el-button style="heigh:30px;margin-top:10px" icon="el-icon-remove-outline" type="danger" :loading='sampleLoading2' size="mini" @click="cancelLimsSampleAcpt">取消接样</el-button>

         <!-- <div v-if="this.matNameAndNum.length>0" style="width:670px;float:right">
            <ul>
              <li v-for="(item, index) in this.matNameAndNum" :key="index" style="float:left;margin-left:20px">{{item.name}}: {{item.count}}</li>
            </ul>
          </div>-->
          <div v-if="matNameAndNum.length>0" style="width:670px;float:right">
            <el-select v-model="mName" placeholder="点击显示接样信息" clearable filterable>
              <el-option
                v-for="(item, index) in matNameAndNum"
                :key="index"
                :label="item.name+' : '+item.count"
                :value="item.name"
              ></el-option>
            </el-select>
          </div>

        </div>
        <div class="common-table-div">
           <el-table v-loading="dataLoading2" ref="dataTable2" border :height="height_bot" highlight-current-row @selection-change="handleSelectionChange2" :data="table.list2" :icore-filter-flag="icoreFilterFlag"
           :header-cell-style="tableHeaderCellStyle" :cell-class-name="tableRowClassName2" :summary-method="getSummaries" show-summary>
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="stateFlagName" 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="140px" prop="sampleNo" label="样品号"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sampleNum" label="样品数量" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="itemTypeName" label="项目类型" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="batchNo" label="批次号" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="suppName" label="发货单位" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="acceptName" label="收货单位" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="refuseNote" label="拒收原因" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="sndTime" label="送样日期" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="sndMan" label="送样人"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="acptTime" label="接样日期" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="acptMan" label="收样人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="memo" label="备注" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" label="创建人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="updateMan" label="修改人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" label="修改时间" align="center"></el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
            <el-pagination  @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
              :current-page="page2.pageNum" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
              :total="page2.totalPage" background>
            </el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible">
      <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>
      <el-form ref="baseData" label-width="60px" :rules="ruleValidate" :model="baseData">
        <el-row>
          <el-col :span="12">
            <el-form-item prop="matName" label="物料">
              <el-input v-model="baseData.matName" readonly disabled size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="sampleNo" label="样号">
              <el-input v-model="baseData.sampleNo" readonly disabled size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
          <el-row>
           <el-col :span="24">
            <el-form-item prop="refuseNote" label="原因">
              <el-input v-model="baseData.refuseNote"  size="small"></el-input>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="memo" label="备注">
                <el-input v-model="baseData.memo" size="small"></el-input>
              </el-form-item>
            </el-col>
         </el-row>
       </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" :loading='backLoading' @click="modifyData()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
    </el-dialog>
  </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 {
      table: {
        list: [],
        list2: []
      },
      matNameAndNum: [],
      mName: '',
      inputLoading:false,
      values:'',
      tabClickIndex:null,
      sampleLoading:false,
      sampleLoading2:false,
      backLoading:false,
      cnacelLoading:false,
      saveRow:[],
      baseData:{},
      baseDataList:[],
      ruleValidate: {
        refuseNote: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
      },
      dialogTableVisible:false,
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      planId: '',
      sectionNameType:[], // 检验车间
      disFlag: false,    // 检验车间下拉框默认无法使用，只有当管理员或者无车间用户可以使用
      sectionClassType:[], // 检验班组
      companyNameType:[], // 公司
      sampleTypeNameType: [],
      multipleSelection4: [],
      search: {
        deptNo:'',
        sectionNo:'',
        createTime: [],
        sampleTypeCode: '',
        matName: '',
      },
      activeName:'first',
      height_top:0,
      height_bot:0,
      activeMenu:'',
      timeId:null,
      pickerOptions: {
        shortcuts: [{
          text: '0点',
          onClick(picker) {
            let date = new Date()
            let year = date.getFullYear().toString();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            day = day < 10  ? "0" + day : day;
            month = month < 10 ? "0" + month : month;
            const end = `${year}-${month}-${day}` + ' 00:59';
            day = day - 1;
            if (day < 10 & day > 0)  day = '0' + day
            if (day < 1)  day = '01'
            const start1 = `${year}-${month}-${day}` + ' 23:00';
            const start = start1;
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '2点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 01:00';
            const end = `${year}-${month}-${day}` + ' 02:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '4点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 03:00';
            const end = `${year}-${month}-${day}` + ' 04:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '8点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 07:00';
            const end = `${year}-${month}-${day}` + ' 08:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '12点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 11:00';
            const end = `${year}-${month}-${day}` + ' 12:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '14点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 13:00';
            const end = `${year}-${month}-${day}` + ' 14:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '16点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 15:00';
            const end = `${year}-${month}-${day}` + ' 16:30';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '20点',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 19:00';
            const end = `${year}-${month}-${day}` + ' 20:30';
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '上午',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 06:00';
            const end = `${year}-${month}-${day}` + ' 12:00';
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '下午',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 12:00';
            const end = `${year}-${month}-${day}` + ' 18:00';
            picker.$emit('pick', [start, end]);
          }
        },{
          text: '晚上',
          onClick(picker) {
            let date = new 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;
            const start = `${year}-${month}-${day}` + ' 18:00';
            const end = `${year}-${month}-${day}` + ' 23:59';
            picker.$emit('pick', [start, end]);
          }
        }]
      },
    }
  },
  created() {
    this.height_top = window.innerHeight -240;
    this.height_bot = window.innerHeight -240;
    this.search.createTime = [this.getYNM(new Date()) +' 00:00:00', this.getYNM(new Date()) +' 23:59:59']
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
    this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",{},{ individualType: "json" }).then((response) => {
      this.companyNameType = response.data;
      this.selectDepartment('F31300000')
      this.getCompany();
    });
  },
  mounted () {
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4801}, {individualType: 'json'}).then(res => {
      this.sampleTypeNameType = res.data
    })
    this.searchData();
    // this.addScreen();
    // this.addScreen2()
  },
  methods: {
    getmatNameAndNum(arr){
      var allData = []
      allData.push({
          name: arr[0].matName,
          count: 0
      })
      // allData.forEach(item=>{
      //   console.log('allData: ' + JSON.stringify(item))
      // })

      // for(var i = 1; i < arr.length; i++){
      //   let obj = arr[i]
      //   var flag = 0
      //   for(var j = 0; j < this.matNameAndNum.length; j++){
      //     if(this.matNameAndNum[j].name == obj.matName){
      //       this.matNameAndNum[j].count++
      //       flag++
      //     }
      //     break
      //   }

      //   if(flag == 0){
      //     console.log(arr[i].matName)
      //     this.matNameAndNum.push({
      //       name: obj.matName,
      //       count: 1
      //     })
      //   }
      // }
      arr.forEach(item => {
        var flag = 0;
        allData.forEach(obj => {
          if(item.matName == obj.name){
            obj.count++;
            flag++
          }
        })
        if(flag == 0){
          allData.push({
            name: item.matName,
            count: 1
          })
        }
      })
      // var temp = allData.length >= 8 ? 8 : allData.length
      //TODO
      var temp=allData.length;
      for(var i = 0; i < temp; i++){
        this.matNameAndNum.push({
          name: allData[i].name,
          count: allData[i].count
        })
      }
      // console.log(this.matNameAndNum)
    },
    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}`;
    },
    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;
    },
    closeDialog(){
      this.baseData = {}
      this.backLoading = false
    },
    showCell(row){
      this.tabClickIndex = row.index
    },
    saveCell(row){
      this.tabClickIndex = null
    },
    tableRowName({row, rowIndex}){
      row.index = rowIndex
    },
    autoSubmit(val){
      if (!this.values) {
        this.$message.warning('请先用扫码枪扫描标签')
        return
      }
      if (!this.timeId) {
        this.timeId = setTimeout(() => {
          this.inputLoading = true
          this.axios.post('pass/testManagement/v1/limssampleacpts/saveLimsSampleAcptScan',{itemTypeCode:'480407',scanCode:this.values,scanName:'sampleNo'},{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.$nextTick(() =>{
              this.$refs.autoInput.focus()
            })
            this.values = ''
            this.inputLoading = false
            }).catch(e => {
              this.$nextTick(() =>{
                this.$refs.autoInput.focus()
              })
            this.values = ''
            this.inputLoading = false
            }).catch(e => {
              this.$nextTick(() =>{
                this.$refs.autoInput.focus()
              })
              this.values = ''
              this.inputLoading = false
             this.$message.error(e.message)
          })
          this.timeId = null;
        }, 1000);
      }
    },
    //接样
    samplingData () {
      if (this.saveRow.length < 1) {
        this.$message.warning('请点击勾选中您接样的数据！')
        return
      }
      let tempArr = []
      tempArr =  JSON.parse(JSON.stringify(this.saveRow))
      // tempArr.forEach(item =>{
      //   item.itemTypeCode = 480402
      // })
      this.sampleLoading = true
      this.axios.post('pass/testManagement/v1/limssampleacpts/saveLimsSampleAcpt',tempArr, {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.sampleLoading = false
        }).catch(e => {
          this.sampleLoading = false
         this.$message.error(e.message)
       })
    },cancelLimsSampleAcpt(){
      //取消接样
      if (this.multipleSelection4.length < 1) {
        this.$message.warning('请点击勾选中您要退样的一条数据！')
        return
      }
      let tempArr = []
      tempArr =  JSON.parse(JSON.stringify(this.multipleSelection4))
      this.sampleLoading2 = true
      // this.multipleSelection4.map(item =>{
      //   tempArr =  JSON.parse(JSON.stringify(item))
      // })
      this.axios.post('pass/testManagement/v1/limssampleacpts/cancelLimsSampleAcpt',tempArr, {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.sampleLoading2 = false
        }).catch(e => {
          this.sampleLoading2 = false
         this.$message.error(e.message)
       })
    },
    //退样弹窗
    sampleWithdrawalData () {
      if (this.saveRow.length != 1) {
        this.$message.warning('请点击勾选中您要退样的一条数据！')
        return
      }
      this.baseData = Object.assign({},this.saveRow[0])
      this.dialogTableVisible = true
    },
    //退样确认
    modifyData () {
      this.$refs['baseData'].validate((valid) => {
        if (valid) {
          this.backLoading = true
          this.baseData.id = ''
          this.baseData.stateFlag = ''
          console.log(this.baseData,"传递的参数");
          this.baseDataList.push(this.baseData);
          this.axios.post('pass/testManagement/v1/limssampleacpts/refuseacpt', this.baseDataList, {individualType: 'json'}).then(res => {
            this.baseDataList=[];
            if (res.code == 0 || res.code == 200) {
              this.dialogTableVisible = false;
              this.$message.success(res.message)
              this.searchData()
            } else {
              this.$message.error(res.message)
            }
            this.backLoading = false
          }).catch(e => {
            this.baseDataList=[];
            this.backLoading = false
            this.$message.error(e.message)
          })
        }
      })
    },
    //弹出窗取消
    cancel(){
      this.baseData = {}
      this.backLoading = false
      this.dialogTableVisible = false
    },
    cancelData () {
      if (this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要取消的数据！')
        return
      }
      let tempArr = []
      this.multipleSelection4.map(item =>{
        tempArr.push(item.id)
      })
      this.cnacelLoading = true
      this.axios.post('pass/testManagement/v1/limssampleacpts/cancel', tempArr, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
         this.$message.success('取消成功');
         this.searchData()
        } else {
         this.$message.error(res.message)
        }
        this.cnacelLoading = false
      }).catch(e => {
        this.cnacelLoading = false
        this.$message.error(e.message)
      })
    },
    searchData (){
      this.page.pageNum = 1;
      this.page.pageSize = 200
      this.page2.pageNum = 1;
      this.page2.pageSize = 200
      this.mainData()
      this.getDataList2()
    },
    selectDepartment(val) {
      this.sectionNameType = [];
      this.companyNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList;
        }
      });
    },
    clearSelect(){
      this.search.sectionNo = '';
    },
    //根据选中的部门名称，查询班组名称
    selectClass(val) {
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
          this.search.sectionNo = '';
        }
      });
    },
    mainData () {
      //  this.saveRow = {}
      this.dataLoading = true;
      if (!this.search.createTime) {
        this.startTime = ''
        this.endTime = ''
      } else {
        this.startTime = this.search.createTime[0],
        this.endTime = this.search.createTime[1]
      }
      let obj = {
        'object':{
          'matName': this.search.matName,
          'sampleTypeCode': this.search.sampleTypeCode,
          'sampleNo' : this.search.sampleNo,
          // 'itemTypeCode':480402,
          'createNo':userId,
          'stateFlag':1,
          deptNo: this.search.deptNo,
          sectionNo: this.search.sectionNo
        },
        'list2':['480402','480407'],
        'list':['-01','-02'],
        'mode':'',
        "pageSize": this.page.pageSize,
        "pageIndex": this.page.pageNum,
        'startTime2': this.startTime,
        'endTime2':this.endTime
      }
      this.axios.post('pass/testManagement/v1/limssampleacpts/queryLimsSampleAcptPage',obj,{individualType: 'json'}).then(res => {
        this.dataLoading = false;
        if (res.code == 0 || res.code == 200) {
          this.table.list = res.data.list;
          this.table.list.forEach(item =>{
            item.stateFlagName = item.stateFlag === '-1' ? '退样' : item.stateFlag === '0' ? '未交样' : item.stateFlag === '1' ? '已交样' : item.stateFlag === '2' ? '已接样' : item.stateFlag === '3' ? '已处理' :'退样'
            // 只有中控物料，显示收货发货单位
            if (item.sampleTypeCode != 480102) {
              item.suppName = ''
              item.acceptName = ''
            }
          })
          this.page.totalPage = res.data.total
        }else{
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(e.message)
      });
    },
    getDataList2 () {
      this.matNameAndNum = []
      this.dataLoading2 = true;
      if (!this.search.createTime) {
        this.startTime = ''
        this.endTime = ''
      } else {
        this.startTime = this.search.createTime[0]
        this.endTime = this.search.createTime[1]
      }
      let obj = {
        'object':{
          'matName': this.search.matName,
          'sampleTypeCode': this.search.sampleTypeCode,
          'sampleNo' : this.search.sampleNo,
          // 'itemTypeCode':480402,
          'createNo':userId,
          'stateFlag':2,
          deptNo: this.search.deptNo,
          sectionNo: this.search.sectionNo
        },
        'list2':['480402','480407'],
        'list':['-01','-02'],
        'mode':'',
        "pageSize": this.page2.pageSize,
        "pageIndex": this.page2.pageNum,
        'startTime2': this.startTime,
        'endTime2':this.endTime
      }
      this.axios.post('pass/testManagement/v1/limssampleacpts/queryLimsSampleAcptPage',obj,{individualType: 'json'}).then(res => {
        this.dataLoading2 = false;
        if (res.code == 0 || res.code == 200) {
          this.table.list2 = res.data.list;
          if(this.table.list2.length != 0){
            this.getmatNameAndNum(this.table.list2)
          }
          this.table.list2.forEach(item =>{
            item.stateFlagName = item.stateFlag === '-1' ? '退样' : item.stateFlag === '0' ? '未交样' : item.stateFlag === '1' ? '已交样' : item.stateFlag === '2' ? '已接样' : item.stateFlag === '3' ? '已处理' :'退样'
            // 只有中控物料，显示收货发货单位
            if (item.sampleTypeCode != 480102) {
              item.suppName = ''
              item.acceptName = ''
            }
          })
          this.page2.totalPage = res.data.total;
        }else{
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.dataLoading2 = false;
        this.$message.error(e.message)
      });
    },
    reset () {
      this.search.createTime = [this.getYNM(new Date()) +' 00:00:00', this.getYNM(new Date()) +' 23:59:59']
      this.search.matName = '';
      this.search.sampleTypeCode = '';
      this.searchData();
    },
    //待接样信息表格点击选中
    handleRow (val) {
      this.saveRow = val
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    handleSelectionChange2 (val) {
      this.multipleSelection4 = val;
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2();
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2();
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    addScreen2 () {
     this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable2.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
  //  tableRowClassName ({
  //       row, column, rowIndex, columnIndex
  //     }) {
  //       if (columnIndex === 13) {
  //       if (row.validFlag !== '1') {
  //         return 'error-row';
  //       }
  //       }
  //       if (columnIndex === 3) {
  //       if (row.stateFlag === '1') {
  //         return 'error-green';
  //       }
  //       return '';
  //       }
  //     },
    tableRowClassName2 ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 2) {
        if (row.stateFlag === '-1') {
          return 'error-row';
        }
        return '';
        }
    },
    tableHeaderCellStyle () {
      return 'background-color: rgb(249,249,249) !important;color: rgb(73, 72, 72);border-bottom: 1px solid #DCDFE7;border-top:3px solid #3ac1ea;'
    },
    //TODO
    getCompany(){
      this.axios.get('pass/baseManagement/v1/limslrcemps/'+userId).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.deptNo = res.data ? res.data.deptNo : ''
          this.deptName=res.data?res.data.deptName:''
          if (this.deptNo) {
            this.search.deptNo = this.deptNo
          }else {
            this.disFlag=false
          }
          this.selectClass(this.search.deptNo)
          this.search.sectionNo = res.data ? res.data.sectionNo : ''
          this.searchData()
        }else{
          this.disSearch = true
          this.$message.error(e.message)
        }
      }).catch(e =>{
        this.disSearch = true
        this.$message.error(e.message)
      })
    }
  }
}
</script>
<style  scoped>
</style>
