<template>
  <a-drawer
    v-if="Assessvisible"
    :visible="Assessvisible"
    class="drawerStyle assessment"
    placement="right"
    width="70%"
    @after-visible-change="afterVisibleChange"
  >
    <div class="drawerMain">
      <div class="header">
        <div class="headerTitle">查看评估详情</div>
        <img
          style="width: 29px; height: 29px; cursor: pointer"
          src="../../assets/images/basicinfo/close.png"
          @click="closeDrawer"
        />
      </div>
      <div class="main">
        <div class="onerow">
          <div class="assname">评估名称：</div>
          <div class="asscontent">{{evalName}}</div>
        </div>
        <div class="onerow" style="margin-top: 30px">
          <div class="assname">评估说明：</div>
          <div class="asscontent">-</div>
        </div>
        <div 
          v-for="(values, index) in questionListArr" 
          :key="index">
          <!-- 单项选择 -->
          <div v-if="values.questionType==1" class="assessbox" style="margin-top: 30px">
            <div class="box1">
              <div class="asstype">评估类型：</div>
              <div class="typename">单选</div>
            </div>
            <div class="box1" style="margin-left: 64px">
              <div class="asstype">题干：</div>
              <div style="color: rgba(153, 153, 153, 1); font-size: 14px">
                {{values?.singleStemName}}
              </div>
            </div>
            <div>
              <div class="box1" v-for="(itteems, indexss) in values.assessmentSingleChoiceVoList" style="margin-left: 55px; margin-top: 20px" :key="indexss">
                <div class="asstype">选择{{indexss+1}}：</div>
                <div style="display:flex;justify-content:center;align-items:center;"> 
                  <div v-if="itteems.select"  style="display:flex;justify-content:center;align-items:center;width:16px;height:16px;border-radius:8px;border:1px solid rgba(151, 151, 151, 0.29);margin-right: 8px;">
                    <div style="width:8px;height:8px;border-radius:4px;background-color:#409eff;"></div>
                  </div>
                  <div v-else style="width:16px;height:16px;border-radius:8px;border:1px solid rgba(151, 151, 151, 0.29);margin-right: 8px;"></div>
                  {{itteems.singleOptionName}}
                </div>
                <!-- <a-radio :value="indexs" defaultValue>{{iitem.singleOptionName}}</a-radio> -->
              </div>
            </div>
            <div style="margin-bottom:30px;"></div>
          </div>
          <!-- 多项选择 -->
          <div v-if="values.questionType==2" class="assessbox" style="margin-top: 30px"> 
            <div class="box1">
              <div class="asstype">评估类型：</div>
              <div class="typename">多选</div>
            </div>
            <div class="box1" style="margin-left: 64px">
              <div class="asstype">题干：</div>
              <div style="color: rgba(153, 153, 153, 1); font-size: 14px">
                {{values?.multipleStemName}}
              </div>
            </div>
            <div>
              <div class="box1" v-for="(itteems, indexss) in values.multipleChoiceVoList" style="margin-left: 55px; margin-top: 20px" :key="indexss">
                <div class="asstype">选择{{indexss+1}}：</div>
                <div style="display:flex;justify-content:center;align-items:center;"> 
                  <div v-if="itteems.select"  style="display:flex;justify-content:center;align-items:center;width:16px;height:16px;border-radius:8px;border:1px solid rgba(151, 151, 151, 0.29);margin-right: 8px;">
                    <div style="width:8px;height:8px;border-radius:4px;background-color:#409eff;"></div>
                  </div>
                  <div v-else style="width:16px;height:16px;border-radius:8px;border:1px solid rgba(151, 151, 151, 0.29);margin-right: 8px;"></div>
                  {{itteems.multipleOptionName}}
                </div>
                <!-- <a-radio :value="indexs" defaultValue>{{iitem.singleOptionName}}</a-radio> -->
              </div>
            </div>
            <div style="margin-bottom:30px;"></div>
          </div>
          <!-- 问答题 -->
          <div v-if="values.questionType==3" class="assessbox" style="margin-top: 30px">
            <div class="box1">
              <div class="asstype">评估类型：</div>
              <div class="typename">问答题</div>
            </div>
            <div class="box1" style="margin-left: 64px">
              <div class="asstype">标题：</div>
              <div style="color: rgba(153, 153, 153, 1); font-size: 14px">
                {{values?.assessmentQaTitle}}
              </div>
            </div>
            <div
              class="box1"
              style="margin-left: 64px; margin-top: 20px; margin-bottom: 30px"
            >
              <div class="asstype">描述：</div>
              <div style="color: rgba(51, 51, 51, 1); font-size: 14px">
                {{ values?.content }}
              </div>
            </div>
          </div>
          <!-- 评分题 -->
          <div v-if="values.questionType==4" class="assessbox" style="margin-top: 30px">
            <div class="box1">
              <div class="asstype">评估类型：</div>
              <div class="typename">评分题</div>
            </div>
            <div class="box1" style="margin-left: 64px">
              <div class="asstype">标题：</div>
              <div style="color: rgba(153, 153, 153, 1); font-size: 14px">
                {{values?.assessmentScTitle}}
              </div>
            </div>
            <div class="lastbox">
              <div class="sorcetext">非常不满意</div>
              <div class="sorcebox" v-for="(iittem, index) in [1,2,3,4,5,6,7,8,9,10] " :key="index">
                <div v-if="iittem >= values.assessmentMinScore && iittem <= values.assessmentMaxScore" :class="(iittem + 1 - values.assessmentMinScore) == values.selectAnswer  ? 'numbox' : 'numbox1'">{{ iittem }}</div>
              </div>
              <div class="sorcetext">非常满意</div>
            </div>
          </div>

        </div>
        <div style="margin-top: 30px;margin-bottom: 60px;"></div>
        
      </div>
      <div class="btnn">
        <button class="btn1" @click="closeDrawer">取消</button>
        <button class="btn2" @click="closeDrawer">确定</button>
      </div>
    </div>
  </a-drawer>
