
<!-- 样品抽查页面 -->
<template>
  <div class="examination">
    <el-row>
      <el-col :span="10" id="getHeight">
        <el-row>
          <el-col :span="24">
            <div class="common-title-div">
              <div
                class="common-title-name"
                style="margin-right: 10px; width: 110px"
              >
                <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"
              class="form_wrap_xb"
            >
              <el-form-item label="样品类型">
                <el-select
                  v-model="form.typeNo"
                  filterable
                  placeholder=""
                  style="width: 120px"
                  collapse-tags
                  size="mini"
                >
                  <el-option
                    v-for="item in typeList"
                    :key="item.baseCode"
                    :label="item.baseName"
                    :value="item.baseCode"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="物料名称">
                <el-input
                  type="text"
                  size="mini"
                  clearable
                  v-model="form.matName"
                ></el-input>
              </el-form-item>
              <el-form-item style="margin-bottom: 0" label="抽查时间段">
                <el-date-picker
                  v-model="startDate"
                  type="datetime"
                  style="width: 135px"
                  size="small"
                  placeholder="请选择抽查日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="00:00:00"
                ></el-date-picker>
                <el-date-picker
                  v-model="wgoDate"
                  type="datetime"
                  style="width: 135px"
                  size="small"
                  placeholder="请选择抽查日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="23:59:59"
                ></el-date-picker>
              </el-form-item>
              <el-form-item style="margin-bottom: 0">
                <el-button
                  size="mini"
                  type="goon"
                  icon="el-icon-check"
                  :loading="allotBLoading"
                  v-privilege="activeMenu + 'AUTO'"
                  @click="firstData"
                  >查询</el-button
                >
                <el-button
                  size="mini"
                  type="goon"
                  icon="el-icon-check"
                  :loading="allotBLoading"
                  v-privilege="activeMenu + 'AUTO'"
                  @click="allot"
                  >抽取</el-button
                >
              </el-form-item>
            </el-form>
            <div class="common-table-div">
              <el-table
                v-loading="tableLoading2"
                ref="dataTable2"
                border
                :height="bHeight"
                highlight-current-row
                @selection-change="handleSelectionChange2"
                :data="tableData2"
                :icore-filter-flag="icoreFilterFlag"
                @row-dblclick="showCell"
                @row-click="filterMat"
                :row-class-name="tableRowName"
                :header-cell-style="tableHeaderCellStyle"
                :summary-method="getSummaries"
                show-summary
              >
                <el-table-column
                  type="index"
                  label="NO"
                  fixed="left"
                  align="center"
                ></el-table-column>
                <el-table-column
                  type="selection"
                  width="55"
                  fixed="left"
                  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="deptName"
                  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="160px"
                  prop="suppNames"
                  label="供应商"
                  align="center"
                >
                  <template slot-scope="{ row }">
                    <el-select
                      v-model="row.suppNames"
                      clearable
                      multiple
                      style="width: 100%"
                      filterable
                      collapse-tags
                      size="small"
                      @change="(val) => suppChange(val, row)"
                    >
                      <el-option
                        v-for="(item, index) in suppNameList"
                        :key="index"
                        :value="item.suppName"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="randomNum"
                  label="抽查个数"
                  align="center"
                >
                  <template slot-scope="{ row }">
                    <el-input
                      type="text"
                      size="mini"
                      v-model="row.randomNum"
                    ></el-input>
                  </template>
                </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="[10, 20, 50, 100, 200]"
                :page-size="page2.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page2.totalPage"
                background
              >
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="14">
        <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>
        <div class="mat_wrap_xb">
          <!-- <el-button
            size="mini"
            type="goon"
            icon="el-icon-check"
            @click="editMatName"
            >修改物料</el-button
          >
          <el-button
            size="mini"
            type="goon"
            icon="el-icon-check"
            :loading="addPlanLaoding"
            @click="addPlan"
            >追加</el-button
          >
          <el-button
            icon="el-icon-circle-close"
            type="danger"
            size="mini"
            :loading="cancelLaoding"
            v-privilege="activeMenu + 'cancel'"
            @click="cancel"
            >取消</el-button
          > -->

          <el-form :inline="true" class="form_wrap_xb">
            <el-form-item label="抽查日期">
              <el-date-picker
                v-model="checkDate1"
                type="datetime"
                style="width: 140px"
                size="small"
                placeholder="请选择抽查日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                default-time="00:00:00"
              ></el-date-picker>
              <el-date-picker
                v-model="checkDate2"
                type="datetime"
                style="width: 140px"
                size="small"
                placeholder="请选择抽查日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                default-time="23:59:59"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="物料名称">
              <el-input
                type="text"
                size="mini"
                v-model="search.matName"
                clearable
              ></el-input>
            </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>
        <div class="common-table-div">
          <el-table
            v-loading="tableLoading3"
            ref="dataTable3"
            border
            :height="bHeight"
            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"
              fixed="left"
              align="center"
            ></el-table-column>
            <el-table-column
              type="selection"
              align="center"
              width="55"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="160px"
              prop="entrId"
              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="120px"
              prop="sampleNoOld"
              label="老样品编号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100px"
              prop="sampleNo"
              label="样品编号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100px"
              prop="strName"
              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="160px"
              prop="suppName"
              label="供货单位"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100px"
              prop="sampleNoZx"
              label="中心级样号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100px"
              prop="sampleNoGs"
              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>
        </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>
  </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 {
      addLoading2: false,
      createTime: '',
      ruleTypeNameType: [],
      matNameType: [],
      ruleTypeName: [],
      tableLoading2: false,
      tableLoading3: false,
      allotLoading: false,
      cancelLaoding: false,
      allotData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      selection1: [],
      selection5: [],
      selection2: [],
      classesCode: '483501',
      dataLoading: false,
      icoreFilterFlag: true,
      dialogTableVisible: false,
      dialogTableVisible2: false,
      form: { typeNo: '', matName: '' },
      classesType: [],
      startDate: '',
      wgoDate: '',
      search: {
        startDate: [],
        deptNo: '',
        wgoDate: [],
        sectionNo: '',
        wrkGrpCode: '',
        matName: ''
      },
      wrkGrpClass: [],
      rules: {
        ruleTypeNo: [{ required: true, message: '不能为空', trigger: 'change' }],
        ruleNo: [{ required: true, message: '不能为空', trigger: 'change' }],
      },
      clickAllot: [],
      allotBLoading: false,
      modeAllotBLoading: false,
      allocationLoading: false,
      allotIndex: 1,
      allotPage: 100,
      allotTotal: 0,
      wgoData: {},
      clickData: [],
      itemType: [],
      savaSampleValue: 'R0046',
      topheight: 0,
      bHeight: 0,
      tabClickIndex: null,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      dialogTableVisible3: false,
      editData: { matNameNo: [] },
      page2: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page3: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      addPlanLaoding: false,
      clearFlag: true,
      companyNameType: [],
      sectionNameType: [],
      sectionClass: [],
      multipleSelection3: [],
      multipleSelection4: [],
      multipleSelection5: [],
      activeMenu: '',
      allList: [],
      nowMatList: [], // 已分配的物资编码list
      currentRow: null, // 当前行
      searchFlag: true,
      matDataList: [], // 已分配的物资数据列表
      editNameList: [], // 修改物料窗口已经分配的物资数据列表
      selectSuppNameList: [], // 选中客商名称
      selectSuppNoList: [], // 选中客商编码
      suppNameList: [],
      checkDate1: '',
      checkDate2: '',
      typeList: []
    }
  },
  created () {
    this.createTime = this.wgoDate = this.getYNM(new Date())
    this.topheight = window.innerHeight / 2 < 249 ? 249 : window.innerHeight / 2 - 115;
    this.topheight = this.topheight < 249 ? 249 : this.topheight
    this.bHeight = this.topheight * 2 + 50
    console.log(this.topheight, this.topheight, 'height');
    this.search.wgoDate = [this.getYNM(new Date(new Date().setHours(-24))), this.getYNM(new Date())]
    this.startDate = formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00'
    this.wgoDate = formatDate(new Date(), 'yyyy-MM-dd') + ' 23:59:59'
    this.checkDate1 = formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00';
    this.checkDate2 = formatDate(new Date(), 'yyyy-MM-dd') + ' 23:59:59';
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  async mounted () {
    // //获取公司
    // this.axios.post("pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll", {}, { individualType: 'json' }).then(response => {
    //   this.companyNameType = response.data
    //   this.selectDepartment('F31300000')
    //   this.clearFlag = false
    //   this.selectClass('P31302800')
    //   this.clearFlag = true
    // });
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4838 }, { individualType: 'json' }).then(res => {
      this.ruleTypeNameType = res.data;
      this.filterData('483811')
    })
    // 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/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4835 }, { individualType: 'json' }).then(res => {
    //   this.classesType = res.data;
    // })
    // 物料信息
    // await this.axios.post("pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage", { object: { validFlag: 1, matClassNo: "" }, pageIndex: 1, pageSize: 50 }, { individualType: 'json' }).then(res => {
    //   this.matNameType = [...res.data.list];
    // })
    this.searchData()
    this.addScreen();
    this.addScreen2();
    this.addScreen3();
    this.getTypeData();
  },
  methods: {
    getCode (code, arr, codeKey, nameKey) {
      if (!code) {
        return '';
      }
      let targetRow = arr.find(item => {
        return item[codeKey] === code;
      });
      return targetRow ? targetRow[nameKey] : '';
    },
    selectDepartment (val) {
      this.companyNameType.find(item => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList
        }
      })
    },
    // 获取文件类别数据
    getTypeData () {
      this.axios
        .get(
          "pass/baseManagement/v1/limsbaseinfos/like/?pageNum=1&pageSize=50&baseCode=4801",
          {},
          { individualType: "json" }
        )
        .then((response) => {
          if (response.data.list && response.data.list.length > 0) {
            console.log(response)
            this.typeList = response.data.list.filter(item => item.baseCode != '4801');
          }
        });
    },
    //根据选中的部门名称，查询班组名称
    selectClass (val) {
      this.sectionClass = []
      this.sectionNameType.find(item => {
        if (val === item.orgCode) {
          this.sectionClass = item.sysOrgList
          this.clearFlag ? this.search.sectionNo = '' : ''
        }
      })
    },
    clearData () {
      this.search.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}`;
    },
    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;
    },
    //筛选出规则名称
    filterData (val) {
      this.ruleTypeName = []
      if (!val) {
        this.ruleTypeName = []
        return
      }
      let obj = {
        object: {
          ruleTypeCode: val,
          // ruleVer: '外检车间',
          validFlag: 1
        },
        pageIndex: 1,
        pageSize: 9999
      }
      this.axios.post('pass/baseManagement/v1/limsbaserules/queryLimsBaseRuleInfoPage', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.ruleTypeName = res.data.list
        } else {
          this.$message.error(res.message);
        }
      }).catch(err => {
        this.$message.error(err.message);
      })
    },
    closeEditDialog () {
      // 关闭修改物料弹窗的时候清空已分配物料数据
      this.editNameList = []
      this.editData = { matNameNo: [] }
      this.addLoading2 = false
      this.dialogTableVisible3 = false
    }
    , cancelData2 () {
      this.form = {
        empNo: '',
        empName: ''
      },
        this.dialogTableVisible2 = false
    },
    //勾选人员表格数据
    handleAllot (val) {
      this.clickAllot = val;
    },
    allocation () {
      if (this.clickAllot.length < 1) {
        this.$message.warning('请勾选人员数据')
        return
      }
      this.allocationLoading = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/composeType', this.clickAllot, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message);
          this.dialogTableVisible = false
          this.searchData()
        } else {
          this.$message.error(res.message);
        }
        this.allocationLoading = false
      }).catch(err => {
        this.allocationLoading = false
        this.$message.error(err.message);
      })
    },
    tableRowName ({ row, rowIndex }) {
      row.index = rowIndex
    },
    showCell (row) {
      this.tabClickIndex = row.index
    },
    saveCell (row) {
      row.ruleItemValue = row.ruleItemValue ? row.ruleItemValue : '0'
      this.tabClickIndex = null
    },
    // 查询
    searchData () {
      this.page.pageNum = 1;
      this.page.pageSize = 50;
      this.page2.pageNum = 1
      this.page2.pageSize = 50
      this.page3.pageNum = 1
      this.page3.pageSize = 50
      this.getAllotData()
    },
    // timeChange () {
    //   this.getAllotData()
    // },
    firstData () {
      this.tableData2 = []
      let obj = {
        object: {
          matName: this.form.matName,
          sampleTypeCode: this.form.typeNo
        },
        startTime: this.startDate,
        endTime: this.wgoDate,
        'pageIndex': this.page2.pageNum,
        'pageSize': this.page2.pageSize
      }
      this.tableLoading2 = true
      this.axios.post('pass/testManagement/v1//limstestchecks/querySampleInfoByTime', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData2 = res.data.list;
          // 为每一项添加默认物资下拉框
          this.tableData2.forEach(item => {
            item.suppNames
            item.maxValue = item.ruleItemValue
            item.isAutoName = item.isAuto == 0 ? '否' : item.isAuto == 1 ? '是' : ''
            // item.matList = [...this.matNameType]
            // item.useIndex = 1
          })
          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)
      });
    },
    //查询任务分配信息表
    getAllotData () {
      let obj = {
        'object': {
          matName: this.search.matName
        },
        'startTime': this.checkDate1,
        'endTime': this.checkDate2,
        'pageIndex': this.page3.pageNum,
        'pageSize': this.page3.pageSize
      }
      this.tableLoading3 = true;
      this.axios.post('pass/testManagement/v1/limstestchecks/queryLimsTestCheckPage', obj, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data.list
          this.page3.totalPage = res.data.total
          // this.tableData3.forEach(item => {
          //   item.validFlagName = item.validFlag == 1 ? '有效' : item.validFlag == 0 ? '无效' : ''
          //   item.wrkOrdName = this.getCode(item.wrkOrdCode, this.classesType, 'baseCode', 'baseName')
          //   // let NameType = []
          //   // let arr = item.matNo ? item.matNo.split(',') : []
          //   // NameType = [...arr.map(item=> this.getCode(item,this.matNameType,'matNo','matName'))]
          //   // item.matName = NameType.join()
          // })
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading3 = false;
      }).catch(e => {
        this.tableLoading3 = false;
      });
    },
    editMatName () {
      if (this.clickData.length != 1) {
        this.$message.warning('请先勾选一条且只能勾选一条要修改的数据')
        return
      }
      let dataList = []
      this.editData = Object.assign(this.editData, this.clickData[0])
      let noList = this.clickData[0].matNo ? this.clickData[0].matNo.split(',') : []
      let nameList = this.clickData[0].matName ? this.clickData[0].matName.split(',') : []
      for (let y = 0; y < nameList.length; y++) {
        dataList.push({ matName: nameList[y], matNo: noList[y] })
      }
      this.editData.matNameNo = noList;
      this.dialogTableVisible3 = true;
      this.editNameList = [...new Set(dataList)]
      this.editNameList.forEach(item => {
        let index = this.matNameType.findIndex(i => i.matNo === item.matNo)
        if (index === -1) {
          this.matNameType.push(item)
        }
      })
    },
    addData2 () {
      this.editData.matNo = this.editData.matNameNo.length > 0 ? this.editData.matNameNo.join() : ''
      let NameType = []
      NameType = [...this.editData.matNameNo.map(items => this.getCode(items, this.matNameType, 'matNo', 'matName'))]
      this.editData.matName = NameType.join()
      this.addLoading2 = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/update', this.editData, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.getAllotData()
          this.dialogTableVisible3 = false
        } else {
          this.$message.error(res.message)
        }
        this.addLoading2 = false
      }).catch(e => {
        this.addLoading2 = false
        this.$message.error(e.message)
      });
    },
    addPlan () {
      if (this.clickData.length < 1) {
        this.$message.warning('请先勾选要取消的数据')
        return
      }
      this.addPlanLaoding = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/addOptNoToTaskTest', this.clickData, { 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.addPlanLaoding = false
      }).catch(e => {
        this.addPlanLaoding = false
        this.$message.error(e.message)
      });
    },
    //取消
    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()
        } else {
          this.$message.error(res.message)
        }
        this.cancelLaoding = false
      }).catch(e => {
        this.cancelLaoding = false
        this.$message.error(e.message)
      });
    },
    allot () {
      if (this.selection2.length <= 0) {
        this.$message.warning("请先勾选任务信息数据");
        return;
      }
      this.selection2.forEach(item => {
        item.startTime = this.startDate
        item.endTime = this.wgoDate
        item.wgoDate = this.wgoDate ? this.wgoDate : ''
        // item.suppNames = [...this.selectSuppNameList]
        // item.suppNos = [...this.selectSuppNoList]
      })
      this.allotBLoading = true
      this.axios.post('pass/testManagement/v1/limstestchecks/getSampleInfoByExtract/', [...this.selection2], { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
          this.firstData()
        } else {
          this.$message.error(res.message)
        }
        this.allotBLoading = false
      }).catch(e => {
        this.allotBLoading = false
        this.$message.error(e.message)
      });
    },
    //手动分配
    modeAllot () {
      if (this.selection5.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.selection5.length != num) {
        this.$message.warning('任务数量与人员数量不相等，请选择对应的人数')
        return
      }
      let time = this.getCode(this.classesCode, this.classesType, 'baseCode', 'memo').split('-') || []
      this.selection2[0].startTime = this.startDate
      this.selection2[0].endTime = this.wgoDate
      this.selection2[0].wgoDate = this.wgoDate ? this.wgoDate : ''
      // this.selection2[0].wrkOrdCode = this.classesCode
      this.selection2[0].matNo = this.selection2[0].matNameNo.join()
      let NameType = []
      NameType = [...this.selection2[0].matNameNo.map(items => this.getCode(items, this.matNameType, 'matNo', 'matName'))]
      this.selection2[0].matName = NameType.join()
      this.modeAllotBLoading = true
      this.axios.post('pass/testManagement/v1/limsempwrkords/allocation/', { llp: this.selection5, llo: this.selection2 }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.cancelData2()
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
        this.modeAllotBLoading = false
      }).catch(e => {
        this.modeAllotBLoading = false
        this.$message.error(e.message)
      });
    },
    //点击选中任务分配信息表
    selectData (row) {
      this.clickData = row
    },
    // 重置
    reset () {
      this.search.deptNo = ''
      this.search.sectionNo = ''
      this.search.wrkGrpCode = ''
      this.searchData();
    },
    dataAllot () {
      this.clickAllot = {}
      this.allotLoading = true
      let obj = {
        object: {
          empNo: this.form.empNo,
          empName: this.form.empName,
          validFlag: 1
        },
        pageIndex: this.allotIndex,
        pageSize: this.allotPage
      }
      this.axios.post('pass/baseManagement/v1/limslrcempwrkgrps/queryLimsLrcEmpWrkgrpPage', 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);
      })
    },
    dataAllot2 () {
      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);
      })
    },
    pageSizeChange2 (size) {
      this.page2.pageNum = 1
      this.page2.pageSize = size;
      this.firstData()
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.firstData()
    },
    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;
    }, handleSelectionChange5 (val) {
      this.selection5 = val;
    },
    addScreen () {
      this.$nextTick(() => {
        let ss = document.createElement('div');
        ss.innerHTML = '筛选';
        ss.style = 'text-align: center;'
        if (this.$refs.dataTable) {
          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;'
        if (this.$refs.dataTable2) {
          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;'
    },
    // 物料改变
    matChange (val, row) {
      try {
        if (val) {
          val.forEach(i => {
            let item = this.matNameType.find(item => item.matNo === i)
            if (item) {
              let index = this.selectMatList.findIndex(iten => iten.matNo === i)
              if (index === -1) {
                this.selectMatList.push({ matNo: i, matName: item.matName })
              }
            }
          })
        }
      } catch (e) {
        console.log(e)
      }
    },
    // 供应商改变
    suppChange (val, row) {
      this.selectSuppNoList = []
      try {
        if (val) {
          val.forEach(i => {
            let oitem = this.suppNameList.find(item => item.suppName === i)
            if (oitem) {
              this.selectSuppNoList.push(oitem.suppNo)
            }
          })
          this.selectSuppNameList = [...val]
          this.$forceUpdate()
        }
      } catch (e) {
        console.log(e)
      }
    },
    // 过滤物料选择项
    async filterMat (row) {
      // 将物料列表设置为前200条
      if (!row) {
        return true;
      }
      let matList = []
      // 获取客商数据
      await this.axios.post('pass/testManagement/v1//limstestchecks/querySuppNameBySampleInfo', { ...row, startTime: this.startDate, endTime: this.wgoDate, suppNames: '', suppNos: '' }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          if (res.data.length > 0 && res.data[0]) {
            this.suppNameList = [...res.data]
            this.suppNameList.forEach(item => {
              if (item.suppName) {
                matList.push(item.suppName)
              }
            })
          } else {
            this.suppNameList = []
          }
          row.suppNames = [...matList]
        } else {
          this.$message.error(res.message)
        }
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    // 物料名称筛选
    async matFilter (val, row) {
      // 如果当前下拉框所在行和之前记录的不是同一行，则清空已分配物资编码列表和物资列表
      if (row.index !== this.currentRow) {
        this.nowMatList = [];
        this.matDataList = [];
      }
      let searchStr = ''
      if (val) {
        searchStr = val
      }
      // 输入值不为空则查询
      this.searchFlag = false
      // 根据输入结果进行远端搜索
      const { data: res } = await this.axios.post("pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage", { object: { validFlag: 1, matName: searchStr, matClassNo: '' }, pageIndex: 1, pageSize: 50 }, { individualType: 'json' })
      this.matNameType = [...res.list]
      // 拼接已经分配的几种物资
      this.matDataList.forEach(item => {
        let index = this.matNameType.findIndex(i => i.matNo === item.matNo)
        if (index === -1) {
          this.matNameType.push(item)
        }
      })
      // 加入已经选中的几种物料
      this.selectMatList.forEach(item => {
        let index = this.matNameType.findIndex(i => i.matNo === item.matNo)
        if (index === -1) {
          this.matNameType.push(item)
        }
      })
    },
    // 修改窗口物料名称筛选
    async matFilter1 (val, row) {
      let searchStr = ''
      if (val) {
        searchStr = val
      }
      // 根据输入内容查询物资数据列表
      const { data: res } = await this.axios.post("pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage", { object: { validFlag: 1, matName: searchStr, matClassNo: '' }, pageIndex: 1, pageSize: 50 }, { individualType: 'json' })
      this.matNameType = [...res.list]
      // 拼接已经分配的几种物资(去重)
      this.editNameList.forEach(item => {
        let index = this.matNameType.findIndex(i => i.matNo === item.matNo)
        if (index === -1) {
          this.matNameType.push(item)
        }
      })
      // 加入已经选中的几种物料
      this.selectMatList.forEach(item => {
        let index = this.matNameType.findIndex(i => i.matNo === item.matNo)
        if (index === -1) {
          this.matNameType.push(item)
        }
      })
    },
    matAdd (nameList, matList, index) {
      nameList.forEach(item => {
        let iItem = this.allList.find(u => u.matNo.trim() === item)
        if (iItem) {
          if (matList.findIndex(i => i.matNo === item) === -1) {
            matList.push(iItem)
          }
        }
      })
      this.tableData2[index]
    }
  }
}
</script>
<style>
.form_wrap_xb .el-input__inner {
  padding: 5px !important;
}

.form_wrap_xb .el-icon-time {
  display: none;
}

.form_wrap_xb .el-form-item {
  margin: 15px 3px 0px 15px !important;
}

.mat_wrap_xb {
  margin: 15px 3px 0px 15px !important;
}
</style>
