<template>
  <div class="mod-config">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" :model="searchData">
      <el-form-item label="序列号">
        <el-input v-model="searchData.referenceNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="单据状态">
        <el-select v-model="searchData.status" clearable style="width: 120px">
          <el-option label="草稿" value="草稿"></el-option>
          <el-option label="审批中" value="审批中"></el-option>
          <el-option label="已完成" value="已完成"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="RoHS状态">
        <el-select v-model="searchData.rohsStatus" clearable style="width: 120px">
          <el-option label="Active" value="Active"></el-option>
          <el-option label="Dead" value="Dead"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="节点审批人">
        <el-input v-model="searchData.currentApprover" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="当前节点">
        <el-select v-model="searchData.nodeId" placeholder="请选择节点" clearable style="width: 120px">
          <el-option
            v-for="option in nodeOptions"
            :key="option.id"
            :label="option.name"
            :value="option.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="authSearch" @click="getDataList">查询</el-button>
        <el-button v-if="authUpdate" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="authDelete" type="danger" @click="deleteHandle()">删除</el-button>
        <download-excel
          v-if="authSearch"
          :fields="exportFieldMap"
          :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', {'is-loading': exportLoading}]">
          <i v-if="exportLoading" class="el-icon-loading"></i>
          <span>{{ "导出" }}</span>
        </download-excel>
        <el-button v-if="authSearch" @click="searchHandle()">搜索</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表 -->
    <el-table
      ref="rohsTable"
      :height="height"
      :data="dataList"
      border
      :row-style="rowStyle"
      @row-click="changeClickRow"
      @current-change="currentChange"
      @selection-change="dataListSelectionChange"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="referenceNo" header-align="center" align="center" label="序列号" width="165"></el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="单据状态" width="120"></el-table-column>
      <el-table-column prop="nodeId" header-align="center" align="center" label="当前节点ID" width="130"></el-table-column>
      <el-table-column prop="nodeName" header-align="center" align="center" label="当前节点" width="150"></el-table-column>
      <el-table-column prop="currentApprover" header-align="center" align="center" label="当前节点审批人" width="170"></el-table-column>
      <el-table-column prop="applicant" header-align="center" align="center" label="申请人编码" width="130"></el-table-column>
      <el-table-column prop="applicantName" header-align="center" align="center" label="申请人名称" width="150"></el-table-column>
      <el-table-column prop="pm" header-align="center" align="center" label="PM编码" width="130"></el-table-column>
      <el-table-column prop="pmName" header-align="center" align="center" label="PM名称" width="150"></el-table-column>
      <el-table-column prop="applicationDate" header-align="center" align="center" label="申请日期" width="165"></el-table-column>
      <el-table-column prop="plannedMassProductionDate" header-align="center" align="center" label="计划转量产时间" width="165">
        <template slot-scope="scope">
          <span>{{ normalizeDateOnly(scope.row.plannedMassProductionDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="process" header-align="center" align="center" label="工艺" width="120"></el-table-column>
      <el-table-column prop="color" header-align="center" align="center" label="颜色" width="120"></el-table-column>
      <el-table-column prop="vendorCode" header-align="center" align="center" label="供应商" width="160"></el-table-column>
      <el-table-column prop="vendorMaterialCode" header-align="center" align="center" label="供应商材料编码" width="200" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="materialClassify" header-align="center" align="center" label="材料分类" width="200" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="otherMaterialClassify" header-align="center" align="center" label="其他材料分类" width="210" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="materialUseFor" header-align="center" align="center" label="辅材用途" width="180" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="endCustomer" header-align="center" align="center" label="最终客户编码" width="160"></el-table-column>
      <el-table-column prop="endCustomerName" header-align="center" align="center" label="最终客户名称" width="180"></el-table-column>
      <el-table-column prop="projectId" header-align="center" align="center" label="项目编码" width="140"></el-table-column>
      <el-table-column prop="projectName" header-align="center" align="center" label="项目名称" width="180"></el-table-column>
      <el-table-column prop="commGroup1" header-align="center" align="center" label="商品组1编码" width="170"></el-table-column>
      <el-table-column prop="commGroup1Desc" header-align="center" align="center" label="商品组1名称" width="170"></el-table-column>
      <el-table-column prop="commGroup2" header-align="center" align="center" label="商品组2编码" width="170"></el-table-column>
      <el-table-column prop="commGroup2Desc" header-align="center" align="center" label="商品组2名称" width="170"></el-table-column>
      <el-table-column prop="commGroup3" header-align="center" align="center" label="商品组3编码" width="170"></el-table-column>
      <el-table-column prop="commGroup3Desc" header-align="center" align="center" label="商品组3名称" width="170"></el-table-column>
      <el-table-column prop="needCreateNumber" header-align="center" align="center" label="需创建内部编号" width="200"></el-table-column>
      <el-table-column prop="npdEngineer" header-align="center" align="center" label="NPD工程师编码" width="170"></el-table-column>
      <el-table-column prop="npdEngineerName" header-align="center" align="center" label="NPD工程师名称" width="170"></el-table-column>
      <el-table-column prop="materialValidityTime" header-align="center" align="center" label="材料有效期" width="200"></el-table-column>
      <el-table-column prop="needDeviation" header-align="center" align="center" label="是否需偏差许可" width="190"></el-table-column>
      <el-table-column prop="technicalPlan" header-align="center" align="center" label="技术计划编码" width="170"></el-table-column>
      <el-table-column prop="technicalPlanName" header-align="center" align="center" label="技术计划名称" width="170"></el-table-column>
      <el-table-column prop="buyer" header-align="center" align="center" label="采购编码" width="130"></el-table-column>
      <el-table-column prop="buyerName" header-align="center" align="center" label="采购名称" width="130"></el-table-column>
      <el-table-column prop="expectReportTime" header-align="center" align="center" label="预计提供报告时间(一个月内)" width="200">
        <template slot-scope="scope">
          <span>{{ normalizeDateOnly(scope.row.expectReportTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="rohsStatus" header-align="center" align="center" label="RoHS状态" width="130"></el-table-column>
      <el-table-column prop="expiredDate" header-align="center" align="center" label="报告日期" width="165"></el-table-column>
      <el-table-column prop="validUntilDisplay" header-align="center" align="center" label="有效期" width="170" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ getValidUntilDisplay(scope.row.validUntilValue, scope.row.validUntil) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="isMeetRohsRequirement" header-align="center" align="center" label="符合RoHS" width="170"></el-table-column>
      <el-table-column prop="isAhGrade" header-align="center" align="center" label="AH属性" width="140"></el-table-column>
      <el-table-column prop="hsfSupplierClassification" header-align="center" align="center" label="HSF供应商等级" width="220"></el-table-column>
      <el-table-column prop="hsfApproverName" header-align="center" align="center" label="HSF审批人" width="240" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.hsfApproverName || scope.row.hsfApprover || '' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="relatedPeopleName" header-align="center" align="center" label="Inform Related people" width="200" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.relatedPeopleName || scope.row.relatedPeople || '' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="isSameMaterialDiffSize" header-align="center" align="center" label="同材不同规格" width="220"></el-table-column>
      <el-table-column prop="ifsPartNo" header-align="center" align="center" label="IFS编号" width="150"></el-table-column>
      <el-table-column prop="remark" header-align="center" align="center" label="备注" width="220" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="130" label="操作">
        <template slot-scope="scope">
          <el-link v-if="authUpdate && scope.row.status !== '已完成'" style="cursor: pointer" @click="addOrUpdateHandle(scope.row)">编辑</el-link>
          <el-link v-if="authUpdate && scope.row.status === '已完成'" style="cursor: pointer" @click="addOrUpdateHandle(scope.row)">详情</el-link>
          <el-link v-if="authIssue && scope.row.status === '草稿'" style="cursor: pointer; margin-left: 10px;" @click="issueModal(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-dialog
      :title="modalTitle"
      :visible.sync="modalFlag"
      width="1012px"
      top="3.8vh"
      v-drag
      :close-on-click-modal="false"
      :showClose="false">

      <el-tabs tab-position="left" type="border-card" v-model="activeName" style="width: 100%;height: 777px;">
        <!-- 基本信息 -->
        <el-tab-pane label="基本信息" name="basicInfo">
          <div style="height: 755px">
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('applicant')" slot="label" @click="getBaseList(103, 1)"><a herf="#">申请人/Reference No.</a></span>
                <span v-else slot="label">申请人/Reference No.</span>
                <el-input v-model="modalData.applicant" @blur="applicantBlur(103)" :disabled="isRohsFieldDisabled('applicant')" style="width: 100px"></el-input>
                <el-input v-model="modalData.applicantName" disabled style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item label="申请日期/Date">
                <el-date-picker v-model="modalData.applicationDate" type="date" value-format="yyyy-MM-dd" :disabled="isRohsFieldDisabled('applicationDate')" style="width: 150px" :editable=false></el-date-picker>
              </el-form-item>
              <el-form-item label="Site">
                <el-input v-model="modalData.site" disabled style="width: 95px"></el-input>
              </el-form-item>
              <el-form-item label="工艺/Process">
                <dict-data-select v-model="modalData.process" clearable @change="handleProcessChange" :disabled="isProcessFieldDisabled()" style="width: 121px" dict-type="rohs_process"></dict-data-select>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item>
                <span slot="label" v-if="!modalData.endCustomerFlag && !isRohsFieldDisabled('endCustomer')" @click="getBaseList(102, 1)"><a herf="#">最终客户/End Customer</a></span>
                <span slot="label" v-else>最终客户/End Customer</span>
                <el-input :disabled="modalData.endCustomerFlag || isRohsFieldDisabled('endCustomer')" readonly v-model="modalData.endCustomer" @blur="handleQueryCustomer" style="width: 100px"></el-input>
                <el-input disabled v-model="modalData.endCustomerName" style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item>
                <span slot="label" v-if="!modalData.projectIdFlag && !isRohsFieldDisabled('projectId')" @click="chooseProjectListFlag = true"><a herf="#">项目编码/Project</a></span>
                <span slot="label" v-else>项目编码/Project</span>
                <el-input :disabled="modalData.projectIdFlag || isRohsFieldDisabled('projectId')" readonly v-model="modalData.projectId" @blur="handleQueryProjectByCustomer" style="width: 100px"></el-input>
                <el-input disabled v-model="modalData.projectName" style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item label="WM所需求规格/The size that WM need">
                <el-input v-model="modalData.wmRequiredSpec" :disabled="isRohsFieldDisabled('wmRequiredSpec')" style="width: 260px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="供应商/Vendor Code">
                <el-input v-model="modalData.vendorCode" :disabled="isRohsFieldDisabled('vendorCode')" style="width: 396px"></el-input>
              </el-form-item>
              <el-form-item label="供应商材料编码/Vendor Material Code">
                <el-input v-model="modalData.vendorMaterialCode" :disabled="isRohsFieldDisabled('vendorMaterialCode')" style="width: 396px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="材料分类/Material Classify">
                <dict-data-select class="rohs-multiple-two-rows" v-model="modalData.materialClassifyList" multiple :title="getMultipleSelectTitle(modalData.materialClassifyList)" :disabled="isRohsFieldDisabled('materialClassify')" style="width: 532px" dict-type="rohs_material_classify"></dict-data-select>
              </el-form-item>
              <el-form-item label="其他分类/Other Material Classify" v-if="modalData.materialClassifyList && modalData.materialClassifyList.includes('Other其他')">
                <el-input v-model="modalData.otherMaterialClassify" :disabled="isRohsFieldDisabled('otherMaterialClassify')" style="width: 260px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 40px">
              <el-form-item label="辅材用途/Assiaccessorial Material Use for">
                <el-input v-model="modalData.materialUseFor" :disabled="isRohsFieldDisabled('materialUseFor')" style="width: 259px"></el-input>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('technicalPlan')" slot="label" @click="getBaseList(2001, 4)"><a herf="#">技术计划/TP</a></span>
                <span v-else slot="label">技术计划/TP</span>
                <el-input v-model="modalData.technicalPlan" @blur="technicalPlanBlur(2001)" :disabled="isRohsFieldDisabled('technicalPlan')" style="width: 100px"></el-input>
                <el-input v-model="modalData.technicalPlanName" disabled style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('pm')" slot="label" @click="getBaseList(2054, 5)"><a herf="#">PM人员/PM</a></span>
                <span v-else slot="label">PM人员/PM</span>
                <el-input v-model="modalData.pm" @blur="pmBlur(2054)" :disabled="isRohsFieldDisabled('pm')" style="width: 100px"></el-input>
                <el-input v-model="modalData.pmName" disabled style="width: 156px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="颜色/Color">
                <el-input v-model="modalData.color" :disabled="isRohsFieldDisabled('color')" style="width: 532px"></el-input>
              </el-form-item>
              <el-form-item label="计划转量产时间/Planned Mass Production Date">
                <el-date-picker v-model="modalData.plannedMassProductionDate" type="date" value-format="yyyy-MM-dd" :disabled="isRohsFieldDisabled('plannedMassProductionDate')" style="width: 260px" :editable=false></el-date-picker>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('commGroup1')" slot="label" @click="getBaseList(110)"><a herf="#">商品组1/Comm Group 1</a></span>
                <span v-else slot="label">商品组1/Comm Group 1</span>
                <el-input v-model="modalData.commGroup1" @change="commGroup1Blur(110)" :disabled="isRohsFieldDisabled('commGroup1')" style="width: 100px"></el-input>
                <el-input v-model="modalData.commGroup1Desc" disabled style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('commGroup2')" slot="label" @click="getBaseList(111)"><a herf="#">商品组2/Comm Group 2</a></span>
                <span v-else slot="label">商品组2/Comm Group 2</span>
                <el-input v-model="modalData.commGroup2" @change="commGroup2Blur(111)" :disabled="isRohsFieldDisabled('commGroup2')" style="width: 100px"></el-input>
                <el-input v-model="modalData.commGroup2Desc" disabled style="width: 155px"></el-input>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('commGroup3')" slot="label" @click="getBaseList(130)"><a herf="#">商品组3/Comm Group 3</a></span>
                <span v-else slot="label">商品组3/Comm Group 3</span>
                <el-input v-model="modalData.commGroup3" @change="commGroup3Blur(130)" :disabled="isRohsFieldDisabled('commGroup3')" style="width: 100px"></el-input>
                <el-input v-model="modalData.commGroup3Desc" disabled style="width: 156px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="是否是Fiber材料">
                <el-radio-group v-model="modalData.isFiberMaterial" :disabled="isRohsFieldDisabled('isFiberMaterial')" style="width: 145px">
                  <el-radio label="Y" @click.native.prevent="radioClick('isFiberMaterial', 'Y')">是</el-radio>
                  <el-radio label="N" @click.native.prevent="radioClick('isFiberMaterial', 'N')">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="是否需要创建300/700/900号/Dose Need Create 300/700/900 Number">
                <el-radio-group v-model="modalData.needCreateNumber" :disabled="isRohsFieldDisabled('needCreateNumber')" style="width: 374px">
                  <el-radio label="Y" @click.native.prevent="radioClick('needCreateNumber', 'Y')">是</el-radio>
                  <el-radio label="N" @click.native.prevent="radioClick('needCreateNumber', 'N')">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="材料厚度/Material Thickness">
                <el-input v-model="modalData.materialThickness" :disabled="isRohsFieldDisabled('materialThickness')" style="width: 260px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="材料有效期/Material Validity Time">
                <dict-data-select v-model="modalData.materialValidityTime" clearable :disabled="isRohsFieldDisabled('materialValidityTime')" style="width: 260px" dict-type="rohs_material_validity_time"></dict-data-select>
              </el-form-item>
              <el-form-item label="是否需要Deviation/If need deviation or not">
                <el-radio-group v-model="modalData.needDeviation" :disabled="isRohsFieldDisabled('needDeviation')" style="width: 259px">
                  <el-radio label="Y" @click.native.prevent="radioClick('needDeviation', 'Y')">是</el-radio>
                  <el-radio label="N" @click.native.prevent="radioClick('needDeviation', 'N')">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('npdEngineer')" slot="label" @click="getBaseList(2001, 3)"><a herf="#">NPD工程师/NPD Engineer</a></span>
                <span v-else slot="label">NPD工程师/NPD Engineer</span>
                <el-input v-model="modalData.npdEngineer" @blur="npdEngineerBlur(2001)" :disabled="isRohsFieldDisabled('npdEngineer')" style="width: 100px"></el-input>
                <el-input v-model="modalData.npdEngineerName" disabled style="width: 155px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="材料有效期备注/Material Validity Time Comments">
                <el-input v-model="modalData.materialValidityComments" :disabled="isRohsFieldDisabled('materialValidityComments')" style="width: 260px"></el-input>
              </el-form-item>
              <el-form-item label="预计提供报告时间(一个月内)/Expect Date" style="margin-left: -2px">
                <el-date-picker v-model="modalData.expectReportTime" type="date" value-format="yyyy-MM-dd" :disabled="isRohsFieldDisabled('expectReportTime')" style="width: 259px" :editable=false></el-date-picker>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('buyer')" slot="label" @click="getBaseList(2000, 2)"><a herf="#">采购/Buyer</a></span>
                <span v-else slot="label">采购/Buyer</span>
                <el-input v-model="modalData.buyer" @blur="buyerBlur(2000)" :disabled="isRohsFieldDisabled('buyer')" style="width: 100px"></el-input>
                <el-input v-model="modalData.buyerName" disabled style="width: 156px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="所需审批文件/Qualification Documents needed" >
                <dict-data-select
                  :key="'qualification-default-' + (modalData.referenceNo || '') + '-' + (isEditMode ? 'edit' : 'add')"
                  class="rohs-multiple-two-rows"
                  v-model="modalData.qualificationDocumentsNeededList"
                  multiple
                  :use-default-value="!isEditMode"
                  :use-type-multi-default-value="!isEditMode"
                  :title="getMultipleSelectTitle(modalData.qualificationDocumentsNeededList)"
                  :disabled="isRohsFieldDisabled('qualificationDocumentsNeeded')"
                  style="width: 807px"
                  dict-type="rohs_qualification_docs">
                </dict-data-select>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 40px">
              <el-form-item label="测试报告必测项/Test Report including items">
                <dict-data-select
                  :key="'test-report-default-' + (modalData.referenceNo || '') + '-' + (isEditMode ? 'edit' : 'add')"
                  class="rohs-multiple-two-rows"
                  v-model="modalData.testReportIncludingItemsList"
                  multiple
                  :use-default-value="!isEditMode"
                  :use-type-multi-default-value="!isEditMode"
                  :title="getMultipleSelectTitle(modalData.testReportIncludingItemsList)"
                  :disabled="isRohsFieldDisabled('testReportIncludingItems')"
                  style="width: 807px"
                  dict-type="rohs_test_report_items">
                </dict-data-select>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 40px">
              <el-form-item style="display: block;">
                <template slot="label">
                  <span>备注说明/Comments</span>
                  <el-button
                    v-if="authDataEntry"
                    style="margin-left: 2px;width: 83px;line-height: 0.5;font-size: 10px;"
                    type="primary"
                    @click="openRohsRemarkDialog">备注</el-button>
                </template>
                <el-input type="textarea" :rows="3" v-model="modalData.remark" :disabled="isRohsFieldDisabled('remark')" resize="none" style="width: 804px;height: 30px"></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>

        <!-- NPD 信息 -->
        <el-tab-pane label="NPD 信息" name="npdInfo">
          <div style="height: 755px; overflow-y: auto;">
<!--            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">-->
<!--              <el-form-item label="现有材料不同规格/Same Material Diff Size">-->
<!--                <el-radio-group v-model="modalData.isSameMaterialDiffSize" :disabled="isRohsFieldDisabled('isSameMaterialDiffSize')" style="width: 190px">-->
<!--                  <el-radio label="Y" @click.native.prevent="radioClick('isSameMaterialDiffSize', 'Y')">是</el-radio>-->
<!--                  <el-radio label="N" @click.native.prevent="radioClick('isSameMaterialDiffSize', 'N')">否</el-radio>-->
<!--                </el-radio-group>-->
<!--              </el-form-item>-->
<!--            </el-form>-->
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item style="display: block;">
                <template slot="label">
                  <span>材料描述/Material Desc.</span>
                  <el-button
                    v-if="authMaterialDescRemark"
                    style="margin-left: 2px;width: 83px;line-height: 0.5;font-size: 10px;"
                    type="primary"
                    @click="openRohsMaterialDescDialog">编辑</el-button>
                </template>
                <el-input type="textarea" :rows="3" v-model="modalData.materialDesc" :disabled="isRohsFieldDisabled('materialDesc')" resize="none" style="width: 804px;height: 30px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 50px">
              <el-form-item label="备注说明/NPD Remark" style="display: block;">
                <el-input type="textarea" :rows="3" v-model="modalData.npdRemark" :disabled="isRohsFieldDisabled('npdRemark')" resize="none" style="width: 804px;height: 30px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 50px">
              <el-form-item label="内部TDS/Inner TDS" style="display: block;">
                <oss-components
                  ref="modalTdsOss"
                  :save-visible="authFileSave"
                  :edit-visible="authFileSave"
                  :download-visible="authFileDownLoad"
                  :remove-visible="authFileRemove"
                  :preview-visible="authFilePreview"
                  :disabled="showModalFlag || modalData.status === '已完成'"
                  :enable-upgrade="!showModalFlag && modalData.status !== '已完成'"
                  :require-file-no-rev="true"
                  :auto-file-no="true"
                  :single-upload="true"
                  :row-click-select="true"
                  :show-order-ref2="false"
                  label="序列号"
                  :height="510"
                  style="margin-top: 2px"
                  :columns="tdsFileColumnList"
                  :order-ref1="modalData.site || ''"
                  :order-ref2="modalData.referenceNo || ''"
                  order-ref3="tdsProperty">
                </oss-components>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>

        <!-- HSF 填写信息 -->
        <el-tab-pane label="HSF 填写信息" name="hsfInfo">
          <div style="height: 755px">
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item label="报告日期/Report Date">
                <el-date-picker v-model="modalData.expiredDate" type="date" value-format="yyyy-MM-dd" :disabled="isRohsFieldDisabled('expiredDate')" style="width: 150px" :editable=false></el-date-picker>
              </el-form-item>
              <el-form-item label="有效期数值/Valid Until Value">
                <el-input-number
                  v-model="modalData.validUntilValue"
                  :controls="false"
                  :min="0"
                  :step="1"
                  :precision="0"
                  :disabled="isValidUntilValueDisabled()"
                  style="width: 150px">
                </el-input-number>
              </el-form-item>
              <el-form-item label="有效期单位/Valid Until Unit">
                <dict-data-select v-model="modalData.validUntil" clearable :disabled="isValidUntilUnitDisabled()" style="width: 150px" dict-type="rohs_valid_until"></dict-data-select>
              </el-form-item>
              <el-form-item label="失效日期/Expiry Date">
                <el-date-picker v-model="modalData.expiryDate" type="date" value-format="yyyy-MM-dd" disabled style="width: 150px" :editable=false></el-date-picker>
              </el-form-item>
              <el-form-item label="状态/Status">
                <el-select v-model="modalData.rohsStatus" clearable :disabled="isRohsFieldDisabled('rohsStatus')" style="width: 150px">
                  <el-option label="Active" value="Active"></el-option>
                  <el-option label="Dead" value="Dead"></el-option>
                </el-select>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="是否符合RoHS/Meet RoHS Req">
                <el-radio-group v-model="modalData.isMeetRohsRequirement" :disabled="isRohsFieldDisabled('isMeetRohsRequirement')" style="width: 190px">
                  <el-radio label="Y" @click.native.prevent="radioClick('isMeetRohsRequirement', 'Y')">是</el-radio>
                  <el-radio label="N" @click.native.prevent="radioClick('isMeetRohsRequirement', 'N')">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label=" ">
                <el-checkbox
                  v-model="modalData.isAhGrade"
                  true-label="Y"
                  false-label="N"
                  :disabled="isRohsFieldDisabled('isAhGrade')"
                style="width: 190px">材料属性是否是AH/Is AH Grade</el-checkbox>
              </el-form-item>
              <el-form-item label="HSF供应商等级/Supplier Class">
                <el-radio-group v-model="modalData.hsfSupplierClassification" :disabled="isRohsFieldDisabled('hsfSupplierClassification')" style="width: 260px">
                  <el-radio label="高风险" @click.native.prevent="radioClick('hsfSupplierClassification', '高风险')">高风险</el-radio>
                  <el-radio label="中风险" @click.native.prevent="radioClick('hsfSupplierClassification', '中风险')">中风险</el-radio>
                  <el-radio label="低风险" @click.native.prevent="radioClick('hsfSupplierClassification', '低风险')">低风险</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData">
              <el-form-item label="Fiber报告信息/Fiber Information" style="display: block;">
                <el-input type="textarea" :rows="3" v-model="modalData.fiberInformation" :disabled="isRohsFieldDisabled('fiberInformation')" resize="none" style="width: 804px;height: 30px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 45px">
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('hsfApprover')" slot="label" @click="openHsfApproverChooseModal"><a herf="#">HSF审批人/HSF Approver</a></span>
                <span v-else slot="label">HSF审批人/HSF Approver</span>
                <el-input
                  v-model="modalData.hsfApproverName"
                  readonly
                  :disabled="isRohsFieldDisabled('hsfApprover')"
                  style="width: 396px"
                  placeholder="请选择人员"
                  @focus="openHsfApproverChooseModal">
                  <span slot="suffix" v-show="modalData.hsfApproverName && !isRohsFieldDisabled('hsfApprover')" @click.stop="clearHsfApproverSelection">
                    <i class="el-icon-circle-close" style="margin-left: 5px;cursor: pointer;"></i>
                  </span>
                </el-input>
              </el-form-item>
              <el-form-item>
                <span style="cursor: pointer" v-if="!isRohsFieldDisabled('relatedPeople')" slot="label" @click="openRelatedPeopleChooseModal"><a herf="#">Inform Related people</a></span>
                <span v-else slot="label">Inform Related people</span>
                <el-input
                  v-model="modalData.relatedPeopleName"
                  readonly
                  :disabled="isRohsFieldDisabled('relatedPeople')"
                  style="width: 396px"
                  placeholder="请从HSF审批人中选择"
                  @focus="openRelatedPeopleChooseModal">
                  <span slot="suffix" v-show="modalData.relatedPeopleName && !isRohsFieldDisabled('relatedPeople')" @click.stop="clearRelatedPeopleSelection">
                    <i class="el-icon-circle-close" style="margin-left: 5px;cursor: pointer;"></i>
                  </span>
                </el-input>
              </el-form-item>
            </el-form>
            <el-form v-if="shouldShowHsfStandard(modalData.endCustomer)" :inline="true" label-position="top" :model="modalData" style="margin-top: 0px">
              <el-form-item label="HSF标准/HSF Standard" style="display: block;">
                <el-input type="textarea" :rows="3" v-model="modalData.hsfStandard" :disabled="isRohsFieldDisabled('hsfStandard')" resize="none" style="width: 804px;height: 30px"></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>

        <!-- 材料信息 -->
        <el-tab-pane label="材料信息" name="materialInfo">
          <div style="height: 755px">
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -15px;">
              <el-form-item label=" ">
                <el-button type="primary" v-if="isEditMode && canEditRohsMaterial()" @click="openCreateIfsPartDialog">创建IFS料号</el-button>
                <el-button type="primary" v-if="!showModalFlag && canEditRohsMaterial()" @click="openProjectMaterialDialog">关联料号</el-button>
                <el-button type="danger" v-if="!showModalFlag && canEditRohsMaterial()" @click="removeSelectedMaterialRows">删除关联</el-button>
              </el-form-item>
            </el-form>
            <el-table
              ref="rohsMaterialTable"
              class="rohs-material-table"
              border
              :data="modalData.materialList"
              @selection-change="materialSelectionChange"
              :header-cell-style="materialDialogHeaderCellStyle"
              :height="715"
              style="width: 100%">
              <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <el-table-column type="index" label="序号" width="50" header-align="center" align="center"></el-table-column>
              <el-table-column prop="finalPartNo" label="IFS物料编码/Final Part No." min-width="150" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="partDesc" label="描述/Part Desc." min-width="250" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="partStatus" label="状态/Part Status" min-width="100" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
            </el-table>
          </div>
        </el-tab-pane>

        <el-tab-pane label="附件信息" name="attachmentInfo">
          <div style="height: 755px; overflow-y: auto;">
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item label="TDS" style="display: block;">
                <oss-components
                  ref="modalAttachmentTdsOss"
                  :save-visible="authFileSave"
                  :edit-visible="authFileSave"
                  :download-visible="authFileDownLoad"
                  :remove-visible="authFileRemove"
                  :preview-visible="authFilePreview"
                  :row-click-select="true"
                  :disabled="modalData.status === '已完成'"
                  label="序列号"
                  :height="145"
                  style="margin-top: 2px"
                  :columns="fileColumnList"
                  :order-ref1="modalData.site || ''"
                  :order-ref2="modalData.referenceNo || ''"
                  order-ref3="rohsAttachmentTds">
                </oss-components>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 150px;">
              <el-form-item label="MSDS" style="display: block;">
                <oss-components
                  ref="modalAttachmentMsdsOss"
                  :save-visible="authFileSave"
                  :edit-visible="authFileSave"
                  :download-visible="authFileDownLoad"
                  :remove-visible="authFileRemove"
                  :preview-visible="authFilePreview"
                  :row-click-select="true"
                  :disabled="modalData.status === '已完成'"
                  label="序列号"
                  :height="145"
                  style="margin-top: 2px"
                  :columns="fileColumnList"
                  :order-ref1="modalData.site || ''"
                  :order-ref2="modalData.referenceNo || ''"
                  order-ref3="rohsAttachmentMsds">
                </oss-components>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 150px;">
              <el-form-item label="测试报告/Test Report" style="display: block;">
                <oss-components
                  ref="modalAttachmentTestReportOss"
                  :save-visible="authFileSave"
                  :edit-visible="authFileSave"
                  :download-visible="authFileDownLoad"
                  :remove-visible="authFileRemove"
                  :preview-visible="authFilePreview"
                  :row-click-select="true"
                  :disabled="modalData.status === '已完成'"
                  label="序列号"
                  :height="145"
                  style="margin-top: 2px"
                  :columns="fileColumnList"
                  :order-ref1="modalData.site || ''"
                  :order-ref2="modalData.referenceNo || ''"
                  order-ref3="rohsAttachmentTestReport">
                </oss-components>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 150px;">
              <el-form-item label="Other" style="display: block;">
                <oss-components
                  ref="modalAttachmentOtherOss"
                  :save-visible="authFileSave"
                  :edit-visible="authFileSave"
                  :download-visible="authFileDownLoad"
                  :remove-visible="authFileRemove"
                  :preview-visible="authFilePreview"
                  :row-click-select="true"
                  :disabled="modalData.status === '已完成'"
                  label="序列号"
                  :height="145"
                  style="margin-top: 2px"
                  :columns="fileColumnList"
                  :order-ref1="modalData.site || ''"
                  :order-ref2="modalData.referenceNo || ''"
                  order-ref3="rohsAttachmentOther">
                </oss-components>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>
      </el-tabs>

      <el-footer style="height:35px;margin-top: 15px;text-align:center">
        <el-button type="primary" v-if="canSaveAction()" @click="dataFormSubmit()">保存</el-button>
        <el-button type="primary" @click="handleModalClose">关闭</el-button>
        <el-button type="primary" v-if="canAgreeAction()" :loading="submitLoading" @click="agreeSubmit">同意</el-button>
        <el-button type="primary" v-if="canRejectAction()" :loading="submitLoading" @click="openRejectModal">驳回</el-button>
      </el-footer>
    </el-dialog>

    <!--选择项目模态框-->
    <el-dialog title="选择-项目" :close-on-click-modal="false" @close="closeProjectInfoDialog"
               @open="searchProjectInfoList" :visible.sync="chooseProjectListFlag" width="35%">
      <el-form label-position="top" :model="searchProjectData" ref="closeProjectInfoForm">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="项目号">
              <el-input v-model="searchProjectData.projectId"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目名称">
              <el-input v-model="searchProjectData.projectName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label=" ">
              <el-button type="primary" @click="searchProjectInfoList">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-table :height="223"
                  :data="projectList"
                  border
                  @row-click="projectClickRow">
          <el-table-column label="项目号" prop="projectId"/>
          <el-table-column label="项目名称" prop="projectName"/>
        </el-table>
      </el-form>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseProjectListFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="选择物料" top="15vh" width="50%" :close-on-click-modal="false" v-drag :visible.sync="projectMaterialDialogFlag">
      <el-form :inline="true" label-position="top" :model="projectMaterialSearchData">
        <el-form-item label="IFS物料编码/Final Part No.">
          <el-input v-model="projectMaterialSearchData.finalPartNo" clearable style="width: 150px"></el-input>
        </el-form-item>
        <el-form-item label="描述/Part Desc">
          <el-input v-model="projectMaterialSearchData.partDesc" clearable style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="状态/Part Status">
          <el-input v-model="projectMaterialSearchData.partStatus" clearable style="width: 100px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" @click="searchProjectMaterialList">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        ref="projectMaterialTable"
        class="rohs-material-table"
        border
        v-loading="projectMaterialLoading"
        :data="projectMaterialList"
        @selection-change="projectMaterialSelectionChange"
        :header-cell-style="materialDialogHeaderCellStyle"
        :height="320"
        style="width: 100%">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="finalPartNo" label="IFS物料编码/Final Part No." min-width="120" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="partDesc" label="描述/Part Desc." min-width="250" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="partStatus" label="状态/Part Status" min-width="80" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <el-pagination
        style="margin-top: 10px"
        @size-change="projectMaterialSizeChangeHandle"
        @current-change="projectMaterialCurrentChangeHandle"
        :current-page="projectMaterialPageIndex"
        :page-sizes="[20, 50, 100]"
        :page-size="projectMaterialPageSize"
        :total="projectMaterialTotal"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="confirmProjectMaterialSelection">确定</el-button>
        <el-button type="primary" @click="projectMaterialDialogFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog
      title="创建IFS料号"
      top="7vh"
      width="1060px"
      v-drag
      :close-on-click-modal="false"
      :visible.sync="rohsCreatePartDialogFlag"
      @close="closeRohsCreatePartDialog">
      <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
        <el-form-item label="Site">
          <el-input v-model="rohsCreatePartData.site" disabled style="width: 80px"></el-input>
        </el-form-item>
        <el-form-item label="物料编码 / Part No.">
          <el-input v-model="rohsCreatePartData.partNo" clearable style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="物料名称 / Part Desc.">
          <el-input v-model="rohsCreatePartData.partDesc" clearable style="width: 360px"></el-input>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="nextRohsCreatePartNo">Next Part No</el-button>
        </el-form-item>
      </el-form>
      <el-tabs v-model="rohsCreatePartTab" style="width: 100%;height: 465px;" type="border-card">
        <el-tab-pane label="General" name="General">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item label="零件类型 / Part Type">
              <el-select v-model="rohsCreatePartData.partType" style="width: 458px">
                <el-option label="Manufactured" value="Manufactured"></el-option>
                <el-option label="Manufactured Recipe" value="Manufactured Recipe"></el-option>
                <el-option label="Purchased (raw)" value="Purchased (raw)"></el-option>
                <el-option label="Purchased" value="Purchased"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(123)"><a herf="#">安全代码 / Safety Code</a></span>
              <el-input v-model="rohsCreatePartData.hazardCode" clearable @blur="rohsCreateHazardCodeBlur(123)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.hazardDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(113)"><a herf="#">计划人 / Planner</a></span>
              <el-input v-model="rohsCreatePartData.productGroupId4" clearable @blur="rohsCreateProductGroupId4Blur(113)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.productGroupName4" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(112)"><a herf="#">会计组 / Accounting Group</a></span>
              <el-input v-model="rohsCreatePartData.productGroupId3" clearable @blur="rohsCreateProductGroupId3Blur(112)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.productGroupName3" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(1007)"><a herf="#">计量单位 / Inventory UoM</a></span>
              <el-input v-model="rohsCreatePartData.umId" clearable @blur="rohsCreateUmIdBlur(1007)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.umName" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(109)"><a herf="#">产品代码 / Product Code</a></span>
              <el-input v-model="rohsCreatePartData.groupId" clearable @blur="rohsCreateGroupIdBlur(109)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.groupName" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span slot="label">商品组1 / Comm Group 1</span>
              <el-input v-model="rohsCreatePartData.productGroupId1" readonly style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.productGroupName1" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(108)"><a herf="#">产品大类 / Product Family</a></span>
              <el-input v-model="rohsCreatePartData.familyId" clearable @blur="rohsCreateFamilyIdBlur(108)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.familyName" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span slot="label">商品组2 / Comm Group 2</span>
              <el-input v-model="rohsCreatePartData.productGroupId2" readonly style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.productGroupName2" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item label="类型指定 / Type Designation">
              <el-input v-model="rohsCreatePartData.typeDesignation" clearable style="width: 458px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="商品组3 / Comm Group 3">
              <el-input v-model="rohsCreatePartData.commGroup3" readonly style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.commGroup3Desc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(124)"><a herf="#">资产等级 / Asset Class</a></span>
              <el-input v-model="rohsCreatePartData.assetClass" clearable @blur="rohsCreateAssetClassBlur(124)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.assetClassDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item label="尺寸/材质 / Dimension/Quality">
              <el-input v-model="rohsCreatePartData.dimQuality" clearable style="width: 458px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(125)"><a herf="#">零件状态 / Part Status</a></span>
              <el-input v-model="rohsCreatePartData.partStatus" clearable @blur="rohsCreatePartStatusBlur(125)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.partStatusDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item label="净重">
              <el-input class="inlineNumber numInput" v-model="rohsCreatePartData.weightNet" readonly type="number" style="width: 110px"></el-input>
            </el-form-item>
            <el-form-item label="净重单位" style="margin-left: -10px">
              <el-input v-model="rohsCreatePartData.uomForWeightNet" readonly style="width: 110px"></el-input>
            </el-form-item>
            <el-form-item label="频率级别 / Frequency Class">
              <el-input v-model="rohsCreatePartData.frequencyClass" readonly style="width: 220px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(126)"><a herf="#">ABC类 / ABC Class</a></span>
              <el-input v-model="rohsCreatePartData.abcClass" clearable @blur="rohsCreateAbcClassBlur(126)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.abcClassDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item label="净数量">
              <el-input class="inlineNumber numInput" v-model="rohsCreatePartData.volumeNet" readonly type="number" style="width: 110px"></el-input>
            </el-form-item>
            <el-form-item label="数量单位" style="margin-left: -10px">
              <el-input v-model="rohsCreatePartData.uomForVolumeNet" readonly style="width: 110px"></el-input>
            </el-form-item>
            <el-form-item label="生命周期阶段 / Lifecycle Stage">
              <el-input v-model="rohsCreatePartData.lifecycleStage" readonly style="width: 220px"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Acquisition" name="Acquisition">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item label="制造备货期 / Manufacturing Lead Time">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.manufacturingLeadTime" @change="rohsChangeExpectedLeadTime" :disabled="!(rohsCreatePartData.partType === 'Manufactured' || rohsCreatePartData.partType === 'Manufactured Recipe')" style="width: 222px"></el-input-number>
            </el-form-item>
            <el-form-item label="Shelf Life(Weeks)">
              <el-input class="inlineNumber numInput" v-model="rohsCreatePartData.durabilityWeek" readonly type="number" style="width: 221px"></el-input>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(127)"><a herf="#">来源国家 / Country of Origin</a></span>
              <el-input v-model="rohsCreatePartData.countryOfOrigin" clearable @blur="rohsCreateCountryOfOriginBlur(127)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.countryOfOriginDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="预期提前期 / Expected Lead Time">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.expectedLeadTime" style="width: 222px"></el-input-number>
            </el-form-item>
            <el-form-item label="Shelf Life(Days)">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.durabilityDay" @change="rohsChangeDurabilityWeek" style="width: 221px"></el-input-number>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(128)"><a herf="#">区域代码 / Region Code</a></span>
              <el-input v-model="rohsCreatePartData.regionOfOrigin" clearable @blur="rohsCreateRegionOfOriginBlur(128)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.regionOfOriginDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="州内转换因子 / Intrastat Conv Factor">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.intrastatConvFactor" style="width: 128px"></el-input-number>
              <el-input v-model="rohsCreatePartData.umDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(129)"><a herf="#">海关统计序号 / Customs Stat No</a></span>
              <el-input v-model="rohsCreatePartData.customsStatNo" clearable @blur="rohsCreateCustomsStatNoBlur(129)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.customsStatDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="默认物料需求供应 / Default Mtr Req Supply">
              <el-select v-model="rohsCreatePartData.supplyCode" style="width: 458px" clearable>
                <el-option label="Inventory Order" value="Inventory Order"></el-option>
                <el-option label="Purchase Order" value="Purchase Order"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="备注" style="height: 80px">
              <el-input type="textarea" v-model="rohsCreatePartData.remark" :rows="3" resize='none' show-word-limit style="width: 931px"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Costs" name="Costs">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item label="配置标识 / Configuration ID">
              <el-select v-model="rohsCreatePartData.configurationId" style="width: 220px">
                <el-option label="*" value="*"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="估计物料成本 / Estimated Material Cost">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.estimatedMaterialCost" style="width: 220px"></el-input-number>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Misc Part Info" name="MiscPartInfo">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item label="库存估价方法 / Inventory Valuation Method">
              <el-select v-model="rohsCreatePartData.inventoryValuationMethod" style="width: 458px">
                <el-option label="Weighted Average" value="Weighted Average"></el-option>
                <el-option label="Standard Cost" value="Standard Cost"></el-option>
                <el-option label="First In First Out" value="First In First Out"></el-option>
                <el-option label="Last In First Out" value="Last In First Out"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(131)"><a herf="#">零件成本组 / Part Cost Group</a></span>
              <el-input v-model="rohsCreatePartData.partCostGroupId" clearable @blur="rohsCreatePartCostGroupIdBlur(131)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.partCostGroupDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="库存件成本层 / Inventory Part Cost Level">
              <el-select v-model="rohsCreatePartData.inventoryPartCostLevel" style="width: 458px">
                <el-option label="Cost Per Part" value="Cost Per Part"></el-option>
                <el-option label="Cost Per Configuration" value="Cost Per Configuration"></el-option>
                <el-option label="Cost Per Condition" value="Cost Per Condition"></el-option>
                <el-option label="Cost Per Lot Batch" value="Cost Per Lot Batch"></el-option>
                <el-option label="Cost Per Serial" value="Cost Per Serial"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="供应商发票事项 / Supplier Invoice Consideration">
              <el-select v-model="rohsCreatePartData.invoiceConsideration" style="width: 458px">
                <el-option label="Ignore Invoice Price" value="Ignore Invoice Price"></el-option>
                <el-option label="Periodic Weighted Average" value="Periodic Weighted Average"></el-option>
                <el-option label="Transaction Based" value="Transaction Based"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="零成本 / Zero Cost">
              <el-select v-model="rohsCreatePartData.zeroCostFlag" style="width: 458px">
                <el-option label="Zero Cost Allowed" value="Zero Cost Allowed"></el-option>
                <el-option label="Zero Cost Forbidden" value="Zero Cost Forbidden"></el-option>
                <el-option label="Zero Cost Only" value="Zero Cost Only"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Planning Data" name="PlanningData">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(132)"><a herf="#">计划方法 / Planning Method</a></span>
              <el-input v-model="rohsCreatePartData.planningMethod" clearable @blur="rohsCreatePlanningMethodBlur(132)" style="width: 170px"></el-input>
            </el-form-item>
            <el-form-item label=" ">
              <el-input v-model="rohsCreatePartData.planningMethodDesc" disabled style="width: 510px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="安全库存 / Safety Stock">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.safetyStock" style="width: 170px"></el-input-number>
            </el-form-item>
            <el-form-item label="最小批量 / Min Lot Size">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.minOrderQty" style="width: 170px"></el-input-number>
            </el-form-item>
            <el-form-item label="最大批量 / Max Lot Size">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.maxOrderQty" style="width: 155px"></el-input-number>
            </el-form-item>
            <el-form-item label="多种批量大小 / Multiple Lot Size">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.mulOrderQty" style="width: 155px"></el-input-number>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="安全提前期 / Safety Lead Time">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.safetyLeadTime" style="width: 170px"></el-input-number>
            </el-form-item>
            <el-form-item label="报废因子(%) / Scrap Factor(%)">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.shrinkageFac" style="width: 170px"></el-input-number>
            </el-form-item>
            <el-form-item label="标准批量大小 / Std Lot Size">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.stdOrderQty" style="width: 155px"></el-input-number>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Manufacturing" name="Manufacturing">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item label="累计提前期 / Cum Lead Time">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.cumLeadTime" style="width: 294px"></el-input-number>
            </el-form-item>
            <el-form-item label="预留/下发来源 / Reserve/Issue from">
              <el-select v-model="rohsCreatePartData.backFlushPart" style="width: 248px">
                <el-option label="All Locations" value="All Locations"></el-option>
                <el-option label="Only Floor Stock" value="Only Floor Stock"></el-option>
                <el-option label="Only Specified Location" value="Only Specified Location"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-top: 23px">
              <el-checkbox v-model="rohsCreatePartData.byProdAsSupplyInMrpDb" true-label="Y">将副产品用作MRP中的供应 / Use By-Product as Supply in MRP</el-checkbox>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="未受保护提前期 / Unprotected Lead Time">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.unprotectedLeadTime" style="width: 294px"></el-input-number>
            </el-form-item>
            <el-form-item label="预留/下发方法 / Reserve/Issue Method">
              <el-select v-model="rohsCreatePartData.issueType" style="width: 248px">
                <el-option label="Reserve" value="Reserve"></el-option>
                <el-option label="Backflush" value="Backflush"></el-option>
                <el-option label="Reserve And Backflush" value="Reserve And Backflush"></el-option>
                <el-option label="Manual" value="Manual"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-top: 23px">
              <el-checkbox v-model="rohsCreatePartData.mrpControlFlagDb" true-label="Y">MRP控制 / MRP Control</el-checkbox>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="按日固定提前期 / Fixed Lead Time by Day">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.fixedLeadTimeDay" style="width: 294px"></el-input-number>
            </el-form-item>
            <el-form-item label="过度报告 / Over Reporting">
              <el-select v-model="rohsCreatePartData.overReporting" style="width: 248px">
                <el-option label="Allowed" value="Allowed"></el-option>
                <el-option label="Allowed with Warning" value="Allowed with Warning"></el-option>
                <el-option label="Not Allowed" value="Not Allowed"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-top: 23px">
              <el-checkbox v-model="rohsCreatePartData.useTheoreticalDensityDb" true-label="Y">使用理论 / Use Theoretical</el-checkbox>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="按天的可变化提前期 / Variable Lead Time by Day">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.variableLeadTimeDay" style="width: 294px"></el-input-number>
            </el-form-item>
            <el-form-item label="报告公差过大 / Over Report Tolerance">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.overReportTolerance" style="width: 248px"></el-input-number>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="按小时的固定提前期 / Fixed Lead Time by Hour">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.fixedLeadTimeHour" style="width: 294px"></el-input-number>
            </el-form-item>
            <el-form-item label="密度 / Density">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.density" style="width: 248px"></el-input-number>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData">
            <el-form-item label="按小时计算的可变提前期 / Variable Lead Time by Hour">
              <el-input-number :controls="false" :step="0" v-model="rohsCreatePartData.variableLeadTimeHour" style="width: 294px"></el-input-number>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="Characteristics" name="Characteristics">
          <el-form :inline="true" label-position="top" :model="rohsCreatePartData" style="margin-top: -5px;">
            <el-form-item>
              <span style="cursor: pointer" slot="label" @click="openRohsCreatePartBaseList(20)"><a herf="#">属性模板</a></span>
              <el-input v-model="rohsCreatePartData.codeNo" clearable @blur="rohsCreateCodeNoBlur(20)" style="width: 128px"></el-input>
              <el-input v-model="rohsCreatePartData.codeDesc" disabled style="width: 327px"></el-input>
            </el-form-item>
            <el-form-item :label="' '">
              <el-button type="primary" @click="openRohsCharacteristicDialog">新增</el-button>
              <el-button type="primary" @click="removeRohsPartItemRows">删除</el-button>
            </el-form-item>
          </el-form>
          <div class="rq">
            <el-table
              :data="rohsCreatePartData.partItemList"
              height="355px"
              border
              @selection-change="rohsPartItemSelectionChange"
              style="width: 100%">
              <el-table-column
                type="selection"
                align="center"
                width="50">
              </el-table-column>
              <el-table-column
                v-for="(item,index) in rohsCreatePartColumnItemList" :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">
                  <div v-if="item.columnProp !== 'textValue' && item.columnProp !== 'numValue'">
                    <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>
                  </div>
                  <div v-else>
                    <div v-if="scope.row.valueChooseFlag !== 'Y'">
                      <el-input-number v-if="scope.row.valueTypeDb === 'N'" v-model="scope.row.numValue" style="padding: 0;width: 100%" :controls="false"></el-input-number>
                      <el-input v-else v-model="scope.row.textValue"></el-input>
                    </div>
                    <div v-else>
                      <el-select style="width: 100%;" v-if="scope.row.valueTypeDb === 'T'" v-model="scope.row.textValue" clearable>
                        <el-option :value="i.availableValue" :label="i.availableValue" v-for="(i,key) in scope.row.availableValueList" :key="key"></el-option>
                      </el-select>
                      <el-select style="width: 100%;" v-else v-model="scope.row.numValue" clearable>
                        <el-option :value="i.availableValue" :label="i.availableValue" v-for="(i,key) in scope.row.availableValueList" :key="key"></el-option>
                      </el-select>
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" :loading="rohsCreatePartLoading" @click="saveRohsCreatePart">保存</el-button>
        <el-button type="primary" @click="rohsCreatePartDialogFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="物料属性" :close-on-click-modal="false" v-drag :visible.sync="rohsCharacteristicDialogFlag" width="730px">
      <el-form :inline="true" label-position="top" :model="rohsCharacteristicQueryData">
        <el-form-item :label="'属性编码'">
          <el-input v-model="rohsCharacteristicQueryData.propertiesItemNo" clearable style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item :label="'属性名称'">
          <el-input v-model="rohsCharacteristicQueryData.itemDesc" clearable style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="queryRohsCharacteristicOptions">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="250"
        :data="rohsCharacteristicList"
        border
        ref="rohsCharacteristicTable"
        @row-click="rohsCharacteristicRowClick"
        @selection-change="rohsCharacteristicSelectionChange"
        style="width: 100%;">
        <el-table-column type="selection" align="center" width="50"></el-table-column>
        <el-table-column
          v-for="(item,index) in rohsCharacteristicColumnList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed===''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveRohsCharacteristics">保存</el-button>
        <el-button type="primary" @click="rohsCharacteristicDialogFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="人员选择" @open="openHsfApproverDialog" @close="closeHsfApproverDialog" v-drag
               :visible.sync="hsfApproverFlag" width="40vw" :close-on-click-modal="false">
      <el-form :inline="true" label-position="top" :model="hsfApproverSearchData">
        <el-form-item label="编码">
          <el-input v-model="hsfApproverSearchData.operatorId" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="名称">
          <el-input v-model="hsfApproverSearchData.operatorName" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" @click="filterHsfApproverOptions">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-if="hsfApproverFlag"
                :height="300"
                :data="hsfApproverDisplayList"
                @selection-change="handleHsfApproverSelectionChange"
                @row-click="(row,column,event) => handleHsfApproverTableClick(row,column,event,'hsfApproverTable')"
                ref="hsfApproverTable"
                border row-key="operatorId"
                style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          :reserve-selection="true"
          width="50">
        </el-table-column>
        <el-table-column label="编码" property="operatorId" align="left" header-align="center"/>
        <el-table-column label="名称" property="operatorName" align="left" header-align="center"/>
      </el-table>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveHsfApproverChooseModal">确定</el-button>
        <el-button type="primary" @click="hsfApproverFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="人员选择" @open="openRelatedPeopleDialog" @close="closeRelatedPeopleDialog" v-drag
               :visible.sync="relatedPeopleFlag" width="40vw" :close-on-click-modal="false">
      <el-form :inline="true" label-position="top" :model="relatedPeopleSearchData">
        <el-form-item label="编码">
          <el-input v-model="relatedPeopleSearchData.operatorId" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="名称">
          <el-input v-model="relatedPeopleSearchData.operatorName" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" @click="filterRelatedPeopleOptions">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-if="relatedPeopleFlag"
                :height="300"
                :data="relatedPeopleDisplayList"
                highlight-current-row
                @current-change="handleRelatedPeopleCurrentChange"
                @row-click="handleRelatedPeopleTableClick"
                ref="relatedPeopleTable"
                border
                style="width: 100%;">
        <el-table-column label="编码" property="operatorId" align="left" header-align="center"/>
        <el-table-column label="名称" property="operatorName" align="left" header-align="center"/>
      </el-table>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveRelatedPeopleChooseModal">确定</el-button>
        <el-button type="primary" @click="relatedPeopleFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="驳回" top="30vh" :close-on-click-modal="false" v-drag :visible.sync="submitModalFlag" width="500px">
      <el-form label-position="top">
        <el-form-item label="驳回意见/Reject Opinion">
          <el-input type="textarea" v-model="rejectOpinion" :rows="3" resize="none" show-word-limit style="width: 479px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:35px;margin-top:50px;text-align:center">
        <el-button type="primary" :loading="submitLoading" @click="rejectSubmit">确定</el-button>
        <el-button type="primary" @click="submitModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog width="700px" title="备注" :close-on-click-modal="false" :visible.sync="rohsRemarkFlag" v-drag>
      <el-form label-position="top">
        <el-form-item label="备注说明">
          <el-input
            type="textarea"
            v-model="rohsRemarkForm.remark"
            :rows="6"
            maxlength="255"
            show-word-limit
            resize="none">
          </el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:35px;margin-top:110px;text-align:center">
        <el-button type="primary" @click="refreshRohsRemark">刷新</el-button>
        <el-button type="primary" @click="saveRohsRemark">保存</el-button>
        <el-button type="primary" @click="rohsRemarkFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog width="700px" title="材料描述" :close-on-click-modal="false" :visible.sync="rohsMaterialDescFlag" v-drag>
      <el-form label-position="top">
        <el-form-item label="材料描述">
          <el-input
            type="textarea"
            v-model="rohsMaterialDescForm.materialDesc"
            :rows="6"
            maxlength="255"
            show-word-limit
            resize="none">
          </el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:35px;margin-top:110px;text-align:center">
        <el-button type="primary" @click="refreshRohsMaterialDesc">刷新</el-button>
        <el-button type="primary" @click="saveRohsMaterialDesc">保存</el-button>
        <el-button type="primary" @click="rohsMaterialDescFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <!-- 底部附件页签 -->
    <el-tabs v-model="activeTable" style="width: 100%; height: 100%;" type="border-card" @tab-click="refreshCurrentTabTable" class="customer-tab">
      <el-tab-pane label="基本信息" name="basicInfo">
        <div :style="{height: secondHeight + 'px'}" style="margin-left: 5px;margin-top: 5px; overflow-y: auto;">
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item>
              <span slot="label">申请人/Reference No.</span>
              <el-input :value="currentRow.applicant || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.applicantName || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item label="申请日期/Date">
              <el-date-picker :value="currentRow.applicationDate" disabled type="date" value-format="yyyy-MM-dd" style="width: 150px"></el-date-picker>
            </el-form-item>
            <el-form-item label="Site">
              <el-input :value="currentRow.site || ''" disabled style="width: 95px"></el-input>
            </el-form-item>
            <el-form-item label="工艺/Process">
              <el-input :value="currentRow.process || ''" disabled style="width: 121px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item>
              <span slot="label">最终客户/End Customer</span>
              <el-input :value="currentRow.endCustomer || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.endCustomerName || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item>
              <span slot="label">项目编码/Project</span>
              <el-input :value="currentRow.projectId || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.projectName || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item label="WM所需求规格/The size that WM need">
              <el-input :value="currentRow.wmRequiredSpec || ''" disabled style="width: 260px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="供应商/Vendor Code">
              <el-input :value="currentRow.vendorCode || ''" disabled style="width: 396px"></el-input>
            </el-form-item>
            <el-form-item label="供应商材料编码/Vendor Material Code">
              <el-input :value="currentRow.vendorMaterialCode || ''" disabled style="width: 396px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="材料分类/Material Classify">
              <el-input type="textarea" :rows="2" resize="none" :value="currentRow.materialClassify || ''" disabled style="width: 532px"></el-input>
            </el-form-item>
            <el-form-item label="其他分类/Other Material Classify" v-if="currentRow.materialClassify && currentRow.materialClassify.includes('Other其他')">
              <el-input :value="currentRow.otherMaterialClassify || ''" disabled style="width: 260px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 30px">
            <el-form-item label="辅材用途/Assiaccessorial Material Use for">
              <el-input :value="currentRow.materialUseFor || ''" disabled style="width: 259px"></el-input>
            </el-form-item>
            <el-form-item>
              <span slot="label">技术计划/TP</span>
              <el-input :value="currentRow.technicalPlan || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.technicalPlanName || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item>
              <span slot="label">PM人员/PM</span>
              <el-input :value="currentRow.pm || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.pmName || ''" disabled style="width: 156px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="颜色/Color">
              <el-input :value="currentRow.color || ''" disabled style="width: 532px"></el-input>
            </el-form-item>
            <el-form-item label="计划转量产时间/Planned Mass Production Date">
              <el-date-picker :value="normalizeDateOnly(currentRow.plannedMassProductionDate)" disabled type="date" value-format="yyyy-MM-dd" style="width: 260px"></el-date-picker>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item>
              <span slot="label">商品组1/Comm Group 1</span>
              <el-input :value="currentRow.commGroup1 || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.commGroup1Desc || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item>
              <span slot="label">商品组2/Comm Group 2</span>
              <el-input :value="currentRow.commGroup2 || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.commGroup2Desc || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
            <el-form-item>
              <span slot="label">商品组3/Comm Group 3</span>
              <el-input :value="currentRow.commGroup3 || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.commGroup3Desc || ''" disabled style="width: 156px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="是否是Fiber材料">
              <el-radio-group :value="currentRow.isFiberMaterial" disabled style="width: 145px">
                <el-radio label="Y">是</el-radio>
                <el-radio label="N">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否需要创建300/700/900号/Dose Need Create 300/700/900 Number">
              <el-radio-group :value="currentRow.needCreateNumber" disabled style="width: 374px">
                <el-radio label="Y">是</el-radio>
                <el-radio label="N">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="材料厚度/Material Thickness">
              <el-input :value="currentRow.materialThickness || ''" disabled style="width: 260px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="材料有效期/Material Validity Time">
              <dict-data-select :value="currentRow.materialValidityTime || ''" :use-default-value="false" disabled style="width: 260px" dict-type="rohs_material_validity_time"></dict-data-select>
            </el-form-item>
            <el-form-item label="是否需要Deviation/If need deviation or not">
              <el-radio-group :value="currentRow.needDeviation" disabled style="width: 259px">
                <el-radio label="Y">是</el-radio>
                <el-radio label="N">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <span slot="label">NPD工程师/NPD Engineer</span>
              <el-input :value="currentRow.npdEngineer || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.npdEngineerName || ''" disabled style="width: 155px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="材料有效期备注/Material Validity Time Comments">
              <el-input :value="currentRow.materialValidityComments || ''" disabled style="width: 260px"></el-input>
            </el-form-item>
            <el-form-item label="预计提供报告时间(一个月内)/Expect Date" style="margin-left: -2px">
              <el-date-picker :value="normalizeDateOnly(currentRow.expectReportTime)" disabled type="date" value-format="yyyy-MM-dd" style="width: 259px"></el-date-picker>
            </el-form-item>
            <el-form-item>
              <span slot="label">采购/Buyer</span>
              <el-input :value="currentRow.buyer || ''" disabled style="width: 100px"></el-input>
              <el-input :value="currentRow.buyerName || ''" disabled style="width: 156px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="所需审批文件/Qualification Documents needed">
              <el-input type="textarea" :rows="2" resize="none" :value="currentRow.qualificationDocumentsNeeded || ''" disabled style="width: 807px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 30px">
            <el-form-item label="测试报告必测项/Test Report including items">
              <el-input type="textarea" :rows="2" resize="none" :value="currentRow.testReportIncludingItems || ''" disabled style="width: 807px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 30px">
            <el-form-item label="备注说明/Comments" style="display: block;">
              <el-input type="textarea" :rows="3" :value="currentRow.remark || ''" disabled resize="none" style="width: 804px;height: 30px"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-tab-pane>

      <el-tab-pane label="NPD 信息" name="npdInfo">
        <div :style="{height: secondHeight + 'px'}" style="margin-left: 5px;margin-top: 5px; overflow-y: auto;">
<!--          <el-form :inline="true" label-position="top" :model="currentRow">-->
<!--            <el-form-item label="现有材料不同规格/Same Material Diff Size">-->
<!--              <el-radio-group :value="currentRow.isSameMaterialDiffSize" disabled style="width: 190px">-->
<!--                <el-radio label="Y">是</el-radio>-->
<!--                <el-radio label="N">否</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
<!--          </el-form>-->
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="材料描述/Material Desc." style="display: block;"><el-input type="textarea" :rows="3" :value="currentRow.materialDesc || ''" disabled resize="none" style="width: 804px;height: 30px"></el-input></el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 50px">
            <el-form-item label="备注说明/NPD Remark" style="display: block;"><el-input type="textarea" :rows="3" :value="currentRow.npdRemark || ''" disabled resize="none" style="width: 804px;height: 30px"></el-input></el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 50px">
            <el-form-item label="内部TDS/Inner TDS" style="display: block;">
              <oss-components
                ref="bottomTdsOss"
                :save-visible="authFileSave"
                :edit-visible="false"
                :download-visible="authFileDownLoad"
                :remove-visible="authFileRemove"
                :preview-visible="authFilePreview"
                :disabled="true"
                label="序列号"
                :height="180"
                style="margin-top: 2px"
                :columns="tdsFileColumnList"
                :order-ref1="currentRow.site || ''"
                :order-ref2="currentRow.referenceNo || ''"
                order-ref3="tdsProperty">
              </oss-components>
            </el-form-item>
          </el-form>
        </div>
      </el-tab-pane>

      <el-tab-pane label="HSF 填写信息" name="hsfInfo">
        <div :style="{height: secondHeight + 'px'}" style="margin-left: 5px;margin-top: 5px; overflow-y: auto;">
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="报告日期/Report Date">
              <el-date-picker :value="currentRow.expiredDate" disabled type="date" value-format="yyyy-MM-dd" style="width: 150px"></el-date-picker>
            </el-form-item>
            <el-form-item label="有效期数值/Valid Until Value">
              <el-input :value="currentRow.validUntilValue || ''" disabled style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="有效期单位/Valid Until Unit">
              <el-input :value="currentRow.validUntil || ''" disabled style="width: 150px"></el-input>
            </el-form-item>
            <el-form-item label="失效日期/Expiry Date">
              <el-date-picker :value="currentRow.expiryDate" disabled type="date" value-format="yyyy-MM-dd" style="width: 150px"></el-date-picker>
            </el-form-item>
            <el-form-item label="状态/Status">
              <el-input :value="currentRow.rohsStatus || ''" disabled style="width: 150px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="是否符合RoHS/Meet RoHS Req">
              <el-radio-group :value="currentRow.isMeetRohsRequirement" disabled style="width: 190px">
                <el-radio label="Y">是</el-radio>
                <el-radio label="N">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label=" ">
              <el-checkbox
                :value="currentRow.isAhGrade"
                true-label="Y"
                false-label="N"
                disabled
                style="width: 190px">材料属性是否是AH/Is AH Grade</el-checkbox>
            </el-form-item>
            <el-form-item label="HSF供应商等级/Supplier Class">
              <el-radio-group :value="currentRow.hsfSupplierClassification" disabled style="width: 260px">
                <el-radio label="高风险">高风险</el-radio>
                <el-radio label="中风险">中风险</el-radio>
                <el-radio label="低风险">低风险</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow">
            <el-form-item label="Fiber报告信息/Fiber Information" style="display: block;"><el-input type="textarea" :rows="3" :value="currentRow.fiberInformation || ''" disabled resize="none" style="width: 804px;height: 30px"></el-input></el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="currentRow" style="margin-top: 45px">
            <el-form-item label="HSF审批人/HSF Approver"><el-input :value="currentRow.hsfApproverName || currentRow.hsfApprover || ''" disabled style="width: 396px"></el-input></el-form-item>
            <el-form-item label="Inform Related people"><el-input :value="currentRow.relatedPeopleName || currentRow.relatedPeople || ''" disabled style="width: 396px"></el-input></el-form-item>
          </el-form>
          <el-form v-if="shouldShowHsfStandard(currentRow.endCustomer)" :inline="true" label-position="top" :model="currentRow" style="margin-top: 0px">
            <el-form-item label="HSF标准/HSF Standard" style="display: block;"><el-input type="textarea" :rows="3" :value="currentRow.hsfStandard || ''" disabled resize="none" style="width: 804px;height: 30px"></el-input></el-form-item>
          </el-form>
        </div>
      </el-tab-pane>

      <el-tab-pane label="材料信息" name="materialInfo">
        <div :style="{height: secondHeight + 'px'}" style="overflow-y: auto;">
          <el-table
            class="rohs-material-table"
            border
            :data="currentRow.materialList || []"
            :height="secondHeight"
            style="width: 100%">
            <el-table-column type="index" label="序号" width="50" header-align="center" align="center"></el-table-column>
            <el-table-column prop="finalPartNo" label="IFS物料编码/Final Part No." min-width="150" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="partDesc" label="描述/Part Desc." min-width="250" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="partStatus" label="状态/Part Status" min-width="100" header-align="center" align="left" :show-overflow-tooltip="true"></el-table-column>
          </el-table>
        </div>
      </el-tab-pane>

      <el-tab-pane label="附件信息" name="attachment">
        <oss-components
          ref="bottomAttachmentOss"
          :save-visible="authFileSave"
          :edit-visible="authFileSave"
          :download-visible="authFileDownLoad"
          :remove-visible="authFileRemove"
          :preview-visible="authFilePreview"
          :disabled="currentRow.status === '已完成'"
          :show-order-ref3-filter="true"
          :order-ref3-filter-options="rohsAttachmentTypeOptionList"
          :query-order-ref3-list="rohsAttachmentQueryOrderRef3List"
          :order-ref3-filter-query-map="rohsAttachmentTypeFilterQueryMap"
          :order-ref3-label-map="rohsAttachmentTypeLabelMap"
          label="序列号"
          :height="secondHeight - 25"
          style="margin-top: 2px"
          :columns="rohsAttachmentSummaryColumnList"
          :order-ref1="currentRow.site"
          :order-ref2="currentRow.referenceNo">
        </oss-components>
      </el-tab-pane>
      <el-tab-pane label="审批信息" name="approvalInformation">
        <approval-information v-model:data-list="approvalList" :height="secondHeight"></approval-information>
      </el-tab-pane>
    </el-tabs>
    <ChooseList ref="baseList" @getBaseData="getBaseData"></ChooseList>
    <filter-search :visible.sync="filterVisible" @search="queryByAnyField"></filter-search>
  </div>
</template>

<script>
import * as api from '@/api/rohs/rohs'
import { checkSuperAdmin } from "@/api/changeManagement/changeManagement"
import { verifyData } from "@/api/chooselist/chooselist.js"
import { searchProjectInfoList } from "@/api/quotation/quotationInformation.js"
import { queryCustomer } from "@/api/customer/customerInformation"
import { queryProjectByCustomer } from "@/api/project/project"
import { createOfficialPartForRohs, getNextPartNo as getPartNextPartNo, getItemListByCodeNo as getPartItemListByCodeNo, getItemExclusionAlreadyExists as getPartItemExclusionAlreadyExists } from "@/api/part/partInformation.js"
import uploadFileList from '../common/uploadFileList'
import ossComponents from '../oss/ossComponents.vue'
import ChooseList from '@/views/modules/common/Chooselist'
import DictDataSelect from "../sys/dict-data-select.vue"
import ApprovalInformation from "../changeManagement/approvalInformation.vue"
import FilterSearch from "../../common/filterSearch.vue"

export default {
  components: {
    uploadFileList,
    ossComponents,
    ChooseList,
    DictDataSelect,
    ApprovalInformation,
    FilterSearch
  },
  data () {
    return {
      searchData: {
        site: this.$store.state.user.site,
        referenceNo: '',
        status: '',
        rohsStatus: '',
        currentApprover: '',
        nodeId: ''
      },
      exportLoading: false,
      exportData: [],
      exportFieldMap: {},
      exportName: '',
      exportHeader: ['RoHs记录'],
      exportFooter: [],
      resultList: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,

      activeTable: 'basicInfo',
      menuId: '112001',
      authSearch: false,
      authUpdate: false,
      authIssue: false,
      authSubmit: false,
      authReject: false,
      authFileSave: false,
      authFileDownLoad: false,
      authFileRemove: false,
      authFilePreview: false,
      authDataEntry: false,
      authMaterialDescRemark: false,
      authDelete: false,
      superAdmin: false,
      createBy2: this.$store.state.user.name,
      height: 400,
      secondHeight: 200,
      currentRow: {},
      fileColumnList: [
        {
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 140
        },
        {
          columnProp: 'fileRemark',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 120
        }
      ],
      rohsAttachmentTypeOptionList: [
        { value: 'rohsAttachmentTds', label: 'TDS' },
        { value: 'rohsAttachmentMsds', label: 'MSDS' },
        { value: 'rohsAttachmentTestReport', label: '测试报告' },
        { value: 'rohsAttachmentOther', label: 'Other' }
      ],
      rohsAttachmentTypeLabelMap: {
        rohsAttachmentTds: 'TDS',
        rohsAttachmentMsds: 'MSDS',
        rohsAttachmentTestReport: '测试报告',
        rohsAttachmentOther: 'Other',
        rohsAttachment: 'Other'
      },
      rohsAttachmentQueryOrderRef3List: [
        'rohsAttachmentTds',
        'rohsAttachmentMsds',
        'rohsAttachmentTestReport',
        'rohsAttachmentOther',
        'rohsAttachment'
      ],
      rohsAttachmentTypeFilterQueryMap: {
        rohsAttachmentTds: ['rohsAttachmentTds'],
        rohsAttachmentMsds: ['rohsAttachmentMsds'],
        rohsAttachmentTestReport: ['rohsAttachmentTestReport'],
        rohsAttachmentOther: ['rohsAttachmentOther', 'rohsAttachment']
      },
      rohsAttachmentSummaryColumnList: [
        {
          columnProp: 'orderRef3Label',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          columnProp: 'fileRemark',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 220
        },
        {
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 120
        }
      ],
      tdsFileColumnList: [
        {
          columnProp: 'fileNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 130
        },
        {
          columnProp: 'rev',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '版本号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 90
        },
        {
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          columnProp: 'fileRemark',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 180
        },
        {
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          columnProp: 'invalidationTime',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '失效时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          status: true,
          fixed: '',
          columnWidth: 120
        }
      ],

      modalFlag: false,
      chooseProjectListFlag: false,
      projectMaterialDialogFlag: false,
      rohsCreatePartDialogFlag: false,
      rohsCreatePartLoading: false,
      rohsCreatePartTab: 'General',
      rohsCreatePartTagNo: 0,
      rohsCharacteristicDialogFlag: false,
      rohsCharacteristicQueryData: {
        propertiesItemNo: '',
        itemDesc: ''
      },
      rohsCharacteristicList: [],
      rohsCharacteristicSelections: [],
      rohsPartItemSelections: [],
      rohsCreatePartColumnItemList: [
        {
          columnProp: 'propertiesItemNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'itemDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          columnProp: 'valueType',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '属性类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          columnProp: 'textValue',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性值',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 140
        }
      ],
      rohsCharacteristicColumnList: [
        {
          columnProp: 'propertiesItemNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'itemDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          columnProp: 'valueType',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '属性类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 60
        }
      ],
      rohsCreatePartData: {
        site: '',
        partNo: '',
        partDesc: '',
        partType: 'Purchased',
        hazardCode: '',
        hazardDesc: '',
        familyId: '',
        familyName: '',
        groupId: '',
        groupName: '',
        umId: '',
        umName: '',
        weightNet: '',
        uomForWeightNet: 'kg',
        volumeNet: '',
        uomForVolumeNet: 'm3',
        lotTrackingCode: 'Order Based',
        remark: '',
        productGroupId1: '',
        productGroupName1: '',
        productGroupId2: '',
        productGroupName2: '',
        productGroupId3: '',
        productGroupName3: '',
        productGroupId4: '*',
        productGroupName4: 'NorthSky Application owner',
        commGroup3: '',
        commGroup3Desc: '',
        codeNo: '',
        codeDesc: '',
        typeDesignation: '',
        assetClass: 'S',
        assetClassDesc: '标准',
        dimQuality: '',
        abcClass: 'C',
        abcClassDesc: '',
        frequencyClass: 'Very Slow Mover',
        lifecycleStage: 'Development',
        countryOfOrigin: '',
        countryOfOriginDesc: '',
        regionOfOrigin: '',
        regionOfOriginDesc: '',
        manufacturingLeadTime: 0,
        expectedLeadTime: 0,
        durabilityWeek: '',
        durabilityDay: '',
        intrastatConvFactor: undefined,
        customsStatNo: '',
        customsStatDesc: '',
        umDesc: '',
        planningMethod: 'A',
        planningMethodDesc: '',
        partStatus: 'A',
        partStatusDesc: '活动',
        active: 'Y',
        status: 'Y',
        supplyCode: 'Inventory Order',
        configurationId: '*',
        partCostGroupId: '',
        partCostGroupDesc: '',
        inventoryValuationMethod: 'Standard Cost',
        inventoryPartCostLevel: 'Cost Per Part',
        invoiceConsideration: 'Ignore Invoice Price',
        zeroCostFlag: 'Zero Cost Forbidden',
        estimatedMaterialCost: 0,
        safetyStock: 0,
        minOrderQty: 0,
        maxOrderQty: 0,
        mulOrderQty: 0,
        safetyLeadTime: 0,
        shrinkageFac: 0,
        stdOrderQty: 0,
        cumLeadTime: 0,
        byProdAsSupplyInMrpDb: '',
        unprotectedLeadTime: 0,
        backFlushPart: 'All Locations',
        issueType: 'Reserve And Backflush',
        mrpControlFlagDb: 'Y',
        fixedLeadTimeDay: 0,
        overReporting: 'Allowed',
        useTheoreticalDensityDb: '',
        variableLeadTimeDay: 0,
        overReportTolerance: 0,
        fixedLeadTimeHour: 0,
        density: undefined,
        variableLeadTimeHour: 0,
        showInQueryFlag: 'Y',
        temporaryPartFlag: 'N',
        partItemList: []
      },
      searchProjectData: {
        site: '',
        projectId: undefined,
        projectName: undefined,
        customerId: undefined,
      },
      projectMaterialSearchData: {
        finalPartNo: '',
        partDesc: '',
        partStatus: ''
      },
      projectMaterialList: [],
      projectMaterialSelections: [],
      dataListSelections: [],
      materialSelections: [],
      projectMaterialPageIndex: 1,
      projectMaterialPageSize: 20,
      projectMaterialTotal: 0,
      projectMaterialLoading: false,
      nodeOptions: [],
      projectList: [],
      hsfApproverOptionList: [],
      hsfApproverDisplayList: [],
      hsfApproverSelectionCache: [],
      hsfApproverFlag: false,
      hsfApproverSearchData: {
        operatorId: '',
        operatorName: ''
      },
      relatedPeopleOptionList: [],
      relatedPeopleDisplayList: [],
      relatedPeopleSelection: null,
      relatedPeopleFlag: false,
      relatedPeopleSearchData: {
        operatorId: '',
        operatorName: ''
      },
      filterVisible: false,
      isFilterSearch: false,
      filterSearchData: {},
      approvalList: [],
      plmRohsAuthorityArr: [],
      nodeAuthorityLoaded: false,
      isEditMode: false,
      modalTitle: 'RoHS 新增',
      activeName: 'basicInfo',
      showModalFlag: false,
      submitModalFlag: false,
      rohsRemarkFlag: false,
      rohsMaterialDescFlag: false,
      rejectOpinion: '',
      submitLoading: false,
      rohsRemarkForm: {
        remark: ''
      },
      rohsMaterialDescForm: {
        materialDesc: ''
      },
      hsfStandardDefaultText: 'With the follow environmental specification: Macallan regulated Substances specification(069-0135) /Macallan sustainable fiber specification(099-00532)',
      modalData: {
        site: 'DEFAULT',
        referenceNo: '',
        applicant: '',
        pm: '',
        pmName: '',
        applicationDate: '',
        process: '',
        plannedMassProductionDate: '',
        color: '',
        vendorCode: '',
        vendorMaterialCode: '',
        materialClassify: '',
        otherMaterialClassify: '',
        materialUseFor: '',
        endCustomer: '',
        projectId: '',
        commGroup1: '',
        commGroup1Desc: '',
        commGroup2: '',
        commGroup2Desc: '',
        commGroup3: '',
        commGroup3Desc: '',
        needCreateNumber: '',
        npdEngineer: '',
        materialValidityTime: '',
        materialValidityComments: '',
        needDeviation: '',
        technicalPlan: '',
        wmRequiredSpec: '',
        isFiberMaterial: '',
        materialThickness: '',
        buyer: '',
        expectReportTime: '',
        qualificationDocumentsNeeded: '',
        qualificationDocumentsNeededList: [],
        testReportIncludingItems: '',
        testReportIncludingItemsList: [],
        remark: '',
        status: '',
        sgsReportNumber: '',
        rohsStatus: 'Active',
        expiredDate: '',
        expiryDate: '',
        fiberInformation: '',
        hsfStandard: '',
        hsfApprover: '',
        hsfApproverName: '',
        hsfApproverCodeList: [],
        relatedPeople: '',
        relatedPeopleName: '',
        buNo: '',
        validUntilValue: 0,
        validUntil: '',
        isMeetRohsRequirement: '',
        isAhGrade: 'N',
        hsfSupplierClassification: '',
        materialDesc: '',
        npdRemark: '',
        isSameMaterialDiffSize: '',
        ifsPartNo: '',
        materialList: [],
        stepId: null,
        rejectFlag: '',
        rejectStepId: null,
        createBy2: '',
        isReject: 'Y',
        tpProcessControl: 'N',
        csProcessControl: 'N'
      }
    }
  },
  created () {
    this.menuId = (this.$route.meta && this.$route.meta.menuId) || this.menuId || '112001'
    this.getButtonAuthData()
    this.checkSuperAdmin()
  },
  mounted () {
    this.fetchNodeOptions()
    if (this.authSearch) {
      this.getDataList()
    }
    this.$nextTick(() => {
      this.height = window.innerHeight / 2 - 30
      /*第二个表格高度的动态调整*/
      this.secondHeight = window.innerHeight / 2  - 186
    })
  },
  watch: {
    activeName (val) {
      if (val === 'attachmentInfo' || val === 'npdInfo') {
        this.$nextTick(() => {
          if (val === 'attachmentInfo') {
            this.refreshOssRef('modalAttachmentTdsOss')
            this.refreshOssRef('modalAttachmentMsdsOss')
            this.refreshOssRef('modalAttachmentTestReportOss')
            this.refreshOssRef('modalAttachmentOtherOss')
          }
          if (val === 'npdInfo') {
            this.refreshOssRef('modalTdsOss')
          }
        })
      }
    },
    'modalData.expiredDate' () {
      this.syncExpiryDateByRule()
    },
    'modalData.validUntilValue' () {
      this.syncExpiryDateByRule()
    },
    'modalData.validUntil' () {
      this.syncExpiryDateByRule()
    },
    'modalData.endCustomer' () {
      this.applyHsfStandardDefaultByCustomer(this.modalData)
    }
  },
  methods: {
    fetchNodeOptions () {
      if (!this.searchData.site || !this.menuId) {
        this.nodeOptions = []
        return
      }
      let params = {
        site: this.searchData.site,
        menuId: this.menuId
      }
      api.getNodeList(params).then(({data}) => {
        if (data && data.code === 0 && Array.isArray(data.rows)) {
          this.nodeOptions = data.rows
            .filter(item => item && item.nodeId)
            .map(item => ({
              id: item.nodeId,
              name: item.nodeName
            }))
        } else {
          this.nodeOptions = []
        }
      }).catch(() => {
        this.nodeOptions = []
      })
    },
    loadNodeAuthority (site, stepId) {
      if (!site || stepId === null || stepId === undefined || !this.menuId) {
        this.plmRohsAuthorityArr = []
        this.nodeAuthorityLoaded = true
        return Promise.resolve()
      }
      this.nodeAuthorityLoaded = false
      let params = {
        site: site,
        stepId: stepId,
        menuId: this.menuId
      }
      return api.getRohsNodeAuthority(params).then(({data}) => {
        if (data && data.code === 0 && data.rows) {
          this.plmRohsAuthorityArr = data.rows.plm_rohs || []
        } else {
          this.plmRohsAuthorityArr = []
        }
        this.nodeAuthorityLoaded = true
      }).catch(() => {
        this.plmRohsAuthorityArr = []
        this.nodeAuthorityLoaded = true
      })
    },
    rohsFieldFlag (fieldId) {
      if (!this.plmRohsAuthorityArr || this.plmRohsAuthorityArr.length === 0) {
        return 'N'
      }
      let target = this.plmRohsAuthorityArr.find(item => item.fieldId === fieldId)
      return target ? target.updateFlag : 'N'
    },
    isRohsFieldDisabled (fieldId) {
      if (this.showModalFlag) {
        return true
      }
      if (!this.isEditMode) {
        return false
      }
      return this.rohsFieldFlag(fieldId) === 'N'
    },
    isProcessFieldDisabled () {
      if (this.isEditMode) {
        return true
      }
      return this.isRohsFieldDisabled('process')
    },
    handleProcessChange (value) {
      const processValue = String(value || '').trim()
      this.$set(this.modalData, 'process', processValue)
      this.$set(this.modalData, 'buNo', processValue)
      if (this.isEditMode) {
        return
      }
      this.clearHsfApproverFields(false)
      if (!processValue) {
        return
      }
      this.loadHsfApproverByCurrentProcess(true)
    },
    isRohsFieldDisabledWithFallback (primaryFieldId, fallbackFieldId) {
      if (this.showModalFlag) {
        return true
      }
      if (!this.isEditMode) {
        return false
      }
      const primaryDisabled = this.rohsFieldFlag(primaryFieldId) === 'N'
      if (!primaryDisabled) {
        return false
      }
      return this.rohsFieldFlag(fallbackFieldId) === 'N'
    },
    isValidUntilValueDisabled () {
      return this.isRohsFieldDisabledWithFallback('validUntilValue', 'validUntil')
    },
    isValidUntilUnitDisabled () {
      return this.isRohsFieldDisabledWithFallback('validUntil', 'validUntilValue')
    },
    canEditRohsMaterial () {
      return !this.showModalFlag
    },
    normalizeDateOnly (value) {
      if (value === null || value === undefined || value === '') {
        return ''
      }
      if (value instanceof Date && !Number.isNaN(value.getTime())) {
        const year = value.getFullYear()
        const month = String(value.getMonth() + 1).padStart(2, '0')
        const day = String(value.getDate()).padStart(2, '0')
        return year + '-' + month + '-' + day
      }
      const text = String(value).trim()
      if (!text) {
        return ''
      }
      if (text.includes('T')) {
        return text.split('T')[0]
      }
      return text.length >= 10 ? text.substring(0, 10) : text
    },
    parseDateOnly (value) {
      const text = this.normalizeDateOnly(value)
      if (!text) {
        return null
      }
      const parts = text.split('-')
      if (parts.length !== 3) {
        return null
      }
      const year = Number.parseInt(parts[0], 10)
      const month = Number.parseInt(parts[1], 10)
      const day = Number.parseInt(parts[2], 10)
      if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day)) {
        return null
      }
      const date = new Date(year, month - 1, day)
      if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
        return null
      }
      return date
    },
    normalizeValidUntilUnitType (unitValue) {
      const text = String(unitValue || '').trim().toLowerCase()
      if (!text) {
        return ''
      }
      if (text === 'd' || text === 'day' || text === 'days' || text.includes('日')) {
        return 'day'
      }
      if (text === 'w' || text === 'week' || text === 'weeks' || text.includes('周')) {
        return 'week'
      }
      if (text === 'm' || text === 'month' || text === 'months' || text.includes('月')) {
        return 'month'
      }
      if (text === 'y' || text === 'year' || text === 'years' || text.includes('年')) {
        return 'year'
      }
      return ''
    },
    addMonthsKeepDay (baseDate, monthDelta) {
      const year = baseDate.getFullYear()
      const month = baseDate.getMonth()
      const day = baseDate.getDate()
      const targetFirstDay = new Date(year, month + monthDelta, 1)
      const targetYear = targetFirstDay.getFullYear()
      const targetMonth = targetFirstDay.getMonth()
      const lastDay = new Date(targetYear, targetMonth + 1, 0).getDate()
      return new Date(targetYear, targetMonth, Math.min(day, lastDay))
    },
    addYearsKeepDay (baseDate, yearDelta) {
      const targetYear = baseDate.getFullYear() + yearDelta
      const month = baseDate.getMonth()
      const day = baseDate.getDate()
      const lastDay = new Date(targetYear, month + 1, 0).getDate()
      return new Date(targetYear, month, Math.min(day, lastDay))
    },
    calculateExpiryDateByRule (reportDate, validUntilValue, validUntilUnit) {
      const baseDate = this.parseDateOnly(reportDate)
      const durationValue = this.normalizeValidUntilValue(validUntilValue)
      const unitType = this.normalizeValidUntilUnitType(validUntilUnit)
      if (!baseDate || !durationValue || !unitType) {
        return ''
      }
      let resultDate = new Date(baseDate.getTime())
      if (unitType === 'day') {
        resultDate.setDate(resultDate.getDate() + durationValue)
      } else if (unitType === 'week') {
        resultDate.setDate(resultDate.getDate() + durationValue * 7)
      } else if (unitType === 'month') {
        resultDate = this.addMonthsKeepDay(baseDate, durationValue)
      } else if (unitType === 'year') {
        resultDate = this.addYearsKeepDay(baseDate, durationValue)
      } else {
        return ''
      }
      return this.normalizeDateOnly(resultDate)
    },
    syncExpiryDateByRule () {
      if (!this.modalData) {
        return ''
      }
      const expiryDate = this.calculateExpiryDateByRule(this.modalData.expiredDate, this.modalData.validUntilValue, this.modalData.validUntil)
      this.$set(this.modalData, 'expiryDate', expiryDate)
      return expiryDate
    },
    getCurrentDateString () {
      return this.normalizeDateOnly(new Date())
    },
    normalizeCheckboxFlag (value) {
      return String(value || '').trim().toUpperCase() === 'Y' ? 'Y' : 'N'
    },
    normalizeValidUntilValue (value) {
      if (value === null || value === undefined || value === '') {
        return null
      }
      const parsed = Number.parseInt(value, 10)
      if (Number.isNaN(parsed) || parsed <= 0) {
        return null
      }
      return parsed
    },
    getValidUntilDisplay (value, unit) {
      const normalizedValue = this.normalizeValidUntilValue(value)
      const normalizedUnit = String(unit || '').trim()
      if (normalizedValue && normalizedUnit) {
        return normalizedValue + normalizedUnit
      }
      if (normalizedValue) {
        return String(normalizedValue)
      }
      return normalizedUnit
    },
    getRohsSubmitFieldValue (fieldId) {
      const fieldMapping = {
        materialClassify: 'materialClassifyList',
        qualificationDocumentsNeeded: 'qualificationDocumentsNeededList',
        testReportIncludingItems: 'testReportIncludingItemsList',
        hsfApprover: 'hsfApproverCodeList'
      }
      const mappedField = fieldMapping[fieldId]
      if (mappedField) {
        return this.modalData[mappedField]
      }
      return this.modalData[fieldId]
    },
    isSubmitFieldEmpty (value) {
      if (Array.isArray(value)) {
        return value.length === 0
      }
      if (typeof value === 'string') {
        return value.trim() === ''
      }
      return !value
    },
    validateSubmitRequiredFields () {
      if (this.plmRohsAuthorityArr && this.plmRohsAuthorityArr.length > 0) {
        let validUntilPairRequiredChecked = false
        for (let i = 0; i < this.plmRohsAuthorityArr.length; i++) {
          const fieldConfig = this.plmRohsAuthorityArr[i]
          if (fieldConfig.required !== 'Y') {
            continue
          }
          if (fieldConfig.fieldId === 'hsfStandard' && !this.shouldShowHsfStandard(this.modalData.endCustomer)) {
            continue
          }
          if (fieldConfig.fieldId === 'validUntil' || fieldConfig.fieldId === 'validUntilValue') {
            if (validUntilPairRequiredChecked) {
              continue
            }
            const validUntilValue = this.normalizeValidUntilValue(this.modalData.validUntilValue)
            this.$set(this.modalData, 'validUntilValue', validUntilValue)
            if (this.isSubmitFieldEmpty(validUntilValue) || this.isSubmitFieldEmpty(this.modalData.validUntil)) {
              this.$message.warning('有效期数值/单位不能为空!')
              return false
            }
            validUntilPairRequiredChecked = true
            continue
          }
          const value = this.getRohsSubmitFieldValue(fieldConfig.fieldId)
          if (this.isSubmitFieldEmpty(value)) {
            this.$message.warning((fieldConfig.fieldName || fieldConfig.fieldId) + '不能为空!')
            return false
          }
        }
      }

      return true
    },
    validateValidUntilPair () {
      const validUntilValue = this.normalizeValidUntilValue(this.modalData.validUntilValue)
      const validUntilUnit = String(this.modalData.validUntil || '').trim()
      this.$set(this.modalData, 'validUntilValue', validUntilValue)
      this.$set(this.modalData, 'validUntil', validUntilUnit)
      if (!validUntilValue && !validUntilUnit) {
        return true
      }
      if (!validUntilValue) {
        this.$message.warning('请填写有效期数值')
        return false
      }
      if (!validUntilUnit) {
        this.$message.warning('请选择有效期单位')
        return false
      }
      return true
    },
    materialDialogHeaderCellStyle () {
      return {
        whiteSpace: 'nowrap',
        wordBreak: 'keep-all'
      }
    },
    displayYesNo (value) {
      if (value === 'Y') {
        return '是'
      }
      if (value === 'N') {
        return '否'
      }
      return value || ''
    },
    getMultipleSelectTitle (value) {
      if (!Array.isArray(value)) {
        return ''
      }
      return value
        .filter(item => item !== null && item !== undefined && String(item).trim() !== '')
        .map(item => String(item).trim())
        .join('；')
    },
    shouldShowHsfStandard (customerCode) {
      return String(customerCode || '').trim().toUpperCase() === 'C00052'
    },
    applyHsfStandardDefaultByCustomer (formData) {
      if (!formData || !this.shouldShowHsfStandard(formData.endCustomer)) {
        return
      }
      const currentValue = String(formData.hsfStandard || '').trim()
      if (!currentValue) {
        this.$set(formData, 'hsfStandard', this.hsfStandardDefaultText)
      }
    },
    normalizeHsfStandardByCustomer (formData) {
      if (!formData) {
        return
      }
      if (!this.shouldShowHsfStandard(formData.endCustomer)) {
        this.$set(formData, 'hsfStandard', '')
        return
      }
      this.applyHsfStandardDefaultByCustomer(formData)
    },
    resolveOperatorNameById (operatorId) {
      const normalizedId = String(operatorId || '').trim()
      if (!normalizedId) {
        return ''
      }
      const option = (this.hsfApproverOptionList || []).find(item => String(item.operatorId || '').trim() === normalizedId) ||
        (this.relatedPeopleOptionList || []).find(item => String(item.operatorId || '').trim() === normalizedId)
      return option ? String(option.operatorName || '').trim() : normalizedId
    },
    resolveOperatorIdByCodeOrName (operatorValue) {
      const normalizedValue = String(operatorValue || '').trim()
      if (!normalizedValue) {
        return ''
      }
      const option = (this.hsfApproverOptionList || []).find(item => String(item.operatorId || '').trim() === normalizedValue) ||
        (this.hsfApproverOptionList || []).find(item => String(item.operatorName || '').trim() === normalizedValue) ||
        (this.relatedPeopleOptionList || []).find(item => String(item.operatorId || '').trim() === normalizedValue) ||
        (this.relatedPeopleOptionList || []).find(item => String(item.operatorName || '').trim() === normalizedValue)
      return option ? String(option.operatorId || '').trim() : normalizedValue
    },
    syncHsfApproverFields () {
      const sourceList = Array.isArray(this.modalData.hsfApproverCodeList)
        ? this.modalData.hsfApproverCodeList
        : []
      const uniqueCodeList = []
      const seen = new Set()
      sourceList.forEach(item => {
        const value = this.resolveOperatorIdByCodeOrName(item)
        if (!value || seen.has(value)) {
          return
        }
        seen.add(value)
        uniqueCodeList.push(value)
      })
      this.$set(this.modalData, 'hsfApproverCodeList', uniqueCodeList)
      this.$set(this.modalData, 'hsfApprover', uniqueCodeList.join(';'))
      this.$set(this.modalData, 'hsfApproverName', uniqueCodeList.map(item => this.resolveOperatorNameById(item)).join(';'))
      this.buildRelatedPeopleOptions(uniqueCodeList)

      const relatedPeopleCode = this.resolveOperatorIdByCodeOrName(this.modalData.relatedPeople)
      if (relatedPeopleCode && !uniqueCodeList.includes(relatedPeopleCode)) {
        this.$set(this.modalData, 'relatedPeople', '')
        this.$set(this.modalData, 'relatedPeopleName', '')
        return
      }
      if (relatedPeopleCode) {
        this.$set(this.modalData, 'relatedPeople', relatedPeopleCode)
        this.$set(this.modalData, 'relatedPeopleName', this.resolveOperatorNameById(relatedPeopleCode))
      }
    },
    buildRelatedPeopleOptions (selectedOperatorIds) {
      const normalizedIds = (Array.isArray(selectedOperatorIds) ? selectedOperatorIds : (this.modalData.hsfApproverCodeList || []))
        .map(item => this.resolveOperatorIdByCodeOrName(item))
        .filter(item => !!item)
      const selectedSet = new Set(normalizedIds)
      let optionList = (this.hsfApproverOptionList || [])
        .filter(item => selectedSet.has(String(item.operatorId || '').trim()))
        .map(item => ({
          operatorId: item.operatorId,
          operatorName: item.operatorName
        }))
      const existingIdSet = new Set(optionList.map(item => String(item.operatorId || '').trim()))
      normalizedIds.forEach(operatorId => {
        if (existingIdSet.has(operatorId)) {
          return
        }
        optionList.push({
          operatorId: operatorId,
          operatorName: this.resolveOperatorNameById(operatorId)
        })
        existingIdSet.add(operatorId)
      })
      this.relatedPeopleOptionList = optionList
      this.filterRelatedPeopleOptions()
      const selectedRelatedPeopleCode = this.resolveOperatorIdByCodeOrName(this.modalData.relatedPeople)
      const selectedRelatedPeopleRow = optionList.find(item => String(item.operatorId || '').trim() === selectedRelatedPeopleCode)
      if (!selectedRelatedPeopleRow) {
        this.$set(this.modalData, 'relatedPeople', '')
        this.$set(this.modalData, 'relatedPeopleName', '')
      } else {
        this.$set(this.modalData, 'relatedPeople', selectedRelatedPeopleCode)
        this.$set(this.modalData, 'relatedPeopleName', String(selectedRelatedPeopleRow.operatorName || '').trim())
      }
    },
    normalizeHsfApproverOptionList (rows) {
      if (!Array.isArray(rows)) {
        return []
      }
      return rows
        .map(item => {
          const operatorId = String(item.operatorId || item.operator_id || item.username || item.userName || '').trim()
          const operatorName = String(item.operatorName || item.operator_name || item.userDisplay || item.user_display || '').trim()
          if (!operatorId || !operatorName) {
            return null
          }
          return {
            operatorId,
            operatorName
          }
        })
        .filter(item => !!item)
    },
    filterHsfApproverOptions () {
      const operatorIdKeyword = String(this.hsfApproverSearchData.operatorId || '').trim().toUpperCase()
      const operatorNameKeyword = String(this.hsfApproverSearchData.operatorName || '').trim().toUpperCase()
      this.hsfApproverDisplayList = (this.hsfApproverOptionList || []).filter(item => {
        const operatorId = String(item.operatorId || '').toUpperCase()
        const operatorName = String(item.operatorName || '').toUpperCase()
        const matchOperatorId = !operatorIdKeyword || operatorId.includes(operatorIdKeyword)
        const matchOperatorName = !operatorNameKeyword || operatorName.includes(operatorNameKeyword)
        return matchOperatorId && matchOperatorName
      })
    },
    filterRelatedPeopleOptions () {
      const operatorIdKeyword = String(this.relatedPeopleSearchData.operatorId || '').trim().toUpperCase()
      const operatorNameKeyword = String(this.relatedPeopleSearchData.operatorName || '').trim().toUpperCase()
      this.relatedPeopleDisplayList = (this.relatedPeopleOptionList || []).filter(item => {
        const operatorId = String(item.operatorId || '').toUpperCase()
        const operatorName = String(item.operatorName || '').toUpperCase()
        const matchOperatorId = !operatorIdKeyword || operatorId.includes(operatorIdKeyword)
        const matchOperatorName = !operatorNameKeyword || operatorName.includes(operatorNameKeyword)
        return matchOperatorId && matchOperatorName
      })
    },
    openHsfApproverChooseModal () {
      if (this.isRohsFieldDisabled('hsfApprover')) {
        return
      }
      if (!this.modalData || !String(this.modalData.process || '').trim()) {
        this.$message.warning('请先选择工艺')
        return
      }
      this.loadHsfApproverByCurrentProcess(false).then(() => {
        if (!this.hsfApproverOptionList || this.hsfApproverOptionList.length === 0) {
          this.$message.warning('未查询到可选HSF审批人')
          return
        }
        this.hsfApproverFlag = true
      })
    },
    openHsfApproverDialog () {
      this.hsfApproverSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.filterHsfApproverOptions()
      const selectedOperatorSet = new Set(
        (this.modalData.hsfApproverCodeList || [])
          .map(item => String(item || '').trim())
          .filter(item => !!item)
      )
      const selectedRows = (this.hsfApproverOptionList || []).filter(item => selectedOperatorSet.has(String(item.operatorId || '').trim()))
      this.hsfApproverSelectionCache = JSON.parse(JSON.stringify(selectedRows))
      this.$nextTick(() => {
        if (!this.$refs.hsfApproverTable) {
          return
        }
        this.$refs.hsfApproverTable.clearSelection()
        selectedRows.forEach(item => {
          this.$refs.hsfApproverTable.toggleRowSelection(item, true)
        })
      })
    },
    closeHsfApproverDialog () {
      this.hsfApproverSelectionCache = []
    },
    handleHsfApproverSelectionChange (rows) {
      this.hsfApproverSelectionCache = rows || []
    },
    handleHsfApproverTableClick (row, column, event, tableRef) {
      if (this.$refs[tableRef]) {
        this.$refs[tableRef].toggleRowSelection(row)
      }
    },
    saveHsfApproverChooseModal () {
      const selectedCodes = (this.hsfApproverSelectionCache || [])
        .map(item => String(item.operatorId || '').trim())
        .filter(item => !!item)
      this.$set(this.modalData, 'hsfApproverCodeList', selectedCodes)
      this.syncHsfApproverFields()
      this.hsfApproverFlag = false
    },
    clearHsfApproverSelection () {
      this.$set(this.modalData, 'hsfApproverCodeList', [])
      this.syncHsfApproverFields()
    },
    openRelatedPeopleChooseModal () {
      if (this.isRohsFieldDisabled('relatedPeople')) {
        return
      }
      if (!this.modalData || !Array.isArray(this.modalData.hsfApproverCodeList) || this.modalData.hsfApproverCodeList.length === 0) {
        this.$message.warning('请先选择HSF审批人')
        return
      }
      this.buildRelatedPeopleOptions(this.modalData.hsfApproverCodeList)
      if (!this.relatedPeopleOptionList || this.relatedPeopleOptionList.length === 0) {
        this.$message.warning('未查询到可选Inform Related people')
        return
      }
      this.relatedPeopleFlag = true
    },
    openRelatedPeopleDialog () {
      this.relatedPeopleSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.filterRelatedPeopleOptions()
      const relatedPeopleCode = String(this.modalData.relatedPeople || '').trim()
      const selectedRow = (this.relatedPeopleOptionList || []).find(item => String(item.operatorId || '').trim() === relatedPeopleCode) || null
      this.relatedPeopleSelection = selectedRow
      this.$nextTick(() => {
        if (!this.$refs.relatedPeopleTable) {
          return
        }
        this.$refs.relatedPeopleTable.setCurrentRow(selectedRow || null)
      })
    },
    closeRelatedPeopleDialog () {
      this.relatedPeopleSelection = null
    },
    handleRelatedPeopleCurrentChange (row) {
      this.relatedPeopleSelection = row || null
    },
    handleRelatedPeopleTableClick (row) {
      this.relatedPeopleSelection = row || null
      if (this.$refs.relatedPeopleTable) {
        this.$refs.relatedPeopleTable.setCurrentRow(row)
      }
    },
    saveRelatedPeopleChooseModal () {
      const selectedCode = this.relatedPeopleSelection ? String(this.relatedPeopleSelection.operatorId || '').trim() : ''
      const selectedName = this.relatedPeopleSelection ? String(this.relatedPeopleSelection.operatorName || '').trim() : ''
      this.$set(this.modalData, 'relatedPeople', selectedCode)
      this.$set(this.modalData, 'relatedPeopleName', selectedName)
      this.relatedPeopleFlag = false
    },
    clearRelatedPeopleSelection () {
      this.$set(this.modalData, 'relatedPeople', '')
      this.$set(this.modalData, 'relatedPeopleName', '')
      this.relatedPeopleSelection = null
      if (this.$refs.relatedPeopleTable) {
        this.$refs.relatedPeopleTable.setCurrentRow(null)
      }
    },
    clearHsfApproverFields (clearBuNo = false) {
      if (clearBuNo) {
        this.$set(this.modalData, 'buNo', '')
      }
      this.hsfApproverOptionList = []
      this.hsfApproverDisplayList = []
      this.hsfApproverSelectionCache = []
      this.relatedPeopleOptionList = []
      this.relatedPeopleDisplayList = []
      this.relatedPeopleSelection = null
      this.relatedPeopleFlag = false
      this.hsfApproverSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.relatedPeopleSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.$set(this.modalData, 'hsfApproverCodeList', [])
      this.$set(this.modalData, 'hsfApprover', '')
      this.$set(this.modalData, 'hsfApproverName', '')
      this.$set(this.modalData, 'relatedPeople', '')
      this.$set(this.modalData, 'relatedPeopleName', '')
    },
    loadHsfApproverByCurrentProcess (forceSelectAll = false) {
      if (!this.modalData || !this.modalData.site) {
        this.hsfApproverOptionList = []
        this.hsfApproverDisplayList = []
        this.hsfApproverSelectionCache = []
        if (forceSelectAll) {
          this.clearHsfApproverFields(false)
        }
        return Promise.resolve()
      }
      const buNo = String(this.modalData.process || '').trim()
      if (!buNo) {
        if (forceSelectAll) {
          this.$message.warning('请先选择工艺')
          this.clearHsfApproverFields(false)
        }
        this.hsfApproverOptionList = []
        this.hsfApproverDisplayList = []
        this.hsfApproverSelectionCache = []
        return Promise.resolve()
      }
      const params = {
        site: this.modalData.site,
        buNo: buNo,
        roleNo: 'R015'
      }
      return api.searchBmUser(params).then(({data}) => {
        if (data && data.code === 0 && Array.isArray(data.rows)) {
          this.hsfApproverOptionList = this.normalizeHsfApproverOptionList(data.rows)
          this.filterHsfApproverOptions()
          this.hsfApproverSelectionCache = []
          if (forceSelectAll) {
            const defaultSelectedCodes = this.hsfApproverOptionList.map(item => item.operatorId).filter(item => item)
            this.$set(this.modalData, 'hsfApproverCodeList', defaultSelectedCodes)
          }
          this.syncHsfApproverFields()
        } else {
          this.hsfApproverOptionList = []
          this.hsfApproverDisplayList = []
          this.hsfApproverSelectionCache = []
          if (forceSelectAll) {
            this.clearHsfApproverFields(false)
          }
        }
      }).catch(() => {
        this.hsfApproverOptionList = []
        this.hsfApproverDisplayList = []
        this.hsfApproverSelectionCache = []
        if (forceSelectAll) {
          this.clearHsfApproverFields(false)
        }
      })
    },
    isCurrentApprover () {
      return this.superAdmin || (this.modalData.createBy2 && this.modalData.createBy2.split(';').includes(this.createBy2))
    },
    canSaveAction () {
      return !this.showModalFlag && (this.modalData.status === '草稿' || (this.modalData.status === '审批中' && this.isCurrentApprover()))
    },
    canAgreeAction () {
      return this.authSubmit && this.isCurrentApprover() && this.modalData.status === '审批中' && this.modalData.tpProcessControl !== 'Y' && this.modalData.csProcessControl !== 'Y'
    },
    canRejectAction () {
      return this.authReject && this.isCurrentApprover() && this.modalData.status === '审批中' && this.modalData.isReject === 'Y'
    },
    hasPersistedRohsRecord () {
      return !!(this.modalData && this.modalData.site && this.modalData.referenceNo && !String(this.modalData.referenceNo).startsWith('TEMP-'))
    },
    openRohsRemarkDialog () {
      this.$set(this.rohsRemarkForm, 'remark', this.modalData.remark || '')
      this.rohsRemarkFlag = true
    },
    refreshRohsRemark () {
      if (!this.hasPersistedRohsRecord()) {
        this.$set(this.rohsRemarkForm, 'remark', this.modalData.remark || '')
        return
      }
      api.getRohsDetail(this.modalData.site, this.modalData.referenceNo).then(({data}) => {
        if (data && data.code === 0 && data.data) {
          this.$set(this.rohsRemarkForm, 'remark', data.data.remark || '')
        } else {
          this.$message.error((data && data.msg) || '刷新失败')
        }
      }).catch(() => {
        this.$message.error('刷新失败')
      })
    },
    saveRohsRemark () {
      const remark = this.rohsRemarkForm.remark || ''
      if (!this.hasPersistedRohsRecord()) {
        this.$set(this.modalData, 'remark', remark)
        this.rohsRemarkFlag = false
        this.$message.success('暂存成功，保存单据后写入数据库')
        return
      }
      const params = {
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo,
        remark: remark
      }
      api.updateRohsRemark(params).then(({data}) => {
        if (data && data.code === 0) {
          this.$set(this.modalData, 'remark', remark)
          if (this.currentRow && this.currentRow.site === this.modalData.site && this.currentRow.referenceNo === this.modalData.referenceNo) {
            this.$set(this.currentRow, 'remark', remark)
          }
          const target = (this.dataList || []).find(item => item.site === this.modalData.site && item.referenceNo === this.modalData.referenceNo)
          if (target) {
            this.$set(target, 'remark', remark)
          }
          this.rohsRemarkFlag = false
          this.$message.success('操作成功')
        } else {
          this.$message.error((data && data.msg) || '保存失败')
        }
      }).catch(() => {
        this.$message.error('保存失败')
      })
    },
    openRohsMaterialDescDialog () {
      this.$set(this.rohsMaterialDescForm, 'materialDesc', this.modalData.materialDesc || '')
      this.rohsMaterialDescFlag = true
    },
    refreshRohsMaterialDesc () {
      if (!this.hasPersistedRohsRecord()) {
        this.$set(this.rohsMaterialDescForm, 'materialDesc', this.modalData.materialDesc || '')
        return
      }
      api.getRohsDetail(this.modalData.site, this.modalData.referenceNo).then(({data}) => {
        if (data && data.code === 0 && data.data) {
          this.$set(this.rohsMaterialDescForm, 'materialDesc', data.data.materialDesc || '')
        } else {
          this.$message.error((data && data.msg) || '刷新失败')
        }
      }).catch(() => {
        this.$message.error('刷新失败')
      })
    },
    saveRohsMaterialDesc () {
      const materialDesc = this.rohsMaterialDescForm.materialDesc || ''
      if (!this.hasPersistedRohsRecord()) {
        this.$set(this.modalData, 'materialDesc', materialDesc)
        this.rohsMaterialDescFlag = false
        this.$message.success('暂存成功，保存单据后写入数据库')
        return
      }
      const params = {
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo,
        materialDesc: materialDesc
      }
      api.updateRohsMaterialDesc(params).then(({data}) => {
        if (data && data.code === 0) {
          this.$set(this.modalData, 'materialDesc', materialDesc)
          if (this.currentRow && this.currentRow.site === this.modalData.site && this.currentRow.referenceNo === this.modalData.referenceNo) {
            this.$set(this.currentRow, 'materialDesc', materialDesc)
          }
          const target = (this.dataList || []).find(item => item.site === this.modalData.site && item.referenceNo === this.modalData.referenceNo)
          if (target) {
            this.$set(target, 'materialDesc', materialDesc)
          }
          this.rohsMaterialDescFlag = false
          this.$message.success('操作成功')
        } else {
          this.$message.error((data && data.msg) || '保存失败')
        }
      }).catch(() => {
        this.$message.error('保存失败')
      })
    },
    loadModalButtonCondition () {
      if (!this.modalData.site || !this.modalData.referenceNo || this.modalData.status !== '审批中') {
        this.$set(this.modalData, 'createBy2', '')
        this.$set(this.modalData, 'isReject', 'Y')
        this.$set(this.modalData, 'tpProcessControl', 'N')
        this.$set(this.modalData, 'csProcessControl', 'N')
        return
      }
      let params = {
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo
      }
      api.getRohsButtonCondition(params).then(({data}) => {
        if (data && data.code === 0 && data.data) {
          this.$set(this.modalData, 'createBy2', data.data.createBy2 || '')
          this.$set(this.modalData, 'isReject', data.data.isReject || 'Y')
          this.$set(this.modalData, 'tpProcessControl', data.data.tpProcessControl || 'N')
          this.$set(this.modalData, 'csProcessControl', data.data.csProcessControl || 'N')
        } else {
          this.$set(this.modalData, 'createBy2', '')
          this.$set(this.modalData, 'isReject', 'Y')
          this.$set(this.modalData, 'tpProcessControl', 'N')
          this.$set(this.modalData, 'csProcessControl', 'N')
        }
      }).catch(() => {
        this.$set(this.modalData, 'createBy2', '')
        this.$set(this.modalData, 'isReject', 'Y')
        this.$set(this.modalData, 'tpProcessControl', 'N')
        this.$set(this.modalData, 'csProcessControl', 'N')
      })
    },
    // 列表行选中变色
    rowStyle ({row}) {
      if (this.currentRow && this.currentRow.referenceNo === row.referenceNo) {
        return { 'background-color': '#E8F7F6', cursor: 'pointer' }
      }
    },
    // 获取按钮的权限数据
    getButtonAuthData () {
      this.authSearch = this.isAuth(this.menuId+":search")
      this.authUpdate = this.isAuth(this.menuId+":update")
      this.authIssue = this.isAuth(this.menuId+":issue")
      this.authSubmit = this.isAuth(this.menuId+":submit")
      this.authReject = this.isAuth(this.menuId+":reject")
      this.authFileSave = this.isAuth(this.menuId+":fileSave")
      this.authFileDownLoad = this.isAuth(this.menuId+":fileDownLoad")
      this.authFileRemove = this.isAuth(this.menuId+":fileRemove")
      this.authFilePreview = this.isAuth(this.menuId+":filePreview")
      this.authDataEntry = this.isAuth(this.menuId+":dataEntry")
      this.authMaterialDescRemark = this.isAuth(this.menuId + ":materialDescRemark")
      this.authDelete = this.isAuth(this.menuId+":delete")
    },
    // 校验是否为超级管理员
    checkSuperAdmin () {
      checkSuperAdmin().then(({data}) => {
        this.superAdmin = data.superAdmin
      })
    },
    changeClickRow (row, column, event) {
      this.loadCurrentRowFromServer(row, row || {})
    },
    currentChange (val) {
      if (val) {
        this.loadCurrentRowFromServer(val, val || {})
      } else {
        this.currentRow = {}
        this.approvalList = []
      }
    },
    dataListSelectionChange (rows) {
      this.dataListSelections = rows || []
    },
    applyCurrentRowData (detailData, fallbackData = {}) {
      this.currentRow = detailData || {}
      if (!Array.isArray(this.currentRow.materialList)) {
        this.$set(this.currentRow, 'materialList', [])
      }
      this.fillDisplayFields(this.currentRow, fallbackData || {})
      this.syncDataListRow(this.currentRow)
      this.refreshCurrentTabTable()
    },
    syncDataListRow (rowData) {
      if (!rowData || !rowData.site || !rowData.referenceNo || !Array.isArray(this.dataList)) {
        return
      }
      const targetIndex = this.dataList.findIndex(item => item.site === rowData.site && item.referenceNo === rowData.referenceNo)
      if (targetIndex < 0) {
        return
      }
      const mergedRow = {
        ...this.dataList[targetIndex],
        ...rowData
      }
      this.fillDisplayFields(mergedRow, this.dataList[targetIndex] || {})
      this.$set(this.dataList, targetIndex, mergedRow)
    },
    loadCurrentRowFromServer (row, fallbackData = {}) {
      if (!row || !row.site || !row.referenceNo) {
        this.applyCurrentRowData(row || {}, fallbackData || {})
        return Promise.resolve()
      }
      return api.getRohsDetail(row.site, row.referenceNo).then(({data}) => {
        if (data && data.code === 0 && data.data) {
          this.applyCurrentRowData(data.data, fallbackData || row)
        } else {
          this.applyCurrentRowData(row || {}, fallbackData || {})
        }
      }).catch(() => {
        this.applyCurrentRowData(row || {}, fallbackData || {})
      })
    },
    refreshCurrentRowFromServer (site, referenceNo) {
      const querySite = site || (this.currentRow && this.currentRow.site)
      const queryReferenceNo = referenceNo || (this.currentRow && this.currentRow.referenceNo)
      if (!querySite || !queryReferenceNo || String(queryReferenceNo).startsWith('TEMP-')) {
        return Promise.resolve()
      }
      return this.loadCurrentRowFromServer({
        site: querySite,
        referenceNo: queryReferenceNo
      }, this.currentRow || {})
    },
    refreshOssRef (refName) {
      const ref = this.$refs[refName]
      if (!ref) {
        return
      }
      const refList = Array.isArray(ref) ? ref : [ref]
      refList.forEach(item => {
        if (item && typeof item.handleQuery === 'function') {
          item.handleQuery()
        }
      })
    },
    refreshAttachmentPanels () {
      this.refreshOssRef('modalAttachmentTdsOss')
      this.refreshOssRef('modalAttachmentMsdsOss')
      this.refreshOssRef('modalAttachmentTestReportOss')
      this.refreshOssRef('modalAttachmentOtherOss')
      this.refreshOssRef('modalTdsOss')
      this.refreshOssRef('bottomAttachmentOss')
      this.refreshOssRef('bottomTdsOss')
    },
    handleModalClose () {
      const site = this.modalData.site
      const referenceNo = this.modalData.referenceNo
      this.modalFlag = false
      this.rohsCreatePartDialogFlag = false
      this.rohsCharacteristicDialogFlag = false
      this.rohsMaterialDescFlag = false
      this.rohsCreatePartTab = 'General'
      this.$nextTick(() => {
        this.refreshAttachmentPanels()
      })
      this.refreshCurrentRowFromServer(site, referenceNo)
    },
    fillDisplayFields (target, fallbackData = {}) {
      if (!target) {
        return
      }
      const fields = ['nodeId', 'nodeName', 'currentApprover', 'applicantName', 'pmName', 'npdEngineerName', 'technicalPlanName', 'buyerName', 'endCustomerName', 'projectName', 'commGroup1Desc', 'commGroup2Desc', 'commGroup3Desc', 'hsfApproverName', 'relatedPeopleName']
      fields.forEach(field => {
        const value = target[field] || fallbackData[field] || ''
        this.$set(target, field, value)
      })
      this.$set(target, 'endCustomerFlag', !!target.endCustomerFlag)
      this.$set(target, 'projectIdFlag', !!target.projectIdFlag)
      const validUntilValue = target.validUntilValue !== undefined && target.validUntilValue !== null && target.validUntilValue !== ''
        ? target.validUntilValue
        : fallbackData.validUntilValue
      this.$set(target, 'validUntilValue', this.normalizeValidUntilValue(validUntilValue))
      const applicationDate = target.applicationDate || fallbackData.applicationDate || ''
      const plannedMassProductionDate = target.plannedMassProductionDate || fallbackData.plannedMassProductionDate || ''
      const expiredDate = target.expiredDate || fallbackData.expiredDate || ''
      const normalizedExpiredDate = this.normalizeDateOnly(expiredDate)
      this.$set(target, 'applicationDate', this.normalizeDateOnly(applicationDate))
      this.$set(target, 'plannedMassProductionDate', this.normalizeDateOnly(plannedMassProductionDate))
      this.$set(target, 'expiredDate', normalizedExpiredDate)
      this.$set(target, 'expiryDate', this.calculateExpiryDateByRule(normalizedExpiredDate, target.validUntilValue, target.validUntil))
    },
    refreshCurrentTabTable () {
      if (this.activeTable === 'approvalInformation') {
        this.getApprovalList()
        return
      }
      if (this.activeTable === 'attachment') {
        this.refreshOssRef('bottomAttachmentOss')
        return
      }
      if (this.activeTable === 'npdInfo') {
        this.refreshOssRef('bottomTdsOss')
      }
    },
    getApprovalList () {
      if (!this.currentRow || !this.currentRow.site || !this.currentRow.referenceNo) {
        this.approvalList = []
        return
      }
      let params = {
        site: this.currentRow.site,
        menuId: this.menuId,
        documentNo: this.currentRow.referenceNo
      }
      api.getRohsApprovalList(params).then(({data}) => {
        if (data && data.code === 0) {
          this.approvalList = data.rows || []
        } else {
          this.approvalList = []
        }
      }).catch(() => {
        this.approvalList = []
      })
    },

    // 获取列表
    getDataList () {
      if (!this.authSearch) {
        this.dataList = []
        this.dataListSelections = []
        this.totalPage = 0
        this.currentRow = {}
        this.approvalList = []
        this.isFilterSearch = false
        return
      }
      this.dataListLoading = true
      let params = {
        page: this.pageIndex,
        limit: this.pageSize,
        site: this.$store.state.user.site,
        menuId: this.menuId,
        referenceNo: this.searchData.referenceNo,
        status: this.searchData.status,
        rohsStatus: this.searchData.rohsStatus,
        currentApprover: this.searchData.currentApprover,
        nodeId: this.searchData.nodeId
      }
      api.getRohsList(params).then(({data}) => {
        if (data && data.code === 0) {
          const list = data.page.list || []
          this.dataList = list.map(item => {
            return {
              applicantName: '',
              pmName: '',
              npdEngineerName: '',
              technicalPlanName: '',
              buyerName: '',
              endCustomerName: '',
              projectName: '',
              nodeId: '',
              nodeName: '',
              currentApprover: '',
              commGroup1Desc: '',
              commGroup2Desc: '',
              commGroup3Desc: '',
              hsfApproverName: '',
              relatedPeopleName: '',
              ...item
            }
          })
          this.dataListSelections = []
          this.totalPage = data.page.totalCount
          this.$nextTick(() => {
            if (this.$refs.rohsTable) {
              this.$refs.rohsTable.clearSelection()
            }
            if (this.$refs.rohsTable && this.dataList.length > 0) {
              this.$refs.rohsTable.setCurrentRow(this.dataList[0])
            } else if (this.$refs.rohsTable) {
              this.$refs.rohsTable.setCurrentRow()
            }
          })
        } else {
          this.dataList = []
          this.dataListSelections = []
          this.totalPage = 0
          this.currentRow = {}
          this.approvalList = []
        }
        this.dataListLoading = false
      }).catch(() => {
        this.dataListSelections = []
        this.currentRow = {}
        this.approvalList = []
        this.dataListLoading = false
      })
      this.isFilterSearch = false
    },
    // 分页
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      if (this.isFilterSearch === false) {
        this.getDataList()
      } else {
        this.queryByAnyField(this.filterSearchData)
      }
    },
    currentChangeHandle (val) {
      this.pageIndex = val
      if (this.isFilterSearch === false) {
        this.getDataList()
      } else {
        this.queryByAnyField(this.filterSearchData)
      }
    },
    // 搜索条件点击
    searchHandle () {
      if (!this.authSearch) {
        return
      }
      this.filterVisible = true
    },
    queryByAnyField (params) {
      const queryParams = {
        ...(params || {})
      }
      queryParams.no = this.pageIndex
      queryParams.size = this.pageSize
      queryParams.userId = this.$store.state.user.id.toString()
      queryParams.site = this.$store.state.user.site
      queryParams.menuId = this.menuId
      this.dataListLoading = true
      api.getRohsListAny(queryParams).then(({data}) => {
        if (data && data.code === 0) {
          const list = (data.page && data.page.list) || []
          this.dataList = list.map(item => {
            return {
              applicantName: '',
              pmName: '',
              npdEngineerName: '',
              technicalPlanName: '',
              buyerName: '',
              endCustomerName: '',
              projectName: '',
              nodeId: '',
              nodeName: '',
              currentApprover: '',
              commGroup1Desc: '',
              commGroup2Desc: '',
              commGroup3Desc: '',
              hsfApproverName: '',
              relatedPeopleName: '',
              ...item
            }
          })
          this.dataListSelections = []
          this.totalPage = data.page.totalCount
          this.$nextTick(() => {
            if (this.$refs.rohsTable) {
              this.$refs.rohsTable.clearSelection()
            }
            if (this.$refs.rohsTable && this.dataList.length > 0) {
              this.$refs.rohsTable.setCurrentRow(this.dataList[0])
            } else if (this.$refs.rohsTable) {
              this.$refs.rohsTable.setCurrentRow()
            }
          })
        } else {
          this.$message.warning((data && data.msg) || '搜索失败')
          this.dataList = []
          this.dataListSelections = []
          this.totalPage = 0
          this.currentRow = {}
          this.approvalList = []
        }
        this.dataListLoading = false
      }).catch(() => {
        this.dataList = []
        this.dataListSelections = []
        this.currentRow = {}
        this.approvalList = []
        this.dataListLoading = false
      })
      this.filterSearchData = JSON.parse(JSON.stringify(queryParams))
      this.isFilterSearch = true
      this.filterVisible = false
    },
    buildExportName () {
      const now = new Date()
      const year = String(now.getFullYear())
      const month = String(now.getMonth() + 1).padStart(2, '0')
      const day = String(now.getDate()).padStart(2, '0')
      const hour = String(now.getHours()).padStart(2, '0')
      const minute = String(now.getMinutes()).padStart(2, '0')
      const second = String(now.getSeconds()).padStart(2, '0')
      return 'RoHs记录' + year + month + day + hour + minute + second
    },
    async createExportData () {
      const params = {
        ...this.searchData,
        site: this.$store.state.user.site,
        menuId: this.menuId,
        page: 1,
        limit: -1
      }
      this.resultList = []
      await api.getRohsList(params).then(({data}) => {
        if (data && data.code === 0 && data.page && Array.isArray(data.page.list)) {
          this.resultList = (data.page.list || []).map(item => {
            const row = {
              ...item
            }
            row.applicationDate = this.normalizeDateOnly(row.applicationDate)
            row.plannedMassProductionDate = this.normalizeDateOnly(row.plannedMassProductionDate)
            row.expectReportTime = this.normalizeDateOnly(row.expectReportTime)
            row.expiredDate = this.normalizeDateOnly(row.expiredDate)
            row.expiryDate = this.normalizeDateOnly(row.expiryDate)
            row.validUntilDisplay = this.getValidUntilDisplay(row.validUntilValue, row.validUntil)
            row.hsfApproverName = row.hsfApproverName || row.hsfApprover || ''
            row.relatedPeopleName = row.relatedPeopleName || row.relatedPeople || ''
            return row
          })
        } else {
          this.$message.warning((data && data.msg) || '导出数据获取失败')
        }
      }).catch(() => {
        this.$message.error('导出数据获取失败')
      })
      return this.resultList
    },
    startDownload () {
      this.exportName = this.buildExportName()
      this.exportFieldMap = this.buildExportFields()
      if (!this.exportFieldMap || Object.keys(this.exportFieldMap).length === 0) {
        this.$message.warning('未获取到可导出的列，请稍后重试')
      }
      this.exportLoading = true
    },
    finishDownload () {
      this.exportLoading = false
    },
    buildExportFields () {
      const tableRef = this.$refs.rohsTable
      if (!tableRef || !Array.isArray(tableRef.columns)) {
        return {}
      }
      const fields = {}
      tableRef.columns.forEach(column => {
        const label = column && column.label ? String(column.label).trim() : ''
        const property = column && column.property ? String(column.property).trim() : ''
        if (!label || !property || label === '操作') {
          return
        }
        fields[label] = property
      })
      return fields
    },
    // 单选可取消
    radioClick (field, value) {
      if (this.modalData[field] === value) {
        this.modalData[field] = ''
      } else {
        this.modalData[field] = value
      }
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      if (!row && !this.authUpdate) {
        this.$message.warning('没有新增权限')
        return
      }
      if (row && !this.authUpdate && !this.authDataEntry) {
        this.$message.warning('没有编辑权限')
        return
      }
      this.modalFlag = true
      this.activeName = 'basicInfo'
      this.submitModalFlag = false
      this.rohsRemarkFlag = false
      this.rohsMaterialDescFlag = false
      this.rejectOpinion = ''
      this.rohsRemarkForm = {
        remark: ''
      }
      this.rohsMaterialDescForm = {
        materialDesc: ''
      }
      this.projectMaterialDialogFlag = false
      this.rohsCreatePartDialogFlag = false
      this.rohsCreatePartLoading = false
      this.rohsCreatePartTab = 'General'
      this.rohsCreatePartTagNo = 0
      this.rohsCharacteristicDialogFlag = false
      this.rohsCharacteristicQueryData = {
        propertiesItemNo: '',
        itemDesc: ''
      }
      this.rohsCharacteristicList = []
      this.rohsCharacteristicSelections = []
      this.rohsPartItemSelections = []
      this.projectMaterialSelections = []
      this.materialSelections = []
      this.hsfApproverOptionList = []
      this.hsfApproverDisplayList = []
      this.hsfApproverSelectionCache = []
      this.hsfApproverSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.hsfApproverFlag = false
      this.relatedPeopleOptionList = []
      this.relatedPeopleDisplayList = []
      this.relatedPeopleSelection = null
      this.relatedPeopleSearchData = {
        operatorId: '',
        operatorName: ''
      }
      this.relatedPeopleFlag = false
      this.plmRohsAuthorityArr = []
      this.nodeAuthorityLoaded = !row
      this.isEditMode = !!row
      this.projectMaterialPageIndex = 1
      this.projectMaterialTotal = 0
      this.projectMaterialList = []
      this.projectMaterialSearchData = {
        finalPartNo: '',
        partDesc: '',
        partStatus: ''
      }
      this.showModalFlag = !!(row && (row.status === '已完成' || !this.authUpdate))

      if (row) {
        this.modalTitle = 'RoHS 编辑'
        api.getRohsDetail(row.site, row.referenceNo).then(({data}) => {
          if (data && data.code === 0) {
            this.modalData = data.data || {}
            this.$set(this.modalData, 'qualificationDocumentsNeededList', this.modalData.qualificationDocumentsNeeded ? this.modalData.qualificationDocumentsNeeded.split(';').filter(item => item) : [])
            this.$set(this.modalData, 'testReportIncludingItemsList', this.modalData.testReportIncludingItems ? this.modalData.testReportIncludingItems.split(';').filter(item => item) : [])
            this.$set(this.modalData, 'materialClassifyList', this.modalData.materialClassify ? this.modalData.materialClassify.split(';').filter(item => item) : [])
            this.$set(this.modalData, 'materialList', Array.isArray(this.modalData.materialList) ? this.modalData.materialList : [])
            this.$set(this.modalData, 'hsfApproverCodeList', this.modalData.hsfApprover ? this.modalData.hsfApprover.split(';').filter(item => item) : [])
            this.$set(this.modalData, 'buNo', this.modalData.process || '')
            this.$set(this.modalData, 'isAhGrade', this.normalizeCheckboxFlag(this.modalData.isAhGrade))
            this.$set(this.modalData, 'validUntilValue', this.normalizeValidUntilValue(this.modalData.validUntilValue))
            this.syncHsfApproverFields()
            this.fillDisplayFields(this.modalData, row || {})
            this.applyHsfStandardDefaultByCustomer(this.modalData)
            // 编辑时不允许修改最终客户和项目编码
            this.$set(this.modalData, 'endCustomerFlag', true)
            this.$set(this.modalData, 'projectIdFlag', true)
            this.$set(this.modalData, 'createBy2', '')
            this.$set(this.modalData, 'isReject', 'Y')
            this.$set(this.modalData, 'tpProcessControl', 'N')
            this.$set(this.modalData, 'csProcessControl', 'N')
            this.loadModalButtonCondition()
            this.loadHsfApproverByCurrentProcess(false)
            this.loadNodeAuthority(this.modalData.site || row.site, this.modalData.stepId !== null && this.modalData.stepId !== undefined ? this.modalData.stepId : (row.stepId !== null && row.stepId !== undefined ? row.stepId : 10))
          }
        }).catch(() => {
          this.loadNodeAuthority(row.site, row.stepId !== null && row.stepId !== undefined ? row.stepId : 10)
        })
      } else {
        this.modalTitle = 'RoHS 新增'
        this.showModalFlag = false
        // 生成一个临时ID用于附件上传绑定
        const tempReferenceNo = 'TEMP-' + new Date().getTime() + '-' + Math.floor(Math.random() * 1000)
        this.modalData = {
          site: this.$store.state.user.site,
          referenceNo: tempReferenceNo,
          applicant: this.$store.state.user.name || '',
          applicantName: this.$store.state.user.userDisplay || this.$store.state.user.user_display || '',
          pm: '',
          pmName: '',
          applicationDate: this.getCurrentDateString(),
          process: '',
          plannedMassProductionDate: '',
          color: '',
          vendorCode: '',
          vendorMaterialCode: '',
          materialClassify: '',
          materialClassifyList: [],
          otherMaterialClassify: '',
          materialUseFor: '',
          endCustomer: '',
          endCustomerName: '',
          endCustomerFlag: false,
          projectId: '',
          projectName: '',
          projectIdFlag: true,
          commGroup1: '',
          commGroup1Desc: '',
          commGroup2: '',
          commGroup2Desc: '',
          commGroup3: '',
          commGroup3Desc: '',
          needCreateNumber: '',
          npdEngineer: '',
          npdEngineerName: '',
          materialValidityTime: '',
          materialValidityComments: '',
          needDeviation: '',
          technicalPlan: '',
          wmRequiredSpec: '',
          isFiberMaterial: '',
          materialThickness: '',
          buyer: '',
          buyerName: '',
          expectReportTime: '',
          qualificationDocumentsNeeded: '',
          qualificationDocumentsNeededList: [],
          testReportIncludingItems: '',
          testReportIncludingItemsList: [],
          remark: '',
          status: '草稿',
          sgsReportNumber: '',
          rohsStatus: 'Active',
          expiredDate: '',
          expiryDate: '',
          fiberInformation: '',
          hsfStandard: '',
          hsfApprover: '',
          hsfApproverName: '',
          hsfApproverCodeList: [],
          relatedPeople: '',
          relatedPeopleName: '',
          buNo: '',
          validUntilValue: 0,
          validUntil: '',
          isMeetRohsRequirement: '',
          isAhGrade: 'N',
          hsfSupplierClassification: '',
          materialDesc: '',
          npdRemark: '',
          isSameMaterialDiffSize: '',
          ifsPartNo: '',
          materialList: [],
          stepId: 10,
          rejectFlag: 'N',
          rejectStepId: null,
          createBy2: '',
          isReject: 'Y',
          tpProcessControl: 'N',
          csProcessControl: 'N'
        }
        this.nodeAuthorityLoaded = true
      }
    },
    // 表单提交
    dataFormSubmit () {
      if (!this.canSaveAction()) {
        this.$message.warning('当前状态不允许保存')
        return
      }
      this.$set(this.modalData, 'isAhGrade', this.normalizeCheckboxFlag(this.modalData.isAhGrade))
      this.normalizeHsfStandardByCustomer(this.modalData)
      this.syncHsfApproverFields()
      if (!this.validateValidUntilPair()) {
        return
      }
      this.syncExpiryDateByRule()
      this.modalData.qualificationDocumentsNeeded = this.modalData.qualificationDocumentsNeededList.join(';')
      this.modalData.testReportIncludingItems = this.modalData.testReportIncludingItemsList.join(';')
      this.modalData.materialClassify = this.modalData.materialClassifyList.join(';')
      this.modalData.materialList = (this.modalData.materialList || []).map((item, index) => {
        return {
          ...item,
          lineNo: index + 1,
          projectId: this.modalData.projectId
        }
      })

      const submitMethod = this.modalTitle === 'RoHS 新增' ? api.saveRohs : api.updateRohs
      submitMethod(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success('操作成功')
          this.modalFlag = false
          this.getDataList()
        } else {
          this.$message.error(data.msg || '操作失败')
        }
      })
    },
    // 同意
    agreeSubmit () {
      if (!this.canAgreeAction()) {
        this.$message.warning('当前状态不允许同意')
        return
      }
      this.$confirm('确认同意该申请单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.submitRohs('Y')
      })
    },
    openRejectModal () {
      if (!this.canRejectAction()) {
        this.$message.warning('当前状态不允许驳回')
        return
      }
      this.rejectOpinion = ''
      this.submitModalFlag = true
    },
    // 驳回
    rejectSubmit () {
      if (!this.rejectOpinion || !this.rejectOpinion.trim()) {
        this.$message.warning('请填写驳回意见')
        return
      }
      this.submitRohs('N')
    },
    submitRohs (nodeConclusion) {
      if (nodeConclusion === 'Y' && !this.canAgreeAction()) {
        this.$message.warning('当前状态不允许同意')
        return
      }
      if (nodeConclusion === 'N' && !this.canRejectAction()) {
        this.$message.warning('当前状态不允许驳回')
        return
      }
      if (!this.modalData.site || !this.modalData.referenceNo) {
        this.$message.warning('单据主键信息缺失，无法提交审批')
        return
      }
      this.$set(this.modalData, 'isAhGrade', this.normalizeCheckboxFlag(this.modalData.isAhGrade))
      this.normalizeHsfStandardByCustomer(this.modalData)
      this.syncHsfApproverFields()
      if (!this.validateValidUntilPair()) {
        return
      }
      this.syncExpiryDateByRule()
      if (!this.nodeAuthorityLoaded) {
        this.$message.warning('节点权限加载中，请稍后重试')
        return
      }
      if (!this.validateSubmitRequiredFields()) {
        return
      }
      const submitMaterialList = this.normalizeMaterialListForSave(this.modalData.materialList || [])
      this.submitLoading = true
      let params = {
        ...this.modalData,
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo,
        materialClassify: (this.modalData.materialClassifyList || []).join(';'),
        qualificationDocumentsNeeded: (this.modalData.qualificationDocumentsNeededList || []).join(';'),
        testReportIncludingItems: (this.modalData.testReportIncludingItemsList || []).join(';'),
        materialList: submitMaterialList,
        nodeConclusion: nodeConclusion,
        rejectOpinion: nodeConclusion === 'N' ? this.rejectOpinion : '',
        menuId: this.menuId,
        documentNo: this.modalData.referenceNo
      }
      api.submitRohs(params).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success(nodeConclusion === 'Y' ? '同意成功' : '驳回成功')
          this.submitModalFlag = false
          this.modalFlag = false
          this.getDataList()
        } else {
          this.$message.error(data.msg || '提交失败')
        }
        this.submitLoading = false
      }).catch(() => {
        this.submitLoading = false
      })
    },
    // 下达
    issueModal (row) {
      if (!this.authIssue) {
        this.$message.warning('没有下达权限')
        return
      }
      this.$confirm('确认下达该申请单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          site: row.site,
          referenceNo: row.referenceNo,
          menuId: this.menuId
        }
        api.issueRohs(params).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success('下达成功')
            if (this.modalFlag && this.modalData.referenceNo === row.referenceNo) {
              this.modalData.status = '审批中'
            }
            this.getDataList()
          } else {
            this.$message.error(data.msg || '下达失败')
          }
        })
      })
    },
    deleteHandle () {
      if (!this.authDelete) {
        this.$message.warning('没有删除权限')
        return
      }
      const selectedRows = (this.dataListSelections || []).filter(item => item && item.site && item.referenceNo)
      if (!selectedRows.length) {
        this.$message.warning('请先勾选要删除的单据')
        return
      }
      const nonDraftRows = selectedRows.filter(item => item.status !== '草稿')
      if (nonDraftRows.length) {
        const previewText = nonDraftRows.slice(0, 3).map(item => item.referenceNo).join('、')
        const suffix = nonDraftRows.length > 3 ? (' 等' + nonDraftRows.length + '条') : ''
        this.$message.warning('仅草稿状态的单据允许删除，当前勾选包含非草稿单据：' + previewText + suffix)
        return
      }
      this.$confirm('确认删除选中的' + selectedRows.length + '条RoHS单据？删除后会同步删除材料和附件数据。', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const deleteTasks = selectedRows.map(item => {
          return api.deleteRohs({
            site: item.site,
            referenceNo: item.referenceNo
          }).then(({data}) => {
            if (data && data.code === 0) {
              return {
                success: true,
                referenceNo: item.referenceNo
              }
            }
            return {
              success: false,
              referenceNo: item.referenceNo,
              msg: (data && data.msg) || '删除失败'
            }
          }).catch(() => {
            return {
              success: false,
              referenceNo: item.referenceNo,
              msg: '删除失败'
            }
          })
        })
        Promise.all(deleteTasks).then(results => {
          const successRows = results.filter(item => item.success)
          const failRows = results.filter(item => !item.success)
          if (this.modalFlag && successRows.some(item => item.referenceNo === this.modalData.referenceNo)) {
            this.modalFlag = false
          }
          if (!failRows.length) {
            this.$message.success('删除成功，共' + successRows.length + '条')
          } else if (!successRows.length) {
            this.$message.error(failRows[0].msg || '删除失败')
          } else {
            this.$message.warning('已删除' + successRows.length + '条，失败' + failRows.length + '条')
          }
          this.getDataList()
        })
      }).catch(() => {})
    },
    buildRohsCreatePartData () {
      const user = this.$store.state.user || {}
      return {
        site: this.modalData.site || user.site || '',
        partNo: '',
        partDesc: this.modalData.materialDesc || '',
        partType: 'Purchased',
        hazardCode: '',
        hazardDesc: '',
        familyId: '',
        familyName: '',
        groupId: '',
        groupName: '',
        umId: '',
        umName: '',
        weightNet: '',
        uomForWeightNet: 'kg',
        volumeNet: '',
        uomForVolumeNet: 'm3',
        lotTrackingCode: 'Order Based',
        remark: '',
        productGroupId1: this.modalData.commGroup1 || '',
        productGroupName1: this.modalData.commGroup1Desc || '',
        productGroupId2: this.modalData.commGroup2 || '',
        productGroupName2: this.modalData.commGroup2Desc || '',
        productGroupId3: '',
        productGroupName3: '',
        productGroupId4: '*',
        productGroupName4: 'NorthSky Application owner',
        commGroup3: this.modalData.commGroup3 || '',
        commGroup3Desc: this.modalData.commGroup3Desc || '',
        codeNo: '',
        codeDesc: '',
        typeDesignation: '',
        assetClass: 'S',
        assetClassDesc: '标准',
        dimQuality: '',
        abcClass: 'C',
        abcClassDesc: '',
        frequencyClass: 'Very Slow Mover',
        lifecycleStage: 'Development',
        countryOfOrigin: '',
        countryOfOriginDesc: '',
        regionOfOrigin: '',
        regionOfOriginDesc: '',
        manufacturingLeadTime: 0,
        expectedLeadTime: 0,
        durabilityWeek: '',
        durabilityDay: '',
        intrastatConvFactor: undefined,
        customsStatNo: '',
        customsStatDesc: '',
        umDesc: '',
        planningMethod: 'A',
        planningMethodDesc: '',
        partStatus: 'A',
        partStatusDesc: '活动',
        active: 'Y',
        status: 'Y',
        supplyCode: 'Inventory Order',
        configurationId: '*',
        partCostGroupId: '',
        partCostGroupDesc: '',
        inventoryValuationMethod: 'Standard Cost',
        inventoryPartCostLevel: 'Cost Per Part',
        invoiceConsideration: 'Ignore Invoice Price',
        zeroCostFlag: 'Zero Cost Forbidden',
        estimatedMaterialCost: 0,
        safetyStock: 0,
        minOrderQty: 0,
        maxOrderQty: 0,
        mulOrderQty: 0,
        safetyLeadTime: 0,
        shrinkageFac: 0,
        stdOrderQty: 0,
        cumLeadTime: 0,
        byProdAsSupplyInMrpDb: '',
        unprotectedLeadTime: 0,
        backFlushPart: 'All Locations',
        issueType: 'Reserve And Backflush',
        mrpControlFlagDb: 'Y',
        fixedLeadTimeDay: 0,
        overReporting: 'Allowed',
        useTheoreticalDensityDb: '',
        variableLeadTimeDay: 0,
        overReportTolerance: 0,
        fixedLeadTimeHour: 0,
        density: undefined,
        variableLeadTimeHour: 0,
        showInQueryFlag: 'Y',
        temporaryPartFlag: 'N',
        partItemList: [],
        createBy: user.name || '',
        updateBy: user.name || ''
      }
    },
    openCreateIfsPartDialog () {
      if (!this.isEditMode || !this.canEditRohsMaterial()) {
        this.$message.warning('当前状态不允许创建IFS料号')
        return
      }
      this.rohsCreatePartData = this.buildRohsCreatePartData()
      this.rohsCreatePartTab = 'General'
      this.rohsCreatePartTagNo = 0
      this.rohsCharacteristicDialogFlag = false
      this.rohsCharacteristicQueryData = {
        propertiesItemNo: '',
        itemDesc: ''
      }
      this.rohsCharacteristicList = []
      this.rohsCharacteristicSelections = []
      this.rohsPartItemSelections = []
      this.rohsCreatePartDialogFlag = true
    },
    closeRohsCreatePartDialog () {
      this.rohsCreatePartTab = 'General'
      this.rohsCreatePartTagNo = 0
      this.rohsCreatePartLoading = false
      this.rohsCharacteristicDialogFlag = false
      this.rohsCharacteristicQueryData = {
        propertiesItemNo: '',
        itemDesc: ''
      }
      this.rohsCharacteristicList = []
      this.rohsCharacteristicSelections = []
      this.rohsPartItemSelections = []
      this.rohsCreatePartData = this.buildRohsCreatePartData()
    },
    rohsChangeExpectedLeadTime () {
      this.rohsCreatePartData.expectedLeadTime = this.rohsCreatePartData.manufacturingLeadTime
    },
    rohsChangeDurabilityWeek () {
      const day = Number(this.rohsCreatePartData.durabilityDay || 0)
      this.rohsCreatePartData.durabilityWeek = day / 7
    },
    nextRohsCreatePartNo (silent = false) {
      this.rohsCreatePartData.ifsPartNo = this.rohsCreatePartData.partNo
      const params = {
        ...this.rohsCreatePartData,
        ifsPartNo: this.rohsCreatePartData.ifsPartNo,
        site: this.rohsCreatePartData.site || this.$store.state.user.site,
        createBy: this.$store.state.user.name || '',
        updateBy: this.$store.state.user.name || ''
      }
      getPartNextPartNo(params).then(({data}) => {
        if (data && data.code === 0) {
          this.$set(this.rohsCreatePartData, 'partNo', data.rows || '')
          this.$set(this.rohsCreatePartData, 'ifsPartNo', data.rows || '')
        } else if (!silent) {
          this.$message.error((data && data.msg) || '获取料号失败')
        }
      }).catch(() => {
        if (!silent) {
          this.$message.error('获取料号失败')
        }
      })
    },
    openRohsCreatePartBaseList (tagNo) {
      if (!this.rohsCreatePartDialogFlag) {
        return
      }
      this.rohsCreatePartTagNo = tagNo
      this.$nextTick(() => {
        let strVal = ''
        if (tagNo === 1007) {
          strVal = this.rohsCreatePartData.umId
        } else if (tagNo === 108) {
          strVal = this.rohsCreatePartData.familyId
        } else if (tagNo === 109) {
          strVal = this.rohsCreatePartData.groupId
        } else if (tagNo === 112) {
          strVal = this.rohsCreatePartData.productGroupId3
        } else if (tagNo === 113) {
          strVal = this.rohsCreatePartData.productGroupId4
        } else if (tagNo === 123) {
          strVal = this.rohsCreatePartData.hazardCode
        } else if (tagNo === 124) {
          strVal = this.rohsCreatePartData.assetClass
        } else if (tagNo === 125) {
          strVal = this.rohsCreatePartData.partStatus
        } else if (tagNo === 126) {
          strVal = this.rohsCreatePartData.abcClass
        } else if (tagNo === 127) {
          strVal = this.rohsCreatePartData.countryOfOrigin
        } else if (tagNo === 128) {
          strVal = this.rohsCreatePartData.regionOfOrigin
        } else if (tagNo === 129) {
          strVal = this.rohsCreatePartData.customsStatNo
        } else if (tagNo === 131) {
          strVal = this.rohsCreatePartData.partCostGroupId
        } else if (tagNo === 20) {
          strVal = this.rohsCreatePartData.codeNo
        } else if (tagNo === 132) {
          strVal = this.rohsCreatePartData.planningMethod
        }
        this.$refs.baseList.init(tagNo, strVal)
      })
    },
    applyRohsCreatePartBaseData (val) {
      if (this.rohsCreatePartTagNo === 1007) {
        this.rohsCreatePartData.umId = val.um_id
        this.rohsCreatePartData.umName = val.um_name
      } else if (this.rohsCreatePartTagNo === 108) {
        this.rohsCreatePartData.familyId = val.family_id
        this.rohsCreatePartData.familyName = val.family_name
      } else if (this.rohsCreatePartTagNo === 109) {
        this.rohsCreatePartData.groupId = val.group_id
        this.rohsCreatePartData.groupName = val.group_name
      } else if (this.rohsCreatePartTagNo === 112) {
        this.rohsCreatePartData.productGroupId3 = val.product_group_id
        this.rohsCreatePartData.productGroupName3 = val.product_group_name
      } else if (this.rohsCreatePartTagNo === 113) {
        this.rohsCreatePartData.productGroupId4 = val.product_group_id
        this.rohsCreatePartData.productGroupName4 = val.product_group_name
      } else if (this.rohsCreatePartTagNo === 123) {
        this.rohsCreatePartData.hazardCode = val.hazard_code
        this.rohsCreatePartData.hazardDesc = val.hazard_desc
      } else if (this.rohsCreatePartTagNo === 124) {
        this.rohsCreatePartData.assetClass = val.asset_class
        this.rohsCreatePartData.assetClassDesc = val.asset_class_desc
      } else if (this.rohsCreatePartTagNo === 125) {
        this.rohsCreatePartData.partStatus = val.part_status
        this.rohsCreatePartData.partStatusDesc = val.part_status_desc
      } else if (this.rohsCreatePartTagNo === 126) {
        this.rohsCreatePartData.abcClass = val.abc_class
        this.rohsCreatePartData.abcClassDesc = val.abc_class_desc
      } else if (this.rohsCreatePartTagNo === 127) {
        this.rohsCreatePartData.countryOfOrigin = val.country_of_origin
        this.rohsCreatePartData.countryOfOriginDesc = val.country_of_origin_desc
      } else if (this.rohsCreatePartTagNo === 128) {
        this.rohsCreatePartData.regionOfOrigin = val.region_of_origin
        this.rohsCreatePartData.regionOfOriginDesc = val.region_of_origin_desc
      } else if (this.rohsCreatePartTagNo === 129) {
        this.rohsCreatePartData.customsStatNo = val.customs_stat_no
        this.rohsCreatePartData.customsStatDesc = val.customs_stat_desc
      } else if (this.rohsCreatePartTagNo === 131) {
        this.rohsCreatePartData.partCostGroupId = val.part_cost_group_id
        this.rohsCreatePartData.partCostGroupDesc = val.part_cost_group_desc
      } else if (this.rohsCreatePartTagNo === 20) {
        this.rohsCreatePartData.codeNo = val.Code_no
        this.rohsCreatePartData.codeDesc = val.Code_desc
        this.loadRohsPartItemListByCodeNo()
      } else if (this.rohsCreatePartTagNo === 132) {
        this.rohsCreatePartData.planningMethod = val.planning_method
        this.rohsCreatePartData.planningMethodDesc = val.planning_method_desc
      }
      this.rohsCreatePartTagNo = 0
    },
    rohsCreateBaseFieldBlur (tagNo, codeKey, descKey, queryField, resultCodeField, resultDescField, withSite = true) {
      this.rohsCreatePartData[codeKey] = (this.rohsCreatePartData[codeKey] || '').replace(/[\s\u00A0\u3000\u200B]/g, '')
      if (!this.rohsCreatePartData[codeKey]) {
        this.rohsCreatePartData[descKey] = ''
        return
      }
      const site = this.rohsCreatePartData.site || this.modalData.site || this.$store.state.user.site
      let conditionSql = " and " + queryField + " = '" + this.rohsCreatePartData[codeKey] + "'"
      if (withSite) {
        conditionSql += " and site = '" + site + "'"
      }
      const tempData = {
        tagno: tagNo,
        conditionSql: conditionSql
      }
      verifyData(tempData).then(({data}) => {
        if (data && data.code === 0 && data.baseListData.length > 0) {
          this.rohsCreatePartData[codeKey] = data.baseListData[0][resultCodeField]
          this.rohsCreatePartData[descKey] = data.baseListData[0][resultDescField]
        } else {
          this.rohsCreatePartData[descKey] = ''
        }
      }).catch(() => {
        this.rohsCreatePartData[descKey] = ''
      })
    },
    rohsCreateHazardCodeBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'hazardCode', 'hazardDesc', 'hazard_code', 'hazard_code', 'hazard_desc')
    },
    rohsCreateProductGroupId4Blur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'productGroupId4', 'productGroupName4', 'product_group_id', 'product_group_id', 'product_group_name')
    },
    rohsCreateProductGroupId3Blur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'productGroupId3', 'productGroupName3', 'product_group_id', 'product_group_id', 'product_group_name')
    },
    rohsCreateUmIdBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'umId', 'umName', 'um_id', 'um_id', 'um_name', false)
    },
    rohsCreateGroupIdBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'groupId', 'groupName', 'group_id', 'group_id', 'group_name')
    },
    rohsCreateFamilyIdBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'familyId', 'familyName', 'family_id', 'family_id', 'family_name')
    },
    rohsCreateAssetClassBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'assetClass', 'assetClassDesc', 'asset_class', 'asset_class', 'asset_class_desc')
    },
    rohsCreatePartStatusBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'partStatus', 'partStatusDesc', 'part_status', 'part_status', 'part_status_desc')
    },
    rohsCreateAbcClassBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'abcClass', 'abcClassDesc', 'abc_class', 'abc_class', 'abc_class_desc')
    },
    rohsCreateCountryOfOriginBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'countryOfOrigin', 'countryOfOriginDesc', 'country_of_origin', 'country_of_origin', 'country_of_origin_desc')
    },
    rohsCreateRegionOfOriginBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'regionOfOrigin', 'regionOfOriginDesc', 'region_of_origin', 'region_of_origin', 'region_of_origin_desc')
    },
    rohsCreateCustomsStatNoBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'customsStatNo', 'customsStatDesc', 'customs_stat_no', 'customs_stat_no', 'customs_stat_desc')
    },
    rohsCreatePartCostGroupIdBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'partCostGroupId', 'partCostGroupDesc', 'part_cost_group_id', 'part_cost_group_id', 'part_cost_group_desc')
    },
    rohsCreatePlanningMethodBlur (tagNo) {
      this.rohsCreateBaseFieldBlur(tagNo, 'planningMethod', 'planningMethodDesc', 'planning_method', 'planning_method', 'planning_method_desc')
    },
    rohsCreateCodeNoBlur (tagNo) {
      this.rohsCreatePartData.codeNo = (this.rohsCreatePartData.codeNo || '').replace(/[\s\u00A0\u3000\u200B]/g, '')
      if (!this.rohsCreatePartData.codeNo) {
        this.rohsCreatePartData.codeDesc = ''
        this.$set(this.rohsCreatePartData, 'partItemList', [])
        this.rohsPartItemSelections = []
        return
      }
      const site = this.rohsCreatePartData.site || this.modalData.site || this.$store.state.user.site
      const tempData = {
        tagno: tagNo,
        conditionSql: " and Code_no = '" + this.rohsCreatePartData.codeNo + "'" + " and site = '" + site + "'"
      }
      verifyData(tempData).then(({data}) => {
        if (data && data.code === 0 && data.baseListData.length > 0) {
          this.rohsCreatePartData.codeNo = data.baseListData[0].Code_no
          this.rohsCreatePartData.codeDesc = data.baseListData[0].Code_desc
          this.loadRohsPartItemListByCodeNo()
        } else {
          this.rohsCreatePartData.codeDesc = ''
          this.$set(this.rohsCreatePartData, 'partItemList', [])
          this.rohsPartItemSelections = []
        }
      }).catch(() => {
        this.rohsCreatePartData.codeDesc = ''
      })
    },
    loadRohsPartItemListByCodeNo () {
      if (!this.rohsCreatePartData.codeNo) {
        this.$set(this.rohsCreatePartData, 'partItemList', [])
        this.rohsPartItemSelections = []
        return
      }
      const params = {
        site: this.rohsCreatePartData.site || this.modalData.site || this.$store.state.user.site,
        codeNo: this.rohsCreatePartData.codeNo,
        recordType: 'IP'
      }
      getPartItemListByCodeNo(params).then(({data}) => {
        if (data && data.code === 0) {
          this.$set(this.rohsCreatePartData, 'partItemList', (data.rows || []).map(item => ({
            ...item,
            numValue: item.numValue === null ? undefined : item.numValue
          })))
        } else {
          this.$set(this.rohsCreatePartData, 'partItemList', [])
        }
        this.rohsPartItemSelections = []
      }).catch(() => {
        this.$set(this.rohsCreatePartData, 'partItemList', [])
        this.rohsPartItemSelections = []
      })
    },
    rohsPartItemSelectionChange (selection) {
      this.rohsPartItemSelections = selection || []
    },
    openRohsCharacteristicDialog () {
      this.rohsCharacteristicSelections = []
      this.rohsCharacteristicQueryData = {
        propertiesItemNo: '',
        itemDesc: ''
      }
      this.queryRohsCharacteristicOptions()
      this.rohsCharacteristicDialogFlag = true
    },
    removeRohsPartItemRows () {
      if (!this.rohsPartItemSelections || this.rohsPartItemSelections.length === 0) {
        this.$message.warning('请选择要删除的属性！')
        return
      }
      this.$confirm('请是否确认删除该属性记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const removeSet = new Set(this.rohsPartItemSelections.map(item => item.propertiesItemNo))
        this.$set(this.rohsCreatePartData, 'partItemList', (this.rohsCreatePartData.partItemList || []).filter(item => !removeSet.has(item.propertiesItemNo)))
        this.rohsPartItemSelections = []
      }).catch(() => {})
    },
    queryRohsCharacteristicOptions () {
      const itemNos = (this.rohsCreatePartData.partItemList || []).map(item => item.propertiesItemNo).filter(item => item).join(',')
      const params = {
        site: this.rohsCreatePartData.site || this.modalData.site || this.$store.state.user.site,
        recordType: 'IP',
        propertiesItemNo: this.rohsCharacteristicQueryData.propertiesItemNo,
        itemDesc: this.rohsCharacteristicQueryData.itemDesc,
        itemNos: itemNos
      }
      getPartItemExclusionAlreadyExists(params).then(({data}) => {
        if (data && data.code === 0) {
          this.rohsCharacteristicList = data.rows || []
        } else {
          this.rohsCharacteristicList = []
        }
      }).catch(() => {
        this.rohsCharacteristicList = []
      })
    },
    rohsCharacteristicRowClick (row) {
      if (this.$refs.rohsCharacteristicTable) {
        this.$refs.rohsCharacteristicTable.toggleRowSelection(row)
      }
    },
    rohsCharacteristicSelectionChange (selection) {
      this.rohsCharacteristicSelections = selection || []
    },
    saveRohsCharacteristics () {
      if (!this.rohsCharacteristicSelections || this.rohsCharacteristicSelections.length === 0) {
        this.$message.warning('请选择属性！')
        return
      }
      const currentList = Array.isArray(this.rohsCreatePartData.partItemList) ? this.rohsCreatePartData.partItemList : []
      const existSet = new Set(currentList.map(item => item.propertiesItemNo))
      const appendList = this.rohsCharacteristicSelections.filter(item => item && item.propertiesItemNo && !existSet.has(item.propertiesItemNo)).map(item => ({
        ...item,
        numValue: item.numValue === null ? undefined : item.numValue
      }))
      if (appendList.length === 0) {
        this.$message.warning('所选属性已存在')
        return
      }
      this.$set(this.rohsCreatePartData, 'partItemList', [...currentList, ...appendList])
      this.rohsCharacteristicDialogFlag = false
      this.rohsCharacteristicSelections = []
    },
    validateRohsCreatePart () {
      this.rohsCreatePartData.partNo = (this.rohsCreatePartData.partNo || '').replace(/[\s\u00A0\u3000\u200B]/g, '')
      if (!this.rohsCreatePartData.partNo) {
        this.$message.warning('请填写物料编码')
        return false
      }
      if (!/^[A-Za-z0-9._-]+$/.test(this.rohsCreatePartData.partNo)) {
        this.$message.warning('物料编码只能包含字母、数字、-、_、.')
        return false
      }
      if (!this.rohsCreatePartData.partDesc || !String(this.rohsCreatePartData.partDesc).trim()) {
        this.$message.warning('请填写物料名称')
        return false
      }
      if (!this.rohsCreatePartData.partType) {
        this.$message.warning('请选择零件类型')
        return false
      }
      if (!this.rohsCreatePartData.umId) {
        this.$message.warning('请选择计量单位')
        return false
      }
      if (!this.rohsCreatePartData.productGroupId1 || !this.rohsCreatePartData.productGroupId2) {
        this.$message.warning('请先在RoHS单据中维护商品组1/2')
        return false
      }
      if (!this.rohsCreatePartData.productGroupId3) {
        this.$message.warning('请选择会计组')
        return false
      }
      if (!this.rohsCreatePartData.productGroupId4) {
        this.$message.warning('请选择计划人')
        return false
      }
      return true
    },
    appendCreatedPartToRohsMaterial (createdPart) {
      const appendResult = this.appendMaterialRows([{
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo,
        projectId: this.modalData.projectId,
        testPartNo: createdPart.partNo,
        finalPartNo: createdPart.partNo,
        partDesc: createdPart.partDesc,
        partStatus: createdPart.partStatus || 'A'
      }])
      if (!appendResult.appendedCount) {
        this.$message.warning('IFS料号创建成功，但该料号已存在于材料列表')
        return Promise.resolve()
      }
      if (!this.shouldPersistMaterialsImmediately()) {
        this.$set(this.modalData, 'materialList', appendResult.materialList)
        this.$message.success('IFS料号创建成功，已加入材料列表')
        return Promise.resolve()
      }
      return this.persistMaterialList(appendResult.materialList, 'IFS料号创建成功并已关联到RoHS材料')
    },
    saveRohsCreatePart () {
      if (!this.validateRohsCreatePart()) {
        return
      }
      const payload = {
        ...this.rohsCreatePartData,
        site: this.modalData.site || this.$store.state.user.site,
        buNo: this.modalData.process || '',
        createBy: this.$store.state.user.name || '',
        updateBy: this.$store.state.user.name || '',
        partDesc: (this.rohsCreatePartData.partDesc || '').trim(),
        productGroupId1: this.modalData.commGroup1 || this.rohsCreatePartData.productGroupId1,
        productGroupName1: this.modalData.commGroup1Desc || this.rohsCreatePartData.productGroupName1,
        productGroupId2: this.modalData.commGroup2 || this.rohsCreatePartData.productGroupId2,
        productGroupName2: this.modalData.commGroup2Desc || this.rohsCreatePartData.productGroupName2,
        productGroupId3: this.rohsCreatePartData.productGroupId3,
        productGroupName3: this.rohsCreatePartData.productGroupName3,
        commGroup3: this.modalData.commGroup3 || this.rohsCreatePartData.commGroup3,
        commGroup3Desc: this.modalData.commGroup3Desc || this.rohsCreatePartData.commGroup3Desc,
        status: 'Y',
        showInQueryFlag: 'Y',
        temporaryPartFlag: 'N',
        ifsPartNo: this.rohsCreatePartData.partNo,
        plmPartNo: this.rohsCreatePartData.partNo,
        partItemList: Array.isArray(this.rohsCreatePartData.partItemList) ? this.rohsCreatePartData.partItemList : []
      }
      this.rohsCreatePartLoading = true
      createOfficialPartForRohs(payload).then(({data}) => {
        if (data && data.code === 0) {
          this.appendCreatedPartToRohsMaterial(payload).then(() => {
            this.rohsCreatePartDialogFlag = false
          })
        } else {
          this.$message.error((data && data.msg) || '创建IFS料号失败')
        }
      }).catch(() => {
        this.$message.error('创建IFS料号失败')
      }).finally(() => {
        this.rohsCreatePartLoading = false
      })
    },
    openProjectMaterialDialog () {
      if (!this.canEditRohsMaterial()) {
        this.$message.warning('当前状态不允许编辑材料')
        return
      }
      this.projectMaterialDialogFlag = true
      this.projectMaterialPageIndex = 1
      this.searchProjectMaterialList()
    },
    searchProjectMaterialList () {
      this.projectMaterialLoading = true
      const params = {
        page: this.projectMaterialPageIndex,
        limit: this.projectMaterialPageSize,
        site: this.$store.state.user.site,
        partDesc: this.projectMaterialSearchData.partDesc,
        finalPartNo: this.projectMaterialSearchData.finalPartNo,
        partStatus: this.projectMaterialSearchData.partStatus
      }
      api.getRohsProjectMaterialList(params).then(({data}) => {
        if (data && data.code === 0 && data.page) {
          this.projectMaterialList = data.page.list || []
          this.projectMaterialTotal = data.page.totalCount || 0
          this.$nextTick(() => {
            if (this.$refs.projectMaterialTable) {
              this.$refs.projectMaterialTable.clearSelection()
            }
          })
        } else {
          this.projectMaterialList = []
          this.projectMaterialTotal = 0
          this.$message.error(data.msg || '物料查询失败')
        }
        this.projectMaterialLoading = false
      }).catch(() => {
        this.projectMaterialList = []
        this.projectMaterialTotal = 0
        this.projectMaterialLoading = false
      })
    },
    projectMaterialSelectionChange (rows) {
      this.projectMaterialSelections = rows || []
    },
    projectMaterialSizeChangeHandle (val) {
      this.projectMaterialPageSize = val
      this.projectMaterialPageIndex = 1
      this.searchProjectMaterialList()
    },
    projectMaterialCurrentChangeHandle (val) {
      this.projectMaterialPageIndex = val
      this.searchProjectMaterialList()
    },
    confirmProjectMaterialSelection () {
      if (!this.canEditRohsMaterial()) {
        this.$message.warning('当前状态不允许编辑材料')
        return
      }
      if (!this.projectMaterialSelections || this.projectMaterialSelections.length === 0) {
        this.$message.warning('请至少选择一条物料')
        return
      }
      const appendResult = this.appendMaterialRows(this.projectMaterialSelections)
      if (!appendResult.appendedCount) {
        this.$message.warning('所选物料已存在，未新增数据')
        return
      }
      if (!this.shouldPersistMaterialsImmediately()) {
        this.$set(this.modalData, 'materialList', appendResult.materialList)
        this.projectMaterialDialogFlag = false
        this.$message.success('已加入材料列表，保存单据后写入数据库')
        return
      }
      this.$confirm('确认新增选中材料？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.persistMaterialList(appendResult.materialList, '新增材料成功', () => {
          this.projectMaterialDialogFlag = false
          this.projectMaterialSelections = []
          if (this.$refs.projectMaterialTable) {
            this.$refs.projectMaterialTable.clearSelection()
          }
        })
      }).catch(() => {})
    },
    appendMaterialRows (rows) {
      const materialList = Array.isArray(this.modalData.materialList) ? [...this.modalData.materialList] : []
      const exists = new Set(materialList.map(item => item.testPartNo))
      let appendedCount = 0
      rows.forEach(row => {
        const testPartNo = row.testPartNo || row.test_part_no
        if (!testPartNo || exists.has(testPartNo)) {
          return
        }
        exists.add(testPartNo)
        appendedCount++
        materialList.push({
          site: this.modalData.site,
          referenceNo: this.modalData.referenceNo,
          projectId: this.modalData.projectId,
          testPartNo: testPartNo,
          finalPartNo: row.finalPartNo || row.final_part_no || '',
          partDesc: row.partDesc || row.part_desc || '',
          partStatus: row.partStatus || row.part_status || ''
        })
      })
      return {
        materialList,
        appendedCount
      }
    },
    materialSelectionChange (rows) {
      this.materialSelections = rows || []
    },
    shouldPersistMaterialsImmediately () {
      return this.modalTitle === 'RoHS 编辑' && this.modalData && this.modalData.referenceNo && !String(this.modalData.referenceNo).startsWith('TEMP-')
    },
    normalizeMaterialListForSave (materialList) {
      return (materialList || []).map((item, index) => {
        return {
          site: item.site || this.modalData.site || '',
          referenceNo: item.referenceNo || this.modalData.referenceNo || '',
          projectId: item.projectId || this.modalData.projectId || '',
          testPartNo: item.testPartNo || item.test_part_no || '',
          finalPartNo: item.finalPartNo || item.final_part_no || '',
          partDesc: item.partDesc || item.part_desc || '',
          partStatus: item.partStatus || item.part_status || '',
          lineNo: index + 1
        }
      }).filter(item => item.testPartNo)
    },
    persistMaterialList (materialList, successMsg, successCallback) {
      const normalizedList = this.normalizeMaterialListForSave(materialList)
      const payload = {
        site: this.modalData.site,
        referenceNo: this.modalData.referenceNo,
        projectId: this.modalData.projectId,
        materialList: normalizedList
      }
      return api.updateRohsMaterials(payload).then(({data}) => {
        if (data && data.code === 0) {
          this.$set(this.modalData, 'materialList', normalizedList)
          this.materialSelections = []
          if (this.currentRow && this.currentRow.referenceNo === this.modalData.referenceNo) {
            this.$set(this.currentRow, 'materialList', normalizedList)
          }
          this.$message.success(successMsg || '保存成功')
          if (typeof successCallback === 'function') {
            successCallback()
          }
        } else {
          this.$message.error((data && data.msg) || '保存失败')
        }
      }).catch(() => {
        this.$message.error('保存失败')
      })
    },
    removeSelectedMaterialRows () {
      if (!this.canEditRohsMaterial()) {
        this.$message.warning('当前状态不允许编辑材料')
        return
      }
      if (!this.materialSelections || this.materialSelections.length === 0) {
        this.$message.warning('请先选择要删除的材料')
        return
      }
      const removeSet = new Set(this.materialSelections.map(item => item.testPartNo))
      const materialList = (this.modalData.materialList || []).filter(item => !removeSet.has(item.testPartNo))
      if (!this.shouldPersistMaterialsImmediately()) {
        this.$set(this.modalData, 'materialList', materialList)
        this.materialSelections = []
        this.$message.success('已删除材料，保存单据后写入数据库')
        return
      }
      this.$confirm('确认删除选中材料？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.persistMaterialList(materialList, '删除材料成功')
      }).catch(() => {})
    },
    // ======== chooseList相关方法 ========
    // 获取基础数据列表
    getBaseList (val, type) {
      this.tagNo = val
      this.tagNo1 = type
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (val === 102) {
          if (type === 1) {
            strVal = this.modalData.endCustomer
            conSql = " order by Customer_no "
          }
        }
        if (val === 103 || val === 2001 || val === 2054) {
          if (type === 1) {
            strVal = this.modalData.applicant
          } else if (type === 3) {
            strVal = this.modalData.npdEngineer
          } else if (type === 4) {
            strVal = this.modalData.technicalPlan
          } else if (type === 5) {
            strVal = this.modalData.pm
          }
          conSql = " and b.site = '" + this.$store.state.user.site + "'"
        }
        if (val === 2000) {
          strVal = this.modalData.buyer
          conSql = " and b.site = '" + this.$store.state.user.site + "'"
        }
        if (val === 110) {
          strVal = this.modalData.commGroup1
        }
        if (val === 111) {
          strVal = this.modalData.commGroup2
        }
        if (val === 130) {
          strVal = this.modalData.commGroup3
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    // 列表方法的回调
    getBaseData (val) {
      if (this.rohsCreatePartDialogFlag && this.rohsCreatePartTagNo) {
        this.applyRohsCreatePartBaseData(val)
        return
      }
      if (this.tagNo === 102) {
        if (this.tagNo1 === 1) {
          if (val.Customer_no === this.modalData.endCustomer) {
            return
          }
          if (this.modalData.projectIdFlag) {
            this.modalData.projectIdFlag = false
          }
          this.modalData.endCustomer = val.Customer_no
          this.modalData.endCustomerName = val.Customer_desc
          this.modalData.projectId = ''
          this.modalData.projectName = ''
          this.$set(this.modalData, 'materialList', [])
        }
      }
      if (this.tagNo === 103 || this.tagNo === 2001 || this.tagNo === 2054) {
        if (this.tagNo1 === 1) {
          this.modalData.applicant = val.username
          this.modalData.applicantName = val.user_display
        } else if (this.tagNo1 === 3) {
          this.modalData.npdEngineer = val.username
          this.modalData.npdEngineerName = val.user_display
        } else if (this.tagNo1 === 4) {
          this.modalData.technicalPlan = val.username
          this.modalData.technicalPlanName = val.user_display
        } else if (this.tagNo1 === 5) {
          this.modalData.pm = val.username
          this.modalData.pmName = val.user_display
        }
      }
      if (this.tagNo === 110) {
        this.modalData.commGroup1 = val.product_group_id
        this.modalData.commGroup1Desc = val.product_group_name
      }
      if (this.tagNo === 111) {
        this.modalData.commGroup2 = val.product_group_id
        this.modalData.commGroup2Desc = val.product_group_name
      }
      if (this.tagNo === 130) {
        this.modalData.commGroup3 = val.product_group_id
        this.modalData.commGroup3Desc = val.product_group_name
      }
      if (this.tagNo === 2000) {
        this.modalData.buyer = val.username
        this.modalData.buyerName = val.user_display
      }
    },
    handleQueryCustomer() {
      if (!this.modalData.endCustomer) {
        this.modalData.endCustomerName = ''
        this.modalData.projectId = ''
        this.modalData.projectName = ''
        this.modalData.projectIdFlag = true
        this.$set(this.modalData, 'materialList', [])
        return
      }
      let params = {
        site: this.$store.state.user.site,
        customerNo: this.modalData.endCustomer
      }
      queryCustomer(params).then(({data}) => {
        if (data && data.code === 0) {
          if (data.rows && data.rows.length === 1) {
            const customer = data.rows[0]
            this.modalData.endCustomerName = customer.customerDesc || customer.Customer_desc || customer.customerName || ''
            this.modalData.projectIdFlag = !!this.modalData.endCustomerFlag
          } else {
            this.modalData.endCustomerName = ''
            this.modalData.projectId = ''
            this.modalData.projectName = ''
            this.modalData.projectIdFlag = true
            this.$set(this.modalData, 'materialList', [])
          }
        } else {
          this.modalData.endCustomerName = ''
          this.modalData.projectId = ''
          this.modalData.projectName = ''
          this.modalData.projectIdFlag = true
          this.$set(this.modalData, 'materialList', [])
        }
      }).catch((error) => {
        this.modalData.endCustomerName = ''
        this.modalData.projectId = ''
        this.modalData.projectName = ''
        this.modalData.projectIdFlag = true
        this.$set(this.modalData, 'materialList', [])
      })
    },
    handleQueryProjectByCustomer() {
      if (!this.modalData.projectId) {
        this.modalData.projectName = ''
        return
      }
      let params = {
        site: this.$store.state.user.site,
        projectId: this.modalData.projectId
      }
      if (this.modalData.endCustomer) {
        params.customerId = this.modalData.endCustomer
      }
      queryProjectByCustomer(params).then(({data}) => {
        if (data && data.code === 0) {
          if (data.rows && data.rows.length === 1) {
            const project = data.rows[0]
            this.modalData.projectName = project.projectName || project.Project_name || ''
          } else {
            this.modalData.projectName = ''
          }
        } else {
          this.modalData.projectName = ''
        }
      }).catch((error) => {
        this.modalData.projectName = ''
      })
    },
    projectClickRow(row) {
      const oldProjectId = this.modalData.projectId
      this.modalData.projectId = row.projectId
      this.modalData.projectName = row.projectName
      if (this.modalData.endCustomer && this.modalData.endCustomer !== '') {
        // do nothing
      } else {
        this.modalData.endCustomer = row.customerId
        this.modalData.endCustomerName = row.customerName
      }
      if (oldProjectId && oldProjectId !== row.projectId) {
        this.$set(this.modalData, 'materialList', [])
      }
      this.chooseProjectListFlag = false
    },
    searchProjectInfoList() {
      this.projectList = [];
      if (this.modalData.endCustomer && this.modalData.endCustomer !== '') {
        this.searchProjectData.customerId = this.modalData.endCustomer
      } else {
        this.searchProjectData.customerId = undefined
      }
      this.searchProjectData.site = this.$store.state.user.site
      searchProjectInfoList(this.searchProjectData).then(({data}) => {
        if (data && data.code === 0) {
          const rows = data.rows || []
          this.projectList = rows
          if ((!this.modalData.endCustomer || this.modalData.endCustomer === '') && rows.length > 0) {
            this.modalData.projectId = rows[0].projectId
            this.modalData.projectName = rows[0].projectName
            this.modalData.endCustomer = rows[0].customerId
            this.modalData.endCustomerName = rows[0].customerName
          }
        } else {
          this.projectList = []
        }
      }).catch((error) => {
        this.$message.error('查询项目信息失败')
      })
    },
    closeProjectInfoDialog() {
      if(this.$refs.closeProjectInfoForm) {
        this.$refs.closeProjectInfoForm.resetFields();
      }
      this.searchProjectData = {
        site: this.$store.state.user.site,
        projectId: undefined,
        projectName: undefined,
        customerId: undefined,
      }
    },
    // 申请人输入校验
    applicantBlur (tagNo) {
      if (this.modalData.applicant != null && this.modalData.applicant !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and a.username = '" + this.modalData.applicant + "'" + " and b.site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.applicant = data.baseListData[0].username
              this.modalData.applicantName = data.baseListData[0].user_display
              return
            }
          }
          this.modalData.applicantName = ''
        })
      } else {
        this.modalData.applicantName = ''
      }
    },
    // PM输入校验
    pmBlur (tagNo) {
      if (this.modalData.pm != null && this.modalData.pm !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and a.username = '" + this.modalData.pm + "'" + " and b.site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.pm = data.baseListData[0].username
              this.modalData.pmName = data.baseListData[0].user_display
              return
            }
          }
          this.modalData.pmName = ''
        })
      } else {
        this.modalData.pmName = ''
      }
    },
    // NPD工程师输入校验
    npdEngineerBlur (tagNo) {
      if (this.modalData.npdEngineer != null && this.modalData.npdEngineer !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and a.username = '" + this.modalData.npdEngineer + "'" + " and b.site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.npdEngineer = data.baseListData[0].username
              this.modalData.npdEngineerName = data.baseListData[0].user_display
              return
            }
          }
          this.modalData.npdEngineerName = ''
        })
      } else {
        this.modalData.npdEngineerName = ''
      }
    },
    // 技术计划输入校验
    technicalPlanBlur (tagNo) {
      if (this.modalData.technicalPlan != null && this.modalData.technicalPlan !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and a.username = '" + this.modalData.technicalPlan + "'" + " and b.site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.technicalPlan = data.baseListData[0].username
              this.modalData.technicalPlanName = data.baseListData[0].user_display
              return
            }
          }
          this.modalData.technicalPlanName = ''
        })
      } else {
        this.modalData.technicalPlanName = ''
      }
    },
    // 采购输入校验
    buyerBlur (tagNo) {
      if (this.modalData.buyer != null && this.modalData.buyer !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and a.username = '" + this.modalData.buyer + "'" + " and b.site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.buyer = data.baseListData[0].username
              this.modalData.buyerName = data.baseListData[0].user_display
              return
            }
          }
          this.modalData.buyerName = ''
        })
      } else {
        this.modalData.buyerName = ''
      }
    },
    // 商品组1输入校验
    commGroup1Blur (tagNo) {
      if (this.modalData.commGroup1 != null && this.modalData.commGroup1 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.commGroup1 + "'" + " and site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0 && data.baseListData.length > 0) {
            this.modalData.commGroup1 = data.baseListData[0].product_group_id
            this.modalData.commGroup1Desc = data.baseListData[0].product_group_name
          } else {
            this.modalData.commGroup1Desc = ''
          }
        })
      } else {
        this.modalData.commGroup1Desc = ''
      }
    },
    // 商品组2输入校验
    commGroup2Blur (tagNo) {
      if (this.modalData.commGroup2 != null && this.modalData.commGroup2 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.commGroup2 + "'" + " and site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0 && data.baseListData.length > 0) {
            this.modalData.commGroup2 = data.baseListData[0].product_group_id
            this.modalData.commGroup2Desc = data.baseListData[0].product_group_name
          } else {
            this.modalData.commGroup2Desc = ''
          }
        })
      } else {
        this.modalData.commGroup2Desc = ''
      }
    },
    // 商品组3输入校验
    commGroup3Blur (tagNo) {
      if (this.modalData.commGroup3 != null && this.modalData.commGroup3 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.commGroup3 + "'" + " and site = '" + this.$store.state.user.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0 && data.baseListData.length > 0) {
            this.modalData.commGroup3 = data.baseListData[0].product_group_id
            this.modalData.commGroup3Desc = data.baseListData[0].product_group_name
          } else {
            this.modalData.commGroup3Desc = ''
          }
        })
      } else {
        this.modalData.commGroup3Desc = ''
      }
    }
  }
}
</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0 !important;
}

/deep/ .rohs-material-table .el-table__header-wrapper th > .cell {
  white-space: nowrap;
  word-break: keep-all;
}

/deep/ .rohs-multiple-two-rows.el-select .el-input__inner,
/deep/ .rohs-multiple-two-rows .el-select .el-input__inner {
  min-height: 62px !important;
  height: auto !important;
  padding-top: 6px !important;
  padding-bottom: 6px !important;
}

/deep/ .rohs-multiple-two-rows.el-select .el-select__tags,
/deep/ .rohs-multiple-two-rows .el-select .el-select__tags {
  max-width: calc(100% - 34px) !important;
  max-height: 50px;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: normal;
}

/deep/ .rohs-multiple-two-rows.el-select .el-select__tags > span,
/deep/ .rohs-multiple-two-rows .el-select .el-select__tags > span {
  display: inline;
  max-width: 100%;
  white-space: normal;
}

/deep/ .rohs-multiple-two-rows.el-select .el-select__tags .el-tag,
/deep/ .rohs-multiple-two-rows .el-select .el-select__tags .el-tag {
  display: inline-flex;
  max-width: 100%;
  height: auto;
  line-height: 16px;
  padding-top: 2px;
  padding-bottom: 2px;
  margin-right: 4px;
  white-space: normal;
  vertical-align: middle;
}

/deep/ .rohs-multiple-two-rows.el-select .el-select__tags .el-tag .el-select__tags-text,
/deep/ .rohs-multiple-two-rows .el-select .el-select__tags .el-tag .el-select__tags-text {
  white-space: normal;
  word-break: break-all;
}
</style>
