inspectionScopeCtrl.js 34 KB

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