knowledgecateCtrl.js 15 KB

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