<template>
  <div class="rightBox">
    <div class="edit_top">
      <div class="edit_btn">
        <span :class="{ active: type == 1 }" @click="type = 1">编辑</span>
        <span :class="{ active: type == 2 }" @click="type = 2">预览</span>
        <!-- <span :class="{ active: type == 3 }" @click="type = 3">回答</span>
        <span :class="{ active: type == 4 }" @click="type = 4">统计</span> -->
      </div>
      <div class="op_btn">
        <el-button type="primary" size="small" @click="lastSteps">上一步</el-button>
        <el-button type="primary" size="small" @click="save">保存</el-button>
        <el-button type="primary" size="small" @click="publish">发布</el-button>

      </div>
    </div>
    <div class="e_box">
      <editBox v-if="type == 1" :checkJson="checkJson"  @changeJson="changeJson" :title="title"></editBox>
      <checkBox v-if="type == 2" :cJson="checkJson" :title="title"></checkBox>
    </div>
  </div>
</template>

<script>
import editBox from './edit/index.vue'
import checkBox from './check/index.vue'

export default {
  components: {
    editBox,
    checkBox
  },
  props: {
    title: {
      type: String
    },
    testType: {
      type: Array
    },
    see: {
      type: Boolean
    },
    steps: {
      type: Number
    },
    cJson: {
      type: Array
    }
  },
  data() {
    return {
      type: 1,
      checkJson: [],
    }
  },
  watch: {
    cJson: {
      handler: function (newVal, oldVal) { 
        this.checkJson = this.depthCopy(newVal);
      },
      deep: true,
    },
  },
  methods: {
    lastSteps() {
      this.$emit('update:steps', this.steps - 1)
    },
    save() {
      this.$emit("save")
    },
    publish() {
      this.$emit("publish")
    },
    depthCopy(s) {
      return s ? JSON.parse(JSON.stringify(s)) : ''
    },
    changeJson(json) {
      this.$emit("update:cJson", json);
    }
  },
  mounted() {
    this.checkJson = this.depthCopy(this.cJson);
  },
}
</script>

<style scoped>
.rightBox {
  width: calc(100%);
  background: #F0F2F5;
  overflow: auto;
  height: calc(100%);
  margin: 0 auto;
  position: relative;
  box-sizing: border-box;
}

.edit_top {
  height: 50px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.edit_top>.edit_btn {
  display: flex;
  height: 100%;
  align-items: center;
}

.edit_top>.edit_btn>span {
  cursor: pointer;
  padding-bottom: 5px;
  display: block;
}

.edit_top>.edit_btn>.active {
  color: #3e88f4;
  border-bottom: 2px solid #2f80f3;
}

.edit_top>.edit_btn>span+span {
  margin-left: 35px;
}

.edit_top>.op_btn {
  position: absolute;
  right: 30px;
}

.e_box {
  height: calc(100% - 50px);
  width: 100%;
  overflow: hidden;
  background: rgb(196, 226, 241);
}</style>