<template>
    <div class="page">
        <NavBar :showIcon="true" :showTitle="false" title="" backgroundBox="#FFFFFF"></NavBar>
        <view class="title">
            <view class="t1">1/5填写职位信息</view>
            <view class="t2">选择对应的职位并填写职位信息</view>
        </view>
        <view class="content">
            <selectbox :options="typeOptions" v-model="typeValue"></selectbox>
            <form-row>
                <form-item title="职位类型">
                    <wd-col-picker
                        v-model="value"
                        :columns="columns"
                        :column-change="columnChange"
                        @confirm="handleConfirm"
                        label-key="name"
                        value-key="id"
                        use-default-slot
                    >
                        <view :class="`inner flex-between ${pinias.formData.jobTypeText ? '' : 'placeholder'}`">
                            {{ pinias.formData.jobTypeText || "请选择职位类型" }}
                        </view>
                    </wd-col-picker>
                </form-item>
            </form-row>
            <form-row>
                <form-item title="职位标题" icon="edit">
                    <input type="text" placeholder="输入职位标题如“财务总监”" />
                </form-item>
            </form-row>
            <form-row>
                <form-item title="职位描述" :border="false" icon="">
                    <textarea></textarea>
                </form-item>
            </form-row>
            <!-- <view class="switch">
                <view
                    v-for="(item, index) in EnumWorkMode"
                    :class="item.code == pinias.formData.workMode ? 'active' : ''"
                    @tap="changeWorkMode(item.code)"
                    :key="index"
                    >{{ item.text }}
                </view>
            </view> -->
            <!-- <view class="form-item">
                <view class="form-item-title">职位类型</view>
                <wd-col-picker
                    v-model="value"
                    :columns="columns"
                    :column-change="columnChange"
                    @confirm="handleConfirm"
                    label-key="name"
                    value-key="id"
                    use-default-slot
                >
                    <view :class="`inner flex-between ${pinias.formData.jobTypeText ? '' : 'placeholder'}`">
                        {{ pinias.formData.jobTypeText || "请选择职位类型" }}
                        <view class="arrow"></view>
                    </view>
                </wd-col-picker>
            </view> -->
            <!-- <view class="form-item">
                <view class="form-item-title">职位标题</view>
                <view class="inner flex-between">
                    <input
                        v-model="pinias.formData.jobName"
                        type="text"
                        placeholder-class="placeholder"
                        placeholder="请输入职业标题"
                    />
                </view>
            </view> -->
            <!-- <view class="form-item describe" style="border: 0">
                <view class="form-item-title">职位描述</view>
                <wd-textarea
                    custom-class="textarea"
                    show-word-limit
                    maxlength="500"
                    v-model="pinias.formData.jobDesc"
                    placeholder="请输入你的职位描述"
                />
            </view> -->
        </view>

        <wd-tabbar
            @tap="next"
            custom-style="display: flex;justify-content: center !important;z-index:1;"
            fixed
            placeholder
            safeAreaInsetBottom
        >
            <view class="foot-btn">下一步</view>
        </wd-tabbar>
    </div>
</template>

<script setup>
import { getEumData } from "@/utils/utils";
import { ref } from "vue";
import { dictJobTypeApi } from "@/api/common";
import { getJobByIdApi } from "@/api/postion";
import { validateForm } from "@/utils/utils";
import _ from "lodash";

import { useReleasePostionStore } from "./store";

import FormItem from "@/components/form/form-item.vue";
import FormRow from "@/components/form/form-row.vue";
import Selectbox from "@/components/form/selectbox.vue";
const pinias = useReleasePostionStore();

onLoad(option => {
    const { id } = option;
    if (!id) {
        pinias.resetForm();
    }
});
/* 兼职全职枚举 */
const EnumWorkMode = ref([]);
const getEnumWorkMode = async () => {
    EnumWorkMode.value = await getEumData("EnumWorkMode");
};

getEnumWorkMode();
const changeWorkMode = mode => {
    pinias.setFormDataKey("workMode", mode);
    pinias.setFormDataKey("minSalary", 0);
    pinias.setFormDataKey("maxSalary", 0);
    console.log("mode", mode);

    if (mode == 2) {
        // 小时
        pinias.setFormDataKey("settlementType", 1);
    } else {
        // 月
        pinias.setFormDataKey("settlementType", 4);
    }
};
/* 职业类型 */
const value = ref([]);
const columns = ref([]);
const getJobType = () => {
    dictJobTypeApi({}).then(res => {
        columns.value.push(res.data);
    });
};
getJobType();
const columnChange = ({ selectedItem, resolve, finish }) => {
    if (selectedItem.children?.length > 0) {
        resolve(selectedItem.children);
    } else {
        finish();
    }
};
const handleConfirm = ({ selectedItems, value }) => {
    const taget = _.last(selectedItems);
    pinias.setFormDataKey("jobTypeText", taget.name);
    pinias.setFormDataKey("jobType", taget.id);
};
const next = () => {
    xma.hideKeyboard();
    if (validateForm(pinias.formData, ["jobType", "jobTypeText", "jobName", "jobDesc"])) {
        uni.navigateTo({
            url: "/pages/recommend/releasePostion/step2"
        });
    }
};

/* 类型 */
const typeValue = ref(1);
const typeOptions = [
    {
        label: "全职",
        value: 1
    },
    {
        label: "兼职",
        value: 2
    },
    {
        label: "见习",
        value: 3
    },
    {
        label: "实习",
        value: 4
    }
];
</script>

<style lang="scss" scoped>
@import "./common.scss";

/* .describe {
    textarea {
        box-sizing: border-box;
        width: 686rpx;
        height: 272rpx;
        padding: 32rpx;
        background: #f2f5fb;
        border-radius: 8rpx;
        opacity: 1;
    }
}
.page {
    .textarea {
        max-height: 272rpx;
        margin-top: 32rpx;
        background: #f2f5fb;
        :deep(.wd-textarea__value) {
            width: 100%;
            max-height: 272rpx;
            padding: 0 !important;
            background: #f2f5fb !important;
        }
        :deep(.wd-textarea__count) {
            background: none !important;
        }
    }
}
.switch {
    display: flex;
    align-items: center;
    width: 320rpx;
    overflow: hidden;
    border-radius: 16rpx;
    view {
        box-sizing: border-box;
        width: 160rpx;
        padding: 14rpx 52rpx;
        font-size: 28rpx;
        color: #1f86ff;
        background: #1f86ff22;
        &.active {
            color: #ffffff;
            background-color: #1f86ff;
        }
    }
} */
textarea {
    box-sizing: border-box;
    width: 100%;
    padding: 32rpx;
    background: #f2f5fb;
    border-radius: 8rpx;
}
.foot-btn {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 622rpx;
    height: 80rpx;
    color: #ffffff;
    background: #1f86ff;
    border-radius: 12rpx;
}
</style>
