<template>
  <div v-loading.fullscreen.lock="fullscreenLoading" class="page">
    <pageTitle title="车企实名认证" />
    <steps :data="dict.carEnterpriseRealnameSteps" :index="1" />
    <page-module name="基本信息" icon="info">
      <FlowEnterpriseInfo ref="baseInfo" :data="pageData" />
    </page-module>
    <div class="next-step">
      <el-button size="small" plain @click="onPrevStep">上一步</el-button>
      <el-button size="small" type="primary" @click="onNextStep">下一步</el-button>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import FlowEnterpriseInfo from './components/flow-enterprise-info'
import Common from '@/components/Common'
import { queryCarEnterpriseDetail } from '@/api/realname-car-enterprise'
export default {
  name: 'CarEnterpriseRealnameFlow2',
  components: {
    FlowEnterpriseInfo
  },
  mixins: [Common],
  data() {
    return {
      fullscreenLoading: false,
      pageData: {}
    }
  },
  computed: {
    ...mapGetters(['dict'])
  },
  created() {
    // this.init()
    this.getBaseInfo()
  },
  methods: {
    // init() {
    //   this.getCacheData()
    //   if (this.$route.params.from === 'prev') {
    //     this.restoreCacheData()
    //   } else {
    //     this.resetStepData()
    //   }
    // },

    // getCacheData() {
    //   this.cacheData = this.cacheGetStepData(this.cacheKey)
    // },

    // restoreCacheData() {
    //   if (this.isValidObject(this.cacheData)) {
    //     this.pageData = this.cloneObject(this.cacheData)
    //   } else {
    //     this.resetStepData()
    //   }
    // },

    // resetStepData() {
    //   this.pageData = {
    //     companyName: '',
    //     companyCertType: '',
    //     companyCertNumber: ''
    //   }
    // },

    getBaseInfo() {
      this.fullscreenLoading = true
      return queryCarEnterpriseDetail({}).then(data => {
        this.pageData = {
          companyName: data.companyName,
          companyCertType: data.companyCertType,
          companyCertNumber: data.companyCertNumber
        }
        this.fullscreenLoading = false
      }).catch(() => {
        this.fullscreenLoading = false
      })
    },

    onPrevStep() {
      this.$router.push({ name: 'CarEnterpriseRealnameFlow1', params: { from: 'prev' }})
    },

    onNextStep() {
      // const data = this.$refs.baseInfo.getPendingCacheData()
      // this.cacheSetStepData(this.cacheKey, data)
      this.$router.push({ name: 'CarEnterpriseRealnameFlow3' })
    }
  }
}
</script>
