<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.buNo" placeholder="请选择" clearable style="width: 75px">
          <el-option
            v-for = "i in buList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buNo">
          </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.poOrderNo" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item :label="'单据行号'">
        <el-input v-model="searchData.poItemNo" clearable style="width: 75px"></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: 200px"></el-input>
      </el-form-item>
      <el-form-item :label="'SKU'">
        <el-input v-model="searchData.sku" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'PN'">
        <el-input v-model="searchData.cinvSourceCode" clearable style="width: 120px"></el-input>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList">
      <el-form-item :label="'供应商'">
        <el-input v-model="searchData.supplierDesc" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item :label="'质检员'">
        <el-input v-model="searchData.inspectorName" clearable style="width: 100px"></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-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.itemResult" clearable style="width: 80px">
          <el-option label="合格" value="Y"></el-option>
          <el-option label="不合格" value="N"></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-item :label="'采购类型'">
        <el-select v-model="searchData.orderType" clearable style="width: 90px">
          <el-option
            v-for = "i in orderTypeList"
            :key = "i.orderType"
            :label = "i.orderType"
            :value = "i.orderType">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'送检类型'">
        <el-select v-model="searchData.submissionType" clearable style="width: 90px">
          <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="'协同人员'">
        <el-input v-model="searchData.operatorName" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item :label="'责任人'">
        <el-input v-model="searchData.responsiblePersonName" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item :label="'送检日期'">
        <el-date-picker style="width: 150px" v-model="searchData.startDate2" type="datetime" value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 150px" v-model="searchData.endDate2" type="datetime" value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item :label="'检验时间'">
        <el-date-picker style="width: 150px" v-model="searchData.startDate" type="datetime" value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 150px" v-model="searchData.endDate" type="datetime" value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList">查询</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
      @row-click="IQCClickRow"
      :row-style="rowStyle"
      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"
        :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="130"
        label="操作">
        <template slot-scope="scope">
          <a style="cursor: pointer" @click="subDetailModal(scope.row)">检验明细</a>
          <a style="cursor: pointer" @click="getFileContentData(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, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-drawer title="检验项目子明细" :visible.sync="subDetailModalFlag" direction="rtl" :with-header="false">
      <div style="padding: 5px">
        <el-table
          :height="height + 210"
          :data="templateTableData"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in SubDetailColumnList" :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>
        <!-- 分页-->
        <el-pagination
          @size-change="sizeChangeHandle2"
          @current-change="currentChangeHandle2"
          :current-page="pageIndex2"
          :page-sizes="[20, 50, 100, 200, 500]"
          :page-size="pageSize2"
          :total="subDetailDataList.length"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </el-drawer>

    <!-- 文件清单 -->
    <el-dialog title="文件清单" :close-on-click-modal="false" v-drag :visible.sync="fileModalFlag" width="800px">
      <qc-report-file-table :columns="fileColumnList" :data-list="fileContentList" :query-loading="fileLoading"></qc-report-file-table>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="fileModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

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

<script>
  import {
    getIQCReport, // 获取IQC报表
  } from "@/api/qc/qc_report.js"
  import {
    getSiteAndBuByUserName2, // 获取site bu
    selectIQCSubDetailedRecord, // 查询子明细
    disposalMeasuresSearch, // 获取处置措施列表
    orderTypeSearch, // 获取采购类型
  } from "@/api/qc/qc.js"
  import {getFileContentList} from '@/api/eam/eam_object_list.js'
  import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import QcReportFileTable from "../qc/QCReportFileTable.vue";
  export default {
    components: {
      QcReportFileTable,
      Chooselist
    },
    computed: {
      templateTableData () {
        let start = (this.pageIndex2 - 1) * this.pageSize2
        let end = start + this.pageSize2
        if (end > this.subDetailDataList.length){
          end = this.subDetailDataList.length
        }
        return this.subDetailDataList.slice(start,end)
      }
    },
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "IQC报表" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["IQC报表"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          inspectionNo: '',
          inspectionTypeNo:'105',
          isQualified: '',
          buNo: '',
          startDate: '',
          endDate: '',
          startDate2: '',
          endDate2: '',
          partNo:'',
          partDesc:'',
          cinvSourceCode:'',
          sku:'',
          state: '',
          inspectionResult: '',
          supplierDesc: '',
          disposalMeasures: '',
          inspectorName: '',
          page: 1,
          limit: 10,
          poOrderNo: '',
          poItemNo: '',
          orderType: '',
          states: [],
          submissionType: '',
          operatorName: '',
          responsiblePersonName: '',
          itemResult: ''
        },
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        pageIndex2: 1,
        pageSize2: 50,
        totalPage2: 0,
        height: 200,
        dataList: [],
        // 标头展示
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1State',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'state',
            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: 107001001,
            serialNumber: '107001001Table1BuDesc',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1InspectionNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1InspectionResult',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1TaskDate',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1InspectionCycle',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1RollNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1PartNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'partNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '物料编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1PartDesc',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 350,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1Sku',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'sku',
            headerAlign: "center",
            align: "left",
            columnLabel: 'SKU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1CinvSourceCode',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'cinvSourceCode',
            headerAlign: "center",
            align: "left",
            columnLabel: 'PN',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1Invdefinetype',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'invdefinetype',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料类别',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1UmId',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1RollQty',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1RollCount',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1SamplingQty',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1PoOrderNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'poOrderNo',
            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: 107001001,
            serialNumber: '107001001Table1OrderType',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'orderType',
            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: 107001001,
            serialNumber: '107001001Table1SubmissionType',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'submissionType',
            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: 107001001,
            serialNumber: '107001001Table1PoItemNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'poItemNo',
            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: 107001001,
            serialNumber: '107001001Table1SupplierDesc',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'supplierDesc',
            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: 107001001,
            serialNumber: '107001001Table1InspectionRemark',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1DisposalMeasures',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1DisposalRemark',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1ActionDate',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1InspectorDate',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1InspectorName',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'inspectorName',
            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: 107001001,
            serialNumber: '107001001Table1OperatorName',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'operatorName',
            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: 107001001,
            serialNumber: '107001001Table1ResponsiblePersonName',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'responsiblePersonName',
            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: 107001001,
            serialNumber: '107001001Table1SubmissionRemark',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'submissionRemark',
            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: 107001001,
            serialNumber: '107001001Table1ItemNo',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1ItemDesc',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'itemDesc',
            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: 107001001,
            serialNumber: '107001001Table1DefaultValue',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'defaultValue',
            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: 107001001,
            serialNumber: '107001001Table1MaxValue',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1MinValue',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            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: 107001001,
            serialNumber: '107001001Table1ItemSamplingQty',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'itemSamplingQty',
            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: 107001001,
            serialNumber: '107001001Table1UnqualifiedQuantity',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'unqualifiedQuantity',
            headerAlign: "center",
            align: "right",
            columnLabel: '不合格数量(项目)',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table1TextValue',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'textValue',
            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: 107001001,
            serialNumber: '107001001Table1ItemResultDesc',
            tableId: "107001001Table1",
            tableName: "IQC报表",
            columnProp: 'itemResultDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '项目检验结论',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        SubDetailColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table2SamplingLocation',
            tableId: "107001001Table2",
            tableName: "IQC子明细",
            columnProp: 'samplingLocation',
            headerAlign: "center",
            align: "center",
            columnLabel: '抽样位置A',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table2SamplingLocationB',
            tableId: "107001001Table2",
            tableName: "IQC子明细",
            columnProp: 'samplingLocationB',
            headerAlign: "center",
            align: "center",
            columnLabel: '抽样位置B',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001001,
            serialNumber: '107001001Table2SubDetailValue',
            tableId: "107001001Table2",
            tableName: "IQC子明细",
            columnProp: 'subDetailValue',
            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
          },
        ],
        options: [],
        buList: [],
        authSearch: false,
        menuId: this.$route.meta.menuId,
        subDetailModalFlag: false,
        subDetailDataList: [],
        currentRow: {},
        disposalMeasuresOptions: [],
        orderTypeList: [],
        fileContentList: [],
        fileModalFlag: false,
        fileLoading: false
      }
    },

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

    activated () {
      if (this.$route.params.type === 'tokenLogin') {
        this.searchData.buNo = this.$route.params.buNo
        this.searchData.inspectionNo = this.$route.params.docNo
        this.searchData.itemResult = this.$route.params.itemResult
      }
      this.getDataList()
    },

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName2()
      // 获取处置措施
      this.disposalMeasuresSearch()
      this.orderTypeSearch()
      // 校验用户是否收藏
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
    },

    methods: {

      // 获取采购类型列表
      orderTypeSearch () {
        orderTypeSearch().then(({data}) => {
          if (data.code === 0) {
            this.orderTypeList = data.rows
          }
        })
      },

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

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

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

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

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

      // 查询获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        getIQCReport(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
          }
        })
      },

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

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

      // 打开子明细
      subDetailModal (row) {
        this.pageIndex2 = 1
        selectIQCSubDetailedRecord(row).then(({data}) => {
          if (data && data.code === 0) {
            this.subDetailDataList = data.rows
            this.subDetailModalFlag = true
          }
        })
      },

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

      // 刷新派设备文档的列表
      getFileContentData (row) {
        let currentData = {
          orderRef1: row.site,
          orderRef2: row.inspectionNo,
          orderRef3: row.itemNo,
          orderRef4: row.buNo,
        }
        this.fileLoading = true
        getFileContentList(currentData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code === 200) {
            this.fileContentList = data.rows
          } else {
            this.fileContentList = []
          }
          this.fileLoading = false
        }).catch(()=>{
          this.fileLoading = false
        })
        this.fileModalFlag = true
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 508) {
            strVal = this.searchData.warehouseId
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 509) {
            strVal = this.searchData.supplierNo
            this.$refs.baseList.init(val, strVal)
          }
        })
      },

      // 列表方法的回调
      getBaseData (val) {
        if (this.tagNo === 508) {
          this.searchData.warehouseId = val.WareHouseID
        }
        if (this.tagNo === 509) {
          this.searchData.supplierNo = val.SupplierID
        }
      },

      // 校验用户是否收藏
      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 getIQCReport(this.searchData).then(({data}) => {
          this.exportList= data.page.list
        })
        return this.exportList
      },

      startDownload() {},

      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
      },

      // 动态列开始 获取 用户保存的 格式列
      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) {
            switch (columnId) {
              case 1:
                this.columnList = 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.columnList = data.rows
                break
            }
          }
        })
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        //处理页面的权限数据
        this.authSearch = !searchFlag
      },
    }
  }
</script>
<style scoped>
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>
