<template>
  <div class="mod-config">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" :model="searchData">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buNo" placeholder="请选择" clearable style="width: 90px">
          <el-option
            v-for = "i in buList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buNo">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'物料编码'">
        <el-input v-model="searchData.partNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料名称'">
        <el-input v-model="searchData.partDesc" clearable style="width: 300px"></el-input>
      </el-form-item>
      <el-form-item :label="'工艺类型'">
        <el-select v-model="searchData.routingType" clearable style="width: 120px">
          <el-option label="Manufacturing" value="Manufacturing"></el-option>
          <el-option label="Repair" value="Repair"></el-option>
          <el-option label="Prototype" value="Prototype"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'Routing版本号'">
        <el-input v-model="searchData.routingRevision" clearable style="width: 90px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" @click="getDataList">查询</el-button>
        <el-button v-if="!authSave" type="primary" @click="addModal">新增</el-button>
        <el-button v-if="!authDelete" type="primary" @click="delModal">删除</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <!-- routing列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      @selection-change="selectionRouting"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="120"
        label="操作">
        <template slot-scope="scope">
          <el-link v-if="!authUpdate" style="cursor: pointer" @click="updateModal(scope.row)">编辑</el-link>
          <el-link style="cursor: pointer" @click="checkOutToBom(scope.row.partNo)">切换BOM</el-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- 复选统计 -->
    <selectDiv ref="selectDiv"></selectDiv>

    <!-- 分页插件 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- routing新增/编辑模态框 -->
    <el-dialog :close-on-click-modal="false" top="8vh" v-drag :before-close="closeModalX" :visible.sync="modalFlag" width="1110px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 5px">
        <el-form-item label="BU" prop="bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" @change="userBuChange" style="width: 150px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.buDesc"
              :value = "i.buNo">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="partNo">
          <span v-if="!modalDisableFlag" slot="label" @click="queryPartList"><a herf="#">物料编码</a></span>
          <span v-else slot="label">物料编码</span>
          <el-input v-model="modalData.partNo" :disabled="modalDisableFlag" @blur="partNoBlur" style="width: 150px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料名称'" prop="partDesc">
          <el-input v-model="modalData.partDesc" disabled style="width: 340px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料单位'">
          <el-input v-model="modalData.printUnit" disabled style="width: 100px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="生效日期" prop="phaseInDate">
          <el-date-picker
            style="width: 150px"
            v-model="modalData.phaseInDate"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="失效日期">
          <el-date-picker
            style="width: 150px"
            v-model="modalData.phaseOutDate"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="'Routing版本号'" prop="routingRevision">
          <el-input-number :controls="false" :step="0" v-model="modalData.routingRevision" :disabled="modalDisableFlag" style="width: 130px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'工艺类型'" prop="routingType">
          <el-select v-model="modalData.routingType" @change="routingTypeChange" :disabled="modalDisableFlag" style="width: 195px">
            <el-option label="Manufacturing" value="Manufacturing"></el-option>
            <el-option label="Repair" value="Repair"></el-option>
            <el-option label="Prototype" value="Prototype"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button v-if="modalData.flag === '1' && headerSaveFlag" :loading="saveHeaderLoading" type="primary" @click="saveRoutingHeader" style="margin-top: 23px;width: 100px">保存</el-button>
          <el-button v-else-if="modalData.flag === '2'" type="primary" @click="copyRoutingRevision" style="margin-top: 23px;width: 100px">Copy</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="备注">
          <el-input type="textarea" v-model="modalData.noteText" :rows="3" resize='none' show-word-limit style="width: 1082px;height: 20px"></el-input>
        </el-form-item>
      </el-form>
      <el-tabs v-model="detailTable" style="margin-top: 50px; width: 100%" type="border-card" class="detail-tab">
        <!-- Routing明细信息页签 -->
        <el-tab-pane label="Routings" name="routing_detail">
          <el-form label-position="top" style="margin-top: -10px">
            <el-form-item>
              <el-button type="primary" @click="saveRoutingDetail" style="margin-left: 7px">新增</el-button>
              <el-button type="primary" :loading="alternativeLoading" @click="deleteRoutingDetail">删除</el-button>
              <el-button type="primary" :loading="alternativeLoading" @click="updateRoutingDetail">编辑</el-button>
              <el-button v-if="modalData.flag === '2'" type="primary" :loading="alternativeLoading" @click="copyRoutingAlternative">Copy</el-button>
              <el-button v-if="detailData.status === 'Tentative' || detailData.status === 'Obsolete'" type="primary" :loading="alternativeLoading" @click="updateStatusToBuildable">Build</el-button>
              <el-button v-if="detailData.status === 'Buildable' && (modalData.effPhaseOutDate == null || modalData.effPhaseOutDate === '')" type="primary" :loading="alternativeLoading" @click="updateStatusToObsolete">Retire</el-button>
              <el-button type="primary" :loading="alternativeLoading" @click="createByStandardOperation">基于标准工序快速创建</el-button>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="detailData" :rules="rules" style="margin-left: 7px">
            <el-form-item :label="'替代编码'">
              <el-select v-model="detailData.alternativeNo" @change="alternativeChange" style="width: 165px">
                <el-option
                  v-for = "(i, index) in detailDataList"
                  :key = "index"
                  :label = "i.alternativeNo"
                  :value = "i.alternativeNo">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="'替代名称'">
              <el-input v-model="detailData.alternativeDescription" readonly style="width: 300px"></el-input>
            </el-form-item>
            <el-form-item :label="'状态'">
              <el-input v-model="detailData.status" readonly style="width: 150px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="detailData" style="margin-left: 7px">
            <el-form-item label="备注">
              <el-input type="textarea" v-model="detailData.detailNoteText" :rows="3" resize='none' show-word-limit readonly style="width: 1073px;height: 20px"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <el-tabs v-show="detailTable === 'routing_detail'" v-model="subDetailTable" style="width: 100%; min-height: 330px" type="border-card" class="sub_detail-tab">
        <!-- Routing子明细信息页签 -->
        <el-tab-pane label="Operations" name="routing_sub_detail">
          <el-form label-position="top" style="margin-top: 5px">
            <el-form-item>
              <el-button type="primary" :loading="alternativeLoading" @click="saveComponentModal" style="margin-left: 7px">新增</el-button>
              <el-button type="primary" :loading="alternativeLoading" @click="deleteComponentPart">删除</el-button>
            </el-form-item>
          </el-form>
          <el-table
            :data="subDetailList"
            height="256px"
            border
            ref="componentTable"
            @row-click="componentClickRow"
            :row-class-name="rowClassName"
            @selection-change="componentSelectionChange"
            style="width:100%">
            <el-table-column type="selection" align="center" width="50"></el-table-column>
            <el-table-column
              v-for="(item,index) in columnSubDetailList" :key="index"
              :sortable="item.columnSortable"
              :prop="item.columnProp"
              :header-align="item.headerAlign"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :align="item.align"
              :fixed="item.fixed == ''?false:item.fixed"
              :min-width="item.columnWidth"
              :label="item.columnLabel">
              <template slot-scope="scope">
                <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              header-align="center"
              align="center"
              width="100"
              label="操作">
              <template slot-scope="scope">
                <a type="text" size="small" @click="updateComponentModal(scope.row)">编辑</a>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:30px;margin-top:20px;text-align:center">
        <el-button :loading="saveAllLoading" type="primary" @click="saveData">保存</el-button>
        <el-button type="primary" @click="closeModal">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 明细新增模态框 -->
    <el-dialog title="替代" :close-on-click-modal="false" v-drag :visible.sync="saveDetailModalFlag" width="730px">
      <el-form :inline="true" label-position="top" :model="saveDetailData" :rules="detailRules" style="margin-left: 5px">
        <el-form-item :label="'替代编码'" prop="alternativeNo" :disabled="saveDetailModalDisable">
          <el-input v-model="saveDetailData.alternativeNo" style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item :label="'替代名称'" prop="alternativeDescription">
          <el-input v-model="saveDetailData.alternativeDescription" style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item :label="'状态'" prop="status">
          <el-input v-model="saveDetailData.status" disabled style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveDetailData" style="margin-left: 5px">
        <el-form-item label="备注">
          <el-input type="textarea" v-model="saveDetailData.detailNoteText" :rows="3" resize='none' show-word-limit style="width: 690px;height: 20px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:35px;margin-top:65px;text-align:center">
        <el-button :loading="saveDetailLoading" type="primary" @click="detailDataSave">保存</el-button>
        <el-button type="primary" @click="saveDetailModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 物料模态框 -->
    <el-dialog title="物料清单" :close-on-click-modal="false" v-drag :visible.sync="partModelFlag" width="900px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="partData">
          <el-form-item :label="'物料编码'">
            <el-input v-model="partData.partNo" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'物料名称'">
            <el-input v-model="partData.partDesc" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="queryPartList">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="partList"
          @row-dblclick="getRowData"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in partColumnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页插件 -->
        <el-pagination
          @size-change="sizeChangeHandle2"
          @current-change="currentChangeHandle2"
          :current-page="pageIndex2"
          :page-sizes="[20, 50, 100, 200, 500]"
          :page-size="pageSize2"
          :total="totalPage2"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="partModelFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 子明细新增模态框 -->
    <el-dialog title="工序" :close-on-click-modal="false" v-drag :visible.sync="componentSaveModal" width="500px">
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'工序编码'" prop="operationNo">
          <el-input-number :controls="false" :step="0" v-model="componentData.operationNo" style="width: 221px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'工序名称'" prop="operationName">
          <el-input v-model="componentData.operationName" style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item prop="workCenterNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(516)"><a herf="#">加工中心编码</a></span>
          <el-input v-model="componentData.workCenterNo" @blur="workCenterBlur(516)" style="width: 103px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-input v-model="componentData.workCenterType" disabled style="width: 103px"></el-input>
        </el-form-item>
        <el-form-item :label="'加工中心名称'">
          <el-input v-model="componentData.workCenterDesc" disabled style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'机器调机时间'" prop="machSetupTime">
          <el-input-number :controls="false" :step="0" v-model="componentData.machSetupTime" @change="changeMachSetupTime" style="width: 221px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'人工调机时间'" prop="laborSetupTime">
          <el-input-number :controls="false" :step="0" v-model="componentData.laborSetupTime" style="width: 221px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item style="margin-left: 235px" prop="setupLaborClassNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(517, 2)"><a herf="#">调机过程中人员等级</a></span>
          <el-input v-model="componentData.setupLaborClassNo" @blur="setupLaborClassBlur(517)" style="width: 70px"></el-input>
          <el-input v-model="componentData.setupLaborClassDesc" disabled style="width: 148px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'调机过程中人数'" style="margin-left: 235px" prop="setupCrewSize">
          <el-input-number :controls="false" :step="0" :precision="2" v-model="componentData.setupCrewSize" style="width: 221px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'产出单位'" prop="runTimeCode">
          <el-select v-model="componentData.runTimeCode" style="width: 221px">
            <el-option label="单位/小时" value="Units/Hour"></el-option>
            <el-option label="小时/单位" value="Hours/Unit"></el-option>
            <el-option label="小时" value="Hours"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="laborClassNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(517, 1)"><a herf="#">人员等级</a></span>
          <el-input v-model="componentData.laborClassNo" @blur="laborClassBlur(517)" style="width: 70px"></el-input>
          <el-input v-model="componentData.laborClassDesc" disabled style="width: 148px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'机器处理时间'">
          <el-input-number :controls="false" :step="0" :precision="6" v-model="componentData.machCycleTime" @change="changeMachCycleTime" style="width: 221px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'人工处理时间'">
          <el-input-number :controls="false" :step="0" :precision="6" v-model="componentData.laborCycleTime" @change="changeLaborCycleTime" style="width: 221px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'机器单位产出'" prop="machRunFactor">
          <el-input-number :controls="false" :step="0" :precision="4" v-model="componentData.machRunFactor" @change="changeMachRunFactor" style="width: 221px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'人工单位产出'" prop="laborRunFactor">
          <el-input-number :controls="false" :step="0" :precision="4" v-model="componentData.laborRunFactor" style="width: 221px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" :rules="componentRules" style="margin-left: 5px">
        <el-form-item :label="'效率%'" prop="efficiencyFactor">
          <el-input-number :controls="false" :step="0" min="0" max="100" v-model="componentData.efficiencyFactor" style="width: 221px"></el-input-number>
        </el-form-item>
        <el-form-item :label="'生产过程中人数'" prop="crewSize">
          <el-input-number :controls="false" :step="0" :precision="2" v-model="componentData.crewSize" style="width: 221px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" style="margin-left: 5px">
        <el-form-item :label="'外协采购料号'">
          <el-input v-model="componentData.outsideOpItem" style="width: 456px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="componentData" style="margin-left: 5px">
        <el-form-item label="备注">
          <el-input type="textarea" v-model="componentData.noteText" :rows="3" resize='none' show-word-limit style="width: 456px;height: 20px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:35px;margin-top:65px;text-align:center">
        <el-button v-if="componentData.flag === '1'" type="primary" @click="componentDataSave(true)">应用</el-button>
        <el-button type="primary" @click="componentDataSave(false)">保存</el-button>
        <el-button type="primary" @click="componentSaveModal = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- copyRouting -->
    <el-dialog title="Copy Structure Revision" :close-on-click-modal="false" v-drag :visible.sync="copyRoutingModelFlag" width="450px">
      <fieldset style="width: 426px">
        <legend>Source Revision</legend>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="物料编码">
            <el-input v-model="modalData.partNo" readonly style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input v-model="modalData.partDesc" readonly style="width: 249px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="Site">
            <el-input v-model="modalData.site" readonly style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="Routing版本号">
            <el-input v-model="modalData.routingRevision" readonly style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="工艺类型">
            <el-input v-model="modalData.routingType" readonly style="width: 185px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="生效日期">
            <el-date-picker style="width: 185px" v-model="modalData.phaseInDate" readonly type="date" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="失效日期">
            <el-date-picker style="width: 185px" v-model="modalData.phaseOutDate" readonly type="date" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-form>
        <el-table
          :data="detailDataList"
          height="100px"
          border
          style="width:100%">
          <el-table-column
            v-for="(item,index) in columnRoutingDetailList" :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>
      </fieldset>
      <fieldset style="width: 426px">
        <legend>Destination Revision</legend>
        <el-form :inline="true" label-position="top" :model="copyRoutingData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item>
            <span slot="label" @click="queryCopyPartModal"><a herf="#">物料编码</a></span>
            <el-input v-model="copyRoutingData.partNo" @change="copyRoutingTypeChange" @blur="copyPartBlur" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'物料名称'">
            <el-input v-model="copyRoutingData.partDesc" disabled style="width: 249px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="copyRoutingData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="Site">
            <el-input v-model="copyRoutingData.site" disabled style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="Routing版本号">
            <el-input v-model="copyRoutingData.routingRevision" disabled style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="工艺类型">
            <el-select v-model="copyRoutingData.routingType" @change="copyRoutingTypeChange" style="width: 185px">
              <el-option label="Manufacturing" value="Manufacturing"></el-option>
              <el-option label="Repair" value="Repair"></el-option>
              <el-option label="Prototype" value="Prototype"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="copyRoutingData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="生效日期">
            <el-date-picker style="width: 185px" v-model="copyRoutingData.phaseInDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
          </el-form-item>
          <el-form-item label="失效日期">
            <el-date-picker style="width: 185px" v-model="copyRoutingData.phaseOutDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
          </el-form-item>
        </el-form>
      </fieldset>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" :loading="copyLoading" @click="copyRouting">保存</el-button>
        <el-button type="primary" @click="copyRoutingModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- copyAlternative -->
    <el-dialog title="Copy Structure Alternative" :close-on-click-modal="false" v-drag :visible.sync="copyAlternativeModelFlag" width="450px">
      <fieldset style="width: 426px">
        <legend>Source Revision</legend>
        <el-form :inline="true" label-position="top" :model="detailData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="物料编码">
            <el-input v-model="detailData.partNo" readonly style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input v-model="modalData.partDesc" readonly style="width: 249px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="detailData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="Site">
            <el-input v-model="detailData.site" readonly style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="Routing版本号">
            <el-input v-model="detailData.routingRevision" readonly style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="工艺类型">
            <el-input v-model="detailData.routingType" readonly style="width: 185px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="detailData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="替代编码">
            <el-input v-model="detailData.alternativeNo" readonly style="width: 185px"></el-input>
          </el-form-item>
          <el-form-item label="替代名称">
            <el-input v-model="detailData.alternativeDescription" readonly style="width: 185px"></el-input>
          </el-form-item>
        </el-form>
      </fieldset>
      <fieldset style="width: 426px">
        <legend>Destination Revision</legend>
        <el-form :inline="true" label-position="top" :model="copyAlternativeData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item>
            <span slot="label" @click="queryCopyPartModal"><a herf="#">物料编码</a></span>
            <el-input v-model="copyAlternativeData.partNo" @blur="copyPartBlur" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'物料名称'">
            <el-input v-model="copyAlternativeData.partDesc" disabled style="width: 249px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="copyAlternativeData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="Site">
            <el-input v-model="copyAlternativeData.site" disabled style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="Routing版本号">
            <el-input v-model="copyAlternativeData.routingRevision" style="width: 85px"></el-input>
          </el-form-item>
          <el-form-item label="工艺类型">
            <el-select v-model="copyAlternativeData.routingType" style="width: 185px">
              <el-option label="Manufacturing" value="Manufacturing"></el-option>
              <el-option label="Repair" value="Repair"></el-option>
              <el-option label="Prototype" value="Prototype"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="copyAlternativeData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="替代编码">
            <el-input v-model="copyAlternativeData.alternativeNo" style="width: 185px"></el-input>
          </el-form-item>
          <el-form-item label="替代名称">
            <el-input v-model="copyAlternativeData.alternativeDescription" style="width: 185px"></el-input>
          </el-form-item>
        </el-form>
      </fieldset>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" :loading="copyLoading" @click="copyAlternative">保存</el-button>
        <el-button type="primary" @click="copyAlternativeModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- copy物料模态框 -->
    <el-dialog title="物料清单" top="17vh" :close-on-click-modal="false" v-drag :visible.sync="copyPartModelFlag" width="700px">
      <el-form :inline="true" label-position="top" :model="copyPartData">
        <el-form-item :label="'物料编码'">
          <el-input v-model="copyPartData.partNo" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料名称'">
          <el-input v-model="copyPartData.partDesc" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="queryCopyPartList">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="250"
        :data="copyPartList"
        @row-dblclick="getCopyRowData"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in componentPartColumnList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <el-pagination
        @size-change="sizeChangeHandle4"
        @current-change="currentChangeHandle4"
        :current-page="pageIndex4"
        :page-sizes="[20, 50, 100, 200, 500]"
        :page-size="pageSize4"
        :total="totalPage4"
        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="copyPartModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 标准工序 -->
    <el-dialog title="标准工序" top="20vh" :close-on-click-modal="false" v-drag :visible.sync="standardOperationModal" width="1000px">
      <el-table
        :height="350"
        :data="standardOperationList"
        ref="standardOperationTable"
        @row-click="standardOperationClickRow"
        @selection-change="selectionStandardOperation"
        border
        style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50">
        </el-table-column>
        <el-table-column
          v-for="(item,index) in standardOperationColumnList" :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:35px;margin-top:10px;text-align:center">
        <el-button type="primary" @click="saveStandardOperation">保存</el-button>
        <el-button type="primary" @click="standardOperationModal = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- chooseList模态框 -->
    <ChooseList ref="baseList" @getBaseData="getBaseData"></ChooseList>
  </div>
