<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,
      progress: {}
    }
  },
  methods: {
    // 获取报名信息
    getApplication() {
      this.loaded = false
      api.getApplication().then(response => {
        const { progress = {} } = response.data
        this.progress = progress
        // 缴费成功
        // if (progress.PREPAYMENT.total_progress) {
        //   this.$router.push('/my/account')
        // } else {
        //   this.loaded = true
        // }
        this.loaded = true
      })
    },
    handleUpdate(data) {
      const { progress } = data
      this.progress = progress
    }
  },
  computed: {
    isSubmited() {
      const { FILLING = {} } = this.progress
      if (FILLING && FILLING.basic_info) {
        return !!FILLING.basic_info.progress
      }
      return false
    }
  },
  beforeCreate() {
    document.body.style.background = '#fff'
  },
  created() {
    // this.$router.replace('/my/account')
  },
  beforeMount() {
    this.getApplication()
  },
  destroyed() {
    document.body.style = ''
  }
}
</script>
