<script setup lang='ts'>
import { ActiveBookingApi } from '@/api/api/activeBooking';
import { showToast } from 'vant';

const active = ref(0)

const router = useRouter()

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

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


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

const allData = ref([] as activeType[])

const typeList = ref([] as any)

const getList = async () => {
  const res: any = await ActiveBookingApi.getActiveList(searchParames.value)
  if (res.code == 0) {
    allData.value = res.data.records
    const types = res.data.records.map((item: any) => {
      return item.type
    })
    typeList.value = [...new Set(types)]
    data.value = allData.value.filter((item: any) => {
      return item.type == typeList.value[active.value]
    })
  } else {
    showToast(res.msg)
  }
}


const goDetai = (id: number) => {
  router.push({ name: 'activeDetail', params: { id } });
}
watch(active, () => {
  data.value = allData.value.filter((item: any) => {
    return item.type == typeList.value[active.value]
  })
})

onMounted(() => {
  getList()
})

</script>

<template>
  <div class='activeBooking'>

    <div class="tabs">
      <div class="tab-item" :class="{ active: index === active }" v-for="(item, index) in typeList" :key="index"
        @click="active = index">{{ 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="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>
</template>

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

.activeBooking {
  width: 100%;
  background: #F7F3E8;
  min-height: 100%;

  .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: 20px;
    max-height: calc(100vh - 8vh);
    overflow: auto;
    background: #F7F3E8;



    .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%;
        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';
    }

  }
}
</style>