aa.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. app.controller('knowledgeMobileCtrl', ["$rootScope", "$scope", "i18nService", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_solution", "api_bpm_domain", "$aside", function($rootScope, $scope, i18nService, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_solution, api_bpm_domain, $aside) {
  2. $scope.langs = i18nService.getAllLangs();
  3. $scope.lang = 'zh-cn';
  4. i18nService.setCurrentLang($scope.lang);
  5. var loginUser = $rootScope.user;
  6. $scope.allfilterData = {
  7. key: 'null',
  8. status: 0,
  9. pageIndex: 0,
  10. pageSum: 10,
  11. //treeIds:'[]',
  12. userId: loginUser.id
  13. }
  14. $scope.paginationList = {
  15. 'count': 0,
  16. 'idx': 0,
  17. 'sum': 10,
  18. 'currentPage': 1,
  19. 'endPage': 0,
  20. 'pages': []
  21. }
  22. var filterData = {
  23. key: 'null',
  24. status: 0,
  25. pageIndex: 0,
  26. pageSum: 10,
  27. //treeIds:'[]',
  28. userId: loginUser.id
  29. }
  30. var knowledgeMobileCtrlParameter = {
  31. ' key': "null",
  32. 'pageIndex': 0,
  33. 'pageSum': 10,
  34. 'status': 0,
  35. 'userId': loginUser.id
  36. }
  37. sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(knowledgeMobileCtrlParameter);
  38. $scope.transferStatus = function(status) {
  39. var statusLabel = "不合法的状态";
  40. if (status == 1) {
  41. statusLabel = "待审核";
  42. } else if (status == 2) {
  43. statusLabel = "已批准";
  44. } else if (status == 3) {
  45. statusLabel = "已发布";
  46. } else if (status == 4) {
  47. statusLabel = "已取消";
  48. } else if (status == 5) {
  49. statusLabel = "已驳回";
  50. } else if (status == 6) {
  51. statusLabel = "已拒绝";
  52. }
  53. return statusLabel;
  54. }
  55. $scope.openAside = function(position) {
  56. var asideOpen = $aside.open({
  57. templateUrl: 'assets/views/knowledge/asideContent.html',
  58. placement: position,
  59. size: 'sm',
  60. backdrop: true,
  61. controller: function($scope, $modalInstance, api_user_data, api_solution) {
  62. $scope.ok = function(e) {
  63. $modalInstance.close("asideOpen");
  64. // e.stopPropagation();
  65. };
  66. $scope.cancel = function(e) {
  67. $modalInstance.dismiss();
  68. // e.stopPropagation();
  69. };
  70. $scope.statuses = [
  71. { status: 1, label: '待审核', idName: 'a' },
  72. { status: 2, label: '已批准', idName: 'b' },
  73. { status: 3, label: '已发布', idName: 'c' },
  74. { status: 4, label: '已取消', idName: 'd' },
  75. { status: 5, label: '已驳回', idName: 'e' },
  76. { status: 6, label: '已拒绝', idName: 'f' }
  77. ];
  78. $scope.onChange = function(searchType) {
  79. var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
  80. filterData.searchType = searchType;
  81. sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(filterData);
  82. }
  83. $scope.my_tree_handler = function(branch) {
  84. var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
  85. filterData.status = branch.id;
  86. sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(filterData);
  87. };
  88. function convertListToTree(data, treeMap) {
  89. var idToNodeMap = {};
  90. var root = null;
  91. var parentNode = null;
  92. for (var i = 0; i < data.length; i++) {
  93. var datum = data[i];
  94. datum.children = [];
  95. idToNodeMap[datum.id] = datum;
  96. if (typeof datum.parent === "undefined" || datum.parent == null) {
  97. root = datum;
  98. treeMap[datum.id] = root;
  99. } else {
  100. parentNode = idToNodeMap[datum.parent];
  101. delete datum.parent;
  102. parentNode.children.push(datum);
  103. }
  104. }
  105. return root;
  106. };
  107. function convertParentToChildList(data) {
  108. var treeMap = {};
  109. var list = [];
  110. convertListToTree(data, treeMap);
  111. angular.forEach(treeMap, function(item) {
  112. list.push(item);
  113. });
  114. return list;
  115. };
  116. $scope.my_tree = tree = {};
  117. $scope.try_async_load = function() {
  118. $scope.my_data = [];
  119. $scope.doing_async = true;
  120. api_solution.findSolutionTypeActions(loginUser.id).then(function(response) {
  121. if (response.status == 200) {
  122. var data = response.data;
  123. // console.log('data='+JSON.stringify(data));
  124. var objects = [];
  125. for (var i = 0; i < data.length; i++) {
  126. var object = {};
  127. object.id = data[i].id;
  128. if (data[i].pid != 0) {
  129. object.parent = data[i].pid;
  130. }
  131. // if (object.parent == 0) {
  132. // object.parent = "#";
  133. // }
  134. object.label = data[i].typeName;
  135. object.actions = data[i].actions; //权限部分
  136. object.group = "1";
  137. object.user = "2";
  138. object.state = {
  139. "opened": true
  140. };
  141. object.typeName = "type";
  142. objects.push(object);
  143. }
  144. $scope.my_data = convertParentToChildList(objects);
  145. $scope.tree_data = angular.copy($scope.my_data);
  146. if ($scope.my_data.length > 0) {
  147. $scope.doing_async = false;
  148. }
  149. } else {
  150. SweetAlert.swal({
  151. title: "系统错误!",
  152. text: "请刷新重试!",
  153. type: "error"
  154. });
  155. }
  156. });
  157. };
  158. $scope.try_async_load();
  159. }
  160. });
  161. asideOpen.result.then(function(result) {
  162. var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
  163. $scope.refreshListData('expand-right', filterData);
  164. });
  165. };
  166. //前往第一页按钮
  167. $scope.paginationList.fristPage = function() {
  168. filterData.pageIndex = 0;
  169. $scope.refreshListData('expand-right', filterData);
  170. }
  171. //前往最后一页按钮
  172. $scope.paginationList.lastPage = function() {
  173. filterData.pageIndex = $scope.paginationList.endPage - 1;
  174. $scope.refreshListData('expand-right', filterData);
  175. }
  176. //加载某一页
  177. $scope.paginationList.loadPage = function(page) {
  178. $scope.allfilterData.pageIndex = page - 1;
  179. filterData.pageIndex = page - 1;
  180. $scope.refreshListData('expand-right', filterData);
  181. }
  182. //初始化分页栏
  183. var reloadPno = function() {
  184. $scope.paginationList.pages = calculateIndexes($scope.paginationList.currentPage, $scope.paginationList.endPage, 3);
  185. };
  186. //分页算法
  187. var calculateIndexes = function(current, length, displayLength) {
  188. var indexes = [];
  189. var start = Math.round(current - displayLength / 2);
  190. var end = Math.round(current + displayLength / 2);
  191. if (start <= 1) {
  192. start = 1;
  193. end = start + displayLength - 1;
  194. if (end >= length - 1) {
  195. end = length - 1;
  196. }
  197. }
  198. if (end >= length - 1) {
  199. end = length;
  200. start = end - displayLength + 1;
  201. if (start <= 1) {
  202. start = 1;
  203. }
  204. }
  205. for (var i = start; i <= end; i++) {
  206. indexes.push(i);
  207. }
  208. return indexes;
  209. };
  210. $scope.refreshListData = function(style, filterData) {
  211. $scope.ldloading[style.replace('-', '_')] = true;
  212. if (angular.isUndefined(filterData)) {
  213. filterData = defaultFilterData;
  214. }
  215. if (angular.isDefined($scope.searchTypes)) {
  216. filterData['searchType'] = $scope.searchTypes;
  217. }
  218. $scope.myData = [];
  219. api_solution.findSolutionByKeys(filterData).then(function(data) {
  220. var myData = Restangular.stripRestangular(data);
  221. if (angular.isArray(myData.list)) {
  222. $scope.myData = myData.list;
  223. if (angular.isDefined($scope.paginationList)) {
  224. $scope.paginationList.count = myData.totalNum;
  225. $scope.paginationList.endPage = Math.ceil($scope.paginationList.count / $scope.paginationList.sum);
  226. $scope.paginationList.currentPage = filterData.pageIndex + 1;
  227. reloadPno();
  228. }
  229. } else {
  230. SweetAlert.swal({
  231. title: "数据为空",
  232. text: myData.list,
  233. type: "warning"
  234. });
  235. }
  236. $scope.ldloading[style.replace('-', '_')] = false;
  237. }, function() {
  238. $scope.ldloading[style.replace('-', '_')] = false;
  239. });
  240. }
  241. $scope.createKnowledge = function() {
  242. var data = { model: { knowledge: { createUserId: loginUser.id, status: 1 } } };
  243. $state.go('app.knowledge.create', { formKey: 'knowledge_create', service: 'api_solution', 'model': JSON.stringify(data) })
  244. }
  245. $scope.detailSolution = function(id) {
  246. api_solution.findSolutionById(id).then(function(response) {
  247. var data = { model: { knowledge: response.data } };
  248. if (!isNaN(data.model.knowledge.vision)) {
  249. data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
  250. }
  251. $state.go('app.knowledge.detail', { formKey: 'knowledge_detail', service: 'api_solution', 'model': JSON.stringify(data) })
  252. })
  253. }
  254. $scope.editSolution = function(id) {
  255. api_solution.findSolutionById(id).then(function(response) {
  256. var data = { model: { knowledge: response.data } };
  257. if (!isNaN(data.model.knowledge.vision)) {
  258. data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
  259. }
  260. $state.go('app.knowledge.editor', { formKey: 'knowledge_editor', service: 'api_solution', 'model': JSON.stringify(data) })
  261. })
  262. }
  263. var apple_selected, tree, treedata_avm, treedata_geography;
  264. //$scope.selectedTreeNode = {};
  265. $scope.my_tree_handler = function(branch) {
  266. filterData.treeIds = branch.id;
  267. $scope.selectedTreeNode = branch;
  268. $scope.refreshListData('expand-right', filterData);
  269. };
  270. $scope.my_data = [];
  271. $scope.tree_data = [];
  272. $scope.my_tree = tree = {};
  273. function convertListToTree(data, treeMap) {
  274. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  275. var root = null; //Initially set our loop to null
  276. var parentNode = null;
  277. //loop over data
  278. for (var i = 0; i < data.length; i++) {
  279. var datum = data[i];
  280. //each node will have children, so let's give it a "children" poperty
  281. datum.children = [];
  282. //add an entry for this node to the map so that any future children can
  283. //lookup the parent
  284. idToNodeMap[datum.id] = datum;
  285. //Does this node have a parent?
  286. if (typeof datum.parent === "undefined" || datum.parent == null) {
  287. //Doesn't look like it, so this node is the root of the tree
  288. root = datum;
  289. treeMap[datum.id] = root;
  290. } else {
  291. //This node has a parent, so let's look it up using the id
  292. parentNode = idToNodeMap[datum.parent];
  293. //We don't need this property, so let's delete it.
  294. delete datum.parent;
  295. //Let's add the current node as a child of the parent node.
  296. parentNode.children.push(datum);
  297. }
  298. }
  299. return root;
  300. }
  301. function convertParentToChildList(data) {
  302. var treeMap = {};
  303. var list = [];
  304. convertListToTree(data, treeMap);
  305. angular.forEach(treeMap, function(item) {
  306. list.push(item);
  307. });
  308. return list;
  309. }
  310. var uploader = $scope.uploader = new FileUploader({
  311. url: api_solution.upload().getRequestedUrl(),
  312. alias: "file",
  313. removeAfterUpload: true,
  314. queueLimit: 10
  315. // headers : {
  316. // }
  317. });
  318. $scope.my_tree = tree = {};
  319. $scope.try_async_load = function() {
  320. $scope.my_data = [];
  321. $scope.doing_async = true;
  322. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(response) {
  323. var myData = Restangular.stripRestangular(response);
  324. var list = myData.list;
  325. var objects = [];
  326. for (var i = 0; i < list.length; i++) {
  327. var object = {};
  328. object.id = list[i].id;
  329. if (list[i].parent == 0) {
  330. object.parent = "#";
  331. } else {
  332. object.parent = list[i].parent;
  333. }
  334. object.text = list[i].groupName;
  335. object.typeName = "group";
  336. object.state = {
  337. "opened": true
  338. };
  339. objects.push(object);
  340. }
  341. $scope.groups = objects;
  342. });
  343. api_solution.findSolutionTypeActions(loginUser.id).then(function(response) {
  344. if (response.status == 200) {
  345. var data = response.data;
  346. // console.log('data='+JSON.stringify(data));
  347. var objects = [];
  348. for (var i = 0; i < data.length; i++) {
  349. var object = {};
  350. object.id = data[i].id;
  351. if (data[i].pid != 0) {
  352. object.parent = data[i].pid;
  353. }
  354. // if (object.parent == 0) {
  355. // object.parent = "#";
  356. // }
  357. object.label = data[i].typeName;
  358. object.actions = data[i].actions; //权限部分
  359. object.group = "1";
  360. object.user = "2";
  361. object.state = {
  362. "opened": true
  363. };
  364. object.typeName = "type";
  365. objects.push(object);
  366. }
  367. $scope.my_data = convertParentToChildList(objects);
  368. $scope.tree_data = angular.copy($scope.my_data);
  369. if ($scope.my_data.length > 0) {
  370. $scope.doing_async = false;
  371. }
  372. } else {
  373. SweetAlert.swal({
  374. title: "系统错误!",
  375. text: "请刷新重试!",
  376. type: "error"
  377. });
  378. }
  379. });
  380. $scope.showAddSolutionType = false; //添加知识类型 按钮
  381. $scope.showReviewKnowledgeType = false; //审核知识类型 按钮
  382. };
  383. $scope.try_async_load();
  384. $scope.ldloading = {};
  385. $scope.statuses = [
  386. { status: 1, label: '待审核' },
  387. { status: 2, label: '已批准' },
  388. { status: 3, label: '已发布' },
  389. { status: 4, label: '已取消' },
  390. { status: 5, label: '已驳回' },
  391. { status: 6, label: '已拒绝' }
  392. ];
  393. $scope.$watch('searchSolutionInput', function(oldvalue, newvalue) {
  394. // console.log(' oldvalue='+JSON.stringify( oldvalue));
  395. // console.log(' newvalue='+JSON.stringify( newvalue));
  396. // if(oldvalue==newvalue) return;
  397. if (angular.isUndefined(oldvalue) || oldvalue == '') {
  398. filterData.key = 'null';
  399. } else {
  400. filterData.key = oldvalue;
  401. }
  402. });
  403. $scope.searchSolution = function() {
  404. $scope.refreshListData('expand-right', filterData);
  405. }
  406. $scope.reload = function() {
  407. if ($rootScope.searchknowledge) { filterData = $rootScope.searchknowledge; }
  408. $scope.refreshListData('expand-right', filterData);
  409. }
  410. $scope.reload();
  411. }]);