<!--  -->
<template>
  <div class="Big-Book-Single">
    <div
      class="Big-Book-Single-content"
      style="margin-left: 50px; margin-top: 20px"
    >
      <div
        class="Big-Book-main"
        v-for="(item, index) in curQue.con"
        :key="item + index"
        style="margin-bottom: 20px"
      >
        <MultiRowInputModule
          :curQueItem="item"
          :curQue="curQue"
          :deleteOptionOne="deleteOptionOne"
          :index="index"
        />
      </div>
      <div class="Big-Book-addrole">
        <div class="addoption" @click="addOption">添加一个</div>
      </div>
      <div class="Big-Book-divide">
        <el-divider content-position="center">功能设置</el-divider>
      </div>
      <div>
        <el-checkbox-group v-model="checkList" @change="handleCheckedFnChange">
          <el-checkbox
            v-for="(fnItem, fnIndex) in curQue.fn_list"
            :key="'fn_list' + fnItem.type + fnIndex"
            :label="fnItem.name"
          ></el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
  </div>
</template>

<script>
import MultiRowInputModule from "../common/MultiRowInputModule.vue";

export default {
  name: "Single",
  props: ["curQue", "fn_data"],
  components: {
    MultiRowInputModule,
  },
  data() {
    return {
      checkList: [],
      form: {
        stem: {
          con: "",
          pinyin: "",
          english: "",
          highlight: "",
          underline: "",
          img_url: [],
          mp3_url: [],
        },
      },
    };
  },
  computed: {},
  watch: {},
  //方法集合
  methods: {
    // 修改正确选项中得某一个为正确答案
    changAnswer(index) {
      this.curQue.option.forEach((item, i) => {
        if (index == i) {
          this.curQue.correct[0].input[index] = item.Answer;
        }
      });
    },
    // 删除其中一个选项
    deleteOptionOne(index) {
        this.$confirm("确定要删除吗?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
        })
        .then(() => {
            if (this.curQue.con.length <= 1) {
                this.$message.warning("至少要保留1个选项");
                return;
            }
            this.curQue.con.splice(index, 1);
        })
    },
    // 新增选项
    addOption() {
      // if (!last.hanzi && !last.pinyin) {
      //   this.$message.warning("数据不能全是空");
      //   return;
      // }
      let type = this.curQue.type;
      let cur_fn_data_arr = this.fn_data.filter((item) => item.type == type);
      let cur_fn_data = JSON.parse(JSON.stringify(cur_fn_data_arr[0]));
      let obj = cur_fn_data.data_structure.con[0];
      this.curQue.con.push(obj);
    },
    // 更多配置选择
    handleCheckedFnChange(value) {
      let fn_list = JSON.parse(JSON.stringify(this.curQue.fn_list));
      this.curQue.fn_list = fn_list.map((item) => {
        if (value.indexOf(item.name) > -1) {
          this.checkList.push(item.name);
          item.isFn = true;
        } else {
          item.isFn = false;
          this.curQue.con.forEach((it) => {
            it.annotation = "";
          });
        }
        return item;
      });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.curQue.fn_list.forEach((item) => {
      if (item.isFn) {
        this.checkList.push(item.name);
      }
    });
    // let length = this.curQue.option.length;
    // if (length != 0) {
    //   for (let i = 0; i < length; i++) {
    //     this.curQue.correct[0].input.push("");
    //   }
    // }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scope>
//@import url(); 引入公共css类
.Big-Book-Single {
  &-content {
    &.m {
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
    }

    .Big-Book-title {
      font-size: 16px;
      line-height: 40px;
      color: #000;
      margin-right: 15px;
    }
    .Big-Book-main {
      > div {
        margin-bottom: 10px;
        &.Big-Book-pinyin {
          display: flex;
          justify-content: flex-start;
          align-items: center;
        }
      }
    }
  }
  .Big-Book-addrole {
    > div {
      margin-left: 115px;
      width: 600px;
      height: 40px;
      background: #f3f3f3;
      border: 1px dashed rgba(0, 0, 0, 0.15);
      box-sizing: border-box;
      border-radius: 4px;
    }
  }
  .Big-Book-more {
    .Big-Book-more-text {
      position: relative;
      text-align: center;
    }
    .Big-Book-more-text:before,
    .Big-Book-more-text:after {
      position: absolute;
      background: #ccc;
      content: "";
      height: 1px;
      top: 50%;
      width: 45%;
    }
    .Big-Book-more-text:before {
      left: 10px;
    }
    .Big-Book-more-text:after {
      right: 10px;
    }
    .Big-Book-more-main {
      display: flex;
      > :not(:nth-child(1)) {
        margin-left: 30px;
      }
    }
  }
}
</style>
<style lang="scss">
</style>