<template>
    <view v-for="job in listData" :key="job.id">
        <view v-if="!job.isTitle" class="cards" @click="nextDetail(job)">
            <view class="card-company">
                <text class="company">{{ job.jobTitle }}</text>
                <view class="salary">
                    <Salary-Expectation :max-salary="job.maxSalary" :min-salary="job.minSalary"></Salary-Expectation>
                </view>
            </view>
            <view class="card-companyName">{{ job.companyName }}</view>
            <view class="card-tags">
                <view class="tag">
                    <dict-Label dictType="education" :value="job.education"></dict-Label>
                </view>
                <view class="tag">
                    <dict-Label dictType="experience" :value="job.experience"></dict-Label>
                </view>
                <view class="tag">
                    {{ vacanciesTo(job.vacancies) }}
                </view>
            </view>
            <view class="card-bottom">
                <view>{{ job.postingDate }}</view>
                <view>
                    <convert-distance
                        :alat="job.latitude"
                        :along="job.longitude"
                        :blat="latitude"
                        :blong="longitude"
                    ></convert-distance>
                    {{ job.regionName || config.appInfo.areaName }}
                </view>
            </view>
        </view>
        <view class="date-jobTitle" v-else>
            {{ job.title }}
        </view>
    </view>
</template>

<script setup>
import { inject, computed, toRaw } from 'vue';
import config from '@/config.js';
const { insertSortData, navTo, vacanciesTo } = inject('globalFunction');
import { useRecommedIndexedDBStore } from '@/stores/useRecommedIndexedDBStore.js';
const recommedIndexDb = useRecommedIndexedDBStore();
const props = defineProps({
    list: {
        type: Array,
        default: '标题',
    },
    longitude: {
        type: Number,
        default: 120.382665,
    },
    latitude: {
        type: Number,
        default: 36.066938,
    },
    seeDate: {
        type: String,
        default: '',
    },
});

const listData = computed(() => {
    if (props.seeDate && props.list.length) {
        const ulist = toRaw(props.list);
        const [reslist, lastDate] = insertSortData(ulist, props.seeDate);
        return reslist;
    }
    return props.list;
});

function nextDetail(job) {
    // 记录岗位类型，用作数据分析
    if (job.jobCategory) {
        const recordData = recommedIndexDb.JobParameter(job);
        recommedIndexDb.addRecord(recordData);
    }
    navTo(`/packageA/pages/post/post?jobId=${encodeURIComponent(job.jobId)}&encryptJobId=${encodeURIComponent(job.encryptJobId)}`);
}
</script>

<style lang="stylus" scoped>
.date-jobTitle{
    font-weight: 400;
    font-size: 28rpx;
    color: #495265;
    padding: 28rpx 0 0 20rpx
}
.cards{
    padding: 32rpx;
    background: #FFFFFF;
    box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0,0,0,0.04);
    border-radius: 20rpx 20rpx 20rpx 20rpx;
    margin-top: 22rpx;
    .card-company{
        display: flex
        justify-content: space-between
        align-items: flex-start
        .company{
            font-family: 'PingFangSC-Medium', 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', sans-serif;
            font-weight: 500;
            font-size: 32rpx;
            color: #333333;
        }
        .salary{
            font-family: DIN-Medium;
            font-weight: 500;
            font-size: 28rpx;
            color: #4C6EFB;
            white-space: nowrap
            line-height: 48rpx
        }
    }
    .card-companyName{
        font-weight: 400;
        font-size: 28rpx;
        color: #6C7282;
    }
    .card-tags{
        display: flex
        flex-wrap: wrap
        .tag{
            font-family: 'PingFangSC-Medium', 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', sans-serif;
            width: fit-content;
            height: 30rpx;
            background: #F4F4F4;
            border-radius: 4rpx;
            padding: 6rpx 20rpx;
            line-height: 30rpx;
            font-weight: 400;
            font-size: 24rpx;
            color: #6C7282;
            text-align: center;
            margin-top: 14rpx;
            white-space: nowrap
            margin-right: 20rpx
        }
    }
    .card-bottom{
        margin-top: 32rpx
        display: flex
        justify-content: space-between
        font-size: 28rpx;
        color: #6C7282;
    }
}
</style>
