<template>
    <view class="collection-content">
        <view class="one-cards">
            <view class="card-box" v-for="(item, index) in pageState.list" :key="index" @click="navToPost(item.jobId)">
                <view class="box-row mar_top0">
                    <view class="row-left">{{ item.jobTitle }}</view>
                    <view class="row-right">
                        <Salary-Expectation
                            :max-salary="item.maxSalary"
                            :min-salary="item.minSalary"
                        ></Salary-Expectation>
                    </view>
                </view>
                <view class="box-row">
                    <view class="row-left">
                        <view class="row-tag" v-if="item.educatio">
                            <dict-Label dictType="education" :value="item.education"></dict-Label>
                        </view>
                        <view class="row-tag" v-if="item.experience">
                            <dict-Label dictType="experience" :value="item.experience"></dict-Label>
                        </view>
                    </view>
                </view>
                <view class="box-row mar_top0">
                    <view class="row-item mineText">{{ item.postingDate || '发布日期' }}</view>
                    <view class="row-item mineText">{{ vacanciesTo(item.vacancies) }}</view>
                    <view class="row-item mineText textblue"><matchingDegree :job="item"></matchingDegree></view>
                    <view class="row-item">
                        <!-- <uni-icons type="star" size="28"></uni-icons> -->
                        <!-- <uni-icons type="star-filled" color="#FFCB47" size="30"></uni-icons> -->
                    </view>
                </view>
                <view class="box-row">
                    <view class="row-left mineText">{{ item.companyName }}</view>
                    <view class="row-right mineText">
                        青岛
                        <dict-Label dictType="area" :value="item.jobLocationAreaCode"></dict-Label>
                        <!-- 550m -->
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script setup>
import img from '/static/icon/filter.png';
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 } = inject('globalFunction');
const userStore = useUserStore();
const state = reactive({});
const pageState = reactive({
    page: 0,
    list: [],
    total: 0,
    maxPage: 1,
    pageSize: 10,
});
onLoad(() => {
    getJobList();
});

onReachBottom(() => {
    getJobList();
});
function navToPost(jobId) {
    navTo(`/packageA/pages/post/post?jobId=${btoa(jobId)}`);
}

function getJobList(type = 'add') {
    if (type === 'refresh') {
        pageState.page = 0;
        pageState.maxPage = 1;
    }
    if (type === 'add' && pageState.page < pageState.maxPage) {
        pageState.page += 1;
    }
    let params = {
        current: pageState.page,
        pageSize: pageState.pageSize,
    };
    $api.createRequest('/app/user/collection/job', params).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.list = resData.rows;
        pageState.total = resData.total;
        pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
    });
}
</script>

<style lang="stylus">
.collection-content
    padding: 20rpx 0 20rpx 0;
.one-cards
    display: flex;
    flex-direction: column;
    padding: 0 20rpx;
    .card-box
        width: calc(100% - 36rpx - 36rpx);
        border-radius: 0rpx 0rpx 0rpx 0rpx;
        background: #FFFFFF;
        border-radius: 17rpx;
        padding: 15rpx 36rpx;
        margin-top: 24rpx;
        .box-row
            display: flex;
            justify-content: space-between;
            margin-top: 8rpx;
            align-items: center;
            .mineText
                font-weight: 400;
                font-size: 21rpx;
                color: #606060;
            .textblue
                color: #4778EC;
            .row-left
                display: flex;
                justify-content: space-between;
                .row-tag
                    background: #13C57C;
                    border-radius: 17rpx 17rpx 17rpx 17rpx;
                    font-size: 21rpx;
                    color: #FFFFFF;
                    line-height: 25rpx;
                    text-align: center;
                    padding: 4rpx 8rpx;
                    margin-right: 23rpx;
    .card-box:first-child
        margin-top: 6rpx;
</style>
