inspectionScopeCtrl.js 40 KB

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