<template>
  <div>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'项目编码'">
        <el-input v-model="searchData.projectNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'项目名称'">
        <el-input v-model="searchData.projectDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'项目料号'">
        <el-input v-model="searchData.testPartNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'料号描述'">
        <el-input v-model="searchData.partDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'客户编码'">
        <el-input v-model="searchData.customerNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'客户名称'">
        <el-input v-model="searchData.customerDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'项目分类'">
        <el-select v-model="searchData.projectCategory" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in projectCategoryList"
            :key = "i.projectCategory"
            :label = "i.projectCategory"
            :value = "i.projectCategory">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'项目状态'">
        <el-select v-model="searchData.status" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in statusList"
            :key = "i.status"
            :label = "i.status"
            :value = "i.status">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'PM/Sales'">
        <el-select v-model="searchData.projectManager" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in projectManagersList"
            :key = "i.projectManagerId"
            :label = "i.projectManagerName"
            :value = "i.projectManager">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'PjM'">
        <el-select v-model="searchData.projectOwner" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in projectOwnersList"
            :key = "i.projectOwnerId"
            :label = "i.projectOwnerName"
            :value = "i.projectOwner">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'Engineer'">
        <el-select v-model="searchData.engineer" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in engineersList"
            :key = "i.engineerId"
            :label = "i.engineerName"
            :value = "i.engineer">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'是否确认'">
        <el-select filterable v-model="searchData.confirmFlag" 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-item :label="'立项日期：'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
        -
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <!--      <el-form-item :label="'在用'">-->
      <!--        <el-select filterable v-model="searchData.active" 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-item :label="' '">
        <el-button @click="getDataList()">查询</el-button>
        <download-excel
          v-if="this.$route.query.flag !== '2' && this.$route.query.flag !== '1'"
          :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 :data="dataList"
              border
              :height="height"
              style="width: 100%;margin-top: 0px;">
      <el-table-column
        v-for="(item,index) in columnProjectList" :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 header-align="center" align="center" width="70" prop="userDisplay" label="指定确认人"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" :formatter="formatDate" prop="wantedConfirmDate" label="要求确认日期"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="confirmFlag" label="是否确认"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="confirmedBy" label="实际确认人"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="remark" label="备注"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="confirmedDate" label="实际确认时间"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="createDate" label="推送时间"></el-table-column>-->
