<template>
  <div class="header-back">
    <m-nav-bar :transparent="true" title="我的下级" style="color: #ffffff" />
    <div class="user-data">
      <m-user-avatar />
      <m-user-name />
    </div>
  </div>
  <van-tabs style="margin: -82px 10px; border-radius: 15px; overflow: hidden">
    <van-tab
      :title="item.title"
      v-for="(item, index) in branchList"
      :key="index"
    >
      <van-search
        class="search"
        shape="round"
        placeholder="请输入下级代理昵称"
        v-model="searchValue"
      />
      <div class="test-scores content-box">
        <table class="table" v-if="item.userList.length > 0">
          <tr>
            <th>头像</th>
            <th>昵称</th>
            <th>绑定时间</th>
          </tr>
          <tr
            v-for="(userInfo, index) in item.userList.filter((userInfo) =>
              userInfo.nickName.includes(searchValue)
            )"
            :key="index"
          >
            <td>
              <van-image
                round
                width="50px"
                height="50px"
                :src="userInfo.headImage"
              />
            </td>
            <td>{{ userInfo.nickName }}</td>
            <td>{{ userInfo.createTime }}</td>
          </tr>
        </table>
        <div v-else style="text-align: center">暂无数据</div>
      </div></van-tab
    >
  </van-tabs>
</template>

<script lang="ts">
import { MyBranchListModel } from "@/dataModel/myBranchList";
import { ref, onBeforeMount } from "vue";

const useMyBranchList = () => {
  const branchList = ref<BranchType.dataInfo[]>([]);
  const myBranchListModel = new MyBranchListModel();
  const setData = async () => {
    const data = await myBranchListModel.getData();
    branchList.value = data;
  };
  setData();
  return {
    branchList,
  };
};
</script>

<script lang="ts" setup>
const { branchList } = useMyBranchList();
const searchValue = ref("");
</script>

<style scoped lang="scss">
.header-back {
  width: 375px;
  padding-bottom: 82px;
  background: linear-gradient(180deg, #498ef5 0%, #4da8e6 100%);
  border-radius: 0px 0px 82px 82px;
  .user-data {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 19px 17px 24px;
    font-size: 23px;
    color: #ffffff;
  }
}
.content-box {
  width: 345px;
  background: #ffffff;
  box-shadow: 0px 0px 8px rgba(124, 129, 136, 0.2);
  border-radius: 10px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 10px;
}
.summary {
  display: flex;
  justify-content: space-around;
  box-sizing: border-box;
  overflow: hidden;
  .search {
    width: 100%;
  }
}
.test-scores {
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 19px;
  color: #0a1a33;
  padding: 15px;
  box-sizing: border-box;
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    th {
      padding: 5px;
      color: #0a1a33;
    }
    td {
      text-align: center;
      padding: 5px;
      color: #8a9099;
    }
    tr {
      &:nth-of-type(n) {
        background: #ffffff;
      }
      &:nth-of-type(2n) {
        background: rgba(73, 142, 245, 0.15);
      }
    }
  }
}
</style>
