提交 | 用户 | 时间
|
1ac2bc
|
1 |
layui.use(['table', 'admin', 'ax', 'ztree', 'func', 'tree'], function () { |
懒 |
2 |
var $ = layui.$; |
|
3 |
var table = layui.table; |
|
4 |
var $ax = layui.ax; |
|
5 |
var admin = layui.admin; |
|
6 |
var $ZTree = layui.ztree; |
|
7 |
var func = layui.func; |
|
8 |
var tree = layui.tree; |
|
9 |
|
|
10 |
/** |
|
11 |
* 系统管理--部门管理 |
|
12 |
*/ |
|
13 |
var Dept = { |
|
14 |
tableId: "deptTable", |
|
15 |
condition: { |
|
16 |
deptId: "" |
|
17 |
} |
|
18 |
}; |
|
19 |
|
|
20 |
/** |
|
21 |
* 初始化表格的列 |
|
22 |
*/ |
|
23 |
Dept.initColumn = function () { |
|
24 |
return [[ |
|
25 |
{type: 'checkbox'}, |
|
26 |
{field: 'deptId', hide: true, sort: true, title: 'id'}, |
|
27 |
{field: 'simpleName', align: "center", sort: true, title: '部门简称'}, |
|
28 |
{field: 'fullName', align: "center", sort: true, title: '部门全称'}, |
|
29 |
{field: 'sort', align: "center", sort: true, title: '排序'}, |
|
30 |
{field: 'description', align: "center", sort: true, title: '备注'}, |
|
31 |
{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200} |
|
32 |
]]; |
|
33 |
}; |
|
34 |
|
|
35 |
/** |
|
36 |
* 点击查询按钮 |
|
37 |
*/ |
|
38 |
Dept.search = function () { |
|
39 |
var queryData = {}; |
|
40 |
queryData['condition'] = $("#name").val(); |
|
41 |
queryData['deptId'] = Dept.condition.deptId; |
|
42 |
table.reload(Dept.tableId, { |
|
43 |
where: queryData, page: {curr: 1} |
|
44 |
}); |
|
45 |
}; |
|
46 |
|
|
47 |
/** |
|
48 |
* 选择部门时 |
|
49 |
*/ |
|
50 |
Dept.onClickDept = function (obj) { |
|
51 |
Dept.condition.deptId = obj.data.id; |
|
52 |
Dept.search(); |
|
53 |
}; |
|
54 |
|
|
55 |
/** |
|
56 |
* 弹出添加 |
|
57 |
*/ |
|
58 |
Dept.openAddDept = function () { |
|
59 |
func.open({ |
|
60 |
height: 530, |
|
61 |
title: '添加部门', |
|
62 |
content: Feng.ctxPath + '/dept/dept_add', |
|
63 |
tableId: Dept.tableId, |
|
64 |
endCallback: function () { |
|
65 |
Dept.loadDeptTree(); |
|
66 |
} |
|
67 |
}); |
|
68 |
}; |
|
69 |
|
|
70 |
/** |
|
71 |
* 点击编辑部门 |
|
72 |
* |
|
73 |
* @param data 点击按钮时候的行数据 |
|
74 |
*/ |
|
75 |
Dept.onEditDept = function (data) { |
|
76 |
func.open({ |
|
77 |
height: 530, |
|
78 |
title: '编辑部门', |
|
79 |
content: Feng.ctxPath + "/dept/dept_update?deptId=" + data.deptId, |
|
80 |
tableId: Dept.tableId, |
|
81 |
endCallback: function () { |
|
82 |
Dept.loadDeptTree(); |
|
83 |
} |
|
84 |
}); |
|
85 |
}; |
|
86 |
|
|
87 |
/** |
|
88 |
* 导出excel按钮 |
|
89 |
*/ |
|
90 |
Dept.exportExcel = function () { |
|
91 |
var checkRows = table.checkStatus(Dept.tableId); |
|
92 |
if (checkRows.data.length === 0) { |
|
93 |
Feng.error("请选择要导出的数据"); |
|
94 |
} else { |
|
95 |
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); |
|
96 |
} |
|
97 |
}; |
|
98 |
|
|
99 |
/** |
|
100 |
* 点击删除部门 |
|
101 |
* |
|
102 |
* @param data 点击按钮时候的行数据 |
|
103 |
*/ |
|
104 |
Dept.onDeleteDept = function (data) { |
|
105 |
var operation = function () { |
|
106 |
var ajax = new $ax(Feng.ctxPath + "/dept/delete", function () { |
|
107 |
Feng.success("删除成功!"); |
|
108 |
table.reload(Dept.tableId); |
|
109 |
|
|
110 |
//左侧树加载 |
|
111 |
Dept.loadDeptTree(); |
|
112 |
|
|
113 |
}, function (data) { |
|
114 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
115 |
}); |
|
116 |
ajax.set("deptId", data.deptId); |
|
117 |
ajax.start(); |
|
118 |
}; |
|
119 |
Feng.confirm("是否删除部门 " + data.simpleName + "?", operation); |
|
120 |
}; |
|
121 |
|
|
122 |
/** |
|
123 |
* 左侧树加载 |
|
124 |
*/ |
|
125 |
Dept.loadDeptTree = function () { |
|
126 |
var ajax = new $ax(Feng.ctxPath + "/dept/layuiTree", function (data) { |
|
127 |
tree.render({ |
|
128 |
elem: '#deptTree', |
|
129 |
data: data, |
|
130 |
click: Dept.onClickDept, |
|
131 |
onlyIconControl: true |
|
132 |
}); |
|
133 |
}, function (data) { |
|
134 |
}); |
|
135 |
ajax.start(); |
|
136 |
}; |
|
137 |
|
|
138 |
// 渲染表格 |
|
139 |
var tableResult = table.render({ |
|
140 |
elem: '#' + Dept.tableId, |
|
141 |
url: Feng.ctxPath + '/dept/list', |
|
142 |
page: true, |
|
143 |
height: "full-98", |
|
144 |
cellMinWidth: 100, |
|
145 |
cols: Dept.initColumn() |
|
146 |
}); |
|
147 |
|
|
148 |
//初始化左侧部门树 |
|
149 |
Dept.loadDeptTree(); |
|
150 |
|
|
151 |
// 搜索按钮点击事件 |
|
152 |
$('#btnSearch').click(function () { |
|
153 |
Dept.search(); |
|
154 |
}); |
|
155 |
|
|
156 |
// 添加按钮点击事件 |
|
157 |
$('#btnAdd').click(function () { |
|
158 |
Dept.openAddDept(); |
|
159 |
}); |
|
160 |
|
|
161 |
// 导出excel |
|
162 |
$('#btnExp').click(function () { |
|
163 |
Dept.exportExcel(); |
|
164 |
}); |
|
165 |
|
|
166 |
// 工具条点击事件 |
|
167 |
table.on('tool(' + Dept.tableId + ')', function (obj) { |
|
168 |
var data = obj.data; |
|
169 |
var layEvent = obj.event; |
|
170 |
|
|
171 |
if (layEvent === 'edit') { |
|
172 |
Dept.onEditDept(data); |
|
173 |
} else if (layEvent === 'delete') { |
|
174 |
Dept.onDeleteDept(data); |
|
175 |
} |
|
176 |
}); |
|
177 |
}); |
|
178 |
|
|
179 |
$(function () { |
|
180 |
var panehHidden = false; |
|
181 |
if ($(this).width() < 769) { |
|
182 |
panehHidden = true; |
|
183 |
} |
|
184 |
$('#myContiner').layout({initClosed: panehHidden, west__size: 260}); |
|
185 |
}); |