linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('请选择题目')"/>
    <style>
        .changeColor {
            background-color: #337dff !important;
            color: #fffefa !important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="questionTemplateId" name="questionTemplateId"
                       th:value="${param.questionTemplateId}"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <p>题干:</p>
                            <input type="text" name="infoTextContentId"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;[[#{basis.search}]]</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;[[#{basis.reset}]]</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                        class="fa fa-check"></i>save
                </button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                        class="fa fa-reply-all"></i>close
                </button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('exam:question:edit')}]];
    var removeFlag = [[${@permission.hasPermi('exam:question:remove')}]];
    var prefix = ctx + "exam/question";
    var $parent = $.operate.parentHtml();
    $(function () {
        var levelId = [[${levelId}]];
        var langType = [[${langType}]];
        var template = [[${template}]];
 
        var options = {
            url: prefix + "/listForProductAddQuestion",
            queryParams: function () {
                var temp = {
                    levelId: levelId,
                    langType: langType,
                    template: template
                };
 
                return temp;
            },
            modalName: [[#{menu.exam.question.view}]],
            columns: [{
                checkbox: true,
                //formatter:stateFormatter
            },
                {
                    field: 'id',
                    title: [[#{jsp.exam.product.titleCode}]],
                    visible: false
                },
                {
                    field: 'permanentId',
                    title: [[#{jsp.exam.question.questionNumberPermanent}]]
                },
                {
                    field: 'title',
                    title: [[#{jsp.exam.product.questionStem}]]
                },
                {
                    field: 'levelName',
                    title: [[#{menu.exam.level.view}]]
                },
            ],
            onLoadSuccess: function (data) {
                // var $thisContent = $parent.$('[add-question-edit = "true"]').parents('.segmentation');
                var $thisContent = $parent.$('[add-question-now-part="true"]');
                $thisContent.removeAttrs('add-question-now-part');
                var $checkedValues = $thisContent.find('[name="questionId"]');
                // job选择维度
                if ($('#questionTemplateId').val() != "" && $('#questionTemplateId').val() != undefined) {
                    var $ibox = $parent.$('#headline').find('.ibox').eq(0);
                    $checkedValues = $ibox.find('[name="questionId"]');
                }
                //打开的时候选中
                $.btTable.bootstrapTable('uncheckAll');
                var template = [[${template}]];
 
                // 如果是大题目,不选择
                if (isTitle(template)) {
                    return;
                }
                var checkby = {};
                checkby['field'] = 'id';
                checkby['values'] = [];
                $($checkedValues).each(function (i) {
                    checkby['values'].push(parseInt($(this).val()));
                });
                $.btTable.bootstrapTable('checkBy', checkby);
            }
        };
        $.table.init(options);
    });
 
    function stateFormatter(value, row, index) {
        // var $thisContent = $parent.$('[add-question-edit="true"]').parents('#headline');
        var $thisContent = $parent.$('[add-question-edit="true"]').parents('.segmentation');
        var $checkedValues = $thisContent.find('[name="questionId"]');
        var flag = true;
        row['checked'] = false;
        $($checkedValues).each(function (i) {
            if (row.id == parseInt($(this).val())) {
                row.checked = true;
                flag = false;
            }
        });
 
        if (!flag) {
            return {
                disabled: true,//设置是否可用
                checked: true//设置选中
            };
        }
        return value;
    }
 
    function jobSubmit($tableSelect, $editConten) {
        $editConten.empty();
        $.each($tableSelect, function (index, obj) {
            if (!obj.checked) {// if do not checked
                var $questionContent = $parent.$('#questionSelect').clone();
                $questionContent.removeAttrs('id');
                $questionContent.removeAttrs('hidden');
                $questionContent.children('div').eq(0).html(1 + ")");
                $questionContent.children('p').eq(0).html(obj.permanentId);
                $questionContent.children('p').eq(1).html(obj.title);
                $questionContent.children('[name="contentId"]').eq(0).val(obj.infoTextContentId);
                $questionContent.children('[name="questionId"]').eq(0).val(obj.id);
 
                $.each(obj.choiceInput, function (index, select) {
                    str = "<li><li>" + select + "</li><li>" + obj.selectInput[index] + "</li></li>";
                    $questionContent.children('ul').eq(0).append(str);
                });
                $editConten.append($questionContent);
            }
        });
 
        $editConten.find('[name="question-seq"]').each(function (i) {
            var $permanentId = $(this).parents('.segmentation').find('[name = "permanentId"]');
            if ($permanentId.val().trim() != "" && $permanentId != undefined) {
                $(this).html($permanentId.val() + "-" + String.fromCharCode(i + 97));
            } else {
                $(this).html((i + 1) + '.');
            }
        });
    }
 
    function selectItem(obj, $questionContent) {
        $.each(obj.choiceInput, function (index, select) {
            str = "<li><li>" + select + "</li><li>" + obj.selectInput[index] + "</li></li>";
            $questionContent.children('ul').eq(0).append(str);
        });
    }
 
    function setParentQuestionId($questionContent) {
        var $iboxContent = $questionContent.prev();
        while ($iboxContent.hasClass('ibox-content') && !isTitle($questionContent.find('[name="template"]').eq(0).val())) {
            if ($iboxContent.attr("add-intelligence-title") == "true" || $iboxContent.find('[name="template"]').eq(0).val() == "intelligence_title") {
                $questionContent.children('[name="parentQuestionId"]').eq(0).val($iboxContent.children('[name="questionId"]').val());
                $iboxContent = $iboxContent.prev();
                break;
            }
            $iboxContent = $iboxContent.prev();
        }
    }
 
    function setQuestionTitle($questionContent, obj) {
        $questionContent.removeAttrs('id');
        $questionContent.removeAttrs('hidden');
        $questionContent.children('div').eq(0).html(1 + ")");
        $questionContent.children('p').eq(0).html(obj.permanentId);
        $questionContent.children('p').eq(1).html(obj.title);
        $questionContent.children('[name="contentId"]').eq(0).val(obj.infoTextContentId);
        $questionContent.children('[name="questionId"]').eq(0).val(obj.id);
        $questionContent.children('[name="template"]').eq(0).val(obj.template);
    }
 
    function isVerify(template, $tableSelect) {
        return template == "intelligence_title" && $tableSelect.length > 1;
    }
 
    function isTitle(template) {
        return template == "intelligence_title";
    }
 
    function isIntelligenceQuestion(template) {
        return template == "intelligence";
    }
 
    function setNumber($editConten) {
        var smallQuestionNum = 1;
        var orderNum = 1;
        $editConten.find('[name="question-seq"]').each(function (i) {
            var $permanentId = $(this).parents('.segmentation').find('[name = "permanentId"]');
            if ($permanentId.val().trim() != "" && $permanentId != undefined) {
                $(this).html($permanentId.val() + "-" + String.fromCharCode(i + 97));
            } else {
                var parentQuestionId = $(this).parent().find('[name="parentQuestionId"]').eq(0).val();
                // 智力题没有不分片的,所以其他地方不需要这样
                if (parentQuestionId == null || parentQuestionId == undefined || parentQuestionId.trim() == "") {
                    $(this).html((orderNum++) + '.');
                    smallQuestionNum = 1;
                } else {
                    $(this).html("(" + (smallQuestionNum++) + ")");
                }
            }
        });
    }
 
    function delteQuetion($editConten, $addPartEdit) {
        // 如果是设置题目不分段
        if ($parent.$('[add-part-edit="true"]').length == 0) {
            $parent.$('.add-part').css("display", "none");
        }
        $addPartEdit.removeAttr('add-part-edit');
        if ($addPartEdit.length != 0) {
            $deleteNode = undefined;
            $addPartEdit = $addPartEdit.next();
            while (true) {
                console.log($addPartEdit.html());
                if ($addPartEdit.hasClass('part-value') || $addPartEdit.attr("add-question-button-edit") != undefined) {
                    break;
                } else {
                    $deleteNode = $addPartEdit;
                    $addPartEdit = $addPartEdit.next();
                    $deleteNode.remove();
                }
            }
        } else {
            $editConten.empty();
        }
    }
 
    function setTitleAttr($questionContent) {
        if ($questionContent.children('[name="template"]').val() == "intelligence_title") {
            $questionContent.attr("add-intelligence-title", "true");
            $questionContent.append('<p style="text-align:right;" class="add-part add-question-click"><a href="#" onclick="deleteTitleAndTheQuestion(this)" style="color:red">删除</a></p>');
        }
    }
 
    function deleteTitleOrTitleQuestion() {
        // 删除问答题或者删除问答题下面的题目,属性在add-question-now-title在add-intelligence添加
        $parent.$('[delete-question="true"]').remove();
        $parent.$('[add-question-now-title="true"]').remove();
    }
 
    // add-question
    function submitHandler() {
        var $tableSelect = $.btTable.bootstrapTable('getSelections');
        var template = [[${template}]];
        if (isVerify(template, $tableSelect)) {
            $.modal.alertWarning([[#{jsp.exam.product.selectIntelliAlert}]]);
            return;
        }
 
        // job选择维度
        if ($('#questionTemplateId').val() != "" && $('#questionTemplateId').val() != undefined) {
            $editConten = $parent.$('#headline').find('.ibox');
            if ($('#questionTemplateId').val() != "job_batch") {
                $editConten.each(function (i) {
                    jobSubmit($tableSelect, $(this));
                });
                $.modal.closeTab();
                return;
            }
        }
 
        var $editConten = $parent.$('[add-question-edit="true"]');
        $editConten.removeAttrs('add-question-edit');
        $addPartEdit = $parent.$('[add-part-edit="true"]');
 
        // 删除每一个分片的题目
        if (isTitle(template) || isIntelligenceQuestion(template)) {
            deleteTitleOrTitleQuestion();
        } else {
            delteQuetion($editConten, $addPartEdit);
        }
 
 
        // 题目设置的那个按钮
        $addQButtonEdit = $parent.$('[add-question-button-edit="true"]');
        $addQButtonEdit.removeAttr('add-question-button-edit');
 
        $.each($tableSelect, function (index, obj) {
            if (!obj.checked) {// if do not checked
 
                // 判断是否已经选过了
                var flag = true;
                if ($('#questionTemplateId').val() != "job_batch") {
                    $parent.$('#headline').find('[name="questionId"]').each(function () {
                        if ($(this).val() == obj.id) {
                            flag = false;
                        }
                    });
                }
                flag = true; // 可以重复添加
                // 盒子里面有了就不用添加了
                if (flag) {
                    var $questionContent = $parent.$('#questionSelect').clone();// 问题的展示
 
                    // 题目题干
                    setQuestionTitle($questionContent, obj);
                    setTitleAttr($questionContent);// add-intelligence-title
 
                    // 智力题的题目不需要选贤
                    if (!isTitle(template)) {
                        // 选项1,2,3,4
                        selectItem(obj, $questionContent);
                    } else {
                        // 删除子选项
                        $questionContent.remove('ul');
                    }
 
                    if ($addPartEdit.length != 0) {
                        $addQButtonEdit.before($questionContent);
                        setParentQuestionId($questionContent);
                    } else {
                        $editConten.append($questionContent);
                    }
                }
 
            }
        });
 
        // 给题目编号
        setNumber($editConten);
 
        $.modal.closeTab();
    }
</script>
</body>
</html>