<template>
  <view class="box defaultBgc">
    <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="getData" @refresherrefresh="refresh" style="position:relative;">
      <uni-search-bar
        class="ss-flex-1 white-bgc"
        radius="8"
        placeholder="请输入关键字"
        cancelButton="none"
        :focus="false"
        @confirm="onSearch($event.value)"
      />
      <view class="block">
        <SwiperAd class="pb-20" :list="swiperAdList"></SwiperAd>
        <FilterList class="pb-10" :list="filterList" idValue="label"></FilterList>
      </view>
      <PositionList class="pb-10" :list="positionListData" :noMore="noMore"></PositionList>
    </scroll-view>
  </view>
</template>

<script setup>
import SwiperAd from '@/components/SwiperAd'
// import SearchBar from '@/components/SearchBar'
import FilterList from '@/components/FilterList'
import PositionList from '@/components/PositionList'
import { positionList, swiperAdListTest } from '@/utils/testData'
import { ref } from 'vue'

const swiperAdList = ref(swiperAdListTest)
const filterList = ref([
  { label: '行业' },
  { label: '城市' },
  { label: '工作性质' },
  { label: '月薪范围' },
  { label: '工作经验' },
])

// 
const positionListData = ref([])
const noMore = ref(false)
let page = { pageSize: 8, pageNo: 1 }
//
const getData = (name) => {
  if (positionListData.value.length > 30) return noMore.value = true
  positionListData.value = positionListData.value.concat(positionList)
}
getData()

const onSearch = (name) => {
  page.pageNo = 1
  positionListData.value = []
  getData(name)
}

const refresh = () => {
  page.pageNo++
  getData()
}


</script>

<style scoped lang="scss">
.pb-10 { padding-bottom: 10px; }
.pb-20 { padding-bottom: 20px; }
.box {
  height: calc(100vh - 110px);
  overflow: hidden;
  .block{
    margin-bottom: 10px;
    padding: 0 10px;
    background-color: #fff;
  }
}
.scrollBox{
  height: 100%;
}
</style>
