<template>
  <el-dialog title="零件信息" v-model="setCrewShow" :before-close="cancel" fullscreen @opened="opened">
    <el-tabs v-if="setCrewShow" v-model="activeName" @tab-click="handleClick">
      <!-- 零件信息-->
      <el-tab-pane label="零件信息" name="1">
        <dsPartBasicInfo ref="dsPartRef" v-if="activeName=='1'" :part-id="partId" @cancelClose="cancelClose" :partType="partType" />
      </el-tab-pane>
      <!-- 子件信息 -->
      <el-tab-pane label="工艺编制" name="2">
        <!-- 工艺编制 -->
        <dsCraftPage ref="craftEdit"  v-if="activeName=='2'" :part-id="partId"></dsCraftPage>
      </el-tab-pane>
    </el-tabs>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="cancel()">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import dsPartBasicInfo from './dsPartBasicInfo.vue';
import dsCraftPage from './dsCraft.vue'
export default {
  name: 'DsPartIndex',
  components: {
    dsPartBasicInfo,
    dsCraftPage,
  },
  props: {
    partType: {
      type: String,
      default: '',
    },
    isOpen: {
      type: Boolean,
      default: false
    },
    partId: {
      type:  [Number,String],
      default: null
    }
  },
  data() {
    return {
      setCrewShow: false,
      activeName: '1'
    };
  },
  methods: {
    opened() {
      if (this.partId) {
        this.$refs.dsPartRef.loadData(this.partId);
      }
    },
    handleClick(tab, event) {
      if (tab.name === '1') {
        // this.$refs.dsPartRef.loadData(this.partId);
      } else if (tab.name === '2') {
        // this.$refs.partSubRef.getData(this.partId, true);
      }
    },
    partSubRefLoad() {
      this.$refs.partSubRef.loadData(this.partId, true);
    },
    cancelClose(flag, dsPart) {
      if (flag) {
        this.cancel(true);
      } else {
        this.partId = dsPart.partId;
      }
    },
    cancel(refresh) {
      this.activeName = '1';
      //   this.$refs.dsPartRef.clear();
      this.setCrewShow = false
      this.$emit('cancel', typeof refresh === 'boolean' && refresh);
    }
  },
  mounted() {
    this.setCrewShow = this.isOpen
  }
};
</script>
