提交 | 用户 | 时间
|
1ac2bc
|
1 |
layui.use(['table', 'admin', 'ax', 'func', 'form'], 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 |
var form = layui.form; |
|
8 |
|
|
9 |
/** |
|
10 |
* 管理 |
|
11 |
*/ |
|
12 |
var Myleave = { |
|
13 |
tableId: "myLeaveTable" |
|
14 |
}; |
|
15 |
|
|
16 |
/** |
|
17 |
* 初始化表格的列 |
|
18 |
*/ |
|
19 |
Myleave.initColumn = function () { |
|
20 |
return [[ |
|
21 |
{type: 'checkbox'}, |
|
22 |
{field: 'myleaveId', hide: true, title: ''}, |
|
23 |
{field: 'username', sort: true, title: '用户名'}, |
|
24 |
{field: 'type', sort: true, title: '类型'}, |
|
25 |
{field: 'starttime', sort: true, title: '开始时间'}, |
|
26 |
{field: 'endtime', sort: true, title: '结束时间'}, |
|
27 |
{field: 'whenlong', sort: true, title: '时长'}, |
|
28 |
{field: 'reason', sort: true, title: '事由'}, |
|
29 |
{align: 'center', toolbar: '#tableBar', title: '操作'} |
|
30 |
]]; |
|
31 |
}; |
|
32 |
|
|
33 |
/** |
|
34 |
* 加载请假类型 |
|
35 |
*/ |
|
36 |
func.initDictSelect("/myleave/getLeaves", "type", "dictName", "dictName"); |
|
37 |
|
|
38 |
/** |
|
39 |
* 点击查询按钮 |
|
40 |
*/ |
|
41 |
Myleave.search = function () { |
|
42 |
var queryData = {}; |
|
43 |
queryData['keywords'] = $("#keywords").val(); |
|
44 |
queryData['type'] = $("#type").val(); |
|
45 |
table.reload(Myleave.tableId, { |
|
46 |
where: queryData, page: {curr: 1} |
|
47 |
}); |
|
48 |
}; |
|
49 |
|
|
50 |
/** |
|
51 |
* 弹出添加对话框 |
|
52 |
*/ |
|
53 |
Myleave.openAddDlg = function () { |
|
54 |
func.open({ |
|
55 |
title: '添加', |
|
56 |
height: 600, |
|
57 |
content: Feng.ctxPath + '/myleave/add', |
|
58 |
tableId: Myleave.tableId |
|
59 |
}); |
|
60 |
}; |
|
61 |
|
|
62 |
/** |
|
63 |
* 点击删除 |
|
64 |
* |
|
65 |
* @param data 点击按钮时候的行数据 |
|
66 |
*/ |
|
67 |
Myleave.onDeleteItem = function (data) { |
|
68 |
var operation = function () { |
|
69 |
var ajax = new $ax(Feng.ctxPath + "/myleave/delete", function (data) { |
|
70 |
Feng.success("删除成功!"); |
|
71 |
table.reload(Myleave.tableId); |
|
72 |
}, function (data) { |
|
73 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
74 |
}); |
|
75 |
ajax.set("myleaveId", data.myleaveId); |
|
76 |
ajax.start(); |
|
77 |
}; |
|
78 |
Feng.confirm("是否删除?", operation); |
|
79 |
}; |
|
80 |
|
|
81 |
// 渲染表格 |
|
82 |
table.render({ |
|
83 |
elem: '#' + Myleave.tableId, |
|
84 |
url: Feng.ctxPath + '/myleave/list', |
|
85 |
page: true, |
|
86 |
height: "full-158", |
|
87 |
cellMinWidth: 100, |
|
88 |
cols: Myleave.initColumn() |
|
89 |
}); |
|
90 |
|
|
91 |
// 搜索按钮点击事件 |
|
92 |
$('#btnSearch').click(function () { |
|
93 |
Myleave.search(); |
|
94 |
}); |
|
95 |
|
|
96 |
// 批量删除点击事件 |
|
97 |
$('#btnBatchDelete').click(function () { |
|
98 |
var operation = function () { |
|
99 |
var idsArray = []; |
|
100 |
var checkStatus = table.checkStatus(Myleave.tableId); |
|
101 |
|
|
102 |
if (checkStatus.data == null || checkStatus.data.length < 1) { |
|
103 |
Feng.error("无选中项"); |
|
104 |
} else { |
|
105 |
for (var i = 0; i < checkStatus.data.length; i++) { |
|
106 |
idsArray.push(checkStatus.data[i].myleaveId); |
|
107 |
} |
|
108 |
$.ajax({ |
|
109 |
url: Feng.ctxPath + "/myleave/batchDelete", |
|
110 |
data: { |
|
111 |
ids: idsArray |
|
112 |
}, |
|
113 |
traditional: true, |
|
114 |
success: function (data) { |
|
115 |
Feng.success("删除成功!"); |
|
116 |
table.reload(Myleave.tableId); |
|
117 |
}, |
|
118 |
error: function (data) { |
|
119 |
Feng.error("获取失败!" + data.responseJSON.message); |
|
120 |
} |
|
121 |
}); |
|
122 |
} |
|
123 |
}; |
|
124 |
Feng.confirm("确认要删除选中项?", operation); |
|
125 |
}); |
|
126 |
|
|
127 |
// 添加按钮点击事件 |
|
128 |
$('#btnAdd').click(function () { |
|
129 |
Myleave.openAddDlg(); |
|
130 |
}); |
|
131 |
|
|
132 |
// 工具条点击事件 |
|
133 |
table.on('tool(' + Myleave.tableId + ')', function (obj) { |
|
134 |
var data = obj.data; |
|
135 |
var layEvent = obj.event; |
|
136 |
|
|
137 |
if (layEvent === 'delete') { |
|
138 |
Myleave.onDeleteItem(data); |
|
139 |
} |
|
140 |
}); |
|
141 |
}); |