yantian yue
2023-10-18 69fbaaa1a5fd16b05953e750ea7fcc3e18e3a27c
提交 | 用户 | 时间
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      * excel导出配置管理
10      */
11     var ExcelExportDeploy = {
12         tableId: "excelExportDeployTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     ExcelExportDeploy.initColumn = function () {
19         return [[
20             {field: 'id', hide: true, title: ''},
21             {field: 'name', sort: true, title: 'excel导出配置名称'},
22             {field: 'title', sort: true, title: '文件名称'},
23             {field: 'nid', sort: true, title: '唯一标识'},
24             {templet: '#template', sort: true, title: '模版文件'},
25             {templet: '#showUrl', sort: true, title: '数据查询'},
26             {templet: '#exportUrl', sort: true, title: '导出链接'},
27             {field: 'statusName', sort: true, title: '状态'},
28             {align: 'center', toolbar: '#tableBar', title: '操作'}
29         ]];
30     };
31
32     /**
33      * 点击查询按钮
34      */
35     ExcelExportDeploy.search = function () {
36         var queryData = {};
37         queryData['condition'] = $("#condition").val();
38         table.reload(ExcelExportDeploy.tableId, {
39             where: queryData, page: {curr: 1}
40         });
41     };
42
43     /**
44      * 弹出添加对话框
45      */
46     ExcelExportDeploy.openAddDlg = function () {
47         func.open({
48             title: '添加excel导出配置',
49             content: Feng.ctxPath + '/excelExportDeploy/add',
50             tableId: ExcelExportDeploy.tableId
51         });
52     };
53
54     /**
55     * 点击编辑
56     *
57     * @param data 点击按钮时候的行数据
58     */
59     ExcelExportDeploy.openEditDlg = function (data) {
60         func.open({
61             title: '修改excel导出配置',
62             content: Feng.ctxPath + '/excelExportDeploy/edit?id=' + data.id,
63             tableId: ExcelExportDeploy.tableId
64         });
65     };
66
67     /**
68      * 导出excel按钮
69      */
70     ExcelExportDeploy.exportExcel = function () {
71         var checkRows = table.checkStatus(ExcelExportDeploy.tableId);
72         if (checkRows.data.length === 0) {
73             Feng.error("请选择要导出的数据");
74         } else {
75             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
76         }
77     };
78
79     /**
80      * 点击删除
81      *
82      * @param data 点击按钮时候的行数据
83      */
84     ExcelExportDeploy.onDeleteItem = function (data) {
85         var operation = function () {
86             var ajax = new $ax(Feng.ctxPath + "/excelExportDeploy/delete", function (data) {
87                 Feng.success("删除成功!");
88                 table.reload(ExcelExportDeploy.tableId);
89             }, function (data) {
90                 Feng.error("删除失败!" + data.responseJSON.message + "!");
91             });
92             ajax.set("id", data.id);
93             ajax.start();
94         };
95         Feng.confirm("是否删除?", operation);
96     };
97
98     // 渲染表格
99     var tableResult = table.render({
100         elem: '#' + ExcelExportDeploy.tableId,
101         url: Feng.ctxPath + '/excelExportDeploy/list',
102         page: true,
103         height: "full-158",
104         cellMinWidth: 100,
105         cols: ExcelExportDeploy.initColumn()
106     });
107
108     // 搜索按钮点击事件
109     $('#btnSearch').click(function () {
110         ExcelExportDeploy.search();
111     });
112
113     // 添加按钮点击事件
114     $('#btnAdd').click(function () {
115         ExcelExportDeploy.openAddDlg();
116     });
117
118     // 导出excel
119     $('#btnExp').click(function () {
120         ExcelExportDeploy.exportExcel();
121     });
122
123     // 工具条点击事件
124     table.on('tool(' + ExcelExportDeploy.tableId + ')', function (obj) {
125         var data = obj.data;
126         var layEvent = obj.event;
127
128         if (layEvent === 'edit') {
129             ExcelExportDeploy.openEditDlg(data);
130         } else if (layEvent === 'delete') {
131             ExcelExportDeploy.onDeleteItem(data);
132         }
133     });
134 });