jry_incidentSetCt.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('jry_incidentSetCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_bpm_data", "api_solution", "api_user_data","jry_api_bpm","api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_bpm_data, api_solution, api_user_data,jry_api_bpm,api_wechatfile) {
  6. $scope.ceshi="哈哈";
  7. $scope.addShow=false;
  8. $scope.editShow=false;
  9. $scope.editData="";
  10. $scope.editToweightData={};
  11. $scope.editToYXData={};
  12. $scope.editDscrip="";
  13. $scope.addNewDescribeOpen=function(){
  14. // console.log('ok')
  15. if($scope.treeId==""){
  16. SweetAlert.swal({
  17. title: "新增失败",
  18. text: "请先选择属性图一类!",
  19. type: "error"
  20. });
  21. }else{
  22. $scope.addShow=true;
  23. $(".addBox").animate({"top":"50%"},800,"linear")
  24. }
  25. }
  26. $scope.addNewDescribeClose=function(){
  27. $scope.addShow=false;
  28. $(".addBox").css({"top":"-169px"});
  29. $scope.addDscrip="";
  30. $scope.toweightData={};
  31. $scope.toYXData={};
  32. }
  33. //获取优先级
  34. $scope.getYXData=function(){
  35. jry_api_bpm.jry_getFetchDataList({"idx":0,"sum":1000},"priority").then(function(res){
  36. $scope.YXData=res.list
  37. // console.log(res)
  38. })
  39. }
  40. //获取权重
  41. $scope.getWeightData=function(){
  42. api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
  43. $scope.weightData=res
  44. // console.log(res)
  45. })
  46. }
  47. $scope.addDscrip="";
  48. // 新增提交
  49. $scope.addSave=function(){
  50. if($scope.addDscrip==""||$scope.toweightData.weightData==undefined||$scope.toYXData.YXData==undefined){
  51. SweetAlert.swal({
  52. title: "新增失败!",
  53. text: "必填项不能为空!",
  54. type: "error"
  55. });
  56. }else{
  57. var filedata={
  58. "incidentdescribe":{
  59. "describes":$scope.addDscrip,
  60. "weight":{id:$scope.toweightData.weightData.id},
  61. "categoryid":{id:$scope.treeId},
  62. "priority":{id:$scope.toYXData.YXData.id}
  63. }
  64. }
  65. jry_api_bpm.jry_addFn(filedata,"incidentdescribe").then(function(res1){
  66. // console.log(res1);
  67. if(res1.status==200){
  68. $scope.addShow=false;
  69. $scope.addDscrip="";
  70. $scope.toweightData={};
  71. $scope.toYXData={};
  72. $(".addBox").css({"top":"-169px"});
  73. jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){
  74. $scope.jry_scricData=res.list;
  75. })
  76. SweetAlert.swal({
  77. title: "修改成功!",
  78. confirmButtonColor: "#007AFF",
  79. type: "success"
  80. });
  81. }else{
  82. SweetAlert.swal({
  83. title: "新增失败!",
  84. text: "请重新再试!",
  85. type: "error"
  86. });
  87. }
  88. })
  89. }
  90. }
  91. // 编辑弹框显示
  92. $scope.jry_editShow=function(res){
  93. $scope.editData=$scope.jry_scricData[res];
  94. $scope.editDscrip=$scope.editData.describes;
  95. $scope.editToweightData.weightData=$scope.editData.weight;
  96. $scope.editToYXData.YXData=$scope.editData.priority;
  97. $scope.editId=$scope.editData.id;
  98. $scope.version=$scope.editData.version;
  99. $scope.editShow=true;
  100. $(".editBox").animate({"top":"50%"},800,"linear")
  101. }
  102. // 关闭编辑框
  103. $scope.editDescribeClose=function(){
  104. $scope.editShow=false;
  105. $(".editBox").css({"top":"-169px"})
  106. }
  107. // 删除
  108. $scope.jry_move=function(res){
  109. var moveId=[];
  110. moveId.push($scope.jry_scricData[res].id);
  111. // console.log($scope.moveId)
  112. SweetAlert.swal({
  113. title: "确认删除?",
  114. text: "删除的数据不可恢复,请确认继续操作!",
  115. type: "warning",
  116. showCancelButton: true,
  117. confirmButtonColor: "#DD6B55",
  118. confirmButtonText: "继续删除",
  119. cancelButtonText: "取消操作",
  120. closeOnConfirm: false,
  121. closeOnCancel: false
  122. }, function (isConfirm) {
  123. if (isConfirm) {
  124. jry_api_bpm.jry_movFn(moveId,"incidentdescribe").then(function (response) {
  125. if (response.status == 200) {
  126. jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){
  127. $scope.jry_scricData=res.list;
  128. })
  129. SweetAlert.swal("操作成功!", "数据已经被删除.", "success");
  130. } else {
  131. SweetAlert.swal("操作失败!", "数据暂时无法被删除,请稍候重试", "error");
  132. }
  133. });
  134. } else {
  135. SweetAlert.swal("操作取消", "数据安全", "error");
  136. }
  137. });
  138. }
  139. // 编辑确认
  140. $scope.editSave=function(){
  141. if($scope.editDscrip==""){
  142. SweetAlert.swal({
  143. title: "修改失败!",
  144. text: "必填项不能为空!",
  145. type: "error"
  146. });
  147. }else{
  148. var filedata={
  149. "incidentdescribe":{
  150. "describes":$scope.editDscrip,
  151. "weight":{id:$scope.editToweightData.weightData.id},
  152. "id":$scope.editId,
  153. "priority":{id:$scope.editToYXData.YXData.id},
  154. "version":$scope.version
  155. }
  156. }
  157. jry_api_bpm.jry_editFn(filedata,"incidentdescribe").then(function(res1){
  158. if(res1.status==200){
  159. $scope.editShow=false;
  160. $(".editBox").css({"top":"-169px"});
  161. jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){
  162. $scope.jry_scricData=res.list;
  163. })
  164. SweetAlert.swal({
  165. title: "修改成功!",
  166. confirmButtonColor: "#007AFF",
  167. type: "success"
  168. });
  169. }else{
  170. SweetAlert.swal({
  171. title: "修改失败!",
  172. text: "请重新再试!",
  173. type: "error"
  174. });
  175. }
  176. })
  177. }
  178. }
  179. $scope.getYXData();
  180. $scope.getWeightData();
  181. $scope.toYXData={};
  182. $scope.toweightData={};
  183. // $scope.langs=i18nService.getAllLangs();
  184. // $scope.lang = 'zh-cn';
  185. var loginUser = $rootScope.user;
  186. // $scope.gridOptions = {};
  187. // $scope.gridOptions.data = 'myData';
  188. // $scope.gridOptions.enableColumnResizing = true;
  189. // $scope.gridOptions.enableFiltering = false;
  190. // $scope.gridOptions.enableGridMenu = false;
  191. // $scope.gridOptions.enableRowSelection = true;
  192. // $scope.gridOptions.showGridFooter = true;
  193. // $scope.gridOptions.showColumnFooter = false;
  194. // $scope.gridOptions.fastWatch = true;
  195. // $scope.gridOptions.useExternalPagination = true;
  196. // $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  197. // $scope.gridOptions.paginationPageSize = 10;
  198. // $scope.gridOptions.multiSelect = true;
  199. //组
  200. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(data) {
  201. $scope.group = data.list;
  202. });
  203. /* ----- tree----- */
  204. var apple_selected, tree, treedata_avm, treedata_geography;
  205. //$scope.selectedTreeNode = {};ssss
  206. var i = 0;
  207. $scope.out = [];
  208. $scope.outdata = [];
  209. var systemtype = [];
  210. $scope.addcate = false;
  211. $scope.changecate = false;
  212. // $scope.refreshListData = function(){
  213. // var data ={"idx":0,"sum":1000};
  214. // api_bpm_data.fetchDataList('incidentcategory',data).then(function(response){
  215. // if(response){
  216. // if(response.status=200){
  217. // $scope.outdata = response.list;
  218. // }
  219. // }
  220. // })
  221. // }
  222. // $scope.refreshListData();
  223. var childdata = {};
  224. $scope.jry_scricData=[];
  225. $scope.toGetData={
  226. "idx":0,
  227. "sum":1000
  228. }
  229. $scope.treeId="";
  230. $scope.my_tree_handler = function(branch) {
  231. console.log(branch);
  232. $scope.treeId=branch.id;
  233. $scope.toGetData["incidentdescribe"]={"categoryid":{id:$scope.treeId}};
  234. jry_api_bpm.jry_getIncidentScri($scope.toGetData).then(function(res){
  235. $scope.jry_scricData=res.list
  236. })
  237. // $scope.changecate = true;
  238. // $scope.addcate = false;
  239. // filterData.treeIds = branch.id;
  240. // $scope.selectedTreeNode = branch;
  241. // $scope.output = branch;
  242. // convertchildToTree(branch);
  243. // // console.log($scope.subdata)
  244. // var eqflag = false;
  245. // angular.forEach($scope.outdata, function(item) {
  246. // if (item.id == $scope.output.id) eqflag = true;
  247. // });
  248. // if (eqflag) {
  249. // } else {
  250. // $scope.outdata.push({
  251. // 'name': $scope.output.label,
  252. // 'id': $scope.output.id
  253. // });
  254. // var postData = {
  255. // typeList: []
  256. // };
  257. // if ($scope.outdata.length > 0) {
  258. // angular.forEach($scope.outdata, function(data) {
  259. // postData.typeList.push({ id: data.id });
  260. // })
  261. // }
  262. // // api_solution.findSolutionTypesUser(postData).then(function(response){
  263. // // //Restangular.
  264. // // $scope.userdata = response.data;
  265. // // });
  266. // }
  267. };
  268. $scope.addType = function(element) {
  269. $scope.addcate = true
  270. $scope.changecate = false
  271. // var modalInstance = $modal.open({
  272. // templateUrl: 'assets/views/system/tpl/systemclose.html',
  273. // controller: function($scope, $modalInstance, api_bpm_data){
  274. // // api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
  275. // // var myData = Restangular.stripRestangular(data);
  276. // // }
  277. // }
  278. // });
  279. }
  280. /* -----start remove incidet category----- */
  281. $scope.remove = function(element) {
  282. var modalInstance = $modal.open({
  283. templateUrl: 'assets/views/delete.html',
  284. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  285. // $scope.title = '优先级删除';
  286. // $scope.connect = '确定要删除此优先级?';
  287. $scope.title = "故障现象删除?";
  288. $scope.connect = "确定要删除此故障现象?";
  289. $scope.ok = function() {
  290. $modalInstance.close(element);
  291. };
  292. $scope.cancel = function() {
  293. $modalInstance.dismiss('cancel');
  294. };
  295. },
  296. size: 'sm',
  297. resolve: {
  298. scope: function() {
  299. return $scope;
  300. }
  301. }
  302. });
  303. modalInstance.result.then(function(selectedItem) {
  304. if (selectedItem) {
  305. var rmvList = [];
  306. rmvList.push(selectedItem.id);
  307. if (selectedItem.children.length > 0) {
  308. SweetAlert.swal({
  309. title: "删除失败!",
  310. text: "请先删除选中的分类的子级",
  311. type: "error"
  312. })
  313. } else {
  314. api_bpm_data.rmvData('incidentcategory', rmvList).then(function(response) {
  315. if (response.data) {
  316. SweetAlert.swal({
  317. title: "删除成功!",
  318. type: "success",
  319. confirmButtonColor: "#007AFF"
  320. }, function() {
  321. $scope.try_async_load();
  322. $scope.$apply($scope.my_data);
  323. });
  324. } else {
  325. SweetAlert.swal({
  326. title: "操作异常!",
  327. text: "系统异常,请稍后重试,或者联系管理员!",
  328. type: "error"
  329. });
  330. }
  331. })
  332. }
  333. }
  334. })
  335. }
  336. /* -----end remove incidet category----- */
  337. // $scope.remove = function(element){
  338. // if(element.children.length>0){
  339. // SweetAlert.swal({
  340. // title:"删除失败!",
  341. // text:"请先删除选中的分类的子级",
  342. // type:"error"
  343. // })
  344. // }else{
  345. // var filedata=[element.id]
  346. // api_bpm_data.rmvData('incidentcategory',filedata).then(function(response){
  347. // if(response){
  348. // if(response.status==200){
  349. // $scope.try_async_load()
  350. // SweetAlert.swal({
  351. // title:"删除成功!",
  352. // type:"success"
  353. // },function(){
  354. // $scope.$apply($scope.my_data);
  355. // })
  356. // }else{
  357. // SweetAlert.swal({
  358. // title:"删除失败!",
  359. // type:"error"
  360. // })
  361. // }
  362. // }
  363. // });
  364. // }
  365. // }
  366. function convertchildToTree(datum) {
  367. $scope.subdata = {};
  368. // console.log($scope.parentdata)
  369. if (datum.parent) {
  370. // angular.forEach($scope.parentdata, function(item, index) {
  371. // if (datum.id == item.id) return $scope.subdata = item;
  372. // });
  373. $scope.subdata = { 'id': datum.id, 'category': datum.label, 'parent': datum.parent, 'hasArea': datum.hasArea, 'hasSimple': datum.hasSimple, 'group': datum.group }
  374. } else {
  375. $scope.subdata = { 'id': datum.id, 'category': datum.label, 'group': datum.group, 'hasSimple': datum.hasSimple, 'hasArea': datum.hasArea }
  376. }
  377. // if(datum.children.length==0){
  378. // angular.forEach($scope.parentdata,function(item, index){
  379. // if(datum.id==item.id) return $scope.subdata=item;
  380. // });
  381. // }else{$scope.subdata={id:datum.id,category:datum.label}}
  382. }
  383. function convertListToTree(data, treeMap) {
  384. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  385. var root = null; //Initially set our loop to null
  386. //loop over data
  387. var parentNode;
  388. for (var i = 0; i < data.length; i++) {
  389. var datum = data[i];
  390. //each node will have children, so let's give it a "children" poperty
  391. datum.children = [];
  392. //add an entry for this node to the map so that any future children can
  393. //lookup the parent
  394. idToNodeMap[datum.id] = datum;
  395. //Does this node have a parent?
  396. // console.log("datum="+JSON.stringify(datum))
  397. if (typeof datum.parent === "undefined") {
  398. //Doesn't look like it, so this node is the root of the tree
  399. root = datum;
  400. treeMap[datum.id] = root;
  401. } else {
  402. //This node has a parent, so let's look it up using the id
  403. parentNode = idToNodeMap[datum.parent.id];
  404. //We don't need this property, so let's delete it.
  405. // delete datum.parent;
  406. //Let's add the current node as a child of the parent node.
  407. parentNode.children.push(datum);
  408. }
  409. }
  410. return root;
  411. }
  412. function convertParentToChildList(data) {
  413. var treeMap = {};
  414. var list = [];
  415. convertListToTree(data, treeMap);
  416. angular.forEach(treeMap, function(item) {
  417. list.push(item);
  418. });
  419. return list;
  420. }
  421. // $scope.onFilterCallback = function(item){
  422. // $scope.addcategory.parent=item.label;
  423. // }
  424. $scope.parentdata = {};
  425. $scope.try_async_load = function() {
  426. $scope.my_data = [];
  427. $scope.doing_async = true;
  428. var data = { "idx": 0, "sum": 1000 };
  429. api_bpm_data.fetchDataList('incidentcategory', data).then(function(response) {
  430. var data = response.list;
  431. var objects = [];
  432. $scope.parentdata = data;
  433. for (var i = 0; i < data.length; i++) {
  434. var object = {};
  435. object.id = data[i].id;
  436. if (angular.isDefined(data[i].parent)) {
  437. object.parent = data[i].parent;
  438. }
  439. if (angular.isDefined(data[i].hasArea)) {
  440. object.hasArea = data[i].hasArea;
  441. }
  442. if (angular.isDefined(data[i].hasSimple)) {
  443. object.hasSimple = data[i].hasSimple;
  444. }
  445. if (angular.isDefined(data[i].group)) {
  446. object.group = data[i].group;
  447. }
  448. object.label = data[i].category;
  449. // object.actions = data[i][3]; //权限部分
  450. // object.group = "1";
  451. // object.user = "2";
  452. object.state = {
  453. "opened": true
  454. };
  455. object.typeName = "type";
  456. // if()
  457. // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
  458. $scope.showAddSolutionType = true;
  459. // }
  460. // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
  461. $scope.showReviewKnowledgeType = true;
  462. // }
  463. objects.push(object);
  464. }
  465. $scope.my_data = convertParentToChildList(objects);
  466. $scope.tree_data = angular.copy($scope.my_data);
  467. if ($scope.my_data.length > 0) {
  468. $scope.doing_async = false;
  469. }
  470. });
  471. };
  472. $scope.closethis = function(formdata) {
  473. formdata.category = "";
  474. formdata.parent.category = "";
  475. };
  476. /* -----start submit incidet category----- */
  477. $scope.submitchange = function(formdata) {
  478. if (formdata.hasArea) {
  479. formdata.hasArea = 1;
  480. formdata.hasPlace = 1;
  481. } else {
  482. formdata.hasArea = 0;
  483. formdata.hasPlace = 0;
  484. }
  485. // }
  486. if (formdata.hasSimple == true) {
  487. formdata.hasSimple = 1;
  488. } else {
  489. formdata.hasSimple = 0;
  490. }
  491. if (formdata.parent) {
  492. formdata.parent = { "id": formdata.parent.id };
  493. }
  494. var filedata = { "incidentcategory": formdata }
  495. api_bpm_data.updData('incidentcategory', filedata).then(function(response) {
  496. if (response) {
  497. if (response.status == 200) {
  498. $scope.try_async_load()
  499. SweetAlert.swal({
  500. title: "修改成功!",
  501. type: "success"
  502. }, function() {
  503. $scope.$apply($scope.my_data);
  504. })
  505. } else {
  506. SweetAlert.swal({
  507. title: "修改失败!",
  508. type: "error"
  509. })
  510. }
  511. }
  512. });
  513. };
  514. $scope.adddata = {};
  515. $scope.addparent = false;
  516. $scope.submitadd = function(formdata) {
  517. // var paret = {};
  518. // var filedata = {};
  519. // filedata = angular.copy(formdata);
  520. // delete filedata.addp
  521. // if (angular.isDefined(formdata.parent) && addparent) {
  522. // angular.forEach($scope.parentdata, function(data) {
  523. // if (formdata.parent.category.id == data.id) {
  524. // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": data.id } } }
  525. // }
  526. // })
  527. // } else {
  528. // filedata = { "incidentcategory": { "category": formdata.category } }
  529. // }
  530. // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": formdata.parentNode.id } } }
  531. // if (formdata.hasArea && formdata.hasArea == true) {
  532. if (formdata.hasArea) {
  533. formdata.hasArea = 1;
  534. formdata.hasPlace = 1;
  535. } else {
  536. formdata.hasArea = 0;
  537. formdata.hasPlace = 0;
  538. }
  539. if (formdata.hasSimple == true) {
  540. formdata.hasSimple = 1;
  541. } else {
  542. formdata.hasSimple = 0;
  543. }
  544. if (formdata.parent) {
  545. formdata.parent = { "id": formdata.parent.id };
  546. }
  547. var filedata = { "incidentcategory": formdata }
  548. api_bpm_data.addData('incidentcategory', filedata).then(function(response) {
  549. if (response) {
  550. if (response.status == 200) {
  551. $scope.userdata = [];
  552. $scope.outdata = [];
  553. $scope.try_async_load();
  554. SweetAlert.swal({
  555. title: "增加成功!",
  556. type: "success"
  557. })
  558. } else if (response.status == 408) {
  559. SweetAlert.swal({
  560. title: "增加失败!",
  561. text: response.error,
  562. type: "error"
  563. })
  564. } else {
  565. SweetAlert.swal({
  566. title: "增加失败!",
  567. type: "error"
  568. })
  569. }
  570. }
  571. });
  572. };
  573. /* -----end submit incidet category----- */
  574. $scope.try_async_load();
  575. // $scope.ldloading={};
  576. var filterData = {
  577. key: 'null',
  578. status: 0,
  579. pageIndex: 0,
  580. pageSum: 10,
  581. //treeIds:'[]',
  582. userId: loginUser.id
  583. }
  584. }])