<style>
  .examPaper_Top {
    width: 100%;
    height: 83px;
    border-bottom: 1px solid #d9d9d9;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .Exam-main {
    width: 100%;
    min-width: 1000px;
    height: auto !important;
    overflow: hidden;
    margin-top: 20px;
  }

  .Exam-left {
    width: 33%;
    border-radius: 3px;
    border: 1px solid #d9d9d9;
    background: #f0f0f0;
    padding-top: 10px;
    padding-bottom: 0px;
  }

  .f1 {
    float: left;
  }

  .Exam-right {
    width: 65%;
    height: auto;
    background: #fff;
    border-radius: 3px;
    border: 1px solid #d9d9d9;
    margin-left: 20px;
  }

  .Left-ptitel {
    font-size: 14px;
    color: #777;
    padding-left: 5px;
  }

  .Left-ptitel span {
    font-size: 14px;
    color: #333;
  }

  .Left-ptitel i {
    color: #c90000;
    font-style: normal;
  }

  .Left-list {
    width: 100%;
    overflow: auto;
    border-top: 1px solid #d9d9d9;
    height: calc(100vh - 270px);
  }

  .right_TiList {
    width: 100%;
    overflow: auto;
    height: calc(100vh - 270px);
  }

  .List-ul {
    margin: 0;
    padding: 0;
  }

  .List-ul li {
    height: 33px;
    border-bottom: 1px solid #f3f3f3;
    list-style-type: none;
  }

  .List-ul-li-checked {
    background: #a6a6a6;
    color: #333;
    width: 328px;
  }

  .List-ul li {
    display: block;
    padding-left: 25px;
    line-height: 33px;
    font-size: 12px;
    height: 33px;
    border-bottom: 1px solid #f3f3f3;
    color: #555;
    text-decoration: none;
    display: flex;
  }

  .List-ul-li-checked b {
    color: #000;
  }

  .Showbtn {
    display: block;
    width: 90px;
    float: right;
    padding-top: 8px;
    z-index: 1000;
  }

  .Left-btn {
    height: 58px;
    padding: 20px 0 20px 20px;
    width: 100%;
    border-bottom: 1px solid #d9d9d9;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .List-bt {
    height: 40px;
    margin-left: 1px;
    background: #fdfdfd;
    font-size: 14px;
    line-height: 40px;
    /* padding-left: 10px; */
  }

  .List-bt i {
    position: relative;
    top: 1px;
    left: 5px;
  }

  .List-bt i:hover {
    color: #2961fe;
    cursor: pointer;
  }

  .List-ul li:hover {
    background: #a6a6a6;
    color: #333;
  }

  .checkUl {
    background: #a6a6a6;
    color: #333;
  }

  .List-ul li:hover .exam_ListSHow {
    display: inline-block;
  }

  .left-btn-list {
    padding: 5px 10px;
    display: inline-block;
    color: #555;
    border-radius: 3px;
    font-size: 14px;
    border: 1px solid #999;
    margin-right: 10px;
    cursor: pointer;
  }

  #btn1 {
    background: #26a69a !important;
  }

  .difficulty_Degree {
    display: inline-block;
    width: 80px;
    text-align: right;
    line-height: 56px;
  }

  .Left-list::-webkit-scrollbar {
    width: 3px;
    height: 3px;
    background-color: #F5F5F5;
  }

  /*!*定义滚动条轨道 内阴影+圆角*!*/
  .Left-list::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    background-color: #F5F5F5;
  }

  /*!*定义滑块 内阴影+圆角*!*/
  .Left-list::-webkit-scrollbar-thumb {
    border-radius: 10px;
    -webkit-box-shadow: -webkit-gradient(linear, 0 0, 0 100%, color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.5, transparent), to(transparent));
    background-color: #0ae;
  }

  .right_TiList::-webkit-scrollbar {
    width: 3px;
    height: 3px;
    background-color: #F5F5F5;
  }

  /*!*定义滚动条轨道 内阴影+圆角*!*/
  .right_TiList::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    background-color: #F5F5F5;
  }

  /*!*定义滑块 内阴影+圆角*!*/
  .right_TiList::-webkit-scrollbar-thumb {
    border-radius: 10px;
    -webkit-box-shadow: -webkit-gradient(linear, 0 0, 0 100%, color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.5, transparent), to(transparent));
    background-color: #0ae;
  }

  .commonDalei {
    display: flex;
    align-content: center;
    margin-bottom: 20px;
  }

  .examPaper .edui-editor {
    z-index: 99 !important;
  }

  .List-bt input {
    outline: none;
  }

  .exam_DetailList {
    width: 70%;
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-left: 5px;
  }

  .exam_ListSHow {
    display: none;
  }

  .exam_ListSHow i:hover {
    color: #2961fe;
  }

  .paper_GroupName {
    max-width: 40%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 5px;
    cursor: pointer;
  }

  .paperEdit_Top {
    display: flex;
    font-weight: bold;
    position: relative;
  }

  .paperEdit_Top i {
    color: #555;
    font-weight: normal;
  }

  .checkedExam {
    background: #9cf !important;
  }

