<template>
    <AppLayout :show-bg-image="false" :use-scroll-view="false">
        <view class="collection-content">
            <scroll-view scroll-y class="main-scroll" @scrolltolower="getJobList('add')">
                <view class="one-cards">
                    <view class="mian">
                        <renderJobs
                            seeDate="shareTime"
                            v-if="pageState.list.length"
                            :list="pageState.list"
                            :longitude="longitudeVal"
                            :latitude="latitudeVal"
                        ></renderJobs>
                        <empty v-else pdTop="200"></empty>
                    </view>
                </view>
            </scroll-view>
        </view>
    </AppLayout>
</template>

<script setup>
import dictLabel from '@/components/dict-Label/dict-Label.vue';
import AppLayout from '@/components/AppLayout/AppLayout.vue';
import { reactive, inject, watch, ref, onMounted } from 'vue';
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app';
import useUserStore from '@/stores/useUserStore';
const { $api, navTo, vacanciesTo } = inject('globalFunction');
import { storeToRefs } from 'pinia';
import useLocationStore from '@/stores/useLocationStore';
const { longitudeVal, latitudeVal } = storeToRefs(useLocationStore());
const userStore = useUserStore();
const state = reactive({});
const pageState = reactive({
    page: 0,
    list: [],
    total: 0,
    maxPage: 1,
    pageSize: 10,
});
onLoad(() => {
    console.log('onLoad');
    getJobList('refresh');
});

onReachBottom(() => {
    getJobList();
});

function navToPost(job) {
    navTo(`/packageA/pages/post/post?jobId=${encodeURIComponent(job.jobId)}&encryptJobId=${encodeURIComponent(job.encryptJobId)}`);
}

function getJobList(type = 'add') {
    if (type === 'refresh') {
        pageState.page = 1;
        pageState.maxPage = 1;
    }
    if (type === 'add' && pageState.page < pageState.maxPage) {
        pageState.page += 1;
    }
    let params = {
        current: pageState.page,
        pageSize: pageState.pageSize,
    };
    $api.createRequest('/app/job/selectCencalList', params, 'GET').then((resData) => {
        const { rows, total } = resData;
        if (type === 'add') {
            const str = pageState.pageSize * (pageState.page - 1);
            const end = pageState.list.length;
            const reslist = rows;
            pageState.list.splice(str, end, ...reslist);
        } else {
            pageState.list = rows;
        }
        pageState.total = resData.total;
        pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
        console.log(pageState.list);
    });
}
</script>

<style lang="stylus" scoped>
.collection-content
    height: 100%
    display: flex
    flex-direction: column

.main-scroll{
    flex: 1
    overflow: hidden
}

.one-cards{
    padding: 0 28rpx 20rpx 28rpx;
    background: #f4f4f4

}
</style>