<!-- 任务分配(原料)页面 -->
<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 style="width: 100%" collapse-tags @clear="clearSelect"
            @change="selectClass" size="small">
            <el-option v-for="item in sectionNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验班组">
          <el-select v-model="search.sectionNo" filterable clearable style="width: 100%" collapse-tags
            @change="selectSection" size="small">
            <el-option v-for="item in sectionClassType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岗位">
          <el-select v-model="search.jobs" clearable style="width: 100%" filterable collapse-tags size="small">
            <el-option v-for="(item, index) in postType" :key="index" :label="item.postName" :value="item.postNo">
            </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: 200px"></el-input>-->
        <!--        </el-form-item>-->
        <el-form-item label="任务日期">
          <el-date-picker v-model="search.entrTime[0]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="开始日期" size="mini" style="width: 140px">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="search.entrTime[1]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="结束日期" size="mini" style="width: 140px">
          </el-date-picker>
          <!-- <el-date-picker
            v-model="search.entrTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="small"
            style="width: 300px"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker> -->
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" :disable="disSearch"
            @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" :disable="disSearch"
            @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-row>
        <el-col :span="4">
          <div class="common-title-name">
            <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
            物料名称
          </div>
          <div class="common-table-div">
            <el-table ref="tableMain11" :height="theight1" v-loading="tableLoading11" :data="tableData11"
              highlight-current-row @row-click="handleCurrentChange" :header-cell-style="tableHeaderCellStyle"
              :summary-method="getSummaries11" show-summary border style="width: 100%" :icorePanelShown="100"
              :icore-filter-flag="icoreFilterFlag">
              <el-table-column sortable show-overflow-tooltip align="center" min-width="100" prop="MAT_NAME"
                label="物料名称"></el-table-column>
            </el-table>
          </div>
        </el-col>
        <el-col :span="20">
          <el-tabs type="border-card" v-model="activeName">
            <el-tab-pane label="任务未分配" name="first">
              <span slot="label">任务未分配<el-badge :max="10" :hidden="total == 0" style="margin-top: -18px"
                  :value="total"></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>
                  <el-button icon="el-icon-check" type="goon" size="mini" v-privilege="activeMenu + 'distribution'"
                    @click="checkAllot">分配</el-button>
                  <el-button icon="el-icon-check" type="goon" size="mini" :loading="recipientsLoading"
                    v-privilege="activeMenu + 'recipients'" @click="recipients">领用</el-button>
                  <!--          <el-button icon="el-icon-circle-close" :loading="buttonLoading1" type="danger" size="mini" v-privilege="activeMenu + 'disable'" @click="deleteData">停用</el-button>-->
                  <!--          <el-button icon="el-icon-check" :loading="buttonLoading2" type="goon" size="mini" v-privilege="activeMenu + 'effectivity'"  @click="recoverData">启用</el-button>-->
                </div>
              </div>
              <div class="common-table-div">
                <el-table v-loading="tableLoading1" ref="dataTable" border :height="tableTop" highlight-current-row
                  @selection-change="handleSelectionChange" :data="tableData1" :row-class-name="tableRowClassName"
                  :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
                  :summary-method="getSummaries2" 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 :show-overflow-tooltip="true" sortable min-width="150px" prop="typeName" label="中心编号"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="150px" prop="carNo" label="委托编号"
                    align="center"></el-table-column>
                  <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="tkId" 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='matOrder' label="物料顺序"></el-table-column> -->
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="testItemName"
                    label="任务名称"></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="validFlagName"
                    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="100px" prop="stdName" label="标准号" align="center"></el-table-column> -->
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="testLimit"
                    label="任务时限" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="taskDate" label="任务日期"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="receivedDate"
                    label="收样日期" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="testPostName"
                    label="岗位名称" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="eqpTypeName"
                    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="pageSizeChange" @current-change="pageCurrentChange"
                  :current-page="pageIndex" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper" :total="total" background>
                </el-pagination>
              </div>
            </el-tab-pane>
            <el-tab-pane label="任务已分配" name="second">
              <span slot="label">任务已分配<el-badge :max="10" :hidden="totalDep == 0" style="margin-top: -18px"
                  :value="totalDep"></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>
                  <el-button icon="el-icon-circle-close" type="danger" :loading="buttonLoading3" size="mini"
                    v-privilege="activeMenu + 'Unassign'" @click="cancel">取消分配</el-button>
                </div>
              </div>
              <div class="common-table-div">
                <el-table v-loading="tableLoading2" ref="dataTable2" border :height="tableBot" highlight-current-row
                  @selection-change="handleSelectionChange2" :data="tableData2" :row-class-name="tableRowClassName2"
                  :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
                  :summary-method="getSummaries2" 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="80px" prop="carNo" label="委托编号"
                    align="center"></el-table-column>
                  <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="typeName" label="中心编号"
                    align="center"></el-table-column>
                  <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="id" label="任务编号" align="center"></el-table-column> -->
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="taskDate" label="任务日期"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="receivedDate"
                    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='matOrder' label="物料顺序"></el-table-column> -->
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="testItemName"
                    label="任务名称" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="itemTypeName"
                    label="任务类型" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="optName" label="执行人"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="stdName" label="标准号"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="pointName" label="地点"
                    align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="testLimit"
                    label="任务时限" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="testPostName"
                    label="岗位" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="eqpTypeName"
                    label="设备" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" 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="80px" prop="validFlagName"
                    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="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="pageIndex_dep" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="pageSize_dep"
                  layout="total, sizes, prev, pager, next, jumper" :total="totalDep" background>
                </el-pagination>
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
    <el-dialog @close="closeDialog" :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-form :inline="true" @submit.native.prevent>
        <el-form-item label="人员编号">
          <el-input v-model="form.empNo" size="small" @keyup.enter.native="searchAllot()" placeholder="请输入搜索条件"
            style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="人员名称">
          <el-input v-model="form.empName" size="small" @keyup.enter.native="searchAllot()" placeholder="请输入搜索条件"
            style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" @click="searchAllot" size="mini">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="allotLoading" ref="dataTable" border height="300" highlight-current-row
        @row-click="handleAllot" :data="allotData" :icore-filter-flag="icoreFilterFlag"
        :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries2" show-summary>
        <el-table-column type="index" label="NO" 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="80px" prop="empName" label="人员姓名"
          align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="deptName" label="部门"
          align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="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" @click="allocation()">确定</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, formatDate, isStartEndDate } from "@/utils/util.js";