</style>
<template>
  <div class="examPaper page-body">
    <div class="examPaper_Top">
      <div style="width:90%;display:flex;">
        <div style="width:32%;margin-right:20px;">
          <q-input filled label="标题" v-model="DataObj.PaperName" />
        </div>
        <div style="width:20%;">
          <q-select filled option-value="Id" option-label="Name" :options="questionDifficultyTypeList" emit-value
            map-options label="难度" use-input clearable v-model="DataObj.DifficultyType" />
        </div>
        <div style="margin-left:20px;">
          <q-field label="组卷类型" stack-label borderless>
            <template v-slot:control>
              <q-radio v-model="DataObj.GroupType" :val="1" label="问题类型" />
              <q-radio v-model="DataObj.GroupType" :val="2" label="题目大类" />
            </template>
          </q-field>
        </div>
        <div style="margin-left:20px;">
          <q-field label="访问设置" stack-label borderless>
            <template v-slot:control>
              <q-radio v-model="DataObj.IsOpen" :val="1" label="私有" title="只能自己查看" />
              <q-radio v-model="DataObj.IsOpen" :val="2" label="公开" title="所有人均可见" />
            </template>
          </q-field>
        </div>
      </div>
      <div style="width:10%;text-align:right;">
        <q-btn color="accent" size="sm" class="q-mr-md" label="预览" style="display:none;" />
        <q-btn color="accent" size="sm" class="q-mr-md" label="保存并返回" :loading="savePaperLoading"
          @click="SavePaper()" />
      </div>
    </div>
    <div class="Exam-main">
      <div class="Exam-left f1">
        <div style="display:flex;justify-content:space-between;align-items:center;padding:0 10px 10px 5px;height:36px;">
          <div class="Left-ptitel">
            <span>题量：<i>{{examNum}}</i></span>
            <span>&nbsp;&nbsp;总分：<i>{{examScore.toFixed(2)}}</i></span>
          </div>
          <div v-if="DataObj.GroupType==2">
            <q-btn-dropdown color="primary" label="添加分类" size="sm">
              <q-list>
                <q-item clickable v-close-popup @click="onCategoryItemClick(item)"
                  v-for="(item,index) in newQuestionCategoryList" :key="index">
                  <q-item-section>
                    <q-item-label>{{item.Name}}</q-item-label>
                  </q-item-section>
                </q-item>
              </q-list>
            </q-btn-dropdown>
          </div>
        </div>
        <div class="Left-list">
          <template v-if="DataObj&&DataObj.GroupList&&DataObj.GroupList.length>0">
            <div class="List-con1" v-for="(gItem,gIndex) in DataObj.GroupList" :key="gIndex">
              <div class="List-bt">
                <div class="paperEdit_Top" :class="{'checkedExam':clickIndex==gIndex}">
                  <template v-if="!gItem.isShowEdit">
                    <template v-if="DataObj.GroupType==2">
                      <div @click="GetGroupItem(gItem,gIndex)" style="display:flex;padding-left:5px;cursor:pointer">
                        <div>{{gIndex+1}}</div>&nbsp;
                        <div class="paper_GroupName" :title="gItem.GroupName">{{gItem.GroupName}}</div>
                        <div>(共{{ gItem.DetailsList?gItem.DetailsList.length:0 }}题，{{gItem.GScore}}分)</div>
                      </div>
                    </template>
                    <template v-else>
                      <div style="display:flex;padding-left:5px;">
                        <div>{{gIndex+1}}</div>&nbsp;
                        <div class="paper_GroupName" :title="gItem.GroupName">{{gItem.GroupName}}</div>
                        <div>(共{{ gItem.DetailsList?gItem.DetailsList.length:0 }}题，{{gItem.GScore}}分)</div>
                      </div>
                    </template>
                  </template>
                  <template v-else>
                    <el-input v-model="gItem.GroupName" size="small" maxlength="50"
                      style="width:160px;margin-right:10px;">
                    </el-input>
                    <el-input v-model="gItem.GScore" size="small" maxlength="6" style="width:80px;"
                      @keyup.native="checkPrice(gItem,'GScore')" @change="changeGroupScore(gItem)"></el-input>
                  </template>
                  <div style="right:10px;position:absolute;">
                    <i class="iconfont icon-edit" title="编辑" style="font-size:18px;margin-right:5px;"
                      @click="getNameEdit(DataObj.GroupList,gIndex)"></i>
                    <i class="iconfont icon-ico_commodity_defaul" v-if="gItem.isShowEdit" title="保存"
                      style="top:0;margin-right:5px;" @click="saveExamName(DataObj.GroupList)"></i>
                    <i class="iconfont icon-shangyi2" style="margin-right:5px;" @click.stop="MoveFatherItem(gIndex,0)"
                      v-if="gIndex!=0"></i>
                    <i class="iconfont icon-xiayi" style="margin-right:5px;" @click.stop="MoveFatherItem(gIndex,1)"
                      v-if="gIndex!=DataObj.GroupList.length-1"></i>
                    <i class="iconfont icon-shanchu2" style="font-size:18px;"
                      @click.stop="removeFather(gItem,gIndex)"></i>
                  </div>
                </div>
              </div>
              <ul class="List-ul" v-if="gItem.DetailsList&&gItem.DetailsList.length>0">
                <li class="" style="cursor:pointer;position:relative;"
                  :class="{'checkUl':dIndex==ComCheckIndex&&gIndex==ComOneIndex}"
                  v-for="(dItem,dIndex) in gItem.DetailsList" :key="dIndex" @click="ClickItem(dItem,gIndex,dIndex)">
                  ({{dIndex+1}}) <span class="exam_DetailList" v-html="dItem.ShowTitle"></span>
                  <span style="position:absolute;right:5px;">
                    <el-tag type="warning" size="mini" style="margin-right:5px;"
                      v-if="getRepeat(dItem.QuestionId,gItem.DetailsList)&&dIndex+1!=getIndex(dItem.QuestionId,gItem.DetailsList)">
                      与{{gIndex+1}}.{{getIndex(dItem.QuestionId,gItem.DetailsList)}}重复出现</el-tag>
                    <span class="exam_ListSHow">
                      <i class="iconfont icon-shangyi2" @click.stop="MoveChildItem(gIndex,dIndex,0)"
                        style="margin-right:5px;" v-if="dIndex!=0"></i>
                      <i class="iconfont icon-xiayi" style="margin-right:5px;"
                        @click.stop="MoveChildItem(gIndex,dIndex,1)" v-if="dIndex!=gItem.DetailsList.length-1"></i>
                      <i class="iconfont icon-shanchu2" @click.stop="delExam(gItem.DetailsList,dItem,dIndex)"
                        style="font-size:17px;"></i>
                    </span>
                  </span>
                </li>
              </ul>
            </div>
          </template>
        </div>
      </div>
      <div class="Exam-right f1">
        <div class="Left-btn">
           <div>
            <template v-for="(fItem,fIndex) in firstTypeList">
              <q-btn :key="fIndex" color="accent" :id="commonIndex==fIndex?'btn1':''" size="sm" :label="fItem.Name"
                style="margin-left:5px;" @click="onItemClick(fItem,fIndex)" />
            </template>
            <q-btn-dropdown color="accent" size="sm" label="更多" style="margin-left:5px;">
              <q-list>
                <q-item v-for="(fItem,fIndex) in secondTypeList" @click="onItemClick(fItem)" clickable v-close-popup
                  :key="fIndex">
                  <q-item-section>
                    <q-item-label>{{fItem.Name}}</q-item-label>
                  </q-item-section>
                </q-item>
              </q-list>
            </q-btn-dropdown>
          </div>
           <div>
            <q-btn color="accent" size="sm" @click="isShowQuestion=true" class="q-mr-md" label="题库选题"  />
          </div>
        </div>
        <div class="right_TiList">
          <div class="row wrap" v-if="ChooseItem" style="padding:20px;">
            <div class="edit_stem">
              <q-input filled stack-label maxlength="5" :dense="false" @keyup.native="checkPrice(ChooseItem,'Score')"
                v-model="ChooseItem.Score" class="col-12 q-pb-lg" label="分数"
                :disable="ChooseItem.QuestionTypeKey=='cloze'||ChooseItem.QuestionTypeKey=='listening'||ChooseItem.QuestionTypeKey=='reading-comprehensio'" />
            </div>
            <div class="col-12">
              <template v-if="ChooseItem.QuestionTypeKey=='cloze'">
                <span class="question_number">选项处用##题号##替换，如##1##</span>
              </template>
              <UeEditor v-if="ChooseItem.QuestionTypeKey!='sharing-choose'" v-model="ChooseItem.Title" :config="config"
                ref="UE_Title"></UeEditor>
            </div>
            <br />
            <!--单选题-->
            <single v-if="ChooseItem.QuestionTypeKey=='single'||ChooseItem.QuestionTypeKey=='single-number'"
              :questionData="ChooseItem.QuestionContentObj" @getChild="getChildData" :setOption="ChooseItem"></single>
            <!--多选题-->
            <multiple v-if="ChooseItem.QuestionTypeKey=='multiple'" :questionData="ChooseItem.QuestionContentObj"
              @getChild="getChildData" :setOption="ChooseItem"></multiple>
            <!--填空题、分录题、资料题-->
            <fill-in
              v-if="ChooseItem.QuestionTypeKey=='fill-in'||ChooseItem.QuestionTypeKey=='entry-problem'|| ChooseItem.QuestionTypeKey=='data-question'"
              :questionData="ChooseItem.QuestionContentObj" @getChild="getChildData" :setOption="ChooseItem"></fill-in>
            <!--判断题-->
            <judge v-if="ChooseItem.QuestionTypeKey=='judge'" :questionData="ChooseItem.QuestionContentObj"
              @getChild="getChildData" :setOption="ChooseItem"></judge>
            <!--简答题、名词解释、论述题、计算题、口语题、其它-->
            <short-answer v-if="ChooseItem.QuestionTypeKey=='short-answer'||ChooseItem.QuestionTypeKey=='noun-explanation'||ChooseItem.QuestionTypeKey=='essay-question'
              ||ChooseItem.QuestionTypeKey=='calculation' || ChooseItem.QuestionTypeKey=='spoken'|| ChooseItem.QuestionTypeKey=='other'
              " :setOption="ChooseItem"> </short-answer>
            <!--连线题-->
            <matching v-if="ChooseItem.QuestionTypeKey=='matching'" :questionData="ChooseItem.QuestionContentObj"
              :setOption="ChooseItem" @getChild="getChildData"></matching>
            <!--排序题-->
            <sorting-problem v-if="ChooseItem.QuestionTypeKey=='sorting-problem'"
              :questionData="ChooseItem.QuestionContentObj" :setOption="ChooseItem" @getChild="getChildData">
            </sorting-problem>
            <!--完型填空-->
            <cloze v-if="ChooseItem.QuestionTypeKey=='cloze'" :questionData="ChooseItem.QuestionContentObj"
              :setOption="ChooseItem" @getChild="getChildData" :isShowScore="true" @getScore="calcPaper"></cloze>
            <!--阅读理解、听力题-->
            <reading-comprehensio
              v-if="ChooseItem.QuestionTypeKey=='reading-comprehensio'||ChooseItem.QuestionTypeKey=='listening'"
              :questionData="ChooseItem.QuestionContentObj" :setOption="ChooseItem" @getChild="getChildData"
              :isShowScore="true" @getScore="calcPaper">
            </reading-comprehensio>
            <!--共用选择题-->
            <sharing-choose v-if="ChooseItem.QuestionTypeKey=='sharing-choose'"
              :questionData="ChooseItem.QuestionContentObj" @getChild="getChildData" :setOption="ChooseItem"
              :isShowScore="true" @getScore="calcPaper">
            </sharing-choose>
            <br />
            <div class="col-12">
              <div style="margin:20px 0;">答案解析</div>
              <UeEditor v-model="ChooseItem.AnswerParse" :config="config" ref="UE_AnswerParse"></UeEditor>
            </div>
            <br />
            <div class="col-12 commonDalei" style="margin-top:20px;">
              <span class="difficulty_Degree">难度：</span>
              <q-select filled option-value="Id" size="sm" style="display:inline-block;width:300px;" option-label="Name"
                v-model="ChooseItem.DifficultyType" :options="questionDifficultyTypeList" emit-value map-options />
            </div>
            <div class="col-12 commonDalei">
              <br />
              <span class="difficulty_Degree">所属大类：</span>
              <q-select filled option-value="Id" size="sm" style="display:inline-block;width:300px;" option-label="Name"
                v-model="ChooseItem.Category" :options="questionCategoryList" emit-value map-options />
            </div>
            <div class="col-12 commonDalei">
              <br />
              <span class="difficulty_Degree">考级程度：</span>
              <q-select filled option-value="Id" size="sm" style="display:inline-block;width:300px;" option-label="Name"
                v-model="ChooseItem.LevelType" :options="questionLevalTypeList" emit-value map-options />
            </div>
            <div class="col-12">
              <span class="difficulty_Degree">知识点：</span>
              <a class="addKnowledge" @click="isShowPoint=true" style="cursor:pointer;">
                <i class="iconfont icon-add" style="position:relative;top:1px;"></i>选择知识点
              </a>
              <span class="knowledge_List" v-for="(x, i) in choosePointArray" :key="i">
                {{x.PointName}}
                <i class="iconfont icon-shanchu1" @click="removePointTag(i)"></i>
              </span>
            </div>
          </div>
        </div>
      </div>
      <questionForm v-if="isShowQuestion" @close="closeQuestForm" @success="getQuestionList"></questionForm>
      <!--选择知识点-->
      <questionpoint v-if="isShowPoint" CourseId="0" :openDialog="isShowPoint" @closed="closeQuestionPoint"
        :multiple="true" @selected="getPointList">
      </questionpoint>
    </div>
  </div>
