StepBar.vue 4.46 KB
<template>
  <div>
    <div class="step-bar container m-b-20">
      <div v-for="(step, index) in steps" :key="index" class="step ">
        <div :class="['step-content', { 'active': index === currentStep },{ 'completed': index < currentStep }]">
          <div class="step-circle">{{ currentStep > index ? '' : index + 1 }}</div>
          <div class="step-label">{{ step }}</div>
        </div>
        <div class="step-line" v-if="index < steps.length - 1"></div>
      </div>
    </div>

    <div class="center">
      <slot name="center"></slot>
    </div>

    <div class="button-container">
      <el-button v-if="currentStep > 0" @click="previousStep" class="previous-button">上一步</el-button>
      <el-button v-if="currentStep == 0" @click="cancelOptions" class="previous-button">取消</el-button>
      <el-button type="primary" v-if="currentStep < steps.length - 1" @click="nextStep" class="next-button">下一步
      </el-button>
      <el-button type="primary" v-if="currentStep == steps.length - 1" class="previous-button" @click="saveTemplate">
        保存
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentStep: 0, // 当前步骤
      isNext: false,
      steps: ['选择旅程模版', '配置旅程SOP', '分配门店'], // 步骤条的文本

      tplId: '',
      sopTplGrants: null,
      nodes:[]
    };
  },
  methods: {
    previousStep() {
      if (this.currentStep > 0) {
        this.currentStep--;
        this.$emit('changeStep', this.currentStep)
      }
    },
    nextStep() {
      // 每次进入先把isNext赋值为false 校验通过后再赋值为true
      this.isNext = false
      if (this.currentStep == 0) {
        this.$bus.$emit('vertifyTemplate', {currentStep: this.currentStep})
      }
      if (this.currentStep < this.steps.length - 1 && (this.isNext || this.currentStep == 1)) {
        this.currentStep++;
        this.$emit('changeStep', this.currentStep)
      }
    },
    cancelOptions() {
      this.$router.back()
    },
    saveTemplate() {
      // 校验门店
      this.isNext = false
      this.$bus.$emit('vertifyMerchant', {currentStep: this.currentStep})
      let params = {
        tplId: this.tplId,
        sopTplGrants:this.sopTplGrants,
        nodes:this.nodes
      }
      if (this.isNext){
        this.$apis.journeyConfig.sopInstsApi(params).then(res=>{
          if (res  && res.code == 200 ){
            console.log(res)
            this.$message.success('创建模板实例成功')
            this.$router.back()
          }else{
            this.$message.error(res.message)
          }
        }).catch(err => {
          console.log(err + 'err')
        })
      }
    }
  },
  mounted() {
    this.$bus.$on('whetherToProceedNext', (data) => {
      this.isNext = data.isNext
      this.tplId = data.tplId
    })

    this.$bus.$on('saveEvent', (data) => {
      this.isNext = data.isNext
      this.sopTplGrants = data.sopTplGrants
    })

    this.$bus.$on('sopListSet',data =>{
      this.nodes = data.sopList
    })
  }
};
</script>


<style lang="scss" scoped>
.step-bar {
  display: flex;
  align-items: center;
  justify-content: center;

  .step {
    display: flex;
    align-items: center;
    //margin: 0 10px;

    &::before {
      content: '';
      flex-grow: 1;
      height: 2px;
      background-color: #ccc;
      margin-right: 5px;
    }

    &:first-child::before {
      display: none;
    }

    & .active {
      .step-circle {
        border-color: #5850FF;
        background: #5850FF;
        color: #ffffff;
      }

      .step-label {
        color: #5850FF;
      }
    }

    & .completed {
      .step-circle {
        border-color: #5850FF;

        &::after {
          content: "√";
          color: #5850FF;
          font-size: 20px;
        }
      }
    }

    .step-line {
      height: 1px;
      width: 200px;
      background: #ccc;
      margin-left: 10px;
    }

    .step-content {
      display: flex;
      align-items: center;
    }

    .step-circle {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 2px solid #ccc;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .step-label {
      margin-left: 10px;
      text-align: center;
    }
  }
}

//.center{
//  min-height: 700px;
//}

.button-container {
  //bottom: 0;
  display: flex;
  justify-content: center;
  margin-top: 20px;

  .previous-button,
  .next-button {
    padding: 10px 20px;
    margin: 0 10px;
  }
}
</style>