<template>
  <div>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-row :gutter="10">
        <el-col :span="3">
          <el-form-item :label="'BU'">
            <el-select v-model="searchData.buNo" placeholder="请选择" clearable>
              <el-option v-for="i in userBuList" :key="i.buNo" :label="i.buDesc" :value="i.buNo">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="项目编码">
            <el-input v-model="searchData.projectNo"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="项目名称">
            <el-input v-model="searchData.projectName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="状态">
            <el-select v-model="searchData.sstatus" style="width: 100%">
              <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-col>
        <el-col :span="6">
          <el-form-item label="开始时间">
            <div style="display: flex">
              <el-date-picker style="width: 47%" v-model="searchData.startDate" type="date" value-format='yyyy-MM-dd'
                format='yyyy-MM-dd'></el-date-picker>
              <div style="width: 6%;text-align: center">-</div>
              <el-date-picker style="width: 47%" v-model="searchData.endDate" type="date" value-format='yyyy-MM-dd'
                format='yyyy-MM-dd'></el-date-picker>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label=" ">
            <el-button @click="getDataListAll">查 询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 询价列表 -->
    <el-table @header-dragend="handleColumnResize" height="30vh" :data="dataList" border ref="mainTable"
      highlight-current-row @row-click="projectClickRow" @current-change="changeCurrentRow" v-loading="dataListLoading"
      style="width: 100%;margin-top: 5px">
      <el-table-column type="index" width="55" align="center" label="序号"></el-table-column>
      <el-table-column v-for="(item,index) in columnList" :key="index" :sortable="item.columnSortable"
        :prop="item.columnProp" :header-align="item.headerAlign" :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed" :min-width="item.columnWidth" :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
              style="width: 100px; height: 80px" /></span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="180" label="操作">
        <template slot-scope="scope">
          <el-link style="cursor: pointer" v-if="scope.row.sstatus == '审核中'"
            @click="updateModal(scope.row)">审批</el-link>
          <!-- <el-link style="cursor: pointer" @click="updateModal(scope.row)">驳回</el-link> -->
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页插件 -->
    <el-pagination style="margin-top: 0px" @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-tabs style="margin-top: 0px; width: 100%; height: 100%;" v-model="activeTable" class="customer-tab"
      type="border-card" @tab-click="tabClick">
      <el-tab-pane label="项目预算" name="projectIncome">
        <!-- <el-form :inline="true" label-width="120px" label-position="top">
          <el-form-item label="Application">
            <el-input v-model="quoteCurrentRow.application" style="width: 210px" readonly></el-input>
          </el-form-item>
          <el-form-item label="Customer">
            <el-input v-model="quoteCurrentRow.customerDesc" readonly></el-input>
          </el-form-item>
          <el-form-item label="年需求量">
            <el-input v-model="quoteCurrentRow.annualDemand" class="right-aligned-input" readonly></el-input>
          </el-form-item>
          <el-form-item label="Cost Model">
            <el-input v-model="quoteCurrentRow.costModel" style="width: 210px" readonly></el-input>
          </el-form-item>
          <el-form-item label="Markup">
            <el-input v-model="quoteCurrentRow.markup" class="right-aligned-input" readonly></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-width="120px" label-position="top">
          <el-form-item label="备注">
            <el-input type="textarea" :rows="2" v-model="quoteCurrentRow.remark" style="width: 1019px"
              readonly></el-input>
          </el-form-item>
        </el-form> -->
        <MachineProjectIncome :projectIncome="projectIncome" :project="model" @IncomeFinished="getIncomeList"
          :auth-flag="true" :height="'33vh'"></MachineProjectIncome>
      </el-tab-pane>
      <el-tab-pane label="项目计划" name="projectPlan">
        <div style="height: 100%;overflow: auto;">
          <MachineProjectPlan :projectPlan="projectPlan" :project="model" @planFinished="getPlanList" :auth-flag="true"
            :height="'33vh'"></MachineProjectPlan>
        </div>
      </el-tab-pane>
      <el-tab-pane label="项目任务" name="projectTask">
        <div style="height: 100%;overflow: auto;">
          <MachineProjectTask :projectTask="projectTask" :project="model" @taskFinished="getTaskList" :auth-flag="true"
            :height="'33vh'"></MachineProjectTask>
        </div>
      </el-tab-pane>
      <el-tab-pane label="结案确认" name="projectClose">
        <div style="height: 100%;overflow: auto;">
          <MachineProjectCloseTable :projectClose="projectClose" :project="model" @taskFinished="getCloseList"
            :auth-flag="true" :height="'33vh'"></MachineProjectCloseTable>
        </div>
      </el-tab-pane>
      <el-tab-pane label="审核记录" name="projectAuth">
        <div style="height: 100%;overflow: auto;">
          <MachineProjectAuthTable :projectAuth="projectAuth" :project="model" @taskFinished="getAuthList"
            :auth-flag="true" :height="'33vh'"></MachineProjectAuthTable>
        </div>
      </el-tab-pane>
      <el-tab-pane label="相关文档" name="inquiryDocument">
        <div style="height: 100%;overflow: auto;">
          <oss-components ref="inquiryDocument" label="申请单号" style="margin-top: 5px" height="44vh" :columns="ossColumns"
            :disabled="false" :orderRef1="model.site" :orderRef2="model.objectId" :rfqNo="model.projectNo"
            :orderRef4="model.buNo" :orderRef5="model.id">
          </oss-components>
        </div>
      </el-tab-pane>
    </el-tabs>

    <el-dialog title="申请单审核" :visible.sync="reviewFlag" width="500px" :close-on-click-modal="false" v-drag top="10%">
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="申请单号">
              <el-input style="width:140%" disabled placeholder="" :value="modalData.projectNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审批步骤号">
              <el-input style="width:140%" disabled placeholder="" :value="modalData.stepId"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="审批人">
              <el-input style="width:140%" disabled placeholder="" :value="modalData.userName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审批时间">
              <el-input style="width:140%" disabled placeholder="" :value="modalData.strActAuthorizeDate"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" style="display: block;min-height: 90px">
              <el-input type="textarea" style="width:103%" :disabled="(modalData.canAuthFlag!=='Y') " :rows="3"
                v-model="modalData.authHistRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="( modalData.canAuthFlag === 'Y') " :loading="loading"
          @click="saveReview(modalData,'Y')">{{'同意'}}
        </el-button>
        <el-button type="primary" v-if="( modalData.canAuthFlag === 'Y') " :loading="loading"
          @click="saveReview(modalData ,'N')">{{'不同意'}}
        </el-button>
      </div>
    </el-dialog>

    <!-- chooseList模态框 -->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

  </div>
