<template>
    <div class="page_container">
        <div class="bg-breadcrumb">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> 开发管理 </el-breadcrumb-item>
                <el-breadcrumb-item :to="{ path: '/develop/account' }"> 系统账号管理 </el-breadcrumb-item>
                <el-breadcrumb-item> {{ route.query.type === "0" ? '新建' : '编辑'}} </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="page_content flex_cloumn">
            <div class="content_top">
                <div class="content_process">
                    <div>
                        <el-steps :active="step">
                            <el-step title="">
                                <template #icon>
                                    <span class="process_desc"><img src="/src/assets/imgs/home_ic_user.png" alt=""> 业务系统信息</span>
                                </template>
                            </el-step>
                            <el-step title="">
                                <template #icon>
                                    <span class="process_desc"><img src="/src/assets/imgs/home_ic_user.png" alt=""> 联系人信息</span>
                                </template>
                            </el-step>
                            <el-step title="">
                                <template #icon>
                                    <span class="process_desc"><img src="/src/assets/imgs/home_ic_user.png" alt=""> 完成</span>
                                </template>
                            </el-step>
                        </el-steps> 
                    </div>
                     
                </div>
                <div class="content_main">
                    <systemForm v-show="step === 1" ref="systemFormRef" :data="tempFormData" @action="getSystemFormData"></systemForm>
                    <contactForm v-show="step === 2" ref="contactFormRef" :data="tempFormData" @action="getContactFormData"></contactForm>
                    <div class="process_end" v-show="step === 3">
                            <el-button  @click="cancel">返回列表</el-button>
                            <el-button type="primary" @click="continueCreate">继续创建</el-button>
                    </div>
                </div>
            </div>
            <div class="content_bottom" v-if="step !== 3">
                <div v-show="step === 1">
                    <el-button  @click="cancel">取消</el-button>
                    <el-button type="primary" @click="nextStep">下一步</el-button>
                </div>
                <div v-show="step === 2">
                    <el-button>取消</el-button>
                    <el-button type="primary" @click="previousStep">上一步</el-button>
                    <el-button type="primary" @click="submit">提交</el-button>
                </div>
                
            </div>
        </div>

    </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router';
import systemForm from './system-form.vue';
import contactForm from './contact-form.vue';
import { reactive, ref,onBeforeMount,toRefs,computed, onBeforeUnmount, onMounted  } from 'vue';

const route = useRoute();
const router = useRouter();
const step = ref(1);
const systemFormRef = ref(null);
const contactFormRef = ref(null);
const tempFormData = ref(null)
const formData = ref({
  org: '',
  code: '',
  name: '',
  desc: '',
  logo: '',
  role: '',
  account: '',
  password: '',
  url: '',
  firm_name: '',
  is_use: '',
  contact_user: '',
  phone: '',
  email: '',
  remark: '',
}); //业务系统表单+联系人表单


onBeforeUnmount(()=>{
    
})
onMounted(() => {
    if(route.query.type === "1") {
        setTimeout(()=> {
            systemFormRef.value.setForm({
                org: 'a',
                code: 'b',
                name: 'b',
                desc: 'b',
                logo: ['b'],
                role: 'b',
                account: 'b',
                password: 'b',
                confirm_password: 'b',
                url: 'b',
                firm_name: 'b',
                is_use: 'b',
               
            })
            contactFormRef.value.setForm({
                contact_user: 'c',
                phone: 'c',
                email: 'c',
                remark: 'c',
            })
        },500)
    }
})
// 下一步
const nextStep = () => {
    systemFormRef.value.submitForm();
}
//业务系统表单检验触发事件 data为null 校验失败
const getSystemFormData = (data) => {
        if(data) {
            formData.value = Object.assign(formData,data);
            step.value = 2;
        }else {

        }
}
//联系人表单检验触发事件 data为null 校验失败
const getContactFormData = (data) => {
    if(data) {
        formData.value = Object.assign(formData,data);
        console.log(formData);
        step.value = 3;
    }
}
//上一步
const previousStep = () => {
    step.value--;
}
//提交表单
const submit = () => {
    contactFormRef.value.submitForm();
}
//继续创建 清空表单
const continueCreate = () => {
    systemFormRef.value.clearForm();
    contactFormRef.value.clearForm();
    step.value = 1;
}
//取消
const cancel = () => {
    router.go(-1);
}

</script>

<style scoped>
.flex_cloumn {
    display: flex;
    flex-direction: column;
}
.content_top {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
}
.content_top::-webkit-scrollbar {
  width: 5px;
  height: 0px;
}
.content_top::-webkit-scrollbar-thumb {
  background: #dedede;
  border-radius: 10px;
  height: 0px;
}
.content_top::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 2px;
}

.content_bottom {
    height: 84px;
    line-height: 84px;
    text-align: right;
    padding: 0 20px;
    border-top: 1px solid #e6e9ef;
}
.content_process {
    border-bottom: 1px solid #e6e9ef;
    padding: 38px 16%;
}
.content_main {
    flex: 1;
    padding: 30px;
    box-sizing: border-box;
}
.process_desc {
    background-color: #fff;
    display: inline-block;
    position: absolute;
    padding: 0 5px;
    font-size: 18px;
    color: #202531;
    font-weight: bold;
}
.process_desc img {
    height: 25px;
    width: 25px;
    vertical-align: middle;
}
.process_end {
    text-align: center;
    padding: 50px 0;
    
}

</style>
