<!--  -->
<template>
  <div class="Big-Book-HzModule">
            
    <div class="adult-book-input-item">
      <span class="adult-book-lable">标题：</span>           
      <el-input
        type="textarea"
        class="adult-book-input"
        :autosize="{ minRows: 2 }"
        placeholder="请输入标题"
        v-model="curQueItem.title"
        @blur="curQueItem.title = curQueItem.title.trim()"
      ></el-input>
              
    </div>
    <div class="adult-book-input-item">
      <span class="adult-book-lable">图片</span>
      <Upload
        :changeFillId="changeImage"
        :datafileList="fileCon.img_list"
        :filleNumber="imgNumber"
        :uploadType="'image'"
      />
    </div>
    <div class="adult-book-input-item">
      <span class="adult-book-lable">内容</span>
      <el-input
        type="textarea"
        class="adult-book-input"
        :autosize="{ minRows: 2 }"
        placeholder="请输入文字"
        v-model="curQueItem.hanzi"
        @blur="onBlur(curQueItem, 'hanzi')"
      ></el-input>
      <div class="adult-book-input-item">
        <div v-if="checkList.indexOf('image_single') > -1">
          <el-radio
            @change="changeIsAnswer('single')"
            v-model="curQueItem.isAnswer"
            :label="index"
            >答案</el-radio
          >
        </div>
        <div v-if="checkList.indexOf('image_checkBox') > -1">
          <el-checkbox
            @change="changeIsAnswer('checkBox')"
            v-model="curQueItem.isChecked"
            :label="index"
            >答案</el-checkbox
          >
        </div>
        <div v-if="checkList.indexOf('image_judge') > -1">
          <el-radio-group v-model="curQue.correct[0].judge[index]">
            <el-radio label="true">正确</el-radio>
            <el-radio label="false">错误</el-radio>
          </el-radio-group>
        </div>
        <div
          class="adult-book-input-item"
          v-if="checkList.indexOf('image_spell') > -1"
        >
          <span class="adult-book-lable">答案</span>
          <el-input
            type="textarea"
            class="adult-book-input"
            :autosize="{ minRows: 2 }"
            placeholder="请输入答案"
            v-model.trim="curQue.correct[0].spell[index]"
          ></el-input>
        </div>
      </div>
    </div>
    <div
      style="margin-top: 10px"
      class="adult-book-input-item"
      v-if="
        checkList.indexOf('image_input') > -1 ||
        checkList.indexOf('image_gdcy') > -1 ||
        checkList.indexOf('image_dobleinput') > -1 ||
        checkList.indexOf('image_wordInput') > -1
      "
    >
      <span class="adult-book-lable" style="width: 50px">答案</span>
      <el-input
        type="textarea"
        class="adult-book-input"
        :autosize="{ minRows: 2 }"
        placeholder="请输入答案"
        v-model="curQue.correct[0].input[index]"
        @blur="onBlurCorrect(curQue.correct[0].input, 0)"
      ></el-input>
    </div>
    <div
      style="margin-top: 10px"
      class="adult-book-input-item"
      v-if="checkList.indexOf('image_dobleinput') > -1"
    >
      <span class="adult-book-lable" style="width: 50px">答案</span>
      <el-input
        type="textarea"
        class="adult-book-input"
        :autosize="{ minRows: 2 }"
        placeholder="请输入答案"
        v-model="curQue.correct[0].input[1]"
        @blur="onBlurCorrect(curQue.correct[1].input, 1)"
      ></el-input>
    </div>
    <div class="adult-book-input-item">
      <span class="adult-book-lable">音频</span>
      <Upload
        :changeFillId="changeMp3"
        :datafileList="fileCon.mp3_list"
        :filleNumber="mp3Number"
        :uploadType="'mp3'"
      />
    </div>
  </div>
</template>

