Administrator
2025-08-01 600ea96a245bd5522c489fafc4993cafa0ce36db
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
<div class="layui-fluid layui-anim febs-anim" id="febs-product" 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="product-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-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="productTable" lay-data="{id: 'productTable'}"></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="productToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productList:add" lay-event="productAdd">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="productList:pointSet" lay-event="pointSet">知识点配置</button>
    </div>
</script>
 
<script type="text/html" id="productOption">
    <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="productList:info" lay-event="productInfoEvent">编辑</button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="productList:info" lay-event="productDeleteEvent">删除</button>
</script>
 
 
<script type="text/html" id="productStateSwitch">
    {{# if(d.state === 1) { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" checked lay-skin="switch" lay-filter="productStateSwitch">
    {{# } else { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" lay-skin="switch" lay-filter="productStateSwitch">
    {{# } }}
</script>
 
 
<script type="text/html" id="productHotStateSwitch">
    {{# if(d.hotState === 1) { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" checked lay-skin="switch" lay-filter="productHotStateSwitch">
    {{# } else { }}
    <input type="checkbox" value={{d.id}} lay-text="启用|禁用" lay-skin="switch" lay-filter="productHotStateSwitch">
    {{# } }}
</script>
 
<style>
    .layui-form-onswitch {
        background-color: #5FB878 !important;
    }
</style>
<!-- 表格操作栏 end -->
<script data-th-inline="none" type="text/javascript">
    // 引入组件并初始化
    layui.use(['febs', 'form', 'formSelects', 'validate', 'treeSelect', 'eleTree','dropdown', 'laydate', 'layedit', 'upload', 'element', 'table', 'xmSelect','jquery'], function () {
        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-product'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'orderNum', type: null},
            tableIns;
 
        form.render();
 
        var category = xmSelect.render({
            el: '#product-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) {
            category.update({
                data : res.data,
                autoRow: true,
            });
        })
 
        // 表格初始化
        setTimeout(() => {
            initproductTable();
        }, 500);
 
        // 初始化表格操作栏各个按钮功能
        table.on('tool(productTable)', function (obj) {
            console.log("触发事件:", obj.event); // 调试信息
            var data = obj.data,
                layEvent = obj.event;
 
            if (layEvent === 'seeImage') {
                var t = $view.find('#seeImage'+data.id+'');
                //页面层
                layer.open({
                    type: 1,
                    title: "小图标",
                    skin: 'layui-layer-rim', //加上边框
                    area: ['100%', '100%'], //宽高
                    shadeClose: true, //开启遮罩关闭
                    end: function (index, layero) {
                        return false;
                    },
                    content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
                });
            }
 
            if (layEvent === 'seeBackImage') {
                var t = $view.find('#seeBackImage'+data.id+'');
                //页面层
                layer.open({
                    type: 1,
                    title: "背景图片",
                    skin: 'layui-layer-rim', //加上边框
                    area: ['100%', '100%'], //宽高
                    shadeClose: true, //开启遮罩关闭
                    end: function (index, layero) {
                        return false;
                    },
                    content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
                });
            }
 
            if (layEvent === 'productInfoEvent') {
                if (data.state == 1){
                    febs.alert.warn('请先禁用这行数据');
                    return;
                }
                febs.modal.open('编辑','modules/ai/product/info/' + data.id, {
                    btn: ['提交', '取消'],
                    area: ['100%', '100%'],
                    yes: function (index, layero) {
                        $('#febs-product-Info').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
 
            if (layEvent === 'productDeleteEvent') {
                if (data.state == 1){
                    febs.alert.warn('请先禁用这行数据');
                    return;
                }
                febs.modal.confirm('删除', '确认删除?', function () {
                    productDeleteEvent(data.id);
                });
            }
        });
 
        form.on('switch(productStateSwitch)', function (data) {
            if (data.elem.checked) {
                productSwitch(data.value,1,1);
            } else {
                productSwitch(data.value,1,0);
            }
        })
        form.on('switch(productHotStateSwitch)', function (data) {
            if (data.elem.checked) {
                productSwitch(data.value,2,1);
            } else {
                productSwitch(data.value,2,0);
            }
        })
        function productSwitch(id,type,state) {
            febs.get(ctx + 'admin/product/changeState/' + id+'/'+ type+'/' + state, null, function (data) {
                febs.alert.success(data.message);
                $query.click();
            });
        }
 
        function productDeleteEvent(id) {
            febs.get(ctx + 'admin/product/delete/' + id, null, function (data) {
                febs.alert.success(data.message);
                $query.click();
            });
        }
 
        // 初始化表格操作栏各个按钮功能
        table.on('toolbar(productTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if(layEvent === 'productAdd'){
                febs.modal.open('新增', 'modules/ai/product/add/', {
                    btn: ['提交', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#febs-product-add').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
 
            if (layEvent === 'pointSet') {
                var checkData = table.checkStatus('productTable').data;
                if (checkData.length > 1 || checkData.length === 0) {
                    febs.alert.warn('每次操作只能操作一行数据');
                    return;
                }
                febs.modal.open('知识点配置', 'modules/ai/product/pointSet/' + checkData[0].id, {
                    btn: ['提交', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#point-set').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });
 
        function initproductTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'productTable',
                url: ctx + 'admin/product/list',
                toolbar:"#productToolbar",
                defaultToolbar:[],
                cols: [[
                    {type: 'checkbox'},
                    {type: 'numbers', title: '', width: 80},
                    {title: '操作', toolbar: '#productOption', minWidth: 200, align: 'center'},
                    {field: 'hotState', title: '推荐首页', templet: '#productHotStateSwitch', minWidth: 130,align:'center'},
                    {field: 'state', title: '状态', templet: '#productStateSwitch', minWidth: 130,align:'center'},
                    {field: 'productCategoryName', title: '产品分类', minWidth: 100,align:'center'},
                    {field: 'sort', title: '排序', minWidth: 100,align:'center'},
                    {field: 'code', title: '编码', minWidth: 100,align:'center'},
                    {field: 'name', title: '名称', minWidth: 100,align:'center'},
                    {field: 'iconImg',title: '小图标',
                        templet: function (d) {
                            return '<a lay-event="seeImage">' +
                                '<img id="seeImage' + d.id + '" src="' + d.iconImg +
                                '" alt="小图标" style="width: 50px; height: 50px; object-fit: cover; border-radius: 5px; cursor: pointer;">' +
                                '</a>';
                        },
                    minWidth: 150,align: 'center'},
                    {field: 'backImg',title: '背景图',
                        templet: function (d) {
                            return '<a lay-event="seeBackImage">' +
                                '<img id="seeBackImage' + d.id + '" src="' + d.backImg +
                                '" alt="小图标" style="width: 50px; height: 50px; object-fit: cover; border-radius: 5px; cursor: pointer;">' +
                                '</a>';
                        },
                    minWidth: 150,align: 'center'},
                    {field: 'companyId', title: '公司编码', minWidth: 150,align:'center'},
                ]]
            });
        }
 
 
        // 查询按钮
        $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 = [];
            category.setValue(categoryList);
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
        // 获取查询参数
        function getQueryParams() {
            return {
                productCategoryId: category.getValue('valueStr'),
            };
        }
 
    })
</script>