<!-- 评估管理-创建评估页面 -->
<template>
  <!-- 多选题 -->
  <div class="content">
    <div class="tagbox">
      <div class="tagname">多选题</div>
      <div class="deleteop" @click="handleTypesDel(2)">
        <div><img src="../../../assets/images/projectadd/delete.png" /></div>
        <div class="del_text">删除选项</div>
      </div>
    </div>
    <div class="name">
      <div class="namebox">
        <img
          class="nameimg"
          src="../../../assets/images/basicinfo/asterisk.png"
        />
        <div class="inname">标题</div>
      </div>
      <div class="in">
        <a-input
          v-model:value="curItem.valueMutil"
          placeholder="请输入题干名称"
          show-count
          :maxlength="20"
          style="border-radius: 8px"
        />
      </div>
    </div>
    <ResearchAddItem
      v-for="(item, index) in curItem.mutilList"
      :key="index"
      :item="item"
      @input="inputMutil"
      @src="imgSrcMutil"
      @delImg="delImgMutil"
      @del="delMutil"
    />
    <div class="name">
      <div class="in" style="margin-left: 85px; margin-bottom: 20px">
        <a-button
          type="primary"
          style="
            width: 100px;
            height: 40px;
            border-radius: 8px;
            background-color: #409eff;
          "
          @click="handleMutilAdd"
        >
          添加选项
        </a-button>
      </div>
    </div>
  </div>
</template>
<script>
import { ref } from "vue";
import ResearchAddItem from "./ResearchAddItem.vue";
import { deleteChoiceQuestion } from "@/api/indexResearch";

