<template>
  <div class="list-wrap">
    <div class="search">
      <el-input
        v-model="params.userName"
        size="mini"
        placeholder="请输入用户昵称"
        clearable
      />
      <el-button type="primary" size="mini" @click="searchMsg">搜索</el-button>
    </div>
    <userItems
      :group-id="groupId"
      :list="list"
      :loading="loading"
      :has-next="hasNext"
      @getList="getList"
      @toPrivateChat="toPrivateChat"
      @modifyStateCallback="modifyStateCallback"
    />
  </div>
</template>
<script>
import { queryCommentBlackList } from "@/api/videoLive";
import userItems from "./components/userItems.vue";
export default {
  components: {
    userItems
  },
  props: {
    groupId: {
      type: Number,
      default: null
    },
    modifyStateObj: {
      // 修改了状态的对象
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      loading: true,
      hasNext: true,
      params: {
        size: 10,
        current: 1,
        productId: this.groupId,
        userName: "",
        productType: 41,
        status: 0,
        userType: 3 // 作为何种角色访问 1:投顾 2:运营(非投顾) 3:忽略数据权限
      },
      list: [],
      userIdsObj: {}
    };
  },
  watch: {
    groupId(value) {
      this.params.productId = value;
      this.params.userName = "";
      this.searchMsg();
    },
    modifyStateObj(value) {
      // modifyType: 1审核通过 2禁言操作
      if (value.modifyType === 2) {
        this.searchMsg();
      }
    }
  },
  methods: {
    modifyStateCallback(item) {
      this.$emit("modifyStateCallback", item);
    },
    async getList() {
      this.loading = true;
      this.params.current++;
      const ret = await queryCommentBlackList(this.params).catch(() => {
        this.loading = false;
      });

      if (ret && ret.code === 0 && ret.data.list) {
        const list = ret.data.list;
        list.forEach(item => {
          item.userId = item.phone;
          item.nickName = item.userName;
          item.isForbidden = 1;
          item.joinTime = item.startTime;
          item.expireTime = item.endTime;
          item.userHeadPicUrl = item.userHeadPic; // 用户头像
          this.userIdsObj[item.userId] = item;
        });
        this.list = this.list.concat(list);
        this.hasNext = ret.data.list.length === this.params.size;
      }
      this.loading = false;
    },
    searchMsg() {
      this.params.lastId = "";
      this.hasNext = true;
      this.params.current = 0;
      this.list = [];
      this.getList();
    },
    toPrivateChat(item) {
      this.$emit("toPrivateChat", item);
    }
  }
};
</script>
<style lang="scss" scoped>
.list-wrap {
  height: 600px;
  overflow-y: scroll;
}
.search {
  display: flex;
  margin-bottom: 10px;
  .el-input {
    margin-right: 10px;
  }
}
dl {
  list-style: none;
  margin: 0;
  padding: 0;
  list-style: none;
  padding: 10px;
  dt {
    padding: 10px 0;
  }
  dd {
    margin: 0;
    padding: 0;
  }
  dt,
  dd {
    display: flex;
    border-bottom: 1px dashed #999;
    & > div {
      display: flex;
      // flex-direction: column;
      justify-content: center;
      padding: 6px 0;
      align-items: center;
    }
    & > div:nth-child(1) {
      width: 60px;
    }
    & > div:nth-child(2) {
      flex: 1;
      text-align: center;
    }
    & > div:nth-child(3) {
      width: 100px;
      text-align: center;
    }
    & > div:nth-child(4) {
      width: 100px;
      text-align: center;
    }
    & > div:nth-child(5) {
      display: block;
      width: 60px;
      text-align: right;
      & > div {
        text-align: right;
      }
    }
    p {
      font-size: 14px;
      margin: 0;
      line-height: 16px;
    }
    ::v-deep .el-button--medium {
      padding: 4px 8px;
    }
    img {
      width: 36px;
      height: 36px;
      border-radius: 50%;
    }
  }
}
</style>
