<template>
  <div class="mod-config">

    <!-- 收藏 -->
    <div>
      <span @click="favoriteFunction()">
        <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
      </span>
    </div>

    <!-- 条件查询 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 75px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'检验单号'">
        <el-input v-model="searchData.inspectionNo" clearable style="width: 140px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料编码'">
        <el-input v-model="searchData.partNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料名称'">
        <el-input v-model="searchData.partDesc" clearable style="width: 230px"></el-input>
      </el-form-item>
      <el-form-item :label="'质检员'">
        <el-input v-model="searchData.inspectorName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.states" multiple style="width: 340px">
          <el-option label="未开始" value="未开始"></el-option>
          <el-option label="待检验" value="待检验"></el-option>
          <el-option label="待审核" value="待审核"></el-option>
          <el-option label="已完成" value="已完成"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList">
      <el-form-item :label="'关联单号1'">
        <el-input v-model="searchData.orderRef1" clearable style="width: 159px"></el-input>
      </el-form-item>
      <el-form-item :label="'关联单号2'">
        <el-input v-model="searchData.orderRef2" clearable style="width: 159px"></el-input>
      </el-form-item>
      <el-form-item :label="'关联单号3'">
        <el-input v-model="searchData.orderRef3" clearable style="width: 159px"></el-input>
      </el-form-item>
      <el-form-item :label="'关联单号4'">
        <el-input v-model="searchData.orderRef4" clearable style="width: 159px"></el-input>
      </el-form-item>
      <el-form-item :label="'关联单号5'">
        <el-input v-model="searchData.orderRef5" clearable style="width: 159px"></el-input>
      </el-form-item>
      <el-form-item :label="'检验结论'">
        <el-select v-model="searchData.inspectionResult" clearable style="width: 80px">
          <el-option label="合格" value="合格"></el-option>
          <el-option label="不合格" value="不合格"></el-option>
          <el-option label="免检" value="免检"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'处置措施'">
        <el-select v-model="searchData.disposalMeasures" clearable style="width: 90px">
          <el-option
            v-for = "i in disposalMeasuresOptions"
            :key = "i.id"
            :label = "i.disposalMeasures"
            :value = "i.disposalMeasures">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList">
      <el-form-item :label="'送检日期'">
        <el-date-picker style="width: 170px" v-model="searchData.startDate2" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 170px" v-model="searchData.endDate2" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item :label="'检验日期'">
        <el-date-picker style="width: 170px" v-model="searchData.startDate" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 170px" v-model="searchData.endDate" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList">查询</el-button>
        <el-button v-if="!authCheck" type="primary" @click="submitResult">审核</el-button>
        <el-button v-if="!authDelete" type="primary" @click="deleteModal">删除</el-button>
        <el-button v-if="!authOverLoad" type="primary" :loading="overLoading" @click="overLoadModal">任务重载</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <!-- 检验记录展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      ref="OQCTable"
      show-summary
      :summary-method="getSummaries"
      :row-style="rowStyle"
      @row-click="FQASClickRow"
      @selection-change="selectionFQAS"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <div :style="{fontWeight:'bold', color: scope.row.state === '待检验' ? 'red' : scope.row.state === '待审核' ? '#ffa500e0' : scope.row.state === '已完成' ? '#3ac252' : ''}">
            {{ scope.row.state }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed===''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <div v-if="item.columnProp === 'inspectionResult' && scope.row.inspectionResult === '不合格' && scope.row.disposalMeasures === '拒收退回'">
            <span v-if="!item.columnHidden" style="color: red"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </div>
          <div v-else>
            <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <el-link style="cursor: pointer" v-if="!authDetail && scope.row.state === '未开始'" @click="actionModal(scope.row)">开始检验</el-link>
          <el-link style="cursor: pointer" v-if="!authDetail && scope.row.state !== '未开始'" @click="detailModal(scope.row)">检验单</el-link>
          <el-dropdown trigger="click">
            <el-link style="cursor: pointer;font-size: 12px">更多</el-link>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="!authFile" @click.native="getFileContentData(scope.row)">工作文件</el-dropdown-item>
              <el-dropdown-item v-if="!authChange && scope.row.state === '待检验'" @click.native="changeInspectionModal(scope.row)">更改检验方式</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页-->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 检验单详情页 -->
    <el-dialog title="检验明细清单" :close-on-click-modal="false" v-drag :visible.sync="detailInformationFlag" width="1200px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'物料编码'">
          <el-input v-model="detailData.partNo" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料名称'">
          <el-input v-model="detailData.partDesc" disabled style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item :label="'计量单位'">
          <el-input v-model="detailData.umId" disabled style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'到货数量'">
          <el-input class="inlineNumber numInput" v-model="detailData.rollQty" type="number" disabled style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'送检数量'">
          <el-input class="inlineNumber numInput" v-model="detailData.rollCount" type="number" style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'抽样数量'">
          <el-input class="inlineNumber numInput" v-model="detailData.samplingQty" type="number" style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'不合格项目数量'">
          <el-input class="inlineNumber numInput" v-if="detailData.submitFlag === 'Y'" v-model="detailData.unqualifiedQty" disabled type="number" style="width: 80px"></el-input>
          <el-input class="inlineNumber numInput" v-else @input="handleInput(detailData.unqualifiedQty,1)" v-model="detailData.unqualifiedQty" type="number" style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'合格数量'">
          <el-input class="inlineNumber numInput" v-if="detailData.submitFlag === 'Y'" v-model="detailData.passQty" disabled type="number" style="width: 80px"></el-input>
          <el-input class="inlineNumber numInput" v-else @input="handleInput(detailData.passQty,2)" v-model="detailData.passQty" type="number" style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="'不合格数量'">
          <el-input class="inlineNumber numInput" v-model="detailData.notPassQty" type="number" disabled style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item :label="' '" style="margin-left: 25px">
          <el-button type="primary" @click="getFileContentData(detailData)">工作文件</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'检验结论'">
          <el-select v-if="detailData.submitFlag === 'Y'" v-model="detailData.inspectionResult" disabled style="width: 100px" placeholder="请选择">
            <el-option label="合格" value="合格"></el-option>
            <el-option label="不合格" value="不合格"></el-option>
          </el-select>
          <el-select v-else v-model="detailData.inspectionResult" @change="resultChange" style="width: 100px" placeholder="请选择">
            <el-option label="合格" value="合格"></el-option>
            <el-option label="不合格" value="不合格"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'质检备注'">
          <el-input v-if="detailData.submitFlag === 'Y'" v-model="detailData.inspectionRemark" disabled style="width: 310px"></el-input>
          <el-input v-else v-model="detailData.inspectionRemark" style="width: 310px"></el-input>
        </el-form-item>
        <el-form-item label="检验员">
          <el-select v-if="detailData.submitFlag === 'Y'" v-model="detailData.inspectorNo" disabled placeholder="请选择" style="width: 100px">
            <el-option
              v-for = "i in options"
              :key = "i.inspectorNo"
              :label = "i.inspectorName"
              :value = "i.inspectorNo">
            </el-option>
          </el-select>
          <el-select v-else v-model="detailData.inspectorNo" disabled placeholder="请选择" style="width: 100px">
            <el-option
              v-for = "i in options"
              :key = "i.inspectorNo"
              :label = "i.inspectorName"
              :value = "i.inspectorNo">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <span v-if="detailData.submitFlag === 'Y'" slot="label">协同人员</span>
          <span v-else style="cursor: pointer" slot="label" @click="getOperatorList"><a>协同人员</a></span>
          <el-input v-model="detailData.operatorName" readonly style="width: 224px"></el-input>
        </el-form-item>
        <el-form-item>
          <span v-if="detailData.submitFlag === 'Y'" slot="label">责任人(供应商)</span>
          <span v-else style="cursor: pointer" slot="label" @click="getBaseList(509)" ><a>责任人(供应商)</a></span>
          <el-input v-model="detailData.responsiblePerson" :readonly="detailData.submitFlag === 'Y'" style="width: 224px"></el-input>
<!--          <span v-if="detailData.submitFlag === 'Y'" slot="label">责任人</span>-->
<!--          <span v-else style="cursor: pointer" slot="label" @click="getResponsiblePersonList"><a>责任人</a></span>-->
<!--          <el-input v-model="detailData.responsiblePersonName" readonly style="width: 224px"></el-input>-->
        </el-form-item>
        <el-form-item :label="' '" style="margin-left: 20px">
          <el-button type="primary" icon="el-icon-upload" @click="subDetailUpload">明细导入</el-button>
        </el-form-item>
      </el-form>
      <el-form v-show="detailData.inspectionResult === '不合格'" :inline="true" label-position="top">
        <el-form-item :label="'处置措施'">
          <el-select v-if="detailData.submitFlag === 'Y'" clearable v-model="detailData.disposalMeasures" disabled style="width: 100px">
            <el-option
              v-for = "i in disposalMeasuresOptions"
              :key = "i.id"
              :label = "i.disposalMeasures"
              :value = "i.disposalMeasures">
            </el-option>
          </el-select>
          <el-select v-else clearable v-model="detailData.disposalMeasures" style="width: 100px">
            <el-option
              v-for = "i in disposalMeasuresOptions"
              :key = "i.id"
              :label = "i.disposalMeasures"
              :value = "i.disposalMeasures">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'处置说明'">
          <el-input v-if="detailData.submitFlag === 'Y'" v-model="detailData.disposalRemark" disabled style="width: 200px"></el-input>
          <el-input v-else v-model="detailData.disposalRemark" style="width: 280px"></el-input>
        </el-form-item>
      </el-form>
      <!-- 展示列表 -->
      <div class="rq ">
        <el-table
          :height="500"
          :data="detailList"
          border
          :row-style="rowDetailStyle"
          @row-click="OQCDetailClickRow"
          style="width: 100%;">
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="60"
            label="操作">
            <template slot-scope="scope">
              <el-button v-if="scope.row.detailImageNum > 0" type="success" class="el-icon-picture" @click="uploadImageModal(scope.row)"></el-button>
              <el-button v-else class="el-icon-picture" type="primary" @click="uploadImageModal(scope.row)"></el-button>
            </template>
          </el-table-column>
          <el-table-column
            v-for="(item,index) in detailColumnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed===''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="right"
            min-width="80"
            label="实测值">
            <template slot-scope="scope">
              <el-input :ref="`textValue${scope.$index}`" v-if="scope.row.valueTypeDb === 'N'" v-model="scope.row.numberValue" @keyup.enter.native="focusNextInput(scope.$index, 'textValue')" type="number" style="height: 11px; width: 98%"></el-input>
              <el-input :ref="`textValue${scope.$index}`" v-else v-model="scope.row.textValue" @keyup.enter.native="focusNextInput(scope.$index, 'textValue')" style="height: 11px; width: 98%"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="center"
            min-width="80"
            label="检验明细">
            <template slot-scope="scope">
              <el-button v-if="scope.row.subDetailRecordNum > 0" type="success" @click="subDetailModal(scope.row) ">点击输入</el-button>
              <el-button v-else type="primary" @click="subDetailModal(scope.row)">点击输入</el-button>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="right"
            min-width="80"
            label="抽样数量">
            <template slot-scope="scope">
              <el-input class="inlineNumber numInput" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.samplingQty" disabled type="number" style="height: 11px; width: 98%"></el-input>
              <el-input class="inlineNumber numInput" v-else :ref="`samplingQty${scope.$index}`" v-model="scope.row.samplingQty" type="number" @keyup.enter.native="focusNextInput(scope.$index, 'samplingQty')" style="height: 11px; width: 98%"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="right"
            min-width="80"
            label="不合格数量">
            <template slot-scope="scope">
              <el-input class="inlineNumber numInput" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.unqualifiedQuantity" disabled type="number" style="height: 11px; width: 98%"></el-input>
              <el-input class="inlineNumber numInput" v-else :ref="`unqualifiedQuantity${scope.$index}`" v-model="scope.row.unqualifiedQuantity" type="number" @keyup.enter.native="focusNextInput(scope.$index, 'unqualifiedQuantity')" style="height: 11px; width: 98%"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop=""
            header-align="center"
            align="right"
            min-width="90"
            label="项目检验结论">
            <template slot-scope="scope">
              <el-select :class="{redElSelect:scope.row.itemResult === 'N', greenElSelect:scope.row.itemResult === 'Y'}" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.itemResult" disabled style="height: 11px;padding: 0px" >
                <el-option label="合格" value="Y" style="color: green"></el-option>
                <el-option label="不合格" value="N" style="color: red"></el-option>
              </el-select>
              <el-select :class="{redElSelect:scope.row.itemResult === 'N', greenElSelect:scope.row.itemResult === 'Y'}" v-else v-model="scope.row.itemResult" style="height: 11px;padding: 0px" placeholder="合格">
                <el-option label="合格" value="Y" style="color: green"></el-option>
                <el-option label="不合格" value="N" style="color: red"></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="Transfer">保存</el-button>
        <el-button type="primary" @click="detailInformationFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 文件清单 -->
    <el-dialog title="文件清单" :close-on-click-modal="false" v-drag :visible.sync="fileFlag" width="800px">
      <el-form :inline="true" label-position="top">
        <el-form-item v-if="detailInformationFlag">
          <el-button type="primary" @click="addUploadFileModal">上传文件</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="350"
        :data="fileContentList"
        border
        style="width: 100%; ">
        <el-table-column
          v-for="(item,index) in fileColumnList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed===''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="100"
          label="操作">
          <template slot-scope="scope">
            <el-link style="cursor: pointer" @click="downloadFile(scope.row)">下载</el-link>
            <el-link style="cursor:pointer" @click="previewFile(scope.row)">预览</el-link>
            <el-link v-if="scope.row.fileType2 !== 'sop'" style="cursor: pointer" @click="deleteFile(scope.row)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="fileFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 子明细信息 -->
    <el-dialog title="子明细信息" :close-on-click-modal="false" v-drag :visible.sync="subDetailFlag" width="572px">
      <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAddBtn(subDetailData)">添加</el-button>
      <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteBtn(subDetailData)">删除</el-button>
      <el-button type="primary" icon="el-icon-more" size="mini" @click="batchHandleAdd(subDetailData)">批量新增</el-button>
      <div class="rq ">
        <el-table
          :height="400"
          :data="templateTableData"
          border
          :row-class-name="rowClassName"
          @selection-change="handleDetailSelectionChange"
          style="width: 100%;">
          <el-table-column type="selection" align="center" width="50"></el-table-column>
          <el-table-column label="序号" align="center" prop="rowI" width="50"></el-table-column>
          <el-table-column prop="samplingLocation" header-align="center" align="center" :required="true" label="抽样位置A" width="150">
            <template slot-scope="{row}">
              <el-input v-if="templateTableData[row.xh-1].isSubmit === 'Y'" v-model="templateTableData[row.xh-1].samplingLocation" readonly placeholder="请输入抽样位置A"></el-input>
              <el-input v-else :ref="`${row.xh-1}` + `a`" v-model="templateTableData[row.xh-1].samplingLocation" @keyup.enter.native="nextFocus1(row.xh-1)" placeholder="请输入抽样位置A"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="samplingLocationB" header-align="center" align="center" :required="true" label="抽样位置B" width="150">
            <template slot-scope="{row}">
              <el-input v-if="templateTableData[row.xh-1].isSubmit === 'Y'" v-model="templateTableData[row.xh-1].samplingLocationB" readonly placeholder="请输入抽样位置B"></el-input>
              <el-input v-else :ref="`${row.xh-1}` + `b`" v-model="templateTableData[row.xh-1].samplingLocationB" @keyup.enter.native="nextFocus2(row.xh-1)" placeholder="请输入抽样位置B"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="subDetailValue" header-align="center" align="center" :required="true" label="实测值" width="200">
            <template slot-scope="{row}">
              <el-input v-if="templateTableData[row.xh-1].isSubmit === 'Y'" v-model="templateTableData[row.xh-1].subDetailValue" readonly placeholder="请输入实测值"></el-input>
              <el-input v-else :ref="`${row.xh-1}` + `c`" v-model="templateTableData[row.xh-1].subDetailValue" @keyup.enter.native="nextFocus3(row.xh-1)" placeholder="请输入实测值"></el-input>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页-->
        <el-pagination
          @size-change="sizeChangeHandle2"
          @current-change="currentChangeHandle2"
          :current-page="pageIndex2"
          :page-sizes="[20, 50, 100, 200, 500]"
          :page-size="pageSize2"
          :total="tableData.length"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button v-if="detailData.submitFlag !== 'Y'" type="primary" @click="saveSubDetailResult">保存</el-button>
        <el-button type="primary" @click="subDetailFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 批量新增子明细操作-->
    <el-dialog title="批量新增" :close-on-click-modal="false" v-drag :visible.sync="batchHandleAddModalFlag" width="510px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'默认抽样位置A'">
          <el-input v-model="batchAddData.samplingLocation" style="width: 150px"></el-input>
        </el-form-item>
        <el-form-item :label="'默认抽样位置B'">
          <el-input v-model="batchAddData.samplingLocationB" style="width: 150px"></el-input>
        </el-form-item>
        <el-form-item :label="'抽样数量'">
          <el-input type="number" v-model="batchAddData.samplingNumber" style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="batchHandleAddModal">保存</el-button>
        <el-button type="primary" @click="batchHandleAddModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 机修人员清单 -->
    <el-dialog title="人员清单" :close-on-click-modal="false" v-drag :visible.sync="operatorModelFlag" width="820px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="operatorData">
          <el-form-item :label="'所属角色'">
            <el-select v-model="operatorData.roleId" placeholder="请选择" style="width: 120px">
              <el-option
                v-for = "i in roleList"
                :key = "i.roleId"
                :label = "i.roleName"
                :value = "i.roleId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="'用户编码'">
            <el-input v-model="operatorData.adminID" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'用户姓名'">
            <el-input v-model="operatorData.adminName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getOperatorList2">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="operatorList"
          ref="operatorTable"
          @row-click="operatorClickRow"
          @selection-change="selectionChangeHandle2"
          border
          style="width: 100%;">
          <el-table-column
            type="selection"
            header-align="center"
            align="center"
            width="50">
          </el-table-column>
          <el-table-column
            v-for="(item,index) in operatorDetailList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="confirmOperator">确认</el-button>
        <el-button type="primary" @click="operatorModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 更改检验方式 -->
    <el-dialog title="更改检验方式" top="25vh" :close-on-click-modal="false" v-drag :visible.sync="changeModalFlag" width="500px">
      <el-form :inline="true" label-position="top" :model="changeData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="检验方式">
          <el-select v-model="changeData.inspectCode" style="width: 210px">
            <el-option label="全检" value="全检"></el-option>
            <el-option label="数量抽检" value="数量抽检"></el-option>
            <el-option label="比例抽检" value="比例抽检"></el-option>
            <el-option label="不固定抽检" value="不固定抽检"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="抽检数量">
          <el-input class="inlineNumber numInput" v-model="changeData.qtySample" type="number" style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label="抽检比例">
          <el-input class="inlineNumber numInput" v-model="changeData.percentSample" type="number" style="width: 110px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="changeData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item>
          <span slot="label" @click="getBaseList(207)"><a herf="#">抽样方案编码</a></span>
          <el-input v-model="changeData.samplingProgrammeNo" style="width: 143px"></el-input>
        </el-form-item>
        <el-form-item label="抽样方案名称">
          <el-input v-model="changeData.samplingProgrammeDesc" disabled style="width: 300px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="changeData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item>
          <span slot="label" @click="getBaseList(208)"><a herf="#">检验水平编码</a></span>
          <el-input v-model="changeData.samplingLevelNo" style="width: 143px"></el-input>
        </el-form-item>
        <el-form-item label="检验水平名称">
          <el-input v-model="changeData.samplingLevelDesc" disabled style="width: 300px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="changeInspectionWay">保存</el-button>
        <el-button type="primary" @click="changeModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>

    <!-- 上传文件的modal -->
    <qcFAIUploadFile ref="qcFAIUploadFile" @refreshPageTables="()=>{this.getFileContentData(this.detailData)}" v-drag></qcFAIUploadFile>

    <!-- 上传文件的modal -->
    <comQcItemImageUploadFile ref="comQcItemImageUploadFile" @refreshPageTables2="getInspectionFormData" v-drag></comQcItemImageUploadFile>

    <!-- 子明细导入 -->
    <subDetailUpload @changeEvent="changeMyString" ref="subDetailUpload" @refreshPageTables="getInspectionFormData" v-drag></subDetailUpload>

  </div>
</template>

<script>
  import {
    qcOQCInspectionSearch, // OQC检验记录查询
    fqasDetailSearch, // FQAS检验记录查询
    inspectorSearch, // 检验员查询
    selectFQASSubDetailedRecord, // 查询子明细记录
    checkIQCSubDetailValue, // 检查子明细中的实测值是否在规定范围
    saveFQASDetailedRecord, // 新增明细信息
    checkFQASIsSubmit, // 检查是否已提交
    saveFQASSubDetailed, // 新增子明细信息
    saveFQASSubmitResult, // 审核
    fqasRecordDelete, // 删除检验记录
    disposalMeasuresSearch, // 获取处置措施列表
    fqasRecordOverLoad, // 重载检验单
    getSiteAndBuByUserName,
    orderTypeSearch, // 获取采购类型
    actionFQASInspection, // 开始检验
    dataAcquisition, // 数据采集
    changeInspectionWay, // 更改检验方式
  } from "@/api/qc/qc.js"
  import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {getFileContentList2, downLoadObjectFile} from '@/api/eam/eam_object_list.js'
  import {
    deleteObjectFile,
    getUserRoleList, // 获取用户角色列表
    getOperatorList
  } from '@/api/eam/eam.js'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import qcFAIUploadFile from "./qc_FAI_upload_file"
  import comQcItemImageUploadFile from "./com_qc_itemImage_upload_file"
  import subDetailUpload from "./sub_detail_upload"
  export default {
    components: {
      Chooselist,
      qcFAIUploadFile,
      comQcItemImageUploadFile,
      subDetailUpload
    },
    computed: {
      templateTableData () {
        let start = (this.pageIndex2 - 1) * this.pageSize2
        let end = start + this.pageSize2
        if (end > this.tableData.length){
          end = this.tableData.length
        }
        return this.tableData.slice(start,end)
      }
    },
    watch: {
      detailData: {
        deep: true,
        handler: function (newV, oldV) {
          this.detailData.notPassQty = this.detailData.samplingQty - this.detailData.passQty
        }
      },
      detailList: {
        deep: true,
        handler: function (newV, oldV) {
          let num = 0
          for (let i = 0; i < this.detailList.length; i++) {
            if (this.detailList[i].itemResult === 'N') {
              num++
            }
          }
          this.detailData.unqualifiedQty = num
        }
      },
    },
    data () {
      return {
        loadFlag: false,
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "FQAS检验录入" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["FQAS检验录入"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        submitData: {
          site: '',
          inspectionNo: '',
          isQualified: '',
          isQualifiedChinese: '',
          submitList: [],
          updateBy: this.$store.state.user.name,
        },
        tagNo:'',
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          inspectionNo: '',
          inspectionTypeNo:'109',
          isQualified: '',
          buDesc: '',
          startDate: '',
          endDate: '',
          startDate2: '',
          endDate2: '',
          partNo:'',
          partDesc:'',
          state: '',
          inspectionResult: '',
          disposalMeasures: '',
          inspectorName: '',
          page: 1,
          limit: 10,
          states: ['未开始','待检验'],
          orderRef1: '',
          orderRef2: '',
          orderRef3: '',
          orderRef4: '',
          orderRef5: '',
        },
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0,
        pageIndex2: 1,
        pageSize2: 20,
        totalPage2: 0,
        height: 200,
        dataList: [],
        dataListSelections: [],
        submitFlag: false,
        modalData: {
          flag:'',
          functionType:'',
          site: '',
          bu: '',
          inspectionNo:'',
          workOrderNumber: '',
          workOrderQuantity: '',
          reelNumber: '',
          partNo: '',
          rollingQuantity: '',
          sampleQuantity: '',
          detailCodeNo:'',
          detailCodeDesc:'',
          inspectionTypeNo:'109',
          inspectionTypeName:'OQC',
          inspectorNo:'',
          inspectorName:'',
          isQualified:'',
          isQualifiedChinese:''
        },
        // 展示列集
        // columnList1: [],
        columnList1: [
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1BuDesc',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'buDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: 'BU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectionNo',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectionNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRefType',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRefType',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验任务类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectionResult',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectionResult',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验结论',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1TaskDate',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'taskDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '送检日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectionCycle',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectionCycle',
            headerAlign: "center",
            align: "right",
            columnLabel: '检验周期(h)',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1RollNo',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'rollNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '标签条码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1PartNo',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'partNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '物料编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1PartDesc',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1Umid',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'umId',
            headerAlign: "center",
            align: "left",
            columnLabel: '计量单位',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1RollQty',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'rollQty',
            headerAlign: "center",
            align: "right",
            columnLabel: '到货数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1RollCount',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'rollCount',
            headerAlign: "center",
            align: "right",
            columnLabel: '送检数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1SamplingQty',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'samplingQty',
            headerAlign: "center",
            align: "right",
            columnLabel: '抽样数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRef1',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRef1',
            headerAlign: "center",
            align: "center",
            columnLabel: '关联单号1',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRef2',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRef2',
            headerAlign: "center",
            align: "center",
            columnLabel: '关联单号2',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRef3',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRef3',
            headerAlign: "center",
            align: "center",
            columnLabel: '关联单号3',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRef4',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRef4',
            headerAlign: "center",
            align: "center",
            columnLabel: '关联单号4',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1OrderRef5',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'orderRef5',
            headerAlign: "center",
            align: "center",
            columnLabel: '关联单号5',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectionRemark',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectionRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '质检备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1DisposalMeasures',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'disposalMeasures',
            headerAlign: "center",
            align: "center",
            columnLabel: '处置措施',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1DisposalRemark',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'disposalRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '处置说明',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1ActionDate',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'actionDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '开始检验时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectorDate',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectorDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1CreateBy',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'createBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '送检员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table1InspectorName',
            tableId: "301016Table1",
            tableName: "FQAS检验记录表",
            columnProp: 'inspectorName',
            headerAlign: "center",
            align: "center",
            columnLabel: '质检员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        detailColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2ItemNo',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'itemNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2ItemDesc',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'itemDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验项目',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2SamplingLevelDesc',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'samplingLevelDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验水平',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2SamplingProgrammeDesc',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'samplingProgrammeDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验方案',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2MethodName',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'methodName',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验方法',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2MethodRemark',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'methodRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验方法说明',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2ObjectDesc',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'objectDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检测仪器',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2Aql',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'aql',
            headerAlign: "center",
            align: "right",
            columnLabel: 'AQL',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2Ac',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'ac',
            headerAlign: "center",
            align: "right",
            columnLabel: 'AC',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2Re',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 're',
            headerAlign: "center",
            align: "right",
            columnLabel: 'RE',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2DefaultValue',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'defaultValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '标准值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2MaxValue',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'maxValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '最大值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2MinValue',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'minValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '最小值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301016,
            serialNumber: '301016Table2ValueType',
            tableId: "301016Table2",
            tableName: "检验单明细表",
            columnProp: 'valueType',
            headerAlign: "center",
            align: "center",
            columnLabel: '检测值类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        fileColumnList: [
          {
            columnProp: 'fileName',
            headerAlign: "center",
            align: "center",
            columnLabel: '文件名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'createdBy',
            headerAlign: "center",
            align: 'center',
            columnLabel: '上传人',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            columnProp: 'createDate',
            headerAlign: "center",
            align: 'center',
            columnLabel: '上传时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            columnProp: 'orderRef3',
            headerAlign: "center",
            align: 'center',
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
        ],
        detailData: {
          site: '',
          buNo: '',
          inspectionNo: '',
          partNo: '',
          partDesc: '',
          rollQty: '',
          samplingQty: '',
          unqualifiedQty: 0,
          unqualifiedQuantity: '',
          disposalMeasures: '',
          disposalRemark: '',
          inspectionResult: '',
          inspectorNo: '',
          inspectionRemark: '',
          submitFlag: '',
          umId: '',
          rollCount: '',
          operator: '',
          operatorName: '',
          responsiblePerson: '',
          responsiblePersonName: '',
          passQty: '',
          notPassQty: ''
        },
        detailInformationFlag: false,
        detailList: [],
        saveInformationData: {
          site: '',
          buNo: '',
          inspectionNo:'',
          disposalMeasures: '',
          disposalRemark: '',
          inspectorNo: '',
          inspectionRemark: '',
          itemList:[],
          unqualifiedQty: '',
          rollCount: '',
          samplingQty: '',
          partNo: '',
          partDesc: '',
          operator: '',
          operatorName: '',
          responsiblePerson: '',
          responsiblePersonName: '',
          subDetailList: [],
          passQty: '',
          notPassQty: ''
        },
        // 子明细数据对象
        tableData: [],
        checkedDetail: [],
        subDetailFlag: false,
        subDetailData: {
          site: '',
          buNo: '',
          inspectionNo: '',
          itemNo: '',
          itemDesc: '',
          defaultValue: '',
          maxValue: '',
          minValue: '',
          valueTypeDb: '',
          subDetailValues:[]
        },
        options: [],
        fileFlag: false,
        fileContentList: [],
        FQASSelections: [],
        batchHandleAddModalFlag: false,
        batchAddData: {
          samplingLocation: '',
          samplingLocationB: '',
          samplingNumber: ''
        },
        disposalMeasuresOptions: [],
        userBuList: [],
        authSearch: false,
        authCheck: false,
        authOverLoad: false,
        authDelete: false,
        authDetail: false,
        authFile: false,
        authChange: false,
        menuId: this.$route.meta.menuId,
        roleList: [],
        operatorList: [],
        operatorData: {
          flag: '',
          site: '',
          bu: '',
          adminID: '',
          adminName: '',
          roleName: '',
          roleId: '',
        },
        operatorModelFlag: false,
        dataListSelections2: [],
        operatorDetailList: [
          {
            columnProp: 'adminID',
            headerAlign: "center",
            align: "center",
            columnLabel: '用户账号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'adminName',
            headerAlign: "center",
            align: "center",
            columnLabel: '用户名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'email',
            headerAlign: "center",
            align: "center",
            columnLabel: '邮箱',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'phone',
            headerAlign: "center",
            align: "center",
            columnLabel: '手机号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        acquisitionList: [],
        fileData: {
          site: '',
          buNo: '',
          inspectionNo: '',
          partNo: '',
          inspectionTypeNo: ''
        },
        currentRow: {},
        currentDetailRow: {},
        changeData: {
          site: '',
          buNo: '',
          inspectionNo: '',
          rollCount: '',
          inspectCode: '',
          qtySample: '',
          percentSample: '',
          samplingProgrammeNo: '',
          samplingProgrammeDesc: '',
          samplingLevelNo: '',
          samplingLevelDesc: '',
          receiptNo: '',
          receiptItemNo: '',
          inspectionTypeNo: ''
        },
        changeModalFlag: false,
        overLoading: false
      }
    },

    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 250
      })
    },

    updated() {
      this.$nextTick(()=>{
        this.$refs.OQCTable.doLayout()
      })
    },

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName()
      this.favoriteIsOk()
      this.disposalMeasuresSearch()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      this.getTableUserColumn(this.$route.meta.menuId+'table2',2)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
      // 获取用户角色
      this.getUserRoleList()
    },

    methods: {
      // 列表数据总结
      getSummaries (param) {
        const { columns, data } = param
        const sums = []
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总计'
            return
          }
          if (column.property !== 'rollQty' && column.property !== 'rollCount') {
            sums[index] = ''
            return
          }
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          } else {
            sums[index] = ''
          }
        })
        return sums
      },

      // 检验结论改变事件
      resultChange () {
        if (this.detailData.inspectionResult === '不合格') {
          this.detailData.passQty = 0
        }
      },
      // 数据采集
      dataAcquisition () {
        this.loadFlag = true
        let tempDate = {
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          inspectionNo: this.detailData.inspectionNo,
          flag: 'iqc'
        }
        dataAcquisition(tempDate).then(({data}) => {
          if (data.code === 0) {
            // this.acquisitionList = data.rows
            this.changeMyString(data.rows)
            this.$message({
              message: '数据采集成功',
              type: 'success',
              duration: 1500
            })
          } else {
            this.$message({
              message: data.msg,
              type: 'warning',
              duration: 1500
            })
          }
          this.loadFlag = false
        })
      },

      // 获取用户角色
      getUserRoleList () {
        getUserRoleList().then(({data}) => {
          if (data.code === 0) {
            this.roleList = data.rows
          } else {
            this.roleList = []
          }
        })
      },

      // 获取协同人员列表
      getOperatorList () {
        this.operatorData.flag = '1'
        this.operatorData.bu = this.detailData.site + '_' + this.detailData.buNo
        if (this.roleList.length > 0) {
          let filterList = this.roleList.filter(item => item.roleName === '机修人员')
          if (filterList.length > 0) {
            this.operatorData.roleId = filterList[0].roleId
          } else {
            this.operatorData.roleId = this.roleList[0].roleId
          }
        } else {
          this.operatorData.roleId = ''
        }
        // 先清空缓存选中
        this.$nextTick(() => this.$refs.operatorTable.clearSelection())
        // 拿到选中的人员编号
        let tempDataList = (this.detailData.operator == null ? '' : this.detailData.operator).split(';')
        getOperatorList(this.operatorData).then(({data}) => {
          if (data && data.code === 0) {
            this.operatorList = data.rows
            this.operatorList.forEach(val => {
              // 回显选中
              if (tempDataList.includes(val.adminID)) {
                this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
              }
            })
            this.operatorModelFlag = true
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 获取责任人员列表
      getResponsiblePersonList () {
        this.operatorData.flag = '2'
        this.operatorData.bu = this.detailData.site + '_' + this.detailData.buNo
        if (this.roleList.length > 0) {
          let filterList = this.roleList.filter(item => item.roleName === '系统管理员')
          if (filterList.length > 0) {
            this.operatorData.roleId = filterList[0].roleId
          } else {
            this.operatorData.roleId = this.roleList[0].roleId
          }
        } else {
          this.operatorData.roleId = ''
        }
        // 先清空缓存选中
        this.$nextTick(() => this.$refs.operatorTable.clearSelection())
        // 拿到选中的人员编号
        let tempDataList = (this.detailData.responsiblePerson == null ? '' : this.detailData.responsiblePerson).split(';')
        getOperatorList(this.operatorData).then(({data}) => {
          if (data && data.code === 0) {
            this.operatorList = data.rows
            this.operatorList.forEach(val => {
              // 回显选中
              if (tempDataList.includes(val.adminID)) {
                this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
              }
            })
            this.operatorModelFlag = true
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 查询机修人员列表
      getOperatorList2 () {
        if (this.operatorData.flag === '1') {
          // 拿到选中的人员编号
          let tempDataList = (this.detailData.operator == null ? '' : this.detailData.operator).split(';')
          getOperatorList(this.operatorData).then(({data}) => {
            if (data && data.code === 0) {
              this.operatorList = data.rows
              this.operatorList.forEach(val => {
                // 回显选中的部门
                if (tempDataList.includes(val.adminID)) {
                  this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
                }
              })
            } else {
              this.operatorList = []
            }
          })
        } else {
          // 拿到选中的人员编号
          let tempDataList = (this.detailData.responsiblePerson == null ? '' : this.detailData.responsiblePerson).split(';')
          getOperatorList(this.operatorData).then(({data}) => {
            if (data && data.code === 0) {
              this.operatorList = data.rows
              this.operatorList.forEach(val => {
                // 回显选中的部门
                if (tempDataList.includes(val.adminID)) {
                  this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
                }
              })
            } else {
              this.operatorList = []
            }
          })
        }
      },

      // 点击行选中复选框
      operatorClickRow (row) {
        this.$refs.operatorTable.toggleRowSelection(row)
      },

      // 多选
      selectionChangeHandle2 (val) {
        this.dataListSelections2 = val
      },

      // 确认多选协同人员
      confirmOperator () {
        if (this.dataListSelections2.length === 0) {
          this.$message.warning('请勾选人员！')
          return
        }
        if (this.operatorData.flag === '1') {
          for (let i = 0; i < this.dataListSelections2.length; i++) {
            if (!this.detailData.operator.split(';').includes(this.dataListSelections2[i].adminID)) {
              this.detailData.operatorName = this.detailData.operatorName + ";" + this.dataListSelections2[i].adminName
              this.detailData.operator = this.detailData.operator + ";" + this.dataListSelections2[i].adminID
            }
          }
          if (this.detailData.operator.charAt(0) === ';') {
            this.detailData.operator = this.detailData.operator.substring(1)
            this.detailData.operatorName = this.detailData.operatorName.substring(1)
          }
        } else {
          for (let i = 0; i < this.dataListSelections2.length; i++) {
            if (!this.detailData.responsiblePerson.split(';').includes(this.dataListSelections2[i].adminID)) {
              this.detailData.responsiblePersonName = this.detailData.responsiblePersonName + ";" + this.dataListSelections2[i].adminName
              this.detailData.responsiblePerson = this.detailData.responsiblePerson + ";" + this.dataListSelections2[i].adminID
            }
          }
          if (this.detailData.responsiblePerson.charAt(0) === ';') {
            this.detailData.responsiblePerson = this.detailData.responsiblePerson.substring(1)
            this.detailData.responsiblePersonName = this.detailData.responsiblePersonName.substring(1)
          }
        }
        this.operatorData = {
          flag: '',
          site: '',
          bu: '',
          adminID: '',
          adminName: '',
          roleName: '',
          roleId: '',
        }
        this.operatorModelFlag = false
      },


      // // 实测值内容改变事件
      // changeValue (row) {
      //   if (row.minValue == null && row.maxValue != null) {
      //     if (row.numberValue > row.maxValue) {
      //       row.itemResult = 'N'
      //     } else {
      //       row.itemResult = 'Y'
      //     }
      //   } else if (row.maxValue == null && row.minValue != null) {
      //     if (row.numberValue < row.minValue) {
      //       row.itemResult = 'N'
      //     } else {
      //       row.itemResult = 'Y'
      //     }
      //   } else if (row.minValue != null && row.maxValue != null) {
      //     if (row.numberValue < row.minValue || row.numberValue > row.maxValue) {
      //       row.itemResult = 'N'
      //     } else {
      //       row.itemResult = 'Y'
      //     }
      //   }
      // },

      // 获取用户的bu
      getSiteAndBuByUserName () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getSiteAndBuByUserName(tempData).then(({data}) => {
          if (data.code === 0) {
            this.userBuList = data.rows
          }
        })
      },

      // ======= 正则校验 =======
      handleInput (value, type) {
        // 大于等于0，且只能输入4位小数
        let val = value.replace(/^\D*([0-9]\d*\.?\d{0,4})?.*$/,'$1')
        if (val === null || val === undefined || val === '') {
          val = 0
        }
        if (type === 1) {
          this.detailData.unqualifiedQty = val
        } else if (type === 2) {
          this.detailData.passQty = val
        }
      },

      // 子明细导入
      subDetailUpload () {
        let currentData = {
          flag: 'FQAS',
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          inspectionNo: this.detailData.inspectionNo
        }
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.subDetailUpload.init(currentData)
        })
      },

      // 获取处置措施列表
      disposalMeasuresSearch () {
        let tempData = {
          inspectionTypeNo: '109'
        }
        disposalMeasuresSearch(tempData).then(({data}) => {
          if (data.code === 0) {
            this.disposalMeasuresOptions = data.rows
          }
        })
      },

      // 单机选中
      FQASClickRow (row) {
        this.currentRow = JSON.parse(JSON.stringify(row))
      },

      // 复选
      selectionFQAS (val) {
        this.FQASSelections = val
      },

      rowStyle ({row}) {
        if (this.currentRow.inspectionNo === row.inspectionNo) {
          return { 'background-color': '#E8F7F6', cursor: 'pointer' };
        }
      },

      // 单机选中
      OQCDetailClickRow (row) {
        this.currentDetailRow = JSON.parse(JSON.stringify(row))
      },

      rowDetailStyle ({row}) {
        if (this.currentDetailRow.itemNo === row.itemNo) {
          return { 'background-color': '#50DCDC', cursor: 'pointer' };
        }
      },

      // 刷新派设备文档的列表
      getFileContentData (row) {
        this.fileData = {
          site: row.site,
          buNo: row.buNo,
          inspectionNo: row.inspectionNo,
          partNo: row.partNo,
          inspectionTypeNo: '109'
        }
        getFileContentList2(this.fileData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code === 200) {
            this.fileContentList = data.rows
          } else {
            this.fileContentList = []
          }
        })
        this.fileFlag = true
      },

      // 新增文件的modal
      addUploadFileModal () {
        let currentData = {
          titleCon: 'OQC文件上传',
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          createBy: this.$store.state.user.name,
          inspectionNo: this.detailData.inspectionNo,
          remark: '',
          folder: 'qcFQAS',
        }
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.qcFAIUploadFile.init(currentData)
        })
      },

      // 上传项目图片
      uploadImageModal (row) {
        let currentData = {
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          createBy: this.$store.state.user.name,
          inspectionNo: this.detailData.inspectionNo,
          itemNo: row.itemNo,
          folder: 'FQASItemImageFile'
        }
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.comQcItemImageUploadFile.init(currentData)
        })
      },

      // 文件下载
      downloadFile (row) {
        downLoadObjectFile(row)
          .then(({data}) => {
          // 不限制文件下载类型
          const blob = new Blob([data], {type: "application/octet-stream"})
          // 下载文件名称
          const fileName = row.fileName
          // a标签下载
          const linkNode = document.createElement('a')
          // a标签的download属性规定下载文件的名称
          linkNode.download = fileName
          linkNode.style.display = 'none'
          // 生成一个Blob URL
          linkNode.href = URL.createObjectURL(blob)
          document.body.appendChild(linkNode)
          // 模拟在按钮上的一次鼠标单击
          linkNode.click()
          // 释放URL 对象
          URL.revokeObjectURL(linkNode.href)
          document.body.removeChild(linkNode)
        })
      },

      // 预览
      previewFile (row) {
        // 预览文件
        let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
        let type = ''
        if (image.includes(row.fileType.toLowerCase())) {
          type = 'image/' + row.fileType
        }
        let video = ['mp4', 'avi', 'mov', 'wmv', 'flv']
        if (video.includes(row.fileType.toLowerCase())) {
          type = 'video/' + row.fileType
        }
        let txt = ['txt']
        if (txt.includes(row.fileType.toLowerCase())) {
          type = 'text/plain'
        }
        let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
        if (office.includes(row.fileType.toLowerCase())) {
          this.$message.warning(`暂不支持预览${row.fileType.toLowerCase()}文件`)
          return
        }
        let pdf = ['pdf']
        if (pdf.includes(row.fileType.toLowerCase())) {
          type = 'application/pdf'
        }
        if (type === ''){
          this.$message.warning(`暂不支持预览${row.fileType.toLowerCase()}文件`)
          return;
        }
        // downLoadObjectFile(row).then(({data}) => {
        //   const blob = new Blob([data], { type: type });
        //   // 创建URL来生成预览
        //   const fileURL = URL.createObjectURL(blob);
        //   // alert(blob)
        //   localStorage.setItem("imgUrl",fileURL)
        //   window.open(window.location.origin+"/#/image",'_blank')
        //   // 在新标签页中打开文件预览
        //   // const newTab = window.open(fileURL, '_blank')
        // })
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          if (type.includes('image')) { // 图片
            localStorage.setItem("imgUrl",fileURL)
            window.open(window.location.origin+"/#/image",'_blank')
          } else {
            // 在新标签页中打开文件预览
            const newTab = window.open(fileURL, '_blank')
          }
        })
      },

      // 删除文件
      deleteFile (row) {
        let tempData = {
          site: row.orderRef1,
          inspectionNo: row.orderRef2,
          buNo: row.orderRef4,
          partNo: this.fileData.partNo,
          inspectionTypeNo: '109'
        }
        this.$confirm('确定要删除此文件?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteObjectFile(row).then(({data}) => {
            if (data && data.code == 0) {
              this.getFileContentData(tempData)
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          let conSql = ''
          if (val === 1037) {
            strVal = this.modalData.detailCodeNo
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1040) {
            strVal = this.modalData.inspectorNo
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 207) {
            strVal = this.changeData.samplingProgrammeNo
            conSql = " and bu_no = '" + this.changeData.buNo + "'"
            this.$refs.baseList.init(val, strVal, conSql)
          }
          if (val === 208) {
            strVal = this.changeData.samplingLevelNo
            conSql = " and bu_no = '" + this.changeData.buNo + "'"
            this.$refs.baseList.init(val, strVal, conSql)
          }
          if (val === 509) {
            strVal = this.detailData.responsiblePerson
            this.$refs.baseList.init(val, strVal)
          }
        })
      },

      // 列表方法的回调
      getBaseData (val) {
        if (this.tagNo === 1037) {
          this.modalData.detailCodeNo = val.code_no
          this.modalData.detailCodeDesc = val.code_desc
        }
        if (this.tagNo === 1040) {
          this.modalData.inspectorNo = val.inspector_no
          this.modalData.inspectorName = val.inspector_name
        }
        if (this.tagNo === 207) {
          this.changeData.samplingProgrammeNo = val.sampling_programme_no
          this.changeData.samplingProgrammeDesc = val.sampling_programme_desc
        }
        if (this.tagNo === 208) {
          this.changeData.samplingLevelNo = val.sampling_level_no
          this.changeData.samplingLevelDesc = val.sampling_level_desc
        }
        if (this.tagNo === 509) {
          this.detailData.responsiblePerson = val.SupplierID
        }
      },

      // 获取主信息数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        qcOQCInspectionSearch(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
          }
        })
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },

      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },

      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

      // 查询检验类型
      inspectorSearch () {
        inspectorSearch().then(({data}) => {
          if (data.code === 0) {
            this.options = data.rows
          }
        })
      },

      async Transfer () {
        if (this.detailData.inspectionResult === '' || this.detailData.inspectionResult == null) {
          this.$message.warning('请选择检验结论！')
          return
        }
        if (this.detailData.inspectionResult === '不合格' && (this.detailData.disposalMeasures == null || this.detailData.disposalMeasures === '')) {
          this.$message.warning('请选择处置措施！')
          return
        }
        if (this.detailList.length > 0 && this.detailData.inspectionResult === '不合格') {
          const flag = this.detailList.some(item => item.itemResult === 'N')
          if (!flag) {
            this.$message.warning('请选择不合格项目！')
            return
          }
        }
        this.$confirm(`确认保存检验数据?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (this.detailData.inspectionResult !== '不合格') {
            this.detailData.disposalMeasures = ''
            this.detailData.disposalRemark = ''
          }
          this.saveDetailInformation()
        })
      },

      // 新增明细信息
      saveDetailInformation () {
        this.saveInformationData.site = this.detailData.site
        this.saveInformationData.buNo = this.detailData.buNo
        this.saveInformationData.inspectionNo = this.detailData.inspectionNo
        this.saveInformationData.disposalMeasures = this.detailData.disposalMeasures
        this.saveInformationData.disposalRemark = this.detailData.disposalRemark
        this.saveInformationData.inspectorNo = this.$store.state.user.name
        this.saveInformationData.inspectionResult = this.detailData.inspectionResult
        this.saveInformationData.inspectionRemark = this.detailData.inspectionRemark
        this.saveInformationData.rollCount = this.detailData.rollCount
        this.saveInformationData.samplingQty = this.detailData.samplingQty
        this.saveInformationData.unqualifiedQty = this.detailData.unqualifiedQty
        this.saveInformationData.partNo = this.detailData.partNo
        this.saveInformationData.partDesc = this.detailData.partDesc
        this.saveInformationData.operator = this.detailData.operator
        this.saveInformationData.responsiblePerson = this.detailData.responsiblePerson
        this.saveInformationData.itemList = JSON.parse(JSON.stringify(this.detailList))
        this.saveInformationData.passQty = this.detailData.passQty == null ? 0 : this.detailData.passQty
        this.saveInformationData.notPassQty = this.detailData.notPassQty == null ? 0 : this.detailData.notPassQty
        // this.saveInformationData.subDetailList = this.acquisitionList
        saveFQASDetailedRecord(this.saveInformationData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.detailInformationFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 开始检验
      actionModal (row) {
        this.$confirm(`确认开始检验?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let tempData = {
            site: row.site,
            buNo: row.buNo,
            inspectionNo: row.inspectionNo,
            actionBy: this.$store.state.user.name,
            state: '待检验'
          }
          actionFQASInspection(tempData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },

      // 明细记录信息查询
      detailModal (row) {
        this.detailData.site = row.site
        this.detailData.buNo = row.buNo
        this.detailData.inspectionNo = row.inspectionNo
        this.detailData.partNo = row.partNo
        this.detailData.partDesc = row.partDesc
        this.detailData.rollQty = row.rollQty
        this.detailData.samplingQty = row.samplingQty
        this.detailData.unqualifiedQty = row.unqualifiedQty
        this.detailData.unqualifiedQuantity = row.unqualifiedQuantity
        this.detailData.submitFlag = row.submitFlag
        this.detailData.disposalMeasures = row.disposalMeasures
        this.detailData.disposalRemark = row.disposalRemark
        this.detailData.inspectionResult = row.inspectionResult
        this.detailData.inspectorNo = row.inspectorNo
        this.detailData.inspectionRemark = row.inspectionRemark
        this.detailData.umId = row.umId
        this.detailData.rollCount = row.rollCount
        this.detailData.operator = row.operator
        this.detailData.operatorName = row.operatorName
        this.detailData.responsiblePerson = row.responsiblePerson
        this.detailData.responsiblePersonName = row.responsiblePersonName
        if (row.state === '待检验') {
          this.detailData.passQty = row.samplingQty
        } else {
          this.detailData.passQty = row.passQty
          this.detailData.notPassQty = row.notPassQty
        }
        this.getInspectionFormData()
        this.inspectorSearch()
        // this.acquisitionList = []
        this.detailInformationFlag = true
      },

      // 检验单明细
      getInspectionFormData () {
        fqasDetailSearch(this.detailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailList = data.rows
          } else {
            this.detailList = []
          }
        })
      },

      // 子明细记录信息查询
      subDetailModal (row) {
        this.subDetailData = row
        this.pageIndex2 = 1
        selectFQASSubDetailedRecord(this.subDetailData).then(({data}) => {
          this.tableData = data.rows
        })
        this.batchAddData = {
          samplingLocation: '',
          samplingLocationB: '',
          samplingNumber: ''
        }
        this.subDetailFlag = true
      },

      // 删除检验记录
      deleteModal () {
        if (this.FQASSelections.length === 0) {
          this.$message.warning('请勾选要删除的检验单！')
          return
        }
        this.$confirm(`是否删除该 `+ this.FQASSelections.length +` 条检验记录?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let tempData = {
            site: '',
            submitList: this.FQASSelections
          }
          fqasRecordDelete(tempData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.FQASSelections = []
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 任务重载
      overLoadModal () {
        if (this.FQASSelections.length === 0) {
          this.$message.warning('请勾选要重载的检验单！')
          return
        }
        if (this.FQASSelections.every(val => val.state === '待检验' || val.state === '未开始')) {
          this.$confirm(`是否重载该 `+ this.FQASSelections.length +` 条检验单?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let tempData = {
              site: '',
              submitList: this.FQASSelections
            }
            this.overLoading = true
            fqasRecordOverLoad(tempData).then(({data}) => {
              if (data && data.code === 0) {
                this.getDataList()
                this.FQASSelections = []
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {}
                })
                this.overLoading = false
              } else {
                this.overLoading = false
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            }).catch(() => {
              this.overLoading = false
            })
          })
        } else {
          this.$message.warning('检验单必须为待检验状态！')
          return
        }

      },

      // 审核按钮
      submitResult () {
        let tempData1 = '' // 记录不是待审核状态的单号
        let tempData2 = '' // 记录处置措施未填写的单号
        if (this.FQASSelections.length === 0) {
          this.$message.warning('请勾选要审核的检验单！')
          return
        }
        for (let i = 0; i < this.FQASSelections.length; i++) {
          if (this.FQASSelections[i].state !== '待审核'){
            tempData1 = tempData1 + this.FQASSelections[i].inspectionNo + '、'
          }
          if (this.FQASSelections[i].inspectionResult === '不合格' && (this.FQASSelections[i].disposalMeasures === '' || this.FQASSelections[i].disposalMeasures == null)) {
            tempData2 = tempData2 + this.FQASSelections[i].inspectionNo + '、'
          }
        }
        if (tempData1 !== '') {
          tempData1 = tempData1.substring(0, tempData1.length - 1)
          this.$message.warning('检验单号 ' + tempData1 + ' 不是待审核状态！')
          return
        }
        if (tempData2 !== '') {
          tempData2 = tempData2.substring(0, tempData2.length - 1)
          this.$message.warning('检验单号 ' + tempData2 + ' 的处置措施未选择！')
          return
        }
        this.$confirm(`已确认单据信息无误，确定审核该 ` + this.FQASSelections.length + ` 条记录`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.submitData.submitList = this.FQASSelections
          saveFQASSubmitResult(this.submitData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.FQASSelections = []
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 子明细每页数
      sizeChangeHandle2 (val) {
        this.pageSize2 = val
      },

      // 子明细当前页
      currentChangeHandle2 (val) {
        this.pageIndex2 = val
      },

      // 子明细方法
      // 表格的新增
      rowClassName ({ row, rowIndex }) {
        row.xh = rowIndex + 1
        row.rowI = this.tableData.indexOf(row) + 1
      },

      // 单选框选中数据
      handleDetailSelectionChange(selection) {
        this.checkedDetail = selection
      },

      // 点击新增更多
      handleAddBtn (td) {
        checkFQASIsSubmit(td).then(({data}) => {
          if (data.flag !== 1) {
            let obj = {}
            obj.subDetailValue = ""
            obj.samplingLocation = ""
            this.tableData.push(obj)
          } else {
            this.$alert("记录已提交！", '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 批量新增操作
      batchHandleAdd (td) {
        checkFQASIsSubmit(td).then(({data}) => {
          if (data.flag !== 1) {
            this.batchHandleAddModalFlag = true
          } else {
            this.$alert("记录已提交！", '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 批量新增行
      batchHandleAddModal () {
        for (let i = 0; i < this.batchAddData.samplingNumber; i++) {
          let obj = {}
          obj.samplingLocation = this.batchAddData.samplingLocation
          obj.samplingLocationB = this.batchAddData.samplingLocationB
          obj.subDetailValue = ""
          this.tableData.push(obj)
        }
        this.batchHandleAddModalFlag = false
      },

      // 回车事件
      nextFocus1 (index) {
        let a1 = `${index + 1}` + `a`
        this.$nextTick(() => {
          this.$refs[a1].focus()
        })
      },

      nextFocus2 (index) {
        let a2 = `${index + 1}` + `b`
        this.$nextTick(() => {
          this.$refs[a2].focus()
        })
      },

      nextFocus3 (index) {
        let a3 = `${index + 1}` + `c`
        this.$nextTick(() => {
          this.$refs[a3].focus()
        })
      },

      focusNextInput (index, type) {
        let aaa = ''
        if (this.detailList.length - 1 === index) {
          aaa = `${type}0`
        } else {
          aaa = `${type}${index + 1}`
        }
        this.$nextTick(() => {
          this.$refs[aaa].focus()
        })
      },

      //删除
      handleDeleteBtn (td) {
        checkFQASIsSubmit(td).then(({data}) => {
          if (data.flag !== 1) {
            if (this.checkedDetail.length === 0) {
              this.$alert("请先选择要删除的数据", "提示", {
                confirmButtonText: "确定",
              })
            } else {
              this.$confirm("请是否确认删除该子明细记录?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
                callback: (action) => {
                  if (action === "confirm") {
                    let val = this.checkedDetail
                    val.forEach((val, index) => {
                      this.tableData.splice(this.tableData.indexOf(val), 1)
                      if (this.templateTableData.length === 0) {
                        this.pageIndex2--
                      }
                    })
                    this.$message({
                      message: "删除成功！",
                      type: "success",
                    })
                    return
                  } else {
                    this.$message({
                      message: "已取消删除操作",
                      type: "warning",
                    })
                    return
                  }
                },
              })
            }
          } else {
            this.$alert("记录已提交！", '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 新增子明细记录
      saveSubDetailResult () {
        for (let i = 0; i < this.tableData.length; i++) {
          if(this.tableData[i].subDetailValue === '' || this.tableData[i].subDetailValue == null){
            this.$message.warning('序号' + (i+1) +'未填写实测值！')
            return
          }
        }
        this.subDetailData.subDetailValues = this.tableData
        saveFQASSubDetailed(this.subDetailData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.count > 0) {
              this.subDetailData.itemResult = 'N'
              this.subDetailData.unqualifiedQuantity = data.count
            }
            if (this.subDetailData.subDetailValues.length > 0) {
              this.subDetailData.subDetailRecordNum = 1
            } else {
              this.subDetailData.subDetailRecordNum = -1
              this.subDetailData.unqualifiedQuantity = 0
              this.subDetailData.itemResult = 'Y'
            }
            this.subDetailFlag = false
            this.tableData = []
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 更改检验方式
      changeInspectionModal (row) {
        this.changeData = {
          site: row.site,
          buNo: row.buNo,
          inspectionNo: row.inspectionNo,
          rollCount: row.rollCount,
          inspectCode: '',
          qtySample: '',
          percentSample: '',
          samplingProgrammeNo: '',
          samplingProgrammeDesc: '',
          samplingLevelNo: '',
          samplingLevelDesc: '',
          receiptNo: row.receiptNo,
          receiptItemNo: row.receiptItemNo,
          inspectionTypeNo: '108'
        }
        this.changeModalFlag = true
      },

      // 保存修改
      changeInspectionWay () {
        if (this.changeData.inspectCode === '' || this.changeData.inspectCode == null) {
          this.$message.warning('请选择检验方式！')
          return
        }
        if (this.changeData.inspectCode === '数量抽检' && (this.changeData.qtySample == null || this.changeData.qtySample === '' || this.changeData.qtySample === 0)) {
          this.$message.warning('请填写抽检数量！')
          return
        }
        if (this.changeData.inspectCode === '比例抽检' && (this.changeData.percentSample == null || this.changeData.percentSample === '' || this.changeData.percentSample === 0)) {
          this.$message.warning('请填写抽检比例！')
          return
        }
        if (this.changeData.inspectCode === '不固定抽检' && (this.changeData.samplingProgrammeNo == null || this.changeData.samplingProgrammeNo === '')) {
          this.$message.warning('请选择抽样方案！')
          return
        }
        if (this.changeData.inspectCode === '不固定抽检' && (this.changeData.samplingLevelNo === null || this.changeData.samplingLevelNo === '')) {
          this.$message.warning('请选择检验水平！')
          return
        }
        if (this.changeData.inspectCode === '数量抽检' && this.changeData.qtySample > this.changeData.rollCount) {
          this.$message.warning('抽检数量不能大于送检数量，当前检验单送检数量为[]！')
          return
        }
        changeInspectionWay(this.changeData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.changeModalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 校验用户是否收藏
      favoriteIsOk () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            if (this.$route.meta.menuId === data.list[i].menuId) {
              this.favorite = true
            }
          }
        })
      },

      // 收藏 OR 取消收藏
      favoriteFunction () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }
      },

      //导出excel
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await qcOQCInspectionSearch(this.searchData).then(({data}) => {
          this.exportList = data.page.list
        })
        return this.exportList
      },

      startDownload() {},

      finishDownload() {},

      fields () {
        let json = "{"
        this.columnList1.forEach((item, index) => {
          if (index == this.columnList1.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn (tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList1 = data.rows
                break;
              case 2:
                this.detailColumnList = data.rows
                break;
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable = {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList1 = data.rows
                break;
              case 2:
                this.detailColumnList = data.rows
                break;
            }
          }
        })
      },

      /**
       * 明细导入后将返回值回传给父组件
       * @param val
       */
      changeMyString (val) {
        for (let i = 0; i < this.detailList.length; i++) {
          if (val[this.detailList[i].itemNo] !== undefined) {
            this.detailList[i].unqualifiedQuantity = val[this.detailList[i].itemNo]
            if (val[this.detailList[i].itemNo] != null) {
              this.detailList[i].subDetailRecordNum = 1
            }
            if (val[this.detailList[i].itemNo] > 0) {
              this.detailList[i].itemResult = 'N'
            }
          }
        }
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let checkFlag = this.isAuth(this.menuId+":check")
        let overLoadFlag = this.isAuth(this.menuId+":overLoad")
        let deleteFlag = this.isAuth(this.menuId+":delete")
        let detailFlag = this.isAuth(this.menuId+":detail")
        let fileFlag = this.isAuth(this.menuId+":file")
        let changeFlag = this.isAuth(this.menuId+":change")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authCheck = !checkFlag
        this.authOverLoad = !overLoadFlag
        this.authDelete = !deleteFlag
        this.authDetail = !detailFlag
        this.authFile = !fileFlag
        this.authChange = !changeFlag
      },
    }
  }
</script>

<style scoped>
/deep/ .redElSelect .el-input--suffix .el-input__inner{
  color: red;
  font-weight: bold;
}
/deep/ .greenElSelect .el-input--suffix .el-input__inner{
  color: rgb(103,194,58);
  font-weight: bold;
}
.numInput /deep/ .el-input__inner{
  text-align: right;
}
/deep/  .inlineNumber input::-webkit-outer-spin-button,
/deep/  .inlineNumber input::-webkit-inner-spin-button {
  -webkit-appearance: none;

}
/deep/  .inlineNumber input[type="number"]{
  -moz-appearance: textfield;
  padding-right: 5px !important;
}
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>
