<!-- 任务管理 - 人员排班-分析室 -->
<template>
  <div class="examination">
    <el-form :inline='true' class="common-head-search">
      <el-form-item label="排班部门">
        <el-select v-model="search.deptNo" disabled filterable @change='selectClass' clearable style="width:150px" collapse-tags 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" :disabled='disFlag' @change='selectPlan' clearable style="width:150px" filterable collapse-tags size="small">
          <el-option v-for="item in sectionClass" :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.wrkGrpCode" clearable style="width:150px" filterable collapse-tags size="small">
          <el-option v-for="item in wrkGrpClass" :key="item.baseCode" :label="item.baseName" :value="item.baseCode">
          </el-option>
        </el-select>
      </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>
    <el-row>
      <el-col :span="11">
        <el-row>
          <div class="common-title-div" style="height:auto">
            <div class="common-title-name" style="margin-right:10px">
              <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
              <span>排班</span>
            </div>
            <div>
              <el-form :model="form" ref="form" :inline="true" size="mini">
                <el-form-item style="margin-bottom:0">
                  <el-button size="mini" type="goon" icon="el-icon-check" :loading='allotBLoading' v-privilege="activeMenu + 'auto'" @click="allot">排班</el-button>
                  <el-button size="mini" type="goon" icon="el-icon-check"  v-privilege="activeMenu + 'manual'" @click="handWork">手动排班</el-button>
                </el-form-item>
                <el-form-item style="margin-bottom:0" label='排班日期'>
                  <el-date-picker v-model="startDate"  type="datetime" style="width:173px" size="small" placeholder="请选择排班日期" value-format="yyyy-MM-dd HH:mm:ss" default-time="12:00:00"></el-date-picker>
                  <el-date-picker v-model="wgoDate"  type="datetime" style="width:173px" size="small" placeholder="请选择排班日期" value-format="yyyy-MM-dd HH:mm:ss" default-time="12:00:00"></el-date-picker>
                </el-form-item>
              </el-form>
            </div>
          </div>
          <div class="common-table-div" style="margin-bottom:0;margin-top:0">
            <el-table
            v-loading="dataLoading" ref="dataTable" border :height="topheight"
            highlight-current-row
            @selection-change="handleSelectionChange1"
            :data="tableData1"
            :icore-filter-flag="icoreFilterFlag"
            :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 sortable :show-overflow-tooltip="true" width="88px" prop="empNo" label="职工编号" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" width="88px" prop="empName" label="职工姓名" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sectionName" label="班组" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="postName" label="岗位"  align="center"></el-table-column>
              <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="wrkGrpName" label="班值" align="center"></el-table-column> -->
              <!-- <el-table-column sortable min-width="100px" prop="wrkOrdName" 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]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.totalPage" background>
            </el-pagination>
          </div>
        </el-row>
      </el-col>
      <el-col :span='13'>
        <div class="common-title-div">
          <div class="common-title-name" style="margin-right:10px">
            <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
            任务分配信息
          </div>
          <div>
            <el-button icon="el-icon-circle-close" type="danger" size="mini" :loading='cancelLaoding' v-privilege="activeMenu + 'cancel'" @click="cancel">取消</el-button>
            <el-date-picker v-model="createTime" @change="timeChange" type="date" style="width:140px" size="small" placeholder="请选择排班日期" value-format="yyyy-MM-dd"></el-date-picker>
          </div>  
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table
          v-loading="tableLoading3" ref="dataTable3" border :height="topheight"
          highlight-current-row
          @selection-change='selectData'
          :data="tableData3" 
          :icore-filter-flag="icoreFilterFlag"
          :header-cell-style="tableHeaderCellStyle"
          :cell-class-name="tableRowClassName3"
          :summary-method="getSummaries" show-summary>
            <el-table-column type="index" label="NO" width="45" fixed="left" align="center"></el-table-column>
            <el-table-column  type="selection" align="center" fixed width="45"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="empNo" label="职工编号" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="empName" label="职工姓名" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="testItemName" 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="100px" prop="planNum" label="计划任务量" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="doNum" label="完成任务量" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="condition4" label="任务名称" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="startTime" label="值班开始时间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="endTime" label="值班结束时间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="wgoDate" label="排班日期" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="deptName" label="部门"  align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sectionName" label="任务班" align="center" style="color:blue;"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="wrkGrpName" label="班组" align="center" style="color:blue;"></el-table-column>
          </el-table>
        </div> 
        <div class="common-foot-style">
          <el-pagination
          @size-change="pageSizeChange3"
          @current-change="pageCurrentChange3"
          :current-page="page3.pageNum"
          :page-sizes="[10, 20, 50, 100, 200]"
          :page-size="page3.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page3.totalPage" background>
          </el-pagination>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span='11'>
        <div class="common-title-div">
          <div class="common-title-name" style="margin-right:10px">
            <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
            <span>任务信息</span>
          </div>
          <div>
            <el-form :model="form" ref="form" :rules="rules" :inline="true" size="mini">
              <el-form-item label='排班名称'>
                <el-select v-model="form.ruleNo" filterable :disabled='disFlag' placeholder='请选择排班名称' style="width:180px" @change='firstData' collapse-tags size="mini">
                  <el-option v-for="item in ruleTypeNameType" :key="item.ruleNo"  :label="item.ruleName" :value="item.ruleNo">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table
          v-loading="tableLoading2" ref="dataTable2" border :height="topheight"
          highlight-current-row
          @selection-change="handleSelectionChange2"
          :data="tableData2"
          @row-click='searchDetail'
          @row-dblclick='showCell'
          :row-class-name="tableRowName"
          :header-cell-style="tableHeaderCellStyle"
          :summary-method="getSummaries" show-summary>
            <el-table-column type="index" label="NO" width="45" fixed="left" align="center"></el-table-column>
            <el-table-column type="selection" fixed width="45" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="ruleItemName" label="测试任务名称" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="ruleItemValue" label="人员数量" align="center">
              <template slot-scope="{row}">
                <el-input oninput ="value=value.replace(/[^0-9]/g,'')" v-if="row.index === tabClickIndex"  v-model="row.ruleItemValue"  @keyup.enter.native="saveCell" size="small" style="width: 100%;"></el-input>
                <span v-else>{{row.ruleItemValue}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
      <el-col :span='13'>
        <div class="common-title-div">
          <div class="common-title-name" style="margin-right:10px">
          </div>
          <div>
            <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini"  @click="addMat">新增物料</el-button>
            <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData">清空物料</el-button>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table
          v-loading="tableLoading2" ref="dataTable2" border :height="topheight"
          highlight-current-row
          :data="dataType"
          @row-dblclick='showTwoCell'
          :row-class-name="tableRowName"
          :header-cell-style="tableHeaderCellStyle"
          :summary-method="getSummaries" show-summary>
            <el-table-column type="index" label="NO" fixed width="45" align="center"></el-table-column>
            <el-table-column  width="45" fixed align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="deleteTable(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" width="140px" prop="matName" label="物料" align="center">
              <template slot-scope="{row}">
                <el-select
                  @change="selectMat(row)"
                  v-model="row.matNos"
                  clearable
                  style="width: 100%"
                  filterable
                  size="small"
                >
                  <el-option
                    v-for="(item, index) in matNameType"
                    :key="index"
                    :label="item.matName"
                    :value="item.matNo"
                  >
                  </el-option>
                </el-select>
                </template>
            </el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="180px" prop="matName" label="任务名称" align="center">
              <template slot-scope="{row}">
                <el-select
                v-model="row.testItemNos"
                clearable
                multiple
                style="width: 100%"
                filterable
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="(item, index) in row.datailTable"
                  :key="index"
                  :label="item.testItemName"
                  :value="item.testItemNo"
                >
                </el-option>
              </el-select>
              </template>
            </el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" width="230px" label="样品编号" align="center">
              <template slot-scope="{row}">
                <el-select
                v-model="row.sampleNos"
                @change="selectSampleNos(row)"
                clearable
                multiple
                style="width: 100%"
                filterable
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="(item, index) in row.datailTable2"
                  :key="index"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" width="75px" label="样品数量" align="center">
              <template slot-scope="{row}">
                <el-input oninput ="value=value.replace(/[^0-9]/g,'')" v-model="row.num1"  @keyup.enter.native="saveTwoCell" size="small" style="width: 100%;"></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>
    <el-dialog @close="cancelData" :visible.sync="dialogTableVisible" width="70%">
      <div slot="title">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">选择人员</span>
      </div>
      <el-table
      v-loading="allotLoading" ref="dataTable2" border height="300"
       highlight-current-row
       :data="allotData"
       @selection-change="handAllot"
       :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle"
       :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="100px" prop="empNo" label="职工编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="empName" label="职工姓名" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sectionName" label="班组" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="postName" label="岗位"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="wrkGrpName" label="班值" align="center"></el-table-column>
      </el-table>
      <div>
          <el-pagination
          @size-change="pageSizeAllot"
          @current-change="pageCurrentAllot"
          :current-page="allotIndex"
          :page-sizes="[100, 200,500]"
          :page-size="allotPage"
          layout="total, sizes, prev, pager, next, jumper"
          :total="allotTotal" background>
          </el-pagination>
        </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" :loading='modeLoading' @click="modeAllot()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancelData">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getCookie
} 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: [],
        list3: []
      },
      createTime:'',
      ruleTypeNameType:[],
      ruleTypeName:[],
      tableLoading2:false,
      tableLoading3:false,
      allotLoading:false,
      cancelLaoding:false,
      dataType:[],
      allotData:[],
      tableData1:[],
      tableData2:[],
      tableData3:[],
      selection1:[],
      selection2:[],
      selection3:[],
      selection4:[],
      datailTable:[],
      datailTable2:[],
      dataLoading: false,
      icoreFilterFlag: true,
      form:{ruleNo:'R0014'},
      search: {
        startDate:[],
        deptNo: 'P31301100',
        wgoDate: [],
        sectionNo:'',
        wrkGrpCode: '',
      },
      wrkGrpClass:[],
      rules:{
        ruleTypeNo: [{ required: true, message: '不能为空', trigger: 'change' }],
        ruleNo: [{ required: true, message: '不能为空', trigger: 'change' }],
      },
      disFlag:false,
      clickAllot:[],
      allotBLoading:false,
      modeAllotBLoading:false,
      allocationLoading:false,
      allotIndex:1,
      allotPage:100,
      allotTotal:0,
      wgoData:{},
      clickData:[],
      itemType:[],
      savaSampleValue:'',
      topheight:0,
      bHeight:0,
      tabClickIndex:null,
      tabClickIndexs:null,
      startDate:'',
      wgoDate:'',
      startDate:'',
      page: {
        pageSize: 500,
        pageNum: 1,
        totalPage: 0
      },
       page2: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      modeLoading:false,
      page3: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      handData:[],
      planRow:{},
      dialogTableVisible:false,
      companyNameType:[],
      sectionNameType:[],
      sectionClass:[],
      multipleSelection3: [],
      multipleSelection4: [],
      multipleSelection5: [],
      matNameType:[],
      activeMenu:''
    }
  },
  created(){
    this.topheight = window.innerHeight / 2 < 249 ? 249 : window.innerHeight / 2 - 115;
    this.topheight = this.topheight < 249 ? 249 : this.topheight
    this.bHeight = this.topheight *2 + 80
    this.search.wgoDate = [this.getYNM(new Date(new Date().setHours(-24))), this.getYNM(new Date())]
    this.startDate= this.getYNM(new Date()) + ' 08:00:00'
    this.wgoDate = this.getYNM(new Date()) + ' 18:00:00'
    this.createTime = this.getYNM(new Date())
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    //获取公司
    this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",{}, {individualType: 'json'}).then(response => {
      this.companyNameType = response.data
      this.selectDepartment('F31300000')
      this.selectClass('P31301100')
    });
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4836}, {individualType: 'json'}).then(res => {
      this.wrkGrpClass = res.data;
    })
    // this.axios.post("pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage",{object:{validFlag:1, matClassNo: "S008"},pageIndex: 1,pageSize: 99999}, {individualType: 'json'}).then(res => {
    //   this.matNameType = res.data.list;
    // })
    this.axios.post("pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage",{object:{validFlag:1, mat_eng_abbr:"ZXFX"},pageIndex: 1,pageSize: 99999}, {individualType: 'json'}).then(res => {
      this.matNameType = res.data.list;
    })
    this.getMustData()
    // this.searchData()
    // this.addScreen();
    // this.addScreen2();
    this.addScreen3();
  },
  methods: {
    getMustData(){
      this.axios.all([this.getCompany(),this.getClass()]).then(this.axios.spread((res1,res2) =>{
        this.ruleTypeNameType = res2.data.list;
        if (res1.code == 0 || res1.code == 200) {
          this.search.sectionNo = res1.data ? res1.data.sectionNo : ''
          this.disFlag = this.search.sectionNo ? true : false
          this.form.ruleNo = this.getCode(res1.data ? res1.data.sectionName : '',this.ruleTypeNameType,'ruleName','ruleNo')
          this.searchData()
        }else{
          this.disSearch = true
          this.$message.error(e.message)
        }
      }))
    },
    //获取个人所属哪个公司、班组
    getCompany () {
      return this.axios.get('pass/baseManagement/v1/limslrcemps/'+userId);
    },
    getClass(){
      return this.axios.post("pass/baseManagement/v1/limsbaserules/queryLimsBaseRuleInfoPage",{object:{validFlag:1,ruleTypeCode:483805,ruleVer:'分析室'},pageIndex:1,pageSize:999}, {individualType: 'json'})
    },
    selectDepartment(val){
      this.companyNameType.find(item =>{
        if(val === item.orgCode){
          this.sectionNameType = item.sysOrgList
        }
      })
    },
    //根据选中的部门名称，查询班组名称
    selectClass (val){
      this.sectionClass = []
      this.sectionNameType.find(item =>{
        if(val === item.orgCode){
          this.sectionClass = item.sysOrgList
        }
      })
    },
    selectPlan(val){
      let name = this.getCode(val,this.sectionClass,'orgCode','orgName')
      this.form.ruleNo = this.getCode(name,this.ruleTypeNameType,'ruleName','ruleNo')
      this.firstData(this.form.ruleNo)
    },
    cancelData(){
      this.modeLoading = false
      this.dialogTableVisible = false
    },
    handWork(){
      if (this.selection2.length != 1) {
        this.$message.warning("请先勾选一条且只能勾选一条任务信息数据");
        return;
      }
      this.searchAllot()
      this.dialogTableVisible = true
    },
    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}`;
    },
    getCode(code, arr, codeKey, nameKey) {
      if (!code) {
        return "";
      }
      let targetRow = arr.find((item) => {
        return item[codeKey] === code;
      });
      // console.log(targetRow, 'targetRow');
      return targetRow ? targetRow[nameKey] : "";
    },
    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;   
    },
    addMat(){
      this.dataType.push({matNos:[]})
    },
    deleteData(){
      this.dataType = []
    },
    tableRowName({row, rowIndex}){
      row.index = rowIndex
    },
    showCell(row){
      this.tabClickIndex = row.index
    },
    saveCell(row){
      row.ruleItemValue  = row.ruleItemValue ? row.ruleItemValue : '0'
      this.tabClickIndex = null
    },
    showTwoCell(row){
      // this.searchDetailMatName(row)
      // this.tabClickIndexs = row.index
    },
    saveTwoCell(row){
      this.tabClickIndexs = null
    },
    // 查询，flag为ture表示 排版操作后的查询
    searchData (flag) {
      this.page.pageNum = 1;
      this.page.pageSize = 100;
      this.page2.pageNum = 1
      this.page2.pageSize = 50
      this.page3.pageNum = 1
      this.page3.pageSize = 50
      this.dataType = []
      this.mainData(flag)
      this.firstData(this.form.ruleNo)
      this.getAllotData()
    },
    firstData(val){
      this.dataType = []
      this.form.ruleNo = val
      if (!val) {
        this.tableData2 = []
        return
      }
      let obj = {
        'mode':this.form.ruleNo,
        'pageIndex':this.page2.pageNum,
        'pageSize':this.page2.pageSize
      }
      this.datailTable = []
      this.datailTable2 = []
      this.tableLoading2 = true
      this.axios.post('pass/testManagement/v1/limsstdtestitems/querylimstdtest',obj,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData2 = res.data.list;
          this.tableData2.forEach(item =>{
            item.matNameNo
            item.maxValue = item.ruleItemValue
            item.isAutoName = item.isAuto == 0 ? '否' :item.isAuto == 1 ? '是' : ''
          })
          this.tableData2.sort((a,b)=>{
            return a.ruleItemOrder - b.ruleItemOrder
          })
          this.page2.totalPage = res.data.total;
        }else{
          this.$message.error(res.message)
        }
        this.tableLoading2 = false;
      }).catch(e => {
        this.tableLoading2 = false;
        this.$message.error(e.message)
      });
      
    },
    searchDetail(row){
      this.planRow = row
    },
    //新增物料，选择物料
    selectMat(row){
      row.testItemNos = []
      row.sampleNos = []
      row.num1 = ''
      this.searchDetailMatName(row)
      // this.$set(row, 'datailTable', [])
      // this.$set(row, 'datailTable2', [])
      // if (this.selection2.length !=1) {
      //   this.$message.warning('请先勾选一条任务信息')
      //   return
      // }
    },
    searchDetailMatName(row){
      if (this.selection2.length !=1) {
        this.$message.warning('请先勾选一条任务信息')
        return true;
      }
      this.$set(row, 'datailTable', [])
      this.$set(row, 'datailTable2', [])
      row.num1 = ''
      if(!row.matNos){
        return true;
      }
      // if (row.matNos.length != 1) {
      //   row.testItemNos = []
      //   return
      // }
      let obj = {
        // matNo:row.matNos.length == 1 ? row.matNos[0] : '',
        matNo:row.matNos,
        testPostCode:this.selection2[0].condition1,
        testTypeCode:480301
      }
      // 根据物料、任务信息获取任务列表
      this.axios.post('pass/baseManagement/v1/limsstdtaskds/queryLimsStdTaskD',obj,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$set(row, 'datailTable', res.data)
          let arr = []
          for(let item of res.data){
            arr.push(item.testItemNo);
          }
          row.testItemNos = arr;
        }else{
          this.$message.error(res.message)
        }
      }).catch(e => {
      });
      // 样品编号列表查询
      this.axios.post('pass/testManagement/v1/limstasktests/querySampleNo?matNo='+row.matNos+'&testPostCode='+this.selection2[0].condition1).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$set(row, 'datailTable2', res.data)
          row.num1 = res.data.length;
        }else{
          this.$message.error(res.message)
        }
      }).catch(e => {
      });
    },
    selectSampleNos(row){
      if(row && row.sampleNos) {
        row.num1 = row.sampleNos.length
      }
    },
    // 排班人员信息查询，flag为ture表示 排版操作后的查询
    mainData (flag){
      this.dataLoading = true;
      let obj = {
        'object':{
          'deptNo': this.search.deptNo,
          'sectionNo': this.search.sectionNo,
          'wrkGrpCode':this.search.wrkGrpCode
        },
        'startTime':this.startDate,
        'endTime':this.wgoDate,
        'pageIndex':this.page.pageNum,
        'pageSize':this.page.pageSize
      }
      this.axios.post('pass/baseManagement/v1/limslrcemps/queryEmpPages',obj,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          let selArr = this.selection1.slice();
          this.tableData1 = res.data.list;
          this.page.totalPage = res.data.total;
          if(flag){
            setTimeout(() => {
              let iarr = [];
              for (let i = 0; i < selArr.length; i++) {
                for(let item of this.tableData1){
                  if(item.empNo == selArr[i].empNo){
                    iarr.push(item)
                    break;
                  }
                }
              }
              this.$refs.dataTable.clearSelection();
              for(let j = 0; j < iarr.length; j++) {
                this.$refs.dataTable.toggleRowSelection(iarr[j], true);
              }
            }, 10);
          }
        }else{
          this.$message.error(res.message)
        }
        this.dataLoading = false;
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(e.message)
      });
    },
    deleteTable(index){
      this.dataType.splice(index,1)
    },
    timeChange(){
      this.getAllotData()
    },
    //查询任务分配信息表
    getAllotData(){
      let obj ={
        'object':{
          'deptNo': this.search.deptNo,
          'sectionNo': this.search.sectionNo,
          'wrkGrpCode':this.search.wrkGrpCode
        },
        'startTime2':this.createTime ? this.createTime + ' 00:00:00' : '',
        'endTime2':this.createTime ? this.createTime + ' 23:59:59' : '',
        'pageIndex':this.page3.pageNum,
        'pageSize':this.page3.pageSize
      }
      this.tableLoading3 = true;
      this.axios.post('pass/testManagement/v1/limsempwrkords/queryLimsEmpWrkordPage',obj,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data.list
          this.tableData3.forEach(item =>{
            item.validFlagName = item.validFlag == 1 ? '有效' : item.validFlag == 0 ? '无效' : ''
          })
        }else{
          this.$message.error(res.message)
        }
        this.tableLoading3 = false;
      }).catch(e => {
        this.tableLoading3 = false;
      });
    },
    //取消
    cancel (){
      if (this.clickData.length < 1) {
        this.$message.warning('请先勾选要取消的数据')
        return
      }
      this.cancelLaoding = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/delete',this.clickData,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData(true)
        }else{
          this.$message.error(res.message)
        }
        this.cancelLaoding = false
      }).catch(e => {
        this.cancelLaoding = false
        this.$message.error(e.message)
      });
    },
    // 排班
    allot (){
      if (this.selection1.length < 1) {
        this.$message.warning("请先勾选排班信息数据");
        return;
      }
      if (this.selection2.length != 1) {
        this.$message.warning("请先勾选一条且只能勾选一条任务信息数据");
        return;
      }
      let num = 0
      for (let index = 0; index < this.selection2.length; index++) {
        num += Number(this.selection2[index].ruleItemValue)
        this.selection2[index].startTime =this.startDate
        this.selection2[index].endTime =this.wgoDate
        this.selection2[index].wgoDate =  this.getYNM(new Date()) + ' 00:00:00'
      }
      //不选物料
      let sendData = []
      if (this.dataType.length < 1) {
        let obj = Object.assign({},this.selection2[0])
        obj.num = 9999
        sendData = [obj]
      }else{
        this.dataType.forEach(item =>{
          Object.assign(item,this.selection2[0]) 
          //物料转成字符串
          //item.matNo = item.matNos.join()
          item.matNo = item.matNos
          let nm = 9999;
          if (item.num1 && item.num1 > 0 && item.testItemNos.length > 0) {
            nm = item.num1 * item.testItemNos.length
          }
          item.num = nm
          // item.num = item.matNo.length < 1 || !item.num ? 9999 : item.num
          // let matNameTypes = []
          // matNameTypes = [...item.matNos.map(items=> this.getCode(items,this.matNameType,'matNo','matName'))]
          // item.matName = matNameTypes.join()
          item.matName = this.getCode(item.matNo,this.matNameType,'matNo','matName')
          //任务名称转成字符串
          item.condition3 = item.testItemNos.length > 0 ? item.testItemNos.join() : ''
          let NameType = []
          NameType = item.testItemNos.length > 0 ? [...item.testItemNos.map(items=> this.getCode(items,item.datailTable,'testItemNo','testItemName'))] : []
          item.condition4 = item.testItemNos.length > 0 ? NameType.join() : ''
          item.memo = item.sampleNos.length > 0 ? item.sampleNos.join() : ''
        })
        sendData = this.dataType
      }
      if (this.selection1.length < num) {
        this.$message.warning(`人员数量不能小于任务所需人数！任务所需人数为${num}个`)
        return
      }
      // 条件5判定
      for (let i = 0; i < this.selection2.length; i++) {
        if (this.form.ruleNo == 'R0014') { // 原料分析班
          if(this.selection2[i].condition5 == '2') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '3') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料任务");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
                if(!sendData[j].condition3){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要任务，第" + (j+1) + "行请选择任务");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '5') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要样号");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].memo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要样号，第" + (j+1) + "行请选择样号");
                  return
                }
                if(!sendData[j].condition3){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要任务，第" + (j+1) + "行请选择任务");
                  return
                }
              }
            }
          }
        } else if(this.form.ruleNo == 'R0022'){ // 原料贵金属分析班
          if(this.selection2[i].condition5 == '2') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '3') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料任务");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
                if(!sendData[j].condition3){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要任务，第" + (j+1) + "行请选择任务");
                  return
                }
              }
            }
          }
        }
      }
      this.allotBLoading = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/analysistion',{llp:this.selection1,llo:sendData},{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message || res.resultMessage)
          this.searchData(true) 
        }else{
          this.$message.error(res.message || res.resultMessage)
        }
        this.allotBLoading = false
      }).catch(e => {
        this.allotBLoading = false
        this.$message.error(e.message || e.resultMessage)
      });
    },
    //手动分配
    modeAllot(){
      if (this.handData.length < 1) {
        this.$message.warning("请先勾选人员数据");
        return;
      }
      if (this.selection2.length != 1) {
        this.$message.warning("请先勾选一条且最多只能勾选一条任务信息数据");
        return;
      }
      let num = 0
      this.selection2.map(item =>{
        num += Number(item.ruleItemValue) 
      })
      if (this.handData.length != num) {
        this.$message.warning(`任务数量与人员数量不相等！任务所需人数为${num}个,当前选择的人数为${this.handData.length}个`)
        return
      }
      this.selection2[0].startTime =this.startDate
      this.selection2[0].endTime =this.wgoDate
      this.selection2[0].wgoDate =  this.getYNM(new Date()) + ' 00:00:00'
      //不选物料
      let sendData = []
      if (this.dataType.length < 1) {
        let obj = Object.assign({},this.selection2[0])
        obj.num = 9999
        sendData = [obj]
      } else {
        this.dataType.forEach(item =>{
          Object.assign(item,this.selection2[0]) 
          //物料转成字符串
          // item.matNo = item.matNos.join()
          item.matNo = item.matNos
          item.num = item.matNo.length < 1 || !item.num ? 9999 : item.num
          // let matNameTypes = []
          // matNameTypes = [...item.matNos.map(items=> this.getCode(items,this.matNameType,'matNo','matName'))]
          // item.matName = matNameTypes.join()
          item.matName = this.getCode(item.matNo,this.matNameType,'matNo','matName')
          //任务名称转成字符串
          item.condition3 = item.testItemNos.length > 0 ? item.testItemNos.join() : ''
          let NameType = []
          NameType = item.testItemNos.length > 0 ? [...item.testItemNos.map(items=> this.getCode(items,item.datailTable,'testItemNo','testItemName'))] : []
          item.condition4 = item.testItemNos.length > 0 ? NameType.join() : ''
          item.memo = item.sampleNos.length > 0 ? item.sampleNos.join() : ''
        })
        sendData = this.dataType
      }
      // 条件5判定
      for (let i = 0; i < this.selection2.length; i++) {
        if (this.form.ruleNo == 'R0014') { // 原料分析班
          if(this.selection2[i].condition5 == '2') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '3') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料任务");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
                if(!sendData[j].condition3){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要任务，第" + (j+1) + "行请选择任务");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '5') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要样号");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].memo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要样号，第" + (j+1) + "行请选择样号");
                  return
                }
              }
            }
          }
        } else if(this.form.ruleNo == 'R0022'){ // 原料贵金属分析班
          if(this.selection2[i].condition5 == '2') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
              }
            }
          } else if(this.selection2[i].condition5 == '3') {
            if(sendData.length < 1 || this.dataType.length < 1){
              this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料任务");
              return
            } else {
              for (let j = 0; j < sendData.length; j++) {
                if(!sendData[j].matNo){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要物料，第" + (j+1) + "行请选择物料");
                  return
                }
                if(!sendData[j].condition3){
                  this.$message.warning("测试任务[" + this.selection2[i].ruleItemName + "]需要任务，第" + (j+1) + "行请选择任务");
                  return
                }
              }
            }
          }
        }
      }
      this.modeLoading = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/analysistionHand',{llp:this.handData,llo:sendData},{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.dialogTableVisible = false
          this.$message.success(res.message || res.resultMessage)
          this.searchData() 
        }else{
          this.$message.error(res.message || res.resultMessage)
        }
        this.modeLoading = false
      }).catch(e => {
        this.modeLoading = false
        this.$message.error(e.message || e.resultMessage)
      });
    },
    //点击选中任务分配信息表
    selectData(row){
      this.clickData = row
    },
      // 重置
    reset () {
      this.search.deptNo = 'P31301100'
      this.search.sectionNo = ''
      this.search.wrkGrpCode = ''
      this.searchData();
    },
    dataAllot(){
      this.clickAllot = {}
      this.allotLoading = true
      let obj = {
        'object':{
          'deptNo': this.search.deptNo,
          'sectionNo': this.search.sectionNo,
          'wrkGrpCode':this.search.wrkGrpCode
        },
        // 'endTime':this.wgoDate,
        'pageIndex':this.allotIndex,
        'pageSize':this.allotPage
      }
      this.axios.post('pass/baseManagement/v1/limslrcemps/queryEmpPagesDS', obj, {individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.allotData = res.data.list;
          this.allotTotal = res.data.total
        }else{
          this.$message.error(res.message);
        }
        this.allotLoading = false
      }).catch(err =>{
        this.allotLoading = false
        this.$message.error(err.message);
      })
    },
    //查人员信息
    searchAllot(){
      this.allotIndex = 1
      this.allotPage = 100
      this.dataAllot()
    },
    pageSizeAllot (size) {
      this.allotIndex = 1
      this.allotPage = size;
      this.dataAllot()
    },
    pageCurrentAllot (index) {
      this.allotIndex = index;
      this.dataAllot()
    },
    pageSizeChange (size) {
      this.page.pageNum = 1
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    pageSizeChange2 (size) {
      this.page2.pageNum = 1
      this.page2.pageSize = size;
      this.firstData(this.form.ruleNo)
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
     this.firstData(this.form.ruleNo)
    },
    pageSizeChange3 (size) {
      this.page3.pageNum = 1
      this.page3.pageSize = size;
      this.getAllotData();
    },
    pageCurrentChange3 (index) {
      this.page3.pageNum = index;
      this.getAllotData();
    },
    handleSelectionChange1 (val) {
      this.selection1 = val;
    },
    handleSelectionChange2 (val) {
      this.selection2 = val;
    },
    handleSelectionChange3 (val) {
      this.selection3 = val;
    },
    handAllot(val){
      this.handData = val
    },
    handleSelectionChange4 (val) {
      this.selection4 = val;
    },
    // 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);
    //    });
    // },
    tableRowClassName3 ({ row, column, rowIndex, columnIndex}) {
      if (columnIndex === 4) {
        if (row.validFlag === '0') {
          return 'error-row';
        }
        return '';
      }
    },
    addScreen3 () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable3.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    // 表格上横线
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style scoped>
</style>
