<template>
  <el-tabs v-model="activeTabName" type="border-card">
    <el-tab-pane label="企业方" name="first">
      <div>
        <div class="content" v-if="comChatUsers && comChatUsers.list">
          <el-table :data="comChatUsers.list" border>
            <el-table-column :className="`clickable`" prop="username" label="企业名称" width="400">
              <template slot-scope="scope">
                <span @click="goCompany(scope.row)">{{scope.row.username}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="lastChatTimeFormat" label="最近聊天" width="160"></el-table-column>
            <el-table-column prop="totalChatTime" label="总计聊天时长" width="160"></el-table-column>
            <el-table-column prop="totalChatUsers" label="总计聊天用户数" width="120"></el-table-column>
            <el-table-column prop="totalSendMessage" label="总计发送消息数" width="120"></el-table-column>
          </el-table>
        </div>
        <el-pagination
          class="order-footer"
          background
          layout="prev, pager, next"
          :page-size="20"
          :total="Number(comChatUsers.total)"
          @current-change="handleCurrentChangeCom"
        />
      </div>
    </el-tab-pane>
    <el-tab-pane label="开发者" name="second">
      <div>
        <div class="content" v-if="devChatUsers && devChatUsers.list">
          <el-table :data="devChatUsers.list" border>
            <el-table-column :className="`clickable`" prop="username" label="开发者名称" width="400">
              <template slot-scope="scope">
                <span @click="goRooterUser(scope.row)">{{scope.row.username}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="lastChatTimeFormat" label="最近聊天" width="160"></el-table-column>
            <el-table-column prop="totalChatTime" label="总计聊天时长" width="160"></el-table-column>
            <el-table-column prop="totalChatUsers" label="总计聊天用户数" width="120"></el-table-column>
            <el-table-column prop="totalSendMessage" label="总计发送消息数" width="120"></el-table-column>
          </el-table>
        </div>
        <el-pagination
          class="order-footer"
          background
          layout="prev, pager, next"
          :page-size="20"
          :total="Number(devChatUsers.total)"
          @current-change="handleCurrentChangeDev"
        />
      </div>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
export default {
  data() {
    return {
      activeTabName: "first",
      pageDev: 1,
      pageCom: 1,
      devChatUsers: "",
      comChatUsers: ""
    };
  },
  mounted() {
    this.getDevChatUsers();
    this.getComChatUsers();
  },
  methods: {
    async getDevChatUsers() {
      const page = this.pageDev;
      const homePageType = 2;
      const data = {
        page,
        homePageType
      };
      let res = await this.$post("/api/admin/chat/chatUsers", data);
      if (res && res.status === 1) {
        this.devChatUsers = res.data;
        console.log(this.devChatUsers);
      }
    },
    async getComChatUsers() {
      const page = this.pageCom;
      const homePageType = 1;
      const data = {
        page,
        homePageType
      };
      let res = await this.$post("/api/admin/chat/chatUsers", data);
      if (res && res.status === 1) {
        this.comChatUsers = res.data;
        console.log(this.comChatUsers);
      }
    },
    handleCurrentChangeCom(val) {
      this.pageCom = val;
      this.getComChatUsers();
    },
    handleCurrentChangeDev(val) {
      this.pageDev = val;
      this.getDevChatUsers();
    },
    goCompany(row) {
      window.open(
        this.$store.state.domainConfig.siteUrl + `/company/${row.uid}`
      );
    },
    goRooterUser() {
      window.open(
        this.$store.state.domainConfig.siteUrl + `/rooter/user/${row.uid}`
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.count-list {
  padding-bottom: 10px;
  display: flex;
  align-items: center;
}

.count-item {
  margin-right: 20px;
  font-size: 16px;
}

.content {
  white-space: nowrap;
  overflow-x: hidden;
}

.btn {
  width: 80px;
}

.order-footer {
  margin-top: 10px;
}
.clickable {
  cursor: pointer;
  color: #409eff;
}
</style>
