userroleUnSyn.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /**
  2. * 用户角色分配管理
  3. *
  4. */
  5. $.namespace("user.userrole");
  6. user.userrole.allData = null;
  7. user.userrole.data;
  8. // 页面初始化展示
  9. user.userrole.init = function() {
  10. var str = "";
  11. var jsonallData = $.parseJSON(user.userrole.allData);
  12. if (jsonallData) {
  13. for ( var i = 0; i < jsonallData.length; i++) {
  14. var all = jsonallData[i];
  15. str += "<tr>";
  16. str += "<td style='text-align: center;'>" + all.roleName + "</td>";
  17. /*一个问题 怎么加是否同步判断,数据库没有这个字*/
  18. /*
  19. if (all.sel&&all.sfcytb=="1"&&all.sftb) {
  20. str += "<td ><input id='"
  21. + all.id
  22. + "' type='checkbox' checked='checked' class='roleClass' value='"
  23. + all.id + "' onclick=\"user.userrole.liandong('"
  24. + all.id + "')\"></td><td><input type='checkbox' id='a"
  25. + all.id + "' class='sfClass' value='" + all.roleCode
  26. + "' onclick=\"user.userrole.sfliandong('"
  27. + all.id + "')\" style='display:none'>已同步</td>";
  28. } else if(all.sel&&all.sfcytb=="1"&&!all.sftb){
  29. str += "<td ><input id='" + all.id
  30. + "' type='checkbox' checked='checked' class='roleClass' value='"
  31. + all.id + "'onclick=\"user.userrole.liandong('"
  32. + all.id + "')\"></td><td><input type='checkbox' id='a"
  33. + all.id + "' class='sfClass' value='" + all.roleCode
  34. + "' onclick=\"user.userrole.sfliandong('"
  35. + all.id + "')\"></td>";
  36. }else if(all.sel&&all.sfcytb!="1"){
  37. str += "<td ><input id='" + all.id
  38. + "' type='checkbox' checked='checked' class='roleClass' value='"
  39. + all.id + "'onclick=\"user.userrole.liandong('"
  40. + all.id + "')\"></td><td></td>";
  41. }else if(!all.sel&&all.sfcytb=="1"&&all.sftb){
  42. str += "<td ><input id='"
  43. + all.id
  44. + "' type='checkbox' class='roleClass' value='"
  45. + all.id + "' onclick=\"user.userrole.liandong('"
  46. + all.id + "')\"></td><td><input type='checkbox' id='a"
  47. + all.id + "' class='sfClass' value='" + all.roleCode
  48. + "' onclick=\"user.userrole.sfliandong('"
  49. + all.id + "')\" style='display:none'>已同步</td>";
  50. }else if(!all.sel&&all.sfcytb=="1"&&!all.sftb){
  51. str += "<td ><input id='" + all.id
  52. + "' type='checkbox' class='roleClass' value='"
  53. + all.id + "'onclick=\"user.userrole.liandong('"
  54. + all.id + "')\"></td><td><input type='checkbox' id='a"
  55. + all.id + "' class='sfClass' value='" + all.roleCode
  56. + "' onclick=\"user.userrole.sfliandong('"
  57. + all.id + "')\"></td>";
  58. }else if(!all.sel&&all.sfcytb!="1"){
  59. str += "<td ><input id='" + all.id
  60. + "' type='checkbox' class='roleClass' value='"
  61. + all.id + "'onclick=\"user.userrole.liandong('"
  62. + all.id + "')\"></td><td></td>";
  63. }
  64. */
  65. str += "<td ><input codeid='" + all.roleCode
  66. + "' id='" + all.id
  67. + "' type='checkbox' class='roleClass' "+(all.sel?"checked='checked'":"")+" isShowrelating='"+(all.sfcytb=="1")+"' value='"
  68. + all.id + "'onclick=\"user.userrole.liandong('"
  69. + all.id + "',this)\"></td>";
  70. if (all.sfcytb=="1"){
  71. str +="<td class='hidetdClass'><input type='checkbox' isShowrelating='true' "+(all.sftb?"checked='checked'":"")+" codeid='" + all.roleCode
  72. + "' id='a"
  73. + all.id + "' class='sfClass' value='" + all.roleCode
  74. + "' onclick=\"user.userrole.liandong('"
  75. + all.id + "',this)\"></td>"
  76. str += "<td><span class='synStatusClass'></span></td>";
  77. }else{
  78. str += "<td class='hidetdClass'>--</td><td>--</td>";
  79. }
  80. str += "</tr>";
  81. }
  82. $("#divcontent").empty();
  83. $("#divcontent").append(str);
  84. }
  85. // 返回按钮功能实现
  86. user.userrole.back = function() {
  87. location.href = $.app + "/user/querylist.html";
  88. };
  89. // 全选按钮功能实现
  90. user.userrole.all = function() {
  91. $(".roleClass").each(function() {
  92. $(this).prop("checked", true);
  93. });
  94. $(".sfClass").each(function() {
  95. //$(this).prop("checked", true);
  96. //需求取消同步
  97. $(this).prop("checked", false);
  98. });
  99. };
  100. // 全不选按钮功能实现
  101. user.userrole.notall = function() {
  102. $(".roleClass").each(function() {
  103. $(this).prop("checked", false);
  104. });
  105. $(".sfClass").each(function() {
  106. $(this).prop("checked", false);
  107. });
  108. };
  109. };
  110. user.userrole.isNotBlank=function(value){
  111. if(typeof(value)!='undefined'){
  112. value=value+"";
  113. for(var i=0; i<value.length; i++) {
  114. var c = value.charAt(i);
  115. if ((c!=' ')&&(c!='\n')&&(c!='\t')) return true;
  116. }
  117. }
  118. return false;
  119. }
  120. //保存分配给该用户的角色的功能实现
  121. user.userrole.synSave = function() {
  122. /*
  123. var roleids = new Array();
  124. var rolecodes=new Array();
  125. $(".roleClass").each(function() {
  126. if ($(this).prop("checked")) {
  127. roleids.push($(this).val());
  128. rolecodes.push($('#a'+$(this)[0].id).val()||'');
  129. }
  130. });
  131. var sfids = new Array();
  132. $(".sfClass").each(function() {
  133. if ($(this).prop("checked")) {
  134. sfids.push($(this).val());
  135. }
  136. });
  137. */
  138. var info = {};
  139. info.userId=$("#userId").val();
  140. info.roles=new Array();
  141. info.needsyssyn=false;
  142. $(".roleClass").each(function() {
  143. if ($(this).prop("checked")) {
  144. //roleids.push($(this).val());
  145. //rolecodes.push($('#a'+$(this)[0].id).val()||'');
  146. var tobj={};
  147. tobj.userId=$("#userId").val();
  148. tobj.roleId=$(this).val();
  149. tobj.sftb="0";
  150. var jobj=$('#a'+$(this)[0].id);
  151. if(jobj&&jobj.length){
  152. //alert(jobj[0].id+"--"+jobj.prop("checked"));
  153. if(jobj.prop("checked")){
  154. tobj.sftb="1";
  155. info.needsyssyn=true;
  156. }
  157. }
  158. info.roles.push(tobj);
  159. }
  160. });
  161. $.ajax({
  162. type : 'post',
  163. dataType : 'json',
  164. contentType : 'application/json;charset=utf-8',
  165. //timeout : 10000, //超时时间设置,单位毫秒
  166. cache : false,// 不从缓存中去数据
  167. async : true,
  168. url : $.app + "/user/saveuserroleSyn.html",
  169. data : JSON.stringify(info),
  170. //headers:headinfo,
  171. success : function(data) {
  172. /*
  173. $.alert({
  174. title : '提示',
  175. content : data.message,
  176. confirm : function() {
  177. if (data.success) {
  178. location.href = $.app + "/user/querylist.html";
  179. }
  180. }
  181. });
  182. */
  183. var message="";
  184. if(data&&data.jsonInfo){
  185. console.log(data.jsonInfo);
  186. console.log("user.userrole.data:",user.userrole.data);
  187. if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
  188. message="提交参数错误";
  189. }else if(!data.jsonInfo.userexist){
  190. message="用户不存在";
  191. }else{
  192. for(var n in data){
  193. if(n=='jsonInfo'){
  194. continue;
  195. }
  196. var pass=true;
  197. if(user.userrole.data&&user.userrole.data[n]){
  198. pass=false;
  199. }
  200. var d=data[n];
  201. //alert(d.success);alert(d.sysname);
  202. //d.success=false;
  203. console.log(pass,d);
  204. if(pass
  205. &&typeof(d.success)=="boolean"&&!d.success&&user.userrole.isNotBlank(d.sysname)){
  206. message=message+d.sysname+"、";
  207. }
  208. }
  209. if(!user.userrole.isNotBlank(message)){
  210. message="保存成功";
  211. if(info&&info.needsyssyn){
  212. message="同步成功";
  213. }
  214. }else{
  215. message=message.substring(0, message.length-1)+"更新失败"
  216. }
  217. }
  218. }
  219. $.alert({
  220. title : '提示',
  221. content : message,
  222. confirm : function() {
  223. /*
  224. if (data.success) {
  225. location.href = $.app + "/user/querylist.html";
  226. }
  227. */
  228. user.userrole.synStatus();
  229. }
  230. });
  231. },
  232. error : function(jqXHR, textStatus, errorThrown) {
  233. //alert(jqXHR.responseText);
  234. }
  235. });
  236. /*
  237. console.log({
  238. userId : $("#userId").val(),
  239. roles : roleids.join(","),
  240. sfids : sfids.join(","),
  241. rolecodes:rolecodes.join(",")
  242. })
  243. */
  244. /*
  245. $.ajax({
  246. type : 'POST',
  247. url : $.app + "/user/saveuserrole.html",
  248. dataType:"json",
  249. data : {
  250. userId : $("#userId").val(),
  251. roles : roleids.join(","),
  252. sfids : sfids.join(","),
  253. rolecodes:rolecodes.join(",")
  254. },
  255. success : function(data) {
  256. if (data.success) {
  257. $.alert({
  258. title : '提示',
  259. content : data.message,
  260. confirm : function() {
  261. location.href = $.app + "/user/querylist.html";
  262. }
  263. });
  264. } else {
  265. $.alert({
  266. title : '提示',
  267. content : data.message,
  268. confirm : function() {
  269. }
  270. });
  271. }
  272. }
  273. });*/
  274. };
  275. user.userrole.save = function() {
  276. var xyqrxx=false;
  277. var jqueryObjArray=[];
  278. $(".sfClass").each(function() {
  279. //$(this).prop("checked", true);
  280. if($(this).is(":checked")&&$(this).attr("isShowrelating")&&$(this).attr("isShowrelating")=="true"){
  281. console.log($(this).attr("id"),$(this).is(":checked")+":"+$(this).attr("isShowrelating"));
  282. jqueryObjArray.push($(this));
  283. }
  284. });
  285. if(jqueryObjArray&&jqueryObjArray.length){
  286. for(var i=0;i<jqueryObjArray.length;i++){
  287. var key=jqueryObjArray[i].attr("codeid");
  288. if(key&&user.userrole.data&&user.userrole.data[key]){
  289. xyqrxx=true;
  290. break;
  291. }
  292. }
  293. }
  294. if(xyqrxx){
  295. $.confirm({
  296. title : '确认框',
  297. content : '同步系统中存在相同用户,待用户确认?',
  298. confirm : function() {
  299. user.userrole.synSave();
  300. },
  301. cancel: function(){
  302. }
  303. });
  304. }else{
  305. user.userrole.synSave();
  306. }
  307. }
  308. user.userrole.liandong = function(data,thisck) {
  309. var checkObj=$('#' + data);
  310. if(checkObj&&checkObj.length){
  311. if ($('#' + data + '').is(":checked")) {
  312. //$('#a' + data + '').prop("checked", true);
  313. } else {
  314. $('#a' + data + '').prop("checked", false);
  315. }
  316. checkObj=$(thisck);
  317. if(checkObj.attr("isShowrelating")&&checkObj.attr("isShowrelating")=="true"){
  318. //console.log()
  319. if(checkObj.parents("tr").find(".synStatusClass").is(":hidden")){
  320. user.userrole.synStatus();
  321. }else{
  322. checkObj.parents("tr").find(".synStatusClass").hide();
  323. }
  324. }
  325. }
  326. }
  327. user.userrole.synStatus = function() {
  328. var jqueryObjArray=[];
  329. var roleObj={};
  330. $('.synStatusClass').hide();
  331. //$('.hidetdClass').hide();
  332. //$(".roleClass").each(function() {
  333. $(".sfClass").each(function() {
  334. //$(this).prop("checked", true);
  335. if($(this).is(":checked")&&$(this).attr("isShowrelating")&&$(this).attr("isShowrelating")=="true"){
  336. console.log($(this).attr("id"),$(this).is(":checked")+":"+$(this).attr("isShowrelating"));
  337. //$(this).parents("tr").find(".synStatusClass").show();
  338. //$(this).parents("tr").find(".synStatusClass").text("");
  339. //console.log($(this).parents("tr").find(".synStatusClass").html());
  340. jqueryObjArray.push($(this));
  341. roleObj[$(this).attr("codeid")]=$(this).attr("value");
  342. }
  343. });
  344. if(jqueryObjArray&&jqueryObjArray.length){
  345. console.log("1.",{roleObj:roleObj,userId:$("#userId").val()});
  346. //alert($(".btn").length);
  347. $(".btn").attr("disabled",true);
  348. $.ajax({
  349. type : 'post',
  350. dataType : 'json',
  351. contentType : 'application/json;charset=utf-8',
  352. //timeout : 10000, //超时时间设置,单位毫秒
  353. cache : false,// 不从缓存中去数据
  354. async : true,
  355. url : $.app + "/user/relating.html",
  356. data : JSON.stringify({roleObj:roleObj,userId:$("#userId").val()}),
  357. //headers:headinfo,
  358. success : function(data) {
  359. console.log("2.",data);
  360. user.userrole.data=data;
  361. for(var i=0;i<jqueryObjArray.length;i++){
  362. jqueryObjArray[i].parents("tr").find(".synStatusClass").show();
  363. jqueryObjArray[i].parents("tr").find(".synStatusClass").text("不存在此用户,同步后将创建");
  364. //console.log("3.",jqueryObjArray[i].attr("codeid"));
  365. var key=jqueryObjArray[i].attr("codeid");
  366. if(key&&user.userrole.data){
  367. //console.log(key,user.userrole.data);
  368. if(user.userrole.data[key+"_error"]){
  369. jqueryObjArray[i].parents("tr").find(".synStatusClass").text("联系管理员,接口调用异常");//,请管理员确认操作
  370. }else if(user.userrole.data[key]){
  371. jqueryObjArray[i].parents("tr").find(".synStatusClass").text("已存在此用户");//,请管理员确认操作
  372. }
  373. }
  374. /*
  375. if(key&&user.userrole.data&&user.userrole.data[key]){
  376. jqueryObjArray[i].parents("tr").find(".synStatusClass").text("已存在此用户");//,请管理员确认操作
  377. }
  378. */
  379. }
  380. $(".btn").attr("disabled",false);
  381. },
  382. error : function(jqXHR, textStatus, errorThrown) {
  383. //alert(jqXHR.responseText);
  384. }
  385. });
  386. }
  387. }
  388. user.userrole.sfliandong=function(data) {
  389. if ($('#a' + data + '').is(":checked")) {
  390. $('#' + data + '').prop("checked", true);
  391. }
  392. }