</template>
  
  <script>
import Chooselist from '@/views/modules/common/Chooselist_eam'
import { getSiteAndBuByUserName } from '../../../api/qc/qc'
import DictDataSelect from '../sys/dict-data-select.vue'
import OssComponents from '../oss/ossProjectComponents.vue'

import quotationUpload from '../quote/quotation_upload.vue'
import TpCost from '../quote/detail/tpCost.vue'
import QuoteDetail from '../quote/detail/quoteDetail.vue'
import {
  getTableDefaultListLanguage,
  getTableUserListLanguage,
  updateColumnSize,
} from '../../../api/table'
import {
  searchUserAuthMachineProjectApplicationInfo,
  updateProjectAuthHist,
  queryMachineProjectAuthList,
} from '../../../api/machine/machineProject'
import {
  queryMachineProjectIncomeList,
  queryMachineProjectPlanList,
  queryMachineProjectTaskList,
  queryMachineProjectCloseList,
} from '../../../api/machine/machineProjectIncome'
import MachineProjectIncome from '../machine/modules/machineProjectIncomeTable.vue'
import MachineProjectPlan from '../machine/modules/machineProjectPlanTable.vue'
import MachineProjectTask from '../machine/modules/machineProjectTaskTable.vue'
import MachineProjectCloseTable from '../machine/modules/machineProjectCloseTable.vue'
import MachineProjectAuthTable from '../machine/modules/machineProjectAuthTable.vue'

