knowledgecateCtrl.js 16 KB

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