</template>

<script>
import {
  routingManagementSearch, // routing 列表查询
  routingManagementSave, // routing 新增
  routingManagementEdit, // routing 编辑
  routingManagementDelete, // routing 删除
  queryRoutingHeader, // 查询 routing 主信息
  saveRoutingHeader, // 新增 routing 主信息
  queryRoutingDetail, // 查 routing 明细
  routingDetailSave, // routing 明细新增
  routingDetailUpdate, // routing 明细编辑
  updateAlternativeStatus, // 修改明细状态
  routingDetailDelete, // routing 明细删除
  queryPartList, // 查询物料清单
  queryPartListRouting, // 查出可创建Routing的物料
  queryRoutingComponent, // 查询 routing 子明细
  saveRoutingComponent, // 新增 routing 子明细
  updateRoutingComponent, // 修改 routing 子明细
  deleteRoutingComponent, // 删除 routing 子明细
  getRottingRevision, // 获取物料的 routing 版本号
  copyRouting, // 复制routing
  copyAlternative, // 复制alternative
  queryMaxOperationNo, // 查询最大工序号
  getStandardOperations, // 根据物料的商品组1查维护的标准工序
  saveStandardOperation, // 新增工序
} from '@/api/part/routingManagement.js'
import {verifyData} from '@/api/part/partInformation.js'
import {getSiteAndBuByUserName, getSiteAndBuByUserName2} from "@/api/qc/qc.js"
import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
import ChooseList from '@/views/modules/common/Chooselist_eam'