import { cookieUserId, cookieUserName } from "@/config/config.js";
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data() {
    return {
      icoreFilterFlag: true,
      dialogTableVisible: false,
      activeName: "first",
      taskId: "",
      theight1: 0,
      tableLoading11: false,
      tableData11: [],
      testItemNo: "",
      form: {
        empNo: "",
        empName: "",
      },
      jobType: [],
      allotIndex: 1,
      allotPage: 500,
      allotTotal: 0,
      classNo: "",
      deptNo: "",
      sectionNo: "",
      allotLoading: false,
      search: {
        mode: "",
        deptNo: "",
        sectionNo: "",
        entrTime: [],
        itemTypeName: "",
        jobs: "",
      },
      matMatName: "", //物料表点击的物料
      sectionNameType: [],
      sectionClassType: [],
      postType: [],
      companyNameType: [],
      disSearch: false,
      allotData: [],
      clickAllot: {},
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableLoading1: false,
      tableLoading2: false,
      tableLoading3: false,
      recipientsLoading: false,
      buttonLoading1: false,
      buttonLoading2: false,
      buttonLoading3: false,
      buttonLoading4: false,
      itemType: [],
      selectMain: [],
      selectDep: [],
      tableTop: 0,
      tableBot: 0,
      pageIndex: 1,
      pageSize: 500,
      total: 0,
      pageIndex_dep: 1,
      pageSize_dep: 500,
      totalDep: 0,
      activeMenu: "",
    };
  },
  created() {
    this.theight1 = window.innerHeight - 165;
    this.tableTop = window.innerHeight - 230;
    this.tableBot = window.innerHeight - 230;
    this.search.entrTime = [this.getYNM(new Date()), this.getYNM(new Date())];
    this.activeMenu = window.top.localStorage.getItem("activeMenu");
    this.axios
      .post(
        "pass/baseManagement/v1/limsbaseposts/queryLimsBasePostList",
        {},
        { individualType: "json" }
      )
      .then((res) => {
        this.jobType = res.data;
      });
    this.axios
      .post(
        "pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",
        {},
        { individualType: "json" }
      )
      .then((response) => {
        this.companyNameType = response.data;
        // this.getCompany()
        this.selectDepartment("JCZX");
      });
  },
  mounted() {
    this.searchAllot();
    this.addScreen();
    this.addScreen2();
  },
  methods: {
    getYNM(date) {
      let year = date.getFullYear().toString();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      return `${year}-${month}-${day}`;
    },
    getSummaries2(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } else if (column.property === "quantity") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].quantity ? data[i].quantity : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "factweight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].factweight ? data[i].factweight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    selectDepartment(val) {
      this.sectionNameType = [];
      this.companyNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList;
        }
      });
    },
    clearSelect() {
      this.search.sectionNo = "";
      this.search.jobs = "";
      this.postType = "";
    },
    //根据选中的部门名称，查询班组名称
    selectClass(val) {
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
          this.search.sectionNo = "";
        }
      });
    },
    //根据选中的部门名称，查询班组名称
    selectClass2(val) {
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
        }
      });
    },
    selectPost(val) {
      this.postType = [];
      this.jobType.forEach((item) => {
        if (val === item.sectionNo) {
          this.postType.push(item);
        }
      });
    },
    selectSection(val) {
      this.search.jobs = "";
      this.selectPost(val);
    },
    closeDialog() {
      this.clickAllot = {};
      this.form = {
        empNo: "",
        empName: "",
      };
      this.searchAllot();
    },
    cancelData() {
      this.clickAllot = {};
      (this.form = {
        empNo: "",
        empName: "",
      }),
        this.searchAllot();
      this.dialogTableVisible = false;
    },
    searchAllot() {
      this.allotIndex = 1;
      this.allotPage = 500;
      this.dataAllot();
    },
    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/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);
        });
    },
    checkAllot() {
      if (this.selectMain.length < 1) {
        this.$message.warning("请勾选您要分配的数据");
        return;
      }
      for (let item of this.selectMain) {
        if (item.validFlag == 0) {
          this.$message.warning("已停用的数据不可进行分配");
          return;
        }
      }
      this.dialogTableVisible = true;
    },
    //获取个人所属哪个公司
    getCompany() {
      this.axios
        .get("pass/baseManagement/v1/limslrcemps/" + userId)
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.search.deptNo = res.data ? res.data.deptNo : "";
            this.search.sectionNo = res.data ? res.data.sectionNo : "";
            this.search.jobs = res.data ? res.data.postNo : "";
            // this.classNo = res.data ? res.data.postNo : ''
            // this.deptNo = res.data ? res.data.deptNo : ''
            // this.sectionNo = res.data ? res.data.sectionNo : ''
            this.selectClass2(this.search.deptNo);
            this.selectPost(this.search.sectionNo);
            this.searchData();
          } else {
            this.disSearch = true;
            this.$message.error(e.message);
          }
        })
        .catch((e) => {
          this.disSearch = true;
          this.$message.error(e.message);
        });
    },
    ///分配
    allocation() {
      if (JSON.stringify(this.clickAllot) === "{}") {
        this.$message.warning("请先点击选中一条数据");
        return;
      }
      let newList = [];
      newList = JSON.parse(JSON.stringify(this.selectMain));
      newList.forEach((item) => {
        (item.optNo = this.clickAllot.empNo),
          (item.optName = this.clickAllot.empName),
          (item.deptNo = this.clickAllot.deptNo),
          (item.deptName = this.clickAllot.deptName),
          (item.sectionNo = this.clickAllot.sectionNo),
          (item.sectionName = this.clickAllot.sectionName);
      });
      this.axios
        .post("pass/testManagement/v1/limstasktests/assign", newList, {
          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);
          }
        })
        .catch((err) => {
          this.$message.error(err.message);
        });
    },
    //领用
    recipients() {
      if (this.selectMain.length < 1) {
        this.$message.warning("请勾选您要领用的数据");
        return;
      }
      for (let item of this.selectMain) {
        if (item.validFlag == 0) {
          this.$message.warning("已停用的数据不可进行领用");
          return;
        }
      }
      let newList = [];
      newList = JSON.parse(JSON.stringify(this.selectMain));
      this.recipientsLoading = true;
      this.axios
        .post("pass/testManagement/v1/limstasktests/assign", newList, {
          individualType: "json",
        })
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.$message.success(res.message);
            this.dataMain(this.matMatName);
            this.dataDep(this.matMatName);
            // this.searchData()
          } else {
            this.$message.error(res.message);
          }
          this.recipientsLoading = false;
        })
        .catch((err) => {
          this.recipientsLoading = false;
          this.$message.error(err.message);
        });
    },
    // 终止
    deleteData() {
      if (this.selectMain.length < 1) {
        this.$message.warning("请勾选您要停用的数据");
        return;
      }
      this.buttonLoading1 = true;
      this.axios
        .post("pass/testManagement/v1/limstasktests/abolish", this.selectMain, {
          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.buttonLoading1 = false;
        })
        .catch((err) => {
          this.buttonLoading1 = false;
          this.$message.error(err.message);
        });
    },
    // 恢复
    recoverData() {
      if (this.selectMain.length < 1) {
        this.$message.warning("请勾选您要启用的数据");
        return;
      }
      this.buttonLoading2 = true;
      this.axios
        .post("pass/testManagement/v1/limstasktests/recover", this.selectMain, {
          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.buttonLoading2 = false;
        })
        .catch((err) => {
          this.buttonLoading2 = false;
          this.$message.error(err.message);
        });
    },
    // TODO 查询物料
    searchData() {
      this.queryTaskMaterials();
    },
    queryTaskMaterials() {
      this.tableLoading11 = true;
      let startTime = "";
      let endTime = "";
      if (!this.search.entrTime) {
        startTime = "";
        endTime = "";
      } else {
        startTime = this.search.entrTime[0] + " 00:00:00";
        endTime = this.search.entrTime[1] + " 23:59:59";
      }
      let params = {
        startTime: startTime,
        endTime: endTime,
        stateFlags: [0],
        sampleTypeCode: "480101",
        deptNo: this.search.deptNo,
        sectionNo: this.search.sectionNo,
        jobs: this.search.jobs,
        matName: this.search.matName,
        optNo: userId,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstasktests/queryTaskMaterials",
          params,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.tableData11 = res.data;
          } else {
            this.$message.error(res.message);
          }
          this.tableLoading11 = false;
        })
        .catch((e) => {
          this.tableLoading11 = false;
          this.$message.error(e.message);
        });
    },
    dataMain(matName) {
      this.tableLoading1 = true;
      let startTime = "";
      let endTime = "";
      if (!this.search.entrTime) {
        startTime = "";
        endTime = "";
      } else {
        startTime = this.search.entrTime[0] + " 00:00:00";
        endTime = this.search.entrTime[1] + " 23:59:59";
      }
      let tempobj = {
        object: {
          itemTypeName: this.search.itemTypeName,
          stateFlag: 0,
          sampleTypeCode: 480101,
        },
        mode3: matName,
        mode4: this.search.deptNo ? this.search.deptNo : this.deptNo,
        list: this.search.sectionNo
          ? [this.search.sectionNo]
          : this.sectionNo
            ? [this.sectionNo]
            : [],
        mode: this.search.jobs ? this.search.jobs : this.classNo,
        pageIndex: this.pageIndex,
        pageSize: this.pageSize,
        startTime: startTime,
        endTime: endTime,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstasktests/queryLimsTaskTestPage",
          tempobj,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.tableData1 = res.data.list;
            this.total = res.data.total;
            this.tableData1.forEach((item) => {
              item.typeName =
                item.itemTypeCode == "480402" ? item.markNo : item.sampleNo;
              item.validFlagName =
                item.validFlag == 0
                  ? "无效"
                  : item.validFlag == 1
                    ? "有效"
                    : "";
              item.stateFlagName =
                item.stateFlag == 0
                  ? "未分配"
                  : item.stateFlag == 1
                    ? "已分配"
                    : "";
              item.isAutoName =
                item.isAuto == 0 ? "手动" : item.isAuto == 1 ? "自动" : "";
            });
          } else {
            this.$message.error(res.message);
          }
          this.tableLoading1 = false;
        })
        .catch((e) => {
          this.tableLoading1 = false;
          this.$message.error(e.message);
        });
    },
    dataDep(matName) {
      this.tableLoading2 = true;
      let startTime = "";
      let endTime = "";
      if (!this.search.entrTime) {
        startTime = "";
        endTime = "";
      } else {
        startTime = this.search.entrTime[0] + " 00:00:00";
        endTime = this.search.entrTime[1] + " 23:59:59";
      }
      let tempobj = {
        object: {
          itemTypeName: this.search.itemTypeName,
          stateFlag: 1,
          sampleTypeCode: 480101,
          optNo: userId,
        },
        mode3: matName,
        mode4: this.search.deptNo ? this.search.deptNo : this.deptNo,
        list: this.search.sectionNo
          ? [this.search.sectionNo]
          : this.sectionNo
            ? [this.sectionNo]
            : [],
        mode: this.search.jobs ? this.search.jobs : this.classNo,
        pageIndex: this.pageIndex_dep,
        pageSize: this.pageSize_dep,
        startTime: startTime,
        endTime: endTime,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstasktests/queryLimsTaskTestPage",
          tempobj,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.tableData2 = res.data.list;
            this.totalDep = res.data.total;
            this.tableData2.forEach((item) => {
              item.typeName =
                item.itemTypeCode == "480402" ? item.markNo : item.sampleNo;
              item.validFlagName =
                item.validFlag == 0
                  ? "无效"
                  : item.validFlag == 1
                    ? "有效"
                    : "";
              item.stateFlagName =
                item.stateFlag == 0
                  ? "未分配"
                  : item.stateFlag == 1
                    ? "已分配"
                    : "";
              item.isAutoName =
                item.isAuto == 0 ? "手动" : item.isAuto == 1 ? "自动" : "";
            });
          } else {
            this.$message.error(res.message);
          }
          this.tableLoading2 = false;
        })
        .catch((e) => {
          this.tableLoading2 = false;
          this.$message.error(e.message);
        });
    },
    // 重置
    reset() {
      this.search.matName = "";
      this.search.jobs = "";
      this.search.deptNo = "";
      this.search.sectionNo = "";
      this.search.entrTime = [this.getYNM(new Date()), this.getYNM(new Date())];
      this.searchData();
    },
    // 取消分配
    cancel() {
      if (this.selectDep.length < 1) {
        this.$message.warning("请勾选需要取消分配的数据");
        return;
      }
      this.buttonLoading3 = true;
      this.axios
        .post("pass/testManagement/v1/limstasktests/unassign", this.selectDep, {
          individualType: "json",
        })
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.$message.success(res.message);
            this.dataMain(this.matMatName);
            this.dataDep(this.matMatName);
            // this.searchData()
          } else {
            this.$message.error(res.message);
          }
          this.buttonLoading3 = false;
        })
        .catch((err) => {
          this.buttonLoading3 = false;
          this.$message.error(err.message);
        });
    },
    pageSizeAllot(size) {
      this.allotIndex = 1;
      this.allotPage = size;
      this.dataAllot();
    },
    pageCurrentAllot(index) {
      this.allotIndex = index;
      this.dataAllot();
    },
    pageSizeChange(size) {
      this.pageIndex = 1;
      this.pageSize = size;
      this.dataMain(this.matMatName);
    },
    pageCurrentChange(index) {
      this.pageIndex = index;
      this.dataMain(this.matMatName);
    },
    pageSizeChange2(size) {
      this.pageIndex_dep = 1;
      this.pageSize_dep = size;
      this.dataDep(this.matMatName);
    },
    pageCurrentChange2(index) {
      this.pageIndex_dep = index;
      this.dataDep(this.matMatName);
    },
    // TODO 点击物料名称
    handleCurrentChange(val) {
      this.matMatName = val.MAT_NAME;
      this.selectMain = [];
      this.pageIndex = 1;
      this.pageSize = 500;
      this.dataMain(val.MAT_NAME);
      this.dataDep(val.MAT_NAME);
    },
    getSummaries11(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计：" + data.length;
        }
      });
      return sums;
    },
    handleSelectionChange(val) {
      this.selectMain = val;
    },
    //勾选人员表格数据
    handleAllot(val) {
      this.clickAllot = Object.assign({}, val);
    },
    handleSelectionChange2(val) {
      this.selectDep = val;
    },
    addScreen() {
      this.$nextTick(() => {
        let ss = document.createElement("div");
        ss.innerHTML = "筛选";
        ss.style = "text-align: center;";
        if (
          this.$refs.dataTable.$el.getElementsByClassName("el-table__fixed")[0]
        ) {
          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.$el.getElementsByClassName("el-table__fixed")[0]
        ) {
          this.$refs.dataTable2.$el
            .getElementsByClassName("el-table__fixed")[0]
            .getElementsByTagName("td")[0]
            .appendChild(ss);
        }
      });
    },
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (row.validFlag !== "1") {
        return "error-row";
      }
    },
    tableRowClassName2({ row, column, rowIndex, columnIndex }) {
      if (row.validFlag !== "1") {
        return "error-row";
      }
      return "";
    },
    // 表格上横线
    tableHeaderCellStyle() {
      return "color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;";
    },
  },
};
</script>
<style scoped></style>
