<template>
  <div>
    <div class="ev-container">
      <h1 @click="toTestPaper" style="cursor:pointer;">新建测试</h1>
      <Divider />
      <div class="exersices-attr display-flex">
        <div class="exersices-attr-type my-radio-style test-scene">
          <IconText :text="'测试情景'" :color="'green'" :icon="'ios-cloudy-night'"></IconText>
          <RadioGroup v-model="testBasicAttr.testScene" type="button">
            <Radio label="simulation">模拟</Radio>
            <Radio label="sectional">段考</Radio>
            <Radio label="week">周考</Radio>
            <Radio label="small">小考</Radio>
            <Radio label="custom">自定</Radio>
          </RadioGroup>
        </div>
        <div class="exersices-attr-diff my-radio-style test-type">
          <IconText :text="'测试类型'" :color="'red'" :icon="'ios-settings'"></IconText>
          <RadioGroup v-model="testBasicAttr.testType" type="button">
            <Radio label="formal">正式成绩</Radio>
            <Radio label="practice">练习成绩</Radio>
            <Radio label="statistics">统计(问卷)</Radio>
          </RadioGroup>
        </div>
      </div>
      <div class="exersices-attr display-flex" style="margin-top:30px;">
        <div class="exersices-attr-type my-radio-style test-target">
          <IconText :text="'测试对象'" :color="'#FF7F24'" :icon="'ios-people'"></IconText>
          <RadioGroup v-model="testBasicAttr.testTarget" type="button">
            <Radio label="class">同年级</Radio>
            <Radio label="grade">跨年级</Radio>
            <Radio label="school">跨学校</Radio>
          </RadioGroup>
        </div>
        <div class="exersices-attr-diff my-radio-style test-mode">
          <IconText :text="'创建方式'" :color="'#0086e6'" :icon="'ios-create'"></IconText>
          <RadioGroup v-model="testBasicAttr.testMode" type="button">
            <Radio label="auto">自动组题</Radio>
            <Radio label="import">批量导入</Radio>
            <Radio label="choose">题库挑选</Radio>
          </RadioGroup>
        </div>
      </div>
      <div class="create-wrap" v-if="testBasicAttr.testMode == 'auto'">
        <Divider />
        <div class="create-test-attr">
          <div>
            <IconText style="float:left;" :text="'已选章节'" :color="'#0086e6'" :icon="'md-checkbox-outline'"></IconText>
            <IconText style="float:right; cursor:pointer;" :text="'清空'" :color="'#AAAAAA'" :icon="'ios-trash-outline'" :iconSize="20" :textSize="14" @click.native="clearTags('auto')"></IconText>
            <div style="clear:both;"></div>
          </div>

          <div class="test-chapter-wrap">
            <p v-if="autoCreate.chapters.length == 0">您未选择章节！</p>
            <Tag type="dot" closable v-for="(item,index) in autoCreate.chapters" :key="index" @on-close="clearCurrentTag(index,'auto')">{{item}}</Tag>
          </div>
        </div>
        <div class="create-test-attr">
          <IconText :text="'试卷设置'" :color="'#0086e6'" :icon="'ios-cog'"></IconText>
          <div class="test-attr-item">
            <label class="label-style">出卷方式：</label>
            <RadioGroup v-model="autoCreate.createWay">
              <Radio label="relation">
                关联出题
              </Radio>
              <Tooltip max-width="200" content="匹配出来的试题包含的知识点（章节），最少有一个在已选的知识点（章节）中，这个方式适用于期末考试、学业考试、升学考试等试卷类型。出题的综合性较强。" placement="top">
                <Icon type="md-help" color="#0086e6" size="16" style="cursor:pointer;" />
              </Tooltip>
              <Radio label="accurate" style="margin-left:30px;">
                精准出题
              </Radio>
              <Tooltip max-width="200" content="匹配出来的试题包含的知识点（章节）。都在已选的知识点（章节）中，这个方式保证了组卷的精准性，避免超纲试题的出现，适用于同步类型的试卷。" placement="top">
                <Icon type="md-help" color="#0086e6" size="16" style="cursor:pointer;" />
              </Tooltip>
            </RadioGroup>
          </div>
          <div class="test-attr-item">
            <label class="label-style">试题过滤：</label>
            <CheckboxGroup v-model="autoCreate.createFilter" style="display:inline-block;">
              <Checkbox label="norepeat">过滤已使用的试题</Checkbox>
              <Checkbox label="nobeyond" style="margin-left:30px;">防超纲出题</Checkbox>
            </CheckboxGroup>
          </div>
        </div>
        <div class="create-test-attr set-question-num">
          <IconText :text="'题型/题量设置'" :color="'#0086e6'" :icon="'md-list'"></IconText>
          <div class="test-attr-item border-buttom">
            <div class="my-check-button" :class="testExerciseType.indexOf(1) == -1 ? '' : 'my-check-active' " @click="toggleStatus(1)">
              单选题
            </div>
            <div class="my-check-button" :class="testExerciseType.indexOf(2) == -1 ? '' : 'my-check-active' " @click="toggleStatus(2)">
              多选题
            </div>
            <div class="my-check-button" :class="testExerciseType.indexOf(3) == -1 ? '' : 'my-check-active' " @click="toggleStatus(3)">
              判断题
            </div>
            <div class="my-check-button" :class="testExerciseType.indexOf(4) == -1 ? '' : 'my-check-active' " @click="toggleStatus(4)">
              填空题
            </div>
            <div class="my-check-button" :class="testExerciseType.indexOf(5) == -1 ? '' : 'my-check-active' " @click="toggleStatus(5)">
              问答题
            </div>
            <div class="my-check-button" :class="testExerciseType.indexOf(6) == -1 ? '' : 'my-check-active' " @click="toggleStatus(6)">
              综合题
            </div>
          </div>
          <div class="test-exercise-settting test-attr-item">
            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(1) != -1">
              <span class="exercise-type">单选题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Single[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Single[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Single[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(2) != -1">
              <span class="exercise-type">多选题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Multiple[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Multiple[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Multiple[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(3) != -1">
              <span class="exercise-type">判断题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Judge[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Judge[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Judge[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(4) != -1">
              <span class="exercise-type">填空题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Complete[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Complete[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Complete[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(5) != -1">
              <span class="exercise-type">问答题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Subjective[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Subjective[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Subjective[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <div class="test-exercise-settting-item" v-show="testExerciseType.indexOf(6) != -1">
              <span class="exercise-type">综合题：</span>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">容易</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Compose[0]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">10道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">普通</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Compose[1]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">5道试题可用</label>
                </div>
              </div>
              <div class="test-settting-num-wrap">
                <div class="test-exercise-settting-num">
                  <label class="test-exercise-diff">困难</label>
                  <InputNumber :max="10" :min="1" v-model="autoCreate.exerciseNum.Compose[2]" placeholder="0"></InputNumber>
                  <label class="test-exercise-diff-num">2道试题可用</label>
                </div>
              </div>
            </div>

            <p v-if="testExerciseType.length == 0">请选择题目类型，并设置题目数量！</p>
          </div>
          <div class="create-test-submit">
            <Button type="info" @click="autoCreateTest">生成试卷</Button>
          </div>

        </div>
      </div>

      <div class="create-wrap" v-if="testBasicAttr.testMode == 'import' ">
        <Divider />
        <div class="create-test-attr">
          <IconText :text="'导入说明'" :color="'#0086e6'" :icon="'md-reorder'"></IconText>
          <div class="test-import-item">
            <p>
              1、暂时只支持“*.doc、.docx”格式的文件导入，文件大小不超过10M，建议使用模板导入；
            </p>
            <p>
              2、题目必须包含【题文】、【答案】、【解析】、【结束】字样，若题目没有解析，则内容写“无”；
            </p>
            <p>
              3、导入的题型暂时只支持单选题、多选题、判断题、填空题、主观题。
            </p>
          </div>
        </div>
        <div class="create-test-attr">
          <IconText :text="'选择文件'" :color="'#0086e6'" :icon="'md-grid'"></IconText>
          <div class="test-import-item test-import-item-bg">
            <Upload multiple action="api/ImportExercise/uploadWord" :headers="headers" :show-upload-list="hind" :on-success="uploadSuccess">
              <Button type="info">导入文件</Button>
            </Upload>
            <span class="download-template"><a href="https://teammodelstorage.blob.core.chinacloudapi.cn/teammodelosevaluation/20190628/%E9%A2%98%E7%9B%AE%E6%A8%A1%E6%9D%BF.docx">下载模板</a></span>
            <p>选择文件“*.doc、 *.docx”文件</p>
          </div>
        </div>

      </div>
      <div class="create-wrap" v-if="testBasicAttr.testMode == 'choose'">
        <Divider />
        <div class="create-test-attr">
          <div>
            <IconText style="float:left;" :text="'已选章节'" :color="'#0086e6'" :icon="'md-checkbox-outline'"></IconText>
            <IconText style="float:right; cursor:pointer;" :text="'清空'" :color="'#AAAAAA'" :icon="'ios-trash-outline'" :iconSize="20" :textSize="14" @click.native="clearTags('auto')"></IconText>
            <div style="clear:both;"></div>
          </div>

          <div class="test-chapter-wrap">
            <p v-if="chooseCreate.chapters.length == 0">您未选择章节！</p>
            <Tag type="dot" closable v-for="(item,index) in chooseCreate.chapters" :key="index" @on-close="clearCurrentTag(index,'choose')">{{item}}</Tag>
          </div>

          <div class="create-test-attr">
            <IconText :text="'题目类型'" :color="'#0086e6'" :icon="'md-apps'"></IconText>
            <div class="my-radio-style" style="margin-left:33px;">
              <RadioGroup v-model="chooseCreate.exersicesType" type="button">
                <Radio label="single">单选</Radio>
                <Radio label="multiple">多选</Radio>
                <Radio label="judge">判断</Radio>
                <Radio label="complete">填空</Radio>
                <Radio label="subjective">问答</Radio>
              </RadioGroup>
            </div>
          </div>
          <div class="create-test-attr">
            <IconText :text="'题目难度'" :color="'#0086e6'" :icon="'md-pulse'"></IconText>
            <div class="my-radio-style" style="margin-left:33px;">
              <RadioGroup v-model="chooseCreate.exersicesDiff" type="button">
                <Radio label="0">容易</Radio>
                <Radio label="1">较易</Radio>
                <Radio label="2">一般</Radio>
                <Radio label="3">较难</Radio>
                <Radio label="4">困难</Radio>
              </RadioGroup>
            </div>
          </div>
          <div class="create-test-attr">
            <IconText :text="'挑选类型'" :color="'#0086e6'" :icon="'md-keypad'"></IconText>
            <div class="my-radio-style" style="margin-left:33px;">
              <RadioGroup v-model="chooseCreate.type" type="button">
                <Radio label="0">挑选题目</Radio>
                <Radio label="1">挑选试卷</Radio>
              </RadioGroup>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="text-order-type-wrap" v-if="testBasicAttr.testMode == 'choose'">
      <div class="text-order-type" style="float:left;">
        <span>时间<Icon type="md-arrow-down" /></span>
        <span>使用次数<Icon type="md-arrow-down" /></span>
        <CheckboxGroup v-model="chooseCreate.filter">
          <Checkbox label="norepeat">过滤已使用的试题</Checkbox>
          <Checkbox label="nobeyond">防超纲出题</Checkbox>
        </CheckboxGroup>
      </div>
      <div class="text-order-type" style="float:right;margin-right:20px;">
        <span>共计：99题</span>
        <span style="margin-right:20px;">已选：0题</span>
        <Button shape="circle">选择本页全部试题</Button>
      </div>
      <div style="clear:both;"></div>
    </div>

    <div class="ev-container" v-if="testBasicAttr.testMode == 'choose'">
      题目列表
    </div>
    <div class="ev-container perview-word-analysis" v-if="testBasicAttr.testMode == 'import' && srcdoc != ''">
      <h2>文档解析预览 </h2>
      <Button shape="circle" icon="md-cloud-upload" @click="uploadHtmlString">确认上传</Button>
      <iframe class="my-iframe-style" src="https://www.baidu.com" :srcdoc="srcdoc"></iframe>
    </div>
  </div>

</template>
<script>
  //默认创建测试模板
  import IconText from '@/components/evaluation/IconText.vue'
  export default {
    components: {
      IconText
    },
    data() {
      return {
        srcdoc: '',
        hind: false,
        value2: null,
        exersicesDiff: '',
        testBasicAttr: {
          testScene: 'simulation',
          testType: 'formal',
          testTarget: 'class',
          testMode: 'auto'
        },
        chooseCreate: {
          chapters: ["1.1 正数和复数", "1.5 有理数的加减法", "3.3 从算式到方程"],
          exersicesType: '',
          exersicesDiff: '',
          type: '',
          filter: []
        },
        autoCreate: {
          chapters: ["1.1 正数和复数", "1.5 有理数的加减法", "3.3 从算式到方程"],
          createWay: 'relation',
          createFilter: [],
          exerciseNum: {
            Single: [null, null, null],
            Multiple: [null, null, null],
            Judge: [null, null, null],
            Complete: [null, null, null],
            Subjective: [null, null, null],
            Compose: [null, null, null]
          }

        },

        testExerciseType: [1]
      }
    },
    created() {

    },
    methods: {
      autoCreateTest() {
        let requestData = {};
        requestData["testBasicAttr"] = this.testBasicAttr;
        requestData["testMode"] = this.autoCreate;
        console.log(requestData);
      },
      uploadSuccess(response, file, fileList) {
        console.log(response);
        if (response.error == null) {
          this.$Message.success('文件上传解析成功！');
          this.srcdoc = response.result.data.HtmlString;
          console.log(response.result.data.HtmlString);
        } else {
          this.$Message.error('对不起，文档解析失败！');
        }
      },
      uploadHtmlString() {
        let requestData = {
          htmlString: this.srcdoc
        }

        this.$api.SaveAnalyzeHtml(requestData).then(res => {
          if (res.error == null) {
            localStorage.setItem("questions", JSON.stringify(res.result.data));
            this.$router.push({
              name: 'testPaper',//或者路径跳转path: '/addCreditCards',
              params: {
                flag: 1
              }
            });
          }
        }
        );
      },
      toTestPaper() {
        this.$router.push({
          path: '/testPaper',//或者路径跳转path: '/addCreditCards',
        });
      },
      toggleStatus(type) {
        let index = this.testExerciseType.indexOf(type);
        if (index == -1) {
          this.testExerciseType.push(type);
        } else {
          this.testExerciseType.splice(index, 1);
        }
      },
      clearTags(flag) {
        if (flag == 'auto') {
          this.autoCreate.chapters = [];
        } else {
          this.chooseCreate.chapters = [];
        }
      },
      clearCurrentTag(index, flag) {
        if (flag == 'auto') {
          this.autoCreate.chapters.splice(index, 1);
        } else {
          this.chooseCreate.chapters.splice(index, 1);
        }

      }

    },
    mounted() {

    },
    computed: {
      headers() {
        let hd = {}
        hd["Authorization"] = "Bearer " + localStorage.getItem("token");
        console.log(hd);
        return hd;
      }
    }
  }
</script>
<style src="../index/CreateTest.css" scoped>
  /*@import "../index/CreateTest.css";*/
</style>
<style>
  .test-exercise-settting-num .ivu-input-number-handler-wrap {
    display: none !important;
  }

  .test-exercise-settting-num .ivu-input-number-input {
    text-align: center;
    color: red;
    font-size: 16px;
  }
</style>
