<template>
    <AppLayout
        title="投递记录"
        :use-scroll-view="true"
        mainback-ground-color="#f4f4f4"
        :show-bg-image="false"
        @onScrollBottom="getJobList()"
    >
        <template #headerleft v-if="isMiniProgram">
            <view class="btnback">
                <image src="@/static/icon/back.png" @click="navBack"></image>
            </view>
        </template>
        <view class="collection-content">
            <renderDeliveryRecord
                v-if="pageState.list.length"
                seeDate="applyTime"
                :list="pageState.list"
                :longitude="longitudeVal"
                :latitude="latitudeVal"
            ></renderDeliveryRecord>
            <empty v-else :is-position="true"></empty>
        </view>
    </AppLayout>
</template>

<script setup>
import dictLabel from '@/components/dict-Label/dict-Label.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, navBack } = inject('globalFunction');
import { storeToRefs } from 'pinia';
import useLocationStore from '@/stores/useLocationStore';
const { longitudeVal, latitudeVal } = storeToRefs(useLocationStore());
const userStore = useUserStore();
const { isMiniProgram } = storeToRefs(useUserStore());
const state = reactive({});
const pageState = reactive({
    page: 0,
    list: [],
    total: 0,
    maxPage: 1,
    pageSize: 10,
});
onLoad(() => {
    console.log('onLoad');
    // $api.sleep(2000).then(() => {
    //     navTo('/pages/login/login');
    // });
    getJobList();
});

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,
    };
    const LoadCache = (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.list = resData.rows;
        pageState.total = resData.total;
        pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
    };

    $api.createRequestWithCache('/app/user/apply/job', params, 'GET', false, {}, LoadCache).then(LoadCache);
}
</script>

<style lang="stylus" scoped>
.btnback{
    width: 64rpx;
    height: 64rpx;
}
image {
    height: 100%;
    width: 100%;
}
.collection-content{
    padding: 1rpx 28rpx 20rpx 28rpx;
    background: #F4F4F4;
    height: 100%;
    position: relative;
}
</style>
