懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 layui.use(['table', 'admin', 'ax'], function () {
2     var $ = layui.$;
3     var table = layui.table;
4     var $ax = layui.ax;
5     var admin = layui.admin;
6
7     /**
8      * 参数配置管理
9      */
10     var SysConfig = {
11         tableId: "sysConfigTable"
12     };
13
14     /**
15      * 初始化表格的列
16      */
17     SysConfig.initColumn = function () {
18         return [[
19             {type: 'checkbox'},
20             {field: 'id', hide: true, title: '主键'},
21             {field: 'name', sort: true, align: "center", title: '名称'},
22             {field: 'code', sort: true, align: "center", title: '属性编码'},
23             {field: 'value', sort: true, align: "center", title: '属性值'},
24             {field: 'remark', sort: true, align: "center", title: '备注'},
25             {field: 'createTime', sort: true, align: "center", title: '创建时间'},
26             {field: 'updateTime', sort: true, align: "center", title: '更新时间'},
27             {align: 'center', toolbar: '#tableBar', title: '操作'}
28         ]];
29     };
30
31     /**
32      * 点击查询按钮
33      */
34     SysConfig.search = function () {
35         var queryData = {};
36         queryData['condition'] = $("#condition").val();
37         table.reload(SysConfig.tableId, {
38             where: queryData, page: {curr: 1}
39         });
40     };
41
42     /**
43      * 弹出添加对话框
44      */
45     SysConfig.openAddDlg = function () {
46         window.location.href = Feng.ctxPath + '/sysConfig/add';
47     };
48
49     /**
50      * 导出excel按钮
51      */
52     SysConfig.exportExcel = function () {
53         var checkRows = table.checkStatus(SysConfig.tableId);
54         if (checkRows.data.length === 0) {
55             Feng.error("请选择要导出的数据");
56         } else {
57             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
58         }
59     };
60
61     /**
62      * 点击编辑
63      *
64      * @param data 点击按钮时候的行数据
65      */
66     SysConfig.openEditDlg = function (data) {
67         window.location.href = Feng.ctxPath + '/sysConfig/edit?id=' + data.id;
68     };
69
70     /**
71      * 点击删除
72      *
73      * @param data 点击按钮时候的行数据
74      */
75     SysConfig.onDeleteItem = function (data) {
76         var operation = function () {
77             var ajax = new $ax(Feng.ctxPath + "/sysConfig/delete", function (data) {
78                 Feng.success("删除成功!");
79                 table.reload(SysConfig.tableId);
80             }, function (data) {
81                 Feng.error("删除失败!" + data.responseJSON.message + "!");
82             });
83             ajax.set("id", data.id);
84             ajax.start();
85         };
86         Feng.confirm("是否删除?", operation);
87     };
88
89     // 渲染表格
90     var tableResult = table.render({
91         elem: '#' + SysConfig.tableId,
92         url: Feng.ctxPath + '/sysConfig/list',
93         page: true,
94         height: "full-158",
95         cellMinWidth: 100,
96         cols: SysConfig.initColumn()
97     });
98
99     // 搜索按钮点击事件
100     $('#btnSearch').click(function () {
101         SysConfig.search();
102     });
103
104     // 添加按钮点击事件
105     $('#btnAdd').click(function () {
106         SysConfig.openAddDlg();
107     });
108
109     // 导出excel
110     $('#btnExp').click(function () {
111         SysConfig.exportExcel();
112     });
113
114     // 工具条点击事件
115     table.on('tool(' + SysConfig.tableId + ')', function (obj) {
116         var data = obj.data;
117         var layEvent = obj.event;
118
119         if (layEvent === 'edit') {
120             SysConfig.openEditDlg(data);
121         } else if (layEvent === 'delete') {
122             SysConfig.onDeleteItem(data);
123         }
124     });
125 });