</template>

<script>
import { reactive, toRefs } from "vue";
import * as api from "@/api/indexTaskManage";

export default {
  name: "ViewAssess",
  props: {
    Assessvisible: {
      type: Boolean,
      default: false,
    },
    evalName: {
      type: String,
      default: "",
    },
    basicdata: {
      type: Object,
      default: function () {
        return {};
      },
    },
    datasource: {
      type: Object,
      default: function () {
        return {};
      },
    }
  },
  setup(props, ctx) {
    const state = reactive({
      value: "1",
      questionListArr: [],
      valueq1:"",
      valueq2:""
    });
    const closeDrawer = () => {
      ctx.emit("update:Assessvisible", false);
    };

    // 数组去空对象
    function formateArr(arr1) {
      console.log(arr1, arr1[0], arr1[0].length)
      let newarr = []
      for (let i = 0; i < arr1.length; i++) {
        if (arr1[i].length !== 0) {
          newarr.push(arr1[i])
        }
      }
      return newarr
    }

    const afterVisibleChange = (bool) => {
      console.log("state", bool);
      if(bool){
        console.log('我是传递过来的参数', props.datasource)
        console.log('我是传递过来的参数2', props.basicdata)
        api.QueryAssessmentDetail({
          "assessmentSubmitId": props.datasource.assessmentSubmitId,
          "courseId": props.basicdata.assessmentId,
          "studentId": props.datasource.studentId
        }).then(res=>{
          console.log(res)
          if(res.data.code==200){
            let qarr = [res.data.data.essayQuestionVoList, res.data.data.multipleStemVoList,res.data.data.scoringQuestionVoList,res.data.data.singleStemVoList]
            let allArr = []
            for(let i=0;i<qarr.length;i++){
              for(let j=0;j<qarr[i].length;j++){
                allArr.push(qarr[i][j])
              }
            }
            let newarr = formateArr(allArr).sort((a, b) => { return a.orderNumber - b.orderNumber})
            state.questionListArr = newarr
            console.log('我是经过排序后的题目',newarr)
          }
        }).catch(err=>{
          console.log(err)
        })
      }
    };

    return {
      ...toRefs(state),
      afterVisibleChange,
      closeDrawer,
      // change,
    };
  },
};

</script>

<style lang="scss">
.assessment {
  .drawerMain {
    min-width: 600px;
    margin: 0px 32px 0px 32px;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
    .header {
      height: 73px;
      border-bottom: 1px solid #e8e8e8;
      display: flex;
      justify-content: space-between;
      align-items: center;
      // background-color: red;
      margin-bottom: 20px;
      .headerTitle {
        font-size: 18px;
        font-weight: 600;
        color: #333333;
        line-height: 25px;
        // margin-left: 24px;
      }
    }
    .main {
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      //align-items: center;
      .onerow {
        display: flex;
        margin-top: 10px;
        margin-left: 10px;
        .assname {
          font-size: 16px;
          color: #333333;
          font-weight: 500;
        }
        .asscontent {
          color: #999999;
          font-size: 16px;
        }
      }
      .assessbox {
        border: 1px solid rgba(151, 151, 151, 0.29);
        border-radius: 8px;
        display: flex;
        flex-direction: column;
        .box1 {
          display: flex;
          margin-top: 20px;
          margin-left: 36px;
          align-items: center;
          .asstype {
            color: rgba(51, 51, 51, 1);
            font-size: 14px;
            font-weight: 500;
          }
          .typename {
            width: 80px;
            height: 32px;
            //margin-left: 10px;
            border-radius: 4px;
            border: 1px solid rgba(64, 158, 255, 1);
            display: flex;
            justify-content: center;
            align-items: center;
            color: rgba(64, 158, 255, 1);
            font-size: 14px;
            background: rgba(64, 158, 255, 0.1);
          }
        }
        .lastbox {
          display: flex;
          align-items: center;
          margin-left: 30px;
          .sorcetext {
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
          }
          .sorcebox {
            display: flex;
            .numbox {
              width: 32px;
              height: 32px;
              display: flex;
              justify-content: center;
              align-items: center;
              background: rgba(64, 158, 255, 1);
              color: #ffffff;
              font-size: 14px;
              border-radius: 4px;
              margin: 20px 5px;
              cursor: pointer;
            }
            .numbox1 {
              width: 32px;
              height: 32px;
              display: flex;
              justify-content: center;
              align-items: center;
              border: 1px solid rgba(151, 151, 151, 0.29);
              color: rgba(0, 0, 0, 0.65);
              margin: 20px 5px;
              cursor: pointer;
              border-radius: 4px;
            }
          }
        }
      }
    }
    .btnn {
      height: 72px;
      width: 100%;
      position: absolute;
      bottom: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0px 1px 35px 0px rgba(118, 136, 166, 0.16);
      .btn1 {
        width: 100px;
        height: 40px;
        border: 1px solid #4ea6ff;
        border-radius: 8px;
        color: #4ea6ff;
        background-color: #fff;
        cursor: pointer;
      }
      .btn2 {
        cursor: pointer;
        width: 100px;
        height: 40px;
        background: #4ea6ff;
        border-radius: 8px;
        border: 0;
        margin-left: 15px;
        color: #fff;
      }
    }
  }
}
</style>
