<!--  -->
<template>
  <div class="Big-Book-Single" v-if="curQue">
    <div class="Big-Book-Single-content" style="margin-top: 20px">
      <div class="adult-book-input-item">
        <span class="adult-book-lable">标题：</span>           
        <el-input
          class="adult-book-input"
          :autosize="{ minRows: 2 }"
          placeholder="请输入标题"
          v-model="curQue.title"
          @blur="onBlur(curQue, 'title')"
          maxlength="500"
          show-word-limit
        ></el-input>
      </div>
      <div
        class="Big-Book-main"
        v-for="(curQueItem, index) in curQue.option"
        :key="'curQueItem' + index"
        style="border-bottom: 1px #ccc solid; margin-bottom: 20px"
      >
        <div class="adult-book-input-item">
          <span class="adult-book-lable">序号：</span>
          <el-input
            class="adult-book-input"
            :autosize="{ minRows: 2 }"
            placeholder="请输入内容"
            v-model="curQueItem.number"
            @blur="onBlur(curQueItem, 'number')"
            maxlength="200"
            show-word-limit
          ></el-input>
          <el-button type="danger" size="small" @click="deleteGroup()"
            >删除</el-button
          >
        </div>
        <div class="adult-book-input-item">
          <span class="adult-book-lable">内容：</span>
          <el-input
            class="adult-book-input"
            :autosize="{ minRows: 2 }"
            placeholder="请输入内容"
            v-model="curQueItem.con"
            @blur="onBlur(curQueItem, 'con')"
            maxlength="200"
            show-word-limit
          ></el-input>
        </div>
        <div class="adult-book-input-item">
          <span class="adult-book-lable">翻译：</span>
          <el-input
            class="adult-book-input"
            :autosize="{ minRows: 2 }"
            placeholder="请输入内容"
            v-model="curQueItem.interpret"
            @blur="onBlur(curQueItem, 'interpret')"
            maxlength="200"
            show-word-limit
          ></el-input>
        </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.note"
            @blur="onBlur(curQueItem, 'note')"
            maxlength="200"
            show-word-limit
          ></el-input>
        </div>
        <div class="adult-book-input-item">
          <span class="adult-book-lable"></span>
          <Upload
            :changeFillId="changeImage"
            :datafileList="fileCon[index] && fileCon[index].img_list"
            :filleNumber="imgNumber"
            :uploadType="'image'"
            :index="index"
          />
        </div>
      </div>
      <div class="addoption" @click="addoption">添加注释</div>
    </div>
  </div>
</template>

<script>
import Upload from "../common/Upload.vue";
export default {
  name: "Single",
  props: ["curQue", "changeCurQue"],
  components: { Upload },
  data() {
    return {
      imgNumber: 10000,
      fileCon: [
        {
          img_list: [],
          mp3_list: [],
        },
      ],
      data_structure: {
        type: "notes_chs",
        name: "注释",
        title: "",
        option: [
          {
            number: "", //序号
            con: "", //内容
            interpret: "", //翻译
            note: "", //注释详情
            img_list: [],
          },
        ],
      },
    };
  },
  computed: {},
  watch: {},
  //方法集合
  methods: {
    onBlur(item, field) {
      item[field] = item[field] ? item[field].trim() : "";
    },
    addoption() {
      let res_data = JSON.parse(JSON.stringify(this.data_structure));
      let obj = res_data.option[0];
      this.curQue.option.push(obj);
    },
    deleteGroup(index) {
      if (this.curQue.option.length == 1) {
        this.$message.warning("至少剩余1个，不能全部删除");
        return;
      }
      this.curQue.option.splice(index, 1);
    },

    changeImage(fileList, duration, index) {
      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]",
          };
          articleImgRes.push(obj);
        }
      });
      this.curQue.option[index].img_list = JSON.parse(
        JSON.stringify(articleImgRes)
      );
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    if (!this.curQue) {
      let res_data = JSON.parse(JSON.stringify(this.data_structure));
      this.changeCurQue(res_data);
    } else {
      let fileCon = [];
      this.curQue.option.forEach((item) => {
        let obj = { img_list: item.img_list };
        fileCon.push(obj);
      });
      this.fileCon = JSON.parse(JSON.stringify(fileCon));
      console.log(this.fileCon);
    }
  },
  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;
        }
      }
    }
  }
  .addoption {
    width: 565px;
    height: 40px;
    left: 40px;
    top: 304px;
    background: #f3f3f3;
    border: 1px dashed rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
    border-radius: 4px;
    text-align: center;
    line-height: 40px;
    cursor: pointer;
  }
  .Big-Book-con {
    display: flex;
    padding-bottom: 6px;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.15);
  }
}
</style>
<style lang="scss">
</style>