<template>
  <div v-if="loaded">
    <index-welcome @update="handleUpdate" v-if="!isSubmited" />
    <index-pay v-else />
  </div>
</template>

<script>
import IndexWelcome from './indexWelcome.vue'
import IndexPay from './indexPay.vue'

import * as api from '@/api/my'
export default {
  components: { IndexWelcome, IndexPay },
  data() {
    return {
      loaded: false,
      isSubmited: false
    }
  },
  methods: {
    // 获取报名信息
    getApplication() {
      this.loaded = false
      api.getApply().then(response => {
        const { error, data } = response
        if (parseInt(error) === 0 && data) {
          this.isSubmited = true
        }
        this.loaded = true
      })
    },
    handleUpdate() {
      this.isSubmited = true
    }
  },
  beforeCreate() {
    document.body.style.background = '#fff'
  },
  created() {
    // this.$router.replace('/my/account')
  },
  beforeMount() {
    this.getApplication()
  },
  destroyed() {
    document.body.style = ''
  }
}
</script>
