<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" >
      <el-form-item :label="'检验编码'">
        <el-input v-model="searchData.inspectionNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'质检员编码'">
        <el-input v-model="searchData.inspectorNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="检验时间">
        <el-col :span="11">
          <el-input v-model="searchData.startDate" type="date"></el-input>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-input v-model="searchData.endDate" type="date"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item  :label="' '">
        <el-button @click="doEmpty()">清空</el-button>
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addInspectionRecords()">新增</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
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in columnList" :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="230"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="detailModal(scope.row)">明细信息</a>
          <a type="text" v-if = "scope.row.isQualified == 'D'" size="small" @click="submitResult(scope.row)">提交</a>
          <a type="text" size="small" @click="deleteModal(scope.row)">删除</a>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页-->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :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="inspectionRecordsFlag" width="430px">
<!--      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">-->
<!--        <el-form-item label="检验编码:">-->
<!--          <el-input v-model="modalData.inspectionNo" :disabled="modalDisableFlag" style="width: 120px"></el-input>-->
<!--        </el-form-item>-->
<!--      </el-form>-->

      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(1040)"><a herf="#">质检员</a></span>
          <el-input v-model="modalData.inspectorNo"  style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="质检员名称:">
          <el-input v-model="modalData.inspectorName" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>

      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item label="工单号:">
          <el-input v-model="modalData.workOrderNumber" @blur="workOrderBlur" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="工单数量:">
          <el-input v-model="modalData.workOrderQuantity" type="number" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="产品料号:">
          <el-input v-model="modalData.partNo" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>

      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item label="卷号:">
          <el-input v-model="modalData.reelNumber" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="收卷数量:">
          <el-input v-model="modalData.rollingQuantity" type="number" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="首件取样数量:">
          <el-input v-model="modalData.sampleQuantity" type="number" style="width: 120px"></el-input>
        </el-form-item>
      </el-form>

      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="inspectionRecordsFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 明细信息详情页 -->
    <el-dialog title="明细信息清单" :close-on-click-modal="false" v-drag :visible.sync="detailInformationFlag" width="1200px">
      <el-form :inline="true"  label-position="top" @keyup.enter.native = "getDataList()">
        <el-form-item :label="'检验编码'">
          <el-input v-model="detailData.inspectionNo" readonly style="width: 170px"></el-input>
        </el-form-item>
        <el-form-item  :label="' '"></el-form-item>
      </el-form>
      <!-- 展示列表 -->

      <div class="rq ">
      <el-table
        :height="200"
        :data="detailList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <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 v-if="scope.row.valueTypeDb=='T' && scope.row.isSubmit=='Y'" v-model="scope.row.textValue" style="height: 11px;padding: 0px " readonly filterable allow-create>;width:98%"></el-input>
            <el-input v-if="scope.row.valueTypeDb=='T' && scope.row.isSubmit!='Y'" v-model="scope.row.textValue" style="height: 11px;padding: 0px " filterable allow-create>;width:98%"></el-input>
            <el-input v-if="scope.row.valueTypeDb=='N' && scope.row.isSubmit=='Y'" v-model="scope.row.numberValue" type="number" style="height: 11px;padding: 0px " readonly filterable allow-create>;width:98%"></el-input>
            <el-input v-if="scope.row.valueTypeDb=='N' && scope.row.isSubmit!='Y'" v-model="scope.row.numberValue" type="number" style="height: 11px;padding: 0px " filterable allow-create>;width:98%"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop=""
          header-align="center"
          align="right"
          min-width="55"
          label="子明细">
          <template slot-scope="scope">
            <el-button type="primary" @click="subDetailModal(scope.row) ">点击输入</el-button>
          </template>
        </el-table-column>

        <el-table-column
          prop=""
          header-align="center"
          align="right"
          min-width="75"
          label="是否合格">
          <template slot-scope="scope">
            <el-select v-if="scope.row.isSubmit=='Y'" disabled="disabled" filterable v-model="scope.row.isQualified" style="height: 11px;padding: 0px ">
              <el-option label="是" value="Y"></el-option>
              <el-option label="否" value="N"></el-option>
            </el-select>
            <el-select v-if="scope.row.isSubmit!='Y'" filterable v-model="scope.row.isQualified" style="height: 11px;padding: 0px ">
              <el-option label="是" value="Y"></el-option>
              <el-option label="否" value="N"></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="submitFlag" width="200px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">

        <el-form-item :label="'请选择检验结果'">
          <el-select filterable v-model="submitData.isQualified" style="width: 130px">
            <el-option label="请选择" value=""></el-option>
            <el-option label="合格" value="Y"></el-option>
            <el-option label="不合格" value="N"></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveSubmitResult()">保存</el-button>
        <el-button type="primary" @click="submitFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>


    <!-- 子明细信息 -->
    <el-dialog title="子明细信息" :close-on-click-modal="false" v-drag :visible.sync="subDetailFlag" width="471px">
      <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>

      <div class="rq ">
      <el-table
        :height="300"
        :data="tableData"
        border
        :header-cell-class-name="starAdd"
        :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="xh" width="50"></el-table-column>

        <el-table-column prop="subDetailValue" header-align="center" align="center" :required="true" label="抽样位置" width="150">
          <template slot-scope="{row}">
            <el-input v-if="tableData[row.xh-1].isSubmit=='Y'" v-model="tableData[row.xh-1].samplingLocation" readonly placeholder="请输入抽样位置"></el-input>
            <el-input v-if="tableData[row.xh-1].isSubmit!='Y'" v-model="tableData[row.xh-1].samplingLocation" placeholder="请输入抽样位置"></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="tableData[row.xh-1].isSubmit=='Y'" v-model="tableData[row.xh-1].subDetailValue" readonly placeholder="请输入实测值"></el-input>
            <el-input v-if="tableData[row.xh-1].isSubmit!='Y'" v-model="tableData[row.xh-1].subDetailValue" placeholder="请输入实测值"></el-input>
          </template>
        </el-table-column>
      </el-table>
      </div>

      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveSubDetailResult()">保存</el-button>
        <el-button type="primary" @click="subDetailFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>


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

  </div>
