<template>
    <div class="edit-popup">
        <popup ref="popupRef" :title="popupTitle" :async="true" width="60vw" @confirm="handleSubmit" @close="handleClose">
            <el-card>
                <template #header>
                    审批内容
                </template>
                <qj ref="forms" v-if="type == '请假'"></qj>
                <cc ref="forms" v-if="type == '出差'"></cc>
                <wc ref="forms" v-if="type == '外出'"></wc>
                <jb ref="forms" v-if="type == '加班'"></jb>
                <hysyd ref="forms" v-if="type == '会议室预定'"></hysyd>
                <gwlz ref="forms" v-if="type == '公文流转'"></gwlz>
                <wpwx ref="forms" v-if="type == '物品维修'"></wpwx>
                <zzjy ref="forms" v-if="type == '资质借用'"></zzjy>
                <yz ref="forms" v-if="type == '用章'"></yz>
                <yc ref="forms" v-if="type == '用车'"></yc>
                <ycgh ref="forms" v-if="type == '用车归还'"></ycgh>
                <jk ref="forms" v-if="type == '借款'"></jk>
                <fk ref="forms" v-if="type == '付款'"></fk>
                <jl ref="forms" v-if="type == '奖励'"></jl>
                <cg ref="forms" v-if="type == '采购'"></cg>
                <hdjf ref="forms" v-if="type == '活动经费'"></hdjf>
                <rz ref="forms" v-if="type == '入职'"></rz>
                <zz ref="forms" v-if="type == '转正'"></zz>
                <lz ref="forms" v-if="type == '离职'"></lz>
                <zg ref="forms" v-if="type == '转岗'"></zg>
                <zpxq ref="forms" v-if="type == '招聘需求'"></zpxq>
                <tysp ref="forms" v-if="type == '通用审批'"></tysp>


            </el-card>
            <oaFlow :form-data="formData" :flow_cate="formData.id"></oaFlow>
        </popup>
    </div>
</template>

<script lang="ts" setup name="oaFlowTypeEdit">
import generateForm from './../../components/generateForm/index.vue'
import Popup from "@/components/popup/index.vue";
import { apiOaoaApproveAdd } from "@/api/oa_Initiate"
import qj from './form/jq/qj.vue'
import cc from './form/jq/cc.vue'
import wc from './form/jq/wc.vue'
import jb from './form/jq/jb.vue'
import hysyd from './form/xz/hysyd.vue'
import gwlz from './form/xz/gwlz.vue'
import wpwx from './form/xz/wpwx.vue'
import zzjy from './form/xz/zzjy.vue'
import yz from './form/xz/yz.vue'
import yc from './form/xz/yc.vue'
import ycgh from './form/xz/ycgh.vue'
import jk from './form/cw/jk.vue'
import fk from './form/cw/fk.vue'
import jl from './form/cw/jl.vue'
import cg from './form/cw/cg.vue'
import hdjf from './form/cw/hdjf.vue'
import rz from './form/rs/rz.vue'
import zz from './form/rs/zz.vue'
import lz from './form/rs/lz.vue'
import zg from './form/rs/zg.vue'
import zpxq from './form/rs/zpxq.vue'
import tysp from './form/qt/tysp.vue'



let props = defineProps({
    type: {
        type: String,
    }
})




const forms = ref('')
const emit = defineEmits(["success", "close"]);
const formRef = shallowRef<FormInstance>();
const popupRef = shallowRef<InstanceType<typeof Popup>>();
const mode = ref("add");
const showDialog = ref(false)
const extend = ref({})

// 弹窗标题
const popupTitle = computed(() => {
    return "新增审批"
});

// 表单数据
const formData = reactive({
    id: 0,
    data: [],
    extends: {}
});


// 表单验证
const formRules = reactive<any>({
    type: [
        {
            required: true,
            message: "请输入所属分类",
            trigger: ["blur"],
        },
    ]
});

// 获取详情
const setFormData = async (data: Record<any, any>) => {
    formData.data = data.data;
    formData.id = data.id;
};

// 获取详情
const setExtend = async (data: Record<any, any>) => {
    extend.value = data
};



// 提交按钮
const handleSubmit = async () => {
    await forms.value?.check();
    const data = { ...formData };
    await apiOaoaApproveAdd(data)
    popupRef.value?.close();
    emit("success");


};

//打开弹窗
const open = (type = "add") => {
    mode.value = type;
    popupRef.value?.open();
};

// 关闭回调
const handleClose = () => {
    emit("close");
};

defineExpose({
    open,
    setFormData,
    setExtend
});
</script>