deptBindUserCtrl.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("deptBindUserCtrl", [
  6. "$rootScope",
  7. "$scope",
  8. "$state",
  9. "$timeout",
  10. "$interval",
  11. "$modal",
  12. "SweetAlert",
  13. "i18nService",
  14. "uiGridConstants",
  15. "uiGridGroupingConstants",
  16. "Restangular",
  17. "api_user_data",
  18. "api_bpm_data",
  19. "api_wechatfile",
  20. "api_custom",
  21. function (
  22. $rootScope,
  23. $scope,
  24. $state,
  25. $timeout,
  26. $interval,
  27. $modal,
  28. SweetAlert,
  29. i18nService,
  30. uiGridConstants,
  31. uiGridGroupingConstants,
  32. Restangular,
  33. api_user_data,
  34. api_bpm_data,
  35. api_wechatfile,
  36. api_custom
  37. ) {
  38. $scope.langs = i18nService.getAllLangs();
  39. $scope.lang = "zh-cn";
  40. i18nService.setCurrentLang($scope.lang);
  41. var loginUser = $rootScope.user;
  42. $scope.xinzeng = false;
  43. $scope.shanchu = false;
  44. $scope.bianji = false;
  45. $scope.fuzhi = false;
  46. for (var i = 0; i < loginUser.menu.length; i++) {
  47. if (loginUser.menu[i].link == "deptBindUser_add") {
  48. $scope.xinzeng = true;
  49. }
  50. if (loginUser.menu[i].link == "deptBindUser_del") {
  51. $scope.shanchu = true;
  52. }
  53. if (loginUser.menu[i].link == "deptBindUser_edit") {
  54. $scope.bianji = true;
  55. }
  56. if (loginUser.menu[i].link == "deptBindUser_copy") {
  57. $scope.fuzhi = true;
  58. }
  59. }
  60. $scope.gridOptions = {};
  61. $scope.gridOptions.data = "myData";
  62. $scope.gridOptions.enableColumnResizing = true;
  63. $scope.gridOptions.enableFiltering = true;
  64. $scope.gridOptions.enableGridMenu = true;
  65. $scope.gridOptions.enableRowSelection = true;
  66. $scope.gridOptions.showGridFooter = true;
  67. $scope.gridOptions.showColumnFooter = false;
  68. $scope.gridOptions.fastWatch = true;
  69. $scope.gridOptions.useExternalFiltering = true;
  70. $scope.gridOptions.useExternalPagination = true;
  71. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  72. $scope.gridOptions.paginationPageSize = 10;
  73. $scope.gridOptions.multiSelect = false;
  74. $scope.gridOptions.rowTemplate =
  75. '<div ng-dblclick="grid.appScope.onDblClick(row)" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + \'-\' + col.uid + \'-cell\'" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }" role="{{col.isRowHeader ? \'rowheader\' : \'gridcell\'}}" ui-grid-cell></div>';
  76. $scope.gridOptions.rowIdentity = function (row) {
  77. return row.id;
  78. };
  79. $scope.gridOptions.getRowIdentity = function (row) {
  80. return row.id;
  81. };
  82. $scope.gridOptions.columnDefs = [
  83. {
  84. name: "item",
  85. displayName: "序号",
  86. width: 50,
  87. enableFiltering: false,
  88. },
  89. {
  90. name: "branchName",
  91. displayName: "院区",
  92. width: "10%",
  93. enableFiltering: false,
  94. },
  95. {
  96. name: "deptArrStr",
  97. displayName: "科室",
  98. width: "20%",
  99. enableFiltering: false,
  100. },
  101. {
  102. name: "dutyName",
  103. displayName: "责任科室",
  104. width: "10%",
  105. enableFiltering: false,
  106. },
  107. {
  108. name: "categoryArrStr",
  109. displayName: "故障现象",
  110. width: "20%",
  111. enableFiltering: false,
  112. },
  113. {
  114. name: "category.categor12y",
  115. displayName: "处理人OR组",
  116. width: "10%",
  117. enableFiltering: false,
  118. cellTemplate:
  119. "<div>" +
  120. '<div class="ui-grid-cell-contents" ng-if="row.entity.userOrGroupType==1">{{row.entity.userName}}</div>' +
  121. '<div class="ui-grid-cell-contents" ng-if="row.entity.userOrGroupType==2">{{row.entity.groupName}}</div>' +
  122. "</div>",
  123. },
  124. {
  125. name: "操作",
  126. cellTemplate:
  127. '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  128. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">修改</a>' +
  129. '<a ng-click="grid.appScope.removeData(row.entity)" ng-show="grid.appScope.shanchu" class="bianjifont">删除</a>' +
  130. '<a ng-click="grid.appScope.copyData(row.entity)" ng-show="grid.appScope.fuzhi" class="bianjifont">复制</a>' +
  131. "</div></div>",
  132. enableFiltering: false,
  133. },
  134. ];
  135. $scope.transferDept = function (data) {
  136. if (data) {
  137. return data;
  138. } else {
  139. return "无";
  140. }
  141. };
  142. function selectItem(pmodel, childrens) {
  143. if (angular.isArray(pmodel)) {
  144. angular.forEach(pmodel, function (index) {
  145. if (index && index.id) {
  146. angular.forEach(childrens, function (item) {
  147. if (item.id == index.id) {
  148. item.selected = true;
  149. }
  150. if (item && item.children) {
  151. selectItem(pmodel, item.children);
  152. }
  153. });
  154. }
  155. });
  156. } else {
  157. if (pmodel && pmodel.id) {
  158. angular.forEach(childrens, function (item, index) {
  159. if (item.id == pmodel.id) {
  160. item.selected = true;
  161. }
  162. if (item && item.children) {
  163. selectItem(pmodel, item.children);
  164. }
  165. });
  166. }
  167. }
  168. }
  169. // 复制
  170. $scope.copyData = function (selectdata) {
  171. console.log(selectdata);
  172. $modal.open({
  173. templateUrl: "assets/views/system/tpl/deptBindUserchange.html",
  174. controller: function (
  175. $scope,
  176. scope,
  177. $modalInstance,
  178. SweetAlert,
  179. api_user_data,
  180. api_bpm_domain,
  181. $rootScope
  182. ) {
  183. // -------------------start----------------------
  184. $scope.title = "复制科室派单组合";
  185. //工单列表数据存储
  186. $scope.incidentModel = {
  187. branch: selectdata.branchObj, //院区
  188. department: selectdata.deptArr, //科室
  189. assign: selectdata.userOrGroupType, //派单人或组
  190. duty: {id: selectdata.dutyId, dept: selectdata.dutyName}, //责任科室
  191. };
  192. if(selectdata.userOrGroupType == 1){
  193. $scope.incidentModel.user = selectdata.userObj;//处理人
  194. }else if(selectdata.userOrGroupType == 2){
  195. $scope.incidentModel.group = selectdata.groupObj;//处理组
  196. }
  197. // 保存
  198. $scope.ok = function () {
  199. if (!$scope.incidentModel.duty) {
  200. SweetAlert.swal({
  201. title: "提示",
  202. text: "请选择责任科室!",
  203. type: "error",
  204. confirmButtonColor: "#DD6B55",
  205. });
  206. return;
  207. }
  208. if (!$scope.incidentModel.branch) {
  209. SweetAlert.swal({
  210. title: "提示",
  211. text: "请选择院区!",
  212. type: "error",
  213. confirmButtonColor: "#DD6B55",
  214. });
  215. return;
  216. }
  217. if (!$scope.incidentModel.department.length) {
  218. SweetAlert.swal({
  219. title: "提示",
  220. text: "请选择科室!",
  221. type: "error",
  222. confirmButtonColor: "#DD6B55",
  223. });
  224. return;
  225. }
  226. if (!$scope.incidentModel.department.length) {
  227. SweetAlert.swal({
  228. title: "提示",
  229. text: "请选择科室!",
  230. type: "error",
  231. confirmButtonColor: "#DD6B55",
  232. });
  233. return;
  234. }
  235. if ($scope.incidentModel.assign == 0) {
  236. SweetAlert.swal({
  237. title: "提示",
  238. text: "请选择派单给人或组!",
  239. type: "error",
  240. confirmButtonColor: "#DD6B55",
  241. });
  242. $scope.flag = false;
  243. return;
  244. }
  245. if (
  246. $scope.incidentModel.assign == 1 &&
  247. !$scope.incidentModel.user
  248. ) {
  249. SweetAlert.swal({
  250. title: "提示",
  251. text: "请选择处理人!",
  252. type: "error",
  253. confirmButtonColor: "#DD6B55",
  254. });
  255. $scope.flag = false;
  256. return;
  257. }
  258. if (
  259. $scope.incidentModel.assign == 2 &&
  260. !$scope.incidentModel.group
  261. ) {
  262. SweetAlert.swal({
  263. title: "提示",
  264. text: "请选择处理组!",
  265. type: "error",
  266. confirmButtonColor: "#DD6B55",
  267. });
  268. $scope.flag = false;
  269. return;
  270. }
  271. // 确定
  272. $scope.flag = false;
  273. handlerStart();
  274. // 保存
  275. function handlerStart() {
  276. if ($scope.flag) {
  277. return;
  278. }
  279. $scope.flag = true;
  280. var postData = {
  281. deptIds: $scope.incidentModel.department
  282. .map((v) => v.id)
  283. .toString(),
  284. categoryIds: $scope.jry_categoryData_selected
  285. .map((v) => v.id)
  286. .toString(),
  287. incidentAssignManager: {
  288. userOrGroupType: $scope.incidentModel.assign,
  289. branch: $scope.incidentModel.branch.id,
  290. dutyId: $scope.incidentModel.duty.id
  291. },
  292. };
  293. if ($scope.incidentModel.assign == 1) {
  294. // 处理人
  295. postData.incidentAssignManager.handleUser =
  296. $scope.incidentModel.user.id;
  297. } else if ($scope.incidentModel.assign == 2) {
  298. // 处理组
  299. postData.incidentAssignManager.group =
  300. $scope.incidentModel.group.id;
  301. }
  302. console.log($scope.incidentModel);
  303. console.log($scope.jry_categoryData_selected);
  304. // return;
  305. api_custom
  306. .addData("incidentAssignManager", postData)
  307. .then(function (response) {
  308. console.log(response);
  309. $scope.flag = false;
  310. if (response.status == 200) {
  311. SweetAlert.swal(
  312. {
  313. title: "保存成功!",
  314. type: "success",
  315. confirmButtonColor: "#007AFF",
  316. },
  317. function () {
  318. $modalInstance.dismiss("cancel");
  319. // $state.go("app.businessConfiguration.deptBindUser");
  320. scope.refreshData("expand-right", scope.fileData);
  321. }
  322. );
  323. } else {
  324. SweetAlert.swal({
  325. title: "操作失败",
  326. text: response.error || "操作失败, 请稍后再试!",
  327. type: "error",
  328. });
  329. }
  330. });
  331. }
  332. };
  333. // 院区
  334. $scope.jry_branchSearch = function (key = "") {
  335. var branchData = {
  336. idx: 0,
  337. sum: 10,
  338. };
  339. api_user_data
  340. .fetchDataList("branch", branchData)
  341. .then(function (data) {
  342. $scope.jry_branchData = data.list;
  343. });
  344. };
  345. // 责任科室模糊搜索
  346. $scope.jry_dutySearch = function (key = "",branchId,isFirst=false) {
  347. var deptData = {
  348. idx: 0,
  349. sum: 10,
  350. dutyDepartment: {
  351. branch:branchId,
  352. dept: key,
  353. selectType: "pinyin_qs",
  354. },
  355. };
  356. api_user_data
  357. .fetchDataList("dutyDepartment", deptData)
  358. .then(function (data) {
  359. $scope.jry_dutyData = data.list;
  360. });
  361. };
  362. // 报修科室模糊搜索
  363. $scope.jry_deptSearch = function (key = "",branchId,isFirst=false) {
  364. var deptData = {
  365. idx: 0,
  366. sum: 10,
  367. department: {
  368. branch:branchId,
  369. dept: key,
  370. selectType: "pinyin_qs",
  371. },
  372. };
  373. api_user_data
  374. .fetchDataList("department", deptData)
  375. .then(function (data) {
  376. var ids = $scope.incidentModel.department.map(v=>v.id);
  377. $scope.jry_deptData = data.list.filter(v=>!ids.includes(v.id));
  378. // $scope.jry_deptData = data.list;
  379. // if(isFirst){
  380. // var deptArr = selectdata.deptArr.map(v=>v.id);
  381. // $scope.incidentModel.department = data.list.filter(function(v){ return deptArr.indexOf(v.id) > -1 })
  382. // }
  383. });
  384. };
  385. $scope.$watch('incidentModel.branch',function(newVal,oldVal){
  386. if(newVal.id != oldVal.id){
  387. $scope.jry_deptSearch('',newVal.id);
  388. $scope.incidentModel.department = [];
  389. $scope.jry_dutySearch('',newVal.id);
  390. $scope.incidentModel.duty = '';
  391. }
  392. })
  393. // $scope.jry_deptSearch();
  394. // 处理人模糊搜索
  395. $scope.jry_userSearch = function (key = "") {
  396. var userData = {
  397. idx: 0,
  398. sum: 10,
  399. user: {
  400. roledata: { rolecode: "first-line support" },
  401. selectDetails: "1",
  402. simple: true,
  403. name: key,
  404. selectType: "pinyin_qs",
  405. engineer: 1,
  406. },
  407. };
  408. api_user_data.fetchDataList("user", userData).then(function (data) {
  409. $scope.jry_userData = data.list;
  410. if ($scope.incidentModel.user) {
  411. if (!$scope.incidentModel.user.name) {
  412. $scope.incidentModel.user = data.list.find(
  413. (v) => v.id == $scope.incidentModel.user.id
  414. );
  415. }
  416. }
  417. });
  418. };
  419. $scope.jry_userSearch();
  420. // 处理组模糊搜索
  421. $scope.jry_groupSearch = function (key = "") {
  422. var groupData = {
  423. idx: 0,
  424. sum: 10,
  425. group: {
  426. group: { selectType: "nouser" },
  427. },
  428. };
  429. api_user_data
  430. .fetchDataList("group", groupData)
  431. .then(function (data) {
  432. $scope.jry_groupData = data.list;
  433. });
  434. };
  435. $scope.jry_groupSearch();
  436. // 故障现象选中
  437. $scope.categorySelect = "";
  438. $scope.jry_categoryData = [];
  439. $scope.jry_categoryData_selected = [];
  440. $scope.jry_categoryData_copy_left = [];
  441. $scope.jry_categoryData_copy_right = [];
  442. $scope.changeCategorySelect = function (item, type) {
  443. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  444. $scope.categorySelect = item;
  445. item.selected = !item.selected;
  446. console.log(item, type);
  447. switch (type) {
  448. case "left":
  449. if (item.selected) {
  450. //选中
  451. $scope.jry_categoryData_copy_left.push(item);
  452. } else {
  453. // 取消
  454. $scope.jry_categoryData_copy_left =
  455. $scope.jry_categoryData_copy_left.filter(
  456. (v) => v.id != item.id
  457. );
  458. }
  459. console.log($scope.jry_categoryData_copy_left, "left");
  460. break;
  461. case "right":
  462. if (item.selected) {
  463. //选中
  464. $scope.jry_categoryData_copy_right.push(item);
  465. } else {
  466. // 取消
  467. $scope.jry_categoryData_copy_right =
  468. $scope.jry_categoryData_copy_right.filter(
  469. (v) => v.id != item.id
  470. );
  471. }
  472. console.log($scope.jry_categoryData_copy_right, "right");
  473. break;
  474. }
  475. };
  476. // 故障现象查询
  477. $scope.c_timer = null;
  478. $scope.c_keyword = "";
  479. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  480. $scope.c_keyword = key;
  481. clearTimeout($scope.c_timer);
  482. $scope.c_timer = setTimeout(() => {
  483. var categoryData = {
  484. idx: 0,
  485. sum: 9999,
  486. incidentcategory: {
  487. category: key,
  488. selectType: "pinyin_qs",
  489. hierarchyQuery:'three'
  490. },
  491. };
  492. $scope.loading_c = true;
  493. if(isFirst){
  494. $scope.loading_b = true;
  495. }
  496. api_user_data
  497. .fetchDataList("incidentcategory", categoryData)
  498. .then(function (data) {
  499. if ($scope.c_keyword == key) {
  500. $scope.loading_c = false;
  501. $scope.loading_b = false;
  502. data.list.forEach((v) => {
  503. v.selected = false; //$scope.jry_categoryData_copy_left
  504. $scope.jry_categoryData_copy_left.forEach((vv) => {
  505. if (v.id == vv.id) {
  506. v.selected = true;
  507. }
  508. });
  509. if (v.mutiCategory) {
  510. v.mutiCategory = v.mutiCategory.replace(
  511. $scope.jry_modelLeft,
  512. '<span class="colorRed">' +
  513. $scope.jry_modelLeft +
  514. "</span>"
  515. );
  516. }
  517. });
  518. if(!isFirst){
  519. //需要过滤右边的选项liaomingming
  520. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  521. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  522. }else{
  523. var categoryArrIds = selectdata.categoryArr.map(v=>v.id);
  524. var arr1 = [];
  525. var arr1_selected = [];
  526. arr1 = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) == -1 });
  527. arr1_selected = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) > -1 });
  528. $scope.jry_categoryData = arr1;
  529. $scope.jry_categoryData_selected = arr1_selected;
  530. }
  531. }
  532. });
  533. }, 500);
  534. };
  535. $scope.jry_categorySearch('',true);
  536. function multisort(array, ...compairers) {
  537. return array.sort((a, b) => {
  538. for (const c of compairers) {
  539. const r = c(a, b);
  540. if (r !== 0) {
  541. return r;
  542. }
  543. }
  544. });
  545. }
  546. // toRight
  547. $scope.toRight = function (arr) {
  548. var arrLeft = angular.copy($scope.jry_categoryData);
  549. var arRight = angular.copy($scope.jry_categoryData_selected);
  550. arr.forEach((v) => (v.selected = false));
  551. arRight = $scope.jry_categoryData_selected.concat(arr);
  552. arr.forEach((v) => {
  553. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  554. });
  555. $scope.jry_categoryData_copy_left = [];
  556. $scope.jry_categoryData = multisort(
  557. arrLeft,
  558. (a, b) => a.hierarchy - b.hierarchy,
  559. (a, b) => a.id - b.id
  560. );
  561. $scope.jry_categoryData_selected = multisort(
  562. arRight,
  563. (a, b) => a.hierarchy - b.hierarchy,
  564. (a, b) => a.id - b.id
  565. );
  566. };
  567. // toLeft
  568. $scope.toLeft = function (arr) {
  569. // var arrLeft = angular.copy($scope.jry_categoryData);
  570. var arRight = angular.copy($scope.jry_categoryData_selected);
  571. arr.forEach((v) => (v.selected = false));
  572. // arrLeft = arrLeft.concat(arr);
  573. arr.forEach((v) => {
  574. arRight = arRight.filter((vv) => vv.id != v.id);
  575. });
  576. $scope.jry_categoryData_copy_right = [];
  577. // $scope.jry_categoryData = multisort(
  578. // arrLeft,
  579. // (a, b) => a.hierarchy - b.hierarchy,
  580. // (a, b) => a.id - b.id
  581. // );
  582. $scope.jry_categoryData_selected = multisort(
  583. arRight,
  584. (a, b) => a.hierarchy - b.hierarchy,
  585. (a, b) => a.id - b.id
  586. );
  587. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  588. };
  589. // 取消
  590. $scope.cancel = function () {
  591. $modalInstance.dismiss("cancel");
  592. };
  593. // -------------------end----------------------
  594. },
  595. resolve: {
  596. scope: function() {
  597. return $scope;
  598. },
  599. selectdata: function() {
  600. return selectdata;
  601. }
  602. },
  603. });
  604. };
  605. // 修改
  606. $scope.saveData = function (selectdata) {
  607. console.log(selectdata);
  608. $modal.open({
  609. templateUrl: "assets/views/system/tpl/deptBindUserchange.html",
  610. controller: function (
  611. $scope,
  612. scope,
  613. $modalInstance,
  614. SweetAlert,
  615. api_user_data,
  616. api_bpm_domain,
  617. $rootScope
  618. ) {
  619. // -------------------start----------------------
  620. $scope.title = "修改科室派单组合";
  621. //工单列表数据存储
  622. $scope.incidentModel = {
  623. branch: selectdata.branchObj, //院区
  624. department: selectdata.deptArr, //科室
  625. assign: selectdata.userOrGroupType, //派单人或组
  626. duty: {id: selectdata.dutyId, dept: selectdata.dutyName}, //责任科室
  627. };
  628. if(selectdata.userOrGroupType == 1){
  629. $scope.incidentModel.user = selectdata.userObj;//处理人
  630. }else if(selectdata.userOrGroupType == 2){
  631. $scope.incidentModel.group = selectdata.groupObj;//处理组
  632. }
  633. // 保存
  634. $scope.ok = function () {
  635. if (!$scope.incidentModel.duty) {
  636. SweetAlert.swal({
  637. title: "提示",
  638. text: "请选择责任科室!",
  639. type: "error",
  640. confirmButtonColor: "#DD6B55",
  641. });
  642. return;
  643. }
  644. if (!$scope.incidentModel.branch) {
  645. SweetAlert.swal({
  646. title: "提示",
  647. text: "请选择院区!",
  648. type: "error",
  649. confirmButtonColor: "#DD6B55",
  650. });
  651. return;
  652. }
  653. if (!$scope.incidentModel.department.length) {
  654. SweetAlert.swal({
  655. title: "提示",
  656. text: "请选择科室!",
  657. type: "error",
  658. confirmButtonColor: "#DD6B55",
  659. });
  660. return;
  661. }
  662. if (!$scope.incidentModel.department.length) {
  663. SweetAlert.swal({
  664. title: "提示",
  665. text: "请选择科室!",
  666. type: "error",
  667. confirmButtonColor: "#DD6B55",
  668. });
  669. return;
  670. }
  671. if ($scope.incidentModel.assign == 0) {
  672. SweetAlert.swal({
  673. title: "提示",
  674. text: "请选择派单给人或组!",
  675. type: "error",
  676. confirmButtonColor: "#DD6B55",
  677. });
  678. $scope.flag = false;
  679. return;
  680. }
  681. if (
  682. $scope.incidentModel.assign == 1 &&
  683. !$scope.incidentModel.user
  684. ) {
  685. SweetAlert.swal({
  686. title: "提示",
  687. text: "请选择处理人!",
  688. type: "error",
  689. confirmButtonColor: "#DD6B55",
  690. });
  691. $scope.flag = false;
  692. return;
  693. }
  694. if (
  695. $scope.incidentModel.assign == 2 &&
  696. !$scope.incidentModel.group
  697. ) {
  698. SweetAlert.swal({
  699. title: "提示",
  700. text: "请选择处理组!",
  701. type: "error",
  702. confirmButtonColor: "#DD6B55",
  703. });
  704. $scope.flag = false;
  705. return;
  706. }
  707. // 确定
  708. $scope.flag = false;
  709. handlerStart();
  710. // 保存
  711. function handlerStart() {
  712. if ($scope.flag) {
  713. return;
  714. }
  715. $scope.flag = true;
  716. var postData = {
  717. deptIds: $scope.incidentModel.department
  718. .map((v) => v.id)
  719. .toString(),
  720. categoryIds: $scope.jry_categoryData_selected
  721. .map((v) => v.id)
  722. .toString(),
  723. incidentAssignManager: {
  724. batchId:selectdata.batchId,
  725. userOrGroupType: $scope.incidentModel.assign,
  726. branch: $scope.incidentModel.branch.id,
  727. dutyId: $scope.incidentModel.duty.id
  728. },
  729. };
  730. if ($scope.incidentModel.assign == 1) {
  731. // 处理人
  732. postData.incidentAssignManager.handleUser =
  733. $scope.incidentModel.user.id;
  734. } else if ($scope.incidentModel.assign == 2) {
  735. // 处理组
  736. postData.incidentAssignManager.group =
  737. $scope.incidentModel.group.id;
  738. }
  739. console.log($scope.incidentModel);
  740. console.log($scope.jry_categoryData_selected);
  741. // return;
  742. api_custom
  743. .updData("incidentAssignManager", postData)
  744. .then(function (response) {
  745. console.log(response);
  746. $scope.flag = false;
  747. if (response.status == 200) {
  748. SweetAlert.swal(
  749. {
  750. title: "保存成功!",
  751. type: "success",
  752. confirmButtonColor: "#007AFF",
  753. },
  754. function () {
  755. $modalInstance.dismiss("cancel");
  756. // $state.go("app.businessConfiguration.deptBindUser");
  757. scope.refreshData("expand-right", scope.fileData);
  758. }
  759. );
  760. } else {
  761. SweetAlert.swal({
  762. title: "操作失败",
  763. text: response.error || "操作失败, 请稍后再试!",
  764. type: "error",
  765. });
  766. }
  767. });
  768. }
  769. };
  770. // 院区
  771. $scope.jry_branchSearch = function (key = "") {
  772. var branchData = {
  773. idx: 0,
  774. sum: 10,
  775. };
  776. api_user_data
  777. .fetchDataList("branch", branchData)
  778. .then(function (data) {
  779. $scope.jry_branchData = data.list;
  780. });
  781. };
  782. // 责任科室模糊搜索
  783. $scope.jry_dutySearch = function (key = "",branchId,isFirst=false) {
  784. var deptData = {
  785. idx: 0,
  786. sum: 10,
  787. dutyDepartment: {
  788. branch:branchId,
  789. dept: key,
  790. selectType: "pinyin_qs",
  791. },
  792. };
  793. api_user_data
  794. .fetchDataList("dutyDepartment", deptData)
  795. .then(function (data) {
  796. $scope.jry_dutyData = data.list;
  797. });
  798. };
  799. // 报修科室模糊搜索
  800. $scope.jry_deptSearch = function (key = "",branchId,isFirst=false) {
  801. var deptData = {
  802. idx: 0,
  803. sum: 10,
  804. department: {
  805. branch:branchId,
  806. dept: key,
  807. selectType: "pinyin_qs",
  808. },
  809. };
  810. api_user_data
  811. .fetchDataList("department", deptData)
  812. .then(function (data) {
  813. var ids = $scope.incidentModel.department.map(v=>v.id);
  814. $scope.jry_deptData = data.list.filter(v=>!ids.includes(v.id));
  815. // if(isFirst){
  816. // var deptArr = selectdata.deptArr.map(v=>v.id);
  817. // $scope.incidentModel.department = data.list.filter(function(v){ return deptArr.indexOf(v.id) > -1 })
  818. // }
  819. });
  820. };
  821. $scope.$watch('incidentModel.branch',function(newVal,oldVal){
  822. if(newVal.id != oldVal.id){
  823. $scope.jry_deptSearch('',newVal.id);
  824. $scope.incidentModel.department = [];
  825. $scope.jry_dutySearch('',newVal.id);
  826. $scope.incidentModel.duty = '';
  827. }
  828. })
  829. // $scope.jry_deptSearch();
  830. // 处理人模糊搜索
  831. $scope.jry_userSearch = function (key = "") {
  832. var userData = {
  833. idx: 0,
  834. sum: 10,
  835. user: {
  836. roledata: { rolecode: "first-line support" },
  837. selectDetails: "1",
  838. simple: true,
  839. name: key,
  840. selectType: "pinyin_qs",
  841. engineer: 1,
  842. },
  843. };
  844. api_user_data.fetchDataList("user", userData).then(function (data) {
  845. $scope.jry_userData = data.list;
  846. if ($scope.incidentModel.user) {
  847. if (!$scope.incidentModel.user.name) {
  848. $scope.incidentModel.user = data.list.find(
  849. (v) => v.id == $scope.incidentModel.user.id
  850. );
  851. }
  852. }
  853. });
  854. };
  855. $scope.jry_userSearch();
  856. // 处理组模糊搜索
  857. $scope.jry_groupSearch = function (key = "") {
  858. var groupData = {
  859. idx: 0,
  860. sum: 10,
  861. group: {
  862. group: { selectType: "nouser" },
  863. },
  864. };
  865. api_user_data
  866. .fetchDataList("group", groupData)
  867. .then(function (data) {
  868. $scope.jry_groupData = data.list;
  869. });
  870. };
  871. $scope.jry_groupSearch();
  872. // 故障现象选中
  873. $scope.categorySelect = "";
  874. $scope.jry_categoryData = [];
  875. $scope.jry_categoryData_selected = [];
  876. $scope.jry_categoryData_copy_left = [];
  877. $scope.jry_categoryData_copy_right = [];
  878. $scope.changeCategorySelect = function (item, type) {
  879. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  880. $scope.categorySelect = item;
  881. item.selected = !item.selected;
  882. console.log(item, type);
  883. switch (type) {
  884. case "left":
  885. if (item.selected) {
  886. //选中
  887. $scope.jry_categoryData_copy_left.push(item);
  888. } else {
  889. // 取消
  890. $scope.jry_categoryData_copy_left =
  891. $scope.jry_categoryData_copy_left.filter(
  892. (v) => v.id != item.id
  893. );
  894. }
  895. console.log($scope.jry_categoryData_copy_left, "left");
  896. break;
  897. case "right":
  898. if (item.selected) {
  899. //选中
  900. $scope.jry_categoryData_copy_right.push(item);
  901. } else {
  902. // 取消
  903. $scope.jry_categoryData_copy_right =
  904. $scope.jry_categoryData_copy_right.filter(
  905. (v) => v.id != item.id
  906. );
  907. }
  908. console.log($scope.jry_categoryData_copy_right, "right");
  909. break;
  910. }
  911. };
  912. // 故障现象查询
  913. $scope.c_timer = null;
  914. $scope.c_keyword = "";
  915. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  916. $scope.c_keyword = key;
  917. clearTimeout($scope.c_timer);
  918. $scope.c_timer = setTimeout(() => {
  919. var categoryData = {
  920. idx: 0,
  921. sum: 9999,
  922. incidentcategory: {
  923. category: key,
  924. selectType: "pinyin_qs",
  925. hierarchyQuery:'three'
  926. },
  927. };
  928. $scope.loading_c = true;
  929. if(isFirst){
  930. $scope.loading_b = true;
  931. }
  932. api_user_data
  933. .fetchDataList("incidentcategory", categoryData)
  934. .then(function (data) {
  935. if ($scope.c_keyword == key) {
  936. $scope.loading_c = false;
  937. $scope.loading_b = false;
  938. data.list.forEach((v) => {
  939. v.selected = false; //$scope.jry_categoryData_copy_left
  940. $scope.jry_categoryData_copy_left.forEach((vv) => {
  941. if (v.id == vv.id) {
  942. v.selected = true;
  943. }
  944. });
  945. if (v.mutiCategory) {
  946. v.mutiCategory = v.mutiCategory.replace(
  947. $scope.jry_modelLeft,
  948. '<span class="colorRed">' +
  949. $scope.jry_modelLeft +
  950. "</span>"
  951. );
  952. }
  953. });
  954. if(!isFirst){
  955. //需要过滤右边的选项liaomingming
  956. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  957. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  958. }else{
  959. var categoryArrIds = selectdata.categoryArr.map(v=>v.id);
  960. var arr1 = [];
  961. var arr1_selected = [];
  962. arr1 = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) == -1 });
  963. arr1_selected = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) > -1 });
  964. $scope.jry_categoryData = arr1;
  965. $scope.jry_categoryData_selected = arr1_selected;
  966. }
  967. }
  968. });
  969. }, 500);
  970. };
  971. $scope.jry_categorySearch('',true);
  972. function multisort(array, ...compairers) {
  973. return array.sort((a, b) => {
  974. for (const c of compairers) {
  975. const r = c(a, b);
  976. if (r !== 0) {
  977. return r;
  978. }
  979. }
  980. });
  981. }
  982. // toRight
  983. $scope.toRight = function (arr) {
  984. var arrLeft = angular.copy($scope.jry_categoryData);
  985. var arRight = angular.copy($scope.jry_categoryData_selected);
  986. arr.forEach((v) => (v.selected = false));
  987. arRight = $scope.jry_categoryData_selected.concat(arr);
  988. arr.forEach((v) => {
  989. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  990. });
  991. $scope.jry_categoryData_copy_left = [];
  992. $scope.jry_categoryData = multisort(
  993. arrLeft,
  994. (a, b) => a.hierarchy - b.hierarchy,
  995. (a, b) => a.id - b.id
  996. );
  997. $scope.jry_categoryData_selected = multisort(
  998. arRight,
  999. (a, b) => a.hierarchy - b.hierarchy,
  1000. (a, b) => a.id - b.id
  1001. );
  1002. };
  1003. // toLeft
  1004. $scope.toLeft = function (arr) {
  1005. // var arrLeft = angular.copy($scope.jry_categoryData);
  1006. var arRight = angular.copy($scope.jry_categoryData_selected);
  1007. arr.forEach((v) => (v.selected = false));
  1008. // arrLeft = arrLeft.concat(arr);
  1009. arr.forEach((v) => {
  1010. arRight = arRight.filter((vv) => vv.id != v.id);
  1011. });
  1012. $scope.jry_categoryData_copy_right = [];
  1013. // $scope.jry_categoryData = multisort(
  1014. // arrLeft,
  1015. // (a, b) => a.hierarchy - b.hierarchy,
  1016. // (a, b) => a.id - b.id
  1017. // );
  1018. $scope.jry_categoryData_selected = multisort(
  1019. arRight,
  1020. (a, b) => a.hierarchy - b.hierarchy,
  1021. (a, b) => a.id - b.id
  1022. );
  1023. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  1024. };
  1025. // 取消
  1026. $scope.cancel = function () {
  1027. $modalInstance.dismiss("cancel");
  1028. };
  1029. // -------------------end----------------------
  1030. },
  1031. resolve: {
  1032. scope: function() {
  1033. return $scope;
  1034. },
  1035. selectdata: function() {
  1036. return selectdata;
  1037. }
  1038. },
  1039. });
  1040. };
  1041. function convertListToTree(data, treeMap) {
  1042. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  1043. var root = null; //Initially set our loop to null
  1044. var parentNode = null;
  1045. //loop over data
  1046. for (var i = 0; i < data.length; i++) {
  1047. var datum = data[i];
  1048. //each node will have children, so let's give it a "children" poperty
  1049. datum.children = [];
  1050. //add an entry for this node to the map so that any future children can
  1051. //lookup the parent
  1052. idToNodeMap[datum.id] = datum;
  1053. //Does this node have a parent?
  1054. if (typeof datum.parent === "undefined" || datum.parent == null) {
  1055. //Doesn't look like it, so this node is the root of the tree
  1056. root = datum;
  1057. treeMap[datum.id] = root;
  1058. } else {
  1059. //This node has a parent, so let's look it up using the id
  1060. parentNode = idToNodeMap[datum.parent.id];
  1061. //We don't need this property, so let's delete it.
  1062. delete datum.parent;
  1063. //Let's add the current node as a child of the parent node.
  1064. parentNode.children.push(datum);
  1065. }
  1066. }
  1067. return root;
  1068. }
  1069. function convertParentToChildList(data) {
  1070. var treeMap = {};
  1071. var list = [];
  1072. convertListToTree(data, treeMap);
  1073. angular.forEach(treeMap, function (item) {
  1074. list.push(item);
  1075. });
  1076. return list;
  1077. }
  1078. // 新增
  1079. $scope.addData = function () {
  1080. $modal.open({
  1081. templateUrl: "assets/views/system/tpl/deptBindUserchange.html",
  1082. controller: function (
  1083. $scope,
  1084. scope,
  1085. $modalInstance,
  1086. SweetAlert,
  1087. api_user_data,
  1088. api_bpm_domain,
  1089. $rootScope
  1090. ) {
  1091. // -------------------start----------------------
  1092. $scope.title = "新增科室派单组合";
  1093. //工单列表数据存储
  1094. $scope.incidentModel = {
  1095. branch: "", //院区
  1096. department: [], //科室
  1097. assign: 1, //派单人或组
  1098. user: "", //处理人
  1099. group: "", //处理组
  1100. duty: "", //责任科室
  1101. };
  1102. // 保存
  1103. $scope.ok = function () {
  1104. if (!$scope.incidentModel.duty) {
  1105. SweetAlert.swal({
  1106. title: "提示",
  1107. text: "请选择责任科室!",
  1108. type: "error",
  1109. confirmButtonColor: "#DD6B55",
  1110. });
  1111. return;
  1112. }
  1113. if (!$scope.incidentModel.branch) {
  1114. SweetAlert.swal({
  1115. title: "提示",
  1116. text: "请选择院区!",
  1117. type: "error",
  1118. confirmButtonColor: "#DD6B55",
  1119. });
  1120. return;
  1121. }
  1122. if (!$scope.incidentModel.department.length) {
  1123. SweetAlert.swal({
  1124. title: "提示",
  1125. text: "请选择科室!",
  1126. type: "error",
  1127. confirmButtonColor: "#DD6B55",
  1128. });
  1129. return;
  1130. }
  1131. if (!$scope.incidentModel.department.length) {
  1132. SweetAlert.swal({
  1133. title: "提示",
  1134. text: "请选择科室!",
  1135. type: "error",
  1136. confirmButtonColor: "#DD6B55",
  1137. });
  1138. return;
  1139. }
  1140. if ($scope.incidentModel.assign == 0) {
  1141. SweetAlert.swal({
  1142. title: "提示",
  1143. text: "请选择派单给人或组!",
  1144. type: "error",
  1145. confirmButtonColor: "#DD6B55",
  1146. });
  1147. $scope.flag = false;
  1148. return;
  1149. }
  1150. if (
  1151. $scope.incidentModel.assign == 1 &&
  1152. !$scope.incidentModel.user
  1153. ) {
  1154. SweetAlert.swal({
  1155. title: "提示",
  1156. text: "请选择处理人!",
  1157. type: "error",
  1158. confirmButtonColor: "#DD6B55",
  1159. });
  1160. $scope.flag = false;
  1161. return;
  1162. }
  1163. if (
  1164. $scope.incidentModel.assign == 2 &&
  1165. !$scope.incidentModel.group
  1166. ) {
  1167. SweetAlert.swal({
  1168. title: "提示",
  1169. text: "请选择处理组!",
  1170. type: "error",
  1171. confirmButtonColor: "#DD6B55",
  1172. });
  1173. $scope.flag = false;
  1174. return;
  1175. }
  1176. // 确定
  1177. $scope.flag = false;
  1178. handlerStart();
  1179. // 保存
  1180. function handlerStart() {
  1181. if ($scope.flag) {
  1182. return;
  1183. }
  1184. $scope.flag = true;
  1185. var postData = {
  1186. deptIds: $scope.incidentModel.department
  1187. .map((v) => v.id)
  1188. .toString(),
  1189. categoryIds: $scope.jry_categoryData_selected
  1190. .map((v) => v.id)
  1191. .toString(),
  1192. incidentAssignManager: {
  1193. userOrGroupType: $scope.incidentModel.assign,
  1194. branch: $scope.incidentModel.branch.id,
  1195. dutyId: $scope.incidentModel.duty.id
  1196. },
  1197. };
  1198. if ($scope.incidentModel.assign == 1) {
  1199. // 处理人
  1200. postData.incidentAssignManager.handleUser =
  1201. $scope.incidentModel.user.id;
  1202. } else if ($scope.incidentModel.assign == 2) {
  1203. // 处理组
  1204. postData.incidentAssignManager.group =
  1205. $scope.incidentModel.group.id;
  1206. }
  1207. console.log($scope.incidentModel);
  1208. console.log($scope.jry_categoryData_selected);
  1209. // return;
  1210. api_custom
  1211. .addData("incidentAssignManager", postData)
  1212. .then(function (response) {
  1213. console.log(response);
  1214. $scope.flag = false;
  1215. if (response.status == 200) {
  1216. SweetAlert.swal(
  1217. {
  1218. title: "保存成功!",
  1219. type: "success",
  1220. confirmButtonColor: "#007AFF",
  1221. },
  1222. function () {
  1223. $modalInstance.dismiss("cancel");
  1224. // $state.go("app.businessConfiguration.deptBindUser");
  1225. scope.refreshData("expand-right", scope.fileData);
  1226. }
  1227. );
  1228. } else {
  1229. SweetAlert.swal({
  1230. title: "操作失败",
  1231. text: response.error || "操作失败, 请稍后再试!",
  1232. type: "error",
  1233. });
  1234. }
  1235. });
  1236. }
  1237. };
  1238. // 院区
  1239. $scope.jry_branchSearch = function (key = "") {
  1240. var branchData = {
  1241. idx: 0,
  1242. sum: 10,
  1243. };
  1244. api_user_data
  1245. .fetchDataList("branch", branchData)
  1246. .then(function (data) {
  1247. $scope.jry_branchData = data.list;
  1248. });
  1249. };
  1250. // 责任科室模糊搜索
  1251. $scope.jry_dutySearch = function (key = "",branchId) {
  1252. var deptData = {
  1253. idx: 0,
  1254. sum: 10,
  1255. dutyDepartment: {
  1256. branch:branchId,
  1257. dept: key,
  1258. selectType: "pinyin_qs",
  1259. },
  1260. };
  1261. api_user_data
  1262. .fetchDataList("dutyDepartment", deptData)
  1263. .then(function (data) {
  1264. $scope.jry_dutyData = data.list;
  1265. });
  1266. };
  1267. // 报修科室模糊搜索
  1268. $scope.jry_deptSearch = function (key = "",branchId) {
  1269. var deptData = {
  1270. idx: 0,
  1271. sum: 10,
  1272. department: {
  1273. branch:branchId,
  1274. dept: key,
  1275. selectType: "pinyin_qs",
  1276. },
  1277. };
  1278. api_user_data
  1279. .fetchDataList("department", deptData)
  1280. .then(function (data) {
  1281. // $scope.jry_deptData = data.list;
  1282. var ids = $scope.incidentModel.department.map(v=>v.id);
  1283. $scope.jry_deptData = data.list.filter(v=>!ids.includes(v.id));
  1284. });
  1285. };
  1286. $scope.$watch('incidentModel.branch',function(newVal,oldVal){
  1287. if(newVal.id != oldVal.id){
  1288. $scope.jry_deptSearch('',newVal.id);
  1289. $scope.incidentModel.department = [];
  1290. $scope.jry_dutySearch('',newVal.id);
  1291. $scope.incidentModel.duty = '';
  1292. }
  1293. })
  1294. // $scope.jry_deptSearch();
  1295. // 处理人模糊搜索
  1296. $scope.jry_userSearch = function (key = "") {
  1297. var userData = {
  1298. idx: 0,
  1299. sum: 10,
  1300. user: {
  1301. roledata: { rolecode: "first-line support" },
  1302. selectDetails: "1",
  1303. simple: true,
  1304. name: key,
  1305. selectType: "pinyin_qs",
  1306. engineer: 1,
  1307. },
  1308. };
  1309. api_user_data.fetchDataList("user", userData).then(function (data) {
  1310. $scope.jry_userData = data.list;
  1311. if ($scope.incidentModel.user) {
  1312. if (!$scope.incidentModel.user.name) {
  1313. $scope.incidentModel.user = data.list.find(
  1314. (v) => v.id == $scope.incidentModel.user.id
  1315. );
  1316. }
  1317. }
  1318. });
  1319. };
  1320. $scope.jry_userSearch();
  1321. // 处理组模糊搜索
  1322. $scope.jry_groupSearch = function (key = "") {
  1323. var groupData = {
  1324. idx: 0,
  1325. sum: 10,
  1326. group: {
  1327. group: { selectType: "nouser" },
  1328. },
  1329. };
  1330. api_user_data
  1331. .fetchDataList("group", groupData)
  1332. .then(function (data) {
  1333. $scope.jry_groupData = data.list;
  1334. });
  1335. };
  1336. $scope.jry_groupSearch();
  1337. // 故障现象选中
  1338. $scope.categorySelect = "";
  1339. $scope.jry_categoryData = [];
  1340. $scope.jry_categoryData_selected = [];
  1341. $scope.jry_categoryData_copy_left = [];
  1342. $scope.jry_categoryData_copy_right = [];
  1343. $scope.changeCategorySelect = function (item, type) {
  1344. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  1345. $scope.categorySelect = item;
  1346. item.selected = !item.selected;
  1347. console.log(item, type);
  1348. switch (type) {
  1349. case "left":
  1350. if (item.selected) {
  1351. //选中
  1352. $scope.jry_categoryData_copy_left.push(item);
  1353. } else {
  1354. // 取消
  1355. $scope.jry_categoryData_copy_left =
  1356. $scope.jry_categoryData_copy_left.filter(
  1357. (v) => v.id != item.id
  1358. );
  1359. }
  1360. console.log($scope.jry_categoryData_copy_left, "left");
  1361. break;
  1362. case "right":
  1363. if (item.selected) {
  1364. //选中
  1365. $scope.jry_categoryData_copy_right.push(item);
  1366. } else {
  1367. // 取消
  1368. $scope.jry_categoryData_copy_right =
  1369. $scope.jry_categoryData_copy_right.filter(
  1370. (v) => v.id != item.id
  1371. );
  1372. }
  1373. console.log($scope.jry_categoryData_copy_right, "right");
  1374. break;
  1375. }
  1376. };
  1377. // 故障现象查询
  1378. $scope.c_timer = null;
  1379. $scope.c_keyword = "";
  1380. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  1381. $scope.c_keyword = key;
  1382. clearTimeout($scope.c_timer);
  1383. $scope.c_timer = setTimeout(() => {
  1384. var categoryData = {
  1385. idx: 0,
  1386. sum: 9999,
  1387. incidentcategory: {
  1388. category: key,
  1389. selectType: "pinyin_qs",
  1390. hierarchyQuery:'three'
  1391. },
  1392. };
  1393. $scope.loading_c = true;
  1394. if(isFirst){
  1395. $scope.loading_b = true;
  1396. }
  1397. api_user_data
  1398. .fetchDataList("incidentcategory", categoryData)
  1399. .then(function (data) {
  1400. if ($scope.c_keyword == key) {
  1401. $scope.loading_c = false;
  1402. $scope.loading_b = false;
  1403. data.list.forEach((v) => {
  1404. v.selected = false; //$scope.jry_categoryData_copy_left
  1405. $scope.jry_categoryData_copy_left.forEach((vv) => {
  1406. if (v.id == vv.id) {
  1407. v.selected = true;
  1408. }
  1409. });
  1410. if (v.mutiCategory) {
  1411. v.mutiCategory = v.mutiCategory.replace(
  1412. $scope.jry_modelLeft,
  1413. '<span class="colorRed">' +
  1414. $scope.jry_modelLeft +
  1415. "</span>"
  1416. );
  1417. }
  1418. });
  1419. //需要过滤右边的选项liaomingming
  1420. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  1421. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  1422. }
  1423. });
  1424. }, 500);
  1425. };
  1426. $scope.jry_categorySearch('',true);
  1427. function multisort(array, ...compairers) {
  1428. return array.sort((a, b) => {
  1429. for (const c of compairers) {
  1430. const r = c(a, b);
  1431. if (r !== 0) {
  1432. return r;
  1433. }
  1434. }
  1435. });
  1436. }
  1437. // toRight
  1438. $scope.toRight = function (arr) {
  1439. var arrLeft = angular.copy($scope.jry_categoryData);
  1440. var arRight = angular.copy($scope.jry_categoryData_selected);
  1441. arr.forEach((v) => (v.selected = false));
  1442. arRight = $scope.jry_categoryData_selected.concat(arr);
  1443. arr.forEach((v) => {
  1444. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  1445. });
  1446. $scope.jry_categoryData_copy_left = [];
  1447. $scope.jry_categoryData = multisort(
  1448. arrLeft,
  1449. (a, b) => a.hierarchy - b.hierarchy,
  1450. (a, b) => a.id - b.id
  1451. );
  1452. $scope.jry_categoryData_selected = multisort(
  1453. arRight,
  1454. (a, b) => a.hierarchy - b.hierarchy,
  1455. (a, b) => a.id - b.id
  1456. );
  1457. };
  1458. // toLeft
  1459. $scope.toLeft = function (arr) {
  1460. // var arrLeft = angular.copy($scope.jry_categoryData);
  1461. var arRight = angular.copy($scope.jry_categoryData_selected);
  1462. arr.forEach((v) => (v.selected = false));
  1463. // arrLeft = arrLeft.concat(arr);
  1464. arr.forEach((v) => {
  1465. arRight = arRight.filter((vv) => vv.id != v.id);
  1466. });
  1467. $scope.jry_categoryData_copy_right = [];
  1468. // $scope.jry_categoryData = multisort(
  1469. // arrLeft,
  1470. // (a, b) => a.hierarchy - b.hierarchy,
  1471. // (a, b) => a.id - b.id
  1472. // );
  1473. $scope.jry_categoryData_selected = multisort(
  1474. arRight,
  1475. (a, b) => a.hierarchy - b.hierarchy,
  1476. (a, b) => a.id - b.id
  1477. );
  1478. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  1479. };
  1480. // 取消
  1481. $scope.cancel = function () {
  1482. $modalInstance.dismiss("cancel");
  1483. };
  1484. // -------------------end----------------------
  1485. },
  1486. resolve: {
  1487. scope: function() {
  1488. return $scope;
  1489. }
  1490. },
  1491. });
  1492. };
  1493. // 删除
  1494. $scope.removeData = function (selectdata) {
  1495. var modalInstance = $modal.open({
  1496. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  1497. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  1498. var rmvList = [];
  1499. $scope.title = "科室派单组合删除";
  1500. $scope.connect = "确定要删除此科室派单组合?";
  1501. rmvList.push(selectdata);
  1502. $scope.ok = function () {
  1503. $modalInstance.close(rmvList);
  1504. };
  1505. $scope.cancel = function () {
  1506. $modalInstance.dismiss("cancel");
  1507. };
  1508. },
  1509. size: "sm",
  1510. resolve: {
  1511. scope: function () {
  1512. return $scope;
  1513. },
  1514. selectdata: function () {
  1515. return selectdata;
  1516. },
  1517. },
  1518. });
  1519. modalInstance.result.then(function (selectedItem) {
  1520. if (selectedItem) {
  1521. if (selectedItem.length > 0) {
  1522. console.log(selectedItem);
  1523. api_custom
  1524. .rmvData("incidentAssignManager", {
  1525. batchId: selectedItem[0].batchId,
  1526. })
  1527. .then(function (response) {
  1528. if (response.status == 200) {
  1529. SweetAlert.swal(
  1530. {
  1531. title: "删除成功!",
  1532. type: "success",
  1533. confirmButtonColor: "#007AFF",
  1534. },
  1535. function () {
  1536. $scope.myData = _.reject($scope.myData, function (o) {
  1537. return _.includes(selectedItem, o.id);
  1538. });
  1539. $scope.selected = {
  1540. items: [],
  1541. };
  1542. $scope.gridOptions.totalItems =
  1543. $scope.gridOptions.totalItems - selectedItem.length;
  1544. // $scope.gridApi.grid.selection.selectedCount = 0;
  1545. $scope.refreshData("expand-right", $scope.fileData);
  1546. }
  1547. );
  1548. } else {
  1549. SweetAlert.swal({
  1550. title: "操作异常!",
  1551. text: "系统异常,请稍后重试,或者联系管理员!",
  1552. type: "error",
  1553. });
  1554. }
  1555. });
  1556. }
  1557. }
  1558. });
  1559. };
  1560. $scope.selected = {
  1561. items: [],
  1562. };
  1563. $scope.editted = {
  1564. items: [],
  1565. };
  1566. $scope.gridOptions.onRegisterApi = function (gridApi) {
  1567. $scope.gridApi = gridApi;
  1568. gridApi.pagination.on.paginationChanged(
  1569. $scope,
  1570. function (newPage, pageSize) {
  1571. var filtersData = $scope.memoryfilterData;
  1572. filtersData.idx = newPage - 1;
  1573. filtersData.sum = pageSize;
  1574. $scope.fileData.idx = newPage - 1;
  1575. $scope.fileData.sum = pageSize;
  1576. defaultFilterData = filtersData;
  1577. $scope.refreshData("expand-right", $scope.fileData);
  1578. }
  1579. );
  1580. // gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  1581. // scope.grid.appScope.selected.items = scope.entity;
  1582. // });
  1583. };
  1584. var defaultFilterData = {
  1585. idx: 0,
  1586. sum: 10,
  1587. };
  1588. $scope.memoryfilterData = {
  1589. idx: 0,
  1590. sum: 10,
  1591. };
  1592. $scope.fileData = {
  1593. idx: 0,
  1594. sum: 10,
  1595. incidentAssignManager: {},
  1596. };
  1597. $scope.ldloading = {};
  1598. $scope.refreshData = function (style, filterData) {
  1599. $scope.selected.items = {};
  1600. $scope.ldloading[style.replace("-", "_")] = true;
  1601. if (angular.isUndefined(filterData)) {
  1602. filterData = defaultFilterData;
  1603. }
  1604. $scope.myData = [];
  1605. $scope.selected = { items: [] };
  1606. // if ($scope.gridApi) {
  1607. // $scope.gridApi.grid.selection.selectedCount = 0;
  1608. // }
  1609. filterData = angular.copy(filterData);
  1610. api_custom.fetchDataList("incidentAssignManager", filterData).then(
  1611. function (data) {
  1612. var myData = Restangular.stripRestangular(data);
  1613. myData.data = myData.data || [];
  1614. // 处理后端返回的数据 start
  1615. myData.data.forEach((v) => {
  1616. v.forEach((vv) => {
  1617. vv.branchObj = { id: vv.branch, hosName: vv.branchName };
  1618. vv.categoryObj = {
  1619. id: vv.categoryId,
  1620. mutiCategory: vv.categoryName,
  1621. };
  1622. vv.deptObj = { id: vv.deptId, dept: vv.deptName };
  1623. if (vv.userOrGroupType == 1) {
  1624. vv.userObj = { id: vv.handleUser, name: vv.userName };
  1625. } else if (vv.userOrGroupType == 2) {
  1626. vv.groupObj = { id: vv.group, groupName: vv.groupName };
  1627. }
  1628. });
  1629. });
  1630. console.log(myData.data);
  1631. var newList = [];
  1632. myData.data.forEach((v, i) => {
  1633. v.forEach((vv) => {
  1634. if (newList[i]) {
  1635. // 存在
  1636. if (!newList[i].categoryArr) {
  1637. newList[i].categoryArr = [newList[i].categoryObj];
  1638. } else {
  1639. let flag = newList[i].categoryArr.some(
  1640. (vvv) => vvv.id == vv.categoryObj.id
  1641. );
  1642. if (!flag) {
  1643. newList[i].categoryArr.push(vv.categoryObj);
  1644. }
  1645. }
  1646. if (!newList[i].deptArr) {
  1647. newList[i].deptArr = [newList[i].deptObj];
  1648. } else {
  1649. let flag = newList[i].deptArr.some(
  1650. (vvv) => vvv.id == vv.deptObj.id
  1651. );
  1652. if (!flag) {
  1653. newList[i].deptArr.push(vv.deptObj);
  1654. }
  1655. }
  1656. if (vv.userOrGroupType == 2 && !newList[i].group) {
  1657. newList[i].groupObj = vv.groupObj;
  1658. }
  1659. if (vv.userOrGroupType == 1 && !newList[i].handleUser) {
  1660. newList[i].userObj = vv.userObj;
  1661. }
  1662. if (!newList[i].branch) {
  1663. newList[i].branchObj = vv.branchObj;
  1664. }
  1665. } else {
  1666. // 不存在
  1667. vv.deptArr = [vv.deptObj];
  1668. vv.categoryArr = [vv.categoryObj];
  1669. newList[i] = vv;
  1670. }
  1671. });
  1672. });
  1673. newList.forEach((v) => {
  1674. v.deptArrStr = v.deptArr.map((v) => v.dept).toString();
  1675. v.categoryArrStr = v.categoryArr
  1676. .map((v) => v.mutiCategory)
  1677. .toString();
  1678. });
  1679. console.log(newList);
  1680. // 处理后端返回的数据 end
  1681. $scope.gridOptions.totalItems = myData.totalNum;
  1682. $scope.myData = newList;
  1683. for (var i = 0; i < $scope.myData.length; i++) {
  1684. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  1685. }
  1686. $scope.ldloading[style.replace("-", "_")] = false;
  1687. },
  1688. function () {
  1689. $scope.ldloading[style.replace("-", "_")] = false;
  1690. }
  1691. );
  1692. };
  1693. $scope.refreshData2 = function (style, filterData) {
  1694. $scope.selected.items = {};
  1695. $scope.ldloading[style.replace("-", "_")] = true;
  1696. if (angular.isUndefined(filterData)) {
  1697. filterData = defaultFilterData;
  1698. }
  1699. $scope.myData = [];
  1700. $scope.selected = { items: [] };
  1701. // if ($scope.gridApi) {
  1702. // $scope.gridApi.grid.selection.selectedCount = 0;
  1703. // }
  1704. filterData = angular.copy(filterData);
  1705. if (filterData.incidentAssignManager.category) {
  1706. filterData.incidentAssignManager.category =
  1707. filterData.incidentAssignManager.category.id;
  1708. }
  1709. api_custom.fetchDataList("incidentAssignManager", filterData).then(
  1710. function (data) {
  1711. var myData = Restangular.stripRestangular(data);
  1712. myData.data = myData.data || [];
  1713. // 处理后端返回的数据 start
  1714. myData.data.forEach((v) => {
  1715. v.forEach((vv) => {
  1716. vv.branchObj = { id: vv.branch, hosName: vv.branchName };
  1717. vv.categoryObj = {
  1718. id: vv.categoryId,
  1719. mutiCategory: vv.categoryName,
  1720. };
  1721. vv.deptObj = { id: vv.deptId, dept: vv.deptName };
  1722. if (vv.userOrGroupType == 1) {
  1723. vv.userObj = { id: vv.handleUser, name: vv.userName };
  1724. } else if (vv.userOrGroupType == 2) {
  1725. vv.groupObj = { id: vv.group, groupName: vv.groupName };
  1726. }
  1727. });
  1728. });
  1729. console.log(myData.data);
  1730. var newList = [];
  1731. myData.data.forEach((v, i) => {
  1732. v.forEach((vv) => {
  1733. if (newList[i]) {
  1734. // 存在
  1735. if (!newList[i].categoryArr) {
  1736. newList[i].categoryArr = [newList[i].categoryObj];
  1737. } else {
  1738. let flag = newList[i].categoryArr.some(
  1739. (vvv) => vvv.id == vv.categoryObj.id
  1740. );
  1741. if (!flag) {
  1742. newList[i].categoryArr.push(vv.categoryObj);
  1743. }
  1744. }
  1745. if (!newList[i].deptArr) {
  1746. newList[i].deptArr = [newList[i].deptObj];
  1747. } else {
  1748. let flag = newList[i].deptArr.some(
  1749. (vvv) => vvv.id == vv.deptObj.id
  1750. );
  1751. if (!flag) {
  1752. newList[i].deptArr.push(vv.deptObj);
  1753. }
  1754. }
  1755. if (vv.userOrGroupType == 2 && !newList[i].group) {
  1756. newList[i].groupObj = vv.groupObj;
  1757. }
  1758. if (vv.userOrGroupType == 1 && !newList[i].handleUser) {
  1759. newList[i].userObj = vv.userObj;
  1760. }
  1761. if (!newList[i].branch) {
  1762. newList[i].branchObj = vv.branchObj;
  1763. }
  1764. } else {
  1765. // 不存在
  1766. vv.deptArr = [vv.deptObj];
  1767. vv.categoryArr = [vv.categoryObj];
  1768. newList[i] = vv;
  1769. }
  1770. });
  1771. });
  1772. newList.forEach((v) => {
  1773. v.deptArrStr = v.deptArr.map((v) => v.dept).toString();
  1774. v.categoryArrStr = v.categoryArr
  1775. .map((v) => v.mutiCategory)
  1776. .toString();
  1777. });
  1778. console.log(newList);
  1779. // 处理后端返回的数据 end
  1780. $scope.gridOptions.totalItems = myData.totalNum;
  1781. $scope.myData = newList;
  1782. for (var i = 0; i < $scope.myData.length; i++) {
  1783. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  1784. }
  1785. $scope.ldloading[style.replace("-", "_")] = false;
  1786. },
  1787. function () {
  1788. $scope.ldloading[style.replace("-", "_")] = false;
  1789. }
  1790. );
  1791. };
  1792. // 搜索
  1793. $scope.searchData = function () {
  1794. $scope.refreshData("expand-right", $scope.fileData);
  1795. };
  1796. // 清空
  1797. $scope.clean = function () {
  1798. delete $scope.fileData.incidentAssignManager.content;
  1799. delete $scope.fileData.incidentAssignManager.category;
  1800. $scope.getCategoryData();
  1801. $scope.refreshData("expand-right", $scope.fileData);
  1802. };
  1803. // 获取故障现象下拉
  1804. $scope.model = {};
  1805. $scope.categoryData = [];
  1806. $scope.getCategoryData = function (s, fn) {
  1807. if (s) {
  1808. var filterKeyword = s.filterKeyword;
  1809. }
  1810. var postData = {
  1811. idx: 0,
  1812. sum: 1000,
  1813. };
  1814. if (filterKeyword) {
  1815. postData.incidentcategory = {
  1816. selectType: "pinyin_qs",
  1817. category: filterKeyword,
  1818. hierarchyQuery:'three'
  1819. };
  1820. }
  1821. $scope.my_data = [];
  1822. $scope.doing_async = true;
  1823. api_bpm_data
  1824. .fetchDataList("incidentcategory", postData)
  1825. .then(function (response) {
  1826. if (response.status == 200) {
  1827. var data = response.list;
  1828. if (filterKeyword) {
  1829. data.forEach((e) => {
  1830. e.isExpanded = true;
  1831. });
  1832. var li = transform(data).children;
  1833. console.log(li);
  1834. fn(li);
  1835. return;
  1836. } else {
  1837. var objects = [];
  1838. for (var i = 0; i < data.length; i++) {
  1839. var object = {};
  1840. object.id = data[i].id;
  1841. object.parent = data[i].parent;
  1842. object.category = data[i].category;
  1843. object.isExpanded = true;
  1844. objects.push(object);
  1845. }
  1846. $scope.my_data = convertParentToChildList(objects);
  1847. $scope.categoryData = angular.copy($scope.my_data);
  1848. }
  1849. if ($scope.my_data.length > 0) {
  1850. $scope.doing_async = false;
  1851. }
  1852. } else {
  1853. SweetAlert.swal({
  1854. title: "系统错误!",
  1855. text: "请刷新重试!",
  1856. type: "error",
  1857. });
  1858. }
  1859. });
  1860. };
  1861. $scope.getCategoryData();
  1862. $scope.refreshData("expand-right", $scope.fileData);
  1863. $scope.timer = $interval(function () {
  1864. $scope.refreshData2("expand-right", $scope.fileData);
  1865. }, $rootScope.refreshTime);
  1866. $scope.$on("$destroy", function () {
  1867. $interval.cancel($scope.timer);
  1868. });
  1869. },
  1870. ]);