<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -5px;">
      <el-form-item :label="labels.workCenterNo">
        <el-input v-model="modelData.workCenterNo"  readonly style="width: 130px"></el-input>
        <el-button @click="getData()" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.search}}</el-button>
      </el-form-item>
      <el-form-item :label="labels.workCenterDesc">
        <el-input v-model="modelData.workCenterDesc" readonly style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="labels.site">
        <el-input v-model="modelData.site" readonly style="width: 130px"></el-input>
      </el-form-item>
      <el-form-item :label="labels.active">
        <el-input v-model="modelData.active" readonly style="width: 40px"></el-input>
        <el-button @click="addModal()" type="primary" :disabled = "authAdd" style="margin-left: 2px;margin-top: 0px">{{buttons.add}}</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">
          {{ buttons.download }}
        </download-excel>
        <download-excel
          :fields="fields2()"
          :data="exportData2"
          type="xls"
          :name="exportName2"
          :header="exportHeader2"
          :footer="exportFooter2"
          :fetch="createExportData2"
          :before-generate="startDownload2"
          :before-finish="finishDownload2"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ buttons.download2 }}
        </download-excel>
      </el-form-item>
    </el-form>
    <el-tabs v-model="activeName" >
      <el-tab-pane :label="labels.base" name="first">
        <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
          <el-form-item :label="labels.workCenterType">
            <el-input v-model="modelData.workCenterType" readonly style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="labels.proLineNo">
            <el-input v-model="modelData.proLineNo" readonly style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="labels.productionLineDesc">
            <el-input v-model="modelData.productionLineDesc" readonly style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="labels.canCreateNewRollFlag">
            <el-input v-model="modelData.canCreateNewRollFlag" readonly style="width: 40px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -5px;">
          <el-form-item :label="labels.createdDate">
            <el-input v-model="modelData.createdDate" readonly style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="labels.remark">
            <el-input v-model="modelData.remark" readonly style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="labels.needSetupFlag">
            <el-input v-model="modelData.needSetupFlag" readonly style="width: 40px"></el-input>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane :label="labels.partInvolved" name="second">
        <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
          <el-button @click="getPartDetail()" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.partInfo}}</el-button>
        </el-form>
        <el-table
          :height="height"
          :data="dataList"
          border
          @row-click="clickData"
          highlight-current-row
          v-loading="dataListLoading"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                                 style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane :label="labels.resource2" name="third">
        <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
          <el-button @click="jumpCalendar()" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.jumpCalendar}}</el-button>
          <el-button @click="addResource()" v-if="!authAdd" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.add}}</el-button>
          <el-button @click="editResource()" v-if="!authEdit" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.update}}</el-button>
          <el-button @click="deleteCalendar()" v-if="!authDelete" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.delete}}</el-button>
          <el-button @click="setResource()" type="primary" style="margin-left: 2px;margin-top: 0px">{{buttons.setResource}}</el-button>
          <el-button @click="uploadSOP()" type="primary" style="margin-left: 2px;margin-top: 0px">上传SOP</el-button>
        </el-form>
        <el-table
          :height="height"
          :data="dataList2"
          border
          @row-click="clickData2"
          highlight-current-row
          v-loading="dataListLoading"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList2" :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-tab-pane>
    </el-tabs>
    <el-dialog :title="labels.dataList" :close-on-click-modal="false" v-drag :visible.sync="modelFlag2" width="680px" >
      <el-table
        height="400"
        :data="dataList3"
        border
        @row-dblclick="tableHanddle"
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          header-align="center"
          align="center"
          width="80"
          :label="labels.do">
          <template slot-scope="scope">
            <a type="text" size="small" v-if="!authEdit" @click="editModel(scope.row)">{{buttons.update}}</a>
            <a type="text" size="small" v-if="!authDelete" @click="deleteData(scope.row)">{{buttons.delete}}</a>
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item,index) in columnList3" :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"
          :width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="modelFlag2 = false">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog :title="labels.workCenter" :close-on-click-modal="false" v-drag :visible.sync="modelFlag" width="619px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.workCenterNo">
          <el-input v-model="modelData2.workCenterNo"   style="width: 130px" onblur="this.value=this.value.toUpperCase()"></el-input>
        </el-form-item>
        <el-form-item :label="labels.workCenterDesc">
          <el-input v-model="modelData2.workCenterDesc" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.site">
          <el-input v-model="modelData2.site" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.active">
          <el-select filterable v-model="modelData2.active" style="width: 130px">
            <el-option label="Y" value="Y"></el-option>
            <el-option label="N" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.workCenterType">
          <el-select filterable v-model="modelData2.workCenterType" style="width: 130px">
            <el-option :label="labels.inner" value="内部"></el-option>
            <el-option :label="labels.outer" value="外部"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(25)"><a herf="#">{{labels.proLineNo}}</a></span>
          <el-input v-model="modelData2.proLineNo" @change="getProLineNo" style="width: 130px" onblur="this.value=this.value.toUpperCase()"></el-input>
        </el-form-item>
        <el-form-item :label="labels.productionLineDesc">
          <el-input v-model="modelData2.productionLineDesc" disabled style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.canCreateNewRollFlag">
          <el-select filterable v-model="modelData2.canCreateNewRollFlag" style="width: 130px">
            <el-option label="Y" value="Y"></el-option>
            <el-option label="N" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.createdDate">
          <el-date-picker
            style="width: 130px"
            v-model="modelData2.createdDate"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="labels.remark">
          <el-input v-model="modelData2.remark" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.needSetupFlag">
          <el-select filterable v-model="modelData2.needSetupFlag" style="width: 130px">
            <el-option label="Y" value="Y"></el-option>
            <el-option label="N" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="ModelSave()">{{buttons.save}}</el-button>
        <el-button type="primary" @click="modelFlag = false">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog :title="labels.resource" :close-on-click-modal="false" v-drag :visible.sync="modelFlag3" width="460px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.workCenterNo">
          <el-input v-model="modelData3.workCenterNo"  disabled style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="labels.site">
          <el-input v-model="modelData3.site" disabled style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="labels.resourceID">
          <el-input v-model="modelData3.resourceID"  :disabled="model3InputFlag" style="width: 130px" onblur="this.value=this.value.toUpperCase()"></el-input>
        </el-form-item>
        <el-form-item :label="labels.resourceDesc">
          <el-input v-model="modelData3.resourceDesc" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.efficiency">
          <el-input v-model="modelData3.efficiency" type="number" style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="labels.utilization">
          <el-input v-model="modelData3.utilization" type="number" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.active">
          <el-select filterable v-model="modelData3.active" style="width: 130px">
            <el-option label="Y" value="Y"></el-option>
            <el-option label="N" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <span slot="label" style="" @click="getBaseList(91)"><a herf="#">{{labels.calendarID}}</a></span>
          <el-input v-model="modelData3.calendarID"  style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="labels.remark">
          <el-input v-model="modelData3.remark" style="width: 420px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="ResourceSave()">{{buttons.save}}</el-button>
        <el-button type="primary" @click="modelFlag3 = false">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog :title="labels.partNo2" :close-on-click-modal="false" v-drag :visible.sync="partFlag" width="630px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.partNo">
          <el-input v-model="partData.partNo" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.partDescription">
          <el-input v-model="partData.partDescription" readonly style="width: 260px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.site">
          <el-input v-model="partData.site" readonly style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.createDate">
          <el-input v-model="partData.createDate" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.umid">
          <el-input v-model="partData.umid" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.active" style="margin-left: 130px">
          <el-input v-model="partData.active" readonly style="width: 130px;"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.configurationTemplateID">
          <el-input v-model="partData.configurationTemplateID" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.remark2">
          <el-input v-model="partData.remark" readonly style="width: 260px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="partFlag = false">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="上传机器SOP" :close-on-click-modal="false" v-drag :visible.sync="uploadSOPFlag" width="630px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.workCenterNo">
          <el-input v-model="sopModelData.workCenterNo" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.workCenterDesc">
          <el-input v-model="sopModelData.workCenterDesc" disabled style="width: 260px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.resourceID">
          <el-input v-model="sopModelData.resourceID" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.resourceDesc">
          <el-input v-model="sopModelData.resourceDesc" disabled style="width: 260px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="版本号">
          <el-input v-model="sopModelData.versionNumber" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item label="生效日期" prop="effectiveDate" :rules="rules.effectiveDate">
          <el-date-picker
            style="width: 123px"
            v-model="sopModelData.effectiveDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="失效日期">
          <el-date-picker
            style="width: 123px"
            v-model="sopModelData.expiryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 5px;">
        <el-form-item label="">
          <a href="javascript:void(0);" @click="triggerUpload">SOP文件(点击上传)</a>
          <tr></tr>
          <el-input v-model="this.fileName" readonly placeholder="文件名称" style="width: 391px"></el-input>
          <el-button type="primary" @click="uploadSOPSave">保存</el-button>
          <el-upload class="custom-upload" :file-list="fileList"
                     action="javascript:void(0);" ref="uploadFile"
                     :on-change="onChange" :on-close="closeFileUpdate"
                     multiple :auto-upload="false"
                     style="text-align: left;margin-top: 0px;margin-left: 6px;display: none;">
          </el-upload>
        </el-form-item>
      </el-form>
      <el-table
        :height="height - 200"
        :data="sopFileList"
        border
        highlight-current-row
        v-loading="dataListLoading"
        style="width: 100%;margin-top: 17px">
        <el-table-column
          v-for="(item,index) in columnSopFileList" :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="80"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" @click="updateSOPFile(scope.row)">编辑</a>
            <a type="text" size="small" @click="deleteSOPFile(scope.row)">删除</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer  style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="closeUploadFileVisible()">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="编辑机器SOP" :close-on-click-modal="false" v-drag :visible.sync="uploadSOPEditFlag" width="427px" >
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.workCenterNo">
          <el-input v-model="sopUpdateModelData.workCenterNo" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.workCenterDesc">
          <el-input v-model="sopUpdateModelData.workCenterDesc" disabled style="width: 260px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="labels.resourceID">
          <el-input v-model="sopUpdateModelData.resourceID" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item :label="labels.resourceDesc">
          <el-input v-model="sopUpdateModelData.resourceDesc" disabled style="width: 260px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="版本号">
          <el-input v-model="sopUpdateModelData.versionNumber" disabled style="width: 116px"></el-input>
        </el-form-item>
        <el-form-item label="生效日期" prop="effectiveDate" :rules="rules.effectiveDate">
          <el-date-picker
            style="width: 123px"
            v-model="sopUpdateModelData.effectiveDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="失效日期">
          <el-date-picker
            style="width: 123px"
            v-model="sopUpdateModelData.expiryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 5px;">
        <el-form-item label="SOP文件">
          <el-input v-model="this.fileName" disabled placeholder="文件名称" style="width: 391px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer  style="height:30px;margin-top: 3px;text-align:center">
        <el-button type="primary" @click="updateSopFile">保存</el-button>
        <el-button type="primary" @click="closeUploadFileEditVisible()">{{buttons.close}}</el-button>
      </el-footer>
    </el-dialog>

      <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>


  </div>
