Administrator
2026-02-12 b59514011cde1377ccb2cf3ca96cd7673efc874d
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<div class="layui-fluid layui-anim febs-anim" id="febs-productQuestion" lay-title="产品题库">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="productQuestion-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-row layui-col-space6 layui-form-item">
                                    <div class="layui-col-lg3">
                                        <label class="layui-form-label">产品分类:</label>
                                        <div class="layui-input-block">
                                            <div id="product-qutestion-category-query"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="productQuestionTable" lay-data="{id: 'productQuestionTable'}"></table>
 
                    <style type="text/css">
                        .layui-table-cell{
                            text-align:center;
                            height: auto;
                            white-space: nowrap; /*文本不会换行,在同一行显示*/
                            overflow: hidden; /*超出隐藏*/
                            text-overflow: ellipsis; /*省略号显示*/
                        }
                        .layui-table img{
                            max-width:100px
                        }
                        ::-webkit-scrollbar {
                            height: 20px !important;
                            background-color: #f4f4f4;
                        }
                    </style>
                </div>
            </div>
        </div>
    </div>
</div>
 
<script type="text/html" id="productQuestionToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:add" lay-event="productQuestionAdd">手动新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:aiAdd" lay-event="productQuestionAiAdd">AI新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:aiAdd" lay-event="productQuestionStateOpen">启用</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:aiAdd" lay-event="productQuestionStateClose">禁用</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:aiAdd" lay-event="productQuestionDelete">删除</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productQuestionList:aiAdd" lay-event="productQuestionAddLabel">打标签</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" shiro:hasPermission="productQuestionList:aiAdd"  lay-event="exportProductQuestion">导出(审核)</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" shiro:hasPermission="productQuestionList:aiAdd" id="importProductQuestion"  lay-event="importProductQuestion">导入(审核)</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" shiro:hasPermission="productQuestionList:aiAdd"  lay-event="exportNewProductQuestion">模板导出(新增)</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" shiro:hasPermission="productQuestionList:aiAdd" id="importNewProductQuestion"  lay-event="importNewProductQuestion">模板导入(新增)</button>
    </div>
</script>
 
<script type="text/html" id="productQuestionOption">
    <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="productQuestionList:info" lay-event="productQuestionInfoEvent">编辑</button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="productQuestionList:info" lay-event="productQuestionDeleteEvent">删除</button>
