<template>
  <div class="study-enter">
    <div class="content-list">
      <div class="search-box" v-show="!showDetail">
        <div class="search-item" :class="active === item.key ? 'active' : ''" v-for="(item, index) in tabList"
          :key="index" @click="changeTab(item)">
          {{ item.name }}
        </div>
      </div>

      <div class="content-box" v-if="study.id!='' && study.id!=undefined">
        <ytbd v-if="active === 'ytbd'" :study="study" @showDetail="showDetailCallback" />
        <tbbd v-if="active === 'tbbd'" :study="study" @showDetail="showDetailCallback"/>
        <sqbd v-if="active === 'sqbd'" :study="study" @showDetail="showDetailCallback"/>
        <wzlb v-if="active === 'wzlb'" :study="study" @showDetail="showDetailCallback"/>
      </div>
    </div>
  </div>
</template>

<script>
import { drug_info} from "@/api/business/form/drug";
import ytbd from './ytbd.vue'
import tbbd from './tbbd.vue'
import sqbd from './sqbd.vue'
import wzlb from './wzlb.vue'
export default {
  name: 'DrugEnter',
  props: {},
  components: { ytbd, tbbd ,sqbd,wzlb},
  computed: {},
  filters: {},
  data() {
    return {
      showDetail: false,
      tabList: [
        { key: 'ytbd', name: this.$t('page.business.study.studyEnter.ytbdlb') },
        { key: 'tbbd', name: this.$t('page.business.study.studyEnter.tbbdlb') },
        { key: 'sqbd', name: this.$t('page.business.study.studyEnter.sqbdlb') },
        { key: 'wzlb', name: this.$t('page.business.study.studyEnter.wzlb') },
      ],
      active: this.$route.params.tab || 'ytbd',

      study: {},
    }
  },
  created() {
    this.getInfo()
   },
  methods: {
    getInfo(){
      this.$modal.loading()
      drug_info({id:this.$route.params.studyId}).then(({data}) => {
        this.study = data
        const obj = Object.assign({}, this.$route, { title: '麻精药表单:'+this.study.sn }) 
        this.$tab.updatePage(obj);
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    show(row) {
      this.study = row
    },
    showDetailCallback(val) {
      this.showDetail = val
    },
    changeTab(item) {
      if (this.active !== item.key) {
        this.active = item.key
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.study-enter {
  margin: 10px 10px;
  .search-box {
    background: #fff;
    padding: 0;
    border-radius: 3px;
    margin-bottom: 10px;

    display: flex;
    flex-direction: row;
    align-items: center;

    .search-item {
      padding: 10px 20px;
      font-size: 14px;
      cursor: pointer;

      &.active {
        background: #1890ff;
        color: #fff;
      }

      &:hover {
        background: #46a6ff;
        color: #fff;
      }

      &:first-child {
        border-top-left-radius: 3px;
        border-bottom-left-radius: 3px;
      }

      &:last-child {
        border-top-right-radius: 3px;
        border-bottom-right-radius: 3px;
      }
    }
  }

  .content-box {}
}
</style>
