incidentcategory.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. app.controller('incidentcateCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_bpm_data", "api_solution", "api_user_data","api_wechatfile", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_bpm_data, api_solution, api_user_data,api_wechatfile) {
  2. // $scope.langs=i18nService.getAllLangs();
  3. // $scope.lang = 'zh-cn';
  4. var loginUser = $rootScope.user;
  5. //组
  6. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(data) {
  7. $scope.group = data.list;
  8. });
  9. //优先级
  10. // api_bpm_data.fetchDataList('priority', { "idx": 0, "sum": 10 }).then(function(data) {
  11. // $scope.priority = data.list;
  12. // });
  13. api_wechatfile.getDictionary({"key":"incident_priority","type":"list"}).then(function(data){
  14. $scope.priority=data
  15. })
  16. /* ----- tree----- */
  17. var apple_selected, tree, treedata_avm, treedata_geography;
  18. //$scope.selectedTreeNode = {};ssss
  19. var i = 0;
  20. $scope.out = [];
  21. $scope.outdata = [];
  22. var systemtype = [];
  23. $scope.subdata={};
  24. $scope.addcate = false;
  25. $scope.changecate = false;
  26. // $scope.refreshListData = function(){
  27. // var data ={"idx":0,"sum":1000};
  28. // api_bpm_data.fetchDataList('incidentcategory',data).then(function(response){
  29. // if(response){
  30. // if(response.status=200){
  31. // $scope.outdata = response.list;
  32. // }
  33. // }
  34. // })
  35. // }
  36. // $scope.refreshListData();
  37. var childdata = {};
  38. $scope.my_tree_handler = function(branch) {
  39. $scope.changecate = true;
  40. $scope.addcate = false;
  41. filterData.treeIds = branch.id;
  42. $scope.selectedTreeNode = branch;
  43. $scope.output = branch;
  44. console.log(branch);
  45. if(branch.hasPlace==1){
  46. $scope.subdata.hasPlace=true
  47. }else{
  48. $scope.subdata.hasPlace=false
  49. }
  50. convertchildToTree(branch);
  51. // console.log($scope.subdata)
  52. var eqflag = false;
  53. angular.forEach($scope.outdata, function(item) {
  54. if (item.id == $scope.output.id) eqflag = true;
  55. });
  56. if (eqflag) {
  57. } else {
  58. $scope.outdata.push({
  59. 'name': $scope.output.label,
  60. 'id': $scope.output.id
  61. });
  62. var postData = {
  63. typeList: []
  64. };
  65. if ($scope.outdata.length > 0) {
  66. angular.forEach($scope.outdata, function(data) {
  67. postData.typeList.push({ id: data.id });
  68. })
  69. }
  70. // api_solution.findSolutionTypesUser(postData).then(function(response){
  71. // //Restangular.
  72. // $scope.userdata = response.data;
  73. // });
  74. }
  75. };
  76. $scope.addType = function(element) {
  77. $scope.addcate = true
  78. $scope.changecate = false
  79. // var modalInstance = $modal.open({
  80. // templateUrl: 'assets/views/system/tpl/systemclose.html',
  81. // controller: function($scope, $modalInstance, api_bpm_data){
  82. // // api_bpm_data.fetchDataList('closecode',filterData).then(function(data){
  83. // // var myData = Restangular.stripRestangular(data);
  84. // // }
  85. // }
  86. // });
  87. }
  88. /* -----start remove incidet category----- */
  89. $scope.remove = function(element) {
  90. var modalInstance = $modal.open({
  91. templateUrl: 'assets/views/delete.html',
  92. controller: function($scope, scope, $modalInstance, api_bpm_data) {
  93. // $scope.title = '优先级删除';
  94. // $scope.connect = '确定要删除此优先级?';
  95. $scope.title = "故障现象删除?";
  96. $scope.connect = "确定要删除此故障现象?";
  97. $scope.ok = function() {
  98. $modalInstance.close(element);
  99. };
  100. $scope.cancel = function() {
  101. $modalInstance.dismiss('cancel');
  102. };
  103. },
  104. size: 'sm',
  105. resolve: {
  106. scope: function() {
  107. return $scope;
  108. }
  109. }
  110. });
  111. modalInstance.result.then(function(selectedItem) {
  112. if (selectedItem) {
  113. var rmvList = [];
  114. rmvList.push(selectedItem.id);
  115. if (selectedItem.children.length > 0) {
  116. SweetAlert.swal({
  117. title: "删除失败!",
  118. text: "请先删除选中的分类的子级",
  119. type: "error"
  120. })
  121. } else {
  122. api_bpm_data.rmvData('incidentcategory', rmvList).then(function(response) {
  123. if (response.data) {
  124. SweetAlert.swal({
  125. title: "删除成功!",
  126. type: "success",
  127. confirmButtonColor: "#007AFF"
  128. }, function() {
  129. $scope.try_async_load();
  130. $scope.$apply($scope.my_data);
  131. });
  132. } else {
  133. SweetAlert.swal({
  134. title: "操作异常!",
  135. text: "系统异常,请稍后重试,或者联系管理员!",
  136. type: "error"
  137. });
  138. }
  139. })
  140. }
  141. }
  142. })
  143. }
  144. /* -----end remove incidet category----- */
  145. function convertchildToTree(datum) {
  146. $scope.subdata = {};
  147. // console.log($scope.parentdata)
  148. if (datum.parent) {
  149. // angular.forEach($scope.parentdata, function(item, index) {
  150. // if (datum.id == item.id) return $scope.subdata = item;
  151. // });
  152. $scope.subdata = { 'id': datum.id, 'category': datum.label, 'parent': datum.parent, 'hasPlace': datum.hasPlace, 'hasSimple': datum.hasSimple, 'group': datum.group, 'priority': datum.priority }
  153. } else {
  154. $scope.subdata = { 'id': datum.id, 'category': datum.label, 'group': datum.group, 'hasSimple': datum.hasSimple, 'hasPlace': datum.hasPlace, 'priority': datum.priority }
  155. }
  156. // if(datum.children.length==0){
  157. // angular.forEach($scope.parentdata,function(item, index){
  158. // if(datum.id==item.id) return $scope.subdata=item;
  159. // });
  160. // }else{$scope.subdata={id:datum.id,category:datum.label}}
  161. }
  162. function convertListToTree(data, treeMap) {
  163. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  164. var root = null; //Initially set our loop to null
  165. //loop over data
  166. for (var i = 0; i < data.length; i++) {
  167. var datum = data[i];
  168. //each node will have children, so let's give it a "children" poperty
  169. datum.children = [];
  170. //add an entry for this node to the map so that any future children can
  171. //lookup the parent
  172. idToNodeMap[datum.id] = datum;
  173. //Does this node have a parent?
  174. // console.log("datum="+JSON.stringify(datum))
  175. if (typeof datum.parent === "undefined") {
  176. //Doesn't look like it, so this node is the root of the tree
  177. root = datum;
  178. treeMap[datum.id] = root;
  179. } else {
  180. //This node has a parent, so let's look it up using the id
  181. parentNode = idToNodeMap[datum.parent.id];
  182. //We don't need this property, so let's delete it.
  183. // delete datum.parent;
  184. //Let's add the current node as a child of the parent node.
  185. parentNode.children.push(datum);
  186. }
  187. }
  188. return root;
  189. }
  190. function convertParentToChildList(data) {
  191. var treeMap = {};
  192. var list = [];
  193. convertListToTree(data, treeMap);
  194. angular.forEach(treeMap, function(item) {
  195. list.push(item);
  196. });
  197. return list;
  198. }
  199. // $scope.onFilterCallback = function(item){
  200. // $scope.addcategory.parent=item.label;
  201. // }
  202. $scope.parentdata = {};
  203. $scope.try_async_load = function() {
  204. $scope.my_data = [];
  205. $scope.doing_async = true;
  206. var data = { "idx": 0, "sum": 1000 };
  207. api_bpm_data.fetchDataList('incidentcategory', data).then(function(response) {
  208. var data = response.list;
  209. var objects = [];
  210. $scope.parentdata = data;
  211. for (var i = 0; i < data.length; i++) {
  212. var object = {};
  213. object.id = data[i].id;
  214. if (angular.isDefined(data[i].parent)) {
  215. object.parent = data[i].parent;
  216. }
  217. if (angular.isDefined(data[i].hasPlace)) {
  218. object.hasPlace = data[i].hasPlace;
  219. }
  220. if (angular.isDefined(data[i].hasSimple)) {
  221. object.hasSimple = data[i].hasSimple;
  222. }
  223. if (angular.isDefined(data[i].group)) {
  224. object.group = data[i].group;
  225. }
  226. if (angular.isDefined(data[i].priority)) {
  227. object.priority = data[i].priority;
  228. }
  229. object.label = data[i].category;
  230. // object.actions = data[i][3]; //权限部分
  231. // object.group = "1";
  232. // object.user = "2";
  233. object.state = {
  234. "opened": true
  235. };
  236. object.typeName = "type";
  237. // if()
  238. // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
  239. $scope.showAddSolutionType = true;
  240. // }
  241. // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
  242. $scope.showReviewKnowledgeType = true;
  243. // }
  244. objects.push(object);
  245. }
  246. $scope.my_data = convertParentToChildList(objects);
  247. $scope.tree_data = angular.copy($scope.my_data);
  248. if ($scope.my_data.length > 0) {
  249. $scope.doing_async = false;
  250. }
  251. });
  252. };
  253. $scope.closethis = function(formdata) {
  254. formdata.category = "";
  255. formdata.parent.category = "";
  256. };
  257. /* -----start submit incidet category----- */
  258. $scope.submitchange = function(formdata) {
  259. // if (formdata.hasArea) {
  260. // formdata.hasArea = 1;
  261. // formdata.hasPlace = 1;
  262. // } else {
  263. // formdata.hasArea = 0;
  264. // formdata.hasPlace = 0;
  265. // }
  266. if (formdata.hasPlace==true) {
  267. formdata.hasPlace = 1;
  268. } else {
  269. formdata.hasPlace = 0;
  270. }
  271. // }
  272. if (formdata.hasSimple == true) {
  273. formdata.hasSimple = 1;
  274. } else {
  275. formdata.hasSimple = 0;
  276. }
  277. if ($scope.selectedTreeNode.parent) {
  278. formdata.parent = { "id": $scope.selectedTreeNode.parent.id };
  279. }
  280. var filedata = { "incidentcategory": formdata }
  281. api_bpm_data.updData('incidentcategory', filedata).then(function(response) {
  282. if (response) {
  283. if (response.status == 200) {
  284. $scope.try_async_load()
  285. SweetAlert.swal({
  286. title: "修改成功!",
  287. type: "success"
  288. }, function() {
  289. $scope.$apply($scope.my_data);
  290. })
  291. } else {
  292. SweetAlert.swal({
  293. title: "修改失败!",
  294. type: "error"
  295. })
  296. }
  297. }
  298. });
  299. };
  300. $scope.adddata = {};
  301. $scope.addparent = false;
  302. $scope.submitadd = function(formdata) {
  303. // var paret = {};
  304. // var filedata = {};
  305. // filedata = angular.copy(formdata);
  306. // delete filedata.addp
  307. // if (angular.isDefined(formdata.parent) && addparent) {
  308. // angular.forEach($scope.parentdata, function(data) {
  309. // if (formdata.parent.category.id == data.id) {
  310. // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": data.id } } }
  311. // }
  312. // })
  313. // } else {
  314. // filedata = { "incidentcategory": { "category": formdata.category } }
  315. // }
  316. // filedata = { "incidentcategory": { "category": formdata.category, "parent": { "id": formdata.parentNode.id } } }
  317. // if (formdata.hasArea && formdata.hasArea == true) {
  318. // if (formdata.hasArea) {
  319. // formdata.hasArea = 1;
  320. // formdata.hasPlace = 1;
  321. // } else {
  322. // formdata.hasArea = 0;
  323. // formdata.hasPlace = 0;
  324. // }
  325. if (formdata.hasPlace == true) {
  326. formdata.hasPlace = 1;
  327. } else {
  328. formdata.hasPlace = 0;
  329. }
  330. if (formdata.hasSimple == true) {
  331. formdata.hasSimple = 1;
  332. } else {
  333. formdata.hasSimple = 0;
  334. }
  335. if (formdata.parent) {
  336. formdata.parent = { "id": formdata.parent.id };
  337. }
  338. var filedata = { "incidentcategory": formdata }
  339. api_bpm_data.addData('incidentcategory', filedata).then(function(response) {
  340. if (response) {
  341. if (response.status == 200) {
  342. $scope.userdata = [];
  343. $scope.outdata = [];
  344. $scope.try_async_load();
  345. SweetAlert.swal({
  346. title: "增加成功!",
  347. type: "success"
  348. })
  349. } else if (response.status == 408) {
  350. SweetAlert.swal({
  351. title: "增加失败!",
  352. text: response.error,
  353. type: "error"
  354. })
  355. } else {
  356. SweetAlert.swal({
  357. title: "增加失败!",
  358. type: "error"
  359. })
  360. }
  361. }
  362. });
  363. };
  364. /* -----end submit incidet category----- */
  365. $scope.try_async_load();
  366. // $scope.ldloading={};
  367. var filterData = {
  368. key: 'null',
  369. status: 0,
  370. pageIndex: 0,
  371. pageSum: 10,
  372. //treeIds:'[]',
  373. userId: loginUser.id
  374. }
  375. }]);