<template>
  <div id="title">
    <div class="left">
      <h2>
        <img :src="dataSource.iconUrl" alt="">
        <span>{{ dataSource.title }}</span>
      </h2>
      <div v-if="tagState==='1'" class="tag-box">
        <span :class="[{active:activeIndex === index},'tag']" v-for="(item,index) in tagData" @click="selectItem(item,index)" :key="index">
          {{ item }}
          <i></i>
        </span>
      </div>

    </div>

    <button v-if="btnType === 'edit'" @click="modelVisidle">
      <img src="../../assets/images/systemNav/edit.png" alt="">
    </button>
    <button class="more" v-if="btnType === 'more'" @click="goUserCenter">
      more
    </button>
    <button class="changeIt" v-if="btnType === 'changeIt'" @click="changeItData(i)">
      换一换
    </button>
    <button class="changeIt" v-if="btnType === 'none'"></button>
  </div>
</template>

<script>
export default {
  props: {
    dataSource: {
      type: Object,
      default: () => {}
    },
    btnType: {
      type: String,
      default: () => {}
    },
    tagData: {
      type: Array,
      default: () => {}
    },
    tagState: {
      type: String,
      default: () => {}
    },
    changeItState: {
      type: Number,
      default: () => {}
    }
  },
  data () {
    return {
      activeIndex: 0,
      i: 1
    }
  },
  methods: {
    changeItData (i) {
      this.$emit('changeItData', i)
      if (this.i === 1) {
        this.i = 0
      } else {
        this.i = 1
      }
    },
    selectItem (item, index) {
      this.activeIndex = index
      this.$emit('getPerListData', index)
    },
    modelVisidle () {
      if (this.dataSource.title === '个人工作台') {
        this.$emit('workOk')
      } else if (this.dataSource.title === '常用系统') {
        this.$emit('systemOk')
      }
    },
    goUserCenter () {
      const newPath = this.$router.resolve({ path: '/userCenter' })
      window.open(newPath.href, '_blank')
    }
  }
}
</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;
  border-bottom: 1px solid #eee;
 img{
    width: 2.6rem;
    height: auto;
  }
  .left {
    display: flex;
    align-items: center;
    h2 {
      display: flex;
      align-items: center;
      margin: 0;
      span {
        font-weight: Bold;
        font-size: 2rem;
        line-height: 6rem;
        color: #171d33;
        margin-left: 1rem;
        border: none;
        background: none;
      }
    }
    .tag-box {
      height: 100%;
      margin-left: 4rem;
      .tag {
        font-size: 1.6rem;
        color: #171d33;
        line-height: 6rem;
        text-align: center;
        margin: 0 2rem 0;
        cursor: pointer;
        display: inline-block;
        position: relative;
        top: 1px;
        i {
          display: block;
          opacity: 0;
          width: 2rem;
          height: 2px;
          border-radius: 1px;
          background: rgba(0, 159, 226, 1);
          margin: 0 auto;
        }
      }
      .tag.active {
        color: #009fe2;
        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>