export default {
  name: "ResearchAddMulti",
  components: {
    ResearchAddItem,
  },
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      },
    },
    assessmentId: {
      type: String,
      default: "",
    },
  },
  setup(props, { emit }) {
    const curItem = ref(props.item);
    const assessmentId = ref(props.assessmentId);

    const handleTypesDel = (type) => {
      emit("del", { id: curItem.value.id, type, curItem: curItem.value });
      // if (state.typesCur.includes(types)) {
      //   const arr = state.typesCur.filter((item) => item !== types);
      //   state.typesCur = arr;
      // }
    };

    const handleMutilAdd = () => {
      curItem.value.mutilList.push({
        id: curItem.value.mutilList.length + 1,
        inputVal: "",
        imgVal: "",
      });
    };
    const inputMutil = ({ id, val }) => {
      curItem.value.mutilList.forEach((item) => {
        if (item.id === id) {
          item.inputVal = val;
        }
      });
    };
    const imgSrcMutil = ({ id, src }) => {
      curItem.value.mutilList.forEach((item) => {
        if (item.id === id) {
          item.imgVal = src;
        }
      });
    };
    const delImgMutil = ({ id }) => {
      curItem.value.mutilList.forEach((item) => {
        if (item.id === id) {
          item.imgVal = "";
        }
      });
    };
    const delMutil = ({ id, optionId }) => {
      curItem.value.mutilList.forEach((item, index) => {
        if (item.id === id) {
          curItem.value.mutilList.splice(index, 1);
        }
      });
      curItem.value.mutilList.map((item, index) => {
        item.id = index + 1;
      });

      deleteChoiceQuestion({
        assessmentId: assessmentId.value,
        questionType: "2",
        optionId,
      }).then((res) => {
        console.log(56444);
        console.log(res);
      });
    };

    return {
      curItem,
      handleTypesDel,
      handleMutilAdd,
      inputMutil,
      imgSrcMutil,
      delImgMutil,
      delMutil,
    };
  },
};
</script>
<style lang="scss">
.researchadd {
  width: 100%;
  display: flex;
  flex-direction: column;
  .header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    .title {
      color: #000000;
      font-size: 18px;
      //line-height: 36px;
      padding-top: 30px;
      padding-left: 37px;
      //font-weight: 500;
    }
    .goback {
      padding-right: 70px;
      //padding-top: 37px;
      position: relative;
      .return {
        display: inline-block;
        width: 42px;
        height: 42px;
        margin-top: 17px;
        margin-right: 10px;
        background-image: url("../../../assets/images/projectadd/return.png");
      }
      .returntext {
        display: inline-block;
        position: absolute;
        top: 27px;
        color: #4ea6ff;
        font-size: 14px;
      }
    }
  }
  .addtype {
    display: flex;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin-right: 20px;
    align-items: center;
    margin-left: 41px;
    .addtypen {
      color: #6f6f6f;
      font-size: 14px;
    }
    .types {
      cursor: pointer;
      width: 80px;
      height: 40px;
      color: #409eff;
      border: 1px solid #409eff;
      border-radius: 4px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 20px 10px;
    }
    .typesCur {
      color: #fff;
      background: #409eff;
    }
  }
  .content {
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.1);
    width: 70%;
    min-width: 690px;
    margin-left: 38px;
    margin-top: 20px;
    .tagbox {
      display: flex;
      justify-content: space-between;
      .tagname {
        width: 90px;
        height: 32px;
        margin-top: 24px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: 134px;
        background: rgba(78, 166, 255, 0.1);
        border-radius: 4px;
        color: rgba(64, 158, 255, 1);
        font-size: 16px;
      }
      .deleteop {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100px;
        height: 40px;
        margin-top: 20px;
        margin-right: 30px;
        border: 1px solid #409eff;
        border-radius: 8px;
        cursor: pointer;
        .del_text {
          color: #409eff;
          font-size: 14px;
          margin-left: 5px;
        }
      }
    }
    .scorebox {
      display: flex;
      align-items: center;
      margin-top: 20px;
      margin-left: 70px;
      .scoretext {
        font-size: 14px;
        color: #56a3f9;
      }
      .number {
        display: flex;
        border: 1px solid #d7e5fd;
        border-radius: 5px;
        margin: 0 10px;
        padding: 5px;
        .btn {
          width: 40px;
          height: 40px;
          border: 1px solid #56a3f9;
          border-radius: 8px;
          display: flex;
          justify-content: center;
          align-items: center;
          margin: 5px;
          font-size: 14px;
          font-weight: 400;
          color: #56a3f9;
          line-height: 24px;
          cursor: pointer;
        }
        .curBtn {
          background: #56a3f9;
          color: #fff;
        }
      }
    }
    .picture {
      width: 100px;
      display: flex;
      flex-direction: column;
      margin-top: 20px;
      margin-left: 133px;
      .pictureimg {
        width: 100px;
        height: 100px;
      }
      .picturename {
        color: #6f6f6f;
        font-size: 14px;
      }
    }
    .options {
      display: flex;
    }
    .delete {
      cursor: pointer;
      margin-top: 32px;
      margin-left: 20px;
      // float: right;
      color: #4ea6ff;
      font-size: 14px;
    }
    .name2 {
      display: flex;
      align-items: flex-start;
    }
    .name {
      width: 60%;
      // background-color: lightcoral;
      display: flex;
      margin-top: 20px;
      //align-items: center;
      //height: 40px;
      // border: 1px solid black;
      .namebox {
        width: 120px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        flex-shrink: 0;
        .nameimg {
          width: 10px;
          height: 10px;
        }
      }
      .inname {
        color: #6f6f6f;
        font-size: 14px;
        margin-left: 7px;
        font-weight: 700;
      }
      .in {
        margin-left: 14px;
        flex: 1;
        .assess {
          display: flex;
          width: 226px;
          height: 40px;
          border: 1px solid #56a3f9;
          //margin-bottom: 20px;
          .assesstype {
            width: 50%;
            background: #56a3f9;
            color: #ffffff;
            display: flex;
            justify-content: center;
            align-items: center;
          }
          .assesswhole {
            width: 50%;
            background: rgba(86, 163, 249, 0.1);
            font-size: 14px;
            color: #6f6f6f;
            display: flex;
            justify-content: center;
            align-items: center;
          }
          .ratio {
            position: absolute;
            right: 10px;
            top: 8px;
            color: #6f6f6f;
            font-size: 14px;
          }
        }
        .addimg {
          cursor: pointer;
          color: rgba(78, 166, 255, 1);
          font-size: 14px;
        }
        .text {
          color: rgba(109, 117, 132, 1);
          font-size: 14px;
          //line-height: 24px;
        }
        .ant-radio-wrapper {
        }
        .ant-input {
          border-radius: 5px;
          // height: 120%;
          width: 100%;
          height: 35px;
        }
        .ant-select-selector {
          border-radius: 5px;
          // height: 120%;
          width: 100%;
          height: 40px;
        }
      }
      .numberInp {
        width: 200px;
        .ant-input-number {
          width: 200px;
          height: 40px;
          border-radius: 8px;
        }
        // .ant-input-number-input-wrap {
        //   width: 200px;
        // }
      }
    }
  }
  .name2 {
    display: flex;
    align-items: flex-start;
  }
  .opinion {
    display: flex;
    margin-top: 30px;
    .namebox {
      width: 120px;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      flex-shrink: 0;
    }
    .in {
      margin-left: 14px;
      width: 500px;
      .ant-input-textarea-show-count {
        position: relative;
        height: 110px;
      }
      .ant-input-textarea-show-count::after {
        position: absolute;
        right: 10px;
        bottom: 0px;
      }
      .ant-input {
        border-radius: 8px;
      }
    }
  }
  .footer {
    width: 100%;
    margin-top: 31px;
    margin-bottom: 14px;
    .btn {
      display: flex;
      margin-bottom: 20px;
      justify-content: center;
      cursor: pointer;
    }
  }

  .uploadContent {
    display: block !important;
    .uploadBtn {
      margin-left: 120px !important;
    }
  }
}
</style>
