<template>
    <div class="page">
        <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="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="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="formData.contactPerson" placeholder="请输入联系人" />
                </view>
            </view>
        </view>

        <view class="btn-wrap">
            <button class="bottom-btn" @tap="submit">提交</button>
        </view>
    </div>
</template>

<script setup>
import { createJobApi, updateJobApi } from "@/api/postion";
import { useReleasePostionStore } from "./store";
const { formData, resetForm } = useReleasePostionStore();
console.log(resetForm);
const submit = () => {
    console.log("submit", formData);
    if (formData.id) {
        // 更新
        updateJobApi(formData).then(res => {
            if (res.code == 200) {
                resetForm();
                uni.showToast({
                    title: "更新成功",
                    icon: "none",
                    duration: 2000,
                    success: () => {
                        uni.switchTab({
                            url: "/pages/recommend/index"
                        });
                    }
                });
            } else {
                uni.showToast({
                    title: res.msg,
                    icon: "none",
                    duration: 2000
                });
            }
        });
    } else {
        // 提交
        createJobApi(formData).then(res => {
            if (res.code == 200) {
                resetForm();
                uni.showToast({
                    title: "发布成功",
                    icon: "none",
                    duration: 2000,
                    success: () => {
                        uni.switchTab({
                            url: "/pages/recommend/index"
                        });
                    }
                });
            } else {
                uni.showToast({
                    title: res.msg,
                    icon: "none",
                    duration: 2000
                });
            }
        });
    }
};
</script>

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