<script>
import Upload from "./Upload.vue";
import "@/utils/pinyin_dict_withtone";
import "@/utils/pinyinUtil";
export default {
  components: { Upload },
  props: [
    "curQue",
    "curQueItem",
    "index",
    "changAnswer",
    "deleteOptionOne",
    "checkList",
  ],
  data() {
    return {
      //checkListRes: [],
      fileCon: {
        mp3_list: [],
        img_list: [],
      },
      mp3Number: 1,
      imgNumber: 1,
    };
  },
  computed: {},
  watch: {
    // checkList: {
    //   handler: function (val, oldVal) {
    //     const _this = this;
    //     _this.checkListRes = val;
    //   },
    //   // 深度观察监听
    //   deep: true,
    // },
  },
  //方法集合
  methods: {
    onBlur(item, field) {
      item[field] = item[field] ? item[field].trim() : "";
    },
    onBlurIndex(index, field) {
      let res = this.curQueItem[field][index].trim();
      this.$set(this.curQueItem[field], index, res);
    },
    onBlurCorrect(item) {
      item[index] = item[index].trim();
    },
    //   删除当前选项
    deleteOption() {
      this.$confirm("确定要删除此选项吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        // this.deleteOptionOne(this.index);
        console.log(this.deleteOptionOne());
      });
    },
    //   修改正确答案
    changeIsAnswer(type) {
      this.changAnswer(this.index, type);
    },
    // 点击生成拼音
    getPinyin(item) {
      let bool = false;
      let value = "";
      if (item.hanzi == "") {
        this.$message.warning("请先输入内容,再生成拼音");
        bool = true;
      } else {
        value = item.hanzi;
      }
      if (bool) {
        return;
      }
      let result = pinyinUtil.getPinyin(value);
      item.pinyin = result;
    },
    changeMp3(fileList) {
      const articleImgList = JSON.parse(JSON.stringify(fileList));
      const articleImgRes = [];
      articleImgList.forEach((item) => {
        if (item.response) {
          const obj = {
            name: item.name,
            url: item.response.file_info_list[0].file_url,
            id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",

            media_duration: item.response.file_info_list[0].media_duration, //音频时长
          };
          articleImgRes.push(obj);
        }
      });
      this.curQueItem.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
    },
    changeImage(fileList) {
      console.log(fileList);
      const articleImgList = JSON.parse(JSON.stringify(fileList));
      const articleImgRes = [];
      articleImgList.forEach((item) => {
        if (item.response) {
          const obj = {
            name: item.name,
            url: item.response.file_info_list[0].file_url,
            id: item.response.file_info_list[0].file_id,
          };
          articleImgRes.push(obj);
        }
      });
      //this.articleImgList = articleImgRes;
      this.curQueItem.img_list = JSON.parse(JSON.stringify(articleImgRes));
    },
    //添加释义
    addDef() {
      let leg = this.curQueItem.definition_list.length;
      let last = this.curQueItem.definition_list[leg - 1];
      if (!last) {
        this.$message.warning("请填写");
        return;
      }
      this.curQueItem.definition_list.push("");
    },
    delDef(defIndex) {
      this.curQueItem.definition_list.splice(defIndex, 1);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    console.log(this.curQueItem);
    if (this.curQueItem) {
      this.fileCon.img_list = this.curQueItem.img_list;
      this.fileCon.mp3_list = this.curQueItem.mp3_list;
    }
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.Big-Book {
  &-delDef {
    padding: 0;
    line-height: 32px;
    color: #f56c6c;
  }
  &-def-list {
    margin-bottom: 8px;
  }
  &-top {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    margin-top: 10px;
    span {
      width: 50px;
    }
    .deleteOptionBox {
      width: 40px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      .close {
        width: 24px;
        cursor: pointer;
      }
    }
    .Big-Book-input {
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
      > span {
        line-height: 32px;
        margin-right: 6px;
      }
    }
  }
  &-HzModule {
    // display: flex;
    // justify-content: flex-start;
    // align-items: center;

    > div {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-right: 10px;
      > span {
        line-height: 32px;
        font-size: 14px;
        margin-right: 10px;
      }
    }
  }

  &-set {
    // min-width: 140px;
  }
  &-mp3 {
    margin-top: 6px;
    span {
      width: 50px;
    }
  }
  &-img {
    span {
      width: 50px;
    }
  }
}
</style>
<style lang="scss">
.Big-Book-HzModule {
  .el-textarea {
    width: 400px;
    margin-right: 15px;
  }
}
.Big-Book-input {
  .el-textarea {
    width: 160px;
    margin-right: 15px;
  }
}
</style>