export default {
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      // 跳转后清除 redirectPath
      localStorage.removeItem('redirectPath')
      console.log('redirectPath 已清除')
    })
  },
  name: 'authMachineProject',
  computed: {},
  components: {
    QuoteDetail,
    TpCost,
    quotationUpload,
    DictDataSelect,
    Chooselist,
    MachineProjectIncome,
    MachineProjectPlan,
    MachineProjectTask,
    MachineProjectCloseTable,
    MachineProjectAuthTable,
    OssComponents,
  },
  props: {},
  data() {
    return {
      userBuList: [],
      projectIncome: [],
      projectPlan: [],
      projectTask: [],
      projectClose: [],
      projectAuth: [],
      model: {},
      loading: false,
      attributeDialog: true,
      priceCheckRule: {
        associatedPartNo: [{ required: true, message: ' ', trigger: 'change' }],
        materialRequired: [{ required: true, message: ' ', trigger: 'change' }],
        yearlyOrMonthlyRequirement: [
          { required: true, message: ' ', trigger: 'change' },
        ],
        runningWidth: [{ required: true, message: ' ', trigger: 'change' }],
      },
      savePriceDetail: {
        site: '',
        quotationNo: '',
        associatedPartNo: '',
        materialRequired: '',
        yearlyOrMonthlyRequirement: '',
        runningWidth: '',
      },
      priceCheckPropertiesList: [],
      // 导出
      exportData: [],
      exportName: '询价申请' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['询价申请'],
      exportFooter: [],
      resultList: [],
      uploadUrl: '/plm/quotationInformation/uploadExcel',
      // ======== 行高 ========
      secondHeight: 200,
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      selectedDataNum: 0,
      ossColumns: [
        {
          userId: this.$store.state.user.name,
          functionId: 101506001001,
          serialNumber: '101506001001Table2FileName',
          tableId: '101506001001Table2',
          tableName: '文件信息表',
          columnProp: 'fileName',
          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: 101506001001,
          serialNumber: '101506001001Table2FileRemark',
          tableId: '101506001001Table2',
          tableName: '文件信息表',
          columnProp: 'cadditionalInfo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 240,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101506001001,
          serialNumber: '101506001001Table2CreateDate',
          tableId: '101506001001Table2',
          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: 101506001001,
          serialNumber: '101506001001Table2CreatedBy',
          tableId: '101506001001Table2',
          tableName: '文件信息表',
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
      ],
      // 条件查询
      searchData: {
        userId: this.$store.state.user.id,
        site: this.$store.state.user.site,
        id: '',
        customerNo: '',
        customerDesc: '',
        projectNo: '',
        buNo: '',
        requestStartDate: '',
        requestEndDate: '',
        requiredCompletionStartDate: '',
        requiredCompletionEndDate: '',
        status: '',
        sstatus: '审核中',
        quoterName: '',
        requesterName: '',
        priorityLevel: '',
        orderRef1: 'PJ',
        page: 1,
        limit: 10,
        menuId: this.$route.meta.menuId,
      },
      searchData1: {
        userId: this.$store.state.user.id,
        site: this.$store.state.user.site,
        id: '',
        customerNo: '',
        customerDesc: '',
        projectNo: '',
        bu: '',
        requestStartDate: '',
        requestEndDate: '',
        requiredCompletionStartDate: '',
        requiredCompletionEndDate: '',
        status: '',
        quoterName: '',
        requesterName: '',
        priorityLevel: '',
        orderRef1: 'PJ',
        page: 1,
        limit: 10,
        menuId: this.$route.meta.menuId,
      },
      // 其它
      dataListLoading: false,
      // 选择项目弹框开关
      chooseProjectListFlag: false,
      reviewFlag: false,
      // 初始页签
      activeTable: 'projectIncome',
      // ======== 数据对象 ========
      modalData: {
        flag: '',
        title: '',
        site: this.$store.state.user.site,
        userName: this.$store.state.user.name,
        id: '',
        projectNo: '',
        customerNo: '',
        customerDesc: '',
        requestDate: '',
        requester: '',
        requesterName: '',
        customerInquiryNo: '',
        priorityLevel: '',
        requiredCompletionDate: '',
        quoter: '',
        quoterName: '',
        status: '',
        remark: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
        authHistId: '',
        approveResult: '',
        authHistRemark: '',
        canAuthFlag: '',
        actAuthorizator: '',
        strActAuthorizeDate: this.dayjs().format('YYYY-MM-DD HH:mm:ss'),
        actAuthorizeDate: '',
      },
      inquiryPartItemModalData: {
        bu: '',
        buDesc: '',
        projectNo: '',
        partNo: '',
        partDesc: '',
        umId: '',
        umName: '',
        codeNo: '',
        codeDesc: '',
        textValue: '',
        numValue: '',
        valueType: '',
        valueTypeDb: '',
        valueChooseFlag: '',
        availableValueList: [],
      },
      // ======== 数据列表 ========
      dataList: [],
      inquiryAuthDataList: [],
      // ======== 列表表头 ========
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 190006,
          serialNumber: '190006Table1BuDesc',
          tableId: '190006Table1',
          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: 190006,
          serialNumber: '190006Table1QuoteVersionNo',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'projectNo',
          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: 190006,
          serialNumber: '190006Table1QuoteDate',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'projectName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '项目名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 190006,
          serialNumber: '190006Table1CustomerNo',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'projectIncome',
          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: 190006,
          serialNumber: '190006Table1CustomerDesc',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'projectBudget',
          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: 190006,
          serialNumber: '190006Table1QuoterName',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'projectActualExpenses',
          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: 190006,
          serialNumber: '190006Table1PurchaseName',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'responsiblePerson',
          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: 190006,
          serialNumber: '190006Table1Currency',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'startDate',
          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: 190006,
          serialNumber: '190006Table1Currency',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'endDate',
          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: 190006,
          serialNumber: '190006Table1Status',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'sstatus',
          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: 190006,
          serialNumber: '190006Table1Status',
          tableId: '190006Table1',
          tableName: '报价审批表',
          columnProp: 'stepId',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '审批步骤号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
      ],
      // ======== 必填规则 ========
      rules: {
        bu: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        projectNo: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        customerNo: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        customerDesc: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        requester: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        requesterName: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        quoter: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        quoterName: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        priorityLevel: [{ required: true, message: ' ', trigger: 'change' }],
        requiredCompletionDate: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        requestDate: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
      },
      inquiryPartRules: {
        bu: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        partNo: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        partDesc: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        inquiryQty: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        umId: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
        codeNo: [
          { required: true, message: ' ', trigger: 'change' },
          { required: true, message: ' ', trigger: 'blur' },
        ],
      },
      // ======== 选中的当前行数据 ========
      projectCurrentRow: {},
      // ======== 模态框开关控制 ========
      modalFlag: false,
      modalDisableFlag: false,
      inquiryPartModalFlag: false,
      inquiryPartModalDisableFlag: false,
      inquiryPartItemModalFlag: false,
    }
  },
  mounted() {
    this.$nextTick(() => {
      /*第二个表格高度的动态调整*/
      this.height = window.innerHeight - 210
    })
  },
  created() {
    this.getSiteAndBuByUserName()
    // 获取 URL 查询参数
    const { projectNo } = this.$route.query
    // 将查询参数赋值给 searchData
    if (projectNo) {
      this.searchData1.projectNo = this.$route.query.projectNo
    }
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId + 'table1', 1)
    this.getDataList()
  },
  methods: {
    handleColumnResize(newWidth, oldWidth, column, event) {
      let inData = this.columnList.filter(
        (item) => item.columnProp === column.property
      )[0]
      inData.columnWidth = newWidth
      updateColumnSize(inData).then(({ data }) => {
        if (data.code === 0) {
          console.log('栏位宽度保存成功！')
        }
      })
    },
    // 获取用户的bu
    getSiteAndBuByUserName() {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({ data }) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },
    // ======== 分页相关方法 ========
    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    /**
     * 当前页
     * @param val
     */
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },

    // ======== 页签切换相关方法 ========
    /**
     * 列表表格选择替换
     * @param tab
     * @param event
     */
    tabClick(tab, event) {
      // 刷新列表数据
      this.refreshCurrentTabTable()
    },

    // ======== 列表操作方法 ========
    /**
     * 单机选中询价信息
     * @param row
     */
    projectClickRow(row) {
      this.projectCurrentRow = JSON.parse(JSON.stringify(row))
      this.model = JSON.parse(JSON.stringify(row))
      //刷新当前页表
      this.refreshCurrentTabTable()
    },
    /**
     * 当前值发生变化的时候修改
     * @param row
     * @param oldRow
     */
    changeCurrentRow(row, oldRow) {
      // 判断是否是获取焦点的事件
      if (row) {
        this.projectCurrentRow = JSON.parse(JSON.stringify(row))
      }
    },
    /**
     * 刷新页签的table数据
     */
    refreshCurrentTabTable() {
      this.getTabs()
    },

    // ======== 列表数据刷新方法 ========
    /**
     * 获取数据列表
     */
    getDataListAll() {
      this.searchData1 = null
      this.getDataList()
    },

    getDataList() {
      //console.log(this.searchData1)
      this.searchData.pageSize = this.pageSize
      this.searchData.pageNo = this.pageIndex
      let inData = this.searchData
      searchUserAuthMachineProjectApplicationInfo(inData).then(({ data }) => {
        if (data.code === 0) {
          this.dataList = data.page.records
          this.pageIndex = data.page.current
          this.pageSize = data.page.size
          this.totalPage = data.page.total
          this.dataList.forEach((item) => {
            if (item.groupDesc === '' || item.groupDesc === null) {
              item.auth = item.userDisplay
            } else {
              item.auth = item.groupDesc
            }
          })
          //判断是否全部存在数据
          if (this.totalPage > 0) {
            //设置选中行
            this.$refs.mainTable.setCurrentRow(this.dataList[0])
            this.projectClickRow(this.dataList[0])
            this.refreshCurrentTabTable() //加载当前的页签的table
          }
        }
        this.dataListLoading = false
      })
    },
    getTabs() {
      switch (this.activeTable) {
        case 'projectIncome':
          this.getIncomeList()
          break
        case 'projectPlan':
          this.getPlanList()
          break
        case 'projectTask':
          this.getTaskList()
          break
        case 'projectClose':
          this.getCloseList()
          break
        case 'projectAuth':
          this.getAuthList()
          break
        case 'inquiryDocument':
          this.$refs.inquiryDocument.handleQuery()
          break
        default:
          this.getIncomeList()
          break
      }
    },
    getIncomeList() {
      console.log('this.model.projectNo', this.model.projectNo)

      if (this.model.projectNo) {
        let obj = {
          projectNo: this.model.projectNo,
        }
        queryMachineProjectIncomeList(obj)
          .then(({ data }) => {
            if (data && data.code === 0) {
              this.projectIncome = data.list
              //判断是否全部存在数据
              //if (this.totalPage > 0) {
              //  this.$refs.mainTable.setCurrentRow(this.dataList[0])
              //  this.refreshCurrentTabTable()
              //  this.inquiryClickRow(this.dataList[0])
              //}
            } else {
              this.$message.warning(data.msg)
            }
            this.queryLoading = false
          })
          .catch((error) => {
            this.$message.error(error)
            this.queryLoading = false
          })
      }
    },
    incomeFinished() {
      this.getIncomeList()
    },
    getPlanList() {
      let obj = {
        projectNo: this.model.projectNo,
      }
      queryMachineProjectPlanList(obj)
        .then(({ data }) => {
          if (data && data.code === 0) {
            this.projectPlan = data.list
          } else {
            this.$message.warning(data.msg)
          }
          this.queryLoading = false
        })
        .catch((error) => {
          this.$message.error(error)
          this.queryLoading = false
        })
    },
    getTaskList() {
      let obj = {
        projectNo: this.model.projectNo,
      }
      queryMachineProjectTaskList(obj)
        .then(({ data }) => {
          if (data && data.code === 0) {
            this.projectTask = data.list
          } else {
            this.$message.warning(data.msg)
          }
          this.queryLoading = false
        })
        .catch((error) => {
          this.$message.error(error)
          this.queryLoading = false
        })
    },
    getCloseList() {
      let obj = {
        projectNo: this.model.projectNo,
      }
      queryMachineProjectCloseList(obj)
        .then(({ data }) => {
          if (data && data.code === 0) {
            this.projectClose = data.list
          } else {
            this.$message.warning(data.msg)
          }
          this.queryLoading = false
        })
        .catch((error) => {
          this.$message.error(error)
          this.queryLoading = false
        })
    },
    getAuthList() {
      let obj = {
        site: this.$store.state.user.site,
        projectNo: this.model.projectNo,
      }
      queryMachineProjectAuthList(obj)
        .then(({ data }) => {
          if (data && data.code === 0) {
            this.projectAuth = data.list
          } else {
            this.$message.warning(data.msg)
          }
          this.queryLoading = false
        })
        .catch((error) => {
          this.$message.error(error)
          this.queryLoading = false
        })
    },

    // /**
    //  * 获得这些询价号的全部附件
    //  */
    // getFileContentList () {
    //   let currentData = {
    //     orderRef1: this.$store.state.user.site,
    //     orderRef2: this.enterResultData.quotationNo
    //   }
    //   getFileContentList(currentData).then(({data}) => {
    //     if (data && data.code === 0) {
    //       this.enterResultData.fileContentList = data.rows
    //     } else {
    //       this.enterResultData.fileContentList = []
    //     }
    //   })
    // },

    // ======== chooseList相关方法 ========
    /**
     * 获取基础数据列表S
     * @param val
     * @param type
     */
    getBaseList(val, type) {
      this.tagNo = val
      this.tagNo1 = type
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (val === 509) {
          if (type === 1) {
            strVal = this.modalData.customerNo ? this.modalData.customerNo : ''
          }
          if (type === 2) {
            strVal = this.searchData.customerNo
              ? this.searchData.customerNo
              : ''
          }
        }
        if (val === 2002) {
          if (type === 1) {
            strVal = this.searchData.quoterName
              ? this.searchData.quoterName
              : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
          if (type === 2) {
            strVal = this.modalData.quoterName ? this.modalData.quoterName : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
        }
        if (val === 2008) {
          if (type === 1) {
            strVal = this.searchData.requesterName
              ? this.searchData.requesterName
              : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
          if (type === 2) {
            strVal = this.modalData.requesterName
              ? this.modalData.requesterName
              : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    /**
     * 列表方法的回调
     * @param val
     */
    getBaseData(val) {
      if (this.tagNo === 509) {
        if (this.tagNo1 === 1) {
          if (val.customer_no === this.modalData.customerNo) {
            return
          }
          this.modalData.customerNo = val.customer_no
          this.modalData.customerDesc = val.customer_desc
        }
        if (this.tagNo1 === 2) {
          if (val.customer_no === this.searchData.customerNo) {
            return
          }
          this.searchData.customerNo = val.customer_no
        }
      }
      if (this.tagNo === 2002) {
        if (this.tagNo1 === 1) {
          this.searchData.quoter = val.username
          this.searchData.quoterName = val.user_display
        }
        if (this.tagNo1 === 2) {
          this.modalData.quoter = val.username
          this.modalData.quoterName = val.user_display
        }
      }
      if (this.tagNo === 2008) {
        if (this.tagNo1 === 1) {
          this.searchData.requester = val.username
          this.searchData.requesterName = val.user_display
        }
        if (this.tagNo1 === 2) {
          this.modalData.requester = val.username
          this.modalData.requesterName = val.user_display
        }
      }
    },

    updateModal(row) {
      this.modalData = JSON.parse(JSON.stringify(row))
      this.modalData.strActAuthorizeDate = this.dayjs().format(
        'YYYY-MM-DD HH:mm:ss'
      )
      this.modalData.userName = this.$store.state.user.name
      this.reviewFlag = true
    },

    saveReview(row, val) {
      if (row.authHistRemark == '') {
        this.$alert(data.msg, '操作提示', {
          confirmButtonText: '确定',
          callback: (action) => {
            this.saveButton = false
          },
        })
      }
      this.loading = true
      this.modalData.id = row.authHistId
      this.modalData.actAuthorizator = row.userName
      this.modalData.remark = row.authHistRemark
      this.modalData.actAuthorizeDate = row.strActAuthorizeDate
      this.modalData.orderRef1 = row.projectNo
      if (val === 'Y') {
        if (row.lastStepFlag === 'Y') {
          this.modalData.approveResult = '已审批'
        } else {
          this.modalData.approveResult = '已审批'
        }
      } else if (val === 'N') {
        this.modalData.approveResult = '未通过'
      }
      updateProjectAuthHist(this.modalData).then(({ data }) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.reviewFlag = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {},
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定',
          })
        }
        this.loading = false
      })
    },

    // ======== 导出相关方法 ========
    /**
     * 导出excel
     */
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await searchUserAuthMachineProjectApplicationInfo(this.searchData).then(
        ({ data }) => {
          this.resultList = data.page.list
        }
      )
      return this.resultList
    },
    startDownload() {},
    finishDownload() {},
    fields() {
      let json = '{'
      this.columnList.forEach((item, index) => {
        if (index == this.columnList.length - 1) {
          json +=
            '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"'
        } else {
          json +=
            '"' +
            item.columnLabel +
            '"' +
            ':' +
            '"' +
            item.columnProp +
            '"' +
            ','
        }
      })
      json += '}'
      let s = eval('(' + json + ')')
      return s
    },
    // ========  导入相关方法 ========
    handleImportQuotation() {
      let currentData = {
        createBy: this.$store.state.user.name,
        site: this.$store.state.user.site,
      }
      //打开组件 去做新增业务
      this.$nextTick(() => {
        this.$refs.quotationUpload.init(currentData)
      })
    },

    // openSaveDataDialog(){
    //   if (this.modalData.title === '询价新增') {
    //     let rfqNos = [];
    //     this.dataList.forEach((item) => {
    //       // 如果item.rfqNo为XJ开头
    //       if (item.projectNo.startsWith('XJ')) {
    //         // 解析数字部分
    //         const numPart = parseInt(item.projectNo.replace('XJ', ''), 10);
    //         if (!isNaN(numPart)) {
    //           rfqNos.push(numPart);
    //         }
    //       }
    //     });
    //     if (rfqNos.length === 0) {
    //       // 如果没有XJ开头的rfqNo
    //       this.modalData.projectNo = 'XJ00000001';
    //     } else {
    //       // 取到最大的XJ开头的rfqNo
    //       let maxRfqNo = Math.max(...rfqNos);
    //
    //       // 生成新的rfqNo，确保有9位数，前面补零
    //       maxRfqNo += 1; // 增加最大值
    //       this.modalData.projectNo = 'XJ' + String(maxRfqNo).padStart(8, '0');
    //     }
    //   }
    // },
    // 保存弹框关闭事件
    closeSaveDataDialog() {
      this.modalData = {
        flag: '',
        title: '',
        site: '',
        bu: '',
        buNo: '',
        buDesc: '',
        id: '',
        projectNo: '',
        customerNo: '',
        customerDesc: '',
        requester: '',
        requesterName: '',
        quoter: '',
        quoterName: '',
        customerInquiryNo: '',
        status: '',
        priorityLevel: '',
        requestDate: '',
        requiredCompletionDate: '',
        remark: '',
      }
      this.modalFlag = false
    },
    rowStyle({ row }) {
      if (this.projectCurrentRow.id === row.id) {
        return { 'background-color': '#E8F7F6', cursor: 'pointer' }
      }
    },
    // 动态列开始 获取 用户保存的 格式列
    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
          }
        }
      })
    },
  },
}
</script>
  
