codemain.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. *字典管理
  3. *
  4. */
  5. $.namespace("code.main");
  6. code.main.treeObj=null;
  7. //初始化树、树对象、列表数据
  8. code.main.init=function(set){
  9. $.fn.zTree.init($("#tree"), set);
  10. code.main.treeObj = $.fn.zTree.getZTreeObj("tree");
  11. code.main.inittable();
  12. };
  13. //单击树节点时,给表单赋值pid,和查询节点下的数据
  14. code.main.onClick=function(event, treeId, treeNode, clickFlag){
  15. $('#editpid').val(treeNode.id);
  16. code.main.inittable(treeNode.id);
  17. };
  18. code.main.inittable=function(data){
  19. $.post($.app + "/code/getDataByPid", {
  20. pid : data
  21. }, function(data) {
  22. if(data){
  23. var str="";
  24. for(var i=0;i<data.length;i++){
  25. var code = data[i];
  26. var v=code.val||"";
  27. var gc=code.groupCode||"";
  28. str+=" <tr class='tr_bg'>";
  29. str+="<td >"+code.text+"</td>";
  30. str+="<td >"+code.code+"</td>";
  31. str+="<td >"+code.id+":"+code.pid+"</td>";
  32. str+="<td >"+v+"</td>";
  33. str+="<td >"+gc+"</td>";
  34. str+="<td >"+code.sortno+"</td>";
  35. str+="<td class='operatetd'> " +
  36. "<a class='btn btn-default btn-xs' href='#' title='编辑' onclick=\"code.main.edit('"+code.id+"')\">"+
  37. "<i class='glyphicon glyphicon-pencil'></i></a> "+
  38. "<a class='btn btn-default btn-xs' href='#' title='删除' onclick=\"code.main.del('"+code.id+"','"+code.pid+"')\">"+
  39. "<i class='glyphicon glyphicon-trash'></i></a> "+
  40. "</td>";
  41. str+=" </tr >";
  42. }
  43. $("#liebiao").empty();
  44. $("#liebiao").append(str);
  45. }
  46. }, "json");
  47. };
  48. //删除某个节点时,列表刷新同时树节点也刷新
  49. code.main.del=function(id,pdata){
  50. $.confirm({
  51. title: '确认框',
  52. content: '确认删除吗',
  53. confirm: function(){
  54. $.post($.app + "/code/delete", {
  55. id : id
  56. }, function(data) {
  57. if (data.success) {
  58. $.alert({
  59. title: '提示',
  60. content: '操作成功',
  61. confirm: function(){
  62. code.main.inittable(pdata);
  63. var selNode = code.main.treeObj.getNodesByParam("id",id,null);
  64. if(selNode){
  65. code.main.treeObj.removeNode(selNode[0]);
  66. }
  67. }
  68. });
  69. } else {
  70. $.alert({
  71. title: '提示',
  72. content: data.message,
  73. confirm: function(){
  74. }
  75. });
  76. }
  77. }, "json");
  78. },
  79. cancel: function(){
  80. }
  81. });
  82. };
  83. code.main.edit=function(id){
  84. $.post($.app + "/code/edit", {
  85. id : id
  86. }, function(data) {
  87. if (data) {
  88. $('#editid').val(data.id);
  89. $('#editpid').val(data.pid);
  90. $('#edittext').val(data.text);
  91. $('#editbz').val(data.bz);
  92. $('#editcode').val(data.code);
  93. $('#editval').val(data.val);
  94. $('#editgroupCode').val(data.groupCode);
  95. $('#editsortno').val(data.sortno);
  96. code.main.show();
  97. }
  98. }, "json");
  99. };
  100. code.main.add=function(){
  101. code.main.clearForm();
  102. code.main.show();
  103. };
  104. code.main.clearForm=function(){
  105. $('#editid').val("");
  106. $('#edittext').val("");
  107. $('#editcode').val("");
  108. $('#editval').val("");
  109. $('#editbz').val("");
  110. $('#editgroupCode').val("");
  111. $('#editsortno').val("");
  112. };
  113. code.main.close=function(){
  114. $('.theme-popover-mask').fadeOut(100);
  115. $('.theme-popover').slideUp(0);
  116. };
  117. code.main.show=function(){
  118. $('.theme-popover-mask').fadeIn(100);
  119. $('.theme-popover').slideDown(0);
  120. };
  121. //保存后刷新数据和树节点,关闭弹出框
  122. code.main.save=function(){
  123. $.ajax({
  124. url:$.app+"/code/save",
  125. data:$("#addform").serialize(),
  126. type:"post",
  127. dataType:"json",
  128. success:function(data){//ajax返回的数据
  129. if (data.success) {
  130. $.alert({
  131. title: '提示',
  132. content: '操作成功',
  133. confirm: function(){
  134. code.main.inittable($('#editpid').val());
  135. var selNode = code.main.treeObj.getNodesByParam("id",$('#editpid').val(),null);
  136. if(selNode){
  137. code.main.treeObj.reAsyncChildNodes(selNode[0], "refresh",false);
  138. }
  139. code.main.close();
  140. }
  141. });
  142. }else {
  143. $.alert({
  144. title: '提示',
  145. content: data.message,
  146. confirm: function(){
  147. }
  148. });
  149. }
  150. }
  151. });
  152. };