</template>
<script>
  import {
    date
  } from "quasar";
  import UeEditor from '../../components/editor/UeEditor'
  //知识点列表
  import questionpoint from '../../components/question/questionpoint'

  import single from '../../components/questiontype/single'
  import multiple from '../../components/questiontype/multiple'
  import fillIn from '../../components/questiontype/fill-in'
  import judge from '../../components/questiontype/judge'
  import shortAnswer from '../../components/questiontype/short-answer'
  import matching from '../../components/questiontype/matching'
  import sortingProblem from '../../components/questiontype/sorting-problem'
  import cloze from '../../components/questiontype/cloze'
  import readingComprehensio from '../../components/questiontype/reading-comprehensio'
  import sharingChoose from '../../components/questiontype/sharing-choose'
  import questionForm from '../../components/exam/question-form'
  import {
    GetPaper,
    savePaperInfo,
  } from '../../api/teacher/index';
  import {
    CreateQuestion, //生成问题
    chooseValidate, //【单选题、多选题、数字选择题】验证
    fillInValidate, //【填空题、分录题、资料题】验证
    judgeValidate, //【判断题】验证
    shortanswerValidate, //【简答题、名词解释、论述题、计算题、其它题】验证
    matchingValidate, //【连线题】验证
    sortingproblemValidate, //【排序题】验证
    clozeValidate, //【完型填空】验证 
    readingcomprehensioValidate, //【阅读理解、听力题】验证
    sharingchooseValidate, //【公用选项题】验证
  } from '../../api/question/questionconfig'
  import {
    queryQuestionTypeList,
    queryDifficultyType,
    queryQuestionCategory,
    queryQuestionLevelType,
    DeletePaperGroup,
    DeletePaperDetails
  } from '../../api/question/question'
  export default {
    components: {
      UeEditor,
      questionpoint, //知识点
      single, //单选题
      multiple, //多选题
      fillIn, //填空题
      judge, //判断题
      shortAnswer, //简答题
      matching, //连线题
      sortingProblem, //排序题
      cloze, //完型填空
      readingComprehensio, //阅读理解
      sharingChoose, //共用选择题、
      questionForm
    },
    meta: {
      title: "编辑试卷"
    },
    watch: {
      'ChooseItem.Title': {
        handler(newValue) {
          if (this.ChooseItem) {
            this.ChooseItem.ShowTitle = this.getRegItem(newValue);
          }
        },
        deep: true
      },
      'ChooseItem.Score': {
        handler(newValue) {
          if (this.ChooseItem) {
            this.ChooseItem.Score = newValue;
            this.calcPaper();
          }
        },
        deep: true
      },
      'ChooseItem.QuestionContentObj': {
        handler(newValue) {
          if (this.ChooseItem) {
            this.ChooseItem.QuestionContentObj = newValue;
          }
        },
        deep: true
      }
    },
    data() {
      return {
        config: {
          initialFrameWidth: null,
          initialFrameHeight: 80,
        },
        msg: {
          PaperId: 0
        },
        //试卷对象
        DataObj: {
          PaperId: 0, //试卷编号
          PaperName: '', //试卷名称
          QuestionBandIds: "", //关联题库编号
          DifficultyType: 1, //试卷难易程度
          GenerateType: 2, //组卷类型(1-智能组卷，2-手动组卷，3-智能导入)
          CreateNum: 1, //生成试卷套数
          PaperType: 2, //试卷类型(1-文件夹，2-试卷)
          ParentId: 0, //父节点编号,
          GroupList: [], //试卷答题分类
          IsOpen: 1, //(1-私有,2-开放)
          GroupType: 1, //组卷类型
          PaperScore: 0, //试卷总分数
        },
        //点击问题对象
        ChooseItem: null,
        questionDifficultyTypeList: [], //难易程度列表
        questionLevalTypeList: [],
        questionCategoryList: [], //分类
        choosePointArray: [], //选择知识点
        firstTypeList: [], //第一类题型
        secondTypeList: [], //第二类题型
        allTypeList: [], //所有题型
        isShowQuestion: false,
        commonIndex: -1,
        examNum: 0, //题量
        examScore: 0, //总分
        ComOneIndex: -1,
        ComCheckIndex: -1,
        savePaperLoading: false,
        isShowPoint: false, //选择知识点
        clickGroupItem: null, //选择的分组
        clickIndex: -1
      }
    },
    computed: {
      //获取计算后的问题分类(读音选择题、汉字选择题等)
      newQuestionCategoryList() {
        let newArray = JSON.parse(JSON.stringify(this.questionCategoryList));
        if (newArray && newArray.length > 0) {
          if (this.DataObj.GroupList && this.DataObj.GroupList.length > 0) {
            this.DataObj.GroupList.forEach(x => {
              newArray.forEach((qItem, index) => {
                if (x.QuestionTypeId == qItem.Id) {
                  newArray.splice(index, 1);
                }
              })
            })
          }
        }
        return newArray;
      }
    },
    created() {
      if (this.$route.query && this.$route.query.Id) {
        this.msg.PaperId = decodeURI(this.$route.query.Id);
      }
      if (this.$route.query && this.$route.query.ToParentId) {
        if (parseInt(this.$route.query.ToParentId) > 0) {
          this.DataObj.ParentId = parseInt(this.$route.query.ToParentId);
        }
      }
      this.getQuestionType();
      this.getDifficultyType();
      this.getQuestionCategory();
      this.getQuestionLevelType();
    },
    mounted() {
      if (this.msg.PaperId && this.msg.PaperId > 0) {
        this.GetPaperInfo()
      } else {
        var timeStr = date.formatDate(Date.now(), "YYYYMMDDHHmmss");
        this.DataObj.PaperName = timeStr + "新建试卷";
      }
    },
    methods: {
      GetGroupItem(gItem, gIndex) {
        this.clickIndex = gIndex;
        this.clickGroupItem = gItem;
      },
      //添加分类
      onCategoryItemClick(qObj) {
        this.DataObj.GroupList.push({
          GId: 0, //大题分组编号
          PaperId: 0, //试卷编号
          GroupName: qObj.Name,
          QuestionTypeId: qObj.Id,
          QuestionTypeKey: "",
          GSortNum: 0,
          GScore: 0, //分数
          DetailsList: [], //问题列表
        });
      },
      //关闭知识点弹窗
      closeQuestionPoint() {
        this.isShowPoint = false;
      },
      //获取知识点列表
      getPointList(obj) {
        if (obj && obj.length > 0) {
          if (this.choosePointArray && this.choosePointArray.length > 0) {
            this.choosePointArray = this.choosePointArray.concat(obj);
          } else {
            this.choosePointArray = obj;
          }
        }
        var pointIds = "";
        if (this.choosePointArray && this.choosePointArray.length > 0) {
          this.choosePointArray.forEach(item => {
            pointIds += ',' + item.PointId
          });
        }
        if (pointIds != '') {
          this.ChooseItem.Knowledge = pointIds.substring(1);
        }
      },
      //大类改变分数
      changeGroupScore(gItem) {
        var subScore = 0;
        if (gItem.GScore && gItem.GScore > 0) {
          subScore = gItem.GScore;
        }
        if (gItem.DetailsList && gItem.DetailsList.length > 0) {
          //阅读理解和听力
          if (gItem.QuestionTypeKey == "reading-comprehensio" || gItem.QuestionTypeKey == "listening") {
            var subCount = 0;
            gItem.DetailsList.forEach(dItem => {
              subCount += dItem.QuestionContentObj.length;
            });
            var avgScore = Number(subScore / subCount).toFixed(2);
            gItem.DetailsList.forEach(dItem => {
              dItem.QuestionContentObj.forEach(qItem => {
                qItem.SubScore = avgScore;
              });
            });
          }
          //完型填空
          else if (gItem.QuestionTypeKey == "cloze") {
            var subCount = 0;
            gItem.DetailsList.forEach(dItem => {
              subCount += dItem.QuestionContentObj.length;
            });
            var avgScore = Number(subScore / subCount).toFixed(2);
            gItem.DetailsList.forEach(dItem => {
              dItem.QuestionContentObj.forEach(qItem => {
                qItem.SubScore = avgScore;
              });
            });
          } else {
            var avgScore = Number(subScore / gItem.DetailsList.length).toFixed(2);
            gItem.DetailsList.forEach(sItem => {
              sItem.Score = avgScore;
            })
          }
        }
      },
      //上移下移(IsUp:0上移，1下移)
      MoveFatherItem(subIndex, IsUp) {
        var currentItem = this.DataObj.GroupList[subIndex];
        //上移
        if (IsUp == 0) {
          if (subIndex > 0) {
            var upItem = this.DataObj.GroupList[subIndex - 1];
            this.$set(this.DataObj.GroupList, subIndex - 1, currentItem);
            this.$set(this.DataObj.GroupList, subIndex, upItem);
            this.$forceUpdate();
          }
        } else {
          //下移
          if (subIndex != this.DataObj.GroupList.length - 1) {
            var downItem = this.DataObj.GroupList[subIndex + 1];
            this.$set(this.DataObj.GroupList, subIndex + 1, currentItem);
            this.$set(this.DataObj.GroupList, subIndex, downItem);
            this.$forceUpdate();
          }
        }
      },
      //移动子项
      MoveChildItem(Index, subIndex, IsUp) {
        var currentItem = this.DataObj.GroupList[Index].DetailsList[subIndex];
        //上移
        if (IsUp == 0) {
          if (subIndex > 0) {
            var upItem = this.DataObj.GroupList[Index].DetailsList[subIndex - 1];
            this.$set(this.DataObj.GroupList[Index].DetailsList, subIndex - 1, currentItem);
            this.$set(this.DataObj.GroupList[Index].DetailsList, subIndex, upItem);
            this.$forceUpdate();
          }
        } else {
          //下移
          if (subIndex != this.DataObj.GroupList[Index].DetailsList.length - 1) {
            var downItem = this.DataObj.GroupList[Index].DetailsList[subIndex + 1];
            this.$set(this.DataObj.GroupList[Index].DetailsList, subIndex + 1, currentItem);
            this.$set(this.DataObj.GroupList[Index].DetailsList, subIndex, downItem);
            this.$forceUpdate();
          }
        }
      },
      //删除题目
      delExam(gitem, item, index) {
        var that = this;
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          if (item.Id == 0) {
            gitem.splice(index, 1);
            that.calcPaper();
          } else {
            let msg = {
              Id: item.Id,
            }
            DeletePaperDetails(msg).then(res => {
              if (res.Code == 1) {
                gitem.splice(index, 1);
                that.calcPaper();
              }
            })
          }
        })
      },
      //删除分组及问题
      removeFather(item, index) {
        var that = this;
        this.$q.dialog({
          title: '提示信息',
          message: '是否删除此分组?',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          if (item.GId == 0) {
            that.DataObj.GroupList.splice(index, 1);
            that.calcPaper();
          } else {
            let msg = {
              GId: item.GId,
              QuestionTypeId: item.QuestionTypeId,
              PaperId: this.msg.PaperId,
            }
            DeletePaperGroup(msg).then(res => {
              if (res.Code == 1) {
                that.DataObj.GroupList.splice(index, 1);
                that.calcPaper();
              }
            })
          }
        })
      },
      //点击修改标题名字和分数
      getNameEdit(item, index) {
        item.forEach(x => {
          x.isShowEdit = false;
        })
        item[index].isShowEdit = true;
        this.$forceUpdate();
      },
      //鼠标移开输入框 保存数据 还有隐藏输入框
      saveExamName(item) {
        item.forEach(x => {
          x.isShowEdit = false;
        })
        this.calcPaper();
        this.$forceUpdate();
      },
      //获取子组件内容
      getChildData(obj) {
        if (obj) {
          this.ChooseItem.QuestionContent = JSON.stringify(obj);
          this.calcPaper();
        }
      },
      //获取题型列表
      getQuestionType() {
        queryQuestionTypeList({}).then(res => {
          if (res.Code == 1) {
            var tempArray = res.Data;
            this.allTypeList = tempArray;
            if (tempArray && tempArray.length > 0) {
              this.firstTypeList = tempArray.slice(0, 5);
              this.secondTypeList = tempArray.slice(5);
            }
          }
        });
      },
      //题型点击【添加问题】
      onItemClick(item, index) {
        var questionObj = this.getDetailsObj();
        questionObj.QuestionTypeId = item.QId;
        questionObj.QuestionTypeKey = item.Key;
        questionObj.GroupName = item.Name;
        var obj = CreateQuestion(item.Key);
        questionObj.QuestionContentObj = obj;
        if (obj) {
          questionObj.QuestionContent = JSON.stringify(obj);
        }
        var tempArray = [];
        questionObj.Score = 0;
        tempArray.push(questionObj);
        this.AddQuestion(tempArray);
      },
      //添加问题
      AddQuestion(qArray) {
        if (this.DataObj) {
          if (!this.DataObj.GroupList) {
            this.DataObj.GroupList = [];
          }
          if (qArray && qArray.length > 0) {
            qArray.forEach(qItem => {
              var gObj = {
                GId: 0, //大题分组编号
                PaperId: 0, //试卷编号
                GroupName: qItem.GroupName,
                QuestionTypeId: qItem.QuestionTypeId,
                QuestionTypeKey: qItem.QuestionTypeKey,
                GSortNum: 0,
                GScore: 0, //分数
                DetailsList: [], //问题列表
              }
              //题目类型
              if (!this.checkGroupExists(qItem.QuestionTypeId) && this.DataObj.GroupType == 1) {
                this.DataObj.GroupList.push(gObj);
              }
              if (this.DataObj.GroupType == 1) {
                this.DataObj.GroupList.forEach((gItem, gIndex) => {
                  if (gItem.QuestionTypeId == qItem.QuestionTypeId) {
                    if (!gItem.DetailsList) {
                      gItem.DetailsList = [];
                    }
                    gItem.DetailsList.push(qItem);
                  }
                })
              }
              //题目分类
              else if (this.DataObj.GroupType == 2) {
                if (!this.clickGroupItem) {
                  this.$q.notify({
                    type: 'negative',
                    position: "top",
                    message: `请先点击左侧分类!在添加问题`
                  })
                } else {
                  if (this.clickGroupItem.DetailsList && this.clickGroupItem.DetailsList.length > 0) {
                    this.clickGroupItem.DetailsList.push(qItem);
                  } else {
                    this.clickGroupItem.DetailsList = [];
                    this.clickGroupItem.DetailsList.push(qItem);
                  }
                }
              }
            })
          }
        }
        this.calcPaper();
      },
      //判断题库是否存在
      checkGroupExists(QuestionTypeId) {
        var isExistsGroup = false;
        if (this.DataObj && this.DataObj.GroupList && this.DataObj.GroupList.length > 0) {
          this.DataObj.GroupList.forEach(item => {
            if (!isExistsGroup) {
              if (item.QuestionTypeId == QuestionTypeId) {
                isExistsGroup = true;
              }
            }
          })
        }
        return isExistsGroup;
      },
      //获取试卷问题详细Obj
      getDetailsObj() {
        var objOption = {
          Id: 0, //试卷详情编号
          PaperId: 0, //试卷编号
          BankId: 0, //题库编号
          QuestionId: 0, //问题编号
          Title: "", //问题标题
          QuestionContent: "", //问题内容
          DifficultyType: 1, //问题难易程度
          AnswerParse: "", //答案解析
          QuestionTypeId: 0, //问题类型编号
          QuestionTypeKey: "", //问题类型Key
          Knowledge: "", //知识点
          IsUpdateJobExam: 0, //是否同步修改引用此题目的作业和考试(1-是)
          SortNum: 0, //排序
          Answer: '', //问题答案【JSON字符串】
          QuestionContentObj: [], //问题选项
          IsMutex: 1, //填空题(答案顺序打乱也判正确)
          Category: 0, //问题大类，
          LevelType: 1, //考级程度
          Score: 0, //分数
          GroupName: "", //分组名称
          ShowTitle: ''
        };
        return objOption;
      },
      //获取问题大类
      getQuestionCategory() {
        queryQuestionCategory().then(res => {
          this.questionCategoryList = res.Data;
        })
      },
      //获取问题考级程度
      getQuestionLevelType() {
        queryQuestionLevelType().then(res => {
          this.questionLevalTypeList = res.Data;
        })
      },
      //获取问题难易程度列表
      getDifficultyType() {
        queryDifficultyType().then(res => {
          if (res.Code == 1) {
            this.questionDifficultyTypeList = res.Data;
          }
        });
      },
      //获取题目
      GetPaperInfo() {
        GetPaper(this.msg).then(res => {
          var tempData = res.Data;
          if (res.Code == 1) {
            this.DataObj.PaperId = tempData.PaperId;
            this.DataObj.PaperName = tempData.PaperName;
            this.DataObj.QuestionBandIds = tempData.QuestionBandIds;
            this.DataObj.DifficultyType = tempData.DifficultyType;
            this.DataObj.GenerateType = tempData.GenerateType;
            this.DataObj.CreateNum = tempData.CreateNum;
            this.DataObj.PaperType = tempData.PaperType;
            this.DataObj.ParentId = tempData.ParentId;
            this.DataObj.IsOpen = tempData.IsOpen;
            this.DataObj.GroupType = tempData.GroupType;
            if (tempData.GroupList && tempData.GroupList.length > 0) {
              this.DataObj.GroupList = tempData.GroupList;
            }
            this.calcPaper();
          }
        })
      },
      //计算试卷相关
      calcPaper() {
        this.examScore = 0;
        this.examNum = 0;
        if (this.DataObj && this.DataObj.GroupList) {
          this.DataObj.GroupList.forEach(x => {
            var tempGScore = 0;
            if (x.DetailsList && x.DetailsList.length > 0) {
              this.examNum += x.DetailsList.length;
              x.DetailsList.forEach(y => {
                if (y.QuestionTypeKey == "cloze") {
                  var clozeScore = 0;
                  if (y.QuestionContentObj && y.QuestionContentObj.length > 0) {
                    y.QuestionContentObj.forEach(qItem => {
                      var tempClozeScore = 0;
                      if (!qItem.SubScore) {
                        qItem.SubScore = 0;
                      }
                      if (qItem.SubScore != '') {
                        tempClozeScore = qItem.SubScore;
                      }
                      clozeScore += Number(tempClozeScore);
                    })
                  }
                  y.Score = clozeScore;
                }
                if (y.QuestionTypeKey == "reading-comprehensio" || y.QuestionTypeKey == "listening") {
                  var readScore = 0;
                  if (y.QuestionContentObj && y.QuestionContentObj.length > 0) {
                    y.QuestionContentObj.forEach(qItem => {
                      var tempReadingScore = 0;
                      if (qItem.SubScore != '') {
                        tempReadingScore = qItem.SubScore;
                      }
                      readScore += Number(tempReadingScore);
                    })
                  }
                  y.Score = readScore;
                }
                if (y.Score) {
                  tempGScore += Number(y.Score);
                  this.examScore += Number(y.Score);
                }
              })
            }
            x.GScore = tempGScore.toFixed(2);
          })
        }
      },
      //点击问题
      ClickItem(questionItem, index, index2) {
        this.ChooseItem = null;
        this.ComOneIndex = index;
        this.ComCheckIndex = index2;
        this.ChooseItem = questionItem;
        this.ChooseItem.QuestionContentObj = questionItem.QuestionContentObj;
        if (this.ChooseItem.Score == null || this.ChooseItem.Score == '') {
          this.ChooseItem.Score = 0;
        }
        if (questionItem.QuestionTypeKey != 'sharing-choose' && this.$refs.UE_Title) {
          this.$refs.UE_Title.reloadNewValue();
        }
        if (this.$refs.UE_AnswerParse) {
          this.$refs.UE_AnswerParse.reloadNewValue();
        }
        this.ChooseItem.AnswerParse = questionItem.AnswerParse;
        if (questionItem.QuestionPointList) {
          this.choosePointArray = questionItem.QuestionPointList;
        } else {
          this.choosePointArray = []
        }
        this.$forceUpdate();
      },
      //正则匹配替换
      getRegItem(val) {
        let Item = val.replace(/<iframe(([\s\S])*?)<\/iframe>/ig, '[音频]').replace(/<img.*?(?:>|\/>)/gi, '[图片]');
        return Item
      },
      //保存题目
      SavePaper() {
        if (this.validateType()) {
          this.DataObj.PaperScore = this.examScore;
          this.savePaperLoading = true;
          savePaperInfo(this.DataObj).then(res => {
            this.savePaperLoading = false;
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '操作成功!',
                position: 'top'
              })
              this.$router.push({
                path: '/exam/examPaper',
                query: {}
              });
            } else {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `操作失败!`
              })
              this.savePaperLoading = false;
            }
          }).catch(() => {
            this.savePaperLoading = false;
          })
        }
      },
      //验证
      validateType() {
        var result = true;
        if (this.DataObj && this.DataObj.GroupList && this.DataObj.GroupList.length > 0) {
          for (let k = 0; k < this.DataObj.GroupList.length; k++) {
            var gIndex = k;
            var newKey = this.DataObj.GroupList[k].QuestionTypeKey;
            var gName = this.DataObj.GroupList[k].GroupName;
            var detailsList = this.DataObj.GroupList[k].DetailsList;
            var retMessage = "";
            switch (newKey) {
              //单选题
              case "single":
                retMessage = chooseValidate(gName, detailsList);
                break;
                //多选题
              case 'multiple':
                retMessage = chooseValidate(gName, detailsList);
                break;
                //填空题
              case "fill-in":
                retMessage = fillInValidate(gName, detailsList);
                break;
                //判断题
              case "judge":
                retMessage = judgeValidate(gName, detailsList);
                break;
                //简答题
              case "short-answer":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //名词解释
              case "noun-explanation":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //论述题
              case "essay-question":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //计算题
              case "calculation":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //分录题
              case "entry-problem":
                retMessage = fillInValidate(gName, detailsList);
                break;
                //资料题
              case "data-question":
                retMessage = fillInValidate(gName, detailsList);
                break;
                //连线题
              case "matching":
                retMessage = matchingValidate(gName, detailsList);
                break;
                //排序题
              case "sorting-problem":
                retMessage = sortingproblemValidate(gName, detailsList);
                break;
                //完型填空
              case "cloze":
                retMessage = clozeValidate(gName, detailsList);
                break;
                //阅读理解
              case "reading-comprehensio":
                retMessage = readingcomprehensioValidate(gName, detailsList);
                break;
                //口语题
              case "spoken":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //听力题
              case "listening":
                retMessage = readingcomprehensioValidate(gName, detailsList);
                break;
                //公用选项题
              case "sharing-choose":
                retMessage = sharingchooseValidate(gName, detailsList);
                break;
                //其它题
              case "other":
                retMessage = shortanswerValidate(gName, detailsList);
                break;
                //单选题-数字
              case "single-number":
                retMessage = chooseValidate(gName, detailsList);
                break;
            }
            if (retMessage != '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: retMessage
              });
              result = false;
              return;
            }
          }
        }
        return result;
      },
      //关闭弹窗
      closeQuestForm() {
        this.isShowQuestion = false;
      },
      //获取选择的问题列表
      getQuestionList(qArray) {
        var tempArray = [];
        if (qArray && qArray.length > 0) {
          qArray.forEach(eItem => {
            var qObj = this.getDetailsObj();
            qObj.QuestionId = eItem.QuestionId;
            qObj.Title = eItem.SourceTitle;
            qObj.ShowTitle = eItem.Title;
            qObj.QuestionContent = eItem.QuestionContent;
            qObj.DifficultyType = eItem.DifficultyType;
            qObj.AnswerParse = eItem.AnswerParse;
            qObj.QuestionTypeId = eItem.QuestionTypeId;
            qObj.QuestionTypeKey = eItem.QuestionTypeKey;
            qObj.Knowledge = eItem.Knowledge;
            qObj.IsUpdateJobExam = eItem.IsUpdateJobExam;
            qObj.SortNum = eItem.SortNum;
            qObj.Answer = eItem.Answer;
            qObj.IsMutex = eItem.IsMutex;
            qObj.Category = eItem.Category;
            qObj.LevelType = eItem.LevelType;
            var tempType = this.allTypeList.find(x => x.QId == qObj.QuestionTypeId);
            if (tempType) {
              qObj.GroupName = tempType.Name;
            }
            //问题选项
            if (eItem.QuestionContent) {
              qObj.QuestionContentObj = JSON.parse(eItem.QuestionContent);
            }
            tempArray.push(qObj);
          });
        }
        this.AddQuestion(tempArray);
        this.isShowQuestion = false;
      },
      //获取相同
      getRepeat(QuestionId, Arr) {
        let Num = 0;
        Arr.forEach((x, index) => {
          if (x.QuestionId == QuestionId) {
            Num++;
          }
        })
        if (Num > 1) {
          return true
        }
      },
      getIndex(Id, Arr) {
        const index = Arr.findIndex(d => d.QuestionId === Id);
        return index + 1;
      }
    }
  }

</script>
