<template>
  <div>
    <!--<div class="step-menu">-->
      <!--<ul class="x-step">-->
        <!--<li :class="section >= 1?'active':''" >第一步：完善企业信息-->
          <!--<i class="x-split"></i></li>-->
        <!--<li :class="section >= 2?'active':''" >第二步：阅读相关条例-->
          <!--<i class="x-split"></i></li>-->
        <!--<li :class="section >= 3?'active':''" >第三步：提交申请</li>-->
      <!--</ul>-->
    <!--</div>-->
    <div class="mobile-tab-list">
      <step-first v-show="section == 1"
                  @sectionEvent="sectionChange"
                  @registerAction="onRegister"
                  :loginData="loginData"
                  @businessImgUrlAction="onBusinessImgUrl"
                  @isSelfCacheDataAction="onCacheData"></step-first>
      <step-second v-show="section == 2"
                   @sectionEvent="sectionChange"
                   :checkData="checkData"
                   :loginData="loginData"
                   :cacheData="cacheData"></step-second>
      <choose-storetype v-show="section == 3"
                  @sectionEvent="sectionChange"
      >

      </choose-storetype>
      <step-third v-show="section == 4"
                  @sectionEvent="sectionChange"
                  :registerData="registerData"
                  :enterpriseData="enterpriseData"
                  :checkData="checkData"
                  @businessImgUrlAction="onBusinessImgUrl"
                  :loginData="loginData"
                  :tab="tab" ref="clearInfo"></step-third>
    </div>
    </div>
</template>
<script>
  import StepFirst from '~components/mobile/register-saler/register/StepFirst.vue'
  import StepSecond from '~components/mobile/register-saler/register/StepSecond.vue'
  import StepThird from '~components/mobile/register-saler/register/StepThird.vue'
  import chooseStoretype from '~components/mobile/register-saler/register/chooseStoretype.vue'
  export default {
    data () {
      return {
        tab: 'ORIGINAL_FACTORY',
        section: 1,
        checkData: {
          checked: false
        },
        registerData: {
          enterprise: {},
          c: false,
          url: ''
        },
        loginData: {
          isSelf: true,
          section: 1,
          enterprise: {}
        },
        cacheData: {},
        enterpriseData: {},
        businessImgUrl: ''
      }
    },
    components: {
      StepFirst,
      StepSecond,
      StepThird,
      chooseStoretype
    },
    computed: {
      user () {
        return this.$store.state.option.user
      }
    },
    created () {
      let ens = this.user.data.enterprises
      let isSelf = true
      let tempEnterprise = {}
      if (ens && ens.length) {
        ens.forEach(function (item) {
          if (item.current) {
            isSelf = false
            tempEnterprise = item
          }
        })
      } else {
        isSelf = true
      }
      if (!isSelf) { // 是企业
        this.$http.get('/basic/enterprise/' + tempEnterprise.uu + '/info')
          .then(response => {
            this.enterpriseData = response.data
            if (this.user.data.enterprise.isVendor === 313) {
              this.$http.get('/basic/vendor/transactionInfo').then(response => {
                if (response.data.isOpenStore === false) {
                  this.section = 3
                  this.checkData.checked = true
                }
              })
          } else {
            this.section = 1
            this.checkData.checked = false
          }
          })
      } else { // 是个人
        this.$http.get('/basic/user/userCacheEnterprise')
          .then(response => {
            if (!response.data.name) {
              this.section = 1
              this.checkData.checked = false
            } else if (!response.data.enIsRead) {
              this.section = 2
              this.checkData.checked = false
              this.enterpriseData = response.data
            } else if (response.data.enIsRead) {
              this.section = 3
              this.checkData.checked = true
              this.enterpriseData = response.data
            }
          })
      }
      this.loginData.isSelf = isSelf
      this.loginData.section = this.section
      this.loginData.enterprise = tempEnterprise
    },
    methods: {
      sectionChange: function (num, tab) {
        this.section = num
        this.tab = ''
        if (tab) {
          this.$refs.clearInfo.clearInfo()
          this.tab = tab
        }
      },
      onRegister: function (data) {
        this.registerData.isValidRegister = data.isValidRegister
        this.registerData.enterprise = data.enterprise
        this.registerData.url = data.url
      },
      onCacheData: function (cache) {
        this.cacheData = cache
      },
      onBusinessImgUrl: function (url) {
        this.businessImgUrl = url
      }
    }
  }
</script>
<style>
</style>
