dict.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * 字典管理初始化
  3. */
  4. var Dict = {
  5. id: "DictTable", //表格id
  6. seItem: null, //选中的条目
  7. table: null,
  8. layerIndex: -1
  9. };
  10. Feng.ctxPath = "/admin";
  11. /**
  12. * 初始化表格的列
  13. */
  14. Dict.initColumn = function () {
  15. return [
  16. {field: 'selectItem', radio: true},
  17. {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
  18. {title: '名称', field: 'name', align: 'center', valign: 'middle', sortable: true},
  19. {title: '详情', field: 'detail', align: 'center', valign: 'middle', sortable: true},
  20. {title: '备注', field: 'tips', align: 'center', valign: 'middle', sortable: true}];
  21. };
  22. /**
  23. * 检查是否选中
  24. */
  25. Dict.check = function () {
  26. var selected = $('#' + this.id).bootstrapTable('getSelections');
  27. if (selected.length == 0) {
  28. Feng.info("请先选中表格中的某一记录!");
  29. return false;
  30. } else {
  31. Dict.seItem = selected[0];
  32. return true;
  33. }
  34. };
  35. /**
  36. * 点击添加字典
  37. */
  38. Dict.openAddDict = function () {
  39. var index = layer.open({
  40. type: 2,
  41. title: '添加字典',
  42. area: ['800px', '420px'], //宽高
  43. fix: false, //不固定
  44. maxmin: true,
  45. content: Feng.ctxPath + '/dict/add'
  46. });
  47. this.layerIndex = index;
  48. };
  49. /**
  50. * 打开查看字典详情
  51. */
  52. Dict.openDictDetail = function () {
  53. if (this.check()) {
  54. var index = layer.open({
  55. type: 2,
  56. title: '字典详情',
  57. area: ['800px', '420px'], //宽高
  58. fix: false, //不固定
  59. maxmin: true,
  60. content: Feng.ctxPath + '/dict/edit/id/' + Dict.seItem.id
  61. });
  62. this.layerIndex = index;
  63. }
  64. };
  65. /**
  66. * 删除字典
  67. */
  68. Dict.delete = function () {
  69. if (this.check()) {
  70. var operation = function(){
  71. var ajax = new $ax(Feng.ctxPath + "/dict/delete", function (data) {
  72. Feng.success("删除成功!");
  73. Dict.table.refresh();
  74. }, function (data) {
  75. Feng.error("删除失败!" + data.responseJSON.message + "!");
  76. });
  77. ajax.set("dictId", Dict.seItem.id);
  78. ajax.start();
  79. };
  80. Feng.confirm("是否刪除字典 " + Dict.seItem.name + "?", operation);
  81. }
  82. };
  83. /**
  84. * 查询字典列表
  85. */
  86. Dict.search = function () {
  87. var queryData = {};
  88. queryData['condition'] = $("#condition").val();
  89. Dict.table.refresh({query: queryData});
  90. };
  91. $(function () {
  92. var defaultColunms = Dict.initColumn();
  93. var table = new BSTable(Dict.id, "/dict/list", defaultColunms);
  94. table.setPaginationType("server");
  95. Dict.table = table.init();
  96. });