<template>
    <div class="mod-config">
      <el-tabs v-if="dataForm.buNo === 'Flexo'" class="tabs" tab-position="left" style="height: 100vh;" type="border-card" v-model="activeName" @tab-click="refreshCurrentTabTable">
        <el-tab-pane label="基本信息" name="baseInfo" >
          <basicInformation :readonly="readonly" ref="basicInformation"></basicInformation>
        </el-tab-pane>
<!--        <el-tab-pane label="备注区"  name="remarkPage" >-->
<!--          <remarkPage ref="remarkPage"  ></remarkPage>-->
<!--        </el-tab-pane>-->
        <el-tab-pane label="客户信息" name="customerInfo" v-if="getPageIf('customerInfo')">
          <customerInfo :readonly="readonly" ref="customerInfo"></customerInfo>
        </el-tab-pane>
        <el-tab-pane label="包装信息" name="packageInfo" v-if="getPageIf('packageInfo')">
          <packageInfo :readonly="readonly" ref="packageInfo"></packageInfo>
        </el-tab-pane>
        <el-tab-pane label="材料信息" name="bom" v-if="getPageIf('bom')">
          <bom ref="bom" :readonly="readonly"></bom>
        </el-tab-pane>
        <el-tab-pane label="工艺信息" name="routing" v-if="getPageIf('routing')">
          <routing ref="routing" :readonly="readonly"></routing>
        </el-tab-pane>
        <el-tab-pane label="图稿信息" name="drawing" v-if="getPageIf('drawing')">
          <drawing ref="drawing" :readonly="readonly" :default-value="true"></drawing>
        </el-tab-pane>
        <el-tab-pane label="FAI" name="fai" v-if="getPageIf('fai')">
          <fai ref="fai" :readonly="readonly" :default-value="true"></fai>
        </el-tab-pane>
        <el-tab-pane label="品质文件" name="qualityDocument" v-if="getPageIf('qualityDocument')">
          <qualityDocument :readonly="readonly" ref="qualityDocument" :default-value="true"></qualityDocument>
        </el-tab-pane>
