<template>
    <view class="app-container">
        <view class="nav-filter">
            <view class="filter-top" @touchmove.stop.prevent>
                <scroll-view :scroll-x="true" :show-scrollbar="false" class="tab-scroll">
                    <view class="jobs-left">
                        <view
                            class="job button-click"
                            :class="{ active: state.tabIndex === 'all' }"
                            @click="choosePosition('all')"
                        >
                            全部
                        </view>
                        <view
                            class="job button-click"
                            :class="{ active: state.tabIndex === index }"
                            v-for="(item, index) in userInfo.jobTitle"
                            :key="index"
                            @click="choosePosition(index)"
                        >
                            {{ item }}
                        </view>
                    </view>
                </scroll-view>
                <view class="jobs-add button-click" @click="navTo('/pages/search/search')">
                    <uni-icons class="iconsearch" color="#666D7F" type="search" size="18"></uni-icons>
                    <text>搜索</text>
                </view>
            </view>
        </view>
        <view class="cards">
            <scroll-view :scroll-y="true" class="tab-scroll">
                <view class="scroll-content">
                    <custom-waterfalls-flow ref="waterfallsFlowRef" :value="data.list">
                        <template v-slot:default="item">
                            <view class="item">
                                <view class="title">{{ item.title }}</view>
                                <view class="desc">{{ item.desc }}</view>
                            </view>
                        </template>
                    </custom-waterfalls-flow>
                </view>
            </scroll-view>
        </view>
    </view>
</template>

<script setup>
import { reactive, inject, watch, ref, onMounted, watchEffect, nextTick } from 'vue';
const { $api, navTo } = inject('globalFunction');
import { storeToRefs } from 'pinia';
import useUserStore from '@/stores/useUserStore';

const { userInfo } = storeToRefs(useUserStore());
const isLoaded = ref(false);
const waterfallsFlowRef = ref(null);
const state = reactive({
    tabIndex: 'all',
});
const data = reactive({
    list: [
        {
            image: 'https://via.placeholder.com/200x500.png/ff0000',
            title: '我是标题1',
            desc: '描述描述描述描述描述描述描述描述1',
        },
        {
            image: 'https://via.placeholder.com/200x200.png/2878ff',
            title: '我是标题2',
            desc: '描述描述描述描述描述描述描述描述2',
        },
        {
            image: 'https://via.placeholder.com/200x100.png/FFB6C1',
            title: '我是标题3',
            desc: '描述描述描述描述描述描述描述描述3',
        },
        {
            image: 'https://via.placeholder.com/200x300.png/9400D3',
            title: '我是标题4',
            desc: '描述描述描述描述描述描述描述描述4',
        },
        {
            image: 'https://via.placeholder.com/100x240.png/B0E0E6',
            title: '我是标题5',
            desc: '描述描述描述描述描述描述描述描述5',
        },
        {
            image: 'https://via.placeholder.com/140x280.png/7FFFAA',
            title: '我是标题6',
            desc: '描述描述描述描述描述描述描述描述6',
        },
        {
            image: 'https://via.placeholder.com/40x60.png/EEE8AA',
            title: '我是标题7',
            desc: '描述描述描述描述描述描述描述描述7',
        },
        {
            image: 'https://via.placeholder.com/140x280.png/7FFFAA',
            title: '我是标题6',
            desc: '描述描述描述描述描述描述描述描述6',
        },
        {
            image: 'https://via.placeholder.com/40x60.png/EEE8AA',
            title: '我是标题7',
            desc: '描述描述描述描述描述描述描述描述7',
        },
    ],
});

async function loadData() {
    try {
        if (isLoaded.value) return;
        isLoaded.value = true;
    } catch (err) {
        isLoaded.value = false; // 重置状态允许重试
        throw err;
    }
}

async function choosePosition() {}

defineExpose({ loadData });
</script>

<style lang="stylus" scoped>
.app-container
    width: 100%;
    height: calc(100vh - var(--window-top) - var(--status-bar-height) - var(--window-bottom));
    background: url('@/static/icon/background2.png') 0 0 no-repeat;
    background-size: 100% 728rpx;
    // background-color: #FFFFFF;
    display: flex;
    flex-direction: column
    .cards
        flex: 1;
        overflow: hidden;
        .tab-scroll
            height: 100%;
            white-space: nowrap;
            text-overflow: clip;
            .scroll-content{
                padding: 24rpx
            }

.nav-filter
    padding: 16rpx 28rpx 30rpx 28rpx
    .filter-top
        display: flex
        justify-content: space-between;
        .tab-scroll
            flex: 1;
            overflow: hidden;
            margin-right: 20rpx
            white-space: nowrap;
            overflow: hidden;
            text-overflow: clip;
            -webkit-mask-image: linear-gradient(to right, black 60%, transparent);
            mask-image: linear-gradient(to right, black 60%, transparent);
            .jobs-left
                display: flex
                flex-wrap: nowrap
                .job
                    font-weight: 400;
                    font-size: 36rpx;
                    color: #666D7F;
                    margin-right: 32rpx;
                    white-space: nowrap
                .active
                    font-weight: 500;
                    font-size: 36rpx;
                    color: #000000;
        .jobs-add
            display: flex
            align-items: center;
            justify-content: center;
            font-weight: 400;
            font-size: 32rpx;
            color: #666D7F;
            line-height: 38rpx;
    .filter-bottom
        display: flex
        justify-content: space-between
        padding: 24rpx 0
        .btm-left
            display: flex
            .filterbtm
                font-weight: 400;
                font-size: 32rpx;
                color: #666D7F;
                margin-right: 24rpx
                padding: 0rpx 16rpx
            .active
                font-weight: 500;
                font-size: 32rpx;
                color: #256BFA;
        .btm-right
            font-weight: 400;
            font-size: 32rpx;
            color: #6C7282;
            .right-sx
                width: 26rpx;
                height: 26rpx;
            .active
                transform: rotate(180deg)
</style>
