distribution.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. {extend name="public/layout" /} {block name="title"}分配{/block} {block name="body"}
  2. <link rel="stylesheet" href="__STATIC__/css/csspc.css">
  3. <link rel="stylesheet" href="__STATIC__/css/font.css">
  4. <link rel="stylesheet" " href=" __STATIC__/css/common.css">
  5. <style>
  6. html,body{
  7. background: #f5f5f5;
  8. font-size: 12px;
  9. padding-bottom: 20px;
  10. box-sizing: border-box;
  11. min-width:1200px;
  12. overflow-x: auto;
  13. }
  14. .toptitbox{
  15. display: block;
  16. width:1200px;
  17. padding: 15px 10px;
  18. border: 1px solid #F0F0F0;
  19. background: #FCFCFC;
  20. margin-bottom: 10px;
  21. position: relative;
  22. line-height: 28px;
  23. }
  24. .golastbtn{
  25. display: block;
  26. margin-right: 21px;
  27. color: #000;
  28. background: url(__STATIC__/img/btn_bg.gif) repeat-x;
  29. border: 1px solid #C0C0C0;
  30. padding: 0 12px;
  31. *padding: 0 6px;
  32. height: 28px;
  33. cursor: pointer;
  34. }
  35. .mainbox{
  36. display: block;
  37. width:1200px;
  38. height:100%;
  39. padding-top: 20px;
  40. margin: 0 auto;
  41. }
  42. .bodys{
  43. padding: 10px 0;
  44. background-color: #fff;
  45. }
  46. .cardheader {
  47. padding-left: 10px;
  48. }
  49. .laytable-cell-1-0-1 {
  50. height: 32px !important;
  51. line-height: 32px !important;
  52. }
  53. .layui-tree-set,
  54. .layui-tree-entry {
  55. margin-top: 5px !important;
  56. }
  57. .layui-table tr {
  58. height: 7vh;
  59. }
  60. @media screen and (min-width: 992px) {
  61. .layui-col-md9 {
  62. margin-left: 1%;
  63. width: 74%;
  64. }
  65. }
  66. .layui-table thead tr,
  67. .layui-table-header {
  68. background-color: #D8E6F1 !important;
  69. }
  70. #root-list {
  71. border-right: 1px solid #f6f6f6;
  72. }
  73. #addRoot {
  74. border-top: 1px solid #f6f6f6;
  75. }
  76. .root {
  77. cursor: pointer;
  78. text-align: center;
  79. padding: 10px 1px;
  80. font-size: 1rem;
  81. font-weight: bold;
  82. }
  83. .root.selected {
  84. font-size: x-large;
  85. color: #269efb;
  86. }
  87. .root:hover {
  88. font-size: x-large;
  89. color: #269efb;
  90. }
  91. .layui-form-label {
  92. width: 150px;
  93. }
  94. .layui-input-block {
  95. margin-left: 180px;
  96. }
  97. .strucinfo {
  98. cursor: pointer;
  99. }
  100. .setleader {
  101. float: right;
  102. display: none;
  103. }
  104. .setleader:hover {
  105. display: block;
  106. }
  107. .leader {
  108. float: right;
  109. }
  110. /*重要 样式*/
  111. .layui-tree-entry.tree-node-current .layui-tree-main {
  112. background-color: #d7edbf87;
  113. }
  114. /*重要 样式*/
  115. .layui-btn.layui-btn-success {
  116. background-color: #009688;
  117. }
  118. .filterbutton {
  119. float: right;
  120. }
  121. .layui-layer-content {
  122. overflow: inherit !important;
  123. }
  124. .layui-zz-box {
  125. border: 1px solid #f2f2f2;
  126. margin-right: 5px;
  127. padding-left: 24px;
  128. }
  129. .list>ul:first-child>li>div {
  130. /*background-color: #f2f2f2;*/
  131. display: block;
  132. padding: 5px
  133. }
  134. .list li {
  135. min-width: 150px;
  136. }
  137. .list li div {
  138. padding: 3px;
  139. padding-right: 5px;
  140. }
  141. .list>ul ul {
  142. margin-left: 15px;
  143. }
  144. .list .op {
  145. float: right;
  146. margin-left: 2px;
  147. }
  148. .list i.op:hover,
  149. .list i.group:hover,
  150. .list span:hover {
  151. cursor: pointer;
  152. }
  153. .list span {
  154. overflow: hidden;
  155. text-overflow: ellipsis;
  156. white-space: nowrap;
  157. max-width: 184px;
  158. display: inline-block;
  159. }
  160. .list li i:first-child {
  161. position: relative;
  162. top: -6px;
  163. margin-right: 5px;
  164. }
  165. .list {
  166. padding-bottom: 24px;
  167. padding-right: 24px;
  168. }
  169. .everydepart {
  170. display: block;
  171. position: relative;
  172. padding-right: 24px !important;
  173. }
  174. .everydepart .checkdiv {
  175. display: block;
  176. position: absolute;
  177. right: 4px;
  178. top: 10px;
  179. }
  180. .addbtn {
  181. position: absolute;
  182. display: block;
  183. width: 48px;
  184. height: 32px;
  185. top: 40%;
  186. left: 50%;
  187. margin-left: -24px;
  188. }
  189. .clearfix {
  190. clear: both;
  191. }
  192. .clearfix::after {
  193. clear: both;
  194. content: ' ';
  195. display: table;
  196. }
  197. .clearfix::before {
  198. content: ' ';
  199. display: table;
  200. }
  201. .height100 {
  202. height: 100%;
  203. }
  204. .showdepartbox {
  205. /*border: 1px solid #f2f2f2;*/
  206. width: 64%;
  207. }
  208. .left {
  209. float: left;
  210. }
  211. .right {
  212. float: right;
  213. }
  214. .everynowdepart {
  215. position: relative;
  216. height: 32px;
  217. padding-left: 16px;
  218. line-height: 32px;
  219. border-bottom: 1px solid #e9e9e9;
  220. padding-right: 48px;
  221. }
  222. .del {
  223. position: absolute;
  224. top: 0;
  225. right: 0;
  226. height: 32px;
  227. width: 48px;
  228. text-align: center;
  229. cursor: pointer;
  230. }
  231. .rightitlebox {
  232. padding: 0 8px;
  233. border-bottom: 1px solid #e4e4e4;
  234. }
  235. div {
  236. box-sizing: border-box;
  237. }
  238. .leftcontentbox {
  239. position: relative;
  240. height: 100%;
  241. overflow: hidden;
  242. width: 36%;
  243. }
  244. .rotate {
  245. transform: rotateY(90deg);
  246. }
  247. .layui-zz-box {
  248. display: block;
  249. height: 100%;
  250. }
  251. .layui-fluid {
  252. padding: 15px 0;
  253. }
  254. .keyword {
  255. height: 35px;
  256. margin: 4px;
  257. }
  258. .keywords {
  259. height: 35px;
  260. margin: 4px;
  261. }
  262. input[disabled][type="checkbox"]:checked::before {
  263. content: "\2713";
  264. background-color: #2196F3;
  265. color: #fff;
  266. position: absolute;
  267. top: 0;
  268. left: 0;
  269. width: 100%;
  270. border: 1px solid #2196F3;
  271. font-size: 12px;
  272. font-weight: bold;
  273. text-align: center;
  274. line-height: 18px;
  275. z-index: 999;
  276. }
  277. #range_person{
  278. height: calc(100vh - 320px);
  279. }
  280. .layui-border-left {
  281. display: inline-block;
  282. border-left: 5px solid #666666;
  283. padding-left: 10px;
  284. }
  285. .flex {
  286. display: flex;
  287. align-items: center;
  288. padding: 0px 20px;
  289. }
  290. .plr20 {
  291. padding: 0px 20px;
  292. }
  293. .circle {
  294. width: 5px;
  295. height: 5px;
  296. background-color: #333;
  297. border-radius: 50%;
  298. position: absolute;
  299. left: 0px;
  300. top: 10px;
  301. }
  302. .relative {
  303. position: relative;
  304. height: 30px;
  305. line-height: 30px;
  306. }
  307. .line {
  308. position: absolute;
  309. width: 1px;
  310. height: 30px;
  311. background-color: #666666;
  312. left: 2.3px;
  313. top: 13px;
  314. }
  315. .mt10 {
  316. margin-top: 10px;
  317. }
  318. .delcolor {
  319. color: #249EFB;
  320. }
  321. .layui-card .layui-tab-brief .layui-tab-content {
  322. padding: 8px;
  323. }
  324. .dapartbox li {
  325. width: 50%;
  326. padding: 0;
  327. }
  328. .layui-table td, .layui-table th{width:25%;}
  329. .layui-table-body{
  330. height: auto !important;
  331. overflow: initial;
  332. }
  333. </style>
  334. <body>
  335. <div class="mainbox">
  336. <div class="clearfix toptitbox">
  337. <div class="left">您当前的操作 · <b>客户资源分配</b></div>
  338. <div class="right">
  339. <div class="left">点击这里返回列表:</div>
  340. <button class="left golastbtn" type="button">返回列表</button>
  341. </div>
  342. </div>
  343. <div class="bodys wpsr">
  344. <div class="layui-fluid">
  345. <div class="layui-card clearfix">
  346. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 leftcontentbox">
  347. <div class="layui-zz-box">
  348. <div class="layui-inline" style="display:block;">
  349. <div class="layui-tab layui-tab-card" lay-filter="maintenanceOrder">
  350. <ul class="layui-tab-title dapartbox">
  351. <li class="lay-dapart layui-this">选择分配到部门</li>
  352. <li class="lay-person">选择分配到人</li>
  353. </ul>
  354. <div class="layui-tab-content">
  355. <div class="layui-tab-item layui-show lay-dapartbox">
  356. <div class="list" id="range_person" style="overflow: auto;"></div>
  357. </div>
  358. <div class="layui-tab-item lay-personbox" style="height: calc(100vh - 320px);overflow: auto;">
  359. <div class="departnum">
  360. <div class="layui-inline layui-form" style="width: 35%;">
  361. <select name="type" lay-filter="type" id="type">
  362. <option value=1>按部门搜索</option>
  363. <option value=2>按人员搜索</option>
  364. </select>
  365. </div>
  366. <div class="layui-inline" style="width: 43%;">
  367. <div class="layui-input-inline" style="width: auto;">
  368. <input type="text" name="keyword" id="keyword" placeholder="请输入关键字搜索"
  369. autocomplete="off" class="layui-input keyword">
  370. </div>
  371. </div>
  372. <div class="layui-inline" id="right_search">
  373. <button class="layui-btn layuiadmin-btn keyword" lay-submit
  374. lay-filter="LAY-app-contlist-search">
  375. <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  376. </button>
  377. </div>
  378. </div>
  379. <table class="customer_table" id="customer_table" lay-filter="customer_table">
  380. </table>
  381. </div>
  382. </div>
  383. </div>
  384. </div>
  385. </div>
  386. </div>
  387. <div class="layui-col-md5 layui-col-xs5 layui-col-sm5 showdepartbox" style="overflow: auto;height: calc(100vh - 255px);">
  388. <div class="clearfix rightitlebox">
  389. <span>可分配资源:<a class="count_a" style="font-weight: bold;color:#249EFB">{$count}</a></span>
  390. <!-- <span>已分配:0</span>
  391. <span>未分配:0</span> -->
  392. </div>
  393. <div class="nowdepartbox">
  394. <table class="layui-table">
  395. <colgroup>
  396. <col width="150">
  397. <col width="200">
  398. <col>
  399. </colgroup>
  400. <thead>
  401. <tr>
  402. <th>部门名称</th>
  403. <th>分配资源数量</th>
  404. <th>操作</th>
  405. </tr>
  406. </thead>
  407. <tbody id="nowdepartbox">
  408. </tbody>
  409. </table>
  410. </div>
  411. <div class="nowdepartbox1 layui-hide">
  412. <table class="layui-table">
  413. <colgroup>
  414. <col width="150">
  415. <col width="200">
  416. <col>
  417. </colgroup>
  418. <thead>
  419. <tr>
  420. <th>姓名</th>
  421. <th>部门名称</th>
  422. <th>分配资源数量</th>
  423. <th>操作</th>
  424. </tr>
  425. </thead>
  426. <tbody id="nowdepartbox1">
  427. </tbody>
  428. </table>
  429. </div>
  430. </div>`
  431. </div>
  432. </div>
  433. <div class="plr20 mt10">
  434. <button class="layui-btn layuiadmin-btn" style="display: flex;align-items: center;" id="all_save"> 确定分配
  435. </button>
  436. </div>
  437. </div>
  438. </div>
  439. <script src="__STATIC__/layui/layui/layui.js"></script>
  440. <script src="__STATIC__/layui/layui/lay/modules/xm-select.js" type="text/javascript" charset="utf-8"></script>
  441. {/block} {block name="js"}
  442. <script>
  443. layui.config({
  444. base: '__LAYUI__/',
  445. }).extend({
  446. index: 'lib/index' //主入口模块
  447. }).use(['index', 'jquery', 'table', 'tree', 'layer', 'element', 'form', 'laydate'], function () {
  448. var table = layui.table,
  449. tree = layui.tree,
  450. layer = layui.layer,
  451. $ = layui.jquery,
  452. element = layui.element,
  453. laydate = layui.laydate,
  454. form = layui.form,
  455. tableData = [],
  456. tableData0 = [],
  457. customertable = [],
  458. customer_id = "{$customer_id}";
  459. var notlist = 1;
  460. var notlist1 = 1;
  461. var htmlright = [];
  462. var cunts = 0;
  463. var time = Date.parse(new Date()) / 1000;
  464. $('.golastbtn').click(function () {
  465. if(!customer_id){
  466. window.parent.backresourcefun(window.location.search.split('?')[1], '{:url("manager_emp/distribution")}', 'distribution');
  467. }else{
  468. window.parent.backresourcefun1(window.location.search.split('?')[1], '{:url("manager_emp/distribution")}', 'distribution');
  469. }
  470. })
  471. //点击选择人员
  472. $(document).on('click', '.leftcontentbox li', function (e) {
  473. if (e.target.localName === 'i') {
  474. let o = $(this).next();
  475. if (o && o[0] && o[0].localName === 'ul') {
  476. if (!o[0].style.display || o[0].style.display == 'block') {
  477. o[0].style.display = 'none';
  478. e.target.className = "group layui-icon layui-icon-triangle-r"
  479. } else {
  480. o[0].style.display = 'block';
  481. e.target.className = "group layui-icon layui-icon-triangle-d"
  482. }
  483. }
  484. }
  485. if (!(e.target.localName == 'input')) {
  486. return;
  487. }
  488. //唯一class
  489. var perclass = $(this).data('perclass');
  490. //类型 per员工 org部门         
  491. var type = $(this).data('type');
  492. //选中/取消
  493. var c = $('.' + perclass).prop("checked");
  494. var res = c == true ? 1 : 0;
  495. //id
  496. var id = $(this).data('id');
  497. var count_a1 = parseInt('{$count}');
  498. var htmlcount2=0;
  499. if (id > 0) {
  500. $.ajax({
  501. url: '{:url("manager_emp/get_child_orgs")}?id=' + id,
  502. data: {},
  503. type: 'get',
  504. success: function (res) {
  505. if (res.code == 0) {
  506. for (var i = res.data.length - 1; i >= 0; i--) {
  507. $('.per_org_' + res.data[i]).prop("checked", c);
  508. var delcount = 0;
  509. if (c == false) {
  510. $('#delorg' + res.data[i]).remove();
  511. ckboxs();
  512. }
  513. }
  514. if (c == true) {
  515. var html = '';
  516. for (var i = res.param.length - 1; i >= 0; i--) {
  517. if ($('#delorg' + res.param[i].id).length > 0) {
  518. //已存在
  519. } else {
  520. html += '<tr data-id=' + res.param[i].id + ' id=delorg' + res.param[i].id + '>';
  521. html += '<td>' + res.param[i].name + '</td>';
  522. html += '<td><input data-id=' + res.param[i].id + ' type="text" name="title" data-index="" value="" required lay-verify="required" placeholder="请输入正整数" autocomplete="off" class="layui-input inputText01 inputText"></td>';
  523. html += '<td data-id=' + res.param[i].id + ' class="strucinfo">删除</td>';
  524. html += '</tr>';
  525. }
  526. }
  527. $('#nowdepartbox').append(html);
  528. ckboxs();
  529. $(".inputText01").keyup(function(){
  530. $(this).val($(this).val().replace(/\D|^0/g,''));
  531. }).bind("paste",function(){
  532. return false;
  533. })
  534. setInterval(()=>{
  535. $(".inputText01").off('input').on('input',function(){
  536. var countleft =0;
  537. var aaa = 0;
  538. for(var i=0;i<$('#nowdepartbox tr').length;i++){
  539. countleft = $($('#nowdepartbox input')[i]).off('input').val();
  540. if(countleft==''||countleft==0){
  541. countleft = 0;
  542. }else{
  543. countleft=parseInt(countleft);
  544. aaa += countleft;
  545. }
  546. }
  547. if(aaa==0){
  548. notlist = 0
  549. }else{
  550. notlist = 1
  551. }
  552. if(aaa>count_a1){
  553. var inputval2;
  554. inputval2=$(this).val().slice(0,-1);
  555. $(this).val(inputval2);
  556. layer.msg('分配资源不能大于可分配资源');
  557. return false;
  558. }else{
  559. htmlcount2=count_a1-aaa;
  560. $('.count_a').html(htmlcount2);
  561. }
  562. })
  563. })
  564. for (let i = 0; i < $('#nowdepartbox .strucinfo').length; i++) {
  565. $($('#nowdepartbox .strucinfo')[i]).off('click').on('click', function (e) {
  566. let id = e.currentTarget.dataset.id;
  567. $('.per_org_' + id).prop("checked", false);
  568. $('#delorg' + id).remove();
  569. ckboxs();
  570. })
  571. }
  572. }
  573. function ckboxs(){
  574. var lengthlist=$('#nowdepartbox tr').length;
  575. var nocounts = count_a1- (count_a1%lengthlist);
  576. var li_list = nocounts/lengthlist;
  577. var inputval=0;
  578. var countcon=0;
  579. for(let i = 0; i < lengthlist; i++){
  580. if(lengthlist>count_a1){
  581. cunts=0;
  582. $($('#nowdepartbox input')[i]).off('input').val(i<count_a1?1:'')
  583. if(i<count_a1-1){
  584. htmlcount2 = count_a1-i;
  585. $('.count_a').html(htmlcount2);
  586. }
  587. }else{
  588. $($('#nowdepartbox input')[i]).off('input').val(li_list);
  589. }
  590. inputval = $($('#nowdepartbox tr')[i]).find('input').val();
  591. if(inputval==''||inputval==0){
  592. inputval = 0;
  593. }else{
  594. countcon+=parseInt(inputval);
  595. }
  596. }
  597. htmlcount2=count_a1-countcon;
  598. $('.count_a').html(htmlcount2);
  599. }
  600. //右侧表格处理
  601. // var selectData = res.param;
  602. // tableData0 = selectData.map(v => {
  603. // let item = tableData0.filter(o => (v.id == o.id && o.value));
  604. // if (item.length) {
  605. // return {...v,value: item[0].value};
  606. // } else {
  607. // return {...v,value: ''};
  608. // }
  609. // })
  610. // var html = '';
  611. // tableData0.forEach( function(item,index){
  612. // // console.log(item.id + '---' + item.name)
  613. // html += '<tr data-id='+item.id+' id=delorg'+item.id+'>';
  614. // html += '<td>'+item.name+'</td>';
  615. // html += `<td><input type="text" name="title" data-index="${index}" value="${item.value}" required lay-verify="required" placeholder="请输入正整数" autocomplete="off" class="layui-input inputText"></td>`;
  616. // html += '<td>删除</td>';
  617. // html += '</tr>';
  618. // // checked.push(item.id);
  619. // })
  620. // $('#nowdepartbox').html(html);
  621. // setTimeout(() => {
  622. // $('.inputText').on('change',function(e){
  623. // let index = parseInt($(this).prop('dataset').index);
  624. // tableData0[index].value = $(this).val();
  625. // })
  626. // })
  627. }else if(res.code == 403){
  628. $(".exitbtn").trigger("click");
  629. }
  630. },
  631. error: function (res) {
  632. }
  633. });
  634. }
  635. })
  636. //右侧搜索按钮
  637. $('#right_search').click(function () {
  638. var keyword = $('#keyword').val();
  639. var type = $('#type').val();
  640. var ids = [];
  641. htmlright = [];
  642. htmlright = htmlright.concat(tableData);
  643. for(var i=0;i<htmlright.length;i++){
  644. ids.push(htmlright[i].id)
  645. }
  646. function noRepeat1(arr) {
  647. for(var i = 0; i < arr.length-1; i++){
  648. for(var j = i+1; j < arr.length; j++){
  649. if(arr[i]===arr[j]){
  650. arr.splice(j,1);
  651. j--;
  652. }
  653. }
  654. }
  655. return arr;
  656. }
  657. var arrinfo=noRepeat1(ids);
  658. table.reload('customer_table', {
  659. where: {
  660. keyword: keyword,
  661. type: type,
  662. ids:arrinfo.toString()
  663. }
  664. , page: false,
  665. done: function (res) {
  666. console.log(res)
  667. for(var i=0;i<res.data.length;i++){
  668. if(res.data[i]['checked']==true){
  669. var index= res.data[i]['LAY_TABLE_INDEX'];
  670. $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
  671. $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
  672. }
  673. }
  674. onform();
  675. }
  676. });
  677. });
  678. table.on('tool(LAY-employee-list)', function (obj) {
  679. var data = obj.data;
  680. if (obj.event === 'edit') {
  681. operate.edit(data.id);
  682. }
  683. });
  684. var operate = {
  685. struct: function (keyword) {
  686. // return false;
  687. var that = this;
  688. that.send({ 'keyword': keyword }, '{:url("manager_emp/get_orgs",array("pid"=>$pid))}', function (res) {
  689. if (res.code == 0) {
  690. if(res.data.length==0){
  691. param_type=1
  692. $('.lay-dapart').hide();
  693. $('.lay-dapartbox').removeClass('layui-show');
  694. $('.lay-dapartbox').hide();
  695. $('.dapartbox li').css('width','100%')
  696. $('.lay-person').addClass('layui-this');
  697. $('.lay-personbox').addClass('layui-show');
  698. $('.nowdepartbox').addClass('layui-hide');
  699. $('.nowdepartbox1').removeClass('layui-hide');
  700. var tableheader = [ //表头
  701. { field: 'name', title: '姓名', templet: '#nameTpl', minWidth: 150 }
  702. , { field: 'org_name', title: '部门', minWidth: 150, templet: '#phone' }
  703. , { type: 'checkbox', minWidth: 40 }
  704. ];
  705. table.render({
  706. elem: '#customer_table'
  707. , url: '{:url("manager_emp/get_persons")}' //数据接口
  708. , id: 'customer_table'
  709. , page: false //开启分页
  710. , autoSort: false
  711. , cols: [tableheader]
  712. , height: 'full-120',
  713. page: false,
  714. limit: 10000,
  715. done: function (res) {
  716. customertable = res.data;
  717. }
  718. });
  719. }else{
  720. param_type=0;
  721. $('.lay-dapart').show();
  722. $('.lay-dapartbox').show();
  723. $('.dapartbox li').css('width', '50%')
  724. $('.lay-person').removeClass('layui-this');
  725. $('.lay-personbox').removeClass('layui-show');
  726. $('.lay-dapart').addClass('layui-this');
  727. $('.lay-dapartbox ').addClass('layui-show');
  728. $('.nowdepartbox').removeClass('layui-hide');
  729. $('.nowdepartbox1').addClass('layui-hide');
  730. $('.list').html(that.setStruct(res.data, res.checkOrg));
  731. }
  732. } else {
  733. $('.list').html('<span>' + res.msg + '</span>');
  734. }
  735. });
  736. },
  737. send: function (data, url, callback) {
  738. if (data.length == 0) {
  739. return $.ajax({
  740. type: 'get',
  741. url: url,
  742. data: {},
  743. success: function (res) {
  744. if(res.code == 403){
  745. $(".exitbtn").trigger("click");
  746. }
  747. callback(res)
  748. }
  749. })
  750. }
  751. return $.ajax({
  752. type: 'post',
  753. url: url,
  754. data: data,
  755. success: function (res) {
  756. if(res.code == 403){
  757. $(".exitbtn").trigger("click");
  758. }
  759. callback(res)
  760. }
  761. })
  762. },
  763. setStruct: function (data, checkOrg) {
  764. var that = this;
  765. var arr = checkOrg ? checkOrg.split(',') : [];
  766. var html = '<ul>';
  767. data.forEach(function (elem, index) {
  768. var flag = false;
  769. 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">';
  770. if (elem.children.length !== 0)
  771. html += '<i class="group layui-icon layui-icon-triangle-d"></i>';
  772. else
  773. html += '<i class="layui-icon layui-icon-user"></i>';
  774. html += '<span>' + elem.title + '</span>';
  775. for (var i in arr) {
  776. if (arr[i] == elem.id) {
  777. 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>';
  778. flag = true;
  779. }
  780. }
  781. if (!flag) {
  782. 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>';
  783. }
  784. html += '</li>';
  785. if (elem.children.length > 0) {
  786. html += that.setStruct(elem.children, checkOrg);
  787. }
  788. });
  789. html += '</ul>';
  790. return html
  791. }
  792. }
  793. // 结构初始化
  794. operate.struct();
  795. //监听 分配类型切换
  796. var is = false;
  797. var param_type = 0;//点击分配时要提交的参数
  798. element.on('tab(maintenanceOrder)', function (data) {
  799. var type = data.index;
  800. if (type == 1 && is == false) {
  801. var tableheader = [ //表头
  802. { field: 'name', title: '姓名', templet: '#nameTpl', minWidth: 150 }
  803. , { field: 'org_name', title: '部门', minWidth: 150, templet: '#phone' }
  804. , { type: 'checkbox', minWidth: 40 }
  805. ];
  806. table.render({
  807. elem: '#customer_table'
  808. , url: '{:url("manager_emp/get_persons")}' //数据接口
  809. , id: 'customer_table'
  810. , page: false //开启分页
  811. , autoSort: false
  812. , cols: [tableheader]
  813. , height: 'full-120',
  814. page: false,
  815. limit: 10000,
  816. done: function (res) {
  817. customertable = res.data;
  818. }
  819. });
  820. is = true;
  821. }
  822. //改变右侧
  823. if (type == 0) {
  824. $('.nowdepartbox').show();
  825. $('.nowdepartbox1').hide();
  826. } else if (type == 1) {
  827. $('.nowdepartbox').hide();
  828. $('.nowdepartbox1').show();
  829. $('.nowdepartbox1').removeClass('layui-hide');
  830. }
  831. param_type = type;
  832. //
  833. });
  834. //监听分配到人员列表的表格
  835. var checked = [];
  836. onform();
  837. var counts = '{$count}';
  838. var htmlcount = 0;
  839. function onform(){
  840. table.on('checkbox(customer_table)', function (obj) {
  841. //选中的数据
  842. var selectData = layui.table.checkStatus('customer_table').data;
  843. var isb=0;
  844. if(counts>selectData.length){
  845. isb=1;
  846. var nocounts = counts- (counts%selectData.length);
  847. var li_list = nocounts/selectData.length;
  848. if(selectData.length>0){
  849. htmlcount = counts-(li_list*(selectData.length))
  850. $('.count_a').html(htmlcount);
  851. }else{
  852. htmlcount = counts
  853. $('.count_a').html(htmlcount);
  854. }
  855. }else if(counts==selectData.length){
  856. isb=0;
  857. htmlcount = counts-selectData.length;
  858. $('.count_a').html(htmlcount);
  859. }else{
  860. isb=0;
  861. }
  862. tableData = selectData.map((v,i) => {
  863. let item = tableData.filter(o => (v.id == o.id));
  864. if(isb==1){
  865. if (item.length) {
  866. // return { ...v, value: item[0].value };
  867. return { ...v, value: li_list};
  868. } else {
  869. return { ...v, value: li_list};
  870. }
  871. }else{
  872. counts = parseInt(counts);
  873. if(selectData.length<counts){
  874. htmlcount = counts-i;
  875. $('.count_a').html(htmlcount);
  876. }else{
  877. htmlcount = 0;
  878. $('.count_a').html(htmlcount);
  879. }
  880. if (item.length) {
  881. // return { ...v, value: item[0].value };
  882. return { ...v, value: i<counts?1:''};
  883. } else {
  884. return { ...v, value: i<counts?1:''};
  885. }
  886. }
  887. })
  888. for(var i=0;i<htmlright.length;i++){
  889. if(htmlright[i].id==obj.data.id){
  890. htmlright.splice(i,1)
  891. }
  892. }
  893. tableData=htmlright.concat(tableData);
  894. tableData = tableData.filter((item, index, selfArr) => {
  895. return tableData.findIndex((x) => x.id === item.id) === index;
  896. });
  897. if (checked.length == 0) {
  898. var html = '';
  899. tableData.forEach(function (item, index) {
  900. html += '<tr data-id=' + item.id + ' id=del' + item.id + '>';
  901. html += '<td>' + item.name + '</td>';
  902. html += '<td>' + item.org_name + '</td>';
  903. html += `<td><input type="text" name="title" data-index="${index}" value="${item.value}" required lay-verify="required" placeholder="请输入正整数" autocomplete="off" class="layui-input inputText"></td>`;
  904. html += '<td data-id=' + item.id + ' class="strucinfo">删除</td>';
  905. html += '</tr>';
  906. })
  907. $('#nowdepartbox1').html(html);
  908. setTimeout(() => {
  909. $('.inputText').on('change', function (e) {
  910. let index = parseInt($(this).prop('dataset').index);
  911. tableData[index].value = $(this).val();
  912. })
  913. })
  914. $(".inputText").keyup(function(){
  915. $(this).val($(this).val().replace(/\D|^0/g,''));
  916. }).bind("paste",function(){
  917. return false;
  918. })
  919. $('.inputText').off('input').on('input', function (obj) {
  920. forlist($(this));
  921. })
  922. function forlist(_this){
  923. var countcon=0;
  924. var inputval = 0;
  925. for (let i = 0; i < $('#nowdepartbox1 tr').length; i++) {
  926. inputval = $($('#nowdepartbox1 tr')[i]).find('input').val();
  927. inputval = inputval.replace(/\D/g,'');
  928. if(inputval==''||inputval==0){
  929. inputval = 0;
  930. }else{
  931. countcon+=parseInt(inputval);
  932. }
  933. }
  934. if(countcon==0){
  935. notlist1 = 0;
  936. }else{
  937. notlist1 = 1;
  938. }
  939. if(countcon>counts){
  940. let index = parseInt(_this.prop('dataset').index);
  941. var inputval2;
  942. if(index==$('#nowdepartbox1 tr').length-1){
  943. inputval2 = _this.val().slice(0,-1);
  944. }
  945. tableData[index].value = _this.val(inputval2);
  946. layer.msg('分配资源不能大于可分配资源');
  947. return false;
  948. }else{
  949. htmlcount=counts-countcon;
  950. $('.count_a').html(htmlcount);
  951. }
  952. }
  953. for (let i = 0; i < $('#nowdepartbox1 .strucinfo').length; i++) {
  954. $($('#nowdepartbox1 .strucinfo')[i]).off('click').on('click', function (e) {
  955. let id = e.currentTarget.dataset.id;
  956. customertable.forEach(function (itm, idx) {
  957. if (id == itm.id) {
  958. let j = idx;
  959. let td = $("tr[data-index='" + j + "'] .layui-form-checkbox");
  960. for (let i = 0; i < td.length; i++) {
  961. let arr = td[i].className.split(' ');
  962. if (arr[arr.length - 1] == 'layui-form-checked') {
  963. td[i].click();
  964. }
  965. }
  966. }
  967. })
  968. for(var i=0;i<htmlright.length;i++){
  969. if(htmlright.length>0){
  970. if(htmlright[i].id==id){
  971. htmlright.splice(i,1)
  972. }
  973. }else{
  974. htmlright=[];
  975. tableData=[];
  976. }
  977. }
  978. $('#del' + id).remove();
  979. })
  980. }
  981. }
  982. });
  983. }
  984. //点击确定分配
  985. $('#all_save').click(function () {
  986. data = [];
  987. var type = param_type;
  988. var resources_id = "{$id}";
  989. if (type == 1) {
  990. console.log(tableData)
  991. type = 'person';
  992. for (let i = 0; i < tableData.length; i++) {
  993. let item = {};
  994. item.con_id = tableData[i].id;
  995. item.count = tableData[i].value;
  996. data.push(item);
  997. }
  998. } else {
  999. type = 'org';
  1000. let param = {};
  1001. $("body").find(".nowdepartbox input").each(function (index, domEle) {
  1002. param = {};
  1003. param.con_id = $(domEle).data('id');
  1004. param.count = $(domEle).val();
  1005. data.push(param);
  1006. // 回调函数第一个参数一定是索引号 可以自己指定索引号名称
  1007. // console.log(index);
  1008. // // 回调函数第二个参数一定是 dom元素对象
  1009. // console.log(domEle);
  1010. // console.log($(domEle).data('id'),$(domEle).val())
  1011. // $(domEle).css("color",arr[index]);
  1012. // sum += parseInt($(domEle).text());
  1013. })
  1014. }
  1015. if (data.length==0) {
  1016. layer.msg('请选择分配对象');
  1017. return false;
  1018. }
  1019. if (param_type == 0 && notlist == 0) {
  1020. layer.msg('请设置分配资源数量');
  1021. return false;
  1022. } else if (param_type == 1 && notlist1 == 0) {
  1023. layer.msg('请设置分配资源数量');
  1024. return false;
  1025. }
  1026. //2023-03-11 添加loading 连点数据错误
  1027. var loadingIndex = layer.load('Loading...', {
  1028. shade: [0.6,'#000'] //0.1透明度的白色背景
  1029. });
  1030. $.ajax({
  1031. url: '{:url("manager_emp/distribution_resources")}',
  1032. type: 'post',
  1033. data: { type: type, content: data, resources_id: resources_id, customer_id: customer_id },
  1034. dataType: 'json',
  1035. success: function (res) {
  1036. if (res.code == 0) {
  1037. layer.msg(res.msg, {
  1038. anim: 0
  1039. , time: 2000
  1040. }, function () {
  1041. if (!customer_id) {
  1042. window.parent.backresourcefun(window.location.search.split('?')[1], '{:url("manager_emp/distribution")}', 'distribution');
  1043. } else {
  1044. window.parent.backresourcefun1(window.location.search.split('?')[1], '{:url("manager_emp/distribution")}', 'distribution');
  1045. }
  1046. // window.parent.backresourcefun(window.location.search.split('?')[1], '{:url("manager_emp/distribution")}', 'distribution');
  1047. // var index = parent.layer.getFrameIndex(window.name);
  1048. // parent.layui.table.reload('pool_customer_table');
  1049. // parent.layer.close(index);
  1050. // window.parent.opoo();
  1051. });
  1052. layer.close(loadingIndex);
  1053. }else if(res.code == 403){
  1054. $(".exitbtn").trigger("click");
  1055. } else {
  1056. layer.msg(res.msg, {
  1057. anim: 6
  1058. , time: 2000
  1059. }, function () {
  1060. // var index = parent.layer.getFrameIndex(window.name);
  1061. // parent.layui.table.reload('pool_customer_table');
  1062. // parent.layer.close(index);
  1063. });
  1064. layer.close(loadingIndex);
  1065. }
  1066. }
  1067. });
  1068. });
  1069. });
  1070. </script>
  1071. </body>
  1072. {/block}