<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"/>
        <syxx v-if="active === 'syxx'" :study="study" @showDetail="showDetailCallback" @changeTab="changeTab"/>
        <syff v-if="active === 'syff'" :study="study" @showDetail="showDetailCallback" @changeTab="changeTab"/>
        <wzlb v-if="active === 'wzlb'" :study="study" @showDetail="showDetailCallback" @changeTab="changeTab"/>
        <syj v-if="active === 'syj'" :study="study" @showDetail="showDetailCallback" @changeTab="changeTab"/>
      </div>
    </div>
  </div>
</template>

<script>
import { checkPermi } from "@/utils/permission";
import { study_info} from "@/api/business/study/study";
import ytbd from './ytbd.vue'
import tbbd from './tbbd.vue'
import syxx from './syxx.vue'
import syff from './syff.vue'
import wzlb from './wzlb.vue'
import syj from './syj.vue'
export default {
  name: 'StudyEnter',
  props: {},
  components: { ytbd, tbbd ,syxx,syff,wzlb, syj},
  computed: {},
  filters: {},
  data() {
    return {
      showDetail: false,
      tabList: [],
      active: '',

      study: {},
    }
  },
  created() {
    // let x = this.$route.params
    // let y = this.$route.query
    // debugger
    this.initTab()
    this.getInfo()

  },
  methods: {
    checkPermi,
    initTab(){
      this.tabList = []
      if(this.checkPermi(['business:studyFormPreTab'])){
        this.tabList.push({ key: 'ytbd', name: 'page.business.study.studyEnter.ytbdlb' })
      }
      if(this.checkPermi(['business:studyFormFillTab'])){
        this.tabList.push({ key: 'tbbd', name: 'page.business.study.studyEnter.tbbdlb' })
      }
      if(this.checkPermi(['business:studyFormPlanTab'])){
        this.tabList.push({ key: 'syxx', name: 'page.business.study.studyEnter.syxx' })
      }
      if(this.checkPermi(['business:studyWzlbTab'])){
        this.tabList.push({ key: 'wzlb', name: 'page.business.study.studyEnter.wzlb' })
      }
      if(this.checkPermi(['business:studyMethodTab'])){
        this.tabList.push({ key: 'syff', name: 'page.business.study.studyEnter.syfflb' })
      }
      if(this.checkPermi(['business:studyRoomTab'])){
        this.tabList.push({ key: 'syj', name: 'page.business.study.studyEnter.syjsygl' })
      }
      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()
      study_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>
