userrole.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * 用户角色分配管理
  3. *
  4. */
  5. $.namespace("user.userrole");
  6. user.userrole.allData = null;
  7. // 页面初始化展示
  8. user.userrole.init = function() {
  9. var str = "";
  10. var jsonallData = $.parseJSON(user.userrole.allData);
  11. if (jsonallData) {
  12. for ( var i = 0; i < jsonallData.length; i++) {
  13. var all = jsonallData[i];
  14. str += "<tr>";
  15. str += "<td style='text-align: center;'>" + all.roleName + "</td>";
  16. /*一个问题 怎么加是否同步判断,数据库没有这个字*/
  17. if (all.sel&&all.sfcytb=="1"&&all.sftb) {
  18. str += "<td ><input id='"
  19. + all.id
  20. + "' type='checkbox' checked='checked' class='roleClass' value='"
  21. + all.id + "' onclick=\"user.userrole.liandong('"
  22. + all.id + "')\"></td><td><input type='checkbox' id='a"
  23. + all.id + "' class='sfClass' value='" + all.roleCode
  24. + "' onclick=\"user.userrole.sfliandong('"
  25. + all.id + "')\" style='display:none'>已同步</td>";
  26. } else if(all.sel&&all.sfcytb=="1"&&!all.sftb){
  27. str += "<td ><input id='" + all.id
  28. + "' type='checkbox' checked='checked' class='roleClass' value='"
  29. + all.id + "'onclick=\"user.userrole.liandong('"
  30. + all.id + "')\"></td><td><input type='checkbox' id='a"
  31. + all.id + "' class='sfClass' value='" + all.roleCode
  32. + "' onclick=\"user.userrole.sfliandong('"
  33. + all.id + "')\"></td>";
  34. }else if(all.sel&&all.sfcytb!="1"){
  35. str += "<td ><input id='" + all.id
  36. + "' type='checkbox' checked='checked' class='roleClass' value='"
  37. + all.id + "'onclick=\"user.userrole.liandong('"
  38. + all.id + "')\"></td><td></td>";
  39. }else if(!all.sel&&all.sfcytb=="1"&&all.sftb){
  40. str += "<td ><input id='"
  41. + all.id
  42. + "' type='checkbox' class='roleClass' value='"
  43. + all.id + "' onclick=\"user.userrole.liandong('"
  44. + all.id + "')\"></td><td><input type='checkbox' id='a"
  45. + all.id + "' class='sfClass' value='" + all.roleCode
  46. + "' onclick=\"user.userrole.sfliandong('"
  47. + all.id + "')\" style='display:none'>已同步</td>";
  48. }else if(!all.sel&&all.sfcytb=="1"&&!all.sftb){
  49. str += "<td ><input id='" + all.id
  50. + "' type='checkbox' class='roleClass' value='"
  51. + all.id + "'onclick=\"user.userrole.liandong('"
  52. + all.id + "')\"></td><td><input type='checkbox' id='a"
  53. + all.id + "' class='sfClass' value='" + all.roleCode
  54. + "' onclick=\"user.userrole.sfliandong('"
  55. + all.id + "')\"></td>";
  56. }else if(!all.sel&&all.sfcytb!="1"){
  57. str += "<td ><input id='" + all.id
  58. + "' type='checkbox' class='roleClass' value='"
  59. + all.id + "'onclick=\"user.userrole.liandong('"
  60. + all.id + "')\"></td><td></td>";
  61. }
  62. str += "</tr>";
  63. }
  64. $("#divcontent").empty();
  65. $("#divcontent").append(str);
  66. }
  67. // 返回按钮功能实现
  68. user.userrole.back = function() {
  69. location.href = $.app + "/user/querylist.html";
  70. };
  71. // 全选按钮功能实现
  72. user.userrole.all = function() {
  73. $(".roleClass").each(function() {
  74. $(this).prop("checked", true);
  75. });
  76. $(".sfClass").each(function() {
  77. $(this).prop("checked", true);
  78. });
  79. };
  80. // 全不选按钮功能实现
  81. user.userrole.notall = function() {
  82. $(".roleClass").each(function() {
  83. $(this).prop("checked", false);
  84. });
  85. $(".sfClass").each(function() {
  86. $(this).prop("checked", false);
  87. });
  88. };
  89. };
  90. //保存分配给该用户的角色的功能实现
  91. user.userrole.save = function() {
  92. var roleids = new Array();
  93. var rolecodes=new Array();
  94. $(".roleClass").each(function() {
  95. if ($(this).prop("checked")) {
  96. roleids.push($(this).val());
  97. rolecodes.push($('#a'+$(this)[0].id).val()||'');
  98. }
  99. });
  100. var sfids = new Array();
  101. $(".sfClass").each(function() {
  102. if ($(this).prop("checked")) {
  103. sfids.push($(this).val());
  104. }
  105. });
  106. /*
  107. console.log({
  108. userId : $("#userId").val(),
  109. roles : roleids.join(","),
  110. sfids : sfids.join(","),
  111. rolecodes:rolecodes.join(",")
  112. })
  113. */
  114. $.ajax({
  115. type : 'POST',
  116. url : $.app + "/user/saveuserrole.html",
  117. dataType:"json",
  118. data : {
  119. userId : $("#userId").val(),
  120. roles : roleids.join(","),
  121. sfids : sfids.join(","),
  122. rolecodes:rolecodes.join(",")
  123. },
  124. success : function(data) {
  125. if (data.success) {
  126. $.alert({
  127. title : '提示',
  128. content : data.message,
  129. confirm : function() {
  130. location.href = $.app + "/user/querylist.html";
  131. }
  132. });
  133. } else {
  134. $.alert({
  135. title : '提示',
  136. content : data.message,
  137. confirm : function() {
  138. }
  139. });
  140. }
  141. }
  142. });
  143. };
  144. user.userrole.liandong = function(data) {
  145. if ($('#' + data + '').is(":checked")) {
  146. $('#a' + data + '').prop("checked", true);
  147. } else {
  148. $('#a' + data + '').prop("checked", false);
  149. }
  150. }
  151. user.userrole.sfliandong=function(data) {
  152. if ($('#a' + data + '').is(":checked")) {
  153. $('#' + data + '').prop("checked", true);
  154. }
  155. }