<template>
  <div class="template-table">
    <!-- <SP001 v-if="sn == 'SP0012'" />
    <SWYPFXRYPZB v-if="sn == 'SP001'" /> -->
     <component ref="templateComponent" :is="getTemplateComponent()" :templateData="templateData" :fillType="fillType">
      </component>
  </div>
</template>

<script>
//色谱
import SP001 from './comps/sp/SP001';
import SWYPFXRYPZB from "./comps/sp/SWYPFXRYPZB.vue";
import SWYPFXCBYPZB from "./comps/sp/SWYPFXCBYPZB.vue";
import SWYPBQGZYZBB from "./comps/sp/SWYPBQGZYZBB.vue";
import SWYPNBGZYZBB from "./comps/sp/SWYPNBGZYZBB.vue";
import Demo from "./comps/sp/Demo.vue";
import IndexDBDemo from "./comps/sp/IndexDBDemo.vue";
//公用
import SYWZPZJHB from "./comps/gy/SYWZPZJHB.vue";
import MJYLQSQD from "./comps/gy/MJYLQSQD.vue";

export default {
  name: "TemplateTable",
  components: { 
    MJYLQSQD,SYWZPZJHB,
    SP001,SWYPFXRYPZB ,Demo,SWYPFXCBYPZB,SWYPBQGZYZBB,SWYPNBGZYZBB,IndexDBDemo
  },
  props: {
    sn: {
      type: String,
      default: '',
    },
    fillType: {
      type: String,
      default: 'preFill',
    },
    templateData: {
      type: Object,
      default: () => {},
    },
  },
  computed: {
    
    templateComponentMap() {
      if (!this.componentMap) {
        this.componentMap = {
          'SP001': 'SWYPFXRYPZB',
          'SP002': 'SWYPFXCBYPZB',
          'SP003': 'SWYPBQGZYZBB',
          'SP004': 'SWYPNBGZYZBB',
          'SYWZPZJHB': 'SYWZPZJHB',
          'MJYLQSQD': 'MJYLQSQD',
          // 'SP001': 'IndexDBDemo',
        }
      }
      return this.componentMap || "Demo"
    }
  },
  watch: {
    sn: {
      immediate: true,
      handler(v) {
        console.log(v,"sn")
      }
    }
  },
  data() {
    return {
      info: {},
    };
  },
  mounted() {
    console.log(this.fillType,"fillType")
  },
  methods: {
    async getFormData() {
      return await this.$refs.templateComponent.getFormData();
    },
    getResource(){
      return this.$refs.templateComponent.getResource();
    },
    getTemplateComponent() {
      return this.templateComponentMap[this.sn] 
    },
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.template-table {
  background: #fff;
  padding: 10px 10px;
}
</style>