<template>
    <div class="page" :style="{ background: pageType == 'update' ? '#fff' : '#E8E9EA' }">
        <NavBar :showIcon="true" :showTitle="true" title="岗位信息" backgroundBox="#FFFFFF"></NavBar>
        <view class="from-1" v-if="pageType == 'update'">
            <wd-checkbox-group v-model="value">
                <view class="wd-cell-item" v-for="i in gwList" :key="i.id">
                    <wd-checkbox :modelValue="i.id"></wd-checkbox>
                    <view class="right">
                        <view class="position-name">{{ i.name }}</view>
                        <view class="tip">贵阳｜{{ i.workDic }}｜{{ i.jobTypeName }}</view>
                    </view>
                </view>
                <wd-status-tip v-if="!gwList || gwList.length == 0" image="content" tip="暂无岗位" />
            </wd-checkbox-group>
        </view>
        <view v-else>
            <view class="from-2" v-for="(item, index) in jobForm" :key="index">
                <view class="title">
                    <view>添加岗位信息{{ index + 1 }}</view>
                    <wd-icon v-if="index > 0" @click="deleteItem(index)" name="close-outline" size="34rpx"></wd-icon
                ></view>
                <selectbox
                    @update="initSalaryColumns"
                    :options="EnumWorkMode"
                    label-key="text"
                    value-key="code"
                    v-model="item.workMode"
                ></selectbox>
                <!-- 职位类型 -->
                <form-row>
                    <form-item title="职位类型" :required="true">
                        <wd-col-picker
                            v-model="positionTypeValue"
                            :columns="columns"
                            :column-change="columnChange"
                            @confirm="params => handleConfirm(params, item)"
                            label-key="name"
                            value-key="id"
                            use-default-slot
                        >
                            <view :class="`inner flex-between ${item.jobTypeName ? '' : 'placeholder'}`">
                                {{ item.jobTypeName || "请选择职位类型" }}
                            </view>
                        </wd-col-picker>
                    </form-item>
                </form-row>
                <!-- 岗位名称 -->
                <form-row>
                    <form-item title="岗位名称" icon="arrow" :required="true">
                        <input type="text" v-model="item.name" placeholder="请输入岗位名称" />
                    </form-item>
                </form-row>
                <!-- 职位描述 -->
                <form-row>
                    <form-item title="岗位描述" :border="false" icon="" :required="true">
                        <textarea maxlength="800" v-model="item.positionDesc" placeholder="请输入你的岗位描述"></textarea>
                    </form-item>
                </form-row>
                <form-item title="岗位薪资" icon="" :required="true">
                    <view
                        v-if="item.settlementType == 4"
                        :class="`inner flex-between ${item.salaryText ? '' : 'placeholder'}`"
                        style="display: flex; justify-content: space-between; width: 100%"
                        @click="onOpen(item, index)"
                    >
                        {{ item.salaryText || "请选择月薪范围" }}

                        <!-- <view class="arrow"></view> -->
                        <checkbox
                            class="checkbox"
                            :value="item.negotiableSalary"
                            @click="onChecked(item)"
                            :checked="item.negotiableSalary == 1"
                            >面议</checkbox
                        >
                    </view>
                    <view
                        v-else
                        :class="`inner flex-between ${item.salaryText ? '' : 'placeholder'}`"
                        style="display: flex; justify-content: space-between; width: 100%"
                        @click="onOpen(item, index)"
                    >
                        {{ item.salaryText || "请选择时薪范围" }}
                        <!-- {{ item.salaryText || "请选择岗位薪资待遇" }} -->
                        <!-- <view class="arrow"></view> -->
                        <checkbox
                            class="checkbox"
                            :value="item.negotiableSalary"
                            @click="onChecked(item)"
                            :checked="item.negotiableSalary == 1"
                            >面议</checkbox
                        >
                    </view>
                </form-item>

                <form-item title="工作地点" icon="" :required="true">
                    <wd-col-picker
                        v-model="cityValue"
                        :columns="cityOpstion"
                        value-key="code"
                        label-key="name"
                        :column-change="columnChangeCity"
                        @confirm="params => handleConfirmCity(params, item)"
                        use-default-slot
                    >
                        <p :class="{ placeholder: !item.cityText }" class="text-single">
                            {{ item.cityText || "请选择岗位工作地点" }}
                        </p>
                    </wd-col-picker>
                </form-item>
                <form-item title="是否提供食宿" icon="" :required="true">
                    <wd-radio-group v-model="item.accommodation" inline shape="dot">
                        <wd-radio v-for="(v, n) in radioOpstion" :value="v.code" :key="n">{{ v.text }}</wd-radio>
                    </wd-radio-group>
                </form-item>
                <form-item title="福利待遇（选填）" icon="">
                    <view class="welfare">
                        <view
                            v-for="(el, nl) in item.myBenefits"
                            :class="`t ${el.active ? 'active' : ''}`"
                            @tap="onChangeBenefits(el, item)"
                            :key="nl"
                            >{{ el.text }}</view
                        >
                    </view>
                </form-item>
                <form-item title="人员类别" icon="" :required="true">
                    <wd-picker
                        :columns="identityPostion"
                        value-key="code"
                        label-key="text"
                        v-model="item.identityRequirement"
                        @confirm="params => handleConfirmIdentity(params, item)"
                        use-default-slot
                    >
                        <view :class="`inner flex-between ${item.identityText ? '' : 'placeholder'}`">
                            <view class="flex-align-center">
                                {{ item.identityText || "请选择人员类别" }}
                            </view>
                        </view>
                    </wd-picker>
                </form-item>
                <view>
                    <form-item title="学历" icon="" :required="true">
                        <wd-picker
                            :columns="educationPostion"
                            value-key="code"
                            label-key="text"
                            v-model="item.educationRequirement"
                            @confirm="params => handleConfirmEducation(params, item)"
                            use-default-slot
                        >
                            <view :class="`inner flex-between ${item.educationText ? '' : 'placeholder'}`">
                                <view class="flex-align-center">
                                    {{ item.educationText || "请选择学历" }}
                                </view>
                            </view>
                        </wd-picker>
                    </form-item>

                    <form-item title="专业" icon="" :required="true">
                        <wd-col-picker
                            v-model="majorValue"
                            :columns="majorOpstion"
                            value-key="name"
                            label-key="name"
                            :column-change="columnChangeMajor"
                            @confirm="params => handleConfirmMajor(params, item)"
                            use-default-slot
                        >
                            <p :class="{ placeholder: !item.majorText }" class="text-single" style="width: 100%">
                                {{ item.majorText || "请选择专业" }}
                            </p>
                        </wd-col-picker>
                    </form-item>
                </view>

                <form-item title="年龄" icon="" :required="true">
                    <!-- <wd-col-picker
                        v-model="ageValue"
                        :columns="ageColumns"
                        :column-change="ageColumnChange"
                        @confirm="params => ageHandleConfirm(params, item)"
                        use-default-slot
                    >
                        <view :class="`inner flex-between ${item.ageText ? '' : 'placeholder'}`">
                            {{ item.ageText || "请选择年龄范围" }}
                        </view>
                    </wd-col-picker> -->
                    <view @click="showAgeSelect(index)" :class="`inner flex-between ${item.ageText ? '' : 'placeholder'}`">
                        {{ item.ageText || "请选择年龄范围" }}
                    </view>
                </form-item>
                <form-row :fill="false">
                    <form-item title="专业技术职称（选填）" icon="edit">
                        <input
                            type="text"
                            @input="inputMajor($event, item)"
                            v-model="item.majorInputValue"
                            placeholder="请填写职称"
                        />
                    </form-item>
                    <form-item title="">
                        <wd-picker
                            :columns="levelOptions"
                            value-key="text"
                            label-key="text"
                            v-model="item.majorSelectValue"
                            @confirm="params => handMajoration(params, item)"
                            use-default-slot
                        >
                            <view :class="`inner flex-between ${item.majorSelectValue ? '' : 'placeholder'}`">
                                <view class="flex-align-center" bind:tap="onShowIdentitySelect">
                                    {{ item.majorSelectValue || "请选择职称等级" }}
                                </view>
                            </view>
                        </wd-picker>
                    </form-item>
                </form-row>
                <form-row :fill="false">
                    <form-item title="职业资格/技能等级证书（选填）" icon="edit">
                        <input
                            type="text"
                            @input="inputLeve($event, item)"
                            v-model="item.certificateInputValue"
                            placeholder="请填写职业资格"
                        />
                    </form-item>
                    <form-item title="">
                        <wd-picker
                            :columns="levelOptions"
                            value-key="text"
                            label-key="text"
                            @confirm="params => handlelevelation(params, item)"
                            v-model="item.certificateSelectValue"
                            use-default-slot
                        >
                            <view :class="`inner flex-between ${item.certificateSelectValue ? '' : 'placeholder'}`">
                                <view class="flex-align-center">
                                    {{ item.certificateSelectValue || "请选择职业资格等级" }}
                                </view>
                            </view>
                        </wd-picker>
                    </form-item>
                </form-row>
                <form-item title="特种作业证（选填）" icon="edit">
                    <input v-model="item.specialCertificates" type="text" placeholder="请填写特种作业证" />
                </form-item>
                <form-row :fill="false">
                    <form-item title="招聘人数" icon="edit" :required="true">
                        <input type="number" v-model="item.recruitmentNumber" placeholder="请输入招聘人数" />
                    </form-item>
                    <form-item title="联系电话" icon="edit" :required="true">
                        <input type="number" v-model="item.contactPhone" placeholder="请输入联系电话" />
                    </form-item> </form-row
                ><form-item title="联系人" icon="edit" :required="true">
                    <input type="text" v-model="item.contactPerson" placeholder="请输入联系人" />
                </form-item>
            </view>
        </view>
        <wd-popup
            v-model="salaryShow"
            position="bottom"
            custom-style="height:40%;border-radius: 20rpx;z-index:999;"
            @close="handleClose"
        >
            <view class="title-box"
                ><view></view>
                <view class="title">薪资选择</view>
                <wd-icon @click="handleClose" name="close" size="30rpx"></wd-icon>
            </view>
            <wd-picker-view
                @change="params => salaryHandleConfirm(params, item)"
                use-default-slot
                :columns="salaryColumns"
                v-if="salaryShow"
                v-model="salaryValue"
            ></wd-picker-view>
            <view style="display: flex; justify-content: center; width: 100%"
                ><wd-button style="width: 80%" @click="handleClose" block :round="false">确定</wd-button></view
            >
        </wd-popup>
        <!-- 年龄选择器 -->
        <wd-action-sheet v-model="isShowAgeSelect" title="年龄选择" :actions="actions" @close="close">
            <div class="age-action-sheet">
                <div class="age-select-tips">
                    <p>最小年龄</p>
                    <p>最大年龄</p>
                </div>
                <wd-picker-view :columns="ageColumns" v-model="ageValue" :column-change="onChangeAge" />
                <wd-button block @click="ageSelectConfirm">确认</wd-button>
            </div>
        </wd-action-sheet>
        <wd-tabbar
            v-if="pageType == 'update'"
            custom-style="display: flex;justify-content: center !important;z-index:1;"
            fixed
            placeholder
            safeAreaInsetBottom
        >
            <view class="footer"> <button class="foot-btn" @click="submitFrom">提交报名</button></view>
        </wd-tabbar>
        <wd-tabbar
            v-else
            custom-style="display: flex;justify-content: center !important;z-index:1;"
            fixed
            placeholder
            safeAreaInsetBottom
        >
            <view class="footer">
                <button class="foot-btn1" @click="addPost">继续添加</button>
                <button class="foot-btn" @click="submitFrom">提交报名</button></view
            >
        </wd-tabbar>
    </div>
