<template>
    <div class="content" v-if="myInfo.ent_id"> 
        <div :class="{ 'top-banner banner': true, [bannerId]: true }" v-if="this.$route.path.startsWith('/aidt')">
            <div class="flex-column align-center justify-center content">
                <h1 class="banner-title text-ct white" aria-live="assertive">{{ $getMenuInfo().menuNm }}</h1>
                <p class="box-title text-ct white">{{ $getMenuInfo().menuCn }}</p>
            </div>
        </div>
        <PageNavigationBar />
        <div class="pt100 pb100 company-page">
            <div v-if="innerStep === 1 || innerStep ===3" class="content">
                <div class="flex-column justify-center align-center content">
                    <div class="login-wrap pd30 border">
                        <div class="page-title mb30">
                            <p class="text-ct">비밀번호 확인</p>
                        </div>
                        <div class="pw-zone mb10">
                            <input type="password" name="" id="pw" placeholder="PASSWORD를 입력하세요." v-model="mbrEncptPswd"
                            @keyup.enter="checkPwd()" class="full-input"  />
                        </div>
                        <button class="large-btn blue-btn ml0" title="확인" @click="checkPwd()">
                            확인
                        </button>
                    </div>
                </div>
            </div>
            <div class="w1280" v-else-if="innerStep === 2" id="companyTitle1">
               <CompanyManageComponent @setPage="changePage" ></CompanyManageComponent>
            </div>
            <div class="w1280"  v-else-if="innerStep === 4" id="companyTitle4">
               <CompanyInfoUpdateComponent @setPage="changePage" ></CompanyInfoUpdateComponent>
            </div>
        </div>
    </div>
    <div class="content" v-else>
        <div :class="{ 'top-banner banner': true, [bannerId]: true }" v-if="this.$route.path.startsWith('/aidt')">
            <div class="flex-column align-center justify-center content">
                <h1 class="banner-title text-ct white" aria-live="assertive">{{ $getMenuInfo().menuNm }}</h1>
                <p class="box-title text-ct white">{{ $getMenuInfo().menuCn }}</p>
            </div>
        </div>
        <PageNavigationBar />
        <div class="pt100 pb100">
            <CompanyApplyComponent @applySuccess="handleApplySuccess()"></CompanyApplyComponent>
        </div>
    </div>
</template>

<script>
import PageNavigationBar from '../../../component/pagenavigationbar/PageNavigationBar.vue';
import CompanyManageComponent from './CompanyManageComponent.vue';
import CompanyInfoUpdateComponent from './CompanyInfoUpdateComponent.vue';
import CompanyApplyComponent from './CompanyApplyComponent.vue';
import { useStore } from "vuex";
import _ from "lodash";



//API
import { pwdCheck, detailProc } from '../../../../resources/api/userPage';


export default {
    data() {
        return {           
            innerStep: 1,         
            mbrEncptPswd :'',
            myInfo: {},
            store: useStore(),
            bannerId:'mypage-banner'
        }
    },
    methods: {      
        // 페이지 변경 
        changePage : function(index){
            this.innerStep = index;
        },

        handleApplySuccess() {
            this.init()
            this.innerStep = 2; // 신청 성공 후 화면 전환
        },
       
        //현재비밀번호 확인
        async checkPwd() {          
            if(this.$isEmpty(this.mbrEncptPswd)){
                alert('비밀번호를 입력해 주세요')
                return false;  
            }

            const data = { 'mbrEncptPswd' : this.mbrEncptPswd }

            try {
                const res = await pwdCheck(data);
                if(res.status == 200) {
                     this.innerStep =  this.innerStep +1;
                     this.mbrEncptPswd = '';
                }
            } catch(error) {  
                alert(error.response.data.message)
            }
        },     

        //내정보 조회
        async init() {

            const vm = this;
            try {
                vm.store.commit('setLoading', true); //로딩 시작
                const res = await detailProc();
                if(res.status == 200) {
                    this.myInfo = res.data.data;
                }
            } catch(error) {
                alert(error.response.data.message)
                this.$router.push({ path: '/'})
            } finally {
                vm.store.commit('setLoading', false); //로딩 종료
            }
        },
    },
    watch: {
    },
    computed: {},
    components: {
        'PageNavigationBar': PageNavigationBar,
        'CompanyManageComponent' : CompanyManageComponent,
        'CompanyInfoUpdateComponent' : CompanyInfoUpdateComponent,
        'CompanyApplyComponent' : CompanyApplyComponent
    },
    mounted() {},
    created() {
        this.init()
    }
}
</script>


<style scoped>
a {
    color: blue;
    text-decoration: underline;
  }
</style>
