inspectionScopeCtrl.js 42 KB

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