activity_assign.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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: 184px;
  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. width: 64%;
  169. }
  170. .left {
  171. float: left;
  172. }
  173. .right {
  174. float: right;
  175. }
  176. .everynowdepart {
  177. position: relative;
  178. height: 32px;
  179. padding-left: 16px;
  180. line-height: 32px;
  181. border-bottom: 1px solid #e9e9e9;
  182. padding-right: 48px;
  183. }
  184. .del {
  185. position: absolute;
  186. top: 0;
  187. right: 0;
  188. height: 32px;
  189. width: 48px;
  190. text-align: center;
  191. cursor: pointer;
  192. }
  193. .rightitlebox {
  194. padding: 0 8px;
  195. border-bottom: 1px solid #e4e4e4;
  196. }
  197. div{
  198. box-sizing: border-box;
  199. }
  200. .leftcontentbox{
  201. position: relative;
  202. height: 100%;
  203. overflow: hidden;
  204. width: 36%;
  205. }
  206. .rotate {
  207. transform: rotateY(90deg);
  208. }
  209. .layui-zz-box{
  210. display: block;
  211. height: 100%;
  212. }
  213. .layui-fluid {
  214. padding: 15px 0;
  215. }
  216. .keyword{
  217. height: 35px;
  218. margin: 4px;
  219. }
  220. .keywords{
  221. height: 35px;
  222. margin: 4px;
  223. }
  224. input[disabled][type="checkbox"]:checked::before {
  225. content: "\2713";
  226. background-color: #2196F3;
  227. color: #fff;
  228. position: absolute;
  229. top: 0;
  230. left: 0;
  231. width: 100%;
  232. border: 1px solid #2196F3;
  233. font-size: 12px;
  234. font-weight: bold;
  235. text-align: center;
  236. line-height: 18px;
  237. z-index: 999;
  238. }
  239. #range_person {
  240. height: calc(100vh - 130px);
  241. }
  242. </style>
  243. <body>
  244. <div class="layui-fluid height100">
  245. <div class="layui-card height100">
  246. <div class="layui-card-body height100">
  247. <div class="layui-row height100">
  248. <div class="layui-col-md12 layui-col-xs12 layui-col-sm12 height100">
  249. <div class="layui-tab layui-tab-brief height100" lay-filter="component-tabs-hash">
  250. <div class="layui-tab-content height100">
  251. <div class="layui-tab-item layui-show clearfix height100">
  252. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 leftcontentbox" style=" min-width: 200px;">
  253. <div class="layui-zz-box" >
  254. <div class="tree">
  255. <div class="clearfix rightitlebox">
  256. <div class="left departnum">
  257. <div class="layui-inline">
  258. <div class="layui-input-inline" style="width: auto;">
  259. <input type="text" name="keyword" placeholder="请输入关键字搜索" autocomplete="off" class="layui-input keyword" id="keyword_left_text">
  260. </div>
  261. </div>
  262. </div>
  263. <div class="" style="cursor: pointer;" id="left_search">
  264. <button class="layui-btn layuiadmin-btn keyword" lay-submit lay-filter="LAY-app-contlist-search">
  265. <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  266. </button>
  267. </div>
  268. </div>
  269. <div class="list" id="range_person" style="overflow: auto;"></div>
  270. </div>
  271. </div>
  272. </div>
  273. <div class="layui-col-md2 layui-col-xs2 layui-col-sm2 layui-hide" style="position: unset;height: 85vh;">
  274. <button type="button" class="addbtn">添加</button>
  275. <input type="hidden" id="departinput" />
  276. </div>
  277. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 showdepartbox" style="overflow: auto;height: 90vh;">
  278. <div class="clearfix rightitlebox">
  279. <div class="left departnum">
  280. <!-- 已选中{$count}人 -->
  281. <div class="layui-inline">
  282. <div class="layui-input-inline" style="width: auto;">
  283. <input type="text" name="keyword" id="keyword" placeholder="请输入关键字搜索" autocomplete="off" class="layui-input keyword">
  284. </div>
  285. </div>
  286. <div class="layui-inline" id="right_search">
  287. <button class="layui-btn layuiadmin-btn keyword" lay-submit lay-filter="LAY-app-contlist-search">
  288. <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  289. </button>
  290. </div>
  291. </div>
  292. <div class="right" style="cursor: pointer;">
  293. <!-- 取消选择 -->
  294. <button class="layui-btn layuiadmin-btn layui-btn-primary keywords" style="display: flex;align-items: center;" id="all_del">取消选择</button>
  295. </div>
  296. </div>
  297. <div class="nowdepartbox">
  298. <table id="LAY-employee-list" lay-filter="LAY-employee-list" style="margin-top:15px;"></table>
  299. </div>
  300. </div>
  301. </div>
  302. </div>
  303. </div>
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. </div>
  309. <script src="__STATIC__/layui/layui/layui.js"></script>
  310. <script src="__STATIC__/layui/layui/lay/modules/xm-select.js" type="text/javascript" charset="utf-8"></script>
  311. <script type="text/html" id="operateTpls">
  312. {{# if(d.is_manager){ }}
  313. <p class="strucinfo" data-leader="{{d.is_manager}}"><span>{{d.org_name}}</span><span class="leader" lay-event="removeleader"><img src="__STATIC__/img/managericon.png" style="width:80%" alt="" /></span></p>
  314. {{# }else{ }}
  315. <p class="strucinfo" data-leader="{{d.is_manager}}"><span>{{d.org_name}}</span><span class="setleader employee" lay-event="setleader"><i class="layui-icon layui-icon-friends"></i><img class="layui-hide" src="__STATIC__/img/managericon.png" style="width:80%" alt="" /></span></span></p>
  316. {{# } }}
  317. </script>
  318. <script type="text/html" id="operateTpl">
  319. <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="edit">取消选择</a>
  320. </script>
  321. {/block} {block name="js"}
  322. <script>
  323. layui.config({
  324. base: '__LAYUI__/',
  325. }).extend({
  326. index: 'lib/index' //主入口模块
  327. }).use(['index', 'jquery', 'table', 'tree', 'layer','element','form'], function() {
  328. var table = layui.table,
  329. tree = layui.tree,
  330. layer = layui.layer,
  331. $ = layui.jquery,
  332. element = layui.element,
  333. form = layui.form;
  334. //点击选择人员
  335. $(document).on('click','.leftcontentbox li',function(e){
  336. if (e.target.localName === 'i') {
  337. let o = $(this).next();
  338. if (o && o[0] && o[0].localName === 'ul') {
  339. if (!o[0].style.display || o[0].style.display == 'block') {
  340. o[0].style.display = 'none';
  341. e.target.className = "group layui-icon layui-icon-triangle-r"
  342. } else {
  343. o[0].style.display = 'block';
  344. e.target.className = "group layui-icon layui-icon-triangle-d"
  345. }
  346. }
  347. }
  348. if (!(e.target.localName == 'input')) {
  349. return;
  350. }
  351. //唯一class
  352. var perclass = $(this).data('perclass');
  353. //类型 per员工 org部门         
  354. var type = $(this).data('type');
  355. //选中/取消
  356. var c = $('.'+perclass).prop("checked");
  357. var res = c==true ? 1 : 0;
  358. //id
  359. var id = $(this).data('id');
  360. if (id>0) {
  361. var index = layer.load(1); //添加laoding,0-2两种方式
  362. $.ajax({
  363. url: '{:url("activity/activity_assign")}?id='+"{:$id}",
  364. data: {
  365. pid:id,type:type,res:res
  366. },
  367. type: 'get',
  368. success: function(res) {
  369. // $('.departnum').html("已选中"+res.count+"人");
  370. if (res.code==0) {
  371. for (var i = res.data.length - 1; i >= 0; i--) {
  372. $('.'+res.data[i]).prop("checked",c);
  373. }
  374. table.reload('LAY-employee-list', {});
  375. layer.close(index);
  376. }
  377. },
  378. error:function(res){
  379. layer.close(index);
  380. }
  381. });
  382. }
  383.             })
  384. //右侧搜索按钮
  385. $('#right_search').click(function(){
  386. var keyword = $('#keyword').val();
  387. table.reload('LAY-employee-list', {
  388. where: {
  389. keyword: keyword
  390. }
  391. , page: { curr: 1 }
  392. });
  393. });
  394. //左侧搜索
  395. $('#left_search').click(function(){
  396. var keyword = $('#keyword_left_text').val();
  397. operate.struct(keyword);
  398. });
  399. //取消全部
  400. $('#all_del').click(function(){
  401. operate.edit(-1);
  402. });
  403. //右侧选中人员列表
  404. var orgstrucUrl = '{:url("activity/activity_assign_list")}?id='+"{:$id}";
  405. table.render({
  406. elem: '#LAY-employee-list',
  407. url: orgstrucUrl,
  408. cols: [
  409. [{
  410. title: '序号',
  411. field: 'xh',
  412. width: '25%',
  413. align:'center',
  414. },
  415. {
  416. title: '姓名',
  417. field: 'name',
  418. width: '25%',
  419. align:'center',
  420. },{
  421. field: 'org_name',
  422. title: '部门',
  423. width: '25%',
  424. templet: '#operateTpls',
  425. align:'center',
  426. },
  427. {
  428. title: '操作',
  429. templet: '#operateTpl',
  430. width: '25%',
  431. align:'center',
  432. fixed:'right'
  433. }]
  434. ],
  435. page: true,
  436. limit: 10,
  437. height: 'full-160',
  438. limits: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
  439. text: '对不起,加载出现异常!'
  440. });
  441. table.on('tool(LAY-employee-list)', function (obj) {
  442. var data = obj.data;
  443. if (obj.event === 'edit') {
  444. operate.edit(data.id);
  445. }
  446. });
  447. var jiaojie = function(from, to, callback) {
  448. return $.ajax({
  449. type: 'post',
  450. url: '{:url("org/receive")}',
  451. data: {
  452. from: from,
  453. to: to
  454. },
  455. success: function(res) {
  456. callback(res)
  457. }
  458. })
  459. }
  460. var operate = {
  461. struct: function(keyword) {
  462. var that = this;
  463. that.send({'keyword':keyword}, '{:url("activity/get_person")}?id='+"{:$id}", function(res) {
  464. if(res.code == 0) {
  465. $('.list').html(that.setStruct(res.data,res.checkOrg));
  466. } else {
  467. $('.list').html('<span>' + res.msg + '</span>');
  468. }
  469. $('.everydepart .checkdiv').click(function(e) {
  470.                             var type = $(this).parents('li').data('type');
  471.                             var perclass = $(this).parents('li').data('perclass');
  472.                             var orgclass = $(this).parents('li').data('orgclass');
  473.                             var c = $('.'+perclass).prop("checked");
  474.                             if (type=='per') {
  475.                                 $('.'+perclass).prop('checked',c);
  476.                                 if (c===false) {
  477.                                     console.log(orgclass);
  478.                                     $('.per_'+orgclass).prop('checked',false);
  479.                                 }
  480.                             }else{
  481.                                 $('.'+orgclass).prop('checked',c);
  482.                             }
  483.                         })
  484. });
  485. },
  486. send: function(data, url, callback) {
  487. if(data.length == 0) {
  488. return $.ajax({
  489. type: 'get',
  490. url: url,
  491. data: {'id':{$id}},
  492. success: function(res) {
  493. callback(res)
  494. }
  495. })
  496. }
  497. return $.ajax({
  498. type: 'post',
  499. url: url,
  500. data: data,
  501. success: function(res) {
  502. callback(res)
  503. }
  504. })
  505. },
  506. setStruct: function(data,checkOrg) {
  507. var that = this;
  508. var arr=checkOrg?checkOrg.split(','):[];
  509. var html = '<ul>';
  510. data.forEach(function(elem, index) {
  511. var flag=false;
  512. html += '<li data-id="' + elem.id + '" data-level="' + elem.level + '" data-type='+elem.type+' data-perclass='+elem.per_class+' data-orgclass='+elem.org_class+'><div class="everydepart">';
  513. if(elem.children.length !== 0)
  514. html += '<i class="group layui-icon layui-icon-triangle-d"></i>';
  515. else
  516. html += '<i class="layui-icon layui-icon-user"></i>';
  517. html += '<span>' + elem.title + '</span>';
  518. for(var i in arr){
  519. if(arr[i]==elem.id){
  520. html += '<input data-did="' + elem.id + '" data-title="' + elem.title + '" data-class='+elem.class+' class="checkdiv '+elem.org_class+' '+elem.per_class+'" data-type="'+elem.type+'" type="checkbox" checked/></div>';
  521. flag=true;
  522. }
  523. }
  524. if(!flag){
  525. html += '<input data-did="' + elem.id + '" data-title="' + elem.title + '" data-class='+elem.class+' class="checkdiv '+elem.org_class+' '+elem.per_class+'" id="'+elem.class+'" data-type="'+elem.type+'" type="checkbox" /></div>';
  526. }
  527. html += '</li>';
  528. if(elem.children.length > 0) {
  529. html += that.setStruct(elem.children,checkOrg);
  530. }
  531. });
  532. html += '</ul>';
  533. return html
  534. },
  535. edit:function(eid){
  536. layer.confirm('确定取消指派此员工?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'] }, function (index) {
  537. $.ajax({
  538. url: '{:url("activity/del_assign")}?id='+"{:$id}",
  539. data: {
  540. eid: eid
  541. },
  542. type: 'post',
  543. success: function (res) {
  544. if (eid == -1) {
  545. $('input').prop('checked',false);
  546. } else {
  547. $(`.per_${eid}`).prop('checked',false);
  548. }
  549. if (res.code === 0) {
  550. layer.msg(res.msg, { anim: 0 });
  551. } else {
  552. layer.msg(res.msg, { anim: 6 });
  553. }
  554. var keywordcs = $('#keyword').val();
  555. table.reload('LAY-employee-list', {
  556. where: {
  557. keyword: keywordcs
  558. }
  559. , page: { curr: 1 }
  560. });
  561. }
  562. });
  563. });
  564. }
  565. }
  566. // 结构初始化
  567. operate.struct();
  568. $('.addbtn').click(function(e) {
  569. var arr = $('#departinput').val() ? JSON.parse($('#departinput').val()) : {};
  570. for(var i = 0; i < $('.checkdiv').length; i++) {
  571. if($('.checkdiv')[i].checked) {
  572. arr[$($('.checkdiv')[i]).data('did')] = $($('.checkdiv')[i]).data('title');
  573. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'none');
  574. }
  575. }
  576. var str = "";
  577. var len = 0;
  578. for(var j in arr) {
  579. len = len + 1;
  580. str += '<div class="everynowdepart">' +
  581. '<span>' + arr[j] + '</span>' +
  582. '<div data-did="' + j + '" class="del">删除</div>' +
  583. '</div >';
  584. }
  585. $('.departnum').html('已选择' + len + '个部门');
  586. $('.nowdepartbox').html(str);
  587. $('#departinput').val(JSON.stringify(arr));
  588. $('.del').click(function() {
  589. $(this).parents('.everynowdepart').remove();
  590. $('.departnum').html('已选择' + $('.nowdepartbox .everynowdepart').length + '个部门');
  591. var arr = $('#departinput').val() ? JSON.parse($('#departinput').val()) : {};
  592. for(var i = 0; i < $('.checkdiv').length; i++) {
  593. delete arr[$(this).data('did')];
  594. if($($('.checkdiv')[i]).data('did') == $(this).data('did')) {
  595. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'block');
  596. }
  597. }
  598. $('#departinput').val(JSON.stringify(arr));
  599. })
  600. })
  601. $('.alldel').click(function() {
  602. $('.nowdepartbox').html('');
  603. $('.departnum').html('已选择0个部门');
  604. $('#departinput').val("");
  605. for(var i = 0; i < $('.checkdiv').length; i++) {
  606. $($('.checkdiv')[i]).parents('.everydepart').css('display', 'block');
  607. }
  608. })
  609. });
  610. </script>
  611. </body>
  612. {/block}