class_assign.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. {extend name="public/layout" /} {block name="title"}组织结构{/block} {block name="body"}
  2. <style>
  3. html,
  4. body {
  5. display: block;
  6. width: 100%;
  7. height: 100%;
  8. background-color: #fff;
  9. }
  10. .cardheader {
  11. padding-left: 10px;
  12. }
  13. .laytable-cell-1-0-1 {
  14. height: 32px !important;
  15. line-height: 32px !important;
  16. }
  17. .layui-tree-set,
  18. .layui-tree-entry {
  19. margin-top: 5px !important;
  20. }
  21. .layui-table tr {
  22. height: 7vh;
  23. }
  24. @media screen and (min-width: 992px) {
  25. .layui-col-md9 {
  26. margin-left: 1%;
  27. width: 74%;
  28. }
  29. }
  30. .layui-table thead tr,
  31. .layui-table-header {
  32. background-color: #D8E6F1 !important;
  33. }
  34. #root-list {
  35. border-right: 1px solid #f6f6f6;
  36. }
  37. #addRoot {
  38. border-top: 1px solid #f6f6f6;
  39. }
  40. .root {
  41. cursor: pointer;
  42. text-align: center;
  43. padding: 10px 1px;
  44. font-size: 1rem;
  45. font-weight: bold;
  46. }
  47. .root.selected {
  48. font-size: x-large;
  49. color: #269efb;
  50. }
  51. .root:hover {
  52. font-size: x-large;
  53. color: #269efb;
  54. }
  55. .layui-form-label {
  56. width: 150px;
  57. }
  58. .layui-input-block {
  59. margin-left: 180px;
  60. }
  61. .strucinfo {
  62. cursor: pointer;
  63. }
  64. .setleader {
  65. float: right;
  66. display: none;
  67. }
  68. .setleader:hover {
  69. display: block;
  70. }
  71. .leader {
  72. float: right;
  73. }
  74. /*重要 样式*/
  75. .layui-tree-entry.tree-node-current .layui-tree-main {
  76. background-color: #d7edbf87;
  77. }
  78. /*重要 样式*/
  79. .layui-btn.layui-btn-success {
  80. background-color: #009688;
  81. }
  82. .filterbutton {
  83. float: right;
  84. }
  85. .layui-layer-content {
  86. overflow: inherit !important;
  87. }
  88. .layui-zz-box {
  89. border: 1px solid #f2f2f2;
  90. margin-right: 5px;
  91. }
  92. .list>ul:first-child>li>div {
  93. background-color: #f2f2f2;
  94. display: block;
  95. padding: 5px
  96. }
  97. .list li {
  98. min-width: 150px;
  99. }
  100. .list li div {
  101. padding: 3px;
  102. padding-right: 5px;
  103. }
  104. .list>ul ul {
  105. margin-left: 15px;
  106. }
  107. .list .op {
  108. float: right;
  109. margin-left: 2px;
  110. }
  111. .list i.op:hover,
  112. .list i.group:hover,
  113. .list span:hover {
  114. cursor: pointer;
  115. }
  116. .list span {
  117. overflow: hidden;
  118. text-overflow: ellipsis;
  119. white-space: nowrap;
  120. max-width: 84px;
  121. display: inline-block;
  122. }
  123. .list li i:first-child {
  124. position: relative;
  125. top: -6px;
  126. margin-right: 5px;
  127. }
  128. .list{
  129. padding-bottom: 24px;
  130. }
  131. .everydepart {
  132. display: block;
  133. position: relative;
  134. padding-right: 24px !important;
  135. }
  136. .everydepart .checkdiv {
  137. display: block;
  138. position: absolute;
  139. right: 4px;
  140. top: 10px;
  141. }
  142. .addbtn {
  143. position: absolute;
  144. display: block;
  145. width: 48px;
  146. height: 32px;
  147. top: 40%;
  148. left: 50%;
  149. margin-left: -24px;
  150. }
  151. .clearfix {
  152. clear: both;
  153. }
  154. .clearfix::after {
  155. clear: both;
  156. content: ' ';
  157. display: table;
  158. }
  159. .clearfix::before {
  160. content: ' ';
  161. display: table;
  162. }
  163. .height100 {
  164. height: 100%;
  165. }
  166. .showdepartbox {
  167. border: 1px solid #f2f2f2;
  168. }
  169. .left {
  170. float: left;
  171. }
  172. .right {
  173. float: right;
  174. }
  175. .everynowdepart {
  176. position: relative;
  177. height: 32px;
  178. padding-left: 16px;
  179. line-height: 32px;
  180. border-bottom: 1px solid #e9e9e9;
  181. padding-right: 48px;
  182. }
  183. .del {
  184. position: absolute;
  185. top: 0;
  186. right: 0;
  187. height: 32px;
  188. width: 48px;
  189. text-align: center;
  190. cursor: pointer;
  191. }
  192. .rightitlebox {
  193. padding: 0 8px;
  194. border-bottom: 1px solid #e4e4e4;
  195. }
  196. div{
  197. box-sizing: border-box;
  198. }
  199. .leftcontentbox{
  200. position: relative;
  201. height: 100%;
  202. overflow: hidden;
  203. }
  204. .layui-zz-box{
  205. display: block;
  206. height: 100%;
  207. }
  208. .layui-fluid {
  209. padding: 15px 0;
  210. }
  211. </style>
  212. <body>
  213. <div class="layui-fluid height100">
  214. <div class="layui-card height100">
  215. <div class="layui-card-body height100">
  216. <div class="layui-row height100">
  217. <div class="layui-col-md12 layui-col-xs12 layui-col-sm12 height100">
  218. <div class="layui-tab layui-tab-brief height100" lay-filter="component-tabs-hash">
  219. <div class="layui-tab-content height100">
  220. <div class="layui-tab-item layui-show clearfix height100">
  221. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 leftcontentbox" style=" min-width: 200px;">
  222. <div class="layui-zz-box" style="overflow: auto;">
  223. <div class="tree">
  224. <div class="list">
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="layui-col-md2 layui-col-xs2 layui-col-sm2 " style="position: unset;height: 85vh;">
  230. <button type="button" class="addbtn">添加</button>
  231. <input type="hidden" id="departinput" />
  232. </div>
  233. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 showdepartbox" style="overflow: auto;height: 85vh;">
  234. <div class="clearfix rightitlebox">
  235. <div class="left departnum">已选择0个部门</div>
  236. <div class="right alldel" style="cursor: pointer;">全部清除</div>
  237. </div>
  238. <div class="nowdepartbox">
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. {/block} {block name="js"}
  250. <script>
  251. layui.config({
  252. base: '__LAYUI__/',
  253. }).extend({
  254. index: 'lib/index' //主入口模块
  255. }).use(['index', 'jquery', 'table', 'tree', 'layer'], function() {
  256. var table = layui.table,
  257. tree = layui.tree,
  258. layer = layui.layer,
  259. $ = layui.jquery,
  260. element = layui.element,
  261. form = layui.form;
  262. var jiaojie = function(from, to, callback) {
  263. return $.ajax({
  264. type: 'post',
  265. url: '{:url("org/receive")}',
  266. data: {
  267. from: from,
  268. to: to
  269. },
  270. success: function(res) {
  271. callback(res)
  272. }
  273. })
  274. }
  275. var operate = {
  276. struct: function() {
  277. var that = this;
  278. that.send([], '{:url("train/class_assign")}', function(res) {
  279. if(res.code == 0) {
  280. $('.list').html(that.setStruct(res.data,res.checkOrg));
  281. } else {
  282. $('.list').html('<span>' + res.msg + '</span>');
  283. }
  284. $('.everydepart').click(function() {
  285. $(this).children('.checkdiv')[0].checked = !$(this).children('.checkdiv')[0].checked;
  286. })
  287. $('.everydepart .checkdiv').click(function(e) {
  288. e.stopPropagation();
  289. })
  290. $('.addbtn').click();
  291. });
  292. },
  293. send: function(data, url, callback) {
  294. if(data.length == 0) {
  295. return $.ajax({
  296. type: 'get',
  297. url: url,
  298. data: {'id':{$id}},
  299. success: function(res) {
  300. callback(res)
  301. }
  302. })
  303. }
  304. return $.ajax({
  305. type: 'post',
  306. url: url,
  307. data: data,
  308. success: function(res) {
  309. callback(res)
  310. }
  311. })
  312. },
  313. setStruct: function(data,checkOrg) {
  314. var that = this;
  315. var arr=checkOrg?checkOrg.split(','):[];
  316. var html = '<ul>';
  317. data.forEach(function(elem, index) {
  318. var flag=false;
  319. html += '<li data-id="' + elem.id + '" data-level="' + elem.level + '"><div class="everydepart">';
  320. if(elem.children.length !== 0)
  321. html += '<i class="group layui-icon layui-icon-triangle-r layui-icon-triangle-d"></i>';
  322. else
  323. html += '<i class="layui-icon layui-icon-user"></i>';
  324. html += '<span>' + elem.title + '</span><span>(' + elem.all_count + ')</span>';
  325. for(var i in arr){
  326. if(arr[i]==elem.id){
  327. html += '<input data-did="' + elem.id + '" data-title="' + elem.title + '" class="checkdiv" type="checkbox" checked /></div>';
  328. flag=true;
  329. }
  330. }
  331. if(!flag){
  332. html += '<input data-did="' + elem.id + '" data-title="' + elem.title + '" class="checkdiv" type="checkbox" /></div>';
  333. }
  334. if(elem.children.length > 0) {
  335. html += that.setStruct(elem.children,checkOrg);
  336. }
  337. html += '</li>';
  338. });
  339. html += '</ul>';
  340. return html
  341. }
  342. }
  343. // 结构初始化
  344. operate.struct();
  345. $('.addbtn').click(function(e) {
  346. var arr = $('#departinput').val() ? JSON.parse($('#departinput').val()) : {};
  347. for(var i = 0; i < $('.checkdiv').length; i++) {
  348. if($('.checkdiv')[i].checked) {
  349. arr[$($('.checkdiv')[i]).data('did')] = $($('.checkdiv')[i]).data('title');
  350. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'none');
  351. }
  352. }
  353. var str = "";
  354. var len = 0;
  355. for(var j in arr) {
  356. len = len + 1;
  357. str += '<div class="everynowdepart">' +
  358. '<span>' + arr[j] + '</span>' +
  359. '<div data-did="' + j + '" class="del">删除</div>' +
  360. '</div >';
  361. }
  362. $('.departnum').html('已选择' + len + '个部门');
  363. $('.nowdepartbox').html(str);
  364. $('#departinput').val(JSON.stringify(arr));
  365. $('.del').click(function() {
  366. $(this).parents('.everynowdepart').remove();
  367. $('.departnum').html('已选择' + $('.nowdepartbox .everynowdepart').length + '个部门');
  368. var arr = $('#departinput').val() ? JSON.parse($('#departinput').val()) : {};
  369. for(var i = 0; i < $('.checkdiv').length; i++) {
  370. delete arr[$(this).data('did')];
  371. if($($('.checkdiv')[i]).data('did') == $(this).data('did')) {
  372. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'block');
  373. }
  374. }
  375. $('#departinput').val(JSON.stringify(arr));
  376. })
  377. })
  378. $('.alldel').click(function() {
  379. $('.nowdepartbox').html('');
  380. $('.departnum').html('已选择0个部门');
  381. $('#departinput').val("");
  382. for(var i = 0; i < $('.checkdiv').length; i++) {
  383. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'block');
  384. }
  385. })
  386. });
  387. </script>
  388. </body>
  389. {/block}