orgmain.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * 组织管理
  3. *
  4. */
  5. $.namespace("org.main");
  6. org.main.treeData=null;
  7. org.main.typeData=null;
  8. org.main.init=function(){
  9. org.main.inittree();
  10. org.main.inittable();
  11. org.main.inittype(null);
  12. }
  13. org.main.inittype=function(existdata){
  14. var str = "";
  15. str+="<select class='selectpicker' name='orgType' >";
  16. str+="<option></option>";
  17. if(org.main.typeData){
  18. var jsonselectdata=$.parseJSON(org.main.typeData);
  19. for(var i=0;i<jsonselectdata.length;i++){
  20. var has=false;
  21. var select = jsonselectdata[i];
  22. if(existdata){
  23. if(select.codeValue==existdata){
  24. has=true;
  25. }
  26. }
  27. if(has){
  28. str+=" <option value='"+select.codeValue+"' selected='selected'>"+select.codeName+"</option>";
  29. }else{
  30. str+=" <option value='"+select.codeValue+"' >"+select.codeName+"</option>";
  31. }
  32. }
  33. }
  34. str+="</select>";
  35. $("#typedata").empty();
  36. $("#typedata").append(str);
  37. $('.selectpicker').selectpicker({
  38. width:300
  39. });
  40. }
  41. org.main.inittree=function(){
  42. $('#treeview').treeview({
  43. color: "#428bca",
  44. showBorder: false,
  45. nodeIcon: 'glyphicon glyphicon-user',
  46. levels: 2,
  47. data: org.main.treeData,
  48. onNodeSelected:function(event, node) {
  49. $("#editpid").val(node.id);
  50. $("#editorgLevel").val(parseInt(node.level)+1);
  51. org.main.inittable();
  52. }
  53. });
  54. }
  55. org.main.inittable=function(){
  56. $.post($.app + "/org/getOrgData", {
  57. pid : $("#editpid").val()
  58. }, function(data) {
  59. if(data){
  60. var str="";
  61. for(var i=0;i<data.length;i++){
  62. var org = data[i];
  63. str+=" <tr >";
  64. str+="<td >"+org.orgName+"</td>";
  65. str+="<td >"+org.orgCode+"</td>";
  66. str+="<td >"+org.orgLevel+"</td>";
  67. str+="<td >"+org.sortno+"</td>";
  68. str+="<td ><a class='btn btn-default btn-xs' href='#' data-toggle='modal' data-target='#myModal' onclick=\"org.main.edit('"+org.id+"')\">"+
  69. "<i class='glyphicon glyphicon-wrench'></i>修改</a> "+
  70. "<a class='btn btn-default btn-xs' href='#' onclick=\"org.main.del('"+org.id+"')\">"+
  71. "<i class='glyphicon glyphicon-wrench'></i>删除</a> "+
  72. "</td>";
  73. str+=" </tr >";
  74. }
  75. $("#orgdata").empty();
  76. $("#orgdata").append(str);
  77. }
  78. }, "json");
  79. }
  80. org.main.del=function(data){
  81. $.confirm({
  82. title: '确认框',
  83. content: '删除会导致下级组织一同被删除,确认删除吗',
  84. confirm: function(){
  85. $.post($.app + "/org/delete", {
  86. id : data
  87. }, function(data) {
  88. if (data.success) {
  89. $.alert({
  90. title: '提示',
  91. content: '删除成功',
  92. confirm: function(){
  93. location.href=$.app+"/org/main";
  94. }
  95. });
  96. } else {
  97. $.alert({
  98. title: '提示',
  99. content: data.message,
  100. confirm: function(){
  101. }
  102. });
  103. }
  104. }, "json");
  105. },
  106. cancel: function(){
  107. }
  108. });
  109. }
  110. org.main.edit=function(data){
  111. $.post($.app + "/org/edit", {
  112. id : data
  113. }, function(data) {
  114. if(data){
  115. for(var a in data){
  116. if($("#edit"+a)){
  117. $("#edit"+a).val(data[a]);
  118. }
  119. }
  120. }
  121. org.main.inittype(data["orgType"]);
  122. }, "json");
  123. }
  124. org.main.save=function(){
  125. $.ajax({
  126. url:$.app+"/org/save",
  127. data:$("#addform").serialize(),
  128. type:"post",
  129. dataType:"json",
  130. success:function(data){//ajax返回的数据
  131. if (data.success) {
  132. $.alert({
  133. title: '提示',
  134. content: '保存成功',
  135. confirm: function(){
  136. location.href=$.app+"/org/main";
  137. }
  138. });
  139. }else {
  140. $.alert({
  141. title: '提示',
  142. content: data.message,
  143. confirm: function(){
  144. }
  145. });
  146. }
  147. }
  148. });
  149. }
  150. org.main.clear=function(){
  151. $("#editid").val("");
  152. $("#editorgName").val("");
  153. $("#editorgCode").val("");
  154. $("#editsortno").val("");
  155. org.main.inittype(null);
  156. }