<template>
    <div class="filter" :style="{ paddingTop: statusBarHeight + 'px' }" id="filter" v-if="show">
        <div class="menu" v-if="false">
            <p v-for="v in menuList" :class="{ active: v.active }" :key="v.name" @click="onClickMenu(v)">{{ v.name }}</p>
        </div>
        <div class="content">
            <!-- 学历要求 -->
            <div class="filter-item education">
                <p class="title">学历</p>
                <div class="filter-select">
                    <div
                        class="select-item"
                        :class="{ active: v.active }"
                        @click="onClickEducation(v)"
                        v-for="(v, i) in educationList"
                        :key="i"
                    >
                        {{ v.text }}
                    </div>
                </div>
            </div>
            <!-- 年龄要求 -->
            <div class="filter-item age">
                <p class="title" style="margin-top: 0">年龄</p>
                <wd-slider
                    style="margin: 0 75rpx"
                    v-model="age"
                    :step="1"
                    hide-min-max
                    :max="100"
                    inactive-color="rgba(31, 134, 255,0.3)"
                    active-color="rgba(31, 134, 255,1)"
                />
            </div>
            <!-- 性别要求 -->
            <div class="filter-item gender">
                <p class="title">性别</p>
                <div class="filter-select">
                    <div
                        class="select-item"
                        :class="{ active: v.active }"
                        @click="onClickGender(v)"
                        v-for="(v, i) in genderList"
                        :key="i"
                    >
                        {{ v.text }}
                    </div>
                </div>
            </div>
            <!-- 工作年限要求 -->
            <div class="filter-item workYear">
                <p class="title">工作年限</p>
                <div class="filter-select">
                    <div
                        class="select-item"
                        :class="{ active: v.active }"
                        @click="onClickWorkYear(v)"
                        v-for="(v, i) in workYearList"
                        :key="i"
                    >
                        {{ v.text }}
                    </div>
                </div>
            </div>
            <!-- 专业要求 -->
            <div class="filter-item major" v-if="false">
                <p class="title">专业要求</p>
                <div class="filter-select">
                    <div
                        class="select-item"
                        :class="{ active: v.active }"
                        @click="onClickMajor(v)"
                        v-for="(v, i) in dictJobTypeList"
                        :key="i"
                    >
                        {{ v.name }}
                    </div>
                </div>
            </div>
            <!-- 专业 -->
            <div class="filter-item certificate">
                <p class="title">学历</p>
                <div class="filter-select">
                    <div
                        class="select-item"
                        :class="{ active: v.active }"
                        @click="onClickCertificate(v)"
                        v-for="(v, i) in certificateList"
                        :key="i"
                    >
                        {{ v.name }}
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom-wrap">
            <button class="cancel" @click="onCancel">重置</button>
            <button class="confirm" @click="onConfirm">确认</button>
        </div>
    </div>
</template>

<script setup>
import { getEumData } from "@/utils/utils";
import { dictJobTypeApi } from "@/api/common";
const statusBarHeight = ref(uni.getWindowInfo().screenTop);
const { show } = defineProps({
    show: {
        type: Boolean,
        default: false
    }
});