</template>

<script setup>
import { ref } from "vue";
import { positionList, positionAddList, jobFair, jobFairRegisterApi } from "@/api/user";
import Selectbox from "@/components/form/selectbox.vue";
import FormItem from "@/components/form/form-item.vue";
import FormRow from "@/components/form/form-row.vue";
import { dictJobTypeApi, getAreaListApi, getMajorTreeApi } from "@/api/common";
import { validateForm } from "@/utils/utils";
import town from "@/assets/town.json";

import { getEumData } from "@/utils/utils";
const tab = ref(0);
const value = ref([]);
const ageValue = ref(["", ""]);
const gwList = ref([]);
const columns = ref([]);
/* 获取省市区 */
const cityOpstion = ref([]);
const cityValue = ref([]);
const cityText = ref("");
let citySelectedItems = [];
const salaryShow = ref(false);
const salaryValue = ref([]);
const identityPostion = ref([]);
const educationPostion = ref([]);
/* 福利待遇 */
/* 薪资选择 */
/* 专业 */
const majorValue = ref([]);
const majorOpstion = ref([]);
let salaryText = ref("");
const salaryColumns = ref([]);
/* 是否提供住宿 */
const radioOpstion = ref([]);
const certificateInputValue = ref("");
const certificateSelectValue = ref("");
const majorInputValue = ref("");
const majorSelectValue = ref("");
/* 职业类型 */
const positionTypeValue = ref([]);
/* 兼职全职枚举 */
const EnumWorkMode = ref([]);
const articleIds = ref("");
const pageType = ref("");

