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(1);
  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', hidden: true},
  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. $.get("../sys/macro/queryAll?type=0", function (r) {
  102. vm.macros = r.list;
  103. });
  104. },
  105. add: function () {
  106. vm.showList = false;
  107. vm.title = "新增";
  108. vm.macro = {type: 0, status: 1};
  109. vm.macros = [];
  110. vm.getMacros();
  111. },
  112. update: function (event) {
  113. var id = TreeGrid.table.getSelectedRow();
  114. if (id.length == 0) {
  115. iview.Message.error("请选择一条记录");
  116. return;
  117. }
  118. vm.showList = false;
  119. vm.title = "修改";
  120. $.get("../sys/macro/info/" + id[0].id, function (r) {
  121. vm.macro = r.macro;
  122. });
  123. vm.getMacros();
  124. },
  125. saveOrUpdate: function (event) {
  126. var url = vm.macro.id == null ? "../sys/macro/save" : "../sys/macro/update";
  127. $.ajax({
  128. type: "POST",
  129. url: url,
  130. contentType: "application/json",
  131. data: JSON.stringify(vm.macro),
  132. success: function (r) {
  133. if (r.code === 0) {
  134. alert('操作成功', function (index) {
  135. vm.reload();
  136. });
  137. } else {
  138. alert(r.msg);
  139. }
  140. }
  141. });
  142. },
  143. del: function (event) {
  144. var id = TreeGrid.table.getSelectedRow(), ids = [];
  145. if (id.length == 0) {
  146. iview.Message.error("请选择一条记录");
  147. return;
  148. }
  149. confirm('确定要删除选中的记录?', function () {
  150. $.each(id, function (idx, item) {
  151. ids[idx] = item.id;
  152. });
  153. $.ajax({
  154. type: "POST",
  155. url: "../sys/macro/delete",
  156. contentType: "application/json",
  157. data: JSON.stringify(ids),
  158. success: function (r) {
  159. if (r.code == 0) {
  160. alert('操作成功', function (index) {
  161. vm.reload();
  162. });
  163. } else {
  164. alert(r.msg);
  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. });