inspectionScopeCtrl.js 43 KB

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