<template>
  <div id="title">
    <h2>
      <img :src="dataSource.iconUrl" alt="">
      <button :class="[{active:activeIndex === index},'tag']" @click="selectItem(item, index)" v-for="(item,index) in dataSource.titleList" :key="index">
        {{ item }}
        <i></i>
      </button>
    </h2>
    <button v-if="btnType === 'edit'">
      <img src="../../assets/images/systemNav/edit.png" alt="">
    </button>
    <button class="more" v-if="btnType === 'more'">
      more
    </button>
    <button class="changeIt" v-if="btnType === 'changeIt'">
      换一换
    </button>

  </div>

</template>

<script>
export default {
  props: {
    dataSource: {
      type: Object,
      default: () => {}
    },
    btnType: {
      type: String,
      default: () => {}
    }
  },
  data () {
    return {
      activeIndex: 0
    }
  },

  methods: {
    selectItem (item, index) {
      if (this.dataSource.titleList[0] === '公司公文') {
        this.activeIndex = index
        this.$emit('getCompanyDocData', index)
      } else if (this.dataSource.titleList[0] === '公司新闻') {
        this.activeIndex = index
        this.$emit('getNewsData', index)
      }
    }
  }
}
</script>

<style lang='less' scoped>
button:focus{
  border: none;
  outline: none;
}
#title {
  padding: 0 3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f4f5fa;
  img{
    width: 2.6rem;
    height: auto;
  }
  h2 {
    display: flex;
    align-items: center;
    margin: 0;
    button.tag {
      font-weight: Bold;
      font-size: 2rem;
      line-height: 5.5rem;
      color: #171d33;
      margin: 0.2rem 1rem 0;
      border: none;
      background: none;
      i {
        display: block;
        opacity: 0;
        width: 4rem;
        height: 2.5px;
        border-radius: 0.4rem;
        background: #009fe2;
        margin: 0 auto;
        position: relative;
        top: 2px;
      }
    }
    button.active {
      i {
        opacity: 1;
      }
    }
  }
  & > button {
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    opacity: 0.8;
    &:hover {
      opacity: 1;
    }
  }
  .changeIt,
  .more {
    color: #009fe2;
    font-size: 1.6rem;
    font-weight: bold;
  }
}
</style>
