<template>
  <div id="danwei">
    <el-row>
      <el-col :span="24">
        <el-tabs v-model="activeName" type="border-card" :before-leave="handleClick">
          <el-tab-pane v-for="(item, index) in danweiList" :key="index">
            <span slot="label">{{ item.title }}</span>
            <el-col :span="24" v-for="(tag, index) in item.children" :key="index" class="shiyeList">
              <el-col :span="20" class="title textOver">
                <el-link :underline="false" @click="$router.push({ path: `/info/detail?id=${tag.id}` })">{{ tag.title }}</el-link>
              </el-col>
              <el-col :span="4" class="time">
                {{ tag.meta && tag.meta.createdAt ? new Date(tag.meta.createdAt).toLocaleDateString() : '' || '' }}
              </el-col>
            </el-col>
          </el-tab-pane>
        </el-tabs>
        <el-link :inderline="false" class="moreLink" :style="`color:${Color}`" @click="moreClick()">MORE<i class="el-icon-video-play"></i> </el-link>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'danwei',
  props: {
    danweiList: null,
  },
  components: {},
  data: () => ({
    activeName: '',
    Color: '#850000',
  }),
  created() {},
  computed: {},
  methods: {
    moreClick() {
      let to = this.danweiList[`${this.activeName}`];
      if (!to) return false;
      if (to.type === 'bugList') this.$router.push({ path: `/info/list/${to.content_id}?news_type=0` });
      if (to.type === 'column') this.$router.push({ path: `/info/list/${to.id}` });
    },
    handleClick(active, old) {
      //略过加载时处理,只有点击后才会走判断逻辑
      if (!old) return true;
      let to = this.danweiList[`${active}`];
      if (!to) return false;
      if (to.type === 'bugList' || to.type === 'column') return true;
      if (to.type === 'url') window.open(to.url);
      if (to.type === 'content') this.$router.push({ path: `/info/detail?id=${to.content_id}` });
    },
  },
};
</script>

<style lang="less" scoped>
.moreLink {
  position: absolute;
  top: 10px;
  right: 10px;
  color: #850000;
}
/deep/.el-tabs__header {
  margin: 0;
}
/deep/.el-tabs--border-card > .el-tabs__content {
  padding: 0;
}
.talksList {
  padding: 12px 10px;
  border-bottom: 1px dashed #ccc;
}
.talksList .title .el-link {
  font-size: 18px;
}
.textOver {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shiyeList {
  padding: 10px;
  border-bottom: 1px dashed #ccc;
}
.shiyeList .title .el-link {
  font-size: 18px;
}
.shiyeList .time {
  font-size: 18px;
  text-align: right;
}
</style>