<!--        <el-tab-pane label="TP工程师填写信息"  name="tpInfo" v-if="getPageIf('tpInfo')">-->
<!--          <tpInfo ref="tpInfo"></tpInfo>-->
<!--        </el-tab-pane>-->
<!--        <el-tab-pane label="产品技术要求"  name="technicalRequirement" v-if="getPageIf('technicalRequirement')">-->
<!--          <technicalRequirement ref="technicalRequirement"></technicalRequirement>-->
<!--        </el-tab-pane>-->
<!--          <el-tab-pane label="PE确认信息"  name="PEConfirm" v-if="getPageIf('PEConfirm')">-->
<!--          <PEConfirm ref="PEConfirm"></PEConfirm>-->
<!--        </el-tab-pane>-->
<!--        <el-tab-pane label="文档控制"  name="documentControl" v-if="getPageIf('documentControl')">-->
<!--          <documentControl ref="documentControl"></documentControl>-->
<!--        </el-tab-pane>-->
<!--        <el-tab-pane label="产品工程师审核/确认"  name="peReviewed" v-if="getPageIf('peReviewed')">-->
<!--          <peReviewed ref="peReviewed"></peReviewed>-->
<!--        </el-tab-pane>-->
<!--&lt;!&ndash;        可能不要&ndash;&gt;-->
<!--        <el-tab-pane label="报价专员确认信息"  name="queteConfirm" v-if="getPageIf('queteConfirm')">-->
<!--          <queteConfirm ref="queteConfirm"></queteConfirm>-->
<!--        </el-tab-pane>-->
<!--        <el-tab-pane label="CQE确认"  name="cqeComfirm" v-if="getPageIf('cqeComfirm')">-->
<!--          <cqeComfirm ref="cqeComfirm"></cqeComfirm>-->
<!--        </el-tab-pane>-->
      </el-tabs>

      <el-tabs v-else-if="dataForm.buNo === 'RDC'" class="tabs" tab-position="left" style="height: 100vh;" type="border-card" v-model="activeName" @tab-click="refreshCurrentTabTable">
        <el-tab-pane label="基本信息" name="baseInfo" >
          <basicInformation :readonly="readonly" ref="basicInformation"></basicInformation>
        </el-tab-pane>
        <el-tab-pane label="客户信息" name="customerInfo" v-if="getPageIf('customerInfo')">
          <customerInfo :readonly="readonly" ref="customerInfo"></customerInfo>
        </el-tab-pane>
        <el-tab-pane label="包装信息" name="packageInfo" v-if="getPageIf('packageInfo')">
          <packageInfo :readonly="readonly" ref="packageInfo"></packageInfo>
        </el-tab-pane>
        <el-tab-pane label="材料信息" name="bom" v-if="getPageIf('bom')">
          <bom ref="bom" :readonly="readonly"></bom>
        </el-tab-pane>
        <el-tab-pane label="工艺信息" name="routing" v-if="getPageIf('routing')">
          <routing ref="routing" :readonly="readonly"></routing>
        </el-tab-pane>
        <el-tab-pane label="图稿信息" name="drawing" v-if="getPageIf('drawing')">
          <drawing ref="drawing" :readonly="readonly" :default-value="true"></drawing>
        </el-tab-pane>
        <el-tab-pane label="FAI" name="fai" v-if="getPageIf('fai')">
          <fai ref="fai" :readonly="readonly" :default-value="true"></fai>
        </el-tab-pane>
        <el-tab-pane label="品质文件" name="qualityDocument" v-if="getPageIf('qualityDocument')">
          <qualityDocument :readonly="readonly" ref="qualityDocument" :default-value="true"></qualityDocument>
        </el-tab-pane>
      </el-tabs>

      <el-tabs v-else-if="dataForm.buNo === 'DBE'" class="tabs" tab-position="left" style="height: 100vh;" type="border-card" v-model="activeName" @tab-click="refreshCurrentTabTable">
        <el-tab-pane label="基本信息" name="baseInfo" >
          <basicInformation :readonly="readonly" ref="basicInformation"></basicInformation>
        </el-tab-pane>
        <el-tab-pane label="客户信息" name="customerInfo" v-if="getPageIf('customerInfo')">
          <customerInfo :readonly="readonly" ref="customerInfo"></customerInfo>
        </el-tab-pane>
        <el-tab-pane label="包装信息" name="packageInfo" v-if="getPageIf('packageInfo')">
          <packageInfo :readonly="readonly" ref="packageInfo"></packageInfo>
        </el-tab-pane>
        <el-tab-pane label="材料信息" name="bom" v-if="getPageIf('bom')">
          <bom ref="bom" :readonly="readonly"></bom>
        </el-tab-pane>
        <el-tab-pane label="工艺信息" name="routing" v-if="getPageIf('routing')">
          <routing ref="routing" :readonly="readonly"></routing>
        </el-tab-pane>
        <el-tab-pane label="图稿信息" name="drawing" v-if="getPageIf('drawing')">
          <drawing ref="drawing" :readonly="readonly" :default-value="true"></drawing>
        </el-tab-pane>
        <el-tab-pane label="FAI" name="fai" v-if="getPageIf('fai')">
          <fai ref="fai" :readonly="readonly" :default-value="true"></fai>
        </el-tab-pane>
        <el-tab-pane label="品质文件" name="qualityDocument" v-if="getPageIf('qualityDocument')">
          <qualityDocument :readonly="readonly" ref="qualityDocument" :default-value="true"></qualityDocument>
        </el-tab-pane>
      </el-tabs>

      <el-tabs v-else-if="dataForm.buNo === 'SS'" class="tabs" tab-position="left" style="height: 100vh;" type="border-card" v-model="activeName" @tab-click="refreshCurrentTabTable">
        <el-tab-pane label="基本信息" name="baseInfo" >
          <basicInformation :readonly="readonly" ref="basicInformation"></basicInformation>
        </el-tab-pane>
        <el-tab-pane label="客户信息" name="customerInfo" v-if="getPageIf('customerInfo')">
          <customerInfo :readonly="readonly" ref="customerInfo"></customerInfo>
        </el-tab-pane>
        <el-tab-pane label="包装信息" name="packageInfo" v-if="getPageIf('packageInfo')">
          <packageInfo :readonly="readonly" ref="packageInfo"></packageInfo>
        </el-tab-pane>
        <el-tab-pane label="材料信息" name="bom" v-if="getPageIf('bom')">
          <bom ref="bom" :readonly="readonly"></bom>
        </el-tab-pane>
        <el-tab-pane label="工艺信息" name="routing" v-if="getPageIf('routing')">
          <routing ref="routing" :readonly="readonly"></routing>
        </el-tab-pane>
        <el-tab-pane label="图稿信息" name="drawing" v-if="getPageIf('drawing')">
          <drawing ref="drawing" :readonly="readonly" :default-value="true"></drawing>
        </el-tab-pane>
        <el-tab-pane label="FAI" name="fai" v-if="getPageIf('fai')">
          <fai ref="fai" :readonly="readonly" :default-value="true"></fai>
        </el-tab-pane>
        <el-tab-pane label="品质文件" name="qualityDocument" v-if="getPageIf('qualityDocument')">
          <qualityDocument :readonly="readonly" ref="qualityDocument" :default-value="true"></qualityDocument>
        </el-tab-pane>
      </el-tabs>
    </div>
