<template>
    <div class="page">
        <NavBar :showIcon="true" :showTitle="false" title="" backgroundBox="#FFFFFF"></NavBar>
        <view class="title">
            <view class="t1">5/5 更多要求</view>
            <view class="t2">设置招聘偏好，让报名更精准</view>
        </view>
        <view class="content">
            <view class="form-item">
                <view class="form-item-title">招聘人数</view>
                <view class="inner felx-between">
                    <input type="number" v-model="pinias.formData.recruitmentNumber" placeholder="请输入招聘人数" />
                </view>
            </view>
            <view class="form-item">
                <view class="form-item-title">联系电话</view>
                <view class="inner felx-between">
                    <input type="number" v-model="pinias.formData.contactPhone" placeholder="请输入联系电话" />
                </view>
            </view>
            <view class="form-item">
                <view class="form-item-title">联系人</view>
                <view class="inner felx-between">
                    <input type="text" v-model="pinias.formData.contactPerson" placeholder="请输入联系人" />
                </view>
            </view>
        </view>

        <wd-tabbar
            @tap="submit"
            custom-style="display: flex;justify-content: center !important;"
            fixed
            placeholder
            safeAreaInsetBottom
        >
            <view class="foot-btn">提交</view>
        </wd-tabbar>
    </div>
</template>

<script setup>
import { createJobApi, updateJobApi } from "@/api/postion";

import { useReleasePostionStore } from "./store";
/* tab */
const pinias = useReleasePostionStore();
import { validateForm } from "@/utils/utils";
const submit = () => {
    xma.hideKeyboard();
    xma.showLoading({
        title: "提交中",
        mask: true
    });
    if (pinias.formData.id) {
        // 更新
        updateJobApi(pinias.formData)
            .then(res => {
                if (res.code == 200) {
                    pinias.resetForm();
                    setTimeout(() => {
                        wx.hideLoading({
                            complete: complete => {
                                if (complete.errMsg == "hideLoading:ok") {
                                    wx.showToast({
                                        title: "更新成功",
                                        icon: "none"
                                    });
                                }
                            }
                        });
                    }, 2000);
                    setTimeout(() => {
                        pinias.resetForm();
                        /* uni.n({
                            url: "/pages/user/positionManagement/index"
                        }); */
                        uni.navigateBack();
                    }, 3000);
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: "none",
                        duration: 2000
                    });
                }
            })
            .catch(err => {
                console.log(err);
                uni.hideLoading();
            });
    } else {
        if (validateForm(pinias.formData, ["contactPhone", "contactPerson"])) {
            // 提交
            createJobApi(pinias.formData)
                .then(res => {
                    if (res.code == 200) {
                        setTimeout(() => {
                            wx.hideLoading({
                                complete: complete => {
                                    if (complete.errMsg == "hideLoading:ok") {
                                        wx.showToast({
                                            title: "发布成功",
                                            icon: "none"
                                        });
                                    }
                                }
                            });
                        }, 2000);
                        setTimeout(() => {
                            pinias.resetForm();
                            uni.switchTab({
                                url: "/pages/user/index"
                            });
                        }, 3000);
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: "none",
                            duration: 2000
                        });
                    }
                })
                .catch(err => {
                    console.log(err);
                    uni.hideLoading();
                });
        }
    }
};
</script>

<style lang="scss" scoped>
@import "./common.scss";
.foot-btn {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 622rpx;
    height: 80rpx;
    color: #ffffff;
    background: #1f86ff;
    border-radius: 12rpx;
}
</style>