<style scoped>
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
  height: 100%;
}

/deep/ .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  background-color: #17b3a3;
  border-color: #17b3a3;
}

/deep/ .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #fff;
}
/deep/ .el-form-item--medium .el-form-item__content {
  height: auto;
}

.el-input-number /deep/ .el-input__inner {
  text-align: right;
  padding-right: 5px !important;
}

/deep/ .el-input .el-input--medium {
  line-height: 20px;
}
/deep/ .el-input-number .el-input--medium {
  line-height: 20px;
}

/*table中input 修改样式*/
/deep/ div.table-el-date {
  padding: 0px 0px;
  height: 25px !important;
}

/*table中input*/
div.table-el-date /deep/ input.el-input__inner {
  padding: 0px 0px;
  height: 23px !important;
  text-align: right;
}

/* 特殊的样式*/
/deep/ .el-table div.cell:has(.table-el-date) {
  /* 直接作用于 <td> 元素 */
  padding: 0px;
  height: 25px;
}

.el-transfer-panel {
  border: 2px solid #17b3a3;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  display: inline-block;
  vertical-align: middle;
  width: 200px;
  max-height: 100%;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
}

.el-transfer-panel .el-transfer-panel__header {
  height: 40px;
  line-height: 40px;
  background: #17b3a3;
  margin: 0;
  padding-left: 15px;
  border-bottom: 1px solid #17b3a3;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  color: #000;
}

.el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
  font-size: 14px;
  color: #303133;
  font-weight: 400;
}
</style>