<template>
  <div class="im-contacts">
    <div class="contact-left">
      <div class="contact-tab">
        <ul class="contact-list">
          <li class="concat-item" :class="{'active': contactTab === 'friend'}" @click="handleContact('friend')"><span>好友</span><span class="line"></span></li>
          <li class="concat-item" :class="{'active': contactTab === 'group'}" @click="handleContact('group')"><span>群组</span><span class="line"></span></li>
          <li class="hover_line" style="display:none"></li>
        </ul>
      </div>
      <div class="contact-content">
        <GroupList :groups-list="groupsList" :lists="friendsList" v-show="contactTab === 'group'" />
        <FriendList :friends-list="friendsList" v-show="contactTab === 'friend'" />
      </div>
    </div>
    <ContactCard :store="store" :contact="currentContact" :members-list="membersList" />
  </div>
</template>
<script>
  import GroupList from '@/components/GroupList/GroupList'
  import FriendList from '@/components/FriendList/FriendList'
  import ContactCard from '@/components/Contacts/ContactCard'
  export default {
    name: 'Contacts',
    props: {
      membersList: Array,
      groupsList: Array,
      friendsList: Array,
      store: Object,
      //是否需要刷新
      needRef: Boolean
    },
    watch:{
      needRef: function() {
        // debugger
        this.$nextTick(()=>{
          this.needRef = false;
        })
      }
    },
    data () {
      return {
        contactTab: 'friend',
        currentContact: null,
        //是否刷新token
        needRef: false
      }
    },
    methods: {
      //更新数据
      Ref: function(){
        //更新完成数据后，执行后面这句即可
        this.needRef = true;
      },
      //刷新触发
      refOK: function(result) {
        if (result) {
          this.needRef = false;
        }
      },
      handleContact (type) {
        this.contactTab = type
      },
      handleCurrentConcatChange (contact) {
        this.currentContact = contact
        if (contact.type === 'group') {
          this.$emit('on-view-members', contact)
        }
      },
      handleCreateNewGroup (data) {
        this.$emit('on-add-group', data)
      },
      handleOpenChatBox (contact) {
        delete contact.key
        delete contact.label
        this.store.commit('setCurrentChat', contact)
        this.store.commit('setCurrentTab', 'chat')
        this.store.commit('updateChatLogsList', contact)
      }
    },
    components: {
      GroupList,
      FriendList,
      ContactCard
    }
  }
</script>
<style lang="scss" scoped>
  .active{
    border-bottom: 1px solid #07c160;
  }
  .contact-list{
    padding-left: 0px;
    border-bottom: 1px solid #292a2c;
    margin: 0;
  }
  .im-contacts {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
  .contact-left {
    width: 230px;
    height: 100%;
    border-right: 1px solid #e5e5e5;
  }
  .contact-tab {
    height: 40px;
    line-height: 40px;
    box-sizing: border-box;
  }
  .contact-content {
    height: calc(100% - 40px);
    overflow: hidden;
  }
  .concat-item {
    position: relative;
    display: inline-block;
    width: 48%;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
  .line {
    position: absolute;
    display: block;
    bottom: 1px;
    left: 25px;
    width: 60px;
    text-align: center;
  }
  }
  }
</style>
