deptBindUserCtrl.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  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. },
  406. };
  407. api_user_data.fetchDataList("user", userData).then(function (data) {
  408. $scope.jry_userData = data.list;
  409. if ($scope.incidentModel.user) {
  410. if (!$scope.incidentModel.user.name) {
  411. $scope.incidentModel.user = data.list.find(
  412. (v) => v.id == $scope.incidentModel.user.id
  413. );
  414. }
  415. }
  416. });
  417. };
  418. $scope.jry_userSearch();
  419. // 处理组模糊搜索
  420. $scope.jry_groupSearch = function (key = "") {
  421. var groupData = {
  422. idx: 0,
  423. sum: 10,
  424. group: {
  425. group: { selectType: "nouser" },
  426. },
  427. };
  428. api_user_data
  429. .fetchDataList("group", groupData)
  430. .then(function (data) {
  431. $scope.jry_groupData = data.list;
  432. });
  433. };
  434. $scope.jry_groupSearch();
  435. // 故障现象选中
  436. $scope.categorySelect = "";
  437. $scope.jry_categoryData = [];
  438. $scope.jry_categoryData_selected = [];
  439. $scope.jry_categoryData_copy_left = [];
  440. $scope.jry_categoryData_copy_right = [];
  441. $scope.changeCategorySelect = function (item, type) {
  442. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  443. $scope.categorySelect = item;
  444. item.selected = !item.selected;
  445. console.log(item, type);
  446. switch (type) {
  447. case "left":
  448. if (item.selected) {
  449. //选中
  450. $scope.jry_categoryData_copy_left.push(item);
  451. } else {
  452. // 取消
  453. $scope.jry_categoryData_copy_left =
  454. $scope.jry_categoryData_copy_left.filter(
  455. (v) => v.id != item.id
  456. );
  457. }
  458. console.log($scope.jry_categoryData_copy_left, "left");
  459. break;
  460. case "right":
  461. if (item.selected) {
  462. //选中
  463. $scope.jry_categoryData_copy_right.push(item);
  464. } else {
  465. // 取消
  466. $scope.jry_categoryData_copy_right =
  467. $scope.jry_categoryData_copy_right.filter(
  468. (v) => v.id != item.id
  469. );
  470. }
  471. console.log($scope.jry_categoryData_copy_right, "right");
  472. break;
  473. }
  474. };
  475. // 故障现象查询
  476. $scope.c_timer = null;
  477. $scope.c_keyword = "";
  478. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  479. $scope.c_keyword = key;
  480. clearTimeout($scope.c_timer);
  481. $scope.c_timer = setTimeout(() => {
  482. var categoryData = {
  483. idx: 0,
  484. sum: 9999,
  485. incidentcategory: {
  486. category: key,
  487. selectType: "pinyin_qs",
  488. hierarchyQuery:'three'
  489. },
  490. };
  491. $scope.loading_c = true;
  492. if(isFirst){
  493. $scope.loading_b = true;
  494. }
  495. api_user_data
  496. .fetchDataList("incidentcategory", categoryData)
  497. .then(function (data) {
  498. if ($scope.c_keyword == key) {
  499. $scope.loading_c = false;
  500. $scope.loading_b = false;
  501. data.list.forEach((v) => {
  502. v.selected = false; //$scope.jry_categoryData_copy_left
  503. $scope.jry_categoryData_copy_left.forEach((vv) => {
  504. if (v.id == vv.id) {
  505. v.selected = true;
  506. }
  507. });
  508. if (v.mutiCategory) {
  509. v.mutiCategory = v.mutiCategory.replace(
  510. $scope.jry_modelLeft,
  511. '<span class="colorRed">' +
  512. $scope.jry_modelLeft +
  513. "</span>"
  514. );
  515. }
  516. });
  517. if(!isFirst){
  518. //需要过滤右边的选项liaomingming
  519. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  520. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  521. }else{
  522. var categoryArrIds = selectdata.categoryArr.map(v=>v.id);
  523. var arr1 = [];
  524. var arr1_selected = [];
  525. arr1 = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) == -1 });
  526. arr1_selected = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) > -1 });
  527. $scope.jry_categoryData = arr1;
  528. $scope.jry_categoryData_selected = arr1_selected;
  529. }
  530. }
  531. });
  532. }, 500);
  533. };
  534. $scope.jry_categorySearch('',true);
  535. function multisort(array, ...compairers) {
  536. return array.sort((a, b) => {
  537. for (const c of compairers) {
  538. const r = c(a, b);
  539. if (r !== 0) {
  540. return r;
  541. }
  542. }
  543. });
  544. }
  545. // toRight
  546. $scope.toRight = function (arr) {
  547. var arrLeft = angular.copy($scope.jry_categoryData);
  548. var arRight = angular.copy($scope.jry_categoryData_selected);
  549. arr.forEach((v) => (v.selected = false));
  550. arRight = $scope.jry_categoryData_selected.concat(arr);
  551. arr.forEach((v) => {
  552. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  553. });
  554. $scope.jry_categoryData_copy_left = [];
  555. $scope.jry_categoryData = multisort(
  556. arrLeft,
  557. (a, b) => a.hierarchy - b.hierarchy,
  558. (a, b) => a.id - b.id
  559. );
  560. $scope.jry_categoryData_selected = multisort(
  561. arRight,
  562. (a, b) => a.hierarchy - b.hierarchy,
  563. (a, b) => a.id - b.id
  564. );
  565. };
  566. // toLeft
  567. $scope.toLeft = function (arr) {
  568. // var arrLeft = angular.copy($scope.jry_categoryData);
  569. var arRight = angular.copy($scope.jry_categoryData_selected);
  570. arr.forEach((v) => (v.selected = false));
  571. // arrLeft = arrLeft.concat(arr);
  572. arr.forEach((v) => {
  573. arRight = arRight.filter((vv) => vv.id != v.id);
  574. });
  575. $scope.jry_categoryData_copy_right = [];
  576. // $scope.jry_categoryData = multisort(
  577. // arrLeft,
  578. // (a, b) => a.hierarchy - b.hierarchy,
  579. // (a, b) => a.id - b.id
  580. // );
  581. $scope.jry_categoryData_selected = multisort(
  582. arRight,
  583. (a, b) => a.hierarchy - b.hierarchy,
  584. (a, b) => a.id - b.id
  585. );
  586. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  587. };
  588. // 取消
  589. $scope.cancel = function () {
  590. $modalInstance.dismiss("cancel");
  591. };
  592. // -------------------end----------------------
  593. },
  594. resolve: {
  595. scope: function() {
  596. return $scope;
  597. },
  598. selectdata: function() {
  599. return selectdata;
  600. }
  601. },
  602. });
  603. };
  604. // 修改
  605. $scope.saveData = function (selectdata) {
  606. console.log(selectdata);
  607. $modal.open({
  608. templateUrl: "assets/views/system/tpl/deptBindUserchange.html",
  609. controller: function (
  610. $scope,
  611. scope,
  612. $modalInstance,
  613. SweetAlert,
  614. api_user_data,
  615. api_bpm_domain,
  616. $rootScope
  617. ) {
  618. // -------------------start----------------------
  619. $scope.title = "修改科室派单组合";
  620. //事件列表数据存储
  621. $scope.incidentModel = {
  622. branch: selectdata.branchObj, //院区
  623. department: selectdata.deptArr, //科室
  624. assign: selectdata.userOrGroupType, //派单人或组
  625. duty: {id: selectdata.dutyId, dept: selectdata.dutyName}, //责任科室
  626. };
  627. if(selectdata.userOrGroupType == 1){
  628. $scope.incidentModel.user = selectdata.userObj;//处理人
  629. }else if(selectdata.userOrGroupType == 2){
  630. $scope.incidentModel.group = selectdata.groupObj;//处理组
  631. }
  632. // 保存
  633. $scope.ok = function () {
  634. if (!$scope.incidentModel.duty) {
  635. SweetAlert.swal({
  636. title: "提示",
  637. text: "请选择责任科室!",
  638. type: "error",
  639. confirmButtonColor: "#DD6B55",
  640. });
  641. return;
  642. }
  643. if (!$scope.incidentModel.branch) {
  644. SweetAlert.swal({
  645. title: "提示",
  646. text: "请选择院区!",
  647. type: "error",
  648. confirmButtonColor: "#DD6B55",
  649. });
  650. return;
  651. }
  652. if (!$scope.incidentModel.department.length) {
  653. SweetAlert.swal({
  654. title: "提示",
  655. text: "请选择科室!",
  656. type: "error",
  657. confirmButtonColor: "#DD6B55",
  658. });
  659. return;
  660. }
  661. if (!$scope.incidentModel.department.length) {
  662. SweetAlert.swal({
  663. title: "提示",
  664. text: "请选择科室!",
  665. type: "error",
  666. confirmButtonColor: "#DD6B55",
  667. });
  668. return;
  669. }
  670. if ($scope.incidentModel.assign == 0) {
  671. SweetAlert.swal({
  672. title: "提示",
  673. text: "请选择派单给人或组!",
  674. type: "error",
  675. confirmButtonColor: "#DD6B55",
  676. });
  677. $scope.flag = false;
  678. return;
  679. }
  680. if (
  681. $scope.incidentModel.assign == 1 &&
  682. !$scope.incidentModel.user
  683. ) {
  684. SweetAlert.swal({
  685. title: "提示",
  686. text: "请选择处理人!",
  687. type: "error",
  688. confirmButtonColor: "#DD6B55",
  689. });
  690. $scope.flag = false;
  691. return;
  692. }
  693. if (
  694. $scope.incidentModel.assign == 2 &&
  695. !$scope.incidentModel.group
  696. ) {
  697. SweetAlert.swal({
  698. title: "提示",
  699. text: "请选择处理组!",
  700. type: "error",
  701. confirmButtonColor: "#DD6B55",
  702. });
  703. $scope.flag = false;
  704. return;
  705. }
  706. // 确定
  707. $scope.flag = false;
  708. handlerStart();
  709. // 保存
  710. function handlerStart() {
  711. if ($scope.flag) {
  712. return;
  713. }
  714. $scope.flag = true;
  715. var postData = {
  716. deptIds: $scope.incidentModel.department
  717. .map((v) => v.id)
  718. .toString(),
  719. categoryIds: $scope.jry_categoryData_selected
  720. .map((v) => v.id)
  721. .toString(),
  722. incidentAssignManager: {
  723. batchId:selectdata.batchId,
  724. userOrGroupType: $scope.incidentModel.assign,
  725. branch: $scope.incidentModel.branch.id,
  726. dutyId: $scope.incidentModel.duty.id
  727. },
  728. };
  729. if ($scope.incidentModel.assign == 1) {
  730. // 处理人
  731. postData.incidentAssignManager.handleUser =
  732. $scope.incidentModel.user.id;
  733. } else if ($scope.incidentModel.assign == 2) {
  734. // 处理组
  735. postData.incidentAssignManager.group =
  736. $scope.incidentModel.group.id;
  737. }
  738. console.log($scope.incidentModel);
  739. console.log($scope.jry_categoryData_selected);
  740. // return;
  741. api_custom
  742. .updData("incidentAssignManager", postData)
  743. .then(function (response) {
  744. console.log(response);
  745. $scope.flag = false;
  746. if (response.status == 200) {
  747. SweetAlert.swal(
  748. {
  749. title: "保存成功!",
  750. type: "success",
  751. confirmButtonColor: "#007AFF",
  752. },
  753. function () {
  754. $modalInstance.dismiss("cancel");
  755. // $state.go("app.businessConfiguration.deptBindUser");
  756. scope.refreshData("expand-right", scope.fileData);
  757. }
  758. );
  759. } else {
  760. SweetAlert.swal({
  761. title: "操作失败",
  762. text: response.error || "操作失败, 请稍后再试!",
  763. type: "error",
  764. });
  765. }
  766. });
  767. }
  768. };
  769. // 院区
  770. $scope.jry_branchSearch = function (key = "") {
  771. var branchData = {
  772. idx: 0,
  773. sum: 10,
  774. };
  775. api_user_data
  776. .fetchDataList("branch", branchData)
  777. .then(function (data) {
  778. $scope.jry_branchData = data.list;
  779. });
  780. };
  781. // 责任科室模糊搜索
  782. $scope.jry_dutySearch = function (key = "",branchId,isFirst=false) {
  783. var deptData = {
  784. idx: 0,
  785. sum: 10,
  786. dutyDepartment: {
  787. branch:branchId,
  788. dept: key,
  789. selectType: "pinyin_qs",
  790. },
  791. };
  792. api_user_data
  793. .fetchDataList("dutyDepartment", deptData)
  794. .then(function (data) {
  795. $scope.jry_dutyData = data.list;
  796. });
  797. };
  798. // 报修科室模糊搜索
  799. $scope.jry_deptSearch = function (key = "",branchId,isFirst=false) {
  800. var deptData = {
  801. idx: 0,
  802. sum: 10,
  803. department: {
  804. branch:branchId,
  805. dept: key,
  806. selectType: "pinyin_qs",
  807. },
  808. };
  809. api_user_data
  810. .fetchDataList("department", deptData)
  811. .then(function (data) {
  812. var ids = $scope.incidentModel.department.map(v=>v.id);
  813. $scope.jry_deptData = data.list.filter(v=>!ids.includes(v.id));
  814. // if(isFirst){
  815. // var deptArr = selectdata.deptArr.map(v=>v.id);
  816. // $scope.incidentModel.department = data.list.filter(function(v){ return deptArr.indexOf(v.id) > -1 })
  817. // }
  818. });
  819. };
  820. $scope.$watch('incidentModel.branch',function(newVal,oldVal){
  821. if(newVal.id != oldVal.id){
  822. $scope.jry_deptSearch('',newVal.id);
  823. $scope.incidentModel.department = [];
  824. $scope.jry_dutySearch('',newVal.id);
  825. $scope.incidentModel.duty = '';
  826. }
  827. })
  828. // $scope.jry_deptSearch();
  829. // 处理人模糊搜索
  830. $scope.jry_userSearch = function (key = "") {
  831. var userData = {
  832. idx: 0,
  833. sum: 10,
  834. user: {
  835. roledata: { rolecode: "first-line support" },
  836. selectDetails: "1",
  837. simple: true,
  838. name: key,
  839. selectType: "pinyin_qs",
  840. },
  841. };
  842. api_user_data.fetchDataList("user", userData).then(function (data) {
  843. $scope.jry_userData = data.list;
  844. if ($scope.incidentModel.user) {
  845. if (!$scope.incidentModel.user.name) {
  846. $scope.incidentModel.user = data.list.find(
  847. (v) => v.id == $scope.incidentModel.user.id
  848. );
  849. }
  850. }
  851. });
  852. };
  853. $scope.jry_userSearch();
  854. // 处理组模糊搜索
  855. $scope.jry_groupSearch = function (key = "") {
  856. var groupData = {
  857. idx: 0,
  858. sum: 10,
  859. group: {
  860. group: { selectType: "nouser" },
  861. },
  862. };
  863. api_user_data
  864. .fetchDataList("group", groupData)
  865. .then(function (data) {
  866. $scope.jry_groupData = data.list;
  867. });
  868. };
  869. $scope.jry_groupSearch();
  870. // 故障现象选中
  871. $scope.categorySelect = "";
  872. $scope.jry_categoryData = [];
  873. $scope.jry_categoryData_selected = [];
  874. $scope.jry_categoryData_copy_left = [];
  875. $scope.jry_categoryData_copy_right = [];
  876. $scope.changeCategorySelect = function (item, type) {
  877. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  878. $scope.categorySelect = item;
  879. item.selected = !item.selected;
  880. console.log(item, type);
  881. switch (type) {
  882. case "left":
  883. if (item.selected) {
  884. //选中
  885. $scope.jry_categoryData_copy_left.push(item);
  886. } else {
  887. // 取消
  888. $scope.jry_categoryData_copy_left =
  889. $scope.jry_categoryData_copy_left.filter(
  890. (v) => v.id != item.id
  891. );
  892. }
  893. console.log($scope.jry_categoryData_copy_left, "left");
  894. break;
  895. case "right":
  896. if (item.selected) {
  897. //选中
  898. $scope.jry_categoryData_copy_right.push(item);
  899. } else {
  900. // 取消
  901. $scope.jry_categoryData_copy_right =
  902. $scope.jry_categoryData_copy_right.filter(
  903. (v) => v.id != item.id
  904. );
  905. }
  906. console.log($scope.jry_categoryData_copy_right, "right");
  907. break;
  908. }
  909. };
  910. // 故障现象查询
  911. $scope.c_timer = null;
  912. $scope.c_keyword = "";
  913. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  914. $scope.c_keyword = key;
  915. clearTimeout($scope.c_timer);
  916. $scope.c_timer = setTimeout(() => {
  917. var categoryData = {
  918. idx: 0,
  919. sum: 9999,
  920. incidentcategory: {
  921. category: key,
  922. selectType: "pinyin_qs",
  923. hierarchyQuery:'three'
  924. },
  925. };
  926. $scope.loading_c = true;
  927. if(isFirst){
  928. $scope.loading_b = true;
  929. }
  930. api_user_data
  931. .fetchDataList("incidentcategory", categoryData)
  932. .then(function (data) {
  933. if ($scope.c_keyword == key) {
  934. $scope.loading_c = false;
  935. $scope.loading_b = false;
  936. data.list.forEach((v) => {
  937. v.selected = false; //$scope.jry_categoryData_copy_left
  938. $scope.jry_categoryData_copy_left.forEach((vv) => {
  939. if (v.id == vv.id) {
  940. v.selected = true;
  941. }
  942. });
  943. if (v.mutiCategory) {
  944. v.mutiCategory = v.mutiCategory.replace(
  945. $scope.jry_modelLeft,
  946. '<span class="colorRed">' +
  947. $scope.jry_modelLeft +
  948. "</span>"
  949. );
  950. }
  951. });
  952. if(!isFirst){
  953. //需要过滤右边的选项liaomingming
  954. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  955. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  956. }else{
  957. var categoryArrIds = selectdata.categoryArr.map(v=>v.id);
  958. var arr1 = [];
  959. var arr1_selected = [];
  960. arr1 = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) == -1 });
  961. arr1_selected = data.list.filter(function(v){ return categoryArrIds.indexOf(v.id) > -1 });
  962. $scope.jry_categoryData = arr1;
  963. $scope.jry_categoryData_selected = arr1_selected;
  964. }
  965. }
  966. });
  967. }, 500);
  968. };
  969. $scope.jry_categorySearch('',true);
  970. function multisort(array, ...compairers) {
  971. return array.sort((a, b) => {
  972. for (const c of compairers) {
  973. const r = c(a, b);
  974. if (r !== 0) {
  975. return r;
  976. }
  977. }
  978. });
  979. }
  980. // toRight
  981. $scope.toRight = function (arr) {
  982. var arrLeft = angular.copy($scope.jry_categoryData);
  983. var arRight = angular.copy($scope.jry_categoryData_selected);
  984. arr.forEach((v) => (v.selected = false));
  985. arRight = $scope.jry_categoryData_selected.concat(arr);
  986. arr.forEach((v) => {
  987. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  988. });
  989. $scope.jry_categoryData_copy_left = [];
  990. $scope.jry_categoryData = multisort(
  991. arrLeft,
  992. (a, b) => a.hierarchy - b.hierarchy,
  993. (a, b) => a.id - b.id
  994. );
  995. $scope.jry_categoryData_selected = multisort(
  996. arRight,
  997. (a, b) => a.hierarchy - b.hierarchy,
  998. (a, b) => a.id - b.id
  999. );
  1000. };
  1001. // toLeft
  1002. $scope.toLeft = function (arr) {
  1003. // var arrLeft = angular.copy($scope.jry_categoryData);
  1004. var arRight = angular.copy($scope.jry_categoryData_selected);
  1005. arr.forEach((v) => (v.selected = false));
  1006. // arrLeft = arrLeft.concat(arr);
  1007. arr.forEach((v) => {
  1008. arRight = arRight.filter((vv) => vv.id != v.id);
  1009. });
  1010. $scope.jry_categoryData_copy_right = [];
  1011. // $scope.jry_categoryData = multisort(
  1012. // arrLeft,
  1013. // (a, b) => a.hierarchy - b.hierarchy,
  1014. // (a, b) => a.id - b.id
  1015. // );
  1016. $scope.jry_categoryData_selected = multisort(
  1017. arRight,
  1018. (a, b) => a.hierarchy - b.hierarchy,
  1019. (a, b) => a.id - b.id
  1020. );
  1021. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  1022. };
  1023. // 取消
  1024. $scope.cancel = function () {
  1025. $modalInstance.dismiss("cancel");
  1026. };
  1027. // -------------------end----------------------
  1028. },
  1029. resolve: {
  1030. scope: function() {
  1031. return $scope;
  1032. },
  1033. selectdata: function() {
  1034. return selectdata;
  1035. }
  1036. },
  1037. });
  1038. };
  1039. function convertListToTree(data, treeMap) {
  1040. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  1041. var root = null; //Initially set our loop to null
  1042. var parentNode = null;
  1043. //loop over data
  1044. for (var i = 0; i < data.length; i++) {
  1045. var datum = data[i];
  1046. //each node will have children, so let's give it a "children" poperty
  1047. datum.children = [];
  1048. //add an entry for this node to the map so that any future children can
  1049. //lookup the parent
  1050. idToNodeMap[datum.id] = datum;
  1051. //Does this node have a parent?
  1052. if (typeof datum.parent === "undefined" || datum.parent == null) {
  1053. //Doesn't look like it, so this node is the root of the tree
  1054. root = datum;
  1055. treeMap[datum.id] = root;
  1056. } else {
  1057. //This node has a parent, so let's look it up using the id
  1058. parentNode = idToNodeMap[datum.parent.id];
  1059. //We don't need this property, so let's delete it.
  1060. delete datum.parent;
  1061. //Let's add the current node as a child of the parent node.
  1062. parentNode.children.push(datum);
  1063. }
  1064. }
  1065. return root;
  1066. }
  1067. function convertParentToChildList(data) {
  1068. var treeMap = {};
  1069. var list = [];
  1070. convertListToTree(data, treeMap);
  1071. angular.forEach(treeMap, function (item) {
  1072. list.push(item);
  1073. });
  1074. return list;
  1075. }
  1076. // 新增
  1077. $scope.addData = function () {
  1078. $modal.open({
  1079. templateUrl: "assets/views/system/tpl/deptBindUserchange.html",
  1080. controller: function (
  1081. $scope,
  1082. scope,
  1083. $modalInstance,
  1084. SweetAlert,
  1085. api_user_data,
  1086. api_bpm_domain,
  1087. $rootScope
  1088. ) {
  1089. // -------------------start----------------------
  1090. $scope.title = "新增科室派单组合";
  1091. //事件列表数据存储
  1092. $scope.incidentModel = {
  1093. branch: "", //院区
  1094. department: [], //科室
  1095. assign: 1, //派单人或组
  1096. user: "", //处理人
  1097. group: "", //处理组
  1098. duty: "", //责任科室
  1099. };
  1100. // 保存
  1101. $scope.ok = function () {
  1102. if (!$scope.incidentModel.duty) {
  1103. SweetAlert.swal({
  1104. title: "提示",
  1105. text: "请选择责任科室!",
  1106. type: "error",
  1107. confirmButtonColor: "#DD6B55",
  1108. });
  1109. return;
  1110. }
  1111. if (!$scope.incidentModel.branch) {
  1112. SweetAlert.swal({
  1113. title: "提示",
  1114. text: "请选择院区!",
  1115. type: "error",
  1116. confirmButtonColor: "#DD6B55",
  1117. });
  1118. return;
  1119. }
  1120. if (!$scope.incidentModel.department.length) {
  1121. SweetAlert.swal({
  1122. title: "提示",
  1123. text: "请选择科室!",
  1124. type: "error",
  1125. confirmButtonColor: "#DD6B55",
  1126. });
  1127. return;
  1128. }
  1129. if (!$scope.incidentModel.department.length) {
  1130. SweetAlert.swal({
  1131. title: "提示",
  1132. text: "请选择科室!",
  1133. type: "error",
  1134. confirmButtonColor: "#DD6B55",
  1135. });
  1136. return;
  1137. }
  1138. if ($scope.incidentModel.assign == 0) {
  1139. SweetAlert.swal({
  1140. title: "提示",
  1141. text: "请选择派单给人或组!",
  1142. type: "error",
  1143. confirmButtonColor: "#DD6B55",
  1144. });
  1145. $scope.flag = false;
  1146. return;
  1147. }
  1148. if (
  1149. $scope.incidentModel.assign == 1 &&
  1150. !$scope.incidentModel.user
  1151. ) {
  1152. SweetAlert.swal({
  1153. title: "提示",
  1154. text: "请选择处理人!",
  1155. type: "error",
  1156. confirmButtonColor: "#DD6B55",
  1157. });
  1158. $scope.flag = false;
  1159. return;
  1160. }
  1161. if (
  1162. $scope.incidentModel.assign == 2 &&
  1163. !$scope.incidentModel.group
  1164. ) {
  1165. SweetAlert.swal({
  1166. title: "提示",
  1167. text: "请选择处理组!",
  1168. type: "error",
  1169. confirmButtonColor: "#DD6B55",
  1170. });
  1171. $scope.flag = false;
  1172. return;
  1173. }
  1174. // 确定
  1175. $scope.flag = false;
  1176. handlerStart();
  1177. // 保存
  1178. function handlerStart() {
  1179. if ($scope.flag) {
  1180. return;
  1181. }
  1182. $scope.flag = true;
  1183. var postData = {
  1184. deptIds: $scope.incidentModel.department
  1185. .map((v) => v.id)
  1186. .toString(),
  1187. categoryIds: $scope.jry_categoryData_selected
  1188. .map((v) => v.id)
  1189. .toString(),
  1190. incidentAssignManager: {
  1191. userOrGroupType: $scope.incidentModel.assign,
  1192. branch: $scope.incidentModel.branch.id,
  1193. dutyId: $scope.incidentModel.duty.id
  1194. },
  1195. };
  1196. if ($scope.incidentModel.assign == 1) {
  1197. // 处理人
  1198. postData.incidentAssignManager.handleUser =
  1199. $scope.incidentModel.user.id;
  1200. } else if ($scope.incidentModel.assign == 2) {
  1201. // 处理组
  1202. postData.incidentAssignManager.group =
  1203. $scope.incidentModel.group.id;
  1204. }
  1205. console.log($scope.incidentModel);
  1206. console.log($scope.jry_categoryData_selected);
  1207. // return;
  1208. api_custom
  1209. .addData("incidentAssignManager", postData)
  1210. .then(function (response) {
  1211. console.log(response);
  1212. $scope.flag = false;
  1213. if (response.status == 200) {
  1214. SweetAlert.swal(
  1215. {
  1216. title: "保存成功!",
  1217. type: "success",
  1218. confirmButtonColor: "#007AFF",
  1219. },
  1220. function () {
  1221. $modalInstance.dismiss("cancel");
  1222. // $state.go("app.businessConfiguration.deptBindUser");
  1223. scope.refreshData("expand-right", scope.fileData);
  1224. }
  1225. );
  1226. } else {
  1227. SweetAlert.swal({
  1228. title: "操作失败",
  1229. text: response.error || "操作失败, 请稍后再试!",
  1230. type: "error",
  1231. });
  1232. }
  1233. });
  1234. }
  1235. };
  1236. // 院区
  1237. $scope.jry_branchSearch = function (key = "") {
  1238. var branchData = {
  1239. idx: 0,
  1240. sum: 10,
  1241. };
  1242. api_user_data
  1243. .fetchDataList("branch", branchData)
  1244. .then(function (data) {
  1245. $scope.jry_branchData = data.list;
  1246. });
  1247. };
  1248. // 责任科室模糊搜索
  1249. $scope.jry_dutySearch = function (key = "",branchId) {
  1250. var deptData = {
  1251. idx: 0,
  1252. sum: 10,
  1253. dutyDepartment: {
  1254. branch:branchId,
  1255. dept: key,
  1256. selectType: "pinyin_qs",
  1257. },
  1258. };
  1259. api_user_data
  1260. .fetchDataList("dutyDepartment", deptData)
  1261. .then(function (data) {
  1262. $scope.jry_dutyData = data.list;
  1263. });
  1264. };
  1265. // 报修科室模糊搜索
  1266. $scope.jry_deptSearch = function (key = "",branchId) {
  1267. var deptData = {
  1268. idx: 0,
  1269. sum: 10,
  1270. department: {
  1271. branch:branchId,
  1272. dept: key,
  1273. selectType: "pinyin_qs",
  1274. },
  1275. };
  1276. api_user_data
  1277. .fetchDataList("department", deptData)
  1278. .then(function (data) {
  1279. // $scope.jry_deptData = data.list;
  1280. var ids = $scope.incidentModel.department.map(v=>v.id);
  1281. $scope.jry_deptData = data.list.filter(v=>!ids.includes(v.id));
  1282. });
  1283. };
  1284. $scope.$watch('incidentModel.branch',function(newVal,oldVal){
  1285. if(newVal.id != oldVal.id){
  1286. $scope.jry_deptSearch('',newVal.id);
  1287. $scope.incidentModel.department = [];
  1288. $scope.jry_dutySearch('',newVal.id);
  1289. $scope.incidentModel.duty = '';
  1290. }
  1291. })
  1292. // $scope.jry_deptSearch();
  1293. // 处理人模糊搜索
  1294. $scope.jry_userSearch = function (key = "") {
  1295. var userData = {
  1296. idx: 0,
  1297. sum: 10,
  1298. user: {
  1299. roledata: { rolecode: "first-line support" },
  1300. selectDetails: "1",
  1301. simple: true,
  1302. name: key,
  1303. selectType: "pinyin_qs",
  1304. },
  1305. };
  1306. api_user_data.fetchDataList("user", userData).then(function (data) {
  1307. $scope.jry_userData = data.list;
  1308. if ($scope.incidentModel.user) {
  1309. if (!$scope.incidentModel.user.name) {
  1310. $scope.incidentModel.user = data.list.find(
  1311. (v) => v.id == $scope.incidentModel.user.id
  1312. );
  1313. }
  1314. }
  1315. });
  1316. };
  1317. $scope.jry_userSearch();
  1318. // 处理组模糊搜索
  1319. $scope.jry_groupSearch = function (key = "") {
  1320. var groupData = {
  1321. idx: 0,
  1322. sum: 10,
  1323. group: {
  1324. group: { selectType: "nouser" },
  1325. },
  1326. };
  1327. api_user_data
  1328. .fetchDataList("group", groupData)
  1329. .then(function (data) {
  1330. $scope.jry_groupData = data.list;
  1331. });
  1332. };
  1333. $scope.jry_groupSearch();
  1334. // 故障现象选中
  1335. $scope.categorySelect = "";
  1336. $scope.jry_categoryData = [];
  1337. $scope.jry_categoryData_selected = [];
  1338. $scope.jry_categoryData_copy_left = [];
  1339. $scope.jry_categoryData_copy_right = [];
  1340. $scope.changeCategorySelect = function (item, type) {
  1341. item.mutiCategory = item.mutiCategory.replace(/<[^<>]+>/g, "");
  1342. $scope.categorySelect = item;
  1343. item.selected = !item.selected;
  1344. console.log(item, type);
  1345. switch (type) {
  1346. case "left":
  1347. if (item.selected) {
  1348. //选中
  1349. $scope.jry_categoryData_copy_left.push(item);
  1350. } else {
  1351. // 取消
  1352. $scope.jry_categoryData_copy_left =
  1353. $scope.jry_categoryData_copy_left.filter(
  1354. (v) => v.id != item.id
  1355. );
  1356. }
  1357. console.log($scope.jry_categoryData_copy_left, "left");
  1358. break;
  1359. case "right":
  1360. if (item.selected) {
  1361. //选中
  1362. $scope.jry_categoryData_copy_right.push(item);
  1363. } else {
  1364. // 取消
  1365. $scope.jry_categoryData_copy_right =
  1366. $scope.jry_categoryData_copy_right.filter(
  1367. (v) => v.id != item.id
  1368. );
  1369. }
  1370. console.log($scope.jry_categoryData_copy_right, "right");
  1371. break;
  1372. }
  1373. };
  1374. // 故障现象查询
  1375. $scope.c_timer = null;
  1376. $scope.c_keyword = "";
  1377. $scope.jry_categorySearch = function (key = "",isFirst=false) {
  1378. $scope.c_keyword = key;
  1379. clearTimeout($scope.c_timer);
  1380. $scope.c_timer = setTimeout(() => {
  1381. var categoryData = {
  1382. idx: 0,
  1383. sum: 9999,
  1384. incidentcategory: {
  1385. category: key,
  1386. selectType: "pinyin_qs",
  1387. hierarchyQuery:'three'
  1388. },
  1389. };
  1390. $scope.loading_c = true;
  1391. if(isFirst){
  1392. $scope.loading_b = true;
  1393. }
  1394. api_user_data
  1395. .fetchDataList("incidentcategory", categoryData)
  1396. .then(function (data) {
  1397. if ($scope.c_keyword == key) {
  1398. $scope.loading_c = false;
  1399. $scope.loading_b = false;
  1400. data.list.forEach((v) => {
  1401. v.selected = false; //$scope.jry_categoryData_copy_left
  1402. $scope.jry_categoryData_copy_left.forEach((vv) => {
  1403. if (v.id == vv.id) {
  1404. v.selected = true;
  1405. }
  1406. });
  1407. if (v.mutiCategory) {
  1408. v.mutiCategory = v.mutiCategory.replace(
  1409. $scope.jry_modelLeft,
  1410. '<span class="colorRed">' +
  1411. $scope.jry_modelLeft +
  1412. "</span>"
  1413. );
  1414. }
  1415. });
  1416. //需要过滤右边的选项liaomingming
  1417. var jry_categoryData_selected = $scope.jry_categoryData_selected.map(v=>v.id);
  1418. $scope.jry_categoryData = data.list.filter(function(v){ return jry_categoryData_selected.indexOf(v.id) == -1 });
  1419. }
  1420. });
  1421. }, 500);
  1422. };
  1423. $scope.jry_categorySearch('',true);
  1424. function multisort(array, ...compairers) {
  1425. return array.sort((a, b) => {
  1426. for (const c of compairers) {
  1427. const r = c(a, b);
  1428. if (r !== 0) {
  1429. return r;
  1430. }
  1431. }
  1432. });
  1433. }
  1434. // toRight
  1435. $scope.toRight = function (arr) {
  1436. var arrLeft = angular.copy($scope.jry_categoryData);
  1437. var arRight = angular.copy($scope.jry_categoryData_selected);
  1438. arr.forEach((v) => (v.selected = false));
  1439. arRight = $scope.jry_categoryData_selected.concat(arr);
  1440. arr.forEach((v) => {
  1441. arrLeft = arrLeft.filter((vv) => vv.id != v.id);
  1442. });
  1443. $scope.jry_categoryData_copy_left = [];
  1444. $scope.jry_categoryData = multisort(
  1445. arrLeft,
  1446. (a, b) => a.hierarchy - b.hierarchy,
  1447. (a, b) => a.id - b.id
  1448. );
  1449. $scope.jry_categoryData_selected = multisort(
  1450. arRight,
  1451. (a, b) => a.hierarchy - b.hierarchy,
  1452. (a, b) => a.id - b.id
  1453. );
  1454. };
  1455. // toLeft
  1456. $scope.toLeft = function (arr) {
  1457. // var arrLeft = angular.copy($scope.jry_categoryData);
  1458. var arRight = angular.copy($scope.jry_categoryData_selected);
  1459. arr.forEach((v) => (v.selected = false));
  1460. // arrLeft = arrLeft.concat(arr);
  1461. arr.forEach((v) => {
  1462. arRight = arRight.filter((vv) => vv.id != v.id);
  1463. });
  1464. $scope.jry_categoryData_copy_right = [];
  1465. // $scope.jry_categoryData = multisort(
  1466. // arrLeft,
  1467. // (a, b) => a.hierarchy - b.hierarchy,
  1468. // (a, b) => a.id - b.id
  1469. // );
  1470. $scope.jry_categoryData_selected = multisort(
  1471. arRight,
  1472. (a, b) => a.hierarchy - b.hierarchy,
  1473. (a, b) => a.id - b.id
  1474. );
  1475. $scope.jry_categorySearch($scope.jry_modelLeft,false);
  1476. };
  1477. // 取消
  1478. $scope.cancel = function () {
  1479. $modalInstance.dismiss("cancel");
  1480. };
  1481. // -------------------end----------------------
  1482. },
  1483. resolve: {
  1484. scope: function() {
  1485. return $scope;
  1486. }
  1487. },
  1488. });
  1489. };
  1490. // 删除
  1491. $scope.removeData = function (selectdata) {
  1492. var modalInstance = $modal.open({
  1493. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  1494. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  1495. var rmvList = [];
  1496. $scope.title = "科室派单组合删除";
  1497. $scope.connect = "确定要删除此科室派单组合?";
  1498. rmvList.push(selectdata);
  1499. $scope.ok = function () {
  1500. $modalInstance.close(rmvList);
  1501. };
  1502. $scope.cancel = function () {
  1503. $modalInstance.dismiss("cancel");
  1504. };
  1505. },
  1506. size: "sm",
  1507. resolve: {
  1508. scope: function () {
  1509. return $scope;
  1510. },
  1511. selectdata: function () {
  1512. return selectdata;
  1513. },
  1514. },
  1515. });
  1516. modalInstance.result.then(function (selectedItem) {
  1517. if (selectedItem) {
  1518. if (selectedItem.length > 0) {
  1519. console.log(selectedItem);
  1520. api_custom
  1521. .rmvData("incidentAssignManager", {
  1522. batchId: selectedItem[0].batchId,
  1523. })
  1524. .then(function (response) {
  1525. if (response.status == 200) {
  1526. SweetAlert.swal(
  1527. {
  1528. title: "删除成功!",
  1529. type: "success",
  1530. confirmButtonColor: "#007AFF",
  1531. },
  1532. function () {
  1533. $scope.myData = _.reject($scope.myData, function (o) {
  1534. return _.includes(selectedItem, o.id);
  1535. });
  1536. $scope.selected = {
  1537. items: [],
  1538. };
  1539. $scope.gridOptions.totalItems =
  1540. $scope.gridOptions.totalItems - selectedItem.length;
  1541. // $scope.gridApi.grid.selection.selectedCount = 0;
  1542. $scope.refreshData("expand-right", $scope.fileData);
  1543. }
  1544. );
  1545. } else {
  1546. SweetAlert.swal({
  1547. title: "操作异常!",
  1548. text: "系统异常,请稍后重试,或者联系管理员!",
  1549. type: "error",
  1550. });
  1551. }
  1552. });
  1553. }
  1554. }
  1555. });
  1556. };
  1557. $scope.selected = {
  1558. items: [],
  1559. };
  1560. $scope.editted = {
  1561. items: [],
  1562. };
  1563. $scope.gridOptions.onRegisterApi = function (gridApi) {
  1564. $scope.gridApi = gridApi;
  1565. gridApi.pagination.on.paginationChanged(
  1566. $scope,
  1567. function (newPage, pageSize) {
  1568. var filtersData = $scope.memoryfilterData;
  1569. filtersData.idx = newPage - 1;
  1570. filtersData.sum = pageSize;
  1571. $scope.fileData.idx = newPage - 1;
  1572. $scope.fileData.sum = pageSize;
  1573. defaultFilterData = filtersData;
  1574. $scope.refreshData("expand-right", $scope.fileData);
  1575. }
  1576. );
  1577. // gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  1578. // scope.grid.appScope.selected.items = scope.entity;
  1579. // });
  1580. };
  1581. var defaultFilterData = {
  1582. idx: 0,
  1583. sum: 10,
  1584. };
  1585. $scope.memoryfilterData = {
  1586. idx: 0,
  1587. sum: 10,
  1588. };
  1589. $scope.fileData = {
  1590. idx: 0,
  1591. sum: 10,
  1592. incidentAssignManager: {},
  1593. };
  1594. $scope.ldloading = {};
  1595. $scope.refreshData = function (style, filterData) {
  1596. $scope.selected.items = {};
  1597. $scope.ldloading[style.replace("-", "_")] = true;
  1598. if (angular.isUndefined(filterData)) {
  1599. filterData = defaultFilterData;
  1600. }
  1601. $scope.myData = [];
  1602. $scope.selected = { items: [] };
  1603. // if ($scope.gridApi) {
  1604. // $scope.gridApi.grid.selection.selectedCount = 0;
  1605. // }
  1606. filterData = angular.copy(filterData);
  1607. api_custom.fetchDataList("incidentAssignManager", filterData).then(
  1608. function (data) {
  1609. var myData = Restangular.stripRestangular(data);
  1610. myData.data = myData.data || [];
  1611. // 处理后端返回的数据 start
  1612. myData.data.forEach((v) => {
  1613. v.forEach((vv) => {
  1614. vv.branchObj = { id: vv.branch, hosName: vv.branchName };
  1615. vv.categoryObj = {
  1616. id: vv.categoryId,
  1617. mutiCategory: vv.categoryName,
  1618. };
  1619. vv.deptObj = { id: vv.deptId, dept: vv.deptName };
  1620. if (vv.userOrGroupType == 1) {
  1621. vv.userObj = { id: vv.handleUser, name: vv.userName };
  1622. } else if (vv.userOrGroupType == 2) {
  1623. vv.groupObj = { id: vv.group, groupName: vv.groupName };
  1624. }
  1625. });
  1626. });
  1627. console.log(myData.data);
  1628. var newList = [];
  1629. myData.data.forEach((v, i) => {
  1630. v.forEach((vv) => {
  1631. if (newList[i]) {
  1632. // 存在
  1633. if (!newList[i].categoryArr) {
  1634. newList[i].categoryArr = [newList[i].categoryObj];
  1635. } else {
  1636. let flag = newList[i].categoryArr.some(
  1637. (vvv) => vvv.id == vv.categoryObj.id
  1638. );
  1639. if (!flag) {
  1640. newList[i].categoryArr.push(vv.categoryObj);
  1641. }
  1642. }
  1643. if (!newList[i].deptArr) {
  1644. newList[i].deptArr = [newList[i].deptObj];
  1645. } else {
  1646. let flag = newList[i].deptArr.some(
  1647. (vvv) => vvv.id == vv.deptObj.id
  1648. );
  1649. if (!flag) {
  1650. newList[i].deptArr.push(vv.deptObj);
  1651. }
  1652. }
  1653. if (vv.userOrGroupType == 2 && !newList[i].group) {
  1654. newList[i].groupObj = vv.groupObj;
  1655. }
  1656. if (vv.userOrGroupType == 1 && !newList[i].handleUser) {
  1657. newList[i].userObj = vv.userObj;
  1658. }
  1659. if (!newList[i].branch) {
  1660. newList[i].branchObj = vv.branchObj;
  1661. }
  1662. } else {
  1663. // 不存在
  1664. vv.deptArr = [vv.deptObj];
  1665. vv.categoryArr = [vv.categoryObj];
  1666. newList[i] = vv;
  1667. }
  1668. });
  1669. });
  1670. newList.forEach((v) => {
  1671. v.deptArrStr = v.deptArr.map((v) => v.dept).toString();
  1672. v.categoryArrStr = v.categoryArr
  1673. .map((v) => v.mutiCategory)
  1674. .toString();
  1675. });
  1676. console.log(newList);
  1677. // 处理后端返回的数据 end
  1678. $scope.gridOptions.totalItems = myData.totalNum;
  1679. $scope.myData = newList;
  1680. for (var i = 0; i < $scope.myData.length; i++) {
  1681. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  1682. }
  1683. $scope.ldloading[style.replace("-", "_")] = false;
  1684. },
  1685. function () {
  1686. $scope.ldloading[style.replace("-", "_")] = false;
  1687. }
  1688. );
  1689. };
  1690. $scope.refreshData2 = function (style, filterData) {
  1691. $scope.selected.items = {};
  1692. $scope.ldloading[style.replace("-", "_")] = true;
  1693. if (angular.isUndefined(filterData)) {
  1694. filterData = defaultFilterData;
  1695. }
  1696. $scope.myData = [];
  1697. $scope.selected = { items: [] };
  1698. // if ($scope.gridApi) {
  1699. // $scope.gridApi.grid.selection.selectedCount = 0;
  1700. // }
  1701. filterData = angular.copy(filterData);
  1702. if (filterData.incidentAssignManager.category) {
  1703. filterData.incidentAssignManager.category =
  1704. filterData.incidentAssignManager.category.id;
  1705. }
  1706. api_custom.fetchDataList("incidentAssignManager", filterData).then(
  1707. function (data) {
  1708. var myData = Restangular.stripRestangular(data);
  1709. myData.data = myData.data || [];
  1710. // 处理后端返回的数据 start
  1711. myData.data.forEach((v) => {
  1712. v.forEach((vv) => {
  1713. vv.branchObj = { id: vv.branch, hosName: vv.branchName };
  1714. vv.categoryObj = {
  1715. id: vv.categoryId,
  1716. mutiCategory: vv.categoryName,
  1717. };
  1718. vv.deptObj = { id: vv.deptId, dept: vv.deptName };
  1719. if (vv.userOrGroupType == 1) {
  1720. vv.userObj = { id: vv.handleUser, name: vv.userName };
  1721. } else if (vv.userOrGroupType == 2) {
  1722. vv.groupObj = { id: vv.group, groupName: vv.groupName };
  1723. }
  1724. });
  1725. });
  1726. console.log(myData.data);
  1727. var newList = [];
  1728. myData.data.forEach((v, i) => {
  1729. v.forEach((vv) => {
  1730. if (newList[i]) {
  1731. // 存在
  1732. if (!newList[i].categoryArr) {
  1733. newList[i].categoryArr = [newList[i].categoryObj];
  1734. } else {
  1735. let flag = newList[i].categoryArr.some(
  1736. (vvv) => vvv.id == vv.categoryObj.id
  1737. );
  1738. if (!flag) {
  1739. newList[i].categoryArr.push(vv.categoryObj);
  1740. }
  1741. }
  1742. if (!newList[i].deptArr) {
  1743. newList[i].deptArr = [newList[i].deptObj];
  1744. } else {
  1745. let flag = newList[i].deptArr.some(
  1746. (vvv) => vvv.id == vv.deptObj.id
  1747. );
  1748. if (!flag) {
  1749. newList[i].deptArr.push(vv.deptObj);
  1750. }
  1751. }
  1752. if (vv.userOrGroupType == 2 && !newList[i].group) {
  1753. newList[i].groupObj = vv.groupObj;
  1754. }
  1755. if (vv.userOrGroupType == 1 && !newList[i].handleUser) {
  1756. newList[i].userObj = vv.userObj;
  1757. }
  1758. if (!newList[i].branch) {
  1759. newList[i].branchObj = vv.branchObj;
  1760. }
  1761. } else {
  1762. // 不存在
  1763. vv.deptArr = [vv.deptObj];
  1764. vv.categoryArr = [vv.categoryObj];
  1765. newList[i] = vv;
  1766. }
  1767. });
  1768. });
  1769. newList.forEach((v) => {
  1770. v.deptArrStr = v.deptArr.map((v) => v.dept).toString();
  1771. v.categoryArrStr = v.categoryArr
  1772. .map((v) => v.mutiCategory)
  1773. .toString();
  1774. });
  1775. console.log(newList);
  1776. // 处理后端返回的数据 end
  1777. $scope.gridOptions.totalItems = myData.totalNum;
  1778. $scope.myData = newList;
  1779. for (var i = 0; i < $scope.myData.length; i++) {
  1780. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  1781. }
  1782. $scope.ldloading[style.replace("-", "_")] = false;
  1783. },
  1784. function () {
  1785. $scope.ldloading[style.replace("-", "_")] = false;
  1786. }
  1787. );
  1788. };
  1789. // 搜索
  1790. $scope.searchData = function () {
  1791. $scope.refreshData("expand-right", $scope.fileData);
  1792. };
  1793. // 清空
  1794. $scope.clean = function () {
  1795. delete $scope.fileData.incidentAssignManager.content;
  1796. delete $scope.fileData.incidentAssignManager.category;
  1797. $scope.getCategoryData();
  1798. $scope.refreshData("expand-right", $scope.fileData);
  1799. };
  1800. // 获取故障现象下拉
  1801. $scope.model = {};
  1802. $scope.categoryData = [];
  1803. $scope.getCategoryData = function (s, fn) {
  1804. if (s) {
  1805. var filterKeyword = s.filterKeyword;
  1806. }
  1807. var postData = {
  1808. idx: 0,
  1809. sum: 1000,
  1810. };
  1811. if (filterKeyword) {
  1812. postData.incidentcategory = {
  1813. selectType: "pinyin_qs",
  1814. category: filterKeyword,
  1815. hierarchyQuery:'three'
  1816. };
  1817. }
  1818. $scope.my_data = [];
  1819. $scope.doing_async = true;
  1820. api_bpm_data
  1821. .fetchDataList("incidentcategory", postData)
  1822. .then(function (response) {
  1823. if (response.status == 200) {
  1824. var data = response.list;
  1825. if (filterKeyword) {
  1826. data.forEach((e) => {
  1827. e.isExpanded = true;
  1828. });
  1829. var li = transform(data).children;
  1830. console.log(li);
  1831. fn(li);
  1832. return;
  1833. } else {
  1834. var objects = [];
  1835. for (var i = 0; i < data.length; i++) {
  1836. var object = {};
  1837. object.id = data[i].id;
  1838. object.parent = data[i].parent;
  1839. object.category = data[i].category;
  1840. object.isExpanded = true;
  1841. objects.push(object);
  1842. }
  1843. $scope.my_data = convertParentToChildList(objects);
  1844. $scope.categoryData = angular.copy($scope.my_data);
  1845. }
  1846. if ($scope.my_data.length > 0) {
  1847. $scope.doing_async = false;
  1848. }
  1849. } else {
  1850. SweetAlert.swal({
  1851. title: "系统错误!",
  1852. text: "请刷新重试!",
  1853. type: "error",
  1854. });
  1855. }
  1856. });
  1857. };
  1858. $scope.getCategoryData();
  1859. $scope.refreshData("expand-right", $scope.fileData);
  1860. $scope.timer = $interval(function () {
  1861. $scope.refreshData2("expand-right", $scope.fileData);
  1862. }, $rootScope.refreshTime);
  1863. $scope.$on("$destroy", function () {
  1864. $interval.cancel($scope.timer);
  1865. });
  1866. },
  1867. ]);