<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)">
          {{ $t(item.name) }}
        </div>
      </div>

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

<script>
import { checkPermi } from "@/utils/permission";
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: [],
      active: '',

      study: {},
    }
  },
  created() {
    this.initTab()
    this.getInfo()
   },
  methods: {
    checkPermi,
    initTab(){
      this.tabList = []
      if(this.checkPermi(['business:drugFormPreTab'])){
        this.tabList.push({ key: 'ytbd', name: 'page.business.study.studyEnter.ytbdlb' })
      }
      if(this.checkPermi(['business:drugFormFillTab'])){
        this.tabList.push({ key: 'tbbd', name: 'page.business.study.studyEnter.tbbdlb' })
      }
      if(this.checkPermi(['business:drugFormApplyTab'])){
        this.tabList.push({ key: 'sqbd', name: 'page.business.study.studyEnter.sqbdlb' })
      }
      if(this.checkPermi(['business:drugWzlbTab'])){
        this.tabList.push({ key: 'wzlb', name: 'page.business.study.studyEnter.wzlb' })
      }
      this.active = this.$route.params.tab && _.findIndex(this.tabList,(o)=>{return o.key===this.$route.params.tab})>-1 ? this.$route.params.tab: this.tabList.length>0 ? this.tabList[0].key :''
      if(this.active){
        let name = this.tabList[_.findIndex(this.tabList,(o)=>{return o.key===this.active})].name
        if(name){
          this.saveSimpleLog({name:this.$t(name,'zh_CN'),nameEn:this.$t(name,'en_US'),jcmc:this.$t('system.enterPage','zh_CN'),jcmcEn:this.$t('system.enterPage','en_US')})
        }
      }
    },
    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.name+'('+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.saveSimpleLog({name:this.$t(item.name,'zh_CN'),nameEn:this.$t(item.name,'en_US'),jcmc:this.$t('system.enterPage','zh_CN'),jcmcEn:this.$t('system.enterPage','en_US')})
        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>