</template>

<script>
  import {
    qcFAIInspectionSearch, // 查询FAI的检验记录

    qcInspectionInformationSearch, // 检验记录查询
    qcInspectionInformationSave, // 新增检验记录
    qcInspectionInformationDelete, // 删除检验记录
    detailInformationSearch, // 查询明细信息
    modalCodeBlur, // 模板信息
    saveDetailInformation, // 新增明细信息
    saveSubmitResult, // 保存检验结果
    checkCompleted, // 判断主信息和明细信息是否已填写
    selectModelByPartNo, // 物料编码失去焦点事件
    subDetailInformationSave, // 新增子明细信息
    selectSubDetailInformation,
    checkOutIsSubmit, // 检查是否已提交
    selectInformationByWorkOrderNo, // 工单号失去焦点事件
    checkSubDetailValue // 检查子明细中的实测值是否在规定范围
  } from "@/api/qc/qc.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  export default {
    components: {
      Chooselist
    },
    watch: {

    },
    data () {
      return {
        // 是否收藏
        favorite: false,

        // 导出 start
        exportData: [],
        exportName: "FAI检验录入" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["FAI检验录入"],
        exportFooter: [],
        exportList:[],
        // 导出 end

        checkCompletedData:{
          inspectionNo: ''
        },
        submitData:{
          site:'',
          inspectionNo: '',
          isQualified: '',
          isQualifiedChinese: '',
        },
        tagNo:'',
        searchData: {
          site: this.$store.state.user.site,
          inspectionNo: '',
          inspectionTypeNo:'102',
          inspectorNo: '',
          isQualified: '',
          familyType:'D',
          partNo:'',
          partDesc:'',
          page: 1,
          limit: 10,
        },
        workOrderData: {
          site: this.$store.state.user.site,
          // page: 1,
          // limit: 10,
        },
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        dataList: [],
        dataListLoading: false,
        dataListSelections: [],
        inspectionRecordsFlag: false,
        modalDisableFlag: false,
        submitFlag: false,
        modalData: {
          flag:'',
          functionType:'',
          site: this.$store.state.user.site,
          inspectionNo:'',
          workOrderNumber: '',
          workOrderQuantity: '',
          reelNumber: '',
          partNo: '',
          rollingQuantity: '',
          sampleQuantity: '',
          detailCodeNo:'',
          detailCodeDesc:'',
          inspectionTypeNo:'102',
          inspectionTypeName:'FAI',
          inspectorNo:'',
          inspectorName:'',
          isQualified:'',
          isQualifiedChinese:''
        },
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TableSite',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'site',
            headerAlign: "center",
            align: "left",
            columnLabel: '工厂编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 40,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TablePlanID',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'inspectionNo',
            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: 301005,
            serialNumber: '301005TablePlanDesc',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'workOrderNumber',
            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: 301005,
            serialNumber: '301005TablePlanDesc',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'reelNumber',
            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: 301005,
            serialNumber: '301005TablePlanDesc',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'partNo',
            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: 301005,
            serialNumber: '301005TablePlanDesc',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 180,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TablePlanDesc',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'inspectionTypeName',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TableObjectID',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'inspectorName',
            headerAlign: "center",
            align: "left",
            columnLabel: '质检员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TablePropertiesCode',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'createTime',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005TablePropertiesCode',
            tableId: "301005Table",
            tableName: "检验记录表",
            columnProp: 'isQualifiedChinese',
            headerAlign: "center",
            align: "left",
            columnLabel: '是否合格',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          }
        ],
        //项目清单
        addDetailModalFlag:false,
        detailData:{
          site:'',
          inspectionNo:'',
          functionType:'',
          familyType:'',
          detailCodeNo:'',
          subDetailCodeNo:'',
          inspectorNo:'',
          userId:this.$store.state.user.name
        },
        masterInformationFlag:false,
        detailInformationFlag:false,
        masterList: [],
        detailList:[],
        saveInformationData:{
          inspectionNo:'',
          itemList:[],
        },
        masterColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table2EamPropertiesItemID',
            tableId: "301005Table2",
            tableName: "主记录信息表",
            columnProp: 'informationNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '主信息编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table2EamPropertiesItemDesc',
            tableId: "301005Table2",
            tableName: "主记录信息表",
            columnProp: 'informationName',
            headerAlign: "center",
            align: "left",
            columnLabel: '主信息名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          }
        ],
        detailColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemID',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'itemNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'itemDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '项目名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'valueType',
            headerAlign: "center",
            align: "left",
            columnLabel: '项目类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'methodName',
            headerAlign: "center",
            align: "left",
            columnLabel: '方法名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'methodRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '方法描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'defaultValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '默认值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'maxValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最大值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301005,
            serialNumber: '301005Table3EamPropertiesItemDesc',
            tableId: "301005Table3",
            tableName: "明细信息表",
            columnProp: 'minValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最小值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50,
          }
        ],
        itemModalData:{
          site:'',
          planID:'',
          flag:'',
          itemNo:'',
          itemDesc:'',
          valueTypeDb:'',
          defaultValue:'',
          valueChooseFlag:'',
          createdBy:this.$store.state.user.name,
          maxValue:'',
          minValue:'',
          itemRemark:'',
          itemType:'A',
        },
        itemModalFlag:false,
        itemModalDisableFlag:false,

        itemFlag:'text',
        chooseModalFlag:false,
        chooseModalData:{
          site:'',
          planID:'',
          itemNo: '',
          itemDesc: '',
          itemType:'A',
          valueTypeDb:'',
        },
        chooseTableData:[],
        itemData:{
          site:'',
          planID:'',
          itemNo:'',
          valueNo:'',
          availableValue:'',
          itemType:'A',
          createdBy: this.$store.state.user.name
        },
        itemAddModalFlag:false,

        // 子明细数据对象
        tableData: [],
        checkedDetail: [],
        showEdit: [], //控制显示及隐藏

        subDetailFlag: false,
        subDetailData: {
          inspectionNo: '',
          itemNo: '',
          itemDesc: '',
          methodName: '',
          methodRemark: '',
          defaultValue: '',
          maxValue: '',
          minValue: '',
          subDetailValues:[]
        }
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    created () {
      this.getDataList()
      this.favoriteIsOk()
    },
    methods: {
      // 清空搜索栏
      doEmpty(){
        this.searchData = {
          site: this.$store.state.user.site,
          inspectionNo: '',
          inspectionTypeNo: '102',
          inspectorNo: '',
          isQualified: '',
          familyType:'D',
          page: 1,
          limit: 10,
        }
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          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)
          }
        })
      },
      /* 列表方法的回调 */
      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
        }
      },

      modalCodeBlur(){
        let inData={
          functionType:'E',
          codeNo:this.modalData.masterCodeNo
        }
        modalCodeBlur(inData).then(({data}) => {
          if(data.rows.length > 0){
            this.modalData.masterCodeDesc = data.rows[0].codeDesc
          }else {
            this.modalData.masterCodeDesc = ''
          }
        })
      },

      // 获取主信息数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        qcFAIInspectionSearch(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
          }
          this.dataListLoading = false
        })
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增检验记录
      addInspectionRecords(){
        this.modalData={
          flag:'1',
          site: this.$store.state.user.site,
          inspectionNo: '',
          workOrderNumber: '',
          workOrderQuantity: '',
          reelNumber: '',
          partNo: '',
          rollingQuantity: '',
          sampleQuantity: '',
          subDetailCodeNo:'',
          inspectionTypeNo:'102',
          inspectorNo:'',
          isQualified:''
        };
        this.modalDisableFlag = false;
        this.inspectionRecordsFlag = true;
      },

      // 删除检验记录
      deleteModal (row) {
        this.$confirm(`是否删除这条检验记录?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          qcInspectionInformationDelete(row).then(({data}) => {
            if (data && data.code ==0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 新增检验记录
      saveData(){
        if (this.modalData.detailCodeNo == '' || this.modalData.detailCodeNo == null) {
          this.$alert('该工单的物料和分类模板不存在，请维护！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.inspectorNo == '' || this.modalData.inspectorNo == null) {
          this.$alert('请选择质检员！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.reelNumber == '' || this.modalData.reelNumber == null) {
          this.$alert('请填写卷号！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.rollingQuantity == '' || this.modalData.rollingQuantity == null) {
          this.$alert('请填写收卷数量！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.sampleQuantity == '' || this.modalData.sampleQuantity == null) {
          this.$alert('请填写首件取样数量！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.modalData.flag == '1'){
          this.modalData.isQualified = 'D'
          this.modalData.isQualifiedChinese = '待提交'
          qcInspectionInformationSave(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.inspectionRecordsFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },

      Transfer(){
        for (let i = 0; i < this.detailList.length; i++) {
          if(this.detailList[i].valueTypeDb == 'N') {
            checkSubDetailValue(this.detailList[i]).then(({data}) => {
              if (data.flag == 2 && this.detailList[i].isQualified == 'Y') {
                this.$confirm(this.detailList[i].itemDesc + '子明细中实测值不在合格范围！是否保存为合格', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  this.saveDetailInformation()
                }).then(() => {
                  return false
                })
              }
            })
          }
        }
      },

      // 新增明细信息
      async saveDetailInformation(){
        for (let i = 0; i < this.detailList.length; i++) {
          if(this.detailList[i].isQualified == '' || this.detailList[i].isQualified == null){
            this.$alert(this.detailList[i].itemDesc+'是否合格未确认！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          if(this.detailList[i].valueTypeDb == 'N' && this.detailList[i].numberValue != '' && this.detailList[i].numberValue != null){
            if(this.detailList[i].minValue != null && this.detailList[i].minValue > this.detailList[i].numberValue && this.detailList[i].isQualified == 'Y'){
              await this.$confirm(this.detailList[i].itemDesc+'实测值小于最小值！是否保存为合格', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
              }).then(() =>{
                return false
              })
            }
            if(this.detailList[i].minValue != null && this.detailList[i].maxValue < this.detailList[i].numberValue && this.detailList[i].isQualified == 'Y'){
              await this.$confirm(this.detailList[i].itemDesc+'实测值大于最大值！是否保存为合格', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
              }).then(() =>{
                return false
              })
            }
          }
        }
        this.saveInformationData.itemList = JSON.parse(JSON.stringify(this.detailList))
        saveDetailInformation(this.saveInformationData.itemList).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: '确定'
            })
          }
        })
      },

      // 明细记录信息查询
      detailModal(row){
        this.detailData.site = row.site
        this.detailData.detailCodeNo = row.detailCodeNo
        this.detailData.inspectionNo = row.inspectionNo
        this.detailData.inspectorNo = row.inspectorNo
        detailInformationSearch(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
        this.detailInformationFlag = true;
      },

      // 子明细记录信息查询
      subDetailModal(row){
        this.subDetailData.inspectionNo = row.inspectionNo;
        this.subDetailData.itemNo = row.itemNo;
        this.subDetailData.itemDesc = row.itemDesc;
        this.subDetailData.methodName = row.methodName;
        this.subDetailData.methodRemark = row.methodRemark;
        this.subDetailData.defaultValue = row.defaultValue;
        this.subDetailData.maxValue = row.maxValue;
        this.subDetailData.minValue = row.minValue;
        selectSubDetailInformation(this.subDetailData).then(({data}) => {
          this.tableData = data.rows
        })
        this.subDetailFlag = true;
      },

      // 提交按钮
      submitResult(row){
        this.submitData.site = row.site
        this.submitData.inspectionNo = row.inspectionNo;
        this.checkCompletedData.inspectionNo = row.inspectionNo;
        // 判断主信息和明细信息是否已填写
        checkCompleted(this.checkCompletedData).then(({data}) =>{
          if (data && data.code == '1') {
            this.submitFlag = true;
          }else {
            this.$alert(data.msg, '错误！', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 保存提交结果
      saveSubmitResult(){
        if (this.submitData.isQualified == '' || this.submitData.isQualified == null){
          this.$alert('请选择是否合格！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.submitData.isQualified == 'Y'){
          this.submitData.isQualifiedChinese = '合格'
        }
        if (this.submitData.isQualified == 'N'){
          this.submitData.isQualifiedChinese = '不合格'
        }
        saveSubmitResult(this.submitData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.submitFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },


      // 子明细方法

      //表格的新增
      rowClassName({ row, rowIndex }) {
        row.xh = rowIndex + 1;
      },
      //单选框选中数据
      handleDetailSelectionChange(selection) {
        this.checkedDetail = selection;
      },
      //点击新增更多
      handleAddBtn(td) {
        checkOutIsSubmit(td).then(({data}) => {
          if (data.flag != 1) {
            let obj = {};
            obj.subDetailValue = "";
            obj.samplingLocation = "";
            this.tableData.push(obj);
          } else {
            this.$alert("记录已提交！", '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      //删除
      handleDeleteBtn(td) {
        checkOutIsSubmit(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.forEach((v, i) => {
                        if (val.xh === v.xh) {
                          this.tableData.splice(i, 1);
                        }
                      });
                    });
                    this.$message({
                      message: "删除成功，记得保存修改喔！",
                      type: "success",
                    });
                    //this.$refs.tb.clearSelection();
                    return;
                  } else {
                    this.$message({
                      message: "已取消删除操作",
                      type: "warning",
                    });
                    return;
                  }
                },
              });
            }
          } else {
            this.$alert("记录已提交！", '错误', {
              confirmButtonText: '确定'
            })
          }
        })


      },
      //红色五角星提示
      starAdd(obj) {
        if (obj.columnIndex === 2 || obj.columnIndex === 3) {
          return "star";
        }
      },
      //点击编辑
      showUpdate(index, row) {
        this.showEdit[index] = true;
        this.$set(this.showEdit, index, true); //这里要用$set方法，否则页面状态不更新
      },
      saveSubDetailResult(){
        //this.modalData.detailCodeNo = JSON.parse(JSON.stringify(this.modalData.detailCodeNo[1]))
        this.subDetailData.subDetailValues = this.tableData
        subDetailInformationSave(this.subDetailData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.subDetailFlag = false
            this.tableData = []
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 工单号失去焦点事件
      workOrderBlur(){
        let inData = {
          site: this.modalData.site,
          workOrderNumber: this.modalData.workOrderNumber
        }
        selectInformationByWorkOrderNo(inData).then(({data}) => {
          if(data.rows.length > 0){
            this.modalData.partNo = data.rows[0].partNo
            this.modalData.workOrderQuantity = data.rows[0].lotSize
            selectModelByPartNo(this.modalData).then(({data}) => {
              if(data.rows != null){
                this.modalData.detailCodeNo = data.rows[0].codeNo
                this.modalData.detailCodeDesc = data.rows[0].detailCodeDesc
                this.detailData.functionType = data.rows[0].functionType
              }else {
                this.modalData.detailCodeNo = ''
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          }else {
            this.modalData.partNo = ''
          }
        })
      },

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

        })
      },
      // 收藏 OR 取消收藏
      favoriteFunction() {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          // 取消收藏
          this.$confirm(`确定取消收藏`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            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 qcInspectionInformationSearch(this.searchData).then(({data}) => {
          this.exportList= data.page.list;
        })

        return this.exportList;
      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      finishDownload() {

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

        return s
      },
      // 导出 end

    }
  }
</script>

<style scoped>

</style>
