<?php use app\components\QuestionHelper; ?>
<div class="layui-tab layui-tab-brief">
  <ul class="layui-tab-title">
    <?php include(__DIR__ ."/../basic/menu.php"); ?>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
<?php if($exam->ispublish!=1){ ?>
<form class="layui-form" id="detail_form" method="post" style="margin-top:15px;">
  <div class="layui-form-item">
    <label class="layui-form-label">组卷方式</label>
    <div class="layui-input-block">
      <input type="radio" name="questway" lay-skin="primary" lay-filter="changeQuestWay" title="题库选取" value="0"<?php if($exam->questway==0){echo ' checked';} ?>>
      <input type="radio" name="questway" lay-skin="primary" lay-filter="changeQuestWay" title="随机组卷" value="1"<?php if($exam->questway==1){echo ' checked';} ?>>
      <input type="radio" name="questway" lay-skin="primary" lay-filter="changeQuestWay" title="学生抽题" value="2"<?php if($exam->questway==2){echo ' checked';} ?>>
    </div>
  </div>

  <div class="layui-form-item" id="questway1box_2"<?php if($exam->questway==0){echo ' style="display:none;"';} ?>>
    <label class="layui-form-label">组卷范围</label>
    <div class="layui-input-block" id="rand_coursenamebox"><?php if(!empty($exam->chouti_courseid)){echo '<span class="layui-badge layui-bg-blue" style="height:36px;line-height:36px;">'. $exam->chouti_coursename .'</span>';} ?><?php if(!empty($exam->chouti_treeid)){echo '&nbsp;&gt;&nbsp;<span class="layui-badge layui-bg-blue" style="height:36px;line-height:36px;">'. $exam->chouti_treename .'</span>';} ?></div>
    <div class="layui-input-block" style="margin-top:5px;"><a class="layui-btn layui-btn-sm" onclick="showCourseList();"><i class="layui-icon layui-icon-add-circle"></i> 选择范围</a></div>
  </div>

  <div id="questway1box_1"<?php if($exam->questway==0){echo ' style="display:none;"';} ?>>
  <?php $qtypejobj = json_decode($exam->qtypejson); foreach($qtypejobj as $oneqtype){ ?>
  <div class="layui-form-item" id="questtype_<?php echo $oneqtype->id; ?>_box">
    <div class="layui-inline">
      <label class="layui-form-label"><?php echo $oneqtype->name; ?></label>
      <div class="layui-input-inline">
        <input type="text" name="questnum[]" class="layui-input" maxlength="3" value="<?php echo $oneqtype->questnum; ?>">
        <input type="hidden" name="typechild[]" value="<?php echo $oneqtype->id; ?>">
        <input type="hidden" name="typename[]" value="<?php echo $oneqtype->name; ?>">
      </div>
      <div class="layui-form-mid">道</div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">每道</label>
      <div class="layui-input-inline">
        <input type="text" name="onepoints[]" class="layui-input" maxlength="3" value="<?php echo $oneqtype->onepoints; ?>">
      </div>
      <div class="layui-form-mid">分</div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">可用题目</label>
      <div class="layui-form-mid"><span class="rand_maxquest" id="maxquest_<?php echo $oneqtype->id; ?>_box">0</span>&nbsp;&nbsp;&nbsp;道</div>
    </div>
  </div>
  <?php } ?>
  </div>

  <div class="layui-form-item" id="questway2box_1"<?php if($exam->questway!=2){echo ' style="display:none;"';} ?>>
    <div class="layui-inline">
      <label class="layui-form-label">重复抽题</label>
      <div class="layui-input-inline" style="width:60px;">
        <input type="text" name="maxchouti" class="layui-input" maxlength="3" value="<?php echo $exam->maxchouti; ?>">
      </div>
      <div class="layui-form-mid">次，允许重新抽题的次数(0为不限)</div>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" id="finished_button">确定</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:window.history.back();">取消</button>
    </div>
  </div>

  <input type="hidden" name="examid" value="<?php echo $exam->id; ?>">
  <input type="hidden" name="rand_courseid" value="<?php echo $exam->chouti_courseid; ?>">
  <input type="hidden" name="rand_coursename" value="<?php echo $exam->chouti_coursename; ?>">
  <input type="hidden" name="rand_treeid" value="<?php echo $exam->chouti_treeid; ?>">
  <input type="hidden" name="rand_treename" value="<?php echo $exam->chouti_treename; ?>">
</form>
<hr>
<?php } ?>

