<template>
  <div class="rightBox">
    <div class="title">
      <div class="c_info_title">创建表单内容</div>
    </div>
    <div class="edit_top">
      <div class="edit_btn">
        <span class="edit" :class="{ active: type == 1 }" @click="type = 1">编辑</span>
        <span class="check" :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", 4)
    },
    publish() {
      this.$emit("publish")
    },
    depthCopy(s) {
      return s ? JSON.parse(JSON.stringify(s)) : ''
    },
    changeJson(json) {
      console.log(json);
      this.$emit("update:cJson", json);
    }
  },
  mounted() {
    this.checkJson = this.depthCopy(this.cJson);
  },
}
</script>

<style scoped>
.c_info_title {
  padding: 15px 0 15px 0;
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 0 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  line-height: 20px;
}

.c_info_title::before {
  content: '';
  display: block;
  width: 3px;
  height: 20px;
  background: #0061FF;
  border-radius: 3px;
  margin: 0 5px 0 0;
}

.rightBox {
  width: calc(100%);
  /* background: #F0F2F5; */
  background: #fff;
  overflow: auto;
  height: calc(100%);
  margin: 0 auto;
  position: relative;
  box-sizing: border-box;
}

.rightBox>.title {
  background: #fff;
  width: 100%;
  padding: 0 20px 0;
  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: 40px;
  align-items: center;
  border: 1px solid #E5E5E5;
  box-sizing: border-box;
  padding: 4px;
  border-radius: 4px;
}

.edit_top>.edit_btn>span {
  cursor: pointer;
  padding-bottom: 5px;
  display: block;
  width: 90px;
  padding: 0 15px;
  height: 100%;
  font-size: 14px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.edit_top>.edit_btn>.active {
  color: #3e88f4;
  /* border-bottom: 2px solid #2f80f3; */
  background: rgb(224, 234, 251);
}

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


.edit_top>.edit_btn>span::before {
  content: '';
  display: block;
  background-size: 100% 100%;
  margin-right: 8px;
}

.edit_top>.edit_btn>.check::before {
  width: 15px;
  height: 15px;
  background-image: url(../../../../../assets/icon/test/add_check_icon.png);
}

.edit_top>.edit_btn>.edit::before {
  width: 15px;
  height: 16px;
  background-image: url(../../../../../assets/icon/test/add_edit_icon.png);
}

.edit_top>.edit_btn>.active.check::before {
  background-image: url(../../../../../assets/icon/test/add_check_icon_active.png);
}

.edit_top>.edit_btn>.active.edit::before {
  background-image: url(../../../../../assets/icon/test/add_edit_icon_active.png);
}


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

.e_box {
  height: calc(100% - 135px);
  width: calc(100% - 40px);
  overflow: hidden;
  /* background: rgb(196, 226, 241); */
  background: #fff;
  border: 1px solid #E5E5E5;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin: 15px auto 0;
  border-radius: 5px;
}</style>