inspectionScopeCtrl.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. app.controller("inspectionScope", [
  2. "$rootScope",
  3. "$scope",
  4. "$state",
  5. "$timeout",
  6. "$interval",
  7. "SweetAlert",
  8. "$modal",
  9. "Restangular",
  10. "api_bpm_data",
  11. "api_solution",
  12. "api_user_data",
  13. "api_wechatfile",
  14. "api_sysinfo",
  15. "api_statistic",
  16. "api_bpm",
  17. "jry_api_bpm",
  18. "api_simple",
  19. function (
  20. $rootScope,
  21. $scope,
  22. $state,
  23. $timeout,
  24. $interval,
  25. SweetAlert,
  26. $modal,
  27. Restangular,
  28. api_bpm_data,
  29. api_solution,
  30. api_user_data,
  31. api_wechatfile,
  32. api_sysinfo,
  33. api_statistic,
  34. api_bpm,
  35. jry_api_bpm,
  36. api_simple
  37. ) {
  38. var loginUser = $rootScope.user;
  39. $scope.stateModel = JSON.parse($state.params.model);
  40. console.log($scope.stateModel);
  41. $scope.modelName = $scope.stateModel.modelName || $scope.stateModel.title;
  42. if ($scope.stateModel.model != 1) {
  43. $scope.stateModel.model = 0;
  44. }
  45. $scope.xinzeng = false;
  46. $scope.shanchu = false;
  47. $scope.bianji = false;
  48. for (var i = 0; i < loginUser.menu.length; i++) {
  49. if (loginUser.menu[i].link == "shijianshezhi_xinzeng") {
  50. $scope.xinzeng = true;
  51. }
  52. if (loginUser.menu[i].link == "shijianshezhi_shanchu") {
  53. $scope.shanchu = true;
  54. }
  55. if (loginUser.menu[i].link == "shijianshezhi_bianji") {
  56. $scope.bianji = true;
  57. }
  58. }
  59. $scope.listDataTop = [];
  60. $scope.listDataBottom = [];
  61. $scope.leftListIdx = -1;
  62. $scope.leftListName = "巡检范围";
  63. $scope.leftListCli = function (idx, data) {
  64. $scope.leftListIdx = idx;
  65. // $scope.stateModel = data;
  66. $scope.stateModel.currentId = data.id;
  67. $scope.modelName = data.modelName;
  68. $scope.copyInspection.tree = [];
  69. $scope.selectedInspection.isShowZtree = false;
  70. setTimeout(() => {
  71. $scope.selectedInspection.isShowZtree = true;
  72. }, 0);
  73. };
  74. // 全选
  75. // 把指令的方法绑定到控制器
  76. $scope.setDirectiveFn = function (fn) {
  77. $scope.selectAll = fn;
  78. }
  79. // 事件分类开始
  80. var loginUser = $rootScope.user;
  81. //组
  82. api_user_data
  83. .fetchDataList("group", { idx: 0, sum: 1000 })
  84. .then(function (data) {
  85. $scope.group = data.list;
  86. });
  87. api_wechatfile
  88. .getDictionary({ key: "incident_priority", type: "list" })
  89. .then(function (data) {
  90. $scope.priority = data;
  91. });
  92. /* ----- tree----- */
  93. var i = 0;
  94. $scope.out = [];
  95. $scope.outdata = [];
  96. $scope.subdata = {};
  97. $scope.sub1data = {};
  98. $scope.addcate = false;
  99. $scope.add1cate = false;
  100. $scope.changecate = false;
  101. $scope.filterTree = function (data, id) {
  102. data = angular.copy(data);
  103. var newTree = data.filter((x) => x.id !== id);
  104. newTree.forEach(
  105. (x) => x.children && (x.children = $scope.filterTree(x.children, id))
  106. );
  107. return newTree;
  108. };
  109. $scope.userOrGroupType = {}; //当前节点运维组/运维人员
  110. $scope.dataSave = []; //储存$scope.tree_data
  111. $scope.group_user = {
  112. // offlineGroup:{},//线下组
  113. // onlineUser:{}//线上人
  114. };
  115. $scope.selectedInspection = {
  116. tree: {},
  117. isShowZtree: true,
  118. };
  119. $scope.copyInspection = {
  120. tree: [],
  121. };
  122. $scope.timerZtree = null;
  123. $scope.timerZtreeCopy = null;
  124. // 新增
  125. $scope.addType1 = function (type) {
  126. console.log();
  127. // ===============================================
  128. var modalInstance = $modal.open({
  129. templateUrl: "assets/views/system/tpl/inspectionchange.html",
  130. controller: function ($scope, scope, $modalInstance) {
  131. $scope.add1data = {};
  132. $scope.thisParent = {}; //当前点击节点的父节点
  133. $scope.filterTree = function (data, id) {
  134. data = angular.copy(data);
  135. var newTree = data.filter((x) => x.id !== id);
  136. newTree.forEach(
  137. (x) =>
  138. x.children && (x.children = $scope.filterTree(x.children, id))
  139. );
  140. return newTree;
  141. };
  142. $scope.try_async_1load = function () {
  143. $scope.my_1data = [];
  144. var data = { idx: 0, sum: 1000, inspectionType: { deleteFlag: 0 } };
  145. api_bpm_data
  146. .fetchDataList("inspectionType", data)
  147. .then(function (response) {
  148. var data = response.list;
  149. data = data.filter((v) => !v.parent); //只显示一级
  150. var objects = [];
  151. for (var i = 0; i < data.length; i++) {
  152. var object = {};
  153. object.id = data[i].id;
  154. if (angular.isDefined(data[i].user)) {
  155. object.user = data[i].user || {};
  156. }
  157. if (angular.isDefined(data[i].group)) {
  158. object.group = data[i].group || {};
  159. }
  160. if (angular.isDefined(data[i].parent)) {
  161. object.parent = data[i].parent;
  162. }
  163. object.label = data[i].type;
  164. objects.push(object);
  165. }
  166. $scope.my_1data = convertParentToChildList(objects);
  167. $scope.tree_1data = angular.copy($scope.my_1data);
  168. // 把选中的巡检范围当作父类回显
  169. if (scope.selectedInspection.tree.id) {
  170. // 区分新增和修改
  171. if (type == "add") {
  172. $scope.thisParent = data.find(
  173. (v) => v.id == scope.selectedInspection.tree.id
  174. );
  175. if ($scope.thisParent) {
  176. $scope.thisParent.label = $scope.thisParent.type;
  177. $scope.thisParent.isExpanded = true;
  178. $scope.thisParent.selected = true;
  179. $scope.addparent = true;
  180. } else {
  181. $scope.addparent = false;
  182. }
  183. } else if (type == "edit") {
  184. // 编辑
  185. console.log($scope.my_1data, "原始数据");
  186. $scope.tree_1data = $scope.my_1data.filter(
  187. (v) => v.id != scope.selectedInspection.tree.id
  188. ); //过滤本条
  189. $scope.thisParent = data.find(
  190. (v) => v.id == scope.selectedInspection.tree.pId
  191. );
  192. if ($scope.thisParent) {
  193. $scope.thisParent.label = $scope.thisParent.type;
  194. $scope.thisParent.isExpanded = true;
  195. $scope.thisParent.selected = true;
  196. $scope.addparent = true;
  197. } else {
  198. $scope.addparent = false;
  199. }
  200. $scope.add1data.type = scope.selectedInspection.tree.name;
  201. $scope.add1data.id = scope.selectedInspection.tree.id;
  202. }
  203. } else {
  204. $scope.addparent = false;
  205. }
  206. });
  207. };
  208. $scope.try_async_1load();
  209. function convertListToTree(data, treeMap) {
  210. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  211. var root = null; //Initially set our loop to null
  212. //loop over data
  213. for (var i = 0; i < data.length; i++) {
  214. var datum = data[i];
  215. //each node will have children, so let's give it a "children" poperty
  216. datum.children = [];
  217. //add an entry for this node to the map so that any future children can
  218. //lookup the parent
  219. idToNodeMap[datum.id] = datum;
  220. //Does this node have a parent?
  221. // console.log("datum="+JSON.stringify(datum))
  222. if (typeof datum.parent === "undefined") {
  223. //Doesn't look like it, so this node is the root of the tree
  224. root = datum;
  225. treeMap[datum.id] = root;
  226. } else {
  227. //This node has a parent, so let's look it up using the id
  228. parentNode = idToNodeMap[datum.parent.id];
  229. //We don't need this property, so let's delete it.
  230. // delete datum.parent;
  231. //Let's add the current node as a child of the parent node.
  232. parentNode.children.push(datum);
  233. }
  234. }
  235. return root;
  236. }
  237. function convertParentToChildList(data) {
  238. var treeMap = {};
  239. var list = [];
  240. convertListToTree(data, treeMap);
  241. angular.forEach(treeMap, function (item) {
  242. list.push(item);
  243. });
  244. return list;
  245. }
  246. // ------------------------------------------------
  247. $scope.title = type == "add" ? "巡检范围新增" : "巡检范围修改";
  248. $scope.cancel = function () {
  249. $modalInstance.dismiss("cancel");
  250. };
  251. $scope.savercode = function (data) {
  252. if (data && data.type) {
  253. if ($scope.addparent) {
  254. data.parent = $scope.add1data.parent || $scope.thisParent;
  255. } else {
  256. data.parent = null;
  257. }
  258. scope.selectedInspection.tree = {};
  259. $modalInstance.close(data);
  260. } else {
  261. SweetAlert.swal(
  262. {
  263. title: "新增失败!",
  264. text: "请填写必填项!",
  265. type: "error",
  266. confirmButtonColor: "#DD6B55",
  267. },
  268. function () {}
  269. );
  270. }
  271. };
  272. },
  273. resolve: {
  274. scope: function () {
  275. return $scope;
  276. },
  277. },
  278. });
  279. // liaomingming
  280. modalInstance.result.then(function (selectedItem) {
  281. console.log($scope);
  282. if (selectedItem.type) {
  283. selectedItem.deleteFlag = 0;
  284. selectedItem.formUiName = "inspection_LinHu_detail";
  285. selectedItem.formUiEdit = "inspection_LinHu_confirm";
  286. selectedItem.processKey = "bpm_inspection";
  287. var filedata = { inspectionType: selectedItem };
  288. console.log(filedata);
  289. // return;
  290. api_bpm_data[type == "add" ? "addData" : "updData"](
  291. "inspectionType",
  292. filedata
  293. ).then(function (response) {
  294. if (response) {
  295. if (response.status == 200) {
  296. $scope.selectedInspection.isShowZtree = false;
  297. setTimeout(() => {
  298. $scope.selectedInspection.isShowZtree = true;
  299. }, 0);
  300. SweetAlert.swal({
  301. title: type == "add" ? "增加成功!" : "修改成功!",
  302. type: "success",
  303. });
  304. } else {
  305. SweetAlert.swal({
  306. title: type == "add" ? "增加失败!" : "修改失败!",
  307. type: "error",
  308. });
  309. }
  310. }
  311. });
  312. } else {
  313. SweetAlert.swal(
  314. {
  315. title: "新增失败!",
  316. text: "请填写必填项!",
  317. type: "error",
  318. confirmButtonColor: "#DD6B55",
  319. },
  320. function () {}
  321. );
  322. }
  323. });
  324. };
  325. /* -----start remove incidet category----- */
  326. // 删除
  327. $scope.remove1 = function () {
  328. var modalInstance = $modal.open({
  329. templateUrl: "assets/views/delete.html",
  330. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  331. $scope.title = "巡检范围删除?";
  332. $scope.connect = "确定要删除此巡检范围?";
  333. $scope.ok = function () {
  334. $modalInstance.close(scope.selectedInspection.tree);
  335. };
  336. $scope.cancel = function () {
  337. $modalInstance.dismiss("cancel");
  338. };
  339. },
  340. size: "sm",
  341. resolve: {
  342. scope: function () {
  343. return $scope;
  344. },
  345. },
  346. });
  347. modalInstance.result.then(function (selectedItem) {
  348. if (selectedItem) {
  349. var rmvList = [];
  350. rmvList.push(selectedItem.id);
  351. if (selectedItem.children && selectedItem.children.length > 0) {
  352. SweetAlert.swal({
  353. title: "删除失败!",
  354. text: "请先删除选中的范围的子级",
  355. type: "error",
  356. });
  357. } else {
  358. api_bpm_data
  359. .rmvData("inspectionType", rmvList)
  360. .then(function (response) {
  361. if (response.data) {
  362. SweetAlert.swal(
  363. {
  364. title: "删除成功!",
  365. type: "success",
  366. confirmButtonColor: "#007AFF",
  367. },
  368. function () {
  369. $scope.selectedInspection.isShowZtree = false;
  370. setTimeout(() => {
  371. $scope.selectedInspection.isShowZtree = true;
  372. }, 0);
  373. }
  374. );
  375. } else {
  376. SweetAlert.swal({
  377. title: "操作异常!",
  378. text: "系统异常,请稍后重试,或者联系管理员!",
  379. type: "error",
  380. });
  381. }
  382. });
  383. }
  384. }
  385. });
  386. };
  387. /* -----end remove incidet category----- */
  388. function convertListToTree(data, treeMap) {
  389. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  390. var root = null; //Initially set our loop to null
  391. //loop over data
  392. for (var i = 0; i < data.length; i++) {
  393. var datum = data[i];
  394. //each node will have children, so let's give it a "children" poperty
  395. datum.children = [];
  396. //add an entry for this node to the map so that any future children can
  397. //lookup the parent
  398. idToNodeMap[datum.id] = datum;
  399. //Does this node have a parent?
  400. // console.log("datum="+JSON.stringify(datum))
  401. if (typeof datum.parent === "undefined") {
  402. //Doesn't look like it, so this node is the root of the tree
  403. root = datum;
  404. treeMap[datum.id] = root;
  405. } else {
  406. //This node has a parent, so let's look it up using the id
  407. parentNode = idToNodeMap[datum.parent.id];
  408. //We don't need this property, so let's delete it.
  409. // delete datum.parent;
  410. //Let's add the current node as a child of the parent node.
  411. parentNode.children.push(datum);
  412. }
  413. }
  414. return root;
  415. }
  416. function convertParentToChildList(data) {
  417. var treeMap = {};
  418. var list = [];
  419. convertListToTree(data, treeMap);
  420. angular.forEach(treeMap, function (item) {
  421. list.push(item);
  422. });
  423. return list;
  424. }
  425. $scope.closethis = function (formdata) {
  426. formdata.category = "";
  427. formdata.parent.category = "";
  428. };
  429. /* -----start submit incidet category----- */
  430. // 保存设置
  431. $scope.selectedchangecategory = { value: {} };
  432. $scope.$watch("selectedchangecategory.value", function (newVal) {
  433. console.log(newVal);
  434. if (newVal.user) {
  435. $scope.group_user["onlineUser"] = newVal.user || undefined;
  436. } else {
  437. $scope.group_user["onlineUser"] = undefined;
  438. }
  439. if (newVal.group) {
  440. $scope.group_user["offlineGroup"] = newVal.group || undefined;
  441. } else {
  442. $scope.group_user["offlineGroup"] = undefined;
  443. }
  444. });
  445. $scope.editInspection = function (tree, id, newVal, type) {
  446. tree.forEach((v) => {
  447. if (v.id == id) {
  448. v[type] = newVal;
  449. } else if (v.children) {
  450. $scope.editInspection(v.children, id, newVal, type);
  451. }
  452. });
  453. };
  454. $scope.$watch("group_user.offlineGroup", function (newVal) {
  455. console.log($scope.selectedchangecategory.value);
  456. console.log($scope.copyInspection.tree);
  457. console.log(newVal, "group");
  458. $scope.editInspection(
  459. $scope.copyInspection.tree,
  460. $scope.selectedchangecategory.value.id,
  461. newVal,
  462. "group"
  463. );
  464. if (newVal && newVal.id) {
  465. $scope.selectedchangecategory.value.group = newVal;
  466. } else {
  467. delete $scope.selectedchangecategory.value.group;
  468. }
  469. });
  470. $scope.$watch("group_user.onlineUser", function (newVal) {
  471. // console.log($scope.selectedchangecategory.value)
  472. // console.log($scope.copyInspection.tree)
  473. // console.log(newVal, 'user')
  474. $scope.editInspection(
  475. $scope.copyInspection.tree,
  476. $scope.selectedchangecategory.value.id,
  477. newVal,
  478. "user"
  479. );
  480. if (newVal && newVal.id) {
  481. $scope.selectedchangecategory.value.user = newVal;
  482. } else {
  483. delete $scope.selectedchangecategory.value.user;
  484. }
  485. });
  486. // 保存设置 liaomingming
  487. $scope.submit1change = function () {
  488. console.log($scope.copyInspection.tree);
  489. console.log($scope.stateModel);
  490. if ($scope.stateModel.model === 0) {
  491. // 不设置为模块的时候需要弹窗提示
  492. var modalInstance = $modal.open({
  493. templateUrl: "assets/views/system/tpl/inspectionModel.html",
  494. controller: function ($scope, scope, $modalInstance) {
  495. $scope.add1data = { model: false };
  496. $scope.title = "提示";
  497. $scope.cancel = function () {
  498. $modalInstance.dismiss("cancel");
  499. };
  500. $scope.savercode = function (data) {
  501. console.log(scope.copyInspection.tree);
  502. scope.stateModel.model = data.model ? 1 : 0;
  503. scope.saveCommon(scope);
  504. $modalInstance.close(data);
  505. };
  506. },
  507. resolve: {
  508. scope: function () {
  509. return $scope;
  510. },
  511. },
  512. });
  513. modalInstance.result.then(function (selectedItem) {});
  514. return;
  515. }
  516. $scope.saveCommon($scope);
  517. };
  518. // 暂存
  519. $scope.submit1change_save = function (flag) {
  520. $rootScope.isMask = true;
  521. var arr = $scope.TreeToArr($scope.copyInspection.tree, []);
  522. $scope.stateModel.modelName = $scope.modelName;
  523. $scope.stateModel.typeIds = arr.map((v) => v.id).toString();
  524. arr = arr.map((v) => ({
  525. inspection: $scope.stateModel.id,
  526. inspectionType: v.id,
  527. inspectionTypeName: v.name,
  528. parent: v.parent,
  529. user: v.user?v.user.id:undefined,
  530. userName: v.user?v.user.name:undefined,
  531. group: v.group?v.group.id:undefined,
  532. groupName: v.group?v.group.groupName:undefined,
  533. }));
  534. // 一条都没选择
  535. if (arr.length === 0) {
  536. arr.push({ inspection: $scope.stateModel.id });
  537. }
  538. console.log(arr);
  539. // return;
  540. api_simple.addListData("inspectionBind", arr).then(function (response) {
  541. $rootScope.isMask = false;
  542. if (response) {
  543. if (response.status == 200) {
  544. SweetAlert.swal(
  545. {
  546. title: "暂存成功!",
  547. type: "success",
  548. },
  549. function () {
  550. if(flag){
  551. window.history.back();
  552. }else{
  553. $scope.selectedchangecategory.value = {};
  554. $scope.copyInspection.tree = [];
  555. $scope.changecateObj.changecate = false;
  556. $scope.selectedInspection.isShowZtree = false;
  557. setTimeout(()=>{
  558. $scope.selectedInspection.isShowZtree = true;
  559. },0)
  560. }
  561. }
  562. );
  563. } else {
  564. SweetAlert.swal({
  565. title: "保存失败!",
  566. type: "error",
  567. });
  568. }
  569. }
  570. });
  571. };
  572. // 上一步
  573. $scope.submit1change_prev = function(){
  574. SweetAlert.swal(
  575. {
  576. title: "您是否暂存当前设置!",
  577. type: "warning",
  578. showCancelButton: true,
  579. confirmButtonColor: "#DD6B55",
  580. confirmButtonText: "是",
  581. cancelButtonText: "否",
  582. },
  583. function (isConfirm) {
  584. if (isConfirm) {
  585. $scope.submit1change_save(true);
  586. }else{
  587. window.history.back();
  588. }
  589. }
  590. );
  591. }
  592. $scope.closeModel = function () {
  593. $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
  594. };
  595. $scope.TreeToArr = function (tree, arr) {
  596. tree.forEach((v) => {
  597. if (v.children) {
  598. arr.push(v);
  599. $scope.TreeToArr(v.children, arr);
  600. } else {
  601. arr.push(v);
  602. }
  603. });
  604. return arr;
  605. };
  606. $scope.saveCommon = function ($scope) {
  607. if (!$scope.modelName.trim()) {
  608. SweetAlert.swal({
  609. title: "策略名称不能为空!",
  610. type: "error",
  611. });
  612. return;
  613. }
  614. $rootScope.isMask = true;
  615. var arr = $scope.TreeToArr($scope.copyInspection.tree, []);
  616. $scope.stateModel.modelName = $scope.modelName;
  617. $scope.stateModel.typeIds = arr.map((v) => v.id).toString();
  618. arr = arr.map((v) => ({
  619. inspection: $scope.stateModel.id,
  620. inspectionType: v.id,
  621. inspectionTypeName: v.name,
  622. parent: v.parent,
  623. user: v.user?v.user.id:undefined,
  624. userName: v.user?v.user.name:undefined,
  625. group: v.group?v.group.id:undefined,
  626. groupName: v.group?v.group.groupName:undefined,
  627. }));
  628. // 一条都没选择
  629. if (arr.length === 0) {
  630. arr.push({ inspection: $scope.stateModel.id });
  631. }
  632. console.log(arr);
  633. // return;
  634. api_simple.addListData("inspectionBind", arr).then(function (response) {
  635. $rootScope.isMask = false;
  636. if (response) {
  637. if (response.status == 200) {
  638. $scope.stateModel.status = { id: 120 }; //强制扭转状态为正常
  639. var filedata = {
  640. close: "关闭",
  641. save: "暂存",
  642. submit: "下一步",
  643. inspection: $scope.stateModel,
  644. };
  645. api_bpm_data
  646. .addData("inspection", filedata)
  647. .then(function (response) {
  648. if (response) {
  649. if (response.status == 200) {
  650. SweetAlert.swal(
  651. {
  652. title: "保存成功!",
  653. type: "success",
  654. },
  655. function () {
  656. // $scope.selectedchangecategory.value = {};
  657. // $scope.copyInspection.tree = [];
  658. // $scope.changecateObj.changecate = false;
  659. // $scope.selectedInspection.isShowZtree = false;
  660. // setTimeout(()=>{
  661. // $scope.selectedInspection.isShowZtree = true;
  662. // },0)
  663. $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
  664. }
  665. );
  666. } else {
  667. SweetAlert.swal({
  668. title: "保存失败!",
  669. type: "error",
  670. });
  671. }
  672. }
  673. });
  674. } else {
  675. SweetAlert.swal({
  676. title: "保存失败!",
  677. type: "error",
  678. });
  679. }
  680. }
  681. });
  682. };
  683. $scope.add1data = {};
  684. $scope.addparent = false;
  685. // 事件分类结束
  686. // 获取组数据
  687. $scope.getGroupList = function () {
  688. var postData = {
  689. idx: 0,
  690. sum: 1000,
  691. group: { selectType: "nouser" },
  692. };
  693. api_user_data.fetchDataList("group", postData).then((res) => {
  694. $scope.groupList = res.list;
  695. });
  696. };
  697. $scope.getGroupList();
  698. // 获取巡检计划数据
  699. $scope.getGroupList = function (model) {
  700. var postData = {
  701. idx: 0,
  702. sum: 3,
  703. inspection: { model: model },
  704. };
  705. api_user_data.fetchDataList("inspection", postData).then((res) => {
  706. if (model == 1) {
  707. $scope.listDataTop = res.list; //巡检范围策略模板
  708. } else {
  709. $scope.listDataBottom = res.list; //往期巡检范围策略
  710. }
  711. });
  712. };
  713. $scope.getGroupList(1);
  714. $scope.getGroupList();
  715. // 获取人数据
  716. $scope.getUserList = function () {
  717. var postData = {
  718. idx: 0,
  719. sum: 1000,
  720. user: {
  721. name: "",
  722. selectType: "pinyin_qs",
  723. },
  724. };
  725. api_user_data.fetchDataList("user", postData).then((res) => {
  726. $scope.userList = res.list;
  727. });
  728. };
  729. $scope.getUserList();
  730. $scope.changecateObj = {
  731. changecate: false,
  732. };
  733. // 缓存的绑定数据-http
  734. $scope.cacheHttp = {
  735. value: [],
  736. };
  737. },
  738. ]);
  739. app.directive("zTree", function () {
  740. // ztree liaomingming
  741. return {
  742. restrict: "EA",
  743. scope: {
  744. selectInspectionType: "=",
  745. copyInspectionType: "=",
  746. stateModel: "=",
  747. changecate: "=",
  748. cachehttp: "=",
  749. setFn: '&'
  750. },
  751. controller: function ($rootScope,$scope, $element, api_bpm_data, api_simple) {
  752. console.log($scope);
  753. getTreeInfo();
  754. function getTreeInfo() {
  755. $rootScope.isMask = true;
  756. $scope.treeInfo = [];
  757. var data = { idx: 0, sum: 1000, inspectionType: { deleteFlag: 0 } };
  758. $scope.isShowZtree = false;
  759. api_bpm_data
  760. .fetchDataList("inspectionType", data)
  761. .then(function (response) {
  762. var data = response.list;
  763. console.log(data);
  764. var objects = [];
  765. for (var i = 0; i < data.length; i++) {
  766. var object = {};
  767. object.id = data[i].id;
  768. if (angular.isDefined(data[i].user)) {
  769. object.user = data[i].user || {};
  770. }
  771. if (angular.isDefined(data[i].group)) {
  772. object.group = data[i].group || {};
  773. }
  774. if (angular.isDefined(data[i].parent)) {
  775. object.parent = data[i].parent;
  776. object.pId = data[i].parent.id;
  777. } else {
  778. object.pId = 0;
  779. }
  780. object.name = data[i].type;
  781. objects.push(object);
  782. }
  783. $scope.treeInfo = convertParentToChildList(objects);
  784. $scope.treeInfo = deleteEmputyChildren($scope.treeInfo);
  785. console.log($scope.treeInfo);
  786. // ==================start================
  787. api_simple
  788. .fetchDataList("inspectionBind", {
  789. idx: 0,
  790. sum: 1000,
  791. inspectionBind: { inspection: $scope.stateModel.currentId || $scope.stateModel.id },
  792. })
  793. .then(function (response) {
  794. $rootScope.isMask = false;
  795. $.fn.zTree.destroy("z-tree");
  796. $.fn.zTree.init($($element), setting, $scope.treeInfo);
  797. $scope.isShowZtree = true;
  798. var result = response.list || [];
  799. $scope.cachehttp = angular.copy(result);
  800. result = result.map((v) => v.inspectionType);
  801. console.log(result);
  802. var zTree = $.fn.zTree.getZTreeObj("z-tree");
  803. var nodesAll = zTree.transformToArray(zTree.getNodes());//全部节点转换成数组array
  804. $('#c_all').prop('checked', nodesAll.length === result.length);
  805. result.forEach((v) => {
  806. // 设置路径树节点选中
  807. // 1、根据id获取树的某个节点:
  808. var node = zTree.getNodeByParam("id", v);
  809. // 2、设置node节点选中状态:
  810. // zTree.selectNode(node);
  811. // 3、设置node节点checked选中:
  812. node.checked = true;
  813. //注:设置checked属性之后,一定要更新该节点
  814. zTree.updateNode(node);
  815. // console.log($scope.copyInspectionType)
  816. // zTree.expandNode(node);
  817. // setTimeout(() => {
  818. // zTreeOnCheck(null, null, node);
  819. // }, 0);
  820. });
  821. // zTree.expandAll(false);
  822. //展示选中的数据
  823. var arr = [];
  824. $scope.cachehttp.forEach(v=>{
  825. arr.push({
  826. id: v.inspectionType,
  827. name: v.inspectionTypeName,
  828. group: v.group?{id:v.group,groupName:v.groupName}:undefined,
  829. user: v.user?{id:v.user,name:v.userName}:undefined,
  830. parent: v.parent ? { id: v.parent.inspectionType } : undefined,
  831. pId: v.parent ? v.parent.inspectionType : 0,
  832. });
  833. })
  834. $scope.copyInspectionType = tranListToTreeData(arr);
  835. });
  836. // ==================end================
  837. });
  838. }
  839. function deleteEmputyChildren(data) {
  840. data.forEach((v) => {
  841. if (v.children.length) {
  842. deleteEmputyChildren(v.children);
  843. } else {
  844. delete v.children;
  845. }
  846. });
  847. return data;
  848. }
  849. function convertParentToChildList(data) {
  850. var treeMap = {};
  851. var list = [];
  852. convertListToTree(data, treeMap);
  853. angular.forEach(treeMap, function (item) {
  854. list.push(item);
  855. });
  856. return list;
  857. }
  858. function convertListToTree(data, treeMap) {
  859. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  860. var root = null; //Initially set our loop to null
  861. //loop over data
  862. for (var i = 0; i < data.length; i++) {
  863. var datum = data[i];
  864. //each node will have children, so let's give it a "children" poperty
  865. datum.children = [];
  866. //add an entry for this node to the map so that any future children can
  867. //lookup the parent
  868. idToNodeMap[datum.id] = datum;
  869. //Does this node have a parent?
  870. // console.log("datum="+JSON.stringify(datum))
  871. // if (typeof datum.parent === "undefined") {
  872. if (datum.pId === 0) {
  873. //Doesn't look like it, so this node is the root of the tree
  874. root = datum;
  875. treeMap[datum.id] = root;
  876. } else {
  877. //This node has a parent, so let's look it up using the id
  878. // parentNode = idToNodeMap[datum.parent.id];
  879. parentNode = idToNodeMap[datum.pId];
  880. //We don't need this property, so let's delete it.
  881. // delete datum.parent;
  882. //Let's add the current node as a child of the parent node.
  883. parentNode.children.push(datum);
  884. }
  885. }
  886. return root;
  887. }
  888. var setting = {
  889. check: {
  890. enable: true,
  891. chkStyle: "checkbox",
  892. chkboxType: { Y: "ps", N: "ps" },
  893. },
  894. callback: {
  895. onClick: onMouseDown,
  896. onCheck: zTreeOnCheck,
  897. },
  898. view: {
  899. showIcon: false,
  900. showLine: false,
  901. },
  902. };
  903. // $.fn.zTree.init($($element), setting, $scope.treeInfo);
  904. //点击菜单项
  905. function onMouseDown(event, treeId, treeNode) {
  906. console.log(event, treeId, treeNode);
  907. $scope.selectInspectionType = treeNode;
  908. }
  909. // 点击复选框
  910. function zTreeOnCheck(event, treeId, treeNode) {
  911. console.log(event, treeId, treeNode);
  912. $scope.changecate = false;
  913. var treeObj = $.fn.zTree.getZTreeObj("z-tree");
  914. var nodesAll = treeObj.transformToArray(treeObj.getNodes());//全部节点转换成数组array
  915. var nodes_arr = treeObj.getCheckedNodes(true);
  916. var nodes = angular.copy(nodes_arr);
  917. $('#c_all').prop('checked', nodesAll.length === nodes_arr.length);
  918. console.log(nodes);
  919. if ($scope.cachehttp && $scope.cachehttp.length) {
  920. var result = angular.copy($scope.cachehttp);
  921. zTreeOnCheckCommon(result, nodes);
  922. } else {
  923. api_simple
  924. .fetchDataList("inspectionBind", {
  925. idx: 0,
  926. sum: 1000,
  927. inspectionBind: { inspection: $scope.stateModel.id },
  928. })
  929. .then(function (response) {
  930. var result = response.list || [];
  931. zTreeOnCheckCommon(result, nodes);
  932. });
  933. }
  934. }
  935. function tranListToTreeData(nodes){
  936. var arr = nodes.filter((v) => v.pId === 0);
  937. arr.forEach((v) => {
  938. v.children = [];
  939. });
  940. arr.forEach((v, i) => {
  941. nodes.forEach((vv) => {
  942. if (vv.pId == v.id) {
  943. arr[i].children.push(vv);
  944. }
  945. });
  946. });
  947. return arr;
  948. }
  949. $scope.clickDirective = function () {
  950. console.log('全选');
  951. var zTree = $.fn.zTree.getZTreeObj("z-tree");//得到tree对象 treeMenu是我的treeid
  952. var node = zTree.getNodes();//得到全部节点
  953. var nodes = zTree.transformToArray(node);//全部节点转换成数组array
  954. var checkNode = zTree.getCheckedNodes().length;//得到被选中的节点数量,zTree.getCheckedNodes()和zTree.getCheckedNodes(true)一样,可以传参(true/false),默认是true
  955. if (checkNode < nodes.length) {//已选中的节点数小于总数 - 全选
  956. zTree.checkAllNodes(true);//给全部节点设置为true
  957. zTreeOnCheckCommon([], nodes)
  958. } else{
  959. zTree.checkAllNodes(false);//给全部节点设置为false
  960. zTreeOnCheckCommon([], [])
  961. }
  962. }
  963. $scope.setFn.call($scope, {
  964. params: $scope.clickDirective
  965. })
  966. // 点击复选框-common
  967. function zTreeOnCheckCommon(result, nodes) {
  968. // 如果有值,则不覆盖
  969. if($scope.copyInspectionType.length){
  970. result = [];
  971. $scope.copyInspectionType.forEach(v=>{
  972. result.push(v);
  973. if(v.children && v.children.length){
  974. v.children.forEach(vv=>{
  975. result.push(vv);
  976. })
  977. }
  978. })
  979. }else{
  980. result = result.map((v) => ({
  981. id: v.inspectionType,
  982. name: v.inspectionTypeName,
  983. group: v.group?{id:v.group,groupName:v.groupName}:undefined,
  984. user: v.user?{id:v.user,name:v.userName}:undefined,
  985. parent: v.parent ? { id: v.parent.inspectionType } : undefined,
  986. pId: v.parent ? v.parent.inspectionType : 0,
  987. }));
  988. }
  989. for (var i = 0; i < nodes.length; i++) {
  990. for (var j = 0; j < result.length; j++) {
  991. if (nodes[i].id == result[j].id) {
  992. nodes[i] = angular.copy(result[j]);
  993. }
  994. }
  995. }
  996. $scope.copyInspectionType = tranListToTreeData(nodes);
  997. }
  998. },
  999. };
  1000. });
  1001. app.directive("zTreeCopy", function () {
  1002. // ztree liaomingming
  1003. return {
  1004. restrict: "EA",
  1005. scope: {
  1006. copyInspectionType: "=",
  1007. changecate: "=",
  1008. selectedchangecategory: "=",
  1009. },
  1010. link: function (scope, element, attrs) {
  1011. scope.$watch("copyInspectionType", function (newVal) {
  1012. console.log(newVal);
  1013. var setting = {
  1014. view: {
  1015. showIcon: false,
  1016. showLine: false,
  1017. },
  1018. callback: {
  1019. onClick: onMouseDown,
  1020. },
  1021. };
  1022. $.fn.zTree.destroy("z-tree-copy");
  1023. $.fn.zTree.init($(element), setting, newVal);
  1024. // var treeObj = $.fn.zTree.init($(element), setting, newVal);
  1025. // treeObj.expandAll(true);
  1026. });
  1027. //点击菜单项
  1028. function onMouseDown(event, treeId, treeNode) {
  1029. console.log(event, treeId, treeNode);
  1030. scope.selectedchangecategory = treeNode;
  1031. scope.changecate = true;
  1032. console.log(scope.copyInspectionType);
  1033. }
  1034. },
  1035. controller: function ($scope, $element, api_bpm_data) {},
  1036. };
  1037. });