<template>
  <div class="add-person">
    <back-bar :title="$t('h5.selectContact')">
      <button class="opt-btn opt-del" v-if="inviteType==3" @click="optSubmit">{{$t('group.delete')}}</button>
      <button class="opt-btn" v-else @click="optSubmit">{{inviteType==1 ? $t('h5.createGroup') : $t('public.complete')}}</button>
    </back-bar>
    <div class="input-wrap" v-if="inviteType==1">
      <input v-focus v-model="groupName" type="text" :placeholder="$t('invite.writeGroupName')">
    </div>
    <div class="input-wrap" v-else>
      <i class="el-icon-search"></i>
      <input type="text" @input="searchUser($event, checkList)" :placeholder="$t('invite.searchContact')">
    </div>
    <div>
        <template v-if="showNum>0 && !isSearchGroup">
          <div v-for="(item, key) in checkList"
            :key="key">
            <div class="user-item"
              :class="{'checked': item.isChecked}"
              @click="changeStateForH5(item.user_id)"
              v-show="item.isShow">
              <i v-if="item.isChecked" class="el-icon-circle-check is-choosed"></i>
              <i v-else class="el-icon-circle-uncheck"></i>
              <img v-if="item.cover_photo" class="user-avatar" :src="item.cover_photo" alt>
              <div
                v-else
                class="user-avatar"
                :class="`avatar_bg${item.user_id % 9}`"
                :data-name="item.nick_name.slice(0,2).toUpperCase()"
              ></div>
              <span class="name">{{item.nick_name}}</span>
            </div>
          </div>
        </template>
        <div class="no-data" v-else>{{$t('invite.noContact')}}</div>
    </div>
  </div>
</template>

<script>
import backBar from '@/components/backBar'
import { groupInviteMixins } from '@/mixins/group'
import { getUrlParam } from '@/util/util'

export default {
  name: 'chatInvite',
  mixins: [groupInviteMixins],
  data () {
    return {
      inviteType: this.$route.params.inviteType * 1,
      ext: {
        tgGroupId: getUrlParam('tgGroupId') || ''
      }
    }
  },
  components: {
    backBar
  },
  computed: {},
  methods: {},
  async created () {
    let groupId = this.$route.params.id
    if (!this.group.groupId && groupId) {
      this.initGroup({
        groupId: groupId,
        useCache: false
      })
      this.changeSessionId(groupId)
      await this.getGroupInfo()
    }
  }
}
</script>

<style lang="scss" scoped>
.add-person {
  background-color: #ffffff;
}
.opt-btn {
  position: absolute;
  top: px2rem(14);
  right: px2rem(10);
  background-color: #279bf3;
  height: px2rem(58);
  line-height: px2rem(58);
  padding: 0 px2rem(26);
  font-size: px2rem(30);
  color: #ffffff;
  border-radius: 4px;
  &.opt-del{
    background-color: #e25151;
  }
}
.input-wrap {
  background-color: #ffffff;
  height: px2rem(100);
  line-height: px2rem(100);
  position: relative;
  padding-left: px2rem(80);
  border-bottom: 1px solid #eeeeee;
  .el-icon-search {
    position: absolute;
    left: 0;
    top: px2rem(36);
    width: px2rem(80);
    height: px2rem(40);
    text-align: center;
    bottom: 0;
    vertical-align: middle;
    color: #999;
    font-size: px2rem(40);
  }
  input {
    height: px2rem(70);
    line-height: px2rem(70);
    padding-left: px2rem(12);
    width: 100%;
    font-size: px2rem(28);
    outline: none;
    box-sizing: border-box;
    border: 0;
  }
}
.user-item {
  border-bottom: 1px solid #eeeeee;
  padding: px2rem(20) px2rem(20) px2rem(20) 0;
  display: flex;
  align-items: center;
  .name {
    flex: 1;
    display: inline-block;
    margin-left: px2rem(20);
    font-size: px2rem(34);
    color: #333333;
  }
}
.no-data{
    text-align: center;
    color: #999999;
    line-height: px2rem(500);
    font-size: 12px;
}
.el-icon-circle-uncheck,.el-icon-circle-check {
  display: inline-block;
  vertical-align: middle;
  width: px2rem(44);
  height: px2rem(44);
  margin: 0 px2rem(26);
}
.el-icon-circle-check{
  color: #279bf3;
}
</style>
