懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 layui.use(['table', 'admin', 'ax', 'func'], function () {
2     var $ = layui.$;
3     var table = layui.table;
4     var $ax = layui.ax;
5     var admin = layui.admin;
6     var func = layui.func;
7
8     /**
9      * 编码规则管理
10      */
11     var CodingRule = {
12         tableId: "codingRuleTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     CodingRule.initColumn = function () {
19         return [[
20             {type: 'checkbox'},
21             {field: 'id', hide: true, title: '主键id'},
22             {field: 'codingRuleCode', sort: true, title: '规则编号',width:138},
23             {field: 'codingRuleDesc', sort: true, title: '规则描述',width:138},
24             {field: 'codingRulePrefix', sort: true, title: '规则前缀',width:138},
25             {field: 'enableDate', sort: true, title: '启用日期',width:120,templet: '#enableDateTpl'},
26             {field: 'dateType', sort: true, title: '日期格式',width:160},
27             {field: 'currentCode', sort: true, title: '当前编号',width:220},
28             {field: 'codeLength', sort: true, title: '编号长度',width:120},
29             {field: 'remark', sort: true, title: '备注'},
30             {field: 'createUser', sort: true, title: '创建用户',width:120},
31             {field: 'createTime', sort: true, title: '创建时间',width:160},
32             {field: 'updateUser', sort: true, title: '更改用户',width:120},
33             {field: 'updateTime', sort: true, title: '更改时间',width:160},
34             {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
35         ]];
36     };
37
38     /**
39      * 点击查询按钮
40      */
41     CodingRule.search = function () {
42         var queryData = {};
43
44         queryData['codingRuleCode'] = $('#codingRuleCode').val();
45         queryData['codingRuleDesc'] = $('#codingRuleDesc').val();
46         queryData['codingRulePrefix'] = $('#codingRulePrefix').val();
47         queryData['enableDate'] = $('#enableDate').val();
48
49         table.reload(CodingRule.tableId, {
50             where: queryData, page: {curr: 1}
51         });
52     };
53
54     /**
55      * 跳转到添加页面
56      */
57     CodingRule.jumpAddPage = function () {
58         window.location.href = Feng.ctxPath + '/codingRule/add'
59     };
60
61     /**
62     * 跳转到编辑页面
63     *
64     * @param data 点击按钮时候的行数据
65     */
66     CodingRule.jumpEditPage = function (data) {
67         window.location.href = Feng.ctxPath + '/codingRule/edit?id=' + data.id
68     };
69
70     /**
71      * 导出excel按钮
72      */
73     CodingRule.exportExcel = function () {
74         var checkRows = table.checkStatus(CodingRule.tableId);
75         if (checkRows.data.length === 0) {
76             Feng.error("请选择要导出的数据");
77         } else {
78             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
79         }
80     };
81
82     /**
83      * 点击删除
84      *
85      * @param data 点击按钮时候的行数据
86      */
87     CodingRule.onDeleteItem = function (data) {
88         var operation = function () {
89             var ajax = new $ax(Feng.ctxPath + "/codingRule/delete", function (data) {
90                 Feng.success("删除成功!");
91                 table.reload(CodingRule.tableId);
92             }, function (data) {
93                 Feng.error("删除失败!" + data.responseJSON.message + "!");
94             });
95             ajax.set("id", data.id);
96             ajax.start();
97         };
98         Feng.confirm("是否删除?", operation);
99     };
100
101     // 渲染表格
102     var tableResult = table.render({
103         elem: '#' + CodingRule.tableId,
104         url: Feng.ctxPath + '/codingRule/list',
105         page: true,
106         height: "full-158",
107         cellMinWidth: 100,
108         cols: CodingRule.initColumn()
109     });
110
111     // 搜索按钮点击事件
112     $('#btnSearch').click(function () {
113         CodingRule.search();
114     });
115
116     // 添加按钮点击事件
117     $('#btnAdd').click(function () {
118
119     CodingRule.jumpAddPage();
120
121     });
122
123     // 导出excel
124     $('#btnExp').click(function () {
125         CodingRule.exportExcel();
126     });
127
128     // 工具条点击事件
129     table.on('tool(' + CodingRule.tableId + ')', function (obj) {
130         var data = obj.data;
131         var layEvent = obj.event;
132
133         if (layEvent === 'edit') {
134             CodingRule.jumpEditPage(data);
135         } else if (layEvent === 'delete') {
136             CodingRule.onDeleteItem(data);
137         }
138     });
139 });