<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'} ">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-form-pane .layui-form-label {width: 130px;}
        .layui-form-pane .layui-input-block {margin-left: 130px;}
    </style>
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
              <a class="close" href="javascript:void(0);">上级列表</a><span lay-separator="">/</span>
              <a href="javascript:void(0);"><cite>新增内容</cite></a>
            </span>
        </div>
        <div class="layui-card-body" style="padding: 15px;">
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-sm8 layui-col-md8">
                    <form class="layui-form layui-form-pane" lay-filter="dataForm">
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="paperName" name="paperName" class="layui-input" value="" placeholder="请输入名称" lay-verify="required">
                            </div>
                        </div>
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label">试卷类型</label>
                            <div class="layui-input-block">
                                <input type="radio" name="paperType" value="test" title="测试试卷" checked>
                                <input type="radio" name="paperType" value="simulation" title="模拟试卷">
                                <input type="radio" name="paperType" value="examination" title="考试试卷">
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">单选数量</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="choiceSingleCount" name="choiceSingleCount" class="layui-input question-count" value="30" placeholder="请输入单选数量" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">单选每题得分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="choiceSingleEachScore" name="choiceSingleEachScore" class="layui-input question-score" value="2.0" placeholder="请输入单选每题得分" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">多选数量</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="choiceMultipleCount" name="choiceMultipleCount" class="layui-input question-count" value="10" placeholder="请输入多选数量" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">多选每题得分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="choiceMultipleEachScore" name="choiceMultipleEachScore" class="layui-input question-score" value="2.0" placeholder="请输入多选每题得分" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">判断数量</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="tureOrFalseCount" name="tureOrFalseCount" class="layui-input question-count" value="10" placeholder="请输入判断数量" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">判断每题得分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="tureOrFalseEachScore" name="tureOrFalseEachScore" class="layui-input question-score" value="2.0" placeholder="请输入判断每题得分" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">填空数量</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="fillInTheBlanksCount" name="fillInTheBlanksCount" class="layui-input question-count" value="10" placeholder="请输入填空数量" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">填空每题得分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="fillInTheBlanksEachScore" name="fillInTheBlanksEachScore" class="layui-input question-score" value="1.0" placeholder="请输入填空每题得分" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">解答数量</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="answerCount" name="answerCount" class="layui-input question-count" value="2" placeholder="请输入解答数量" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">解答每题得分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="answerEachScore" name="answerEachScore" class="layui-input question-score" value="5.0" placeholder="请输入解答每题得分" lay-verify="required|minNumberVerify">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">及格分数</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="passScore" name="passScore" class="layui-input" value="60.0" placeholder="请输入及格分数" lay-verify="required|minNumberVerify|passScoreVerify">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">总分</label>
                                    <div class="layui-input-block">
                                        <input type="number" step="0.01" id="totalScore" name="totalScore" class="layui-input" value="100.0" placeholder="请输入总分" lay-verify="required|minNumberVerify" readonly>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-layout-admin">
                            <div class="layui-input-block">
                                <div class="layui-footer" style="left: 0;">
                                    <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">提交新增</button>
                                    <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        // 初始化内容
        function initData() {
        }
        initData();

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                top.restAjax.post(top.restAjax.path('api/paper/save', []), formData.field, null, function(code, data) {
                    var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
                        time: 0,
                        btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
                        shade: 0.3,
                        yes: function(index) {
                            top.dialog.close(index);
                            window.location.reload();
                        },
                        btn2: function() {
                            closeBox();
                        }
                    });
                }, function(code, data) {
                    top.dialog.msg(data.msg);
                }, function() {
                    loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                }, function() {
                    top.dialog.close(loadLayerIndex);
                });
            });
            return false;
        });

        $('.close').on('click', function() {
            closeBox();
        });

        $('.question-count, .question-score').on('keyup', function() {
            var choiceSingleCount = $('#choiceSingleCount').val() ? $('#choiceSingleCount').val() : 0;
            var choiceMultipleCount = $('#choiceMultipleCount').val() ? $('#choiceMultipleCount').val() : 0;
            var tureOrFalseCount = $('#tureOrFalseCount').val() ? $('#tureOrFalseCount').val() : 0;
            var fillInTheBlanksCount = $('#fillInTheBlanksCount').val() ? $('#fillInTheBlanksCount').val() : 0;
            var answerCount = $('#answerCount').val() ? $('#answerCount').val() : 0;

            var choiceSingleEachScore = parseFloat($('#choiceSingleEachScore').val() ? $('#choiceSingleEachScore').val() : 0);
            var choiceMultipleEachScore = parseFloat($('#choiceMultipleEachScore').val() ? $('#choiceMultipleEachScore').val() : 0);
            var tureOrFalseEachScore = parseFloat($('#tureOrFalseEachScore').val() ? $('#tureOrFalseEachScore').val() : 0);
            var fillInTheBlanksEachScore = parseFloat($('#fillInTheBlanksEachScore').val() ? $('#fillInTheBlanksEachScore').val() : 0);
            var answerEachScore = parseFloat($('#answerEachScore').val() ? $('#answerEachScore').val() : 0);
            var totalScore = choiceSingleCount * choiceSingleEachScore +
                choiceMultipleCount * choiceMultipleEachScore +
                tureOrFalseCount * tureOrFalseEachScore +
                fillInTheBlanksCount * fillInTheBlanksEachScore +
                answerCount * answerEachScore;
            form.val('dataForm', {
                totalScore: totalScore
            });
        });

        // 校验
        form.verify({
            minNumberVerify: function(value, item) {
                if(parseFloat(value) < 0) {
                    return '数字不能小于0';
                }
            },
            passScoreVerify: function(value, item) {
                if(parseFloat(value) > parseFloat($('#totalScore').val() ? $('#totalScore').val() : 0)) {
                    return '及格分数不能大于总分';
                }
            }
        });
    });
</script>
</body>
</html>