/* 等级选择项 */
const levelOptions = ref(["初级", "中级", "高级", "高级以上"]);
const isShowAgeSelect = ref(false);
const ageColumns = ref([]);
const jobForm = ref([
    {
        workMode: 1,
        name: "",
        jobTypeId: null,
        jobTypePid: "",
        jobTypeName: "",
        positionDesc: "",
        negotiableSalary: 0,
        settlementType: 4,
        minSalary: null,
        maxSalary: null,
        benefits: "",
        identityRequirement: 1,
        educationRequirement: 0,
        minAgeRequirement: 0,
        maxAgeRequirement: 0,
        recruitmentNumber: 1,
        accommodation: 0,
        provinceCode: "",
        cityCode: "",
        districtCode: "",
        street: "",
        address: "",
        contactPerson: "",
        majorRequirement: "",
        contactPhone: "",
        positionalTitle: "",
        professionalCertificates: "",
        specialCertificates: "",
        articleId: articleIds.value,
        salaryText: "", //显示
        myBenefits: [
            {
                text: "年底双薪",
                active: false
            },
            {
                text: "节假日福利",
                active: false
            },
            {
                text: "旅游团建",
                active: false
            },
            {
                text: "生日福利",
                active: false
            },
            {
                text: "五险一金",
                active: false
            },
            {
                text: "三险一金",
                active: false
            },
            {
                text: "其他",
                active: false
            }
        ]
    }
]);
onLoad(({ articleId, type }) => {
    articleIds.value = articleId;
    pageType.value = type;
    jobForm.value[0].articleId = articleId;
    jobFair(articleId).then(res => {
        if (res.data) {
            value.value = res.data.positionIds.split(",");
        }
    });
});
getMajorTreeApi().then(res => {
    console.log(res);
    if (res.code === 200) {
        majorOpstion.value.push(
            Object.keys(res.data).map(key => ({
                name: key,
                children: res.data[key]
            }))
        );
        majorOpstion.value[0].unshift({ name: "不限" });
    }
});
const tabList = ref([
    { id: 213213, name: "选择已有岗位", type: 1 },
    { id: 1651651, name: "新增岗位", type: 2 }
]);

