<template>
  <a-card :bordered="false">
    <a-steps class="steps" :current="currentTab">
      <a-step title="创建计划" />
      <a-step title="创建广告组" />
      <a-step title="创建创意" />
    </a-steps>
    <div class="content">
      <step1 v-if="currentTab === 0" @nextStep="nextStep" ref="step" />
      <step2 v-if="currentTab === 1" :campaignId="campaignId" @nextStep="nextStepTwo" @prevStep="prevStep" />
      <component  v-if="currentTab === 2" :is="formComponent" @prevStep="prevStepTwo" @removeTab="remove"></component>
      <!-- <step3 v-if="currentTab === 2" @prevStep="prevStepTwo" @removeTab="remove" /> -->
    </div>
  </a-card>
</template>

<script>
import Step1 from './Step1'
import Step2 from './Step2'
import Step3 from './Step3'
import Step4 from './Step4'
export default {
  name: 'StepForm',
  components: {
    Step1,
    Step2,
    Step3,
    Step4
  },
  data() {
    return {
      currentTab: 0,

      // form
      form: null,
      campaignId: null,
      formComponent:null
    }
  },
  methods: {
    // handler
    nextStep(campaignId) {
      this.campaignId = campaignId
      if (this.currentTab < 2) {
        this.currentTab += 1
        localStorage.setItem('step', this.currentTab)
      }
    },
    nextStepTwo() {
      if (this.currentTab < 2) {
        this.currentTab += 1
        localStorage.setItem('step', this.currentTab)
      }
     
    },
    prevStep(campaignId) {
      if (this.currentTab > 0) {
        this.currentTab -= 1
        localStorage.setItem('step', this.currentTab)
        this.$nextTick(() => {
          this.$refs.step.getCampaignId(campaignId)
        })
      }
    },
    prevStepTwo() {
      if (this.currentTab > 0) {
        this.currentTab -= 1
        localStorage.setItem('step', this.currentTab)
      }
    },
    finish() {
      this.currentTab = 0
    },
    remove(key) {
      alert(key)
      this.$emit('removeTab', key)
    }
  },
  watch:{
    currentTab(n,o){
      if(n==2){
        var data = JSON.parse(localStorage.getItem('pans')).map(item => {
            return {
              ...item,
            }
          })
        if(data[0].unitType == '7'){
          this.formComponent = Step4
        }else{
          this.formComponent = Step3
        }
        
      }
    }
  },
  mounted() {
    this.currentTab = parseInt(localStorage.getItem('step'))
  }
}
</script>

<style lang="scss" scoped>
.steps {
  max-width: 750px;
  margin: 16px auto;
}
</style>
