dict.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. layui.use(['layer', 'form', 'table', 'admin', 'ax'], function () {
  2. var $ = layui.$;
  3. var layer = layui.layer;
  4. var form = layui.form;
  5. var table = layui.table;
  6. var $ax = layui.ax;
  7. var admin = layui.admin;
  8. /**
  9. * 系统管理--字典管理
  10. */
  11. var Dict = {
  12. tableId: "dictTable", //表格id
  13. condition: {
  14. condition: ""
  15. }
  16. };
  17. /**
  18. * 初始化表格的列
  19. */
  20. Dict.initColumn = function () {
  21. return [[
  22. {type: 'checkbox'},
  23. {field: 'dictId', hide: true, sort: true, title: 'id'},
  24. {field: 'name', sort: true, title: '名称'},
  25. {field: 'code', sort: true, title: '字典编码'},
  26. {field: 'detail', sort: true, title: '详情'},
  27. {field: 'description', sort: true, title: '备注'},
  28. {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
  29. ]];
  30. };
  31. /**
  32. * 点击查询按钮
  33. */
  34. Dict.search = function () {
  35. var queryData = {};
  36. queryData['condition'] = $("#condition").val();
  37. table.reload(Dict.tableId, {where: queryData});
  38. };
  39. /**
  40. * 弹出添加字典
  41. */
  42. Dict.openAddDict = function () {
  43. admin.putTempData('formOk', false);
  44. top.layui.admin.open({
  45. type: 2,
  46. title: '添加字典类型',
  47. content: Feng.ctxPath + '/dict/dict_add_type',
  48. end: function () {
  49. admin.getTempData('formOk') && table.reload(Dict.tableId);
  50. }
  51. });
  52. };
  53. /**
  54. * 弹出添加子条目
  55. */
  56. Dict.openAddDictSub = function (data) {
  57. admin.putTempData('formOk', false);
  58. top.layui.admin.open({
  59. type: 2,
  60. title: '添加子条目',
  61. content: Feng.ctxPath + '/dict/dict_add_item?dictId=' + data.dictId,
  62. end: function () {
  63. admin.getTempData('formOk') && table.reload(Dict.tableId);
  64. }
  65. });
  66. };
  67. /**
  68. * 导出excel按钮
  69. */
  70. Dict.exportExcel = function () {
  71. var checkRows = table.checkStatus(Dict.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. * @param data 点击按钮时候的行数据
  82. */
  83. Dict.onDeleteRole = function (data) {
  84. var operation = function () {
  85. var ajax = new $ax(Feng.ctxPath + "/dict/delete", function (data) {
  86. Feng.success("删除成功!");
  87. table.reload(Dict.tableId);
  88. }, function (data) {
  89. Feng.error("删除失败!" + data.responseJSON.message + "!");
  90. });
  91. ajax.set("dictId", data.dictId);
  92. ajax.start();
  93. };
  94. Feng.confirm("是否刪除字典 " + data.name + "?", operation);
  95. };
  96. // 渲染表格
  97. var tableResult = table.render({
  98. elem: '#' + Dict.tableId,
  99. url: Feng.ctxPath + '/dict/list',
  100. page: true,
  101. height: "full-158",
  102. cellMinWidth: 100,
  103. cols: Dict.initColumn()
  104. });
  105. // 搜索按钮点击事件
  106. $('#btnSearch').click(function () {
  107. Dict.search();
  108. });
  109. // 添加按钮点击事件
  110. $('#btnAdd').click(function () {
  111. Dict.openAddDict();
  112. });
  113. // 导出excel
  114. $('#btnExp').click(function () {
  115. Dict.exportExcel();
  116. });
  117. // 工具条点击事件
  118. table.on('tool(' + Dict.tableId + ')', function (obj) {
  119. var data = obj.data;
  120. var layEvent = obj.event;
  121. if (layEvent === 'addSub') {
  122. Dict.openAddDictSub(data);
  123. } else if (layEvent === 'delete') {
  124. Dict.onDeleteRole(data);
  125. } else if (layEvent === 'roleAssign') {
  126. Dict.roleAssign(data);
  127. }
  128. });
  129. });