</template>

<script>
  import {
    getBMPageBase
  } from '@/api/sampleManagement/technicalSpecificationList.js'
  import basicInformation from "./com_tsd_basicInformation";/*組件*/
  import remarkPage from "./com_bm_remarkSlot.vue";/*备注*/
  import customerInfo from "./com_bm_customerInformation";/*客户信息*/
  import packageInfo from "./com_bm_packageInfo";/*包装信息*/
  import bom from "./com_bm_bom";/*BOM*/
  import routing from "./com_bm_routing";/*工艺*/
  import prepress from "./com_bm_prepress";/*组件*/
  import technicalRequirement from "./com_bm_demoSlot";/*组件*/
  import drawing from "./com_bm_demoSlot";/*组件*/
  import PEConfirm from "./com_bm_demoSlot";/*组件*/
  import overprinting from "./com_bm_demoSlot";/*组件*/
  import slitting from "./com_bm_demoSlot";/*组件*/
  import lamTemperature from "./com_bm_demoSlot";/*组件*/
  import cutting from "./com_bm_demoSlot";/*组件*/
  import packagePage from "./com_bm_demoSlot";/*组件*/
  import fqc from "./com_bm_demoSlot";/*组件*/
  import cqc from "./com_bm_demoSlot";/*组件*/
  import qualityDocument from "./com_bm_demoSlot";/*组件*/
  import documentControl from "./com_bm_demoSlot";/*组件*/
  import peReviewed from "./com_bm_demoSlot";/*组件*/
  import queteConfirm from "./com_bm_demoSlot";/*组件*/
  import fai from "./com_bm_demoSlot";/*组件*/
  import cqeComfirm from "./com_bm_demoSlot";/*组件*/
  import tpInfo from "./com_bm_tpInfo";/*组件*/
  import printOther from "./com_bm_printOther";/*组件*/
  import InkMixing from "./com_bm_inkMixing";/*组件*/
  import InkFormulation from "./com_bm_inkFormulation";/*组件*/
  import lamination from "./com_bm_lamination";/*组件*/
  import printing from "./com_bm_printing";/*组件*/

  import CNC from "./com_bm_cnc";
  import Cut from "./com_bm_cut";
  import {isAuth} from "../../../../utils";
  export default {
    name: "technicalSpecificationDetail",
    props:{
      readonly:{
        type:Boolean,
        default:false
      }
    },
    watch: {
      'activeName': {
        deep: true,
        handler: function (val, oldVal) {
          if (this.readonly===false&&isAuth('103002:bmSave')){
            if (oldVal === 'baseInfo') {
              this.$refs.basicInformation.saveData1()
            } else if (oldVal === 'customerInfo') {
              this.$refs.customerInfo.saveData1()
            } else if (oldVal === 'packageInfo') {
              this.$refs.packageInfo.saveData()
            } else if (oldVal === 'bom') {
              this.$refs.bom.updateBMProcess()
            } else if (oldVal === 'routing') {
              this.$refs.routing.updateBMProcess()
            } else if (oldVal === 'drawing') {
              this.$refs.drawing.saveTable()
            } else if (oldVal === 'fai') {
              this.$refs.fai.saveTable()
            } else if (oldVal === 'qualityDocument') {
              this.$refs.qualityDocument.saveTable()
            }
          }
        }
      }
    },
    components: {
      basicInformation,
      customerInfo,
      packageInfo,
      bom,
      routing,
      technicalRequirement,
      drawing,
      PEConfirm,
      qualityDocument,
      documentControl,
      peReviewed,
      queteConfirm,
      fai,
      cqeComfirm,
      tpInfo,
      remarkPage,
    },
    data() {
      return {
        dataForm:{
          site:'',
          codeNo:'',
          buNo:'',
          username:this.$store.state.user.name,
          type:'',
          ifDisableFlag:false,
          fieldId:'',
        },
        pageRole:'',
        activeName:'baseInfo',
      }
    },
    created() {
      // 注册 页面销毁前,即刷新 存储最新的activeName 即 TAB标签
      window.addEventListener('beforeunload', () => {
        localStorage.setItem('activeName', this.activeName);
      });
    },
    mounted() {
      let data = JSON.parse(localStorage.getItem('tsfData'))
      if (data) {
        let id = this.$route.params.id
        if (data.uuid !== id) {
          // localStorage.removeItem('tsfData');
          this.$router.replace("/404")
        }
        this.dataForm.site = data.site
        this.dataForm.codeNo = data.codeNo
        this.dataForm.buNo = data.buNo
        this.dataForm.username = data.username
        this.readonly = data.readonly
        // 页面数据和页面高度
        this.getPageRole()
        this.changeHeightAuto();
        // 传递的 tab
        if (data.activeName) {
          // 当前使用哪个tab
          this.activeName = data.activeName
          // 使用后清除
          data.activeName = ''
        } else {
          // 使用刷新的tab
          this.activeName = localStorage.getItem('activeName')
        }
        // 重新保存当前数据 目的是刷新首次的TAB
        localStorage.setItem('tsfData',JSON.stringify(data))
        // 刷新数据
        // this.$nextTick(() => {
        //   // this.getBaseInfoData();
        // })
      }
    },
    methods: {

      refreshCurrentTabTable () {
        this.dataForm.fieldId = this.activeName
        //先调整页面的高度
        this.changeHeightAuto()
        if (this.activeName === 'baseInfo') {
          this.getBaseInfoData()
        // }else if (this.activeName == 'remarkPage') {
        //   this.changeHeight(800);
        //   this.getRemarkSlot();
        } else if (this.activeName === 'customerInfo') {
          //有的页面要高一点
          this.changeHeight(1000)
          this.getCustomerInfo()
        } else if (this.activeName === 'packageInfo') {
          this.getPackageInfo()
        } else if (this.activeName === 'bom') {
          this.getBom()
        } else if (this.activeName === 'routing') {
          this.changeHeight(2000)
          this.getRouting()
        } else if (this.activeName === 'technicalRequirement') {
          this.getTechnicalRequirement()
        } else if (this.activeName === 'PEConfirm') {
          this.getPEConfirm()
        } else if (this.activeName === 'drawing') {
          this.getDrawing()
        } else if (this.activeName === 'qualityDocument') {
          this.getQualityDocument()
        } else if (this.activeName === 'documentControl') {
          this.getDocumentControl()
        } else if (this.activeName === 'peReviewed') {
          this.getPeReviewed()
        } else if (this.activeName === 'queteConfirm') {
          this.getQueteConfirm()
        } else if (this.activeName === 'fai') {
          this.getFai()
        } else if (this.activeName === 'cqeComfirm') {
          this.getCqeComfirm()
        } else if (this.activeName === 'tpInfo') {
          this.changeHeight(800)
          this.getTpInfo()
        }
      },

      // 基本信息
      getBaseInfoData () {
        this.$refs.basicInformation.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getRemarkSlot () {
        this.$refs.remarkPage.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // 客户信息
      getCustomerInfo () {
        this.$refs.customerInfo.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // 包装信息
      getPackageInfo () {
        this.$refs.packageInfo.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // BOM
      getBom () {
        this.$refs.bom.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // Routing
      getRouting () {
        this.$refs.routing.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getTechnicalRequirement () {
        this.dataForm.type = 'technicalRequirement'
        this.$refs.technicalRequirement.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getPEConfirm () {
        this.dataForm.type = 'PEConfirm'
        this.$refs.PEConfirm.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // 图稿信息
      getDrawing () {
        this.dataForm.type = 'drawing'
        this.$refs.drawing.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // 品质文件
      getQualityDocument () {
        this.dataForm.type = 'qualityDocument'
        this.$refs.qualityDocument.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getDocumentControl () {
        this.dataForm.type = 'documentControl'
        this.$refs.documentControl.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getPeReviewed () {
        this.dataForm.type='peReviewed'
        this.$refs.peReviewed.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getQueteConfirm () {
        this.dataForm.type = 'queteConfirm'
        this.$refs.queteConfirm.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      // FAI
      getFai () {
        this.dataForm.type = 'fai'
        this.$refs.fai.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getCqeComfirm () {
        this.dataForm.type = 'cqeComfirm'
        this.$refs.cqeComfirm.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

      getTpInfo () {
        this.dataForm.type = 'tpInfo'
        this.$refs.tpInfo.init(JSON.parse(JSON.stringify(this.dataForm)))
      },

   //看有没有这个页面的权限
      getPageRole(){
        getBMPageBase(this.dataForm).then(({data}) => {
          if (data && data.code === 0) {
            this.pageRole=data.row
            // 2025-05-12 新增页面初始化后调用
            // 用于刷新当前使用的TAB数据
            this.$nextTick(()=>{
              this.refreshCurrentTabTable();
            })
          }
        })
      },
      getPageIf(key){
        return this.pageRole.indexOf(';'+key+';') !== -1 || false
      },

      changeHeight(height){
        var tabsElement = document.querySelector('.tabs');
        // tabsElement.style.minHeight = window.innerHeight+'px';
        tabsElement.style.minHeight = height +'px';
      },
      changeHeightAuto(){
        //页签大小铺满网页
        var tabsElement = document.querySelector('.tabs');
        tabsElement.style.minHeight = window.innerHeight+'px';
      }
    },
  }
</script>

<style >

</style>
