add.vue 3.98 KB
<template>
  <div class="layout" v-loading="loading">
    <div class="tabs flex">
      <template v-for="(i,index) in tabs">
        <template>
          <div
            :key="index"
            :class="['tab flex',{'active':step == index + 1}]"
          >
            <template v-if="index != 0">
              <div class="line"></div>
            </template>
            <template v-if="step == 2 && index == 0">
              <div class="icon finish">
                <span class="el-icon-check"></span>
              </div>
            </template>
            <template v-else>
              <div class="icon">{{index + 1}}</div>
            </template>
            {{i}}
          </div>
        </template>
      </template>
    </div>
    <div class="content">
      <step-one
        v-show="step == 1"
        ref="stepOne"
      />
      <step-two
        v-show="step == 2"
        ref="stepTwo"
      />
    </div>
    <GLFooter class="footer">
      <el-button
        @click="handleCancel"
        size="medium"
      >{{step == 1?'取消':'上一步'}}</el-button>
      <el-button
        type="primary"
        @click="handleConfirm"
        size="medium"
      >{{step == 1?'下一步':'提交'}}</el-button>
    </GLFooter>
  </div>
</template>

<script type='text/ecmascript-6'>
import StepOne from './components/StepOne/index.vue'
import StepTwo from './components/StepTwo/index.vue'
export default {
  components: { StepOne, StepTwo },
  name: '',
  data () {
    return {
      parsedData: [],
      step: 1,
      tabs: ['基本信息', '配置内容'],
      loading:false
    }
  },
  mounted () {
  },
  methods: {
    handleCancel () {
      const { step } = this
      step == 1 ? this.$router.go(-1) : this.step = 1
    },
    handleConfirm () {
      const { step, $refs: {
        stepOne,
        stepTwo
      } } = this
      if (step == 1) {
        stepOne.formRef().validate(valid => {
          if (valid) this.step = 2
        })
      } else {
        stepTwo.formRef().validate(async valid => {
          if (valid) {
            this.loading = true
            try {
              const params = {
                ...stepOne.configForm,
                ...stepTwo.configForm,
                status: 1
              }, res = await this.$apis.questionnaire.addQuestionnaire(params)
              console.log(res)
              if (res) {
                this.$message({
                  message: '创建成功',
                  type: 'success'
                })
                this.$router.go(-1)
              }
              else throw '创建失败'
            } catch (error) {
              this.loading = false
              if (error) this.$message.error(error)
            }
          }
        })
      }
    }

  }
}
</script>

<style scoped lang='scss'>
.layout {
  position: absolute;
  width: 100%;
  height: calc(100vh - 48px);
  top: 0;
  left: 0;
  .tabs {
    height: 64px;
    justify-content: center;
    -webkit-user-select: none;
    .tab {
      font-size: 16px;
      color: #000000a6;
      line-height: 24px;
      .icon {
        width: 32px;
        height: 32px;
        border-radius: 100%;
        border: 1px solid #c6c6c6;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 8px;
        font-size: 14px;
        color: #c6c6c6;
      }
      .finish {
        border-color: #5850ff !important;
        border-width: 2px;
      }
      .line {
        width: 160px;
        height: 1px;
        background: #e5e5e5;
        margin: 0 8px;
      }
    }
    .active {
      font-weight: 500;
      color: #000000d9;
      .icon {
        background: #5850ff;
        border-color: #5850ff;
        color: #fff;
      }
    }
    .el-icon-check {
      color: #5850ff;
      font-size: 18px;
      font-weight: 700;
    }
  }
  .content {
    height: calc(100% - 136px);
    background-color: #fff;
    margin: 0 24px;
    border-radius: 0 4px 4px 4px;
  }
  .footer {
    padding: 16px 0;
  }
}
</style>