</template>

<script>
import {
  saveTableDefaultList,
  getTableDefaultListLanguage,
  getTableUserListLanguage,
  removerDefault,
  removerUser
} from "@/api/table.js"
import {
  getWorkCenterData,
  getWorkCenterDataDetail,
  getProLineNoDetail,
  saveWorkCenterData,
  deleteWorkCenterData,
  saveResource,
  deleteResource,
  setResourceFlag,
  sopFileListSearch,
  deleteSOPFile,
}from "@/api/base/site.js"
import {
  searchPartNoData,
} from "@/api/base/site.js"
import Chooselist from '@/views/modules/common/Chooselist'
import {

  searchFunctionButtonList,

} from "@/api/sysLanguage.js"
import {uploadSOPFile,sopFileEdit} from "../../../api/base/site";
var functionId='103004';

export default {
  //加工中心
  name: "workCenter",
  components: {
    Chooselist
  },
  data() {
    return {
      visible: false,
      queryTable: {
        functionId: this.$route.meta.menuId,
        tableId: "mainTable",
        languageCode: this.$i18n.locale
      },
      // 用户table 查询参数
      queryTableUser: {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: "mainTable",
        status: true,
        languageCode: this.$i18n.locale
      },

      labels: {
        workCenterNo:'加工中心编码:',
        workCenterDesc:'名称:',
        site:'工厂编号:',
        active:'是否在用:',
        base:'基本信息',
        workCenterType:'加工中心类型:',
        proLineNo:'生产线编码:',
        productionLineDesc:'生产线名称:',
        canCreateNewRollFlag:'是否可以创建新卷:',
        createdDate:'新增日期:',
        remark:'备注:',
        needSetupFlag:'生产是否需要调机:',
        partInvolved:'涉及产品',
        dataList:'数据表',
        workCenter:'加工中心',
        inner:'内部',
        outer:'外部',
        chooseDate:'选择日期',
        resource:'机台维护',
        resourceID:'机台编码:',
        resourceDesc:'机台名称:',
        efficiency:'效率:',
        utilization:'利用率:',
        calendarID:'工作日历编码:',
        partNo:'物料编码:',
        partNo2:'物料编码',
        partDescription:'物料名称:',
        createDate:'新增日期:',
        umid:'计量单位:',
        configurationTemplateID:'客户名称:',
        remark2:'客户产品料号:',
        resource2:'机台',
        do:'操作',
        error:'错误',
        true:'确定',
        point:'提示',
        cancel:'取消',
        doYes:'操作成功',
        resourceIn:'请选择机台！',
        workCenterNoChoose:'请先选择加工中心！',
        resourceIDIn:'请输入机台编码！',
        resourceDescIn:'请输入机台名称！',
        efficiencyIn:'请输入效率！',
        utilizationIn:'请输入利用率！',
        activeIn:'请输入是否在用！',
        calendarIDIn:'请输入工作日编码！',
        virturlFlagAsk1:'是否将该机台设为虚拟机台？',
        virturlFlagAsk2:'是否将该机台设为常规机台？',
        deleteResourceAsk:'是否删除此机台?',
        rollIn:'请选择卷！',
        partNot:'该物料编码不存在',
        workCenterNoIn:'请输入加工中心编码！',
        workCenterDescIn:'请输入加工中心名称！',
        siteIn:'请输入工厂编码！',
        createdDateIn:'请选择新增日期！',
        workCenterDeleteAsk:'是否删除此加工中心',

      },
      buttons:{
        search:'查询',
        download:'导出',
        list:'列表',
        add:'新增',
        partInfo:'物料信息',
        jumpCalendar:'工作日历',
        update:'编辑',
        delete:'删除',
        setResource:'设为虚拟/常规机台',
        close:'关闭',
        save:'保存',
        download2:'导出机台'

      },
      rules: {
        effectiveDate: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      queryButton: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      },
      queryLabel: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'label'
      },
      tagNo:'',
      currentRow:null,
      partFlag:false,
      partData:{
        partNo:'',
        partDescription:'',
        site:'',
        createDate:'',
        umid:'',
        active:'',
        configurationTemplateID:'',
        modelFlag:'',
      },
      model3InputFlag:false,
      currentRow2:null,
      // 导出 start
      exportData: [],
      exportName: "加工中心涉及产品"+this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["加工中心涉及产品"],
      exportFooter: [],
      // 导出 end
      // 导出 start
      exportData2: [],
      exportName2: "加工中心机台"+this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader2: ["加工中心机台"],
      exportFooter2: [],
      // 导出 end
      activeName:'first',
      height: 200,
      modelFlag3:false,
      modelFlag2:false,
      modelFlag:false,
      modelInputFlag:true,
      fileName:'',
      uploadSOPFlag:false,
      uploadSOPEditFlag:false,
      uploadSOPDisableFlag:true,
      sopFileList:[],
      fileList:[],
      sopModelData:{
        flag:'',
        id : '',
        workCenterNo:'',
        workCenterDesc: '',
        site:'',
        resourceID:'',
        resourceDesc:'',
        versionNumber:'',
        effectiveDate:'',
        expiryDate:'',
      },
      sopUpdateModelData:{
        flag:'',
        id : '',
        workCenterNo:'',
        workCenterDesc: '',
        site:'',
        resourceID:'',
        resourceDesc:'',
        versionNumber:'',
        effectiveDate:'',
        expiryDate:null,
      },
      selectList:[],
      modelData: {
        add:'',
        workCenterNo:'',
        workCenterDesc:'',
        site:'',
        active:'',
        workCenterType:'',
        proLineNo:'',
        productionLineDesc:'',
        canCreateNewRollFlag:'',
        createdDate:'',
        remark:'',
        needSetupFlag:'',
        user:this.$store.state.user.name,
      },
      modelData2: {
        add:'',
        workCenterNo:'',
        workCenterDesc:'',
        site:'',
        active:'',
        workCenterType:'',
        proLineNo:'',
        productionLineDesc:'',
        canCreateNewRollFlag:'',
        createdDate:'',
        remark:'',
        needSetupFlag:'',
        user:this.$store.state.user.name,
      },
      modelData3:{
        workCenterNo:'',
        site:'',
        resourceID:'',
        resourceDesc:'',
        efficiency:'',
        utilization:'',
        active:'',
        calendarID:'',
        remark:'',

        add:'',
      },
      dataList:[],
      dataList2:[],
      dataList3:[],

      dataListLoading: false,

      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TablePartNo',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "partNo",
          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: 103004,
          serialNumber: '103004TableRevNo',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "revNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "版本号",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableItemNo',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "itemNo",
          headerAlign: "center",
          align: "right",
          columnLabel: "工序号",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableOperationDesc',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "operationDesc",
          headerAlign: "center",
          align: "left",
          columnLabel: "工序名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableMachSetuptime',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          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: 103004,
          serialNumber: '103004TableMachRunFactor',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          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: 103004,
          serialNumber: '103004TableFactorUnit',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "factorUnit",
          headerAlign: "center",
          align: "left",
          columnLabel: "产出类型",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableCrewsize',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          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: 103004,
          serialNumber: '103004TableEfficiency',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "efficiency",
          headerAlign: "center",
          align: "right",
          columnLabel: "效率",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 50
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableStatus',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "status",
          headerAlign: "center",
          align: "left",
          columnLabel: "状态",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 50
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableRoutingType',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "routingType",
          headerAlign: "center",
          align: "left",
          columnLabel: "工序类别",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004TableRemark',
          tableId: "103004Table",
          tableName: "加工中心涉及产品表",
          columnProp: "remark",
          headerAlign: "center",
          align: "left",
          columnLabel: "备注",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        }
      ],
      columnList2: [
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table2ResourceID',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "resourceID",
          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: 103004,
          serialNumber: '103004Table2ResourceDesc',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "resourceDesc",
          headerAlign: "center",
          align: "left",
          columnLabel: "机台名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table2Efficiency',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "efficiency",
          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: 103004,
          serialNumber: '103004Table2Utilization',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "utilization",
          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: 103004,
          serialNumber: '103004Table2Active',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "active",
          headerAlign: "center",
          align: "left",
          columnLabel: "在用",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table2CreatedDate',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "createdDate",
          headerAlign: "center",
          align: "left",
          columnLabel: "新增日期",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table2Remark',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "remark",
          headerAlign: "center",
          align: "left",
          columnLabel: "备注",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 400
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table2CalendarID',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "calendarID",
          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: 103004,
          serialNumber: '103004Table2VirturlFlag',
          tableId: "103004Table2",
          tableName: "加工中心涉及机台表",
          columnProp: "virturlFlag",
          headerAlign: "center",
          align: "left",
          columnLabel: "虚拟机台",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        }
      ],
      columnList3: [
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table3WorkCenterNo',
          tableId: "103004Table3",
          tableName: "加工中心表",
          columnProp: "workCenterNo",
          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: 103004,
          serialNumber: '103004Table3WorkCenterDesc',
          tableId: "103004Table3",
          tableName: "加工中心表",
          columnProp: "workCenterDesc",
          headerAlign: "center",
          align: "left",
          columnLabel: "加工中心名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table3WorkCenterType',
          tableId: "103004Table3",
          tableName: "加工中心表",
          columnProp: "workCenterType",
          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: 103004,
          serialNumber: '103004Table3Active',
          tableId: "103004Table3",
          tableName: "加工中心表",
          columnProp: "active",
          headerAlign: "center",
          align: "left",
          columnLabel: "在用",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 40
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table3Site',
          tableId: "103004Table3",
          tableName: "加工中心表",
          columnProp: "site",
          headerAlign: "center",
          align: "left",
          columnLabel: "工厂编号",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        }
      ],
      columnSopFileList:[
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table4VersionNumber',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "versionNumber",
          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: 103004,
          serialNumber: '103004Table4FileName',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "fileName",
          headerAlign: "center",
          align: "left",
          columnLabel: "文件名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103004,
          serialNumber: '103004Table4CreatedBy',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "createdBy",
          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: 103004,
          serialNumber: '103004Table4CreateDate',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "createDate",
          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: 103004,
          serialNumber: '103004Table4EffectiveDate',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "effectiveDate",
          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: 103004,
          serialNumber: '103004Table4ExpiryDate',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "expiryDate",
          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: 103004,
          serialNumber: '103004Table4Status',
          tableId: "103004Table3",
          tableName: "SOP文件表",
          columnProp: "status",
          headerAlign: "center",
          align: "center",
          columnLabel: "状态",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
      ],
      authEdit: false,
      authAdd: false,
      authDelete: false,
      menuId: this.$route.meta.menuId,
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - 225;
    })
  },
  watch: {
    '$route' (to, from) {
      if(localStorage.getItem('workCenterNo')!=undefined){
        this.jump();
      }
    },
    modelData2: {
      deep: true,
      handler: function (newV, oldV) {
        this.modelData2.proLineNo = this.modelData2.proLineNo.toUpperCase()
        this.modelData2.workCenterNo = this.modelData2.workCenterNo.toUpperCase()
      }
    },
    modelData3: {
      deep: true,
      handler: function (newV, oldV) {
        this.modelData3.resourceID = this.modelData3.resourceID.toUpperCase()
        this.modelData3.calendarID = this.modelData3.calendarID.toUpperCase()
      }
    },
  },
  methods: {
    editResource(){
      if(this.currentRow2==null){
        this.$alert(this.labels.resourceIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      this.modelData3={
        workCenterNo:this.modelData.workCenterNo,
        site:this.modelData.site,
        resourceID:this.currentRow2.resourceID,
        resourceDesc:this.currentRow2.resourceDesc,
        efficiency:this.currentRow2.efficiency,
        utilization:this.currentRow2.utilization,
        active:this.currentRow2.active,
        calendarID:this.currentRow2.calendarID,
        remark:this.currentRow2.remark,
        add:1,
      };
      this.model3InputFlag=true;
      this.modelFlag3=true;
    },
    addResource(){
      if(this.modelData.workCenterNo==''||this.modelData.workCenterNo==null){
        this.$alert(this.labels.workCenterNoChoose,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }

      this.modelData3={
        workCenterNo:this.modelData.workCenterNo,
        site:this.modelData.site,
        resourceID:'',
        resourceDesc:'',
        efficiency:'',
        utilization:'',
        active:'Y',
        calendarID:'',
        remark:'',
        add:0,
      };
      this.model3InputFlag=false;
      this.modelFlag3=true;

    },
    ResourceSave(){
      if(this.modelData3.resourceID==''||this.modelData3.resourceID==null){
        this.$alert(this.labels.resourceIDIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData3.resourceDesc==''||this.modelData3.resourceDesc==null){
        this.$alert(this.labels.resourceDescIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData3.efficiency==''||this.modelData3.efficiency==null){
        this.$alert(this.labels.efficiencyIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData3.utilization==''||this.modelData3.utilization==null){
        this.$alert(this.labels.utilizationIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData3.active==''||this.modelData3.active==null){
        this.$alert(this.labels.activeIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData3.calendarID==''||this.modelData3.calendarID==null){
        this.$alert(this.labels.calendarIDIn,this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      saveResource(this.modelData3).then(({data}) => {
        if (data && data.code == 200) {
          this.modelFlag3 = false
          getWorkCenterDataDetail(this.modelData).then(({data}) => {
            this.dataList2 = data.rows2;
          })
          this.$message.success(this.labels.doYes)
        } else {
          this.$alert(data.msg, this.labels.error, {
            confirmButtonText: this.labels.true
          })
        }
      })
    },
    setResource(){
      if(this.currentRow2==null){
        this.$alert(this.labels.resourceIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      let msg=this.labels.virturlFlagAsk1;
      if(this.currentRow2.virturlFlag=='Y'){
        msg=this.labels.virturlFlagAsk2;
      }
      this.$confirm(msg, this.labels.point, {
        confirmButtonText: this.labels.true,
        cancelButtonText: this.labels.cancel,
        type: 'warning'
      }).then(() => {
        setResourceFlag(this.currentRow2).then(({data}) => {
          if (data && data.code == 200) {
            getWorkCenterDataDetail(this.modelData).then(({data}) => {
              this.dataList2 = data.rows2;
            })
            this.$message.success(this.labels.doYes)
          } else {
            this.$alert(data.msg, this.labels.error, {
              confirmButtonText: this.labels.true
            })
          }
        })
      })
    },
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    uploadSOP(){
      if(this.currentRow2==null){
        this.$alert(this.labels.resourceIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      this.sopModelData={
        workCenterNo:this.currentRow2.workCenterNo,
        workCenterDesc: this.currentRow2.workCenterDesc,
        site:this.currentRow2.site,
        resourceID:this.currentRow2.resourceID,
        resourceDesc:this.currentRow2.resourceDesc,
        versionNumber:'A01',
        effectiveDate:this.formatDate(new Date()),
        expiryDate:'',
      };
      this.sopFileListSearch();
      this.uploadSOPFlag=true;
    },
    updateSOPFile(row){
      this.sopUpdateModelData= {
        id: row.id,
        workCenterNo: this.currentRow2.workCenterNo,
        workCenterDesc: this.currentRow2.workCenterDesc,
        site: this.currentRow2.site,
        resourceID: this.currentRow2.resourceID,
        resourceDesc: this.currentRow2.resourceDesc,
        versionNumber: row.versionNumber,
        effectiveDate: new Date(row.effectiveDate),
        expiryDate: row.expiryDate,
      }
      this.fileName = row.fileName;
      this.uploadSOPDisableFlag=false
      this.uploadSOPEditFlag=true;
    },
    sopFileListSearch(){
      let inData={
        orderRef1:this.currentRow2.site,
        orderRef2:this.currentRow2.workCenterNo,
        orderRef3:this.currentRow2.resourceID,
        orderRef4:'',
        fileType: 'SOP'
      }
      sopFileListSearch(inData).then(({data}) => {
        // 遍历data
        for (let i = 0; i < data.rows.length; i++) {
          if (data.rows[i].expiryDate != null) {
            if (data.rows[i].expiryDate < this.dayjs().format('YYYY-MM-DD')) {
              data.rows[i].status = '失效'
            } else {
              data.rows[i].status = '有效'
            }
          } else {
            data.rows[i].status = '有效'
          }
          this.sopFileList.push(data.rows[i]);
          this.sopFileList[i].versionNumber = data.rows[i].orderRef4

        }
        // 如果this.sopFileList不为空，拿到versionNumber的最后一个并给versionNumber赋值（versionNumber由 A + 两位数组成，赋值时给数字+1）
        if (this.sopFileList.length > 0) {
          let versionNumber = this.sopFileList[this.sopFileList.length - 1].versionNumber;
          // 如果A后面的数字小于10则为A0+数字加一，否则为A+数字加一
          if (versionNumber.substring(1) < 9) {
            this.sopModelData.versionNumber = 'A0' + (parseInt(versionNumber.substring(1)) + 1);
          } else {
            this.sopModelData.versionNumber = 'A' + (parseInt(versionNumber.substring(1)) + 1);
          }
        } else {
          this.sopModelData.versionNumber = 'A01';
        }
      })
    },
    triggerUpload() {
      this.$refs.uploadFile.$el.querySelector('input').click()
    },
    /*选择上传文件时*/
    onChange(file,fileList){
      const newFileName = file.name;
      if (this.fileName) {
        this.fileName += ', ' + newFileName;
      } else {
        this.fileName = newFileName;
      }
      this.fileList.push(file);
    },
    closeFileUpdate() {
      this.fileName = '';
      //this.fileRemark = ''
      this.$refs.uploadFile.clearFiles()
      this.fileList = []
    },
    uploadSOPSave() {
      if (this.sopModelData.effectiveDate === '' || this.sopModelData.effectiveDate == null) {
        this.$alert('请选择生效日期！', this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
        if (this.fileList.length === 0) {
          this.$alert('上传的SOP文件不能为空！', this.labels.error, {
            confirmButtonText: this.labels.true
          })
          return false;
        }
        const formData = new FormData();
        //片接文件
        for (let i = 0; i < this.fileList.length; i++) {
          formData.append("file", this.fileList[i].raw)
        }
        formData.append("orderRef2", this.sopModelData.workCenterNo)
        formData.append("orderRef1", this.sopModelData.site)
        formData.append("orderRef3", this.sopModelData.resourceID)
        formData.append("orderRef4", this.sopModelData.versionNumber)
        formData.append("effectiveDate", this.sopModelData.effectiveDate)
        if (this.sopModelData.expiryDate != null && this.sopModelData.expiryDate !== '') {
          formData.append("expiryDate", this.sopModelData.expiryDate)
        }
        formData.append("fileType", 'SOP')
        console.log(this.sopModelData.expiryDate)
        uploadSOPFile(formData).then(({data}) => {
          if (data && data.code === 0) {
            this.uploadSOPFlag = false
            this.$message.success(this.labels.doYes)
            //清空文件上传记录
            this.$refs.uploadFile.clearFiles();
            this.closeFileUpdate();
            this.sopFileList = []
          } else {
            this.$alert(data.msg, this.labels.error, {
              confirmButtonText: this.labels.true
            })
          }
        })
    },
    updateSopFile(){
      if (this.sopModelData.effectiveDate === '' || this.sopModelData.effectiveDate == null) {
        this.$alert('请选择生效日期！', this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      let inData = {
        id: this.sopUpdateModelData.id,
        effectiveDate: this.sopUpdateModelData.effectiveDate,
        expiryDate: this.sopUpdateModelData.expiryDate,
      }
      sopFileEdit(inData).then(({data}) => {
        if (data && data.code === 0) {
          this.sopFileList = [];
          this.sopFileListSearch();
          this.uploadSOPEditFlag = false
          this.fileName = '';
          this.$message.success(this.labels.doYes)
        } else {
          this.$alert(data.msg, this.labels.error, {
            confirmButtonText: this.labels.true
          })
        }
      })
    },
    deleteSOPFile(row){
      this.$confirm('确认删除该文件？', this.labels.point, {
        confirmButtonText: this.labels.true,
        cancelButtonText: this.labels.cancel,
        type: 'warning'
      }).then(() => {
        deleteSOPFile(row).then(({data}) => {
          if (data && data.code === 0) {
            this.sopFileList = [];
            this.sopFileListSearch();
            this.$message.success(this.labels.doYes)
          } else {
            this.$alert(data.msg, this.labels.error, {
              confirmButtonText: this.labels.true
            })
          }
        })
      })
    },
    closeUploadFileVisible(){
      this.uploadSOPFlag=false;
      this.sopFileList=[];
      this.fileList = [];
      this.closeFileUpdate();
    },
    closeUploadFileEditVisible(){
      this.uploadSOPEditFlag=false;
      this.fileName = '';
    },
    deleteCalendar(){
      if(this.currentRow2==null){
        this.$alert(this.labels.resourceIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      this.$confirm( this.labels.deleteResourceAsk,  this.labels.point, {
        confirmButtonText: this.labels.true,
        cancelButtonText: this.labels.cancel,
        type: 'warning'
      }).then(() => {
        deleteResource(this.currentRow2).then(({data}) => {
          if (data && data.code == 200) {
            getWorkCenterDataDetail(this.modelData).then(({data}) => {
              this.dataList2 = data.rows2;
            })
            this.$message.success(this.labels.doYes)
          } else {
            this.$alert(data.msg, this.labels.error, {
              confirmButtonText: this.labels.true
            })
          }
        })
      })
    },
    getBaseData(val){
      if (this.tagNo === 25){
        this.modelData2.proLineNo = val.ProLineNo
      }
      if (this.tagNo === 91){
        this.modelData3.calendarID = val.CalendarID
      }
    },
    // 获取基础数据列表
    getBaseList(val){
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = "";
        if (val === 25){
          strVal = this.modelData2.proLineNo
        }
        if (val === 91){
          strVal = this.modelData3.calendarID
        }
        this.$refs.baseList.init(val,strVal)
      })
    },
    clickData2(row){
      this.currentRow2 = JSON.parse(JSON.stringify(row));
    },
    jumpCalendar(){
      if(this.currentRow2==null){
        this.$alert(this.labels.resourceIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      let inData={user:this.$store.state.user.name,site:this.currentRow2.site,calendarId:this.currentRow2.calendarID};
      localStorage.setItem('calendar', JSON.stringify(inData))
      this.$router.replace('base-calendar')
    },
    getPartDetail(){
      if(this.currentRow==null){
        this.$alert(this.labels.rollIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      let inData={
        user:this.$store.state.user.name,
        site:this.currentRow.site,
        partNo:this.currentRow.partNo
      }
      searchPartNoData(inData).then(({data}) => {
        if (data.rows.length==0){
          this.$alert(this.labels.partNot, this.labels.error, {
            confirmButtonText: this.labels.true
          })
          return false;
        }
        this.partData = data.rows[0];
        this.partFlag=true;
      })

    },
    first(){
      if(localStorage.getItem('workCenterNo')!=undefined){
        this.jump();
      }
    },
    getData(){
      let inData={
        user:this.$store.state.user.name
      }
      getWorkCenterData(inData).then(({data}) => {
        this.dataList3 = data.rows;
        this.modelFlag2=true;
      })
    },
    jump(){
      let data=JSON.parse(localStorage.getItem('workCenterNo'));
      localStorage.removeItem('workCenterNo');
      getWorkCenterData(data).then(({data}) => {
        this.dataList3 = data.rows;
        this.modelData=data.rows[0];
        getWorkCenterDataDetail(this.modelData).then(({data}) => {
          this.dataList2 = data.rows2;
          this.dataList = data.rows1;
        })
      })
    },
    clickData(row){
      this.currentRow = JSON.parse(JSON.stringify(row));
    },
    addModal(){
      this.modelData2={
        add:'',
        workCenterNo:'',
        workCenterDesc:'',
        site:this.$store.state.user.site,
        active:'',
        workCenterType:'',
        proLineNo:'',
        productionLineDesc:'',
        canCreateNewRollFlag:'',
        createdDate:'',
        remark:'',
        needSetupFlag:'',
        user:this.$store.state.user.name,
      },
        this.modelData2.add=0;
      this.modelInputFlag=false;
      this.modelData2.active='Y';
      this.modelData2.canCreateNewRollFlag='Y';
      this.modelData2.needSetupFlag='Y';
      this.modelData2.workCenterType='内部',
        this.modelData2.createdDate=new Date();
      this.modelFlag=true;
    },
    editModel(row){
      this.modelData2=JSON.parse(JSON.stringify(row));
      this.modelData2.add=1;
      this.modelInputFlag=true;
      this.modelFlag=true;
    },
    ModelSave(){
      if(this.modelData2.workCenterNo==''||this.modelData2.workCenterNo==null){
        this.$alert(this.labels.workCenterNoIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData2.workCenterDesc==''||this.modelData2.workCenterDesc==null){
        this.$alert(this.labels.workCenterDescIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData2.site==''||this.modelData2.site==null){
        this.$alert(this.labels.siteIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }
      if(this.modelData2.createdDate==''||this.modelData2.createdDate==null){
        this.$alert(this.labels.createdDateIn, this.labels.error, {
          confirmButtonText: this.labels.true
        })
        return false;
      }

      this.modelData2.user=this.$store.state.user.name;

      saveWorkCenterData(this.modelData2).then(({data}) => {
        if (data && data.code == 200) {
          this.modelFlag = false
          this.getData();
          this.$message.success(this.labels.doYes)
        } else {
          this.$alert(data.msg, this.labels.error, {
            confirmButtonText: this.labels.true
          })
        }
      })
    },
    deleteData(row){
      this.$confirm( this.labels.workCenterDeleteAsk,  this.labels.point, {
        confirmButtonText: this.labels.true,
        cancelButtonText: this.labels.cancel,
        type: 'warning'

      }).then(() => {
        let inData = {
          workCenterNo: row.workCenterNo,
          site:row.site
        }
        deleteWorkCenterData(inData).then(({data}) => {
          if (data && data.code == 200) {
            this.modelFlag = false
            this.getData();
            this.$message.success( this.labels.doYes)
          } else {
            this.$alert(data.msg,  this.labels.error, {
              confirmButtonText: this.labels.true
            })
          }
        })
      })
    },
    tableHanddle(row){
      this.modelData=row;
      this.modelFlag2=false;
      getWorkCenterDataDetail(this.modelData).then(({data}) => {
        this.dataList2 = data.rows2;
        this.dataList = data.rows1;
      })
    },
    getProLineNo(){
      let inData={
        site : this.$store.state.user.site,
        proLineNo : this.modelData2.proLineNo
      }
      getProLineNoDetail(inData).then(({data}) => {
        let outList = data.rows
        if (outList.length>0){
          this.modelData2.productionLineDesc=outList[0].proLineDesc;
          this.modelData2=JSON.parse(JSON.stringify(this.modelData2));
        }else {
          this.modelData2.productionLineDesc='';
        }
      })
    },
    //导出excel
    createExportData() {

      return this.dataList;

    },
    startDownload() {
      //  this.exportData = this.dataList

    },
    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
    },
    // 导出 end

    //导出excel
    createExportData2() {

      return this.dataList2;

    },
    startDownload2() {
      //  this.exportData = this.dataList

    },
    finishDownload2() {

    },
    fields2() {
      let json = "{"
      this.columnList2.forEach((item, index) => {
        if (index == this.columnList2.length - 1) {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
        } else {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
        }
      })
      json += "}"
      let s = eval("(" + json + ")")

      return s
    },
    // 导出 end
    //获取按钮的权限数据
    getButtonAuthData(){
      let updateFlag = this.isAuth(this.menuId+":revise");
      let fullControFlag = this.isAuth(this.menuId+":fullContro");
      let deleteFlag = this.isAuth(this.menuId+":remove");
      //处理页面的权限数据
      this.authEdit = !updateFlag ||!fullControFlag;
      this.authAdd = !fullControFlag;
      this.authDelete = !deleteFlag;
    },
    //多语言
    getMultiLanguageList() {
      //首先查询当前按钮的多语言
      searchFunctionButtonList(this.queryButton).then(({data}) => {
        if (data && data.code == 0) {
          this.buttons = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
      //其次查询当前标签的多语言
      searchFunctionButtonList(this.queryLabel).then(({data}) => {
        if (data && data.code == 0) {
          this.labels = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
    },
// 获取 用户保存的 格式列
    async getTableUserColumn(tableId, columnId) {
      let queryTableUser = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        status: true,
        languageCode: this.$i18n.locale
      }
      await getTableUserListLanguage(queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          //this.columnList = []
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
            case 2:
              this.columnList2 = data.rows
              break;
            case 3:
              this.columnList3 = data.rows
              break;
          }

        } else {
          this.getColumnList(tableId, columnId)
        }
      })

    },
    // 获取 tableDefault 列
    async getColumnList(tableId, columnId) {
      this.queryTable.tableId = tableId
      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;
            case 2:
              this.columnList2 = data.rows
              break;
            case 3:
              this.columnList3 = data.rows
              break;
          }
        } else {
          // this.showDefault = true
        }
      })

    },


  },
  created() {
    this.first();
    //获取按钮的权限
    this.getButtonAuthData();
    //
    this.getMultiLanguageList()//刷新按钮
    this.getTableUserColumn('103004Table',1)
    this.getTableUserColumn('103004Table2',2)
    this.getTableUserColumn('103004Table3',3)
  }
}
</script>

<style scoped>

</style>