// 导航
const menuList = ref([]);
const onClickMenu = data => {
    menuList.value.forEach(v => (v.active = false));
    data.active = true;
    document.querySelector("#filter").querySelector(`.${data.className}`).scrollIntoView();
};
// 学历
const educationList = ref([]);
const onClickEducation = v => {
    educationList.value.forEach(v => (v.active = false));
    v.active = true;
};
// 年龄
const age = ref([16, 100]);
// 性别
const genderList = ref([]);
const onClickGender = v => {
    genderList.value.forEach(v => (v.active = false));
    v.active = true;
};
// 工作年限
const workYearList = ref([]);
const onClickWorkYear = v => {
    workYearList.value.forEach(v => (v.active = false));
    v.active = true;
};
// 证书
const certificateList = ref([]);
const onClickCertificate = v => {
    certificateList.value.forEach(v => (v.active = false));
    v.active = true;
};
// 类型
// 证书
// positionalTitle professionalCertificates specialCertificates
// 初始化数据
const initData = async () => {
    /* 初始化菜单 */
    menuList.value = [
        { active: true, name: "学历", className: "education" },
        { active: false, name: "年龄", className: "age" },
        { active: false, name: "性别", className: "gender" },
        { active: false, name: "工作年限", className: "workYear" },
        { active: false, name: "证书", className: "certificate" }
    ];
    /* 初始化数据 */
    educationList.value = await getEumData("EnumEducationRequirement");
    genderList.value = await getEumData("EnumGenderRequirement");
    workYearList.value = [
        {
            text: "不限",
            min: null,
            max: null
        },
        {
            text: "1年",
            min: 0,
            max: 1
        },
        {
            text: "2~3年",
            min: 2,
            max: 3
        },
        {
            text: "4~5年",
            min: 4,
            max: 5
        },
        {
            text: "5~10年",
            min: 5,
            max: 10
        },
        {
            text: "10年以上",
            min: 10,
            max: null
        }
    ];
    certificateList.value = [
        { active: false, name: "专业技术职称", key: "positionalTitle" },
        { active: false, name: "职业等级证书", key: "professionalCertificates" },
        { active: false, name: "特种作业证书", key: "specialCertificates" }
    ];
    /* const dictJobType = await dictJobTypeApi({});
    dictJobTypeList.value = dictJobType.data; */
};
initData();
/*
    接受两个方法
    1. 确认 接收数据
    2. 取消
*/
const emit = defineEmits(["confirm", "cancel"]);
// 2. 取消
const onCancel = () => {
    initData();
    onConfirm();
    // emit("cancel");
};
// 1. 确认 接收数据
const onConfirm = () => {
    const [minAge, maxAge] = age.value;
    const { min: minWorkAge, max: maxWorkAge } = workYearList.value.find(v => v.active) || { min: 0, max: 100 };
    const education = educationList.value.find(v => v.active)?.code;
    // const jobType = dictJobTypeList.value.find(v => v.active)?.id;
    const sex = genderList.value.find(v => v.active)?.code;
    const certificateKey = certificateList.value.find(v => v.active)?.key;
    const temp = { minAge, maxAge, minWorkAge, maxWorkAge, education, jobType: "", sex };
    certificateKey && (temp[certificateKey] = certificateKey);
    emit("confirm", temp);
};
</script>

<style lang="scss" scoped>
.filter {
    position: fixed;
    inset: 0;
    z-index: 6666666;
    display: flex;
    background-color: #ffffff;
    .menu {
        width: 200rpx;
        height: 100%;
        background-color: #e8f2ff;
        p {
            padding: 32rpx 24rpx;
            font-size: 32rpx;
            color: #1b2026;
        }
        .active {
            padding-left: 16rpx;
            color: #1f86ff;
            background-color: #ffffff;
            border-left: 8rpx solid #1f86ff;
        }
    }
    .content {
        flex: 1;
        padding: 32rpx;
        padding-bottom: 80rpx;
        overflow-y: auto;
        .filter-item {
            margin-bottom: 66rpx;
            .title {
                margin-bottom: 24rpx;
                font-size: 36rpx;
                font-weight: 600;
                line-height: 36rpx;
                color: #1b2026;
            }
            .filter-select {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 16rpx 22rpx;
                .select-item {
                    box-sizing: border-box;
                    height: 60rpx;
                    font-size: 24rpx;
                    line-height: 60rpx;
                    color: #1b2026;
                    text-align: center;
                    background: #f0f4fa;
                    border: 2rpx solid #f0f4fa;
                    border-radius: 8rpx;
                }
                .active {
                    color: #1f86ff;
                    border-color: #1f86ff;
                }
            }
            :deep(.wd-slider) {
                height: auto;
                padding-top: 36rpx;
                .wd-slider__bar-wrapper {
                    margin: 12rpx;
                    background: red;
                }
                .wd-slider__button-wrapper {
                    top: 50%;
                    width: 20rpx;
                    .wd-slider__button {
                        width: 20rpx;
                        height: 20rpx;
                        background: #1f86ff;
                        border: 0;
                        box-shadow: none;
                    }
                    .wd-slider__label {
                        bottom: 16rpx;
                        left: 50%;
                        width: auto;
                        color: #1f86ff;
                        background-color: transparent;
                        transform: translateX(-50%);
                    }
                }
            }
        }
    }
    .bottom-wrap {
        position: absolute;
        bottom: 0;
        left: 0;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        width: 100%;
        padding: 16rpx 64rpx;
        background-color: #ffffff;
        border-top: 1px solid #dae4e7;
        button {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 294rpx;
            height: 80rpx;
            margin: 0;
            border: 0;
        }
        .cancel {
            color: #1f86ff;
            background: #e8f2ff;
        }
        .confirm {
            color: #ffffff;
            background: #1f86ff;
        }
    }
}
</style>