<?php if($exam->ispublish==1 && $exam->questway==2){ ?>
<div style="line-height: 30px;">组卷方式：学生抽题</div>
<div style="line-height: 30px;">抽题范围：<?php echo $exam->chouti_coursename; ?><?php if(!empty($exam->chouti_treename)){echo "&nbsp;&gt;&nbsp;". $exam->chouti_treename;} ?></div>
<div style="line-height: 30px;"><?php $qtypejobj = json_decode($exam->qtypejson); foreach($qtypejobj as $oneqtype){if($oneqtype->questnum>0){echo $oneqtype->name .' '. $oneqtype->questnum .' 道，每道 '. $oneqtype->onepoints .' 分。<br>';}} ?></div>
<div style="line-height: 30px;">允许重新抽题：<?php echo $exam->maxchouti; ?>次 (0为不限)</div>
<?php } ?>

<?php if($exam->questway!=2){ ?>
<form class="layui-form" id="exstems_form" method="post">
<?php $totalpoints = 0; ?>
<?php foreach ($exstems as $onekey => $onestem) { ?>
  <div style="margin: 10px 0;">
  <div style="float:left;"><span class="layui-badge"><?php echo $onekey+1; ?>.</span>
  <span class="layui-badge layui-bg-blue"><?php echo QuestionHelper::ShowStemtypeName($onestem->typechild); ?></span>&nbsp;</div>
  <div class="quest-stem-content" style="float:left;"><?php echo htmlspecialchars_decode($onestem->content); ?></div>
  <div style="float:right;">
    <?php if($exam->ispublish!=1){ ?>
    <input type="hidden" name="exstemid[]" value="<?php echo $onestem->id; ?>">
    <input type="checkbox" name="exstemidel[]" title="删除" value="<?php echo $onestem->id; ?>">
    <?php } ?>
  </div>
  <div style="clear:both;height:4px;"></div>
  <?php if($onestem->typeid==1 || $onestem->typeid==2){ ?>
  <div style="margin: 10px 0;">
  <?php foreach ($onestem->options as $oneoption) {
    echo '<div style="float:left;"><span class="layui-badge layui-bg-blue">'. $oneoption->code .'</span>&nbsp;</div>';
    echo '<div class="quest-option-content" style="float:left;">'. htmlspecialchars_decode($oneoption->content) .'</div>';
    echo '<p style="clear:both;height:4px;"></p>';
  }?>
  </div>
  <?php } ?>
  </div>

  <div class="quest-answer-content" style="margin: 10px 0;">
  答案：
  <?php if($onestem->typeid==1 || $onestem->typeid==2 || $onestem->typeid==5){ ?>
  <?php echo htmlspecialchars_decode($onestem->answer); ?>
  <?php }elseif($onestem->typeid==3){ ?>
  <?php if($onestem->answer=="1"){echo '正确';}else{echo '错误';} ?>
  <?php }elseif($onestem->typeid==4){ ?>
  <?php foreach ($onestem->options as $oneoption) {
    echo '<span class="layui-badge layui-bg-blue">'. $oneoption->content .'</span>&nbsp;';
  }?>
  <?php } ?>
  </div>

  <div style="margin:10px 0;">
  分值：<?php if($exam->ispublish!=1){ ?>
    <div class="layui-input-inline" style="width:60px;">
      <input type="text" name="expoints[]" class="layui-input" maxlength="3" value="<?php echo $onestem->points; ?>">
    </div>
    <?php }else{echo $onestem->points;} ?>
  </div>
  
  <hr>
  <?php $totalpoints += $onestem->points; ?>
<?php } ?>

<div id="totalpointsbox" style="margin-bottom:10px;">总分：<?php echo $totalpoints; ?></div>

<?php if(!empty($exstems) && $exam->ispublish!=1){ ?>
<div style="float:left;">
<button type="button" class="layui-btn" id="savepoints_button">保存题目分值</button>
</div>
<div style="float:right;">
<input type="checkbox" name="chooseall" title="全选" value="all" lay-filter="allChoose">
<button type="button" class="layui-btn" id="deletstems_button">删除题目</button>
</div>
<?php } ?>

<input type="hidden" name="examid" value="<?php echo $exam->id; ?>">
</form>
<?php } ?>

    </div>
  </div>
</div>
<br>

<script type="text/javascript">
var examid = <?php echo $exam->id; ?>;
var questway = <?php echo $exam->questway; ?>;
var ispublish = <?php echo $exam->ispublish; ?>;
</script>

<script src="/public/modules/glexam/question/index.js"></script>