inspectionScopeCtrl.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. }
  582. }
  583. );
  584. }
  585. $scope.closeModel = function () {
  586. $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
  587. };
  588. $scope.TreeToArr = function (tree, arr) {
  589. tree.forEach((v) => {
  590. if (v.children) {
  591. arr.push(v);
  592. $scope.TreeToArr(v.children, arr);
  593. } else {
  594. arr.push(v);
  595. }
  596. });
  597. return arr;
  598. };
  599. $scope.saveCommon = function ($scope) {
  600. if (!$scope.modelName.trim()) {
  601. SweetAlert.swal({
  602. title: "策略名称不能为空!",
  603. type: "error",
  604. });
  605. return;
  606. }
  607. $rootScope.isMask = true;
  608. var arr = $scope.TreeToArr($scope.copyInspection.tree, []);
  609. $scope.stateModel.modelName = $scope.modelName;
  610. $scope.stateModel.typeIds = arr.map((v) => v.id).toString();
  611. arr = arr.map((v) => ({
  612. inspection: $scope.stateModel.id,
  613. inspectionType: v.id,
  614. inspectionTypeName: v.name,
  615. parent: v.parent,
  616. user: v.user?v.user.id:undefined,
  617. userName: v.user?v.user.name:undefined,
  618. group: v.group?v.group.id:undefined,
  619. groupName: v.group?v.group.groupName:undefined,
  620. }));
  621. // 一条都没选择
  622. if (arr.length === 0) {
  623. arr.push({ inspection: $scope.stateModel.id });
  624. }
  625. console.log(arr);
  626. // return;
  627. api_simple.addListData("inspectionBind", arr).then(function (response) {
  628. $rootScope.isMask = false;
  629. if (response) {
  630. if (response.status == 200) {
  631. $scope.stateModel.status = { id: 120 }; //强制扭转状态为正常
  632. var filedata = {
  633. close: "关闭",
  634. save: "暂存",
  635. submit: "下一步",
  636. inspection: $scope.stateModel,
  637. };
  638. api_bpm_data
  639. .addData("inspection", filedata)
  640. .then(function (response) {
  641. if (response) {
  642. if (response.status == 200) {
  643. SweetAlert.swal(
  644. {
  645. title: "保存成功!",
  646. type: "success",
  647. },
  648. function () {
  649. // $scope.selectedchangecategory.value = {};
  650. // $scope.copyInspection.tree = [];
  651. // $scope.changecateObj.changecate = false;
  652. // $scope.selectedInspection.isShowZtree = false;
  653. // setTimeout(()=>{
  654. // $scope.selectedInspection.isShowZtree = true;
  655. // },0)
  656. $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
  657. }
  658. );
  659. } else {
  660. SweetAlert.swal({
  661. title: "保存失败!",
  662. type: "error",
  663. });
  664. }
  665. }
  666. });
  667. } else {
  668. SweetAlert.swal({
  669. title: "保存失败!",
  670. type: "error",
  671. });
  672. }
  673. }
  674. });
  675. };
  676. $scope.add1data = {};
  677. $scope.addparent = false;
  678. // 事件分类结束
  679. // 获取组数据
  680. $scope.getGroupList = function () {
  681. var postData = {
  682. idx: 0,
  683. sum: 1000,
  684. group: { selectType: "nouser" },
  685. };
  686. api_user_data.fetchDataList("group", postData).then((res) => {
  687. $scope.groupList = res.list;
  688. });
  689. };
  690. $scope.getGroupList();
  691. // 获取巡检计划数据
  692. $scope.getGroupList = function (model) {
  693. var postData = {
  694. idx: 0,
  695. sum: 3,
  696. inspection: { model: model },
  697. };
  698. api_user_data.fetchDataList("inspection", postData).then((res) => {
  699. if (model == 1) {
  700. $scope.listDataTop = res.list; //巡检范围策略模板
  701. } else {
  702. $scope.listDataBottom = res.list; //往期巡检范围策略
  703. }
  704. });
  705. };
  706. $scope.getGroupList(1);
  707. $scope.getGroupList();
  708. // 获取人数据
  709. $scope.getUserList = function () {
  710. var postData = {
  711. idx: 0,
  712. sum: 1000,
  713. user: {
  714. name: "",
  715. selectType: "pinyin_qs",
  716. },
  717. };
  718. api_user_data.fetchDataList("user", postData).then((res) => {
  719. $scope.userList = res.list;
  720. });
  721. };
  722. $scope.getUserList();
  723. $scope.changecateObj = {
  724. changecate: false,
  725. };
  726. // 缓存的绑定数据-http
  727. $scope.cacheHttp = {
  728. value: [],
  729. };
  730. },
  731. ]);
  732. app.directive("zTree", function () {
  733. // ztree liaomingming
  734. return {
  735. restrict: "EA",
  736. scope: {
  737. selectInspectionType: "=",
  738. copyInspectionType: "=",
  739. stateModel: "=",
  740. changecate: "=",
  741. cachehttp: "=",
  742. },
  743. controller: function ($rootScope,$scope, $element, api_bpm_data, api_simple) {
  744. console.log($scope);
  745. getTreeInfo();
  746. function getTreeInfo() {
  747. $rootScope.isMask = true;
  748. $scope.treeInfo = [];
  749. var data = { idx: 0, sum: 1000, inspectionType: { deleteFlag: 0 } };
  750. $scope.isShowZtree = false;
  751. api_bpm_data
  752. .fetchDataList("inspectionType", data)
  753. .then(function (response) {
  754. var data = response.list;
  755. console.log(data);
  756. var objects = [];
  757. for (var i = 0; i < data.length; i++) {
  758. var object = {};
  759. object.id = data[i].id;
  760. if (angular.isDefined(data[i].user)) {
  761. object.user = data[i].user || {};
  762. }
  763. if (angular.isDefined(data[i].group)) {
  764. object.group = data[i].group || {};
  765. }
  766. if (angular.isDefined(data[i].parent)) {
  767. object.parent = data[i].parent;
  768. object.pId = data[i].parent.id;
  769. } else {
  770. object.pId = 0;
  771. }
  772. object.name = data[i].type;
  773. objects.push(object);
  774. }
  775. $scope.treeInfo = convertParentToChildList(objects);
  776. $scope.treeInfo = deleteEmputyChildren($scope.treeInfo);
  777. console.log($scope.treeInfo);
  778. // ==================start================
  779. api_simple
  780. .fetchDataList("inspectionBind", {
  781. idx: 0,
  782. sum: 1000,
  783. inspectionBind: { inspection: $scope.stateModel.currentId || $scope.stateModel.id },
  784. })
  785. .then(function (response) {
  786. $rootScope.isMask = false;
  787. $.fn.zTree.destroy("z-tree");
  788. $.fn.zTree.init($($element), setting, $scope.treeInfo);
  789. $scope.isShowZtree = true;
  790. var result = response.list || [];
  791. $scope.cachehttp = angular.copy(result);
  792. result = result.map((v) => v.inspectionType);
  793. console.log(result);
  794. result.forEach((v, i) => {
  795. // 设置路径树节点选中
  796. // 1、根据id获取树的某个节点:
  797. var zTree = $.fn.zTree.getZTreeObj("z-tree");
  798. var node = zTree.getNodeByParam("id", v);
  799. // 2、设置node节点选中状态:
  800. zTree.selectNode(node);
  801. // 3、设置node节点checked选中:
  802. node.checked = true;
  803. //注:设置checked属性之后,一定要更新该节点
  804. zTree.updateNode(node);
  805. console.log($scope.copyInspectionType)
  806. // 展开
  807. // zTree.expandNode(node);
  808. // setTimeout(() => {
  809. // zTreeOnCheck(null, null, node);
  810. // }, 0);
  811. });
  812. //展示选中的数据
  813. var arr = [];
  814. $scope.cachehttp.forEach(v=>{
  815. arr.push({
  816. id: v.inspectionType,
  817. name: v.inspectionTypeName,
  818. group: v.group?{id:v.group,groupName:v.groupName}:undefined,
  819. user: v.user?{id:v.user,name:v.userName}:undefined,
  820. parent: v.parent ? { id: v.parent.inspectionType } : undefined,
  821. pId: v.parent ? v.parent.inspectionType : 0,
  822. });
  823. })
  824. $scope.copyInspectionType = tranListToTreeData(arr);
  825. });
  826. // ==================end================
  827. });
  828. }
  829. function deleteEmputyChildren(data) {
  830. data.forEach((v) => {
  831. if (v.children.length) {
  832. deleteEmputyChildren(v.children);
  833. } else {
  834. delete v.children;
  835. }
  836. });
  837. return data;
  838. }
  839. function convertParentToChildList(data) {
  840. var treeMap = {};
  841. var list = [];
  842. convertListToTree(data, treeMap);
  843. angular.forEach(treeMap, function (item) {
  844. list.push(item);
  845. });
  846. return list;
  847. }
  848. function convertListToTree(data, treeMap) {
  849. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  850. var root = null; //Initially set our loop to null
  851. //loop over data
  852. for (var i = 0; i < data.length; i++) {
  853. var datum = data[i];
  854. //each node will have children, so let's give it a "children" poperty
  855. datum.children = [];
  856. //add an entry for this node to the map so that any future children can
  857. //lookup the parent
  858. idToNodeMap[datum.id] = datum;
  859. //Does this node have a parent?
  860. // console.log("datum="+JSON.stringify(datum))
  861. // if (typeof datum.parent === "undefined") {
  862. if (datum.pId === 0) {
  863. //Doesn't look like it, so this node is the root of the tree
  864. root = datum;
  865. treeMap[datum.id] = root;
  866. } else {
  867. //This node has a parent, so let's look it up using the id
  868. // parentNode = idToNodeMap[datum.parent.id];
  869. parentNode = idToNodeMap[datum.pId];
  870. //We don't need this property, so let's delete it.
  871. // delete datum.parent;
  872. //Let's add the current node as a child of the parent node.
  873. parentNode.children.push(datum);
  874. }
  875. }
  876. return root;
  877. }
  878. var setting = {
  879. check: {
  880. enable: true,
  881. chkStyle: "checkbox",
  882. chkboxType: { Y: "ps", N: "ps" },
  883. },
  884. callback: {
  885. onClick: onMouseDown,
  886. onCheck: zTreeOnCheck,
  887. },
  888. view: {
  889. showIcon: false,
  890. showLine: false,
  891. },
  892. };
  893. // $.fn.zTree.init($($element), setting, $scope.treeInfo);
  894. //点击菜单项
  895. function onMouseDown(event, treeId, treeNode) {
  896. console.log(event, treeId, treeNode);
  897. $scope.selectInspectionType = treeNode;
  898. }
  899. // 点击复选框
  900. function zTreeOnCheck(event, treeId, treeNode) {
  901. console.log(event, treeId, treeNode);
  902. $scope.changecate = false;
  903. var treeObj = $.fn.zTree.getZTreeObj("z-tree");
  904. var nodes_arr = treeObj.getCheckedNodes(true);
  905. var nodes = angular.copy(nodes_arr);
  906. console.log(nodes);
  907. if ($scope.cachehttp && $scope.cachehttp.length) {
  908. var result = angular.copy($scope.cachehttp);
  909. zTreeOnCheckCommon(result, nodes);
  910. } else {
  911. api_simple
  912. .fetchDataList("inspectionBind", {
  913. idx: 0,
  914. sum: 1000,
  915. inspectionBind: { inspection: $scope.stateModel.id },
  916. })
  917. .then(function (response) {
  918. var result = response.list || [];
  919. zTreeOnCheckCommon(result, nodes);
  920. });
  921. }
  922. }
  923. function tranListToTreeData(nodes){
  924. var arr = nodes.filter((v) => v.pId === 0);
  925. arr.forEach((v) => {
  926. v.children = [];
  927. });
  928. arr.forEach((v, i) => {
  929. nodes.forEach((vv) => {
  930. if (vv.pId == v.id) {
  931. arr[i].children.push(vv);
  932. }
  933. });
  934. });
  935. return arr;
  936. }
  937. // 点击复选框-common
  938. function zTreeOnCheckCommon(result, nodes) {
  939. // 如果有值,则不覆盖
  940. if($scope.copyInspectionType.length){
  941. result = [];
  942. $scope.copyInspectionType.forEach(v=>{
  943. result.push(v);
  944. if(v.children && v.children.length){
  945. v.children.forEach(vv=>{
  946. result.push(vv);
  947. })
  948. }
  949. })
  950. }else{
  951. result = result.map((v) => ({
  952. id: v.inspectionType,
  953. name: v.inspectionTypeName,
  954. group: v.group?{id:v.group,groupName:v.groupName}:undefined,
  955. user: v.user?{id:v.user,name:v.userName}:undefined,
  956. parent: v.parent ? { id: v.parent.inspectionType } : undefined,
  957. pId: v.parent ? v.parent.inspectionType : 0,
  958. }));
  959. }
  960. for (var i = 0; i < nodes.length; i++) {
  961. for (var j = 0; j < result.length; j++) {
  962. if (nodes[i].id == result[j].id) {
  963. nodes[i] = angular.copy(result[j]);
  964. }
  965. }
  966. }
  967. $scope.copyInspectionType = tranListToTreeData(nodes);
  968. }
  969. },
  970. };
  971. });
  972. app.directive("zTreeCopy", function () {
  973. // ztree liaomingming
  974. return {
  975. restrict: "EA",
  976. scope: {
  977. copyInspectionType: "=",
  978. changecate: "=",
  979. selectedchangecategory: "=",
  980. },
  981. link: function (scope, element, attrs) {
  982. scope.$watch("copyInspectionType", function (newVal) {
  983. console.log(newVal);
  984. var setting = {
  985. view: {
  986. showIcon: false,
  987. showLine: false,
  988. },
  989. callback: {
  990. onClick: onMouseDown,
  991. },
  992. };
  993. $.fn.zTree.destroy("z-tree-copy");
  994. $.fn.zTree.init($(element), setting, newVal);
  995. // var treeObj = $.fn.zTree.init($(element), setting, newVal);
  996. // treeObj.expandAll(true);
  997. });
  998. //点击菜单项
  999. function onMouseDown(event, treeId, treeNode) {
  1000. console.log(event, treeId, treeNode);
  1001. scope.selectedchangecategory = treeNode;
  1002. scope.changecate = true;
  1003. console.log(scope.copyInspectionType);
  1004. }
  1005. },
  1006. controller: function ($scope, $element, api_bpm_data) {},
  1007. };
  1008. });