export default {
  // 组件
  components: {
    ChooseList
  },
  // 监听
  watch: {
    searchData: {
      deep: true,
      handler: function (newV, oldV) {
        this.searchData.partNo = this.searchData.partNo.toUpperCase()
      }
    },
    modalData: {
      deep: true,
      handler: function (newV, oldV) {
        this.modalData.partNo = this.modalData.partNo.toUpperCase()
      }
    },
    saveDetailData: {
      deep: true,
      handler: function (newV, oldV) {
        this.saveDetailData.alternativeNo = this.saveDetailData.alternativeNo.toUpperCase()
      }
    },
    copyAlternativeData: {
      deep: true,
      handler: function (newV, oldV) {
        this.copyAlternativeData.partNo = this.copyAlternativeData.partNo.toUpperCase()
      }
    },
    copyRoutingData: {
      deep: true,
      handler: function (newV, oldV) {
        this.copyRoutingData.partNo = this.copyRoutingData.partNo.toUpperCase()
      }
    },
    componentData: {
      deep: true,
      handler: function (newV, oldV) {
        this.componentData.workCenterNo = this.componentData.workCenterNo.toUpperCase()
        this.componentData.laborClassNo = this.componentData.laborClassNo.toUpperCase()
        this.componentData.setupLaborClassNo = this.componentData.setupLaborClassNo.toUpperCase()
      }
    },
  },
  // 对象
  data () {
    return {
      // 导出
      exportData: [],
      exportName: 'routing物料列表' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['routing物料列表'],
      exportFooter: [],
      resultList: [],
      userBuList: [],
      buList: [],
      // ======== 行高 ========
      height: 200,
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      pageIndex2: 1,
      pageSize2: 20,
      totalPage2: 0,
      pageIndex4: 1,
      pageSize4: 20,
      totalPage4: 0,
      selectedDataNum: 0,
      // 条件查询
      searchData: {
        site: '',
        userName: this.$store.state.user.name,
        partNo: '',
        partDesc: '',
        routingType:'',
        routingRevision:'',
        page: 1,
        limit: 10
      },
      // loading
      saveHeaderLoading: false,
      saveDetailLoading: false,
      saveAllLoading: false,
      copyLoading: false,
      alternativeLoading: false,
      // 初始页签
      detailTable: 'routing_detail',
      subDetailTable: 'routing_sub_detail',
      // ======== 数据对象 ========
      modalData: {
        flag: '',
        title: '',
        bu: '',
        site: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        routingRevision: '',
        routingType: '',
        noteText: '',
        phaseInDate: '',
        phaseOutDate: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
        printUnit: '',
        printUnitName: '',
      },
      detailData: {
        site: '',
        buNo: '',
        partNo: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        alternativeDescription: '',
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: '',
        status: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
      },
      componentData: {
        flag: '',
        site: '',
        buNo: '',
        partNo: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        operationId: '',
        operationNo: '',
        operationName: '',
        efficiencyFactor: '',
        machRunFactor: '',
        machSetupTime: '',
        machCycleTime: '',
        laborCycleTime: '',
        runTimeCode: '',
        laborRunFactor: '',
        laborSetupTime: '',
        crewSize: '',
        setupCrewSize: '',
        outsideOpItem: '',
        machineNo: '',
        workCenterNo: '',
        workCenterDesc: '',
        workCenterType: '',
        laborClassNo: '',
        laborClassDesc: '',
        setupLaborClassNo: '',
        setupLaborClassDesc: '',
        overlap: '',
        noteText: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
      },
      partData: {
        site: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10
      },
      operationData: {
        site: this.$store.state.user.site,
        partNo: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        operationNo: '',
        operationName: '',
      },
      saveDetailData: {
        flag: '',
        site: '',
        buNo: '',
        partNo: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        alternativeDescription: '',
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: '',
        status: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: ''
      },
      copyRoutingData: {
        site: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        routingRevision: '',
        routingType: '',
        phaseInDate: '',
        phaseOutDate: '',
        previousVersion: {},
        createBy: ''
      },
      copyAlternativeData: {
        site: '',
        partNo: '',
        partDesc: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        alternativeDescription: '',
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: '',
        status: '',
        previousVersion: {},
        createBy: ''
      },
      copyPartData: {
        type: '',
        site: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10
      },
      // ======== 数据列表 ========
      dataList: [],
      partList: [],
      operationList: [],
      componentPartSelections: [],
      subDetailList: [],
      detailDataList: [],
      checkedDetail: [],
      checkedTool: [],
      alternativeList: [],
      copyPartList: [],
      standardOperationList: [],
      standardOperationSelections: [],
      // ======== 列表表头 ========
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '601003Table1Bu',
          tableId: '601003Table1',
          tableName: 'Routing信息表',
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1PartNo',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1PartDesc',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1RoutingType',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'routingType',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工艺类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1RoutingRevision',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'routingRevision',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'Routing版本号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1CreateDate',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1CreateBy',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1UpdateDate',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table1UpdateBy',
          tableId: '104003Table1',
          tableName: 'Routing信息表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        }
      ],
      partColumnList: [
        {
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'partDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          columnProp: 'spec',
          headerAlign: "center",
          align: "left",
          columnLabel: '规格型号',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          columnProp: 'printUnitName',
          headerAlign: "center",
          align: "center",
          columnLabel: '计量单位',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'partType2',
          headerAlign: "center",
          align: "center",
          columnLabel: '零件类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        }
      ],
      componentOperationColumnList: [
        {
          columnProp: 'operationNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '工序编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnProp: 'operationName',
          headerAlign: "center",
          align: "center",
          columnLabel: '工序名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        }
      ],
      columnSubDetailList: [
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2OperationNo',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'operationNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工序编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2OperationName',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'operationName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '工序名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2RunTimeCodeDesc',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'runTimeCodeDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '产出单位',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2MachSetupTime',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'machSetupTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '机器调机时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2SetupCrewSize',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'setupCrewSize',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '调机过程人数',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2SetupLaborClassDesc',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'setupLaborClassDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '调机时人员等级',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2MachCycleTime',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'machCycleTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '机器处理时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2MachRunFactor',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'machRunFactor',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '机器单位产出',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2CrewSize',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'crewSize',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '生产过程人数',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2LaborClassNo',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'laborClassDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '人员等级',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2LaborSetupTime',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'laborSetupTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '人工调机时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2LaborCycleTime',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'laborCycleTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '人工处理时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2LaborRunFactor',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'laborRunFactor',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '人工单位产出',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2EfficiencyFactor',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'efficiencyFactor',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '效率%',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2WorkCenterNo',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'workCenterNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '加工中心编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2WorkCenterDesc',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'workCenterDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '加工中心名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '601003Table2WorkCenterType',
          tableId: '601003Table2',
          tableName: 'Routing工序表',
          columnProp: 'workCenterType',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '加工中心类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2OutsideOpItem',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'outsideOpItem',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '外协采购料号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601003,
          serialNumber: '104003Table2NoteText',
          tableId: '104003Table2',
          tableName: 'Routing工序表',
          columnProp: 'noteText',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
      ],
      columnRoutingDetailList: [
        {
          columnProp: 'alternativeNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '替代编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnProp: 'alternativeDescription',
          headerAlign: "center",
          align: "center",
          columnLabel: '替代名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnProp: 'status',
          headerAlign: "center",
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      componentPartColumnList: [
        {
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'partDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          columnProp: 'spec',
          headerAlign: "center",
          align: "center",
          columnLabel: '规格型号',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          columnProp: 'printUnitName',
          headerAlign: "center",
          align: "center",
          columnLabel: '计量单位',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'partType2',
          headerAlign: "center",
          align: "center",
          columnLabel: '零件类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        }
      ],
      standardOperationColumnList: [
        {
          columnProp: 'operationNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '工序编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          columnProp: 'operationName',
          headerAlign: "center",
          align: "left",
          columnLabel: '工序描述',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'setupCrewSize',
          headerAlign: "center",
          align: "right",
          columnLabel: '调机过程中人数',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'setupLaborClassNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '调机时人员等级编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'setupLaborClassDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '调机时人员等级描述',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'machCycleTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '机器处理时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'machRunFactor',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '机器单位产出',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'crewSize',
          headerAlign: "center",
          align: "right",
          columnLabel: '生产过程中人数',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'laborClassNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '人员等级编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'laborClassDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '人员等级描述',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'laborCycleTime',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '人工处理时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'laborRunFactor',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '人工单位产出',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'workCenterNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '加工中心编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          columnProp: 'workCenterDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '加工中心描述',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          columnProp: 'conditionDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '条件描述',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 200
        },
      ],
      // ======== 必填规则 ========
      rules: {
        partNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        partDesc: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        routingType: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        phaseInDate: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        routingRevision: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      detailRules: {
        alternativeNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        alternativeDescription: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        status: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      componentRules: {
        operationNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        operationName: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        workCenterNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        machSetupTime: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        laborSetupTime: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        setupLaborClassNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        setupCrewSize: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        machRunFactor: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        laborRunFactor: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        runTimeCode: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        laborClassNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        efficiencyFactor: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        crewSize: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      // ======== 复选数据集 ========
      routingSelections: [],
      // ======== 模态框开关控制 ========
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      modalFlag: false,
      modalDisableFlag: false,
      partModelFlag: false,
      saveDetailModalFlag: false,
      saveDetailModalDisable: false,
      componentSaveModal: false,
      componentDisableFlag: false,
      copyRoutingModelFlag: false,
      copyAlternativeModelFlag: false,
      headerSaveFlag: false,
      menuId: this.$route.meta.menuId,
      copyPartModelFlag: false,
      standardOperationModal: false
    }
  },

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

  created () {
    // 按钮控制
    this.getButtonAuthData()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName2()
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
    if (!this.authSearch) {
      // 获取数据列表
      this.getDataList()
    }
  },

  activated () {
    if (!this.authSearch) {
      if (this.$route.params.type === 'quote'){
        this.searchData.partNo = this.$route.params.partNo
        this.searchData.routingType = this.$route.params.routingType
        this.searchData.routingRevision = this.$route.params.routingRevision
      }else if (this.$route.params.partNo) {
        this.searchData.partNo = this.$route.params.partNo
      }
      this.getDataList()
    } else {
      this.$message.warning('无操作权限！')
    }
  },

  methods: {
    // bu改变事件
    userBuChange () {
      this.modalData.site = this.modalData.bu.split('_')[0]
      this.modalData.buNo = this.modalData.bu.split('_')[1]
    },

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

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

    // ======== 分页相关方法 ========
    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

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

    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle2 (val) {
      this.pageSize2 = val
      this.pageIndex2 = 1
      this.queryPartList()
    },

    /**
     * 当前页
     * @param val
     */
    currentChangeHandle2 (val) {
      this.pageIndex2 = val
      this.queryPartList()
    },

    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle4 (val) {
      this.pageSize4 = val
      this.pageIndex4 = 1
      this.queryCopyPartModal()
    },

    /**
     * 当前页
     * @param val
     */
    currentChangeHandle4 (val) {
      this.pageIndex4 = val
      this.queryCopyPartModal()
    },

    /**
     * copy物料列表
     */
    queryCopyPartModal () {
      this.copyPartData.limit = this.pageSize4
      this.copyPartData.page = this.pageIndex4
      this.copyPartData.site = this.modalData.site
      this.copyPartData.buNo = this.modalData.buNo
      // 查询所有物料
      queryPartList(this.copyPartData).then(({data}) => {
        if (data && data.code === 0) {
          this.copyPartList = data.page.list
          this.pageIndex4 = data.page.currPage
          this.pageSize4 = data.page.pageSize
          this.totalPage4 = data.page.totalCount
          this.copyPartModelFlag = true
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    /**
     * copy物料查询列表
     */
    queryCopyPartList () {
      this.copyPartData.limit = this.pageSize4
      this.copyPartData.page = this.pageIndex4
      // 查询所有物料
      queryPartList(this.copyPartData).then(({data}) => {
        if (data && data.code === 0) {
          this.copyPartList = data.page.list
          this.pageIndex4 = data.page.currPage
          this.pageSize4 = data.page.pageSize
          this.totalPage4 = data.page.totalCount
        } else {
          this.copyPartList = []
        }
      })
    },

    // copy物料编码失焦事件
    copyPartBlur () {
      if (this.copyPartData.type === '1') {
        if (this.copyRoutingData.partNo != null && this.copyRoutingData.partNo !== '') {
          this.copyPartData.limit = this.pageSize4
          this.copyPartData.page = this.pageIndex4
          this.copyPartData.partNo = this.copyRoutingData.partNo
          queryPartList(this.copyPartData).then(({data}) => {
            if (data && data.code === 0) {
              if (data.page.list.length === 1) {
                this.copyRoutingData.partDesc = data.page.list[0].partDesc
                return
              }
            }
          })
        }
        this.copyRoutingData.partDesc = ''
      } else {
        if (this.copyAlternativeData.partNo != null && this.copyAlternativeData.partNo !== '') {
          this.copyPartData.limit = this.pageSize4
          this.copyPartData.page = this.pageIndex4
          this.copyPartData.partNo = this.copyAlternativeData.partNo
          queryPartList(this.copyPartData).then(({data}) => {
            if (data && data.code === 0) {
              if (data.page.list.length === 1) {
                this.copyAlternativeData.partDesc = data.page.list[0].partDesc
                return
              }
            }
          })
        }
        this.copyAlternativeData.partDesc = ''
      }
    },

    // 双击选择copy物料
    getCopyRowData (row) {
      if (this.copyPartData.type === '1') {
        this.copyRoutingData.partNo = row.partNo
        this.copyRoutingData.partDesc = row.partDesc
        this.copyRoutingTypeChange()
      } else {
        this.copyAlternativeData.partNo = row.partNo
        this.copyAlternativeData.partDesc = row.partDesc
      }
      this.copyPartModelFlag = false
    },

    // copy BOM类型改变
    copyRoutingTypeChange () {
      // 获取物料的routing版本号
      getRottingRevision(this.copyRoutingData).then(({data}) => {
        if (data && data.code === 0) {
          this.copyRoutingData.routingRevision = data.routingRevision
        } else {
          this.copyRoutingData.routingRevision = ''
        }
      })
    },

    // ======== 列表数据操作方法 ========
    /**
     * 获取数据列表
     */
    getDataList () {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      routingManagementSearch(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          this.$refs.selectDiv.setLengthAll( this.dataList.length)
        }
      })
    },

    /**
     * 复选列表信息
     * @param val
     */
    selectionRouting (val) {
      this.routingSelections = val
      this.$refs.selectDiv.setLengthselected(this.routingSelections.length)
    },

    // ======== 新增/编辑模态框 ========
    /**
     * routing新增模态框
     */
    addModal () {
      this.modalData = {
        flag: '1',
        title: 'Routing新增',
        bu: this.userBuList[0].buNo,
        site: this.userBuList[0].buNo.split('_')[0],
        buNo: this.userBuList[0].buNo.split('_')[1],
        partNo: '',
        partDesc: '',
        routingRevision: undefined,
        routingType: 'Manufacturing',
        noteText: '',
        phaseInDate: new Date(+ new Date() + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''),
        phaseOutDate: '',
        createBy: this.$store.state.user.name,
        printUnit: '',
        printUnitName: '',
      }
      this.detailData = {
        site: '',
        buNo: '',
        partNo: '',
        routingRevision: '',
        routingType: '',
        alternativeNo: '',
        alternativeDescription: '',
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: '',
        status: '',
        createBy: this.$store.state.user.name,
      }
      this.detailTable = 'routing_detail'
      this.detailDataList = []
      this.subDetailList = []
      this.headerSaveFlag = true
      this.modalDisableFlag = false
      this.modalFlag = true
    },

    /**
     * routing编辑模态框
     */
    async updateModal (row) {
      this.modalData = {
        flag: '2',
        bu: row.site + '_' + row.buNo,
        site: row.site,
        buNo: row.buNo,
        partNo: row.partNo,
        partDesc: row.partDesc,
        routingRevision: row.routingRevision,
        routingType: row.routingType,
        noteText: row.noteText,
        phaseInDate: row.phaseInDate,
        phaseOutDate: row.phaseOutDate,
        engRevision: row.engRevision,
        typeFlag: row.typeFlag,
        netWeight: row.netWeight,
        updateBy: this.$store.state.user.name,
        printUnit: row.printUnit,
        printUnitName: row.printUnitName,
        alternativeNo: row.alternativeNo,
      }
      // 查routing明细
      queryRoutingDetail(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.detailDataList = data.rows.detailList
          this.subDetailList = data.rows.componentList
          this.detailData = data.rows.detailData
          this.detailTable = 'routing_detail'
          this.modalDisableFlag = true
          this.modalFlag = true
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    /**
     * 新增替代模态框
     */
    saveRoutingDetail () {
      if (this.modalData.partNo === '' || this.modalData.partNo == null) {
        this.$message.warning('请先选择Routing物料！')
        return
      }
      if (this.modalData.routingRevision === '' || this.modalData.routingRevision == null) {
        this.$message.warning('请先填写Routing版本号！')
        return
      }
      if (this.modalData.routingType === '' || this.modalData.routingType == null) {
        this.$message.warning('请先选择工艺类型！')
        return
      }
      this.saveDetailData = {
        flag: '1',
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        routingRevision: this.modalData.routingRevision,
        routingType: this.modalData.routingType,
        alternativeNo: '',
        alternativeDescription: '',
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: '',
        status: 'Tentative',
        createDate: '',
        createBy: this.$store.state.user.name,
      }
      // 查询routing主信息
      queryRoutingHeader(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          if (data.rows.length > 0) {
            this.saveDetailModalFlag = true
            this.saveDetailModalDisable = false
          } else {
            this.$message.warning('请先保存Routing主记录！')
          }
        } else {
          this.$alert(data.msg, '提示', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    /**
     * 替代编辑模态框
     */
    updateRoutingDetail () {
      if (this.modalData.partNo === '' || this.modalData.partNo == null) {
        this.$message.warning('请先选择Routing物料！')
        return
      }
      if (this.modalData.routingRevision === '' || this.modalData.routingRevision == null) {
        this.$message.warning('请先填写Routing版本号！')
        return
      }
      if (this.modalData.routingType === '' || this.modalData.routingType == null) {
        this.$message.warning('请先选择工艺类型！')
        return
      }
      this.saveDetailData = {
        flag: '2',
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        partNo: this.detailData.partNo,
        routingRevision: this.detailData.routingRevision,
        routingType: this.detailData.routingType,
        alternativeNo: this.detailData.alternativeNo,
        alternativeDescription: this.detailData.alternativeDescription,
        routTemplateId: this.detailData.routTemplateId,
        planDate: this.detailData.planDate,
        fixedLeadTimeDay: this.detailData.fixedLeadTimeDay,
        fixedLeadTimeHour: this.detailData.fixedLeadTimeHour,
        variableLeadTimeDay: this.detailData.variableLeadTimeDay,
        variableLeadTimeHour: this.detailData.variableLeadTimeHour,
        forStdLotByDay: this.detailData.forStdLotByDay,
        forLotByDay: this.detailData.forLotByDay,
        minLotQty: this.detailData.minLotQty,
        detailNoteText: this.detailData.detailNoteText,
        status: this.detailData.status,
        updateBy: this.$store.state.user.name,
      }
      // 查询routing主信息
      queryRoutingHeader(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          if (data.rows.length > 0) {
            this.saveDetailModalFlag = true
            this.saveDetailModalDisable = true
          } else {
            this.$message.warning('请先保存Routing主记录！')
          }
        } else {
          this.$alert(data.msg, '提示', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 基于标准工序快速创建
    createByStandardOperation () {
      if (this.detailData.alternativeNo === '' || this.detailData.alternativeNo == null) {
        this.$message.warning('请先选择替代！')
        return
      }
      // if (this.detailData.status != null && this.detailData.status !== '' && this.detailData.status !== 'Tentative') {
      //   this.$message.warning('不可编辑的替代状态!')
      //   return
      // }
      this.standardOperationSelections = []
      getStandardOperations(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.standardOperationList = data.rows
          this.standardOperationModal = true
        } else {
          this.$alert(data.msg, '提示', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 更新 Routing 的工序
    saveStandardOperation () {
      if (this.standardOperationSelections.length === 0) {
        this.$message.warning('请选择标准工序！')
        return
      }
      this.$confirm("是否确认更改替代下的工序?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let tempData = {
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          partNo: this.detailData.partNo,
          routingRevision: this.detailData.routingRevision,
          routingType: this.detailData.routingType,
          alternativeNo: this.detailData.alternativeNo,
          informationList: this.standardOperationSelections
        }
        saveStandardOperation(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.subDetailList = data.rows
            this.standardOperationModal = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '提示', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },

    /**
     * 新增子明细模态框
     */
    saveComponentModal () {
      if (this.detailData.alternativeNo === '' || this.detailData.alternativeNo == null) {
        this.$message.warning('请先选择替代！')
        return
      }
      // if (this.detailData.status != null && this.detailData.status !== '' && this.detailData.status !== 'Tentative') {
      //   this.$message.warning('不可编辑的替代状态!')
      //   return
      // }
      this.componentData = {
        flag: '1',
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        routingRevision: this.modalData.routingRevision,
        routingType: this.modalData.routingType,
        alternativeNo: this.detailData.alternativeNo,
        operationId: '',
        operationNo: '',
        operationName: '',
        efficiencyFactor: 100,
        machRunFactor: '',
        machSetupTime: '',
        runTimeCode: 'Units/Hour',
        laborRunFactor: '',
        laborSetupTime: '',
        crewSize: 1,
        setupCrewSize: 1,
        outsideOpItem: '',
        machineNo: '',
        workCenterNo: '',
        workCenterDesc: '',
        workCenterType: '',
        laborClassNo: '',
        laborClassDesc: '',
        setupLaborClassNo: '',
        setupLaborClassDesc: '',
        noteText: '',
        createBy: this.$store.state.user.name,
        machCycleTime: '',
        laborCycleTime: ''
      }
      this.queryMaxOperationNo()
      this.componentDisableFlag = false
      this.componentSaveModal = true
    },

    // 查询最大工序号
    queryMaxOperationNo () {
      queryMaxOperationNo(this.detailData).then(({data}) => {
        if (data && data.code === 0) {
          this.componentData.operationNo = data.operationNo
        }
      })
    },

    /**
     * 编辑模态框
     */
    updateComponentModal (row) {
      // if (this.detailData.status != null && this.detailData.status !== '' && this.detailData.status !== 'Tentative') {
      //   this.$message.warning('不可编辑的替代状态!')
      //   return
      // }
      this.componentData = {
        flag: '2',
        site: row.site,
        buNo: row.buNo,
        partNo: row.partNo,
        routingRevision: row.routingRevision,
        routingType: row.routingType,
        alternativeNo: row.alternativeNo,
        operationId: row.operationId,
        operationNo: row.operationNo,
        operationName: row.operationName,
        efficiencyFactor: row.efficiencyFactor,
        machRunFactor: row.machRunFactor,
        machSetupTime: row.machSetupTime,
        runTimeCode: row.runTimeCode,
        laborRunFactor: row.laborRunFactor,
        laborSetupTime: row.laborSetupTime,
        crewSize: row.crewSize,
        setupCrewSize: row.setupCrewSize,
        outsideOpItem: row.outsideOpItem,
        machineNo: row.machineNo,
        workCenterNo: row.workCenterNo,
        workCenterDesc: row.workCenterDesc,
        workCenterType: row.workCenterType,
        laborClassNo: row.laborClassNo,
        laborClassDesc: row.laborClassDesc,
        setupLaborClassNo: row.setupLaborClassNo,
        setupLaborClassDesc: row.setupLaborClassDesc,
        noteText: row.noteText,
        updateBy: this.$store.state.user.name,
        machCycleTime: row.machCycleTime,
        laborCycleTime: row.laborCycleTime
      }
      this.componentDisableFlag = true
      this.componentSaveModal = true
    },

    // ======== 新增/编辑/删除方法 ========
    /**
     * routing新增/编辑
     */
    saveData () {
      if (this.modalData.partNo === '' || this.modalData.partNo == null) {
        this.$message.warning('请选择物料编码！')
        return
      }
      if (this.modalData.partDesc === '' || this.modalData.partDesc == null) {
        this.$message.warning('请选择物料名称！')
        return
      }
      if (this.modalData.routingType === '' || this.modalData.routingType == null) {
        this.$message.warning('请选择制造类型！')
        return
      }
      if (this.modalData.phaseInDate === '' || this.modalData.phaseInDate == null) {
        this.$message.warning('请选择生效时间！')
        return
      }
      if (this.modalData.routingRevision === '' || this.modalData.routingRevision == null) {
        this.$message.warning('请填写Routing版本号！')
        return
      }
      if (this.detailData.alternativeNo === '' || this.detailData.alternativeNo == null) {
        this.$message.warning('请选择替代！')
        return
      }
      if (this.detailData.status === '' || this.detailData.status == null) {
        this.$message.warning('请选择替代状态！')
        return
      }
      let tempData = {
        site: this.$store.state.user.site,
        partNo: this.modalData.partNo,
        partDesc: this.modalData.partDesc,
        routingRevision: this.modalData.routingRevision,
        routingType: this.modalData.routingType,
        noteText: this.modalData.noteText,
        phaseInDate: this.modalData.phaseInDate,
        phaseOutDate: this.modalData.phaseOutDate,
        alternativeNo: this.detailData.alternativeNo,
        alternativeDescription: this.detailData.alternativeDescription,
        detailNoteText: this.detailData.detailNoteText,
        status: this.detailData.status,
        createBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
        informationList: this.subDetailList
      }
      if (this.modalData.flag === '1') {
        this.saveAllLoading = true
        routingManagementSave(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveAllLoading = false
        })
      } else {
        this.saveAllLoading = true
        routingManagementEdit(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveAllLoading = false
        })
      }
    },

    /**
     * 新增编辑模态框关闭
     */
    closeModal () {
      this.getDataList()
      this.modalFlag = false
    },

    /**
     * 新增编辑模态框关闭
     */
    closeModalX (done) {
      this.getDataList()
      done()
    },

    /**
     * routing删除
     */
    delModal () {
      if(this.routingSelections.length === 0){
        this.$message.warning('请勾选要删除的Routing！')
        return
      }
      this.$confirm(`是否删除这 `+ this.routingSelections.length +` 条Routing?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let tempData = {
          informationList: this.routingSelections
        }
        routingManagementDelete(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.routingSelections = []
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    /**
     * 查询物料
     */
    queryPartList () {
      this.partData.limit = this.pageSize2
      this.partData.page = this.pageIndex2
      this.partData.site = this.modalData.bu.split('_')[0]
      this.partData.buNo = this.modalData.bu.split('_')[1]
      queryPartListRouting(this.partData).then(({data}) => {
        if (data && data.code === 0) {
          this.partList = data.page.list
          this.pageIndex2 = data.page.currPage
          this.pageSize2 = data.page.pageSize
          this.totalPage2 = data.page.totalCount
          this.partModelFlag = true
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 物料编码失焦事件
    partNoBlur () {
      if (this.modalData.partNo != null && this.modalData.partNo !== '') {
        this.partData.limit = this.pageSize2
        this.partData.page = this.pageIndex2
        this.partData.partNo = this.modalData.partNo
        queryPartList(this.partData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.page.list.length === 1) {
              this.modalData.partDesc = data.page.list[0].partDesc
              this.modalData.printUnit = data.page.list[0].printUnit
              this.modalData.printUnitName = data.page.list[0].printUnitName
              // 获取物料的routing版本号
              getRottingRevision(this.modalData).then(({data}) => {
                if (data && data.code === 0) {
                  this.modalData.routingRevision = data.routingRevision
                } else {
                  this.modalData.routingRevision = ''
                }
              })
            } else {
              this.modalData.partDesc = ''
              this.modalData.printUnit = ''
              this.modalData.printUnitName = ''
              this.modalData.routingRevision = ''
            }
          }
        })
      } else {
        this.modalData.partDesc = ''
        this.modalData.printUnit = ''
        this.modalData.printUnitName = ''
        this.modalData.routingRevision = ''
      }
    },

    /**
     * 双击选中物料
     * @param row
     */
    getRowData (row) {
      this.modalData.partNo = row.partNo
      this.modalData.partDesc = row.partDesc
      this.modalData.printUnit = row.printUnit
      this.modalData.printUnitName = row.printUnitName
      // 获取物料的routing版本号
      getRottingRevision(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.modalData.routingRevision = data.routingRevision
        } else {
          this.modalData.routingRevision = ''
        }
        this.partModelFlag = false
      })
    },

    /**
     * 工艺类型改变
     */
    routingTypeChange () {
      // 获取物料的routing版本号
      getRottingRevision(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.modalData.routingRevision = data.routingRevision
        } else {
          this.modalData.routingRevision = ''
        }
      })
    },

    /**
     * 表格的新增
     * @param row
     * @param rowIndex
     */
    rowClassName({ row, rowIndex }) {
      row.xh = rowIndex + 1
    },

    /**
     * 单选框选中数据
     * @param selection
     */
    componentSelectionChange(selection) {
      this.checkedDetail = selection
    },

    /**
     * 删除子物料
     */
    deleteComponentPart () {
      // if (this.detailData.status != null && this.detailData.status !== '' && this.detailData.status !== 'Tentative') {
      //   this.$message.warning('不可编辑的替代状态!')
      //   return
      // }
      if (this.checkedDetail.length === 0) {
        this.$message.warning('请选择要删除子物料！')
        return
      } else {
        this.$confirm("请是否确认删除该子明细记录?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          let tempData = {
            informationList: this.checkedDetail
          }
          deleteRoutingComponent(tempData).then(({data}) => {
            if (data && data.code === 0) {
              this.subDetailList = data.rows
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      }
    },

    /**
     * 子物料
     * @param row
     */
    componentClickRow (row) {
      this.$refs.componentTable.toggleRowSelection(row)
    },

    /**
     * 新增子明细方法
     */
    componentDataSave (isClose) {
      if (this.componentData.partNo === '' || this.componentData.partNo == null) {
        this.$message.warning('请选择主记录物料编码！')
        return
      }
      if (this.componentData.routingType === '' || this.componentData.routingType == null) {
        this.$message.warning('请选择主记录工艺类型！')
        return
      }
      if (this.componentData.routingRevision === '' || this.componentData.routingRevision == null) {
        this.$message.warning('请填写主记录Routing版本号！')
        return
      }
      if (this.componentData.operationNo === '' || this.componentData.operationNo == null) {
        this.$message.warning('请填写工序编码！')
        return
      }
      if (this.componentData.operationName === '' || this.componentData.operationName == null) {
        this.$message.warning('请填写工序名称！')
        return
      }
      if (this.componentData.workCenterNo === '' || this.componentData.workCenterNo == null) {
        this.$message.warning('请选择加工中心！')
        return
      }
      if (this.componentData.machSetupTime === '' || this.componentData.machSetupTime == null) {
        this.$message.warning('请填写机器调机时间！')
        return
      }
      if (this.componentData.laborSetupTime === '' || this.componentData.laborSetupTime == null) {
        this.$message.warning('请填写人工调机时间！')
        return
      }
      if (this.componentData.setupLaborClassNo === '' || this.componentData.setupLaborClassNo == null) {
        this.$message.warning('请选择调机过程中人员等级！')
        return
      }
      if (this.componentData.setupCrewSize === '' || this.componentData.setupCrewSize == null) {
        this.$message.warning('请填写调机过程中人数！')
        return
      }
      if (this.componentData.machRunFactor === '' || this.componentData.machRunFactor == null) {
        this.$message.warning('请填写机器单位产出！')
        return
      }
      if (this.componentData.laborRunFactor === '' || this.componentData.laborRunFactor == null) {
        this.$message.warning('请填写人工单位产出！')
        return
      }
      if (this.componentData.runTimeCode === '' || this.componentData.runTimeCode == null) {
        this.$message.warning('请选择产出单位！')
        return
      }
      if (this.componentData.laborClassNo === '' || this.componentData.laborClassNo == null) {
        this.$message.warning('请选择人员等级！')
        return
      }
      if (this.componentData.efficiencyFactor === '' || this.componentData.efficiencyFactor == null) {
        this.$message.warning('请填写效率！')
        return
      }
      if (this.componentData.crewSize === '' || this.componentData.crewSize == null) {
        this.$message.warning('请填写生产过程中人数！')
        return
      }
      if (this.componentData.flag === '1') {
        saveRoutingComponent(this.componentData).then(({data}) => {
          if (data && data.code === 0) {
            this.subDetailList = data.rows
            if (isClose) {
              this.saveComponentModal()
            } else {
              this.componentSaveModal = false
            }
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else if (this.componentData.flag === '2') {
        updateRoutingComponent(this.componentData).then(({data}) => {
          if (data && data.code === 0) {
            this.subDetailList = data.rows
            this.componentSaveModal = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },

    /**
     * 回车事件
     */
    focusNextInput (index, type) {
      let aaa = ''
      if (this.subDetailList.length - 1 === index) {
        aaa = `${type}0`
      } else {
        aaa = `${type}${index + 1}`
      }
      this.$nextTick(() => {
        this.$refs[aaa].focus()
      })
    },

    /**
     * 保存主表信息
     */
    saveRoutingHeader () {
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      if (this.modalData.partNo === '' || this.modalData.partNo == null) {
        this.$message.warning('请先选择Routing物料！')
        return
      }
      if (this.modalData.routingRevision === '' || this.modalData.routingRevision == null) {
        this.$message.warning('请先填写Routing版本号！')
        return
      }
      if (this.modalData.routingType === '' || this.modalData.routingType == null) {
        this.$message.warning('请先选择制造类型！')
        return
      }
      if (this.modalData.phaseOutDate != null && this.modalData.phaseOutDate !== '' && (this.modalData.phaseInDate > this.modalData.phaseOutDate)) {
        this.$message.warning('失效日期不能小于生效日期！')
        return
      }
      this.saveHeaderLoading = true
      // 新增主表信息
      saveRoutingHeader(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.modalData = {
            flag: '1',
            title: 'routing新增',
            bu: data.rows.modalData.site + '_' + data.rows.modalData.buNo,
            site: data.rows.modalData.site,
            buNo: data.rows.modalData.buNo,
            partNo: data.rows.modalData.partNo,
            partDesc: data.rows.modalData.partDesc,
            routingRevision: data.rows.modalData.routingRevision,
            routingType: data.rows.modalData.routingType,
            noteText: data.rows.modalData.noteText,
            phaseInDate: data.rows.modalData.phaseInDate,
            phaseOutDate: data.rows.modalData.phaseOutDate,
            engRevision: data.rows.modalData.engRevision,
            typeFlag: data.rows.modalData.typeFlag,
            netWeight: data.rows.modalData.netWeight,
          }
          this.detailDataList = data.rows.detailDataList
          this.detailData = data.rows.detailData
          this.subDetailList = []
          this.headerSaveFlag = false
          this.modalDisableFlag = true
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
        this.saveHeaderLoading = false
      })
    },

    /**
     * 复制Routing的模态框
     */
    copyRoutingRevision () {
      this.copyRoutingData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        partDesc: this.modalData.partDesc,
        routingRevision: this.modalData.routingRevision + 1,
        routingType: this.modalData.routingType,
        phaseInDate: this.dayjs(new Date()).format('YYYY-MM-DD'),
        phaseOutDate: '',
        previousVersion: {},
        createBy: this.$store.state.user.name,
      }
      this.copyPartData = {
        type: '1',
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10
      }
      this.copyRoutingModelFlag = true
    },

    /**
     * 复制Routing的方法
     */
    copyRouting () {
      if (this.copyRoutingData.partNo === '' || this.copyRoutingData.partNo == null) {
        this.$message.warning('请选择Routing物料！')
        return
      }
      if (this.copyRoutingData.routingRevision === '' || this.copyRoutingData.routingRevision == null) {
        this.$message.warning('请填写Routing版本号！')
        return
      }
      if (this.copyRoutingData.routingType === '' || this.copyRoutingData.routingType == null) {
        this.$message.warning('请选择工艺类型！')
        return
      }
      this.copyRoutingData.previousVersion = this.modalData
      this.copyLoading = true
      // 新增主表信息
      copyRouting(this.copyRoutingData).then(({data}) => {
        if (data && data.code === 0) {
          this.copyRoutingModelFlag = false
          this.updateModal(data.rows)
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
        this.copyLoading = false
      }).catch(()=>{
        this.copyLoading = false
      })
    },

    /**
     * 复制alternative的模态框
     */
    copyRoutingAlternative () {
      this.copyAlternativeData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        partNo: this.detailData.partNo,
        partDesc: this.modalData.partDesc,
        routingRevision: this.detailData.routingRevision,
        routingType: this.detailData.routingType,
        alternativeNo: this.detailData.alternativeNo,
        alternativeDescription: this.detailData.alternativeDescription,
        routTemplateId: '',
        planDate: '',
        fixedLeadTimeDay: '',
        fixedLeadTimeHour: '',
        variableLeadTimeDay: '',
        variableLeadTimeHour: '',
        forStdLotByDay: '',
        forLotByDay: '',
        minLotQty: '',
        detailNoteText: this.detailData.detailNoteText,
        status: 'Tentative',
        previousVersion: {},
        createBy: this.$store.state.user.name
      }
      this.copyPartData = {
        type: '2',
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10
      }
      this.copyAlternativeModelFlag = true
    },

    /**
     * 复制alternative的方法
     */
    copyAlternative () {
      if (this.copyAlternativeData.partNo === '' || this.copyAlternativeData.partNo == null) {
        this.$message.warning('请选择Routing物料！')
        return
      }
      if (this.copyAlternativeData.routingRevision === '' || this.copyAlternativeData.routingRevision == null) {
        this.$message.warning('请填写Routing版本号！')
        return
      }
      if (this.copyAlternativeData.routingType === '' || this.copyAlternativeData.routingType == null) {
        this.$message.warning('请选择工艺类型！')
        return
      }
      if (this.copyAlternativeData.alternativeNo === '' || this.copyAlternativeData.alternativeNo == null) {
        this.$message.warning('请填写替代编码！')
        return
      }
      if (this.copyAlternativeData.alternativeDescription === '' || this.copyAlternativeData.alternativeDescription == null) {
        this.$message.warning('请填写替代名称！')
        return
      }
      this.copyAlternativeData.previousVersion = this.detailData
      this.copyLoading = true
      copyAlternative(this.copyAlternativeData).then(({data}) => {
        if (data && data.code === 0) {
          this.copyAlternativeModelFlag = false
          this.updateModal(data.rows)
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
        this.copyLoading = false
      }).catch(()=>{
        this.copyLoading = false
      })
    },

    /**
     * 新增替代方法
     */
    detailDataSave () {
      if (this.saveDetailData.partNo === '' || this.saveDetailData.partNo == null) {
        this.$message.warning('请先选择Routing物料！')
        return
      }
      if (this.saveDetailData.routingRevision === '' || this.saveDetailData.routingRevision == null) {
        this.$message.warning('请先填写Routing版本号！')
        return
      }
      if (this.saveDetailData.routingType === '' || this.saveDetailData.routingType == null) {
        this.$message.warning('请先选择工艺类型！')
        return
      }
      if (this.saveDetailData.alternativeNo === '' || this.saveDetailData.alternativeNo == null) {
        this.$message.warning('请填写替代编码！')
        return
      }
      if (this.saveDetailData.alternativeDescription === '' || this.saveDetailData.alternativeDescription == null) {
        this.$message.warning('请填写替代名称！')
        return
      }
      if (this.saveDetailData.status === '' || this.saveDetailData.status == null) {
        this.$message.warning('请选择替代状态！')
        return
      }
      this.saveDetailLoading = true
      if (this.saveDetailData.flag === '1') {
        routingDetailSave(this.saveDetailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailDataList = data.rows
            this.detailData = this.saveDetailData
            this.subDetailList = []
            this.saveDetailModalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveDetailLoading = false
        })
      } else {
        routingDetailUpdate(this.saveDetailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailDataList = data.rows.detailDataList
            this.detailData = data.rows.detailData
            this.subDetailList = data.rows.subDetailList
            this.saveDetailModalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveDetailLoading = false
        })
      }
    },

    /**
     * 删除替代
     */
    deleteRoutingDetail () {
      if (this.detailData.alternativeNo === '' || this.detailData.alternativeNo == null) {
        this.$message.warning('请选择要删除的替代编码！')
        return
      }
      if (this.detailData.alternativeNo === '*') {
        this.$message.warning('当前为默认替代，不可以删除！')
        return
      }
      this.$confirm(`是否删除这项替代?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        routingDetailDelete(this.detailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailData = data.rows.detailData
            this.detailDataList = data.rows.detailDataList
            this.subDetailList = data.rows.subDetailList
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },

    /**
     * 修改替代状态为 Buildable
     */
    updateStatusToBuildable () {
      this.$confirm(`是否修改状态为Buildable?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateAlternativeStatus(this.detailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailDataList = data.rows.detailDataList
            this.detailData = data.rows.detailData
            this.subDetailList = data.rows.subDetailList
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {confirmButtonText: '确定'})
            // 刷新替代和子明细
            this.alternativeChange()
          }
        })
      })
    },
    /**
     * 修改替代状态为 Obsolete
     */
    updateStatusToObsolete () {
      this.$confirm(`是否修改状态为Obsolete?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateAlternativeStatus(this.detailData).then(({data}) => {
          if (data && data.code === 0) {
            this.detailDataList = data.rows.detailDataList
            this.detailData = data.rows.detailData
            this.subDetailList = data.rows.subDetailList
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {confirmButtonText: '确定'})
            // 刷新替代和子明细
            this.alternativeChange()
          }
        })
      })
    },

    /**
     * 替代改变事件
     */
    alternativeChange () {
      this.alternativeLoading = true
      queryRoutingComponent(this.detailData).then(({data}) => {
        if (data && data.code === 0) {
          this.detailDataList = data.rows.detailDataList
          this.detailData = data.rows.detailData
          this.subDetailList = data.rows.subDetailList
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
        this.alternativeLoading = false
      }).catch(()=>{
        this.alternativeLoading = false
      })
    },

    // ======== chooseList相关方法 ========
    /**
     * 获取基础数据列表S
     * @param val
     * @param type
     */
    getBaseList (val, type) {
      this.tagNo = val
      this.tagNo1 = type
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        // if (this.modalData.bu === null || this.modalData.bu === '') {
        //   this.$message.warning("请选择BU!")
        //   return
        // } else {
        //   conSql = " and site = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no = '" + this.modalData.bu.split('_')[1] + "'"
        // }
        if (val === 517) {
          if (type === 1) {
            strVal = this.componentData.laborClassNo
          } else if (type === 2) {
            strVal = this.componentData.setupLaborClassNo
          }
        }
        if (val === 516) {
          conSql = ''
          strVal = this.componentData.workCenterNo
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    /**
     * 列表方法的回调
     * @param val
     */
    getBaseData (val) {
      if (this.tagNo === 517) {
        if (this.tagNo1 === 1) {
          this.componentData.laborClassNo = val.class_no
          this.componentData.laborClassDesc = val.class_desc
        } else if (this.tagNo1 === 2) {
          this.componentData.setupLaborClassNo = val.class_no
          this.componentData.setupLaborClassDesc = val.class_desc
        }
      }
      if (this.tagNo === 516) {
        this.componentData.workCenterNo = val.work_center_no
        this.componentData.workCenterDesc = val.work_center_desc
        this.componentData.workCenterType = val.work_center_type
      }
    },

    // 机器调机时间改变
    changeMachSetupTime () {
      this.componentData.laborSetupTime = this.componentData.machSetupTime
    },

    // 机器单位产出改变
    changeMachRunFactor () {
      this.componentData.laborRunFactor = this.componentData.machRunFactor
    },

    // 机器处理时间改变
    changeMachCycleTime () {
      // 人工处理时间赋值
      this.componentData.laborCycleTime = this.componentData.machCycleTime
      // 计算机器单位产出
      if (this.componentData.machCycleTime != 0) {
        this.componentData.machRunFactor = 1/this.componentData.machCycleTime
      } else {
        this.componentData.machRunFactor = 0
      }
      // 人工单位产出赋值
      this.componentData.laborRunFactor = this.componentData.machRunFactor
    },

    // 人工处理时间改变
    changeLaborCycleTime () {
      // 计算人工单位产出
      if (this.componentData.laborCycleTime == 0) {
        this.componentData.laborRunFactor = 0
      } else {
        this.componentData.laborRunFactor = 1/this.componentData.laborCycleTime
      }
    },

    // 加工中心输入校验
    workCenterBlur (tagNo) {
      if (this.componentData.workCenterNo != null && this.componentData.workCenterNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and work_center_no = '" + this.componentData.workCenterNo + "'" + " and site  = '" + this.modalData.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.componentData.workCenterNo = data.baseListData[0].work_center_no
              this.componentData.workCenterDesc = data.baseListData[0].work_center_desc
              this.componentData.workCenterType = data.baseListData[0].work_center_type
              return
            }
          }
        })
      }
      this.componentData.workCenterDesc = ''
      this.componentData.workCenterType = ''
    },

    // 人员等级
    setupLaborClassBlur (tagNo) {
      if (this.componentData.setupLaborClassNo != null && this.componentData.setupLaborClassNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and class_no = '" + this.componentData.setupLaborClassNo + "'" + " and site  = '" + this.modalData.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.componentData.setupLaborClassNo = data.baseListData[0].class_no
              this.componentData.setupLaborClassDesc = data.baseListData[0].class_desc
              return
            }
          }
        })
      }
      this.componentData.setupLaborClassDesc = ''
    },

    // 人员等级
    laborClassBlur (tagNo) {
      if (this.componentData.laborClassNo != null && this.componentData.laborClassNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and class_no = '" + this.componentData.laborClassNo + "'" + " and site  = '" + this.modalData.site + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.componentData.laborClassNo = data.baseListData[0].class_no
              this.componentData.laborClassDesc = data.baseListData[0].class_desc
              return
            }
          }
        })
      }
      this.componentData.laborClassDesc = ''
    },

    // 点击行选中复选框
    standardOperationClickRow (row) {
      this.$refs.standardOperationTable.toggleRowSelection(row)
    },

    // 复选信息
    selectionStandardOperation (val) {
      this.standardOperationSelections = val
    },

    // ======== 导出相关方法 ========
    /**
     * 导出excel
     */
    async createExportData () {
      this.searchData.limit = -1
      this.searchData.page = 1
      await routingManagementSearch(this.searchData).then(({data}) => {
        this.resultList = data.page.list
      })
      return this.resultList
    },

    startDownload () {},

    finishDownload () {},

    fields () {
      let json = '{'
      this.columnList.forEach((item, index) => {
        if (index == this.columnList.length - 1) {
          json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"'
        } else {
          json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"' + ','
        }
      })
      json += '}'
      let s = eval('(' + json + ')')
      return s
    },

    // 动态列开始 获取 用户保存的 格式列
    async getTableUserColumn(tableId, columnId) {
      let queryTableUser = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        status: true,
        languageCode: this.$i18n.locale
      }
      await getTableUserListLanguage(queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
          }
        } else {
          this.getColumnList(tableId, columnId)
        }
      })
    },

    // 获取 tableDefault 列
    async getColumnList (tableId, columnId) {
      let queryTable= {
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        languageCode: this.$i18n.locale
      }
      await getTableDefaultListLanguage(queryTable).then(({data}) => {
        if (!data.rows.length === 0) {
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
          }
        }
      })
    },

    //获取按钮的权限数据
    getButtonAuthData () {
      let searchFlag = this.isAuth(this.menuId+":search")
      let saveFlag = this.isAuth(this.menuId+":save")
      let updateFlag = this.isAuth(this.menuId+":update")
      let deleteFlag = this.isAuth(this.menuId+":delete")
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authSave = !saveFlag
      this.authUpdate = !updateFlag
      this.authDelete = !deleteFlag
    },

    // 切换到Bom
    checkOutToBom (partNo) {
      if (this.$router.resolve('part-bomManagement').resolved.name === '404') {
        this.$alert('权限不足,访问失败', '警告', {confirmButtonText: '确定',})
      } else {
        this.$router.push({name:"part-bomManagement",params:{partNo: partNo}})
      }
    }
  }
}
</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
}
/deep/ .detail-tab .el-tabs__content {
  height: 165px;
  padding: 15px 0px 0px 0px;
}
/deep/ .sub_detail-tab .el-tabs__content {
  height: 280px;
  padding: 0px;
}
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>










