userGroupManager.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <!-- 用户组管理 -->
  2. <div id="roleGroupList" class="plg-tab-container">
  3. <div class="layui-carousel" id="usergroupmanager_grid" style="margin-bottom: -15px;">
  4. <div carousel-item>
  5. <div id="usergroupmanager_grid_01" class="grid-container-full"></div>
  6. <div id="usergroupmanager_grid_01_edit" class="grid-container-full" style="min-height: 550px;">
  7. <div class="layui-row">
  8. <div class="layui-col-lg12">
  9. <div class="tc-title">
  10. <a href="#" id="usergroupmanager_btn_back" class="back-link"><i class="layui-icon layui-icon-return"></i></a>
  11. <span id="usergroupmanager_span_title"></span>
  12. </div>
  13. </div>
  14. </div>
  15. <div class="layui-row layui-col-space15" style="margin: 20px;">
  16. <div class="layui-col-lg12 tc-panel" style="min-height: 300px;">
  17. <div id="usergroupmanager_grid_sub" style="min-height: 450px;"></div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <style>
  25. #usergroupmanager_grid>div .layui-tab { margin-top: 0px;}
  26. #usergroupmanager_grid td {word-wrap:break-word;word-break:break-all;white-space:pre-wrap;}
  27. </style>
  28. <script type="text/javascript">
  29. /**
  30. * jiw
  31. * 2018.11.19
  32. * 用户组管理界面
  33. */
  34. (function () {
  35. var param = { "pageNum": 1, "pageSize": 10 };
  36. var grid = null, grid4 = null;
  37. var grid_wnd_0 = null;
  38. var form1 = null, tmp_gridrow_id = 0;
  39. var m = $(document.body).height();
  40. var stepindex = 0;
  41. //滑屏
  42. var carousel = layui.carousel;
  43. var car = carousel.render({
  44. elem: "#usergroupmanager_grid",
  45. autoplay: false,
  46. index: 0,
  47. arrow: "none",
  48. indicator: "none",
  49. anim: "fade",
  50. width: "100%", //设置容器宽度
  51. height: "100%"
  52. });
  53. function changePanel(name) {
  54. car.slide(name);
  55. }
  56. //返回主页面
  57. $("#usergroupmanager_btn_back").click(function () {
  58. changePanel("usergroupmanager_grid_01");
  59. return false;
  60. });
  61. gridInit(1);
  62. //主页面Grid
  63. function gridInit(type) {
  64. //用户组
  65. if (type === 1) {
  66. var gridOpts = {
  67. skin: "terrace",
  68. rowId: "p_id",
  69. columns: [
  70. { id: "p_id", name: "id", type: "ro", hidden: true },
  71. { id: "p_name", name: "名称", type: "ro", width:100 },
  72. { id: "p_description", name: "名称", type: "ro", width:100 },
  73. { id: "p_userlist", name: "用户列表", type: "ro", width: "*",className:"grid-td-word" },
  74. {
  75. id: "op", name: "操作", type: 'button', align: "center", width: 160, render: function () {
  76. return "修改^res_userGroupManage_edit1Click,删除^res_userGroupManage_del1Click,分配用户^res_userGroupManage_edit2Click";
  77. }
  78. }
  79. ],
  80. multiselect: false,
  81. toolbar: [
  82. {
  83. type: "input",
  84. name: "search",
  85. label: "查询条件:",
  86. placeholder: "用户组名称",
  87. offsetLeft: 10
  88. }, { type: "newcolumn" },
  89. { type: "button", name: "btn_search", value: "查询" },
  90. { type: "newcolumn" },
  91. { type: "newcolumn" },
  92. {
  93. type: "button",
  94. name: "btn_add",
  95. className: "plg-toolbar-right",
  96. offsetLeft: 20,
  97. value: "<i class='layui-icon layui-icon-add-1'></i>新增"
  98. }, { type: "newcolumn" }
  99. ],
  100. imagePath: "/prologui/assets/PlgGrid",
  101. url: '/api/service-users/usergroup/getPlgFxUsergroupPage/v1.0',
  102. type: "post",
  103. params: param,
  104. contentType: "application/x-www-form-urlencoded",
  105. page: true,
  106. totalCount: "totalCount"
  107. };
  108. grid4 = new PlgGrid(gridOpts);
  109. grid4.renderTo("usergroupmanager_grid_01");
  110. grid4.loadData();
  111. //工具栏按钮事件
  112. grid4.attachToolBarEvent("onButtonClick", function (name) {
  113. // 查询
  114. if (name === "btn_search") {
  115. grid4.setParams(grid4.getToolBarForm().getFormData());
  116. grid4.reload();
  117. }
  118. // 新增
  119. else if (name === "btn_add") {
  120. addusergroup();
  121. }
  122. });
  123. // 双击行
  124. grid4.on("onRowDblClicked", function () {
  125. show_usergroupinfo(grid4.getSelectedRowId(), grid4.getSelectedRowData());
  126. });
  127. }
  128. }
  129. //添加用户组
  130. function addusergroup() {
  131. stepindex = 0;
  132. var str = `<div class="layui-col-lg12 tc-15-step" id="usergroupmanager_grid_useradd_main">
  133. <ol>
  134. <li class="succeed">
  135. <div class="tc-15-step-name"><span class="tc-15-step-num">1</span>填写用户组信息</div>
  136. <div class="tc-15-step-arrow"></div>
  137. </li>
  138. <li class="disabled">
  139. <div class="tc-15-step-name"><span class="tc-15-step-num">2</span>分配用户</div>
  140. <div class="tc-15-step-arrow"></div>
  141. </li>
  142. <li class="disabled">
  143. <div class="tc-15-step-name"><span class="tc-15-step-num">3</span>完成</div>
  144. <div class="tc-15-step-arrow"></div>
  145. </li>
  146. </ol>
  147. </div>
  148. <div class="layui-col-lg12" style="min-height: 280px;">
  149. <div id="usergroupmanager_grid_useradd_content"></div>
  150. </div>
  151. <div class="layui-col-lg12 button-ft">
  152. <button class="layui-btn layui-btn-sm layui-btn-normal" id="usergroupadd_btn_next">下一步</button>
  153. </div>`;
  154. $("#usergroupmanager_grid_sub").html(str);
  155. $("#usergroupadd_btn_next").show();
  156. $("ol li").each(function () {
  157. if ($(this).index() === 0) {
  158. $(this).removeClass("disabled");
  159. $(this).addClass("succeed");
  160. }
  161. else {
  162. $(this).removeClass("succeed");
  163. $(this).addClass("disabled");
  164. }
  165. });
  166. usergroupFormInit(0, {});
  167. changePanel("usergroupmanager_grid_01_edit");
  168. $("#usergroupmanager_grid_useradd_content").height((m > 530) ? m - 400 : m);
  169. $("#usergroupmanager_grid_sub").width("100%");
  170. $("#usergroupmanager_grid_01_edit .tc-panel").attr("style", "min-height: 400px;");
  171. $("#usergroupadd_btn_next").click(function () {
  172. if (stepindex === 0) {
  173. var b = form1.validate();
  174. if (!b) return;
  175. var fd = form1.getFormData();
  176. var rdata = save_usergroupinfo(grid4, "/api/service-users/usergroup/insertPlgFxUsergroup/v1.0", "post", "application/x-www-form-urlencoded", fd);
  177. if (rdata === null) {
  178. layer.msg("获取用户组信息失败!");
  179. return;
  180. }
  181. tmp_gridrow_id = rdata.p_id;
  182. $("#usergroupmanager_grid_useradd_content").html("");
  183. usergroupInit(0, rdata);
  184. }
  185. else if (stepindex === 1) {
  186. //var b = save_usergroup(0);
  187. //if (b) {
  188. $("#usergroupmanager_grid_useradd_content").html("<h1>用户组新增成功,3秒后返回!</h1>");
  189. grid4.reload();
  190. $("#usergroupadd_btn_next").hide();
  191. setTimeout(function () { changePanel("usergroupmanager_grid_01"); }, 3000);
  192. //}
  193. }
  194. stepindex++;
  195. $("ol li").each(function () {
  196. if (stepindex === $(this).index()) {
  197. $(this).removeClass("disabled");
  198. $(this).addClass("succeed");
  199. }
  200. });
  201. });
  202. }
  203. //用户组表单
  204. function usergroupFormInit(ntype, rdata) {
  205. var tit = "新增用户组";
  206. var rediv = "usergroupmanager_grid_useradd_content";
  207. if (ntype === 1) {
  208. rediv = "usergroupmanager_grid_sub";
  209. tit = "用户组 [" + rdata.p_name + "] 信息修改";
  210. }
  211. $("#" + rediv).html("");
  212. $("#usergroupmanager_span_title").html(tit);
  213. var formcfg = {
  214. renderer: rediv,
  215. items: [
  216. { type: "settings", inputWidth: 340, width: 550, labelWidth: 80, position: "label-left", labelAlign: "left" },
  217. { type: "input", name: "p_name", label: "用户组名称:", editable: false, validate: "NotEmpty", required: true },
  218. { type: "input", name: "p_description", label: "用户组描述:", validate: "NotEmpty", required: true, rows: 5 },
  219. { type: "button", name: "btn_save_userinfo", offsetLeft: 80, value: "保存", hidden: (ntype != 1) },
  220. { type: "hidden", name: "p_id" }
  221. ]
  222. };
  223. form1 = new PlgForm(formcfg);
  224. form1.setFormData(rdata);
  225. if (ntype === 1) {
  226. form1.getDForm().disableItem("p_name");
  227. }
  228. form1.attachEvent("onButtonClick", function (name) {
  229. if (name === "btn_save_userinfo") {
  230. var fd = form1.getFormData();
  231. save_usergroupinfo(grid4, "/api/service-users/usergroup/updatePlgFxUsergroup/v1.0", "put", "application/x-www-form-urlencoded", fd);
  232. }
  233. });
  234. }
  235. //用户组分配用户
  236. function usergroupInit(ntype, rdata) {
  237. $("#usergroupmanager_span_title").html("用户组 [" + rdata.p_name + "] 分配用户");
  238. var rediv = "usergroupmanager_grid_useradd_content";
  239. param.type = 0;
  240. var tbar = [
  241. {
  242. type: "input",
  243. name: "search",
  244. label: "查询条件:",
  245. placeholder: "用户名称",
  246. offsetLeft: 10,
  247. width: 100
  248. }, { type: "newcolumn" },
  249. {
  250. type: "combo",
  251. name: "type",
  252. label: "状态:",
  253. offsetLeft: 10,
  254. width: 100,
  255. options: [{ text: "未分配", value: "0" }, { text: "已分配", value: "1" }],
  256. hidden: (ntype === 0)
  257. }, { type: "newcolumn" },
  258. { type: "button", name: "btn_search", offsetLeft: 10, value: "查询" }, { type: "newcolumn" },
  259. { type: "button", name: "btn_save", offsetLeft: 10, value: "保存" }
  260. ];
  261. if (ntype === 1) {
  262. rediv = "usergroupmanager_grid_sub";
  263. //param.type = 1;
  264. }
  265. $("#" + rediv).html("");
  266. param.usergroupid = rdata.p_id;
  267. var gridopt = {
  268. skin: "terrace",
  269. rowId: "p_id",
  270. columns: [
  271. { id: "p_id", name: "id", type: "ro", hidden: true },
  272. { id: "p_nickname", name: "用户名称", type: "ro" },
  273. { id: "p_username", name: "用户账号", type: "ro" }
  274. ],
  275. toolbar: tbar,
  276. multiselect: true,
  277. imagePath: "/prologui/assets/PlgGrid",
  278. url: "/api/service-users/usergroup/getAllocatedUser/v1.0",
  279. type: "post",
  280. contentType: "application/x-www-form-urlencoded",
  281. params: param,
  282. page: true,
  283. totalCount: "totalCount"
  284. };
  285. grid_wnd_0 = new PlgGrid(gridopt);
  286. grid_wnd_0.renderTo(rediv);
  287. grid_wnd_0.loadData();
  288. if (ntype === 1) {
  289. grid_wnd_0.attachToolBarEvent("onButtonClick", function (name) {
  290. // 查询
  291. if (name === "btn_search") {
  292. var p = grid_wnd_0.getToolBarForm().getFormData();
  293. p.pageNum = 1;
  294. p.pageSize = 10;
  295. p.usergroupid = rdata.p_id;
  296. grid_wnd_0.setParams(p);
  297. grid_wnd_0.reload();
  298. }
  299. else if (name === "btn_save") {
  300. save_usergroup(1);
  301. }
  302. });
  303. grid_wnd_0.getToolBarForm().getCombo("type").attachEvent("onChange", function (v, t) {
  304. var p = grid_wnd_0.getToolBarForm().getFormData();
  305. p.pageNum = 1;
  306. p.pageSize = 10;
  307. p.usergroupid = rdata.p_id;
  308. grid_wnd_0.setParams(p);
  309. grid_wnd_0.reload();
  310. });
  311. }
  312. }
  313. //用户组信息保存
  314. function save_usergroupinfo(grid, url, type, contentType, formData) {
  315. var rep = null;
  316. Prolog.ajax({
  317. url: url,
  318. type: type,
  319. contentType: contentType,
  320. data: formData,
  321. async: false,
  322. success: function (data) {
  323. if (data.success) {
  324. if (type === "put")
  325. layer.msg("保存成功!");
  326. grid.reload();
  327. rep = data.data;
  328. }
  329. else {
  330. layer.msg(data.message);
  331. }
  332. },
  333. error: function () {
  334. }
  335. });
  336. return rep;
  337. }
  338. //分配用户保存
  339. function save_usergroup(ntype) {
  340. var par, type, rsp = null;
  341. (ntype === 0) ? type = "0" : type = grid_wnd_0.getToolBarForm().getFormData().type;
  342. if (type === "0") {
  343. par = { "type": "1", "usergroupid": tmp_gridrow_id, "userids": grid_wnd_0.getCheckedIds() };
  344. }
  345. else if (type === "1") {
  346. par = { "type": "0", "usergroupid": tmp_gridrow_id, "userids": grid_wnd_0.getCheckedIds() };
  347. }
  348. if (grid_wnd_0.getCheckedIds() === "") return rsp;
  349. layer.msg("数据处理中...");
  350. Prolog.ajax({
  351. url: "/api/service-users/usergroup/allotUserGroup/v1.0",
  352. type: "post",
  353. contentType: "application/json",
  354. data: JSON.stringify(par),
  355. async: false,
  356. success: function (data) {
  357. if (typeof data != "object") data = JSON.parse(data);
  358. if (data.success) {
  359. layer.closeAll();
  360. if (ntype === 1) {
  361. grid_wnd_0.reload();
  362. grid4.reload();
  363. }
  364. rsp = data;
  365. }
  366. else {
  367. layer.open({
  368. type: 1, offset: "auto", id: 'layerError', title: "错误提示"
  369. , area: ["500px"], content: '<div style="padding: 10px;">' + data.message + '</div>'
  370. , btn: '关闭', btnAlign: 'r', shade: 0
  371. , yes: function () {
  372. layer.closeAll();
  373. }
  374. });
  375. rsp = null;
  376. }
  377. },
  378. error: function () {
  379. }
  380. });
  381. return rsp;
  382. }
  383. //查看用户组详细
  384. function show_usergroupinfo(rid, rdata) {
  385. grid4.selectRowById(rid);
  386. $("#usergroupmanager_span_title").html("用户组 [" + rdata.p_name + "] 信息查看");
  387. var str = `<ul>
  388. <li><span class='span-item-tit'>用户组名称</span>
  389. <span class='span-item-txt'>` + ((rdata.p_name === null) ? "" : rdata.p_name) + `</sapn></li>
  390. <li><span class='span-item-tit'>用户组描述</span>
  391. <span class='span-item-txt'>` + ((rdata.p_description === null) ? "" : rdata.p_description) + `</span></li>
  392. <li><span class='span-item-tit'>用户列表</span>
  393. <span class='span-item-txt'>` + ((rdata.p_userlist === null) ? "" : rdata.p_userlist) + `</span></li>
  394. </ul>`;
  395. $("#usergroupmanager_grid_sub").html(str);
  396. changePanel("usergroupmanager_grid_01_edit");
  397. }
  398. window.res_userGroupManage_del1Click = function (rid, rdata) {
  399. Prolog.delGridRowData(grid4, "/api/service-users/usergroup/deletePlgFxUsergroupById/v1.0", "", "", { "id": rid }, false);
  400. return false;
  401. };
  402. window.res_userGroupManage_edit1Click = function (rid, rdata) {
  403. grid4.selectRowById(rid);
  404. usergroupFormInit(1, rdata);
  405. changePanel("usergroupmanager_grid_01_edit");
  406. $("#usergroupmanager_grid_sub").width("100%");
  407. $("#usergroupmanager_grid_sub").height((m > 530) ? m - 260 : m);
  408. return false;
  409. };
  410. window.res_userGroupManage_edit2Click = function (rid, rdata) {
  411. grid4.selectRowById(rid);
  412. tmp_gridrow_id = rid;
  413. usergroupInit(1, rdata);
  414. changePanel("usergroupmanager_grid_01_edit");
  415. $("#usergroupmanager_grid_sub").width("100%");
  416. $("#usergroupmanager_grid_sub").height((m > 530) ? m - 260 : m);
  417. return false;
  418. };
  419. })();
  420. </script>