</script>
 
 
<script type="text/html" id="productQuestionStateSwitch">
    {{# if(d.state === 1) { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" checked lay-skin="switch" lay-filter="productQuestionStateSwitch">
    {{# } else { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" lay-skin="switch" lay-filter="productQuestionStateSwitch">
    {{# } }}
</script>
 
<script type="text/html" id="difficultyFormat">
    {{# if(d.difficulty == 1) { }}
    <span>简单</span>
    {{# }else if(d.difficulty == 2) { }}
    <span>中等</span>
    {{# }else if(d.difficulty == 3) { }}
    <span>困难</span>
    {{# } else { }}
    <span>-</span>
    {{# } }}
</script>
 
<style>
    .layui-form-onswitch {
        background-color: #5FB878 !important;
    }
</style>
<!-- 表格操作栏 end -->
<script data-th-inline="none" type="text/javascript">
    // 引入组件并初始化
    layui.use([ 'jquery', 'form', 'table', 'febs', 'xmSelect', 'upload'], function () {
        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            upload = layui.upload,
            $view = $('#febs-productQuestion'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'orderNum', type: null},
            tableIns;
 
        form.render();
 
        var categoryQuestion = xmSelect.render({
            el: '#product-qutestion-category-query',
            language: 'zn',
            prop : {
                value : 'id',
                children : 'child'
            },
            iconfont: {
                parent: 'hidden',
            },
            tips: '请选择',
            filterable: true,
            radio: true,
            clickClose: true,
            tree: {
                show: true,
                //非严格模式
                strict: false,
            },
            data: []
        })
 
        febs.get(ctx + 'admin/productCategory/categoryTree', null, function(res) {
            categoryQuestion.update({
                data : res.data,
                autoRow: true,
            });
        })
 
        // 表格初始化
        initProductQuestionTable();
 
        // 初始化表格操作栏各个按钮功能
        table.on('tool(productQuestionTable)', function (obj) {
            console.log("触发事件:", obj.event); // 调试信息
            var data = obj.data,
                layEvent = obj.event;
 
            if (layEvent === 'productQuestionInfoEvent') {
                if (data.state == 1){
                    febs.alert.warn('请先禁用这行数据');
                    return;
                }
                febs.modal.open('编辑','modules/ai/productQuestion/info/' + data.id, {
                    btn: ['提交', '取消'],
                    area: ['100%', '100%'],
                    yes: function (index, layero) {
                        $('#febs-productQuestion-Info').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
 
            if (layEvent === 'productQuestionDeleteEvent') {
                if (data.state == 1){
                    febs.alert.warn('请先禁用这行数据');
                    return;
                }
                febs.modal.confirm('删除', '确认删除?', function () {
                    productQuestionDeleteEvent(data.id);
                });
            }
        });
 
        function productQuestionDeleteEvent(id) {
            febs.get(ctx + 'admin/productQuestion/delete/' + id, null, function (data) {
                febs.alert.success(data.message);
                $query.click();
            });
        }
 
        // 初始化表格操作栏各个按钮功能
        table.on('toolbar(productQuestionTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if(layEvent === 'productQuestionAdd'){
                febs.modal.open('新增', 'modules/ai/productQuestion/add/', {
                    btn: ['提交', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#febs-productQuestion-add').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
            if(layEvent === 'productQuestionAiAdd'){
                febs.modal.open('新增', 'modules/ai/productQuestion/aiAdd/', {
                    btn: ['提交', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#febs-productQuestion-ai-add').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
            if (layEvent === 'productQuestionStateOpen') {
                var checkData = table.checkStatus('productQuestionTable').data;
                if (checkData.length <= 0) {
                    febs.alert.warn('请选择');
                    return;
                }
                febs.modal.confirm('状态', '启用?', function () {
                    var ids = [];
                    layui.each(checkData, function (key, item) {
                        ids.push(item.id)
                    });
                    productQuestionStateUpdate(ids.join(','), 1);
                });
            }
            if (layEvent === 'productQuestionStateClose') {
 
                var checkData = table.checkStatus('productQuestionTable').data;
                if (checkData.length <= 0) {
                    febs.alert.warn('请选择');
                    return;
                }
                febs.modal.confirm('状态', '禁用?', function () {
                    var ids = [];
                    layui.each(checkData, function (key, item) {
                        ids.push(item.id)
                    });
                    productQuestionStateUpdate(ids.join(','), 0);
                });
            }
            if (layEvent === 'productQuestionDelete') {
 
                var checkData = table.checkStatus('productQuestionTable').data;
                if (checkData.length <= 0) {
                    febs.alert.warn('请选择');
                    return;
                }
                febs.modal.confirm('删除', '确定?', function () {
                    var ids = [];
                    layui.each(checkData, function (key, item) {
                        ids.push(item.id)
                    });
                    productQuestionDelete(ids.join(','));
                });
            }
            if (layEvent == 'exportProductQuestion') {
                var checkData = table.checkStatus('productQuestionTable').data;
                if (checkData.length <= 0) {
                    febs.alert.warn('请选择');
                    return;
                }
                var ids = [];
                layui.each(checkData, function (key, item) {
                    ids.push(item.id)
                });
                window.location.href = ctx + "admin/productQuestion/exportProductQuestion?ids="+ids;
            }
            if (layEvent === 'productQuestionAddLabel') {
                var checkData = table.checkStatus('productQuestionTable').data;
                if (checkData.length <= 0) {
                    febs.alert.warn('请选择');
                    return;
                }
                var ids = [];
                layui.each(checkData, function (key, item) {
                    ids.push(item.id)
                });
                let strIds = ids.join(',');
                febs.modal.open('打标签', 'modules/ai/productQuestion/labelSet/' + strIds, {
                    btn: ['确定', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#labelSet').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
 
            if (layEvent == 'exportNewProductQuestion') {
                window.location.href = ctx + "admin/productQuestion/exportNewProductQuestion";
            }
            if (layEvent == 'importNewProductQuestion') {
                layui.use(['layer', 'upload', 'form', 'xmSelect'], function(){
                    var layer = layui.layer;
                    var upload = layui.upload;
                    var form = layui.form;
 
                    // 在外层定义变量,使其在多个函数中可访问
                    var selectedCategoryId = '';
                    var selectedDifficulty = '2'; // 默认选择中等难度
                    var selectedFile = null;
 
                    // 使用 layer.open 替代 febs.modal.open
                    layer.open({
                        title: '模板导入(新增)',
                        type: 1,
                        area: ['500px', '400px'], // 增加高度以适应新选项
                        btn: ['开始导入', '取消'],
                        content: '<div style="padding: 20px;">' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">选择分类</label>' +
                            '<div class="layui-input-block">' +
                            '<div id="importCategorySelect"></div>' +
                            '</div>' +
                            '</div>' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">难易程度</label>' +
                            '<div class="layui-input-block">' +
                            '<select id="importDifficultySelect" lay-filter="difficulty">' +
                            '<option value="1">简单</option>' +
                            '<option value="2" selected>中等</option>' +
                            '<option value="3">困难</option>' +
                            '</select>' +
                            '</div>' +
                            '</div>' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">上传文件</label>' +
                            '<div class="layui-input-block">' +
                            '<button type="button" class="layui-btn" id="importFileBtn">' +
                            '<i class="layui-icon">&#xe67c;</i>选择文件' +
                            '</button>' +
                            '<div id="fileInfo" style="margin-top: 10px; color: #666;"></div>' +
                            '</div>' +
                            '</div>' +
                            '</div>',
                        success: function(layero, index) {
                            // 确保 xmSelect 已加载
                            if (typeof xmSelect === 'undefined') {
                                layer.msg('xmSelect 组件未加载');
                                return;
                            }
 
                            // 初始化分类选择器
                            var importCategory = xmSelect.render({
                                el: '#importCategorySelect',
                                language: 'zn',
                                prop: {
                                    name: 'name',
                                    value: 'id',
                                    children: 'child'
                                },
                                tips: '请选择分类',
                                filterable: true,
                                radio: true,
                                clickClose: true,
                                tree: {
                                    show: true,
                                    strict: false,
                                },
                                data: [],
                                on: function(data) {
                                    console.log('xmSelect 选择数据:', data); // 调试用
                                    // 监听分类选择变化
                                    if (data.arr && data.arr.length > 0) {
                                        // 尝试不同的属性名
                                        selectedCategoryId = data.arr[0].value || data.arr[0].id || data.arr[0].val;
                                        console.log('选择的分类ID:', selectedCategoryId); // 调试用
                                    } else {
                                        selectedCategoryId = '';
                                    }
                                }
                            });
 
                            // 获取分类列表
                            $.ajax({
                                url: ctx + 'admin/productCategory/categoryTree',
                                type: 'GET',
                                success: function(res) {
                                    console.log('分类数据:', res); // 调试用
                                    if (res.code === 200) {
                                        importCategory.update({ data: res.data });
                                    }
                                }
                            });
 
                            // 初始化难易程度下拉框
                            form.render('select', 'importDifficultySelect');
 
                            // 监听难易程度选择变化
                            form.on('select(difficulty)', function(data){
                                selectedDifficulty = data.value;
                                console.log('选择的难易程度:', selectedDifficulty);
                            });
 
                            // 初始化文件选择(不上传)
                            $('#importFileBtn').click(function() {
                                // 创建隐藏的文件输入
                                var fileInput = $('<input type="file" style="display:none">');
                                $('body').append(fileInput);
 
                                fileInput.click();
 
                                fileInput.on('change', function() {
                                    var file = this.files[0];
                                    if (file) {
                                        selectedFile = file;
                                        $('#fileInfo').html('<span style="color:#666">已选择文件: ' + file.name + '</span>');
                                    }
                                    fileInput.remove();
                                });
                            });
                        },
                        yes: function(index, layero) {
                            console.log('开始导入,selectedCategoryId:', selectedCategoryId); // 调试用
                            console.log('开始导入,selectedDifficulty:', selectedDifficulty); // 调试用
                            console.log('开始导入,selectedFile:', selectedFile); // 调试用
 
                            // 点击"开始导入"按钮
                            if (!selectedCategoryId) {
                                layer.msg('请先选择分类', { icon: 2 });
                                return false;
                            }
 
                            if (!selectedFile) {
                                layer.msg('请先选择文件', { icon: 2 });
                                return false;
                            }
 
                            // 创建 FormData
                            var formData = new FormData();
                            formData.append('file', selectedFile);
 
                            // 显示加载中
                            var loadingIndex = layer.load(1);
 
                            // 使用 AJAX 上传文件,同时传递难易程度参数
                            $.ajax({
                                url: ctx + 'admin/productQuestion/importNewProductQuestion?categoryId=' + selectedCategoryId + '&difficulty=' + selectedDifficulty,
                                type: 'POST',
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function(res) {
                                    layer.close(loadingIndex);
                                    if (res.code === 200) {
                                        layer.msg('导入成功', { icon: 1 });
                                        layer.close(index);
                                        // 刷新表格
                                        if (typeof $query !== 'undefined') {
                                            $query.click();
                                        }
                                    } else {
                                        layer.msg(res.msg || '导入失败', { icon: 2 });
                                    }
                                },
                                error: function() {
                                    layer.close(loadingIndex);
                                    layer.msg('上传失败', { icon: 2 });
                                }
                            });
                        }
                    });
                });
            }
        });
 
        upload.render({
            elem: '#importProductQuestion'
            ,url: 'admin/productQuestion/importProductQuestion' //此处配置你自己的上传接口即可
            ,accept: 'file' //普通文件
            ,done: function(res){
                console.log("123");
                febs.alert.success('操作成功');
                $query.click();
            }
        });
 
 
 
        function productQuestionStateUpdate(ids, type) {
            febs.post(ctx + 'admin/productQuestion/stateUpdate/' + type + "/"+ ids, null, function () {
                febs.alert.success('操作成功');
            });
        }
 
 
 
        function productQuestionDelete(ids) {
            febs.post(ctx + 'admin/productQuestion/productQuestionDelete/'+ ids, null, function () {
                febs.alert.success('操作成功');
            });
        }
 
        function initProductQuestionTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'productQuestionTable',
                url: ctx + 'admin/productQuestion/list',
                toolbar:"#productQuestionToolbar",
                defaultToolbar:[],
                cols: [[
                    {type: 'checkbox'},
                    {type: 'numbers', title: '', width: 80},
                    {title: '操作', toolbar: '#productQuestionOption', minWidth: 200, align: 'center'},
                    {field: 'state', title: '状态', templet: '#productQuestionStateSwitch', minWidth: 130,align:'center'},
                    {field: 'productCategoryName', title: '分类', minWidth: 100,align:'center'},
                    {field: 'title', title: '题目', minWidth: 100,align:'center'},
                    {field: 'label', title: '标签', minWidth: 100,align:'center'},
                    {templet:"#difficultyFormat",  title: '难度', minWidth: 140,align:'center'},
                    {field: 'companyId', title: '公司编码', minWidth: 150,align:'center'},
                ]]
            });
        }
 
        form.on('switch(productQuestionStateSwitch)', function (data) {
            if (data.elem.checked) {
                productSwitch(data.value,1);
            } else {
                productSwitch(data.value,0);
            }
        })
        function productSwitch(id,state) {
            febs.get(ctx + 'admin/productQuestion/changeState/' + id+'/' + state, null, function (data) {
                febs.alert.success(data.message);
                // $query.click();
            });
        }
 
 
        // 查询按钮
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
 
        // 刷新按钮
        $reset.on('click', function () {
 
            var categoryList = [];
            categoryQuestion.setValue(categoryList);
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: null, page: {curr: 1}, initSort: sortObject});
        });
        // 获取查询参数
        function getQueryParams() {
            return {
                productCategoryId: categoryQuestion.getValue('valueStr'),
            };
        }
 
    })
</script>