const columnChangeMajor = ({ selectedItem, resolve, finish }) => {
    if (selectedItem.children) {
        resolve(selectedItem.children);
    } else {
        finish();
    }
};
const handleConfirmMajor = (params, item) => {
    const { value } = params;
    if (value[1]) {
        item.majorText = value.join("-");
        item.majorRequirement = value.join("-");
    } else {
        item.majorText = "不限";
        item.majorRequirement = "";
    }
};
const getEnumCertificatesLevel = async () => {
    levelOptions.value = await getEumData("EnumCertificatesLevel");
};
getEnumCertificatesLevel();
const initPostion = async () => {
    identityPostion.value = await getEumData("EnumIdentityRequirement");
    educationPostion.value = await getEumData("EnumEducationRequirement");
};
initPostion();
function handleClose() {
    if (salaryValue.value[1] < salaryValue.value[0]) {
        xma.showToast({
            title: "最高薪资不能小于最低薪资",
            icon: "none"
        });
        return;
    }
    salaryShow.value = false;
}
function deleteItem(index) {
    jobForm.value.splice(index, 1);
}
const initageColumns = () => {
    // const temp = [
    //     {
    //         value: "不限",
    //         label: "不限",
    //         next: false
    //     }
    // ];
    const temp = [];
    for (let i = 16; i < 81; i++) {
        temp.push({
            value: i,
            label: i + "岁",
            next: true
        });
    }
    // columns.value.push(temp);
    ageColumns.value = [temp, temp];
    // for (let i = 16; i < 81; i++) {
    //     temp.push({
    //         value: i,
    //         label: i + "岁",
    //         next: true
    //     });
    // }
    // ageColumns.value.push(temp);
};
initageColumns();
const getEnumWorkMode = async () => {
    EnumWorkMode.value = await getEumData("EnumWorkMode");
};
getAreaListApi({ type: "province", code: "" }).then(res => {
    res.data.unshift({ name: "不限", code: null });
    cityOpstion.value.push(res.data);
});

