<template>
  <div class="chat-list">
    <div class="top-search">
      <i class="meechat-icon"></i>
      <input type="text" class="search-wrap" @input="searchUser($event, sessionList)" @blur="handleBlur" v-focus v-if="searchShow">
      <div class="search-tips search-wrap" @click="searchShow = true" v-else>
        <i class="el-icon-search"></i>搜索
      </div>
      <i class="add-icon"></i>
    </div>
    <div class="chat-list pub-scroll-box">
      <template v-if="!isSearch">
        <session-item
          v-for="(item, index) in sessionList"
          :key="index"
          :item="item"
          :isMoblie="true">
        </session-item>
      </template>
      <template v-else>
        <session-item
          v-for="(item, index) in searchList"
          :key="index"
          :item="item"
          :isMoblie="true">
        </session-item>
      </template>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import sessionItem from '@/components/panel/sessionItem'
import { searchUserMixin } from '@/mixins'

export default {
  name: 'chatList',
  mixins: [searchUserMixin],
  components: {
    sessionItem
  },
  data () {
    return {
      searchShow: false
    }
  },
  computed: {
    ...mapState({
      sessionList: state => state.chat.sessionList,
      userInfo: state => state.userInfo
    })
  },
  methods: {
    handleBlur (e) {
      let val = e.target.value
      if (!val) {
        this.searchShow = false
      }
    }
  },
  created () {
    this.$store.dispatch('getSessionList')
    this.$store.dispatch('getUserInfo')
  }
}
</script>

<style lang="scss" scoped>
.chat-list{
  background-color: #ffffff;
  overflow-x: hidden;
}
.top-search{
  height: px2rem(88);
  background-color: #f2f2f2;
  display: flex;
  align-items: center;
  > i{
    margin: 0 px2rem(20);
  }
  .search-wrap{
    flex: 1;
    background-color: #ffffff;
    border-radius: 4px;
    border: 1px solid #eeeeee;
    height: px2rem(58);
    line-height: px2rem(58);
    box-sizing: border-box;
    font-size: px2rem(28);
  }
  input{
    padding-left: px2rem(10);
    font-size: px2rem(28);
    color: #666666;
  }
}
.meechat-icon{
  background: url('../../../assets/h5/meechat-logo.png');
  width: px2rem(42);
  height: px2rem(51);
  background-size: 100%;
}
.add-icon{
  background: url('../../../assets/more-icon.png');
  width: px2rem(42);
  height: px2rem(42);
  background-size: 100%;
}
.search-tips{
  text-align: center;
  color: #8e8e93;
  i{
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
    font-size: px2rem(36);
  }
}
</style>
