macro.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. $(function () {
  2. initialPage();
  3. getGrid();
  4. });
  5. function initialPage() {
  6. $(window).resize(function () {
  7. TreeGrid.table.resetHeight({height: $(window).height() - 100});
  8. });
  9. }
  10. function getGrid() {
  11. var colunms = TreeGrid.initColumn();
  12. var table = new TreeTable(TreeGrid.id, '../sys/macro/queryAll', colunms);
  13. table.setExpandColumn(2);
  14. table.setIdField("id");
  15. table.setCodeField("id");
  16. table.setParentCodeField("parentId");
  17. table.setExpandAll(false);
  18. table.setHeight($(window).height() - 100);
  19. table.init();
  20. TreeGrid.table = table;
  21. }
  22. var TreeGrid = {
  23. id: "jqGrid",
  24. table: null,
  25. layerIndex: -1
  26. };
  27. /**
  28. * 初始化表格的列
  29. */
  30. TreeGrid.initColumn = function () {
  31. var columns = [
  32. {field: 'selectItem', radio: true},
  33. {title: 'id', field: 'id', align: 'center', valign: 'middle', width: '50px'},
  34. {title: '名称', field: 'name', align: 'center', valign: 'middle', width: '50px'},
  35. {title: '值', field: 'value', align: 'center', valign: 'middle', width: '50px'},
  36. {
  37. title: '状态',
  38. field: 'status',
  39. align: 'center',
  40. valign: 'middle',
  41. width: '50px',
  42. formatter: function (item) {
  43. if (item.status == 1) {
  44. return '显示';
  45. } else {
  46. return '隐藏';
  47. }
  48. }
  49. },
  50. {
  51. title: '类型', field: 'type', align: 'center', valign: 'middle', width: '50px',
  52. formatter: function (item, index) {
  53. if (item.type === 1) {
  54. return '<span class="label label-success">参数配置</span>';
  55. }
  56. return '<span class="label label-primary">目录</span>';
  57. }
  58. },
  59. {title: '排序', field: 'orderNum', align: 'center', valign: 'middle', width: '50px'},
  60. {title: '备注', field: 'remark', align: 'center', valign: 'middle', width: '50px'},
  61. {
  62. title: '创建时间',
  63. field: 'gmtCreate',
  64. align: 'center',
  65. valign: 'middle',
  66. width: '80px',
  67. formatter: function (item) {
  68. return transDate(item.gmtCreate);
  69. }
  70. },
  71. {
  72. title: '修改时间', field: 'gmtModified', align: 'center', valign: 'middle', width: '80px',
  73. formatter: function (item) {
  74. return transDate(item.gmtCreate);
  75. }
  76. }
  77. ];
  78. return columns;
  79. };
  80. var vm = new Vue({
  81. el: '#rrapp',
  82. data: {
  83. showList: true,
  84. title: null,
  85. macro: {type: 0, status: 1},
  86. ruleValidate: {
  87. name: [
  88. {required: true, message: '名称不能为空', trigger: 'blur'}
  89. ]
  90. },
  91. q: {
  92. name: ''
  93. },
  94. macros: []
  95. },
  96. methods: {
  97. query: function () {
  98. vm.reload();
  99. },
  100. getMacros: function () {
  101. Ajax.request({
  102. url: "../sys/macro/queryAllParent",
  103. async: true,
  104. successCallback: function (r) {
  105. vm.macros = r.list;
  106. }
  107. });
  108. },
  109. add: function () {
  110. vm.showList = false;
  111. vm.title = "新增";
  112. vm.macro = {type: 0, status: 1};
  113. vm.macros = [];
  114. vm.getMacros();
  115. },
  116. update: function (event) {
  117. var id = TreeGrid.table.getSelectedRow();
  118. if (id.length == 0) {
  119. alert("请选择一条记录");
  120. return;
  121. }
  122. vm.showList = false;
  123. vm.title = "修改";
  124. Ajax.request({
  125. url: "../sys/macro/info/" + id[0].id,
  126. async: true,
  127. successCallback: function (r) {
  128. vm.macro = r.macro;
  129. }
  130. });
  131. vm.getMacros();
  132. },
  133. saveOrUpdate: function (event) {
  134. var url = vm.macro.id == null ? "../sys/macro/save" : "../sys/macro/update";
  135. Ajax.request({
  136. type: 'POST',
  137. url: url,
  138. params: JSON.stringify(vm.macro),
  139. contentType: "application/json",
  140. successCallback: function () {
  141. alert('操作成功', function (index) {
  142. vm.reload();
  143. });
  144. }
  145. });
  146. },
  147. del: function (event) {
  148. var id = TreeGrid.table.getSelectedRow(), ids = [];
  149. if (id.length == 0) {
  150. alert("请选择一条记录");
  151. return;
  152. }
  153. confirm('确定要删除选中的记录?', function () {
  154. $.each(id, function (idx, item) {
  155. ids[idx] = item.id;
  156. });
  157. Ajax.request({
  158. url: "../sys/macro/delete",
  159. params: JSON.stringify(ids),
  160. contentType: "application/json",
  161. type: 'POST',
  162. successCallback: function () {
  163. alert('操作成功', function (index) {
  164. vm.reload();
  165. });
  166. }
  167. });
  168. });
  169. },
  170. reload: function (event) {
  171. vm.showList = true;
  172. TreeGrid.table.refresh();
  173. },
  174. handleSubmit: function (name) {
  175. handleSubmitValidate(this, name, function () {
  176. vm.saveOrUpdate()
  177. });
  178. },
  179. handleReset: function (name) {
  180. handleResetForm(this, name);
  181. }
  182. }
  183. });