const keys = ["city", "district", "street"];
getEnumWorkMode();
positionList({ status: 3 }).then(res => {
    res.data = res.data.map(item => {
        item.workDic = EnumWorkMode.value.find(v => v.code == item.workMode).text;
        return item;
    });
    gwList.value = res.data;
});
const getJobType = () => {
    dictJobTypeApi({}).then(res => {
        columns.value.push(res.data);
    });
};
getJobType();
const initRadioOpstion = async () => {
    radioOpstion.value = await getEumData("EnumAccommodation");
};
initRadioOpstion();
// 职业类型
const columnChange = ({ selectedItem, resolve, finish }) => {
    if (selectedItem.children?.length > 0) {
        resolve(selectedItem.children);
    } else {
        finish();
    }
};
const handleConfirm = (params, item) => {
    const { selectedItems, value } = params;

    item.jobTypeName = selectedItems[1].name;
    item.jobTypeId = selectedItems[1].id;
    item.jobTypePid = selectedItems[0].id;
    console.log("selectedItems", item.jobTypeName, item.jobTypeId, item.jobTypePid);
};
// 职业类型
// 地址

const columnChangeCity = ({ selectedItem, resolve, index, finish }) => {
    const type = keys[index];
    if (type && selectedItem.code) {
        getAreaListApi({ type, code: selectedItem.code }).then(res => {
            res.data.unshift({ name: "不限", code: null });
            resolve(res.data);
        });
    } else {
        finish();
    }
};
const handleConfirmCity = (params, item) => {
    const { selectedItems } = params;
    const [province, city, district, street] = selectedItems;
    item.cityText = selectedItems
        .filter(v => v.code)
        .map(v => v.name || "")
        .join("-");
    item.address = selectedItems
        .filter(v => v.code)
        .map(v => v.name || "")
        .join("");
    if (!province.code) {
        item.cityText = "不限";
        item.address = "不限";
    }
    // item.provinceCode = 520000;
    item.provinceCode = province.code;
    item.cityCode = city?.code;
    item.cityName = district?.name;
    item.districtCode = district?.code;
    item.street = street ? street.name : "";
};

const onChangeAge = (pickerView, value, columnIndex, resolve) => {
    const minAge = 16;
    const maxAge = 81;
    const createColumns = (min, max) => {
        const temp = [];
        for (let i = min; i < max; i++) {
            temp.push({
                value: i,
                label: i + "岁",
                next: true
            });
        }
        return temp;
    };
    if (columnIndex === 0) {
        const min = value[0].value;
        const columns = min
            ? createColumns(min, maxAge)
            : [
                  {
                      value: "",
                      label: "不限",
                      next: false
                  }
              ];
        pickerView.setColumnData(1, columns);
    }
    resolve();
};

const ageSelectConfirm = () => {
    if (ageValue.value[0]) {
        const [min, max] = ageValue.value;
        jobForm.value[activeIndex.value].ageText = `${ageValue.value[0]}-${ageValue.value[1]}岁`;
        jobForm.value[activeIndex.value].minAgeRequirement = min;
        jobForm.value[activeIndex.value].maxAgeRequirement = max;
    } else {
        jobForm.value[activeIndex.value].ageText = "不限";
    }
    isShowAgeSelect.value = false;
};
const showAgeSelect = index => {
    isShowAgeSelect.value = true;
    activeIndex.value = index;
};
// 地址

// 薪资-fun
const activeIndex = ref(0);

const initSalaryColumns = () => {
    salaryColumns.value = [];
    let index = activeIndex.value;
    let multiple = 1;
    // 确定 settlementType
    jobForm.value[index].settlementType = jobForm.value[index].workMode === 2 ? 1 : 4;

    // 设置基准值
    multiple = jobForm.value[index].settlementType === 1 ? 50 : 1000;
    const temp = [];
    const maxSalary = jobForm.value[index].settlementType == 1 ? 1000 : 50 * multiple;
    if (jobForm.value[index].settlementType == 1) {
        temp.push({
            value: 10,
            label: "10",
            next: true
        });
    }
    // 生成序列
    for (let i = 1; i * multiple <= maxSalary; i++) {
        const currentValue = i * multiple;
        temp.push({
            value: currentValue,
            label: jobForm.value[index].settlementType == 1 ? currentValue : `${currentValue / 1000}k`,
            next: true
        });
    }

    // 确保 columns.value 是一个数组
    if (!Array.isArray(salaryColumns.value)) {
        salaryColumns.value = [];
    }

    // 清空原来的数组，以确保只包含新的数据
    salaryColumns.value.length = 0;

    // 将 temp 复制两次，推入 columns.value
    salaryColumns.value.push([...temp], [...temp]);
};
initSalaryColumns();

function onChecked(item) {
    item.negotiableSalary = item.negotiableSalary == 1 ? 0 : 1;
    // 如果勾选了面议
    if (item.negotiableSalary == 1) {
        salaryText.value = "";
        item.maxSalary = 0;
        item.minSalary = 0;
        item.negotiableSalary = 1;
    } else {
        item.negotiableSalary = 0;
    }
}
function onOpen(item, index) {
    salaryValue.value = [];
    activeIndex.value = index;
    initSalaryColumns();
    if (item.negotiableSalary == 1) return;
    salaryShow.value = true;
}

const salaryHandleConfirm = (params, item) => {
    let multiple = 1;
    multiple = jobForm.value[activeIndex.value].settlementType === 1 ? 50 : 1000;
    const { selectedItems, value } = params;
    if (value[1] < value[0]) {
        xma.showToast({
            title: "最高薪资不能小于最低薪资",
            icon: "none"
        });
        return;
    }
    jobForm.value[activeIndex.value].negotiableSalary = 0;

    if (jobForm.value[activeIndex.value].settlementType === 1) {
        jobForm.value[activeIndex.value].salaryText = value.join("~");
    } else {
        jobForm.value[activeIndex.value].salaryText = value.map(num => `${num / multiple}k`).join("~");
    }

    const [min, max] = value;
    if (max) {
        jobForm.value[activeIndex.value].maxSalary = max;
        jobForm.value[activeIndex.value].minSalary = min;
        jobForm.value[activeIndex.value].negotiableSalary = 0;
    } else {
        jobForm.value[activeIndex.value].maxSalary = 0;
        jobForm.value[activeIndex.value].minSalary = 0;
        jobForm.value[activeIndex.value].negotiableSalary = 1;
    }
};

const onChangeBenefits = (el, item) => {
    el.active = !el.active;
    item.benefits = item.myBenefits
        .filter(benefit => benefit.active) // 只保留选中的
        .map(benefit => benefit.text) // 获取文本
        .join(", ");
};
// 选择身份
const handleConfirmIdentity = (params, item) => {
    const { selectedItems, value } = params;
    item.identityText = selectedItems.text;
};
const ageColumnChange = ({ selectedItem, resolve, finish }) => {
    console.log(selectedItem);
    if (selectedItem.next) {
        const temp = [];
        for (let i = 1; i < 50; i++) {
            temp.push({
                value: i + selectedItem.value,
                label: i + selectedItem.value + "岁",
                next: false
            });
            resolve(temp);
        }
    } else {
        finish();
    }
};
const ageHandleConfirm = (params, item) => {
    const { selectedItems, value } = params;
    item.ageText = value.join("~");
    const [min, max] = value;
    if (max) {
        // 没有选择不限
        item.maxAgeRequirement = max;
        item.minAgeRequirement = min;
    } else {
        item.maxAgeRequirement = 0;
        item.minAgeRequirement = 0;
    }
};
// 选择学历
const handleConfirmEducation = (params, item) => {
    const { selectedItems, value } = params;
    item.educationText = selectedItems.text;
};
const inputLeve = (e, item) => {
    const { value } = e.detail;
    item.certificateInputValue = value;
    item.professionalCertificates = value + "-" + certificateSelectValue.value;
};
const handlelevelation = (params, item) => {
    const { selectedItems, value } = params;
    item.professionalCertificates = certificateInputValue.value + "-" + value;
};
const inputMajor = (e, item) => {
    const { value } = e.detail;
    item.majorInputValue = value;
    item.positionalTitle = value + "-" + majorSelectValue.value;
};
const handMajoration = (params, item) => {
    const { selectedItems, value } = params;
    console.log("value", value);

    item.positionalTitle = majorInputValue.value + "-" + value;
};
const selectedJobs = ref([]);
const submitFrom = () => {
    if (pageType.value == "update") {
        let updateArr = gwList.value.filter(item => value.value.includes(String(item.id)));
        updateArr = updateArr.map(item => {
            return item.id;
        });
        if (updateArr.length > 0) {
            xma.showLoading({
                title: "提交中...",
                mask: true
            });
            jobFairRegisterApi({ positionIdList: updateArr, articleId: articleIds.value }).then(res => {
                xma.hideLoading();
                if (res.code == 200) {
                    xma.navigateBack({
                        delta: 1
                    });
                }
            });
        } else {
            xma.showToast({
                title: "请选择职位",
                icon: "none"
            });
        }
    } else {
        const allValid =
            jobForm.value.length > 0 &&
            jobForm.value.every(item => {
                return (
                    item &&
                    validateForm(
                        item,
                        [
                            "jobTypeId",
                            "jobTypeName",
                            "name",
                            "positionDesc",
                            "address",
                            "identityRequirement",
                            "educationRequirement",
                            "minAgeRequirement",
                            "contactPhone",
                            "contactPerson",
                            "majorRequirement"
                        ],
                        "post"
                    )
                );
            });
        if (allValid) {
            xma.showLoading({
                title: "提交中...",
                mask: true
            });
            positionAddList(jobForm.value).then(res => {
                xma.hideLoading();
                if (res.code == 200) {
                    xma.navigateBack({
                        delta: 1
                    });
                }
            });
        } else {
            xma.showToast({
                title: "请完善相关信息",
                icon: "none"
            });
        }
    }
};
function openMask() {
    tab.value = 1;
}
function addPost() {
    jobForm.value.push({
        workMode: 1,
        name: "",
        jobTypeId: null,
        jobTypePid: "",
        jobTypeName: "",
        positionDesc: "",
        negotiableSalary: 0,
        settlementType: 4,
        minSalary: null,
        maxSalary: null,
        benefits: "",
        identityRequirement: 1,
        educationRequirement: null,
        minAgeRequirement: null,
        maxAgeRequirement: null,
        recruitmentNumber: 1,
        accommodation: 0,
        majorRequirement: "",
        provinceCode: "",
        cityCode: "",
        districtCode: "",
        street: "",
        address: "",
        contactPerson: "",
        contactPhone: "",
        positionalTitle: "",
        professionalCertificates: "",
        specialCertificates: "",
        articleId: articleIds.value,
        salaryText: "", //显示
        myBenefits: [
            {
                text: "年底双薪",
                active: false
            },
            {
                text: "节假日福利",
                active: false
            },
            {
                text: "旅游团建",
                active: false
            },
            {
                text: "生日福利",
                active: false
            },
            {
                text: "五险一金",
                active: false
            },
            {
                text: "三险一金",
                active: false
            },
            {
                text: "其他",
                active: false
            }
        ]
    });
}
</script>

