<template>
  <div class="permanent">
    <ul v-if="list.length > 0" v-infinite-scroll="getData" infinite-scroll-disabled="busy" :infinite-scroll-immediate-check="true"
      infinite-scroll-distance="30">
      <li v-for="(item,i) in list" :key="i">
        <exItem :exData="item" />
      </li>
    </ul>

    <div class="searchNone" style="padding-top: 10px" v-else>
      <img src="@/assets/images/resource/searchNone.svg" alt="" />
      <p>暂时没有数据</p>
    </div>
  </div>

  <teleport to='body'>
    <div class="fnbar">
      <!-- <div class="barsub">
        <mb_select :noradius="true" class="mb_select" @handleOption="handleTab" :value="activeId" :options="yearlist" />
      </div> -->

      <div class="searchimg" v-show="!showInput">
        <img @click="showInput=true" :src="require('@/assets/images/icon/label_search.png')" alt="">
      </div>

      <transition name="fade">
        <div class="searchcon" v-if="showInput">
          <img :src="require('@/assets/images/icon/label_search.png')" alt="">
          <input v-model="searchKey" type="text" placeholder="请输入展览名称">
          <span @click="showInput=false">取消</span>
        </div>
      </transition>
    </div>
  </teleport>
</template>

<script setup>
import { defineProps, onMounted, watch, nextTick, ref } from "vue";
import exItem from "@/components/exItem";
import mb_select from "@/components/mb_select";
import { getExhibitionList } from "@/config/api";


const searchKey = ref("");

const showInput = ref(false)
const busy = ref(false)

const list = ref([]);

let paging = ref({
  pageSize: 10,
  pageNum: 1,
  showSize: 4,
  current: 1,
});

watch(searchKey, () => {
  getData(true)
});

const getData = (reset = null) => {
  if (reset) {
    list.value = []
    busy.value = false
  }
  if (busy.value) {
    return
  }

  getExhibitionList({
    "museumId": 1,
    "pageNum": paging.value.pageNum,
    "pageSize": paging.value.pageSize,
    "searchKey": searchKey.value,
    "type": "end"
  }, data => {
    if (data.data.total <= list.value.length) {
      busy.value = true
      return
    }
    list.value = list.value.concat(data.data.records)
    paging.value.pageNum += 1
  })
}
onMounted(() => {
  getData()
})
</script>

<style lang="scss" scoped>
.permanent {
  width: 90%;
  margin: 10px auto;

  >ul {
    width: 100%;

    >li {
      width: 100%;
      position: relative;

      &::after {
        content: '';
        display: inline-block;
        background: #d9c791;
        height: 1px;
        width: 100%;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
}

.fnbar {
  position: absolute;
  bottom: 20px;
  right: 5%;
  background: var(--main-color);
  z-index: 99;
  width: 56%;
  display: flex;
  align-items: center;
  border-radius: 50px;
  font-size: 0;
  min-height: 40px;

  .barsub {
    width: 80%;
    flex-shrink: 0;
  }

  .searchimg {
    position: absolute;
    right: 20px;

    >img {
      width: 16px;
      height: 16px;
    }
  }

  .searchcon {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 999;
    background: var(--main-color);
    border-radius: 50px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding: 0 10px;
    justify-content: space-around;

    >img {
      width: 20px;
      height: 20px;
    }

    >input {
      width: 100%;
      height: 100%;
      padding-left: 16px;
      color: #fff;

      &::placeholder {
        color: #D2D2D2;
      }
    }

    >span {
      display: inline-block;
      color: var(--font-active);
      width: 30px;
      white-space: nowrap;
    }
  }
}
</style>