<!--      <el-table-column header-align="center" align="center" prop="createBy" label="推送人"></el-table-column>-->
      <el-table-column
        header-align="center"
        align="center"
        width="90"
        fixed="left"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="toMes(scope.row)">项目信息</a>
          <a v-if="scope.row.confirmFlag === 'N'" type="text" size="small" @click="confirmDocument(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-dialog title="确认" @close="closeUploadFileVisible" :visible.sync="confirmVisible" width="579px" style="margin-top: 0vh;height: 100%;" :close-on-click-modal="false">
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="项目编码" prop="projectNo" class="red-label">
          <el-input v-model="modalData.projectNo" readonly style="width: 110px;" class="red-text"></el-input>
        </el-form-item>
        <el-form-item label="项目名称" prop="projectDesc" >
          <el-input v-model="modalData.projectDesc" readonly style="width: 170px;" class="red-text"></el-input>
        </el-form-item>
        <el-form-item label="BU" prop="bu">
          <el-input v-model="modalData.bu" readonly style="width: 110px;" class="red-text"></el-input>
        </el-form-item>
        <el-form-item label="项目分类" prop="cProjectTypeDb">
          <el-input v-model="modalData.cProjectTypeDb" readonly style="width: 110px;" class="red-text"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="指定确认人" prop="userDisplay">
          <el-input v-model="confirmData.userDisplay" readonly style="width: 110px;"></el-input>
        </el-form-item>
        <el-form-item label="要求确认日期" prop="wantedConfirmDate">
          <el-input v-model="confirmData.wantedConfirmDate" readonly style="width: 170px;" class="red-text"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="confirmData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="confirmData.remark" style="width: 541px" type="textarea" :rows="1"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="confirmData" style="margin-left: 7px;margin-top: -15px;">
        <el-form-item label=" ">
          <a href="javascript:void(0);" @click="triggerUpload" type="text" size="small">点击选择文件</a>
          <tr></tr>
          <el-input v-model="this.fileName" readonly placeholder="文件名称" style="width: 541px"></el-input>
          <el-upload class="custom-upload" :file-list="fileList"
                     action="javascript:void(0);" ref="uploadFile"
                     :on-change="onChange" :on-close="closeFileUpdate"
                     multiple :auto-upload="false"
                     style="text-align: left;margin-top: 0px;margin-left: 6px;display: none;">
          </el-upload>
        </el-form-item>
      </el-form>
      <el-table
        :height="height - 200"
        :data="projectConfirmatorFileList"
        border
        style="width: 100%;margin-top: 17px;margin-left: 0px;">
        <el-table-column
          prop="fileName"
          header-align="center"
          align="center"
          min-width="120"
          label="文件名">
        </el-table-column>
        <el-table-column
          prop="createDate"
          header-align="center"
          align="center"
          min-width="80"
          label="上传时间">
        </el-table-column>
        <el-table-column
          prop="createdBy"
          header-align="center"
          align="center"
          min-width="60"
          label="上传人">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" style="margin-top: 0px">
        <el-button type="primary" @click="saveUploadFile()">确定</el-button>
        <el-button @click="closeUploadFileVisible()">关闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="查看附件" @close="closeViewDocumentFileVisible" :visible.sync="viewDocumentFileVisible" width="520px" style="margin-top: 0vh" :close-on-click-modal="false">
      <el-table
        :height="height + 200"
        :data="projectConfirmatorFileList"
        border
        style="width: 100%;margin-top: 0px;margin-left: 0px;">
        <el-table-column
          prop="fileName"
          header-align="center"
          align="center"
          min-width="120"
          label="文件名">
        </el-table-column>
        <el-table-column
          prop="createDate"
          header-align="center"
          align="center"
          min-width="80"
          label="上传时间">
        </el-table-column>
        <el-table-column
          prop="createdBy"
          header-align="center"
          align="center"
          min-width="50"
          label="上传人">
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          width="100"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" @click="viewFile(scope.row)">查看</a>
            <a type="text" size="small" @click="downloadFile(scope.row)">下载</a>
            <a type="text" size="small" @click="deleteFile(scope.row)">删除</a>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" style="margin-top: 0px">
        <el-button @click="closeViewDocumentFileVisible()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
  searchProjectUploadsDocumentList,
  searchProjectOverUploadsDocumentList,
  searchConfirmProgressList,
  searchOverConfirmProgressList,
  searchAllConfirmProgressList,
  queryOverConfirmProgressList,
  queryConfirmProgressList, queryAllConfirmProgressList
} from "../../../api/eam/eamProofing";
import {
  deleteProjectFile,
  searchConfirmProgressPusherList,
  searchProjectConfirmatorFileList, updateProjectDocumentConfirm, uploadProjectFile
} from "../../../api/eam/eamProject";
import {downLoadObjectFile} from "../../../api/eam/eam_object_list";
import {getSiteAndBuByUserName} from "../../../api/qc/qc";
import {removeUserFavorite, saveUserFavorite, userFavoriteList} from "../../../api/userFavorite";
import {getTableDefaultListLanguage, getTableUserListLanguage} from "../../../api/table";
import moment from "moment/moment";
import {EventBus} from "../../../main";

export default {

  computed: {
    projectOwnersList() {
      return this.allPersonnelInfoList.filter(item => item.projectOwnerId !== undefined);
    },
    projectManagersList() {
      return this.allPersonnelInfoList.filter(item => item.projectManagerId !== undefined);
    },
    engineersList() {
      return this.allPersonnelInfoList.filter(item => item.engineerId !== undefined);
    }
  },

  data() {
    return {
      // 导出
      exportData: [],
      exportName: '待文档确认' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['待文档确认'],
      exportFooter: [],
      dataList: [],
      confirmProgressList: [],
      projectConfirmatorFileList: [],
      fileList: [],
      height: 200,
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      fileName:'',
      dataListLoading: false,
      viewDocumentFileVisible: false,
      confirmVisible: false,
      selectTypeFlag: [],
      searchData: {
        site: this.$store.state.user.site,
        userId: this.$store.state.user.id,
        projectId: '',
        projectNo: '',
        projectDesc: '',
        projectPartId: '',
        testPartNo: '',
        partDesc: '',
        customerNo: '',
        customerDesc: '',
        buDesc: '',
        projectCategory: '',
        status: '',
        startDate:'',
        endDate:'',
        projectCreationDate: new Date(),
        projectCloseDate:'',
        needDate:'',
        projectManager:'',
        projectOwner:'',
        engineer:'',
        confirmFlag:'N',
        page: 1,
        limit: 10,
      },
      modalData:{
        flag:'',
        id:'',
        bu: '',
        buNo: '',
        site: this.$store.state.user.site,
        projectId: '',
        oriProjectId: '',
        projectDesc:'',
        projectCloseDate:'',
        proofingNo:'',
        needDate:'',
        customerNo:'',
        finalCustomerId:'',
        customerDesc:'',
        projectCategory:'',
        testPartNo:'',
        partDesc:'',
        priority:'',
        projectManager:'',
        projectManagerName:'',
        projectOwner:'',
        projectOwnerName:'',
        cProjectRegion:'',
        cProjectBuildDate:'',
        cQualityEngineer1:'',
        cQualityEngineer1Name:'',
        cQualityEngineer2:'',
        cQualityEngineer2Name:'',
        cQualityEngineer3:'',
        cQualityEngineer3Name:'',
        cQualityEngineer4:'',
        cQualityEngineer4Name:'',
        cQualityEngineer5:'',
        cQualityEngineer5Name:'',
        cQualityEngineer6:'',
        cQualityEngineer6Name:'',
        cManufactureEngineer:'',
        cManufactureEngineerName:'',
        engineer:'',
        engineerName:'',
        docEngineer:'',
        docEngineerName:'',
        //projectCreationDate为当前服务器的时间
        projectCreationDate: new Date(),
        finalPartNo:'',
        finalPartDesc:'',
        wantedConfirmDate: new Date(),
        // active:'',
        createBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
      },
      confirmData:{
        site: '',
        projectId: '',
        orderRef1: '',
        orderRef2: '',
        documentId: '',
        documentType: '',
        itemNo: '',
        userid: '',
        wantedConfirmDate: '',
        confirmFlag: '',
        confirmedBy: '',
        remark: '',
        confirmedDate: '',
        createDate: '',
        createBy: '',
        page: 1,
        limit: 1000
      },
      columnProjectList: [
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1BuDesc',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          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: 401007,
          serialNumber: '401007Table1ProjectId',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'projectNo',
          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: 401007,
          serialNumber: '401007Table1ProjectDesc',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'projectDesc',
          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: 401007,
          serialNumber: '401007Table1TestPartNo',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'testPartNo',
          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: 401007,
          serialNumber: '401007Table1PartDesc',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'partDesc',
          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: 401007,
          serialNumber: '401007Table1customerNo',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: "customerNo",
          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: 401007,
          serialNumber: '401007Table1customerDesc',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: "customerDesc",
          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: 401007,
          serialNumber: '401007Table1BuildDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: "buildDate",
          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: 401007,
          serialNumber: '401007Table1ProjectCategory',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'projectCategory',
          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: 401007,
          serialNumber: '401007Table1Priority',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'priority',
          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: 401007,
          serialNumber: '401007Table1CProjectRegion',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cProjectRegion',
          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: 401007,
          serialNumber: '401007Table1ProjectManager',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'projectManagerName',
          headerAlign: "center",
          align: "left",
          columnLabel: 'PM/Sales',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1ProjectOwner',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'projectOwnerName',
          headerAlign: "center",
          align: "left",
          columnLabel: 'PjM',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1Engineer',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'engineerName',
          headerAlign: "center",
          align: "left",
          columnLabel: 'Engineer',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer1',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer1Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'IPQC-Lam/Pri/Etch/Slit',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer2',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer2Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'IPQC-Converting',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer3',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer3Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'FQC1',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer5',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer5Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'FQC2',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer6',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer6Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'IQC',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer6',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer6Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'IQC',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CManufactureEngineer',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cManufactureEngineerName',
          headerAlign: "center",
          align: "left",
          columnLabel: 'MFG',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CQualityEngineer4',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'cQualityEngineer4Name',
          headerAlign: "center",
          align: "left",
          columnLabel: 'SQE',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1DocEngineer',
          tableId: "401007Table1",
          tableName: "项目信息待上传文件表",
          columnProp: 'docEngineerName',
          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: 401007,
          serialNumber: '401007Table1Status',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'status',
          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: 401007,
          serialNumber: '401007Table1NeedDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'needDate',
          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: 401007,
          serialNumber: '401007Table1CloseDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'closeDate',
          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: 401007,
          serialNumber: '401007Table1FinalPartNo',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'finalPartNo',
          headerAlign: "center",
          align: "left",
          columnLabel: 'ERP正式料号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1UserDisplay',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'userDisplay',
          headerAlign: "center",
          align: "center",
          columnLabel: '指定确认人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1WantedConfirmDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'wantedConfirmDate',
          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: 401007,
          serialNumber: '401007Table1ConfirmFlag',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'confirmFlag',
          headerAlign: "center",
          align: "center",
          columnLabel: '是否确认',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1ConfirmedBy',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'confirmedBy',
          headerAlign: "center",
          align: "center",
          columnLabel: '实际确认人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1Remark',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'remark',
          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: 401007,
          serialNumber: '401007Table1ConfirmedDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'confirmedDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '实际确认时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CreateDate',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'createDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '推送时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 401007,
          serialNumber: '401007Table1CreateBy',
          tableId: "401007Table1",
          tableName: "项目信息待文档确认表",
          columnProp: 'createBy',
          headerAlign: "center",
          align: "center",
          columnLabel: '推送人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70,
        },
      ],
      userBuList: [],
      projectCategoryList: [
        {
          projectCategory: 'Low Risk',
        },
        {
          projectCategory: 'High Risk',
        },
        {
          projectCategory: 'Sustaining',
        }
      ],
      statusList: [
        {
          status: '草稿',
        },
        {
          status: '进行中',
        },
        {
          status: '已量产',
        }
      ],
      allPersonnelInfoList: [],
    };
  },
  created() {
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    // 校验用户是否收藏
    this.favoriteIsOk()
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
    this.getDataList()
  },
  activated() {
    if (this.$route.query.flag) {
      this.getDataList()
    }
    this.$store.commit("sift/commitSearchFunction",this.queryConfirmProgressList)
  },
  mounted () {
    this.$nextTick(() => {
      this.height = window.innerHeight - 200
    })
    EventBus.$on('updateAgencyMatterForConfirm', () => {
      this.getDataList();
    });
  },
  methods: {
    // 获取用户的bu
    getSiteAndBuByUserName () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    //导出excel
    async createExportData () {
      this.searchData.limit = -1
      this.searchData.page = 1
      await searchAllConfirmProgressList(this.searchData).then(({data}) => {
        this.exportList = data.page.list
        this.exportList.forEach((item) => {
          item.projectManagerName = item.projectManager.split('-')[1];
          item.projectOwnerName = item.projectOwner.split('-')[1];
          item.engineerName = item.engineer.split('-')[1];
          item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1];
          item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1];
          item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1];
          item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1];
          if (item.cQualityEngineer4 !== null && item.cQualityEngineer4 !== ''){
            item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1];
          }
          if (item.cQualityEngineer5 !== null && item.cQualityEngineer5 !== ''){
            item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1];
          }
          if (item.cQualityEngineer6 !== null && item.cQualityEngineer6 !== ''){
            item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1];
          }
          if (item.docEngineer !== null && item.docEngineer !== ''){
            item.docEngineerName = item.docEngineer.split('-')[1];
          }
        });

        for (let i = 0; i < this.exportList.length; i++) {
          if (this.exportList[i].responsibleDepartment === 'R001') {
            this.exportList[i].projectLeader = this.exportList[i].projectManager.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R002') {
            this.exportList[i].projectLeader = this.exportList[i].projectOwner.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R004') {
            this.exportList[i].projectLeader = this.exportList[i].engineer.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R005') {
            this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer1.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R007') {
            this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer2.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R008') {
            this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer3.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R009') {
            this.exportList[i].projectLeader = this.exportList[i].cManufactureEngineer.split("-")[1];
          } else if (this.exportList[i].responsibleDepartment === 'R011') {
            if (this.exportList[i].cQualityEngineer4 !== null && this.exportList[i].cQualityEngineer4 !== '') {
              this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer4.split("-")[1];
            }
          } else if (this.exportList[i].responsibleDepartment === 'R012') {
            if (this.exportList[i].docEngineer !== null && this.exportList[i].docEngineer !== '') {
              this.exportList[i].projectLeader = this.exportList[i].docEngineer.split("-")[1];
            }
          } else if (this.exportList[i].responsibleDepartment === 'R013') {
            if (this.exportList[i].cQualityEngineer5 !== null && this.exportList[i].cQualityEngineer5 !== '') {
              this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer5.split("-")[1];
            }
          } else if (this.exportList[i].responsibleDepartment === 'R014') {
            if (this.exportList[i].cQualityEngineer6 !== null && this.exportList[i].cQualityEngineer6 !== '') {
              this.exportList[i].projectLeader = this.exportList[i].cQualityEngineer6.split("-")[1];
            }
          }
        }
      })
      return this.exportList
    },
    startDownload () {},
    finishDownload () {},
    fields () {
      let json = "{"
      this.columnProjectList.forEach((item, index) => {
        if (index == this.columnProjectList.length - 1) {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
        } else {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
        }
      })
      json += "}"
      let s = eval("(" + json + ")")
      return s
    },

    // 获取数据列表
    getDataList (params) {
      this.selectTypeFlag = params
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      if (this.$route.query.flag === '4') {
        searchOverConfirmProgressList(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.allPersonnelInfoList = data.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            this.dataList.forEach((item) => {
              item.projectManagerName = item.projectManager.split('-')[1]
              item.projectOwnerName = item.projectOwner.split('-')[1]
              item.engineerName = item.engineer.split('-')[1]
              item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
              item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
              item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
              item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
              if (item.docEngineer === null || item.docEngineer === ''){
                item.docEngineerName = ''
              } else {
                item.docEngineerName = item.docEngineer.split('-')[1]
              }
              if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                item.cQualityEngineer4Name = ''
              } else {
                item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
              }
              if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                item.cQualityEngineer5Name = ''
              } else {
                item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
              }
              if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                item.cQualityEngineer6Name = ''
              } else {
                item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
              }
            })
          }
          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      } else if (this.$route.query.flag === '3') {
        searchConfirmProgressList(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.allPersonnelInfoList = data.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            this.dataList.forEach((item) => {
              item.projectManagerName = item.projectManager.split('-')[1]
              item.projectOwnerName = item.projectOwner.split('-')[1]
              item.engineerName = item.engineer.split('-')[1]
              item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
              item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
              item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
              item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
              if (item.docEngineer === null || item.docEngineer === ''){
                item.docEngineerName = ''
              } else {
                item.docEngineerName = item.docEngineer.split('-')[1]
              }
              if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                item.cQualityEngineer4Name = ''
              } else {
                item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
              }
              if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                item.cQualityEngineer5Name = ''
              } else {
                item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
              }
              if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                item.cQualityEngineer6Name = ''
              } else {
                item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
              }
            })
          }
          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      }else {
        searchAllConfirmProgressList(this.searchData).then(({data}) => {
          if (data.code === 0) {
            let pjmList = []
            // 遍历data.page.list
            data.list.forEach((item) => {
              if (!pjmList.includes(item.projectOwner.split('-')[0])) {
                pjmList.push(item.projectOwner.split('-')[0])
              }
            })
            if (pjmList.includes(this.$store.state.user.name)) {
              this.dataList = data.page.list
              this.allPersonnelInfoList = data.list
              this.pageIndex = data.page.currPage
              this.pageSize = data.page.pageSize
              this.totalPage = data.page.totalCount
              this.dataList.forEach((item) => {
                item.projectManagerName = item.projectManager.split('-')[1]
                item.projectOwnerName = item.projectOwner.split('-')[1]
                item.engineerName = item.engineer.split('-')[1]
                item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
                item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
                item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
                item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
                if (item.docEngineer === null || item.docEngineer === ''){
                  item.docEngineerName = ''
                } else {
                  item.docEngineerName = item.docEngineer.split('-')[1]
                }
                if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                  item.cQualityEngineer4Name = ''
                } else {
                  item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
                }
                if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                  item.cQualityEngineer5Name = ''
                } else {
                  item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
                }
                if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                  item.cQualityEngineer6Name = ''
                } else {
                  item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
                }
              })
            }
          } else {
            this.$route.query.flag = '3'
          }

          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      }
    },

    queryConfirmProgressList (params) {
      this.selectTypeFlag = params
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      if (params !== null && params !== undefined) {
        params.limit = this.pageSize
        params.page = this.pageIndex
        params.site = this.$store.state.user.site
        params.userName = this.$store.state.user.name
      } else {
        params = this.searchData
      }
      if (this.$route.query.flag === '4') {
        queryOverConfirmProgressList(params).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.allPersonnelInfoList = data.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            this.dataList.forEach((item) => {
              item.projectManagerName = item.projectManager.split('-')[1]
              item.projectOwnerName = item.projectOwner.split('-')[1]
              item.engineerName = item.engineer.split('-')[1]
              item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
              item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
              item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
              item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
              if (item.docEngineer === null || item.docEngineer === ''){
                item.docEngineerName = ''
              } else {
                item.docEngineerName = item.docEngineer.split('-')[1]
              }
              if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                item.cQualityEngineer4Name = ''
              } else {
                item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
              }
              if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                item.cQualityEngineer5Name = ''
              } else {
                item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
              }
              if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                item.cQualityEngineer6Name = ''
              } else {
                item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
              }
            })
          }
          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      } else if (this.$route.query.flag === '3') {
        queryConfirmProgressList(params).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.allPersonnelInfoList = data.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            this.dataList.forEach((item) => {
              item.projectManagerName = item.projectManager.split('-')[1]
              item.projectOwnerName = item.projectOwner.split('-')[1]
              item.engineerName = item.engineer.split('-')[1]
              item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
              item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
              item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
              item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
              if (item.docEngineer === null || item.docEngineer === ''){
                item.docEngineerName = ''
              } else {
                item.docEngineerName = item.docEngineer.split('-')[1]
              }
              if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                item.cQualityEngineer4Name = ''
              } else {
                item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
              }
              if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                item.cQualityEngineer5Name = ''
              } else {
                item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
              }
              if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                item.cQualityEngineer6Name = ''
              } else {
                item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
              }
            })
          }
          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      }else {
        queryAllConfirmProgressList(params).then(({data}) => {
          if (data.code === 0) {
            // let pjmList = []
            // 遍历data.page.list
            // data.list.forEach((item) => {
            //   if (item.projectOwner !== null && item.projectOwner !== ''){
            //     if (!pjmList.includes(item.projectOwner.split('-')[0])) {
            //       pjmList.push(item.projectOwner.split('-')[0])
            //     }
            //   }
            // })
            // if (pjmList.includes(this.$store.state.user.name)) {
              this.dataList = data.page.list
              this.pageIndex = data.page.currPage
              this.pageSize = data.page.pageSize
              this.totalPage = data.page.totalCount
              this.dataList.forEach((item) => {
                item.projectManagerName = item.projectManager.split('-')[1]
                item.projectOwnerName = item.projectOwner.split('-')[1]
                item.engineerName = item.engineer.split('-')[1]
                item.cQualityEngineer1Name = item.cQualityEngineer1.split('-')[1]
                item.cQualityEngineer2Name = item.cQualityEngineer2.split('-')[1]
                item.cQualityEngineer3Name = item.cQualityEngineer3.split('-')[1]
                item.cManufactureEngineerName = item.cManufactureEngineer.split('-')[1]
                if (item.docEngineer === null || item.docEngineer === ''){
                  item.docEngineerName = ''
                } else {
                  item.docEngineerName = item.docEngineer.split('-')[1]
                }
                if (item.cQualityEngineer4 === null || item.cQualityEngineer4 === ''){
                  item.cQualityEngineer4Name = ''
                } else {
                  item.cQualityEngineer4Name = item.cQualityEngineer4.split('-')[1]
                }
                if (item.cQualityEngineer5 === null || item.cQualityEngineer5 === ''){
                  item.cQualityEngineer5Name = ''
                } else {
                  item.cQualityEngineer5Name = item.cQualityEngineer5.split('-')[1]
                }
                if (item.cQualityEngineer6 === null || item.cQualityEngineer6 === ''){
                  item.cQualityEngineer6Name = ''
                } else {
                  item.cQualityEngineer6Name = item.cQualityEngineer6.split('-')[1]
                }
              })
            // }
          } else {
            this.$route.query.flag = '3'
          }

          // 获取全部人员信息用于下拉框
          this.getAllPersonnelList()
        })
      }
    },

    // 获取全部人员信息用于下拉框
    getAllPersonnelList() {

      let allPersonnelInfoDataList = JSON.parse(JSON.stringify(this.allPersonnelInfoList))

      // 找出所有的同时过滤出唯一的 project owners, managers, and engineers
      const allPersonnelList = [];
      const projectOwnersMap = new Map();
      const projectManagersMap = new Map();
      const engineersMap = new Map();

      allPersonnelInfoDataList.forEach((item) => {
        // Handle project owners
        if (!projectOwnersMap.has(item.projectOwner)) {
          const projectOwnerId = projectOwnersMap.size + 1;  // Incrementing by +1
          projectOwnersMap.set(item.projectOwner, {
            projectOwnerId,
            projectOwner: item.projectOwner,
            projectOwnerName: item.projectOwner.split('-')[1]
          });
          allPersonnelList.push(projectOwnersMap.get(item.projectOwner));
        }

        // Handle project managers
        if (!projectManagersMap.has(item.projectManager)) {
          const projectManagerId = projectManagersMap.size + 1;
          projectManagersMap.set(item.projectManager, {
            projectManagerId,
            projectManager: item.projectManager,
            projectManagerName: item.projectManager.split('-')[1]
          });
          allPersonnelList.push(projectManagersMap.get(item.projectManager));
        }

        // Handle engineers
        if (!engineersMap.has(item.engineer)) {
          const engineerId = engineersMap.size + 1;
          engineersMap.set(item.engineer, {
            engineerId,
            engineer: item.engineer,
            engineerName: item.engineer.split('-')[1]
          });
          allPersonnelList.push(engineersMap.get(item.engineer));
        }
      });

      this.allPersonnelInfoList = allPersonnelList;
    },

    toMes (row) {
      this.$router.push({ path: 'eam-eamProjectPartInfo', query: { projectNo: row.projectNo, testPartNo: row.testPartNo }})
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      if (this.selectTypeFlag !== null && this.selectTypeFlag !== undefined) {
        this.queryConfirmProgressList(this.selectTypeFlag)
      } else {
        this.getDataList()
      }
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      if (this.selectTypeFlag !== null && this.selectTypeFlag !== undefined) {
        this.queryConfirmProgressList(this.selectTypeFlag)
      } else {
        this.getDataList()
      }
    },

    viewDocumentFile(row) {
      this.confirmData = {
        site: row.site,
        documentType: row.documentType,
        orderRef1: row.orderRef1,
        orderRef2: row.orderRef2,
        itemNo: row.itemNo,
        userid: row.userid,
        username: row.username,
        userDisplay: row.userDisplay,
        wantedConfirmDate: row.wantedConfirmDate,
        confirmFlag: row.confirmFlag,
        confirmedDate: new Date(),
        createBy: row.createBy,
        createDate: row.createDate,
        confirmedBy: this.$store.state.user.userDisplay,
        documentId: row.documentId,
        remark: row.remark
      }
      let inData = {
        orderRef1: row.site,
        orderRef2: row.itemNo,
        orderRef3: row.userid,
        orderRef4: row.orderRef1,
        orderRef5: row.orderRef2,
        page: 1,
        limit: 1000
      }
      searchProjectConfirmatorFileList(inData).then(({data}) => {
        if (data && data.code === 0){
          this.projectConfirmatorFileList = data.page.list;
        }
      })
      this.viewDocumentFileVisible = true
    },
    closeViewDocumentFileVisible(){
      this.viewDocumentFileVisible = false;
      this.projectConfirmatorFileList = [];
    },
    // 查看文件
    viewFile(row) {
      // 预览文件
      let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
      let video = ['mp4', 'avi', 'mov', 'wmv', 'flv']
      let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
      let txt = ['txt']
      let type = ''
      let pdf = ['pdf']
      if (image.includes(row.fileType.toLowerCase())) {
        type = 'image/' + row.fileType
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          // 在新标签页中打开文件预览
          const newTab = window.open(fileURL, '_blank')
        })
      }
      else if (video.includes(row.fileType.toLowerCase())) {
        type = 'video/' + row.fileType
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          // 在新标签页中打开文件预览
          const newTab = window.open(fileURL, '_blank')
        })
      }
      else if (txt.includes(row.fileType.toLowerCase())) {
        type = 'text/plain'
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          // 在新标签页中打开文件预览
          const newTab = window.open(fileURL, '_blank')
        })
      }
      else if (office.includes(row.fileType.toLowerCase())) {
        if (row.fileType.toLowerCase() === 'doc' || row.fileType.toLowerCase() === 'docx') {
          type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        } else if (row.fileType.toLowerCase() === 'ppt' || row.fileType.toLowerCase() === 'pptx') {
          type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
        } else {
          type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        }
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          // 在新标签页中打开文件预览
          const newTab = window.open(fileURL, '_blank')
        })
      }
      else if (pdf.includes(row.fileType.toLowerCase())) {
        type = 'application/pdf'
        downLoadObjectFile(row).then(({data}) => {
          const blob = new Blob([data], { type: type });
          // 创建URL来生成预览
          const fileURL = URL.createObjectURL(blob);
          // 在新标签页中打开文件预览
          const newTab = window.open(fileURL, '_blank')
        })
      }
      else {
        this.$message({
          message: '不支持的文件类型',
          type: 'warning'
        })
      }
    },
    // 下载
    downloadFile (row) {
      downLoadObjectFile(row)
        .then(({data}) => {
          // 不限制文件下载类型
          const blob = new Blob([data], {type:'application/octet-stream;charset=utf-8'})
          // 下载文件名称
          const fileName = row.fileName
          // a标签下载
          const linkNode = document.createElement('a')
          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
        })
    },
    deleteFile(row) {
      if (this.confirmData.confirmedBy === this.$store.state.user.userDisplay) {
        this.$confirm('是否删除该文件?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let inData = {
            id: row.id,
            orderRef1: row.orderRef1,
            orderRef2: row.orderRef2,
            orderRef3: row.orderRef3,
            orderRef4: row.orderRef4,
            orderRef5: row.orderRef5,
            createdBy: this.$store.state.user.name
          }
          deleteProjectFile(inData).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '删除成功',
                type: 'success'
              })
              this.getProjectConfirmatorFileList(this.confirmData)
            } else {
              this.$message({
                message: '删除失败',
                type: 'error'
              })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      } else {
        this.$message({
          message: '只有确认人员才能删除文件',
          type: 'error'
        })
      }
    },
    confirmDocument(row) {
      this.confirmData = {
        site: row.site,
        documentType: row.documentType,
        orderRef1: row.orderRef1,
        orderRef2: row.orderRef2,
        itemNo: row.itemNo,
        userid: row.userid,
        username: row.username,
        userDisplay: row.userDisplay,
        wantedConfirmDate: row.wantedConfirmDate,
        confirmFlag: row.confirmFlag,
        confirmedDate: new Date(),
        createBy: row.createBy,
        createDate: row.createDate,
        confirmedBy: this.$store.state.user.userDisplay,
        documentId: row.documentId,
        remark: row.remark
      }
      this.modalData = {
        site: row.site,
        projectId: row.projectId,
        projectNo: row.projectNo,
        projectDesc: row.projectDesc,
        projectPartId: row.projectPartId,
        testPartNo: row.testPartNo,
        partDesc: row.partDesc,
        customerNo: row.customerNo,
        customerDesc: row.customerDesc,
        buNo: row.buNo,
        bu: row.site + '_' + row.buNo,
        cProjectTypeDb: row.projectCategory,
      }
      this.getProjectConfirmatorFileList(row)
      this.confirmVisible = true
    },

    getProjectConfirmatorFileList (row) {
      let inData = {
        orderRef1: row.site,
        orderRef3: row.userid,
        orderRef2: row.itemNo,
        orderRef4: row.orderRef1,
        orderRef5: row.orderRef2,
        page: 1,
        limit: 1000
      }
      searchProjectConfirmatorFileList(inData).then(({data}) => {
        if (data && data.code === 0){
          this.projectConfirmatorFileList = data.page.list;
        }
      })
    },

    closeUploadFileVisible(){
      this.confirmVisible = false;
      this.projectConfirmatorFileList = [];
      this.fileList = [];
      this.closeFileUpdate()
    },

    saveUploadFile(){
      this.confirmData.confirmedDate = moment(this.confirmData.confirmedDate).utcOffset('+8').format('YYYY-MM-DD HH:mm:ss');
      this.confirmData.confirmedBy = this.$store.state.user.userDisplay;
      this.confirmData.userid = this.$store.state.user.id;
      updateProjectDocumentConfirm(this.confirmData) .then(({data}) => {
        if (data.code === 0) {
          this.confirmVisible = false;
          this.getDataList();
          // 成功操作后触发事件
          EventBus.$emit('updateProjectPartInfo');
        }else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
      let remark = this.confirmData.remark;
      const formData = new FormData();
      //片接文件
      for (let i = 0; i < this.fileList.length; i++) {
        formData.append("file",this.fileList[i].raw)
      }
      formData.append("folder", 'projectPDConfirmFiles');
      formData.append("orderRef1", this.confirmData.site);
      formData.append("orderRef4", this.confirmData.orderRef1);
      formData.append("orderRef2", this.confirmData.itemNo);
      formData.append("orderRef3", this.confirmData.userid);
      formData.append("orderRef5", this.confirmData.orderRef2);
      formData.append("createdBy", this.$store.state.user.name);
      formData.append("updatedBy", this.$store.state.user.name);
      formData.append("remark", remark);
      uploadProjectFile(formData).then(({data}) => {
        if (data.code === 0) {
          this.$message.success('操作成功');
          //清空文件上传记录
          this.$refs.uploadFile.clearFiles();
          this.closeFileUpdate();
          this.projectConfirmatorFileList = [];
        }else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    closeFileUpdate() {
      this.fileName = '';
      this.uploadDialog = false;
      //this.fileRemark = ''
      this.$refs.uploadFile.clearFiles()
      this.fileList = []
    },

    /*选择上传文件时*/
    onChange(file,fileList){
      const newFileName = file.name;
      if (this.fileName) {
        this.fileName += ', ' + newFileName;
      } else {
        this.fileName = newFileName;
      }
      this.fileList.push(file);
    },

    triggerUpload() {
      this.$refs.uploadFile.$el.querySelector('input').click()
    },

    formatDate(row, column) {
      // row 是当前行的数据对象
      // column 是当前列的属性信息对象
      const date = row[column.property];
      if (date) {
        const s = new Date(date).toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' });
        return s.replace(/\//g, '-')
      } else {
        return '';
      }
    },
    rowStyle ({row}) {
    },
    getCombinedDocumentType(row) {
      // 根据您的需求，组合或拼接需要显示的字段
      if (row.documentType === null || row.documentType === undefined) {
        return row.documentDesc
      }else {
        return row.documentType
      }
    },
    // 校验用户是否收藏
    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
        })
      }
    },

    // 动态列开始 获取 用户保存的 格式列
    async getTableUserColumn(tableId, columnId) {
      let queryTableUser = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        status: true,
        languageCode: this.$i18n.locale
      }
      await getTableUserListLanguage(queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          //this.columnList1 = []
          switch (columnId) {
            case 1:
              this.columnProjectList = data.rows
              break;
            // case 2:
            //   this.detailColumnList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = 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.columnProjectList = data.rows
              break;
            // case 2:
            //   this.detailColumnList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = data.rows
            //   break;
          }
        } else {
          // this.showDefault = true.
        }
      })
    },
    //获取按钮的权限数据
    getButtonAuthData () {
      let searchFlag = this.isAuth(this.menuId+":search")
      let saveFlag = this.isAuth(this.menuId+":save")
      let updateFlag = this.isAuth(this.menuId+":update")
      let deleteFlag = this.isAuth(this.menuId+":delete")
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authSave = !saveFlag
      this.authUpdate = !updateFlag
      this.authDelete = !deleteFlag
    },
  },
};
</script>

<style scoped>

.red-text /deep/ .el-input__inner {
  color: red;
}

.card-item {
  cursor: pointer;
  margin-bottom: 20px;
  transition: transform 0.3s, box-shadow 0.3s;
  overflow: hidden;
  //padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  height: 208px;
  width: 230px;
  margin-left: 40px;
  margin-top: 10px;
}

.card-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
  margin-top: 20px;
}

.card-count {
  font-size: 55px;
  color: #17B3A3;
  text-align: center;
  font-weight: bold;
  margin-top: 50px;
}

.project-list {
  font-size: 12px;
  color: #333;
  line-height: 1.5;
  margin-bottom: 5px;
}

.el-divider {
  margin: 10px 0;
}
</style>