<style lang="scss" scoped>
.page {
    width: 100%;

    .age-action-sheet {
        .age-select-tips {
            display: flex;
            p {
                flex: 1;
                text-align: center;
            }
        }
        .wd-button {
            margin: 32rpx;
        }
    }
    .title-box {
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 32rpx;
    }
    .from-1 {
        display: flex;
        flex-direction: column;
        width: 100%;
        .wd-cell-item {
            box-sizing: border-box;
            display: flex;
            width: 100%;
            padding: 32rpx 28rpx;
            border-bottom: 2rpx solid #e0e0e1;
            .right {
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                .position-name {
                    font-size: 32rpx;
                    font-weight: 500;
                    color: #1b2026;
                }
                .tip {
                    font-size: 24rpx;
                    color: #77818f;
                }
            }
        }
    }
    .from-2 {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 32rpx;
        margin-top: 32rpx;
        background: #ffffff;
        .title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            margin-bottom: 32rpx;
            font-size: 48rpx;
            font-weight: 500;
            color: #1b2026;
        }
        textarea {
            box-sizing: border-box;
            width: 100%;
            padding: 32rpx;
            background: #f2f5fb;
            border-radius: 8rpx;
        }
        .placeholder {
            width: 50%;
            text-wrap: nowrap;
        }
        .checkbox {
            flex-shrink: 0;
            white-space: nowrap;
        }
        .transverse {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            :deep(.uni-checkbox-input) {
                flex-shrink: 0;
                margin-left: 20rpx;
                border-radius: 50% !important;
            }
        }
        .welfare {
            display: flex;
            flex-wrap: wrap;
            gap: 24rpx;
            view {
                gap: 12rpx;
                padding: 12rpx 20rpx;
                font-size: 24rpx;
                line-height: 36rpx;
                color: #1f86ff;
                background: rgb(31 134 255 / 10%);
                border-radius: 8rpx;
                &.active {
                    color: #ffffff;
                    background-color: #1f86ff;
                }
            }
        }
        .text-single {
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: wrap;
        }
    }
    .footer {
        display: flex;
        align-items: center;
        justify-content: space-around;
        width: 100%;
        .foot-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 296rpx;
            height: 80rpx;
            color: #ffffff;
            background: #1f86ff;
            border-radius: 12rpx;
        }
        .foot-btn1 {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 296rpx;
            height: 80rpx;
            color: #1f86ff;
            background: #e8f2ff;
            border-radius: 12rpx;
        }
    }
}
</style>
