dept.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. layui.use(['table', 'admin', 'ax', 'ztree'], 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. /**
  8. * 系统管理--部门管理
  9. */
  10. var Dept = {
  11. tableId: "deptTable",
  12. condition: {
  13. deptId: ""
  14. }
  15. };
  16. /**
  17. * 初始化表格的列
  18. */
  19. Dept.initColumn = function () {
  20. return [[
  21. {type: 'checkbox'},
  22. {field: 'deptId', hide: true, sort: true, title: 'id'},
  23. {field: 'simpleName', sort: true, title: '部门简称'},
  24. {field: 'fullName', sort: true, title: '部门全称'},
  25. {field: 'sort', sort: true, title: '排序'},
  26. {field: 'description', sort: true, title: '备注'},
  27. {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
  28. ]];
  29. };
  30. /**
  31. * 点击查询按钮
  32. */
  33. Dept.search = function () {
  34. var queryData = {};
  35. queryData['condition'] = $("#name").val();
  36. queryData['deptId'] = Dept.condition.deptId;
  37. table.reload(Dept.tableId, {where: queryData});
  38. };
  39. /**
  40. * 选择部门时
  41. */
  42. Dept.onClickDept = function (e, treeId, treeNode) {
  43. Dept.condition.deptId = treeNode.id;
  44. Dept.search();
  45. };
  46. /**
  47. * 弹出添加
  48. */
  49. Dept.openAddDept = function () {
  50. admin.putTempData('formOk', false);
  51. top.layui.admin.open({
  52. type: 2,
  53. title: '添加部门',
  54. content: Feng.ctxPath + '/dept/dept_add',
  55. end: function () {
  56. admin.getTempData('formOk') && table.reload(Dept.tableId);
  57. }
  58. });
  59. };
  60. /**
  61. * 导出excel按钮
  62. */
  63. Dept.exportExcel = function () {
  64. var checkRows = table.checkStatus(Dept.tableId);
  65. if (checkRows.data.length === 0) {
  66. Feng.error("请选择要导出的数据");
  67. } else {
  68. table.exportFile(tableResult.config.id, checkRows.data, 'xls');
  69. }
  70. };
  71. /**
  72. * 点击编辑部门
  73. *
  74. * @param data 点击按钮时候的行数据
  75. */
  76. Dept.onEditDept = function (data) {
  77. admin.putTempData('formOk', false);
  78. top.layui.admin.open({
  79. type: 2,
  80. title: '修改部门',
  81. content: Feng.ctxPath + '/dept/dept_update?deptId=' + data.deptId,
  82. end: function () {
  83. admin.getTempData('formOk') && table.reload(Dept.tableId);
  84. }
  85. });
  86. };
  87. /**
  88. * 点击删除部门
  89. *
  90. * @param data 点击按钮时候的行数据
  91. */
  92. Dept.onDeleteDept = function (data) {
  93. var operation = function () {
  94. var ajax = new $ax(Feng.ctxPath + "/dept/delete", function () {
  95. Feng.success("删除成功!");
  96. table.reload(Dept.tableId);
  97. }, function (data) {
  98. Feng.error("删除失败!" + data.responseJSON.message + "!");
  99. });
  100. ajax.set("deptId", data.deptId);
  101. ajax.start();
  102. };
  103. Feng.confirm("是否删除部门 " + data.simpleName + "?", operation);
  104. };
  105. // 渲染表格
  106. var tableResult = table.render({
  107. elem: '#' + Dept.tableId,
  108. url: Feng.ctxPath + '/dept/list',
  109. page: true,
  110. height: "full-158",
  111. cellMinWidth: 100,
  112. cols: Dept.initColumn()
  113. });
  114. //初始化左侧部门树
  115. var ztree = new $ZTree("deptTree", "/dept/tree");
  116. ztree.bindOnClick(Dept.onClickDept);
  117. ztree.init();
  118. // 搜索按钮点击事件
  119. $('#btnSearch').click(function () {
  120. Dept.search();
  121. });
  122. // 添加按钮点击事件
  123. $('#btnAdd').click(function () {
  124. Dept.openAddDept();
  125. });
  126. // 导出excel
  127. $('#btnExp').click(function () {
  128. Dept.exportExcel();
  129. });
  130. // 工具条点击事件
  131. table.on('tool(' + Dept.tableId + ')', function (obj) {
  132. var data = obj.data;
  133. var layEvent = obj.event;
  134. if (layEvent === 'edit') {
  135. Dept.onEditDept(data);
  136. } else if (layEvent === 'delete') {
  137. Dept.onDeleteDept(data);
  138. }
  139. });
  140. });