<template>
  <div class="ent-info-list">
    <span class="close" @click="handleClose"></span>
    <span class="title-dialog">企业列表</span>
    <ul class="ent-list" v-if="props.listData.length>0" ref="list">
      <li v-for="item, index in listSlice.value" class="list-item">
        <span>{{ formatIndex(index+1) }}</span>
        <span>{{item.entName}}</span>
      </li>
    </ul>
    <div class="no-data" v-else>
      无数据
    </div>
    <transition name="loading">
      <div class="loading" v-if="showLoading">加载中...</div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'EntInfoList',
}
</script>

<script setup>

  import { defineProps, onMounted, reactive, ref } from 'vue'
  import { useInfiniteScroll } from '@vueuse/core'

  const props = defineProps(['list-data'])

  const listSlice = reactive({value: []})

  onMounted(() => {
    if(props.listData.length>0) {
      listSlice.value = props.listData.slice(0, 20)
    }
  })

  const showLoading = ref(false)

  const list = ref(null)

  useInfiniteScroll(
    list,
    () => {
      // load more
      const length = listSlice.value.length
      if(length<props.listData.length) {
        showLoading.value = true
        setTimeout(() => {
          listSlice.value.push(...props.listData.slice(length, length+20))
          showLoading.value = false
        }, 1000);
      }
    },
    { distance: 10 }
  )

  const emit = defineEmits(['closeEntList'])

  function handleClose() {
    emit('closeEntList')
  }

  function formatIndex(index) {
    return index.toString().padStart(2, '0')
  }

</script>

<style lang="scss" scoped>
.ent-info-list {
  box-sizing: border-box;
  position: absolute;
  top: 60px;
  right: -310px;
  width: 320px;
  height: 754px;
  padding: 25px 15px 25px 25px;
  background: url('@/assets/imgs/page_yyjg/bg-popup.png') no-repeat;
  background-size: 100% 100%;
  overflow: hidden;

  .no-data {
    margin: 330px 10px 0 0;
    text-align: center;
    color: #eee;
  }

  .loading {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    text-align: center;
    color: #ddd;
    font-size: 14px;
    line-height: 40px;
    background: linear-gradient(0deg, rgb(26, 48, 86, 1) 0%, rgba(26, 48, 86, 0.2) 100%);
  }


  .loading-enter-active,.loading-leave-active{
    transition: all 0.2s ease;
  }
  .loading-enter-from,.loading-leave-to {
    opacity: 0;
    transform: translateY(40px);
  }

  .ent-list {
    height: calc(100% - 42px);
    box-sizing: border-box;
    margin-top: 18px;
    overflow-y: auto;

    .list-item {
      display: flex;
      align-items: center;
      margin-bottom: 19px;
      span:nth-child(1) {
        display: inline-block;
        width: 20px;
        margin-right: 18px;
        height: 26px;
        font-size: 18px;
        line-height: 24px;
        font-family: BarlowBold;
        color: #FBFDFF;
        text-shadow: 0px 2px 10px rgba(2,28,34,0.71);
      }
      span:nth-child(2) {
        flex: 1;
        height: 26px;
        margin-right: 15px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 14px;
        font-weight: 400;
        color: #FBFDFF;
        text-shadow: 0px 2px 10px rgba(2,28,34,0.71);
        background: url('@/assets/imgs/page_yyjg/ent-item-bg.png') no-repeat;
        background-size: contain;
        background-position: bottom;
      }
    }
  }

  .close {
    position: absolute;
    top: 18px;
    right: 18px;
    display: block;
    width: 18px;
    height: 18px;
    background: url('@/assets/imgs/common/btn-close.png') no-repeat;
    background-size: 12px 12px;
    background-position: center;
    cursor: pointer;
  }
}
</style>
