<!-- eslint-disable vue/multi-word-component-names -->
<script setup lang='ts'>
import { VolunteerApi } from '@/api/api/volunteerHome';
import { baseIMGUrl } from '@/api/request';
import { showToast } from 'vant';

const active = ref(0)

const router = useRouter()


const searchParames = ref({
  pageNum: 1,
  pageSize: 9999,
  searchKey: '',
  type: ''
} as {
  pageNum: number,
  pageSize: number,
  searchKey: string,
  type: string
})

export type volunteerType = {
  createTime: string,
  creatorId: number,
  creatorName: string,
  dirCode: string,
  fileIds: string,
  id: number,
  name: string,
  publishDate: string,
  rtf: string,
  thumb: string,
  type: string,
  updateTime: string
}

const data = ref([] as volunteerType[])

const goDetai = (id: number) => {
  router.push({ name: 'volunteerDetail', params: { id } });
}

const goApply = () => {
  router.push({ name: 'activeBookApply' });
}

const typesList = ref(['志愿者资讯', '志愿者风采'] as string[])

const getList = async () => {
  searchParames.value.type = typesList.value[active.value]
  const res: any = await VolunteerApi.getVolunteerList(searchParames.value)
  if (res.code == 0) {
    data.value = res.data.records
    console.log(data.value.length, res.data.records)
  } else {
    showToast(res.msg)
  }
}

onBeforeMount(() => {
  getList()
})
</script>

<template>
  <div class='home-box'>
    <!-- <van-tabs v-model:active="active" id="tabs">
      <van-tab v-for="(item, index) in data" :key="index" :name="item.type">
      </van-tab>
    </van-tabs> -->

    <div class="tabs">
      <div class="tab-item" :class="{ active: index === active }" v-for="(item, index) in typesList" :key="item"
        @click="() => { active = index, getList() }">{{ item }}</div>
    </div>

    <div class="tab-content" v-if="data.length > 0">
      <div class="activity-card" v-for="(item, index) in data" :key="index" @click="goDetai(item.id)">
        <img v-show="item.thumb != ''" class="thumb" :src="baseIMGUrl + item.thumb" alt="">
        <div class="bottom-box">
          <div class="name">{{ item.name }}</div>
          <div class="income">了解详情</div>
        </div>
      </div>
    </div>
    <div class="no-data" v-else>
      <img src="@/assets/images/no-data.png" alt="">
      <div class="tips">暂时没有数据</div>
    </div>
    <div class="apply-btn" @click="goApply()">我要报名</div>
  </div>
</template>

<style lang='less' scoped>
* {
  box-sizing: border-box;
}

.home-box {
  width: 100%;
  background: #F7F3E8;
  min-height: 100%;
  overflow: auto;


  .tabs {
    // height: 40px;
    white-space: nowrap;
    overflow-x: auto;
    padding: 15px 10px 10px 0px;
    font-family: 'SourceHanSansCN-Regular';

    &::-webkit-scrollbar {
      display: none;
      /* 或 width: 0; */
    }

    .tab-item {
      margin-left: 10px;
      display: inline-block;
      width: 85px;
      height: 30px;
      float: none;
      font-size: 0.9rem;
      line-height: 30px;
      text-align: center;
      background-color: #F1E9D4;
      border-radius: 5px;
      // box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.3);
      color: rgba(0, 0, 0, 0.8);
      color: #88866F;
    }

    .active {
      background: #9D4F0B;
      color: #F7F3E8;
    }
  }

  .tab-content {
    width: 100%;
    padding: 10px;
    padding-bottom: 100px;


    .activity-card {
      width: 100%;
      background: #FFFDF6;
      border-radius: 15px;
      margin-bottom: 30px;
      box-shadow: 0px 0px 20px 0px rgba(222, 216, 199, 0.6);

      .thumb {
        width: 100%;
        height: 25vh;
        border-radius: 15px 15px 0 0;
      }

      .bottom-box {
        padding: 10px;
        display: flex;
        flex-direction: column;
        align-items: end;

        .name {
          font-size: 1.2em;
          font-weight: bold;
          line-height: 1.3em;
          margin-top: 10px;
          color: #333333;
          width: 100%;
        }

        .income {
          width: 30%;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #9D4F0B;
          line-height: 30px;
          border: 1px solid #9D4F0B;
          border-radius: 50px;
        }

      }


    }
  }

  .no-data {
    width: 100%;
    height: calc(100% - 7vh);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-top: 10%;


    img {
      width: 40%;
    }

    .tips {
      color: #88866F;
      margin-top: 10px;
      font-family: 'SourceHanSansCN-Regular';
    }

  }

  .apply-btn {
    width: 80%;
    max-width: 400px;
    height: 60px;
    border-radius: 50px;
    background: url(@/assets/images/onlineBg.png);
    background-size: 100% 100%;
    color: #F1E9D4;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 3vh;
    display: flex;
    justify-content: center;
    align-items: center;
    letter-spacing: 2px;
    font-weight: bold;
    z-index: 2;
    font-size: 1.3em;
  }
}
</style>