<template>
  <div id="create-success">
    <div v-show="step === 2" class="box one">
      <van-cell-group class="input-cell">
        <van-field v-model="newTemplateName" placeholder="请输入新的模板名称！" />
      </van-cell-group>
    </div>
    <div v-show="step === 1" class="box two">
      <div class="success-icon">
        <img class="fg" src="../../../public/img/success.png" alt="success-fg">
        <p>创建活动成功！</p>
      </div>
    </div>
    <div class="box three">
      <div class="btn-group">
        <template v-if="step === 1">
          <van-button type="info" @click="saveNewTemplate">保存为新的模板</van-button>
          <van-button type="info" @click="$router.push('/')">完成</van-button>
        </template>
        <template v-if="step === 2">
          <van-button type="info" @click="$router.push('/ActTemplate')">取消</van-button>
          <van-button type="info" @click="save">完成</van-button>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import * as API_Active from '@/api/active';
export default {
  name: "createSuccess",
  components: {},
  data() {
    return {
      newTemplateName: '',
      step: 1
    };
  },
  methods: {
    save() {
      let params = {
        id: 0,
        activityId: this.$route.params.activityId,
        logo: this.$route.params.logo,
        des: this.$route.params.des,
        activityType: this.$route.params.activityType,
        templateName: this.newTemplateName
      }
      API_Active.saveTemplate(params).then(res=>{
        this.$toast('模板保存成功');
        setTimeout(() => {
          this.$router.push('/ActTemplate')
        }, 2000)
      })
    },
    saveNewTemplate() {
      this.step = 2;
    }
  }
};
</script>

<style lang="scss">
#create-success {
  display: flex;
  flex-direction: column;
  height: 100%;
  .box {
    margin-bottom: 20px;
  }
  
  .one { 
    flex: 1;
    .input-cell {
      width: 90%;
      margin: 20px auto;
      border: 1px solid #d4cfcf;
    }
  }

  .two {
    flex: 3;
    .success-icon {
      margin-top: 100px;
      text-align: center;
      img {
        margin: 0 auto;
      }
      p {
        font-size: 14px;
      }
    }
  }

  .three { 
    display: flex;
    justify-content: center;
    padding: 0 20px;
    .btn-group {

      .van-button {
        width: 150px;
        &:first-child{
          margin-right: 10px;
        }
      }
    }
  }
}
</style>
