<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">
            <FormRow>
                <FormItem title="招聘人数" icon="edit" required>
                    <input type="number" v-model="pinias.formData.recruitmentNumber" placeholder="请输入招聘人数" />
                </FormItem>
            </FormRow>
            <FormRow>
                <FormItem title="联系电话" icon="edit" required>
                    <view class="inner felx-between">
                        <input type="number" v-model="pinias.formData.contactPhone" placeholder="请输入联系电话" />
                    </view>
                </FormItem>
            </FormRow>
            <FormRow>
                <FormItem title="联系人" icon="edit" required>
                    <view class="inner felx-between">
                        <input type="text" v-model="pinias.formData.contactPerson" placeholder="请输入联系人" />
                    </view>
                </FormItem>
            </FormRow>
        </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 FormItem from "@/components/form/form-item.vue";
import FormRow from "@/components/form/form-row.vue";

import { createJobApi, updateJobApi } from "@/api/postion";

import { useReleasePostionStore } from "./store";
/* tab */
const pinias = useReleasePostionStore();
import { validateForm } from "@/utils/utils";
const submit = () => {
    if (!validateForm(pinias.formData, ["number", "contactPhone", "contactPerson"], "post")) {
        return;
    }
    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({
                            delta: 5
                        });
                    }, 3000);
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: "none",
                        duration: 2000
                    });
                }
            })
            .catch(err => {
                console.log(err);
                uni.hideLoading();
            });
    } else {
        // 提交
        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>
