user.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="renderer" content="webkit|ie-comp|ie-stand">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  8. <meta http-equiv="Cache-Control" content="no-siteapp" />
  9. <script type="text/ecmascript" src="${ctx}/assets/lib/jquery/1.9.1/jquery.js"></script>
  10. <link rel="stylesheet" type="text/css" href="${ctx}/assets/lib/easyui/themes/gray/easyui.css" />
  11. <link rel="stylesheet" type="text/css" href="${ctx}/assets/lib/easyui/themes/icon.css" />
  12. <script type="text/ecmascript" src="${ctx}/assets/lib/easyui/jquery.easyui.min.js"></script>
  13. <script type="text/ecmascript" src="${ctx}/assets/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
  14. <style type="text/css">
  15. .panel-header, .panel-body{border-color:#FCFCFC}
  16. .layout-split-west{border-right:none}
  17. </style>
  18. <script type="text/javascript">
  19. var $easy = $.noConflict(true);
  20. $easy(function(){
  21. $easy('#pageright').panel({
  22. onResize:function(width, height){
  23. $("#jqGrid").setGridWidth(width-4); 
  24. }
  25. });
  26. })
  27. </script>
  28. <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" >
  29. <script type="text/ecmascript" src="${ctx}/assets/lib/jquery/1.9.1/jquery.js"></script>
  30. <script type="text/javascript" src="${ctx}/assets/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
  31. <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqueryui/jquery-ui.css" />
  32. <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqgrid/css/ui.jqgrid.css" />
  33. <script type="text/ecmascript" src="${ctx}/assets/lib/jqueryui/jquery-ui.js"></script>
  34. <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/i18n/grid.locale-cn.js"></script>
  35. <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/jquery.jqGrid.min.js"></script>
  36. <script type="text/javascript" src="${ctx}/assets/js/base.js"></script>
  37. <script type="text/javascript">
  38. var currentOrgID = '${currentOrgID!}';
  39. var OrgTree = '${OrgTree!}';
  40. var setting = {
  41. view: {
  42. dblClickExpand: false,
  43. showLine: false,
  44. selectedMulti: false
  45. },
  46. data: {
  47. simpleData: {
  48. enable:true,
  49. idKey: "id",
  50. pIdKey: "pId",
  51. rootPId: "-1"
  52. }
  53. },
  54. callback: {
  55. onClick: zTreeClick
  56. }
  57. };
  58. //创建树型菜单
  59. function createTree(OrgTree){
  60. var zNodes = [];
  61. if(OrgTree == ""){
  62. return false;
  63. }
  64. var jsonorgtree = JSON.parse(OrgTree);
  65. jsonorgtree.forEach(function(item,index){
  66. if(currentOrgID==item.orgid){ //所在一级展开
  67. zNodes.push({id:item.orgid,pId:item.parentid,name:item.orgname,open:true});
  68. }else{
  69. zNodes.push({id:item.orgid,pId:item.parentid,name:item.orgname});
  70. }
  71. })
  72. return zNodes;
  73. }
  74. //ztree的点击回调函数
  75. function zTreeClick(event, treeId, treeNode) {
  76. currentOrgID = treeNode.id; //用于添加操作时使用
  77. setGrid(treeNode.id,treeNode.name);
  78. }
  79. $(document).ready(function(){
  80. var ztreeNode = $.fn.zTree.init($("#treeDemo"), setting,createTree(OrgTree));
  81. var captionName = ztreeNode.getNodes(currentOrgID)[0].name;
  82. //DOM加载完成后,加载jqgrid
  83. $("#jqGrid").jqGrid({
  84. url : '${ctx}/myconsole/user/getByPage',
  85. editurl:"${ctx}/myconsole/user/saveOrUpdate", //保存或者添加
  86. mtype : "POST",
  87. datatype : "json",
  88. sidx : "sortid",
  89. sord : "asc",
  90. caption:captionName,
  91. prmNames : {
  92. id: "keyid", 
  93. oper:"oper",    
  94. addoper:"add",
  95. editoper:"edit",
  96. deloper:"del" 
  97. },
  98. colModel : [ {
  99. label : '用户编号',
  100. name : 'keyid',
  101. hidden : true,
  102. key : true,
  103. width : 50,
  104. }, {
  105. label : '登录账号',
  106. name : 'userid',
  107. editable: true,
  108. formoptions:{
  109. elmsuffix:" <span style='color:red'>*(初始密码${defaultPassword})<span>"
  110. },
  111. editrules:{
  112. required:true
  113. },
  114. width : 80,
  115. editoptions: {
  116. size:50,
  117. maxlength: 32
  118. }
  119. }, {
  120. label : '用户姓名',
  121. name : 'username',
  122. editable: true,
  123. formoptions:{
  124. elmsuffix:" <span style='color:red'>*<span>"
  125. },
  126. editrules:{required:true},
  127. width : 80,
  128. editoptions: {
  129. size:50,
  130. maxlength: 120
  131. }
  132. }, {
  133. label : '机构名称',
  134. name : 'orgid',
  135. editable: true,
  136. width : 50,
  137. edittype :"select",
  138. formatter:"select",
  139. editoptions:{value:"${orgOptions}"}
  140. }, {
  141. label : '手机号码',
  142. name : 'mobile',
  143. editable: true,
  144. width : 80,
  145. editrules:{
  146. edithidden:true,
  147. custom:true, 
  148. custom_func: function(strFieldValue, strFieldName){
  149. var strTelephone = /^([\x00-\xff]+$)?$/; //非汉字
  150.  if(!strTelephone.test(strFieldValue)){
  151.    return [false, strFieldName+"应该为电话号"];
  152.  }
  153. if(strTelephone.length>100){
  154.    return [false, strFieldName+"字符数过多,大于100"];
  155. }
  156. return [true,""];
  157. }
  158. },
  159. editoptions: {
  160. size:50,
  161. maxlength: 50
  162. }
  163. } ,{
  164. label : '邮箱',
  165. name : 'email',
  166. editable: true,
  167. width : 80,
  168. editrules:{
  169. edithidden:true,
  170. custom:true, 
  171. custom_func: function(strFieldValue, strFieldName){
  172. var strMail = /^(.+\@.+\..+)?$/; //邮箱
  173.  if(!strMail.test(strFieldValue)){
  174.    return [false, strFieldName+"格式不正确"];
  175.  }
  176. if(strMail.length>100){
  177.    return [false, strFieldName+"字符数过多,大于100"];
  178. }
  179.  return [true,""];
  180. }
  181. },
  182. editoptions: {
  183. size:50,
  184. maxlength: 50
  185. }
  186. }, {
  187. label : '排序号',
  188. name : 'sortid',
  189. hidden : true,
  190. editable: true,
  191. width : 80,
  192. editrules:{
  193. edithidden:true,
  194. custom:true, 
  195. custom_func: function(strFieldValue, strFieldName){
  196. var strFloat = /^([-\+]?(((\d+)(\.\d+))|(\.\d+)|(\d*)))?$/;
  197.  if(!strFloat.test(strFieldValue)){
  198.    return [false, strFieldName+"应该为实数"];
  199.   }
  200. else
  201. {
  202.   return [true,""];
  203. }
  204. }
  205. },
  206. editoptions: {
  207. size:50,
  208. maxlength: 5
  209. }
  210. },{
  211. label : '用户类型',
  212. name : 'usertype',
  213. editable: true,
  214. edittype: "select",
  215. editoptions:{
  216. dataInit: function(elem){
  217. $(elem).width(300);
  218. },
  219. value : "后台用户:后台用户;前台用户:前台用户;综合用户:综合用户"
  220. },
  221. editrules:{edithidden:true},
  222. width : 45
  223. }, {
  224. label : '创建人',
  225. name : 'insertusername',
  226. editable: false,
  227. width : 45
  228. }, {
  229. label : '创建时间',
  230. name : 'inserttime',
  231. editable: false,
  232. width : 70
  233. } ],
  234. rownumbers : true,//添加左侧行号
  235. viewrecords : true,//是否在浏览导航栏显示记录总数
  236. rowNum : 15,//每页显示记录数
  237. rowList : [10,15,20,30,40,50 ],//用于改变显示行数的下拉列表框的元素数组。
  238. autowidth : true,
  239. height : 'auto',
  240. pager : "#jqGridPager"
  241. });
  242. $('#jqGrid').navGrid('#jqGridPager',
  243. {
  244. add : true,
  245. edit : true,
  246. del : true,
  247. search : true,
  248. refresh : false,
  249. view : true,
  250. position : "left",
  251. cloneToTop : true
  252. },
  253. //点击编辑触发的区域
  254. {
  255. closeAfterEdit : true,
  256. recreateForm : true,
  257. width:600,
  258. beforeShowForm:function(formid){
  259. var useridObj = formid.find('#userid');
  260. useridObj.attr('readOnly',true);
  261. useridObj.css({'background':'#cccccc'});
  262. },
  263. beforeSubmit: function(postdata, formid){
  264. var keyid = postdata.jqGrid_id;
  265. $.each(postdata,function (index, value) {
  266. if(index!="oper"){
  267. modifyJosnKey(postdata,index,"user."+index);
  268. }
  269. })
  270. postdata["user.keyid"]=keyid;
  271. return [true,'']; //返回值必须这么写 目前没找到原因,用true 和 返回对象都不好使。待查
  272. },
  273. afterSubmit: function(response,postdata) //
  274. {
  275. var res=eval('(' + response.responseText + ')');
  276. if(res.flag)
  277. {
  278. parent.layer.alert(res.message, {
  279. skin: 'layui-layer-molv' //样式类名
  280. ,closeBtn: 0
  281. });
  282. return [true,res.message,''];
  283. }else{
  284. parent.layer.alert(res.message, {
  285. skin: 'layui-layer-molv' //样式类名
  286. ,closeBtn: 0
  287. });
  288. return [false,res.message,''];
  289. }
  290. },
  291. errorTextFormat : function(data) {
  292. return 'Error: ' + data.responseText
  293. }
  294. },
  295. //添加操作区
  296. {
  297. closeAfterAdd : true, //添加完成后关闭
  298. width:600,
  299. serializeEditData: function(postdata) { //提前数据前,加工数据
  300. $.each(postdata,function(index,value){
  301. if(index!="oper"){
  302. modifyJosnKey(postdata,index,"user."+index);
  303. }
  304. })
  305. postdata["user.keyid"] = "";
  306. return postdata;
  307. },
  308. beforeShowForm:function(formid){
  309. $("#orgid").val(currentOrgID);
  310. },
  311. afterShowForm: function (formid){ //点击添加按钮显示表单后,用于绑定事件
  312. var useridObj = formid.find('#userid');
  313. useridObj.blur(function(){
  314. verifyUser(useridObj.val());
  315. });
  316. },
  317. afterSubmit: function(response,postdata) //
  318. {
  319. var res=eval('(' + response.responseText + ')');
  320. if(res.flag)
  321. {
  322. parent.layer.alert(res.message, {
  323. skin: 'layui-layer-molv' //样式类名
  324. ,closeBtn: 0
  325. });
  326. return [true,res.message,''];
  327. }else{
  328. parent.layer.alert(res.message, {
  329. skin: 'layui-layer-molv' //样式类名
  330. ,closeBtn: 0
  331. });
  332. return [false,res.message,''];
  333. }
  334. },
  335. errorTextFormat : function(data) {
  336. return 'Error: ' + data.responseText
  337. }
  338. },
  339. //删除操作区
  340. {
  341. afterSubmit: function(response,postdata)
  342. {
  343. var res=eval('(' + response.responseText + ')');
  344. if(res.flag)
  345. {
  346. parent.layer.alert(res.message, {
  347. skin: 'layui-layer-molv' //样式类名
  348. ,closeBtn: 0
  349. });
  350. return [true,res.message,''];
  351. }else{
  352. parent.layer.alert(res.message, {
  353. skin: 'layui-layer-molv' //样式类名
  354. ,closeBtn: 0
  355. });
  356. return [false,res.message,''];
  357. }
  358. },
  359. errorTextFormat : function(data) {
  360. return 'Error: ' + data.responseText
  361. }
  362. },{
  363. // search options 这里支持多条件查询
  364. multipleSearch: true,
  365. closeAfterSearch: true,
  366. sopt:['eq','ne','cn','nc','lt','le','gt','ge'],
  367. afterSubmit: function(r, data) {
  368. var messageString = r.responseText;
  369. var mesObj = eval('(' + messageString + ')');
  370. return [mesObj.state, mesObj.message];
  371. }
  372. }
  373. )
  374. .navButtonAdd("#jqGridPager",{
  375. caption:'分配角色',
  376. onClickButton:function(){
  377. var selectedRowId = $("#jqGrid").jqGrid("getGridParam", "selrow");
  378. if (!selectedRowId) {
  379. alert("请先选择需要编辑的行!");
  380. return false;
  381. } else {
  382. var UserID=selectedRowId;
  383. function zTreeOnCheck(event, treeId, treeNode) {
  384. //myconsole.log(treeNode);
  385. $.post("${ctx}/myconsole/user/saveUserRole",{"userid":UserID,"roleid":treeNode.id,"checked":treeNode.checked},function(data){
  386. parent.layer.msg(data);
  387. })
  388. };
  389. var zTreeObj;
  390. var zNodes;
  391. var setting = {
  392. check: {
  393. enable: true,
  394. chkboxType:{ "Y" : "ps", "N" : "ps" },
  395. autoCheckTrigger: true
  396. },
  397. data: {
  398. simpleData: {
  399. idKey:"id",
  400. pIdKey:"upperid",
  401. enable:true,
  402. rootPId:"0"
  403. }
  404. },
  405. callback: {
  406. onCheck: zTreeOnCheck
  407. }
  408. };
  409. $.ajax({
  410. url : "${ctx}/myconsole/user/getRoleTree?userid=" + UserID,
  411. type : "post",
  412. dataType : "json",
  413. success : function(data) {
  414. var zNodes = [];
  415. var roleInfo = data;
  416. roleInfo.forEach(function(item,index){
  417. zNodes.push({id:item.keyid,pId:0,name:item.rolename,istype:true,checked:item.chk});
  418. })
  419. $.fn.zTree.init($("#RoleTree"), setting, zNodes);//初始化树节点时,添加同步获取的数据
  420. var zTree = $.fn.zTree.getZTreeObj("tree");//获取zTree对象
  421. }
  422. });
  423. $('<div id="dlgSetRole"><ul id="RoleTree" class="ztree"></ul></div>').dialog({
  424. title : '分配角色',
  425. width : 300,
  426. height : 400,
  427. closed : false,
  428. cache : false,
  429. modal : true,
  430. });
  431. $(".ui-dialog-titlebar-close").click(function(){
  432. $("#dlgSetRole").remove();
  433. });
  434. }
  435. },
  436. id:'role'
  437. }).navButtonAdd("#jqGridPager",{
  438. caption:'坐席分机构',
  439. onClickButton:function(){
  440. var selectedRowId = $("#jqGrid").jqGrid("getGridParam", "selrow");
  441. if (!selectedRowId) {
  442. alert("请先选择需要编辑的行!");
  443. return false;
  444. } else {
  445. var UserID=selectedRowId;
  446. function zTreeOnCheck(event, treeId, treeNode) {
  447. //myconsole.log(treeNode);
  448. $.post("${ctx}/myconsole/user/saveUserOrg",{"userkeyid":UserID,"orgid":treeNode.id,"orgname":treeNode.name,"checked":treeNode.checked},function(data){
  449. parent.layer.msg(data);
  450. })
  451. };
  452. var zTreeObj;
  453. var zNodes;
  454. var setting = {
  455. check: {
  456. enable: true,
  457. chkboxType:{ "Y" : "ps", "N" : "ps" },
  458. autoCheckTrigger: true
  459. },
  460. data: {
  461. simpleData: {
  462. idKey:"id",
  463. pIdKey:"upperid",
  464. enable:true,
  465. rootPId:"0"
  466. }
  467. },
  468. callback: {
  469. onCheck: zTreeOnCheck
  470. }
  471. };
  472. $.ajax({
  473. url : "${ctx}/myconsole/user/getOrgTree?userkeyid=" + UserID,
  474. type : "post",
  475. dataType : "json",
  476. success : function(data) {
  477. var zNodes = [];
  478. var roleInfo = data;
  479. roleInfo.forEach(function(item,index){
  480. zNodes.push({id:item.orgid,pId:0,name:item.orgname,istype:true,checked:item.chk});
  481. })
  482. $.fn.zTree.init($("#OrgTree"), setting, zNodes);//初始化树节点时,添加同步获取的数据
  483. var zTree = $.fn.zTree.getZTreeObj("tree");//获取zTree对象
  484. }
  485. });
  486. $('<div id="dlgSetRole"><ul id="OrgTree" class="ztree"></ul></div>').dialog({
  487. title : '坐席分机构',
  488. width : 500,
  489. height : 550,
  490. closed : false,
  491. cache : false,
  492. modal : true,
  493. });
  494. $(".ui-dialog-titlebar-close").click(function(){
  495. $("#dlgSetRole").remove();
  496. });
  497. }
  498. },
  499. id:'agentorg'
  500. }) .navButtonAdd("#jqGridPager",{
  501. caption:'重置密码',
  502. onClickButton:function(){
  503. var selectedRowId = $("#jqGrid").jqGrid("getGridParam", "selrow");
  504. if (!selectedRowId) {
  505. alert("请先选择需要编辑的行!");
  506. return false;
  507. } else {
  508. var UserID=selectedRowId;
  509. $.post("${ctx}/myconsole/user/initPass",{"keyid":UserID},function(data){
  510. if(data){
  511. alert("密码修改成功,默认密码为${defaultPassword}");
  512. }else{
  513. alert("修改失败");
  514. }
  515. })
  516. }
  517. }
  518. }
  519. );
  520. })
  521. </script>
  522. <title>我的桌面</title>
  523. </head>
  524. <body>
  525. <div class="easyui-layout" data-options="fit:true">
  526. <div region="west" split="true" style="width:250px;height:100%;background-color:#f5f5f5">
  527. <ul id="treeDemo" class="ztree">
  528. </ul>
  529. </div>
  530. <div region="center" id="pageright">
  531. <div class="page-container">
  532. <table id="jqGrid"></table>
  533. <div id="jqGridPager"></div>
  534. </div>
  535. </div>
  536. </div>
  537. </body>
  538. </html>
  539. <script>
  540. //加载所选机构ID下面的人员
  541. function setGrid(OrgID,OrgName) {
  542. $("#jqGrid").jqGrid('setGridParam', {
  543. datatype : 'json',
  544. postData : {OrgID:currentOrgID}
  545. }).jqGrid('setCaption', OrgName).trigger("reloadGrid");
  546. }
  547. function verifyUser(userID){
  548. if(userID == "") return ;
  549. var errorShow = $(".FormError");
  550. errorShow.html("").hide();
  551. $.post("${ctx}/myconsole/user/verifyUser", {'userID':userID},
  552. function(data){
  553. if(data.length>0){
  554. $('#userid').val("");
  555. errorShow.html("该登录账号["+userID+"]已存在,请尝试其他用户名").show();
  556. }
  557. }
  558. );
  559. }
  560. </script>