<template>
  <div class="mod-config">
    <!-- 条件查询 -->
    <el-form :inline="true" label-position="top" :model="searchData">
      <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: 120px"></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: 250px"></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-item :label="'检验项目编码'">
        <el-input v-model="searchData.itemNo" clearable style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item :label="'检验项目名称'">
        <el-input v-model="searchData.itemDesc" clearable style="width: 150px"></el-input>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData">
      <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-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-input v-model="searchData.orderNo" clearable style="width: 137px"></el-input>
      </el-form-item>
      <el-form-item :label="'派工单号'">
        <el-input v-model="searchData.seqNo" clearable style="width: 167px"></el-input>
      </el-form-item>
      <el-form-item :label="'工序'">
        <el-input v-model="searchData.operationDesc" clearable style="width: 108px"></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">
      <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: 160px" 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: 160px" 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: 170px" v-model="searchData.startDate" type="datetime" value-format='yyyy-MM-dd HH:mm:ss' format='yyyy-MM-dd HH:mm:ss' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 170px" v-model="searchData.endDate" type="datetime" value-format='yyyy-MM-dd HH:mm:ss' format='yyyy-MM-dd HH:mm:ss' 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="!authSearch" type="primary" :loading="downLoading" @click="downloadQcDetailRecord">导出</el-button>
      </el-form-item>
    </el-form>

    <!-- 展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="searchLoading"
      element-loading-text="拼命加载中"
      @row-click="FAIClickRow"
      :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"
        :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="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>
  </div>
</template>

<script>
import {
  getFAIDetailReport, // 查询
  downloadQcDetailRecord, // 导出
} from "@/api/qc/qc_report.js"
import {disposalMeasuresSearch, getSiteAndBuByUserName2, orderTypeSearch,} from "@/api/qc/qc.js"
import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
import {removeUserFavorite, saveUserFavorite, userFavoriteList} from '@/api/userFavorite.js'
export default {
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "FAI明细报表" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["FAI明细报表"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          inspectionNo: '',
          state: '',
          inspectionResult: '',
          orderNo: '',
          operationDesc: '',
          buNo: '',
          startDate: '',
          endDate: '',
          startDate2: '',
          endDate2: '',
          partNo: '',
          partDesc: '',
          cinvSourceCode: '',
          sku: '',
          disposalMeasures: '',
          page: 1,
          limit: 10,
          seqNo: '',
          states: [],
          operatorName: '',
          responsiblePersonName: '',
          itemResult: '',
          downloadType: 'fai',
          itemNo: '',
          itemDesc: ''
        },
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        height: 200,
        dataList: [],
        // 标头展示
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1State',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1BuDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectionNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1BatchRollNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'batchRollNo',
            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: 107001006,
            serialNumber: '107001006Table1RollNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectionResult',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1DisposalMeasures',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1TaskDate',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectionCycle',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1OrderNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'orderNo',
            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: 107001006,
            serialNumber: '107001006Table1SeqNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'seqNo',
            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: 107001006,
            serialNumber: '107001006Table1OperationDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'operationDesc',
            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: 107001006,
            serialNumber: '107001006Table1ResourceDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'resourceDesc',
            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: 107001006,
            serialNumber: '107001006Table1PartNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1PartDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1Sku',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'sku',
            headerAlign: "center",
            align: "center",
            columnLabel: 'SKU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1cinvSourceCode',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'cinvSourceCode',
            headerAlign: "center",
            align: "center",
            columnLabel: 'PN',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1Invdefinetype',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'invdefinetype',
            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: 107001006,
            serialNumber: '107001006Table1UmName',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'umName',
            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: 107001006,
            serialNumber: '107001006Table1RollCount',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1SamplingQty',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectionRemark',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1DisposalRemark',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1ActionDate',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectorDate',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1InspectorName',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1OperatorName',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1ResponsiblePersonName',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1SpecialRequirements',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'specialRequirements',
            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: 107001006,
            serialNumber: '107001006Table1ItemNo',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1ItemDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1DefaultValue',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1MaxValue',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1MinValue',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1ItemSamplingQty',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1UnqualifiedQuantity',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1TextValue',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            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: 107001006,
            serialNumber: '107001006Table1ItemResultDesc',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'itemResultDesc',
            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: 107001006,
            serialNumber: '107001006Table1SamplingLocation',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'samplingLocation',
            headerAlign: "center",
            align: "left",
            columnLabel: '默认抽样位置A',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SamplingLocationB',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'samplingLocationB',
            headerAlign: "center",
            align: "left",
            columnLabel: '默认抽样位置B',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SubDetailValue',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'subDetailValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '实测值A',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SubDetailValueB',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'subDetailValueB',
            headerAlign: "center",
            align: "right",
            columnLabel: '实测值B',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SubDetailValueC',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'subDetailValueC',
            headerAlign: "center",
            align: "right",
            columnLabel: '实测值C',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SubDetailValueD',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'subDetailValueD',
            headerAlign: "center",
            align: "right",
            columnLabel: '实测值D',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 107001006,
            serialNumber: '107001006Table1SubDetailValueE',
            tableId: "107001006Table1",
            tableName: "FAI明细报表",
            columnProp: 'subDetailValueE',
            headerAlign: "center",
            align: "right",
            columnLabel: '实测值E',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        buList: [],
        authSearch: false,
        menuId: this.$route.meta.menuId,
        currentRow: {},
        disposalMeasuresOptions: [],
        orderTypeList: [],
        searchLoading: false,
        downLoading: false
      }
    },

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

    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: {

      // 导出按钮
      downloadQcDetailRecord () {
        this.downLoading = true
        downloadQcDetailRecord(this.searchData)
          .then(response => {
            const blob = new Blob([response.data],{ type: 'application/vnd.ms-excel'});
            const url = window.URL.createObjectURL(blob);
            const link= document.createElement('a');
            link.href = url;
            link.download='FAI检验单明细.xlsx';// 设置下载文件名
            link.click();
            window.URL.revokeObjectURL(url);//释放URL对象
            this.downLoading = false
          }).catch(()=>{
          this.downLoading = false
        })
      },

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

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

      rowStyle ({row}) {
        if (this.currentRow.id === row.id) {
          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 () {
        let searchFlag = true
        Object.keys(this.searchData).forEach(val=>{
          if (val !== 'userName' && val !== 'page' && val !== 'limit' && val !== 'downloadType') {
            if (this.searchData[val].length > 0) {
              searchFlag = false
              return
            }
          }
        })
        if (searchFlag) {
          this.$message.warning('请填写查询条件后再执行操作！')
          return
        }
        this.searchLoading = true
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        getFAIDetailReport(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.searchLoading = false
        }).catch(()=>{
          this.searchLoading = false
        })
      },

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

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

      startDownload() {},

      finishDownload() {},

      fields () {
        return this.columnList.reduce((acc, item, index) => {
          acc[item.columnLabel] = item.columnProp;
          return acc;
        }, {});
      },

      // 动态列开始 获取 用户保存的 格式列
      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>
