resourceSearchResult.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. angular.module('push')
  2. .controller('resourceSearchResultCtrl', function ($scope, $state, $timeout, $ionicTabsDelegate, $stateParams, $http, UtilService, $ionicScrollDelegate,
  3. ResourceLibraryService, SearchResultService, $ionicHistory, $sce, CommentService, UserService) {
  4. $scope.key = $stateParams.key;
  5. $scope.searchtype = $stateParams.searchtype;
  6. var infoid = $stateParams.infoid;
  7. var infotype = $stateParams.infotype;
  8. var reclibid = $stateParams.reclibid;
  9. $scope.isedit = $stateParams.isedit;
  10. $scope.choseTab = $stateParams.tabindex;
  11. $scope.oldtabindex = angular.copy($stateParams.tabindex);
  12. $scope.userid = UserService.id;
  13. $scope.showbaidu = false;
  14. var libtype = 1001;
  15. if ($scope.choseTab == 4) {
  16. libtype = 1;
  17. } else if ($scope.choseTab == 3) {
  18. libtype = 2;
  19. } else if ($scope.choseTab == 5) {
  20. libtype = 6;
  21. } else if ($scope.choseTab == 6) {
  22. libtype = 8;
  23. }
  24. var checked = {
  25. SortType: 0,
  26. classificationType: libtype,
  27. starType: 0,
  28. MaturityType: 0,
  29. RightType: 0,
  30. ModelType: 0,
  31. BudgetType: 0,
  32. ScaleType: 0,
  33. EnterpriseType: 0,
  34. DegreeType: 0,
  35. sexType: 0,
  36. TitleType: 0,
  37. UniversityType: 0
  38. };
  39. $scope.hasmore = [{currentPage: 1, isload: false}, {currentPage: 1, isload: false}, {
  40. currentPage: 1,
  41. isload: false
  42. }];
  43. $scope.changeAct = function (index) {
  44. $scope.choseTab = index;
  45. if ($scope.choseTab == 4) {
  46. checked.classificationType = 1;
  47. } else if ($scope.choseTab == 3) {
  48. checked.classificationType = 2;
  49. } else if ($scope.choseTab == 5) {
  50. checked.classificationType = 6;
  51. } else if ($scope.choseTab == 6) {
  52. checked.classificationType = 8;
  53. } else {
  54. checked.classificationType = 1001;
  55. }
  56. $scope.searchResultByKey($scope.key);
  57. };
  58. //根据关键字搜索综合、用户信息
  59. $scope.searchResultByKey = function (key) {
  60. if (!UtilService.isDefined(key)) {
  61. return;
  62. }
  63. if ($scope.searchtype == 0) {
  64. if ($scope.choseTab == 0) {
  65. searchResourceLibary(key);
  66. } else if ($scope.choseTab == 2) {
  67. searchUser(key);
  68. } else {
  69. searchResource(key);
  70. }
  71. } else {
  72. selectComment($scope.key);
  73. }
  74. };
  75. //搜索资源库
  76. var searchResourceLibary = function (key) {
  77. $scope.showbaidu = false;
  78. $scope.showLoadingToast();
  79. ResourceLibraryService.getResourceLibrary(key).then(function (response) {
  80. // console.log(response);
  81. if (response.length == 0) {
  82. UtilService.showMess("未搜索到相关信息");
  83. }
  84. $scope.resourcelibrarylist = response;
  85. $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0);
  86. $scope.hideLoadingToast();
  87. }, function () {
  88. UtilService.showMess("网络不给力,请重试");
  89. }).finally(function () {
  90. $scope.hideLoadingToast();
  91. $scope.$broadcast('scroll.refreshComplete');
  92. });
  93. };
  94. //搜索资源
  95. var searchResource = function (key) {
  96. $scope.showbaidu = false;
  97. $scope.showLoadingToast();
  98. ResourceLibraryService.getFirstResourceList(reclibid, checked, "", "", key, reclibid, 0).then(function (response) {
  99. $scope.resourcelist = angular.fromJson(response.resourcelibrary);
  100. // console.log($scope.resourcelist);
  101. var temppage = angular.fromJson(response.page);
  102. var totalPage = Math.ceil(temppage.totalCount / 10);
  103. if ($scope.hasmore[1].currentPage >= totalPage) {
  104. $scope.hasmore[1].isload = false;
  105. } else {
  106. $scope.hasmore[1].isload = true;
  107. }
  108. $scope.hasmore[1].currentPage = 2;
  109. $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0);
  110. }, function () {
  111. UtilService.showMess("网络不给力,请重试");
  112. }).finally(function () {
  113. $scope.hideLoadingToast();
  114. $scope.$broadcast('scroll.refreshComplete');
  115. });
  116. };
  117. //加载更多资源
  118. var searchMoreResource = function (key) {
  119. $scope.showbaidu = false;
  120. $scope.showLoadingToast();
  121. ResourceLibraryService.getSecondResourceList(reclibid, checked, "", "", key, $scope.hasmore[1].currentPage, reclibid, 0).then(function (response) {
  122. var tempreslib = angular.fromJson(response.resourcelibrary);
  123. //加载数据,更新当前页数
  124. if (tempreslib.length > 0) {
  125. $scope.resourcelist = $scope.resourcelist.concat(tempreslib);
  126. }
  127. // console.log($scope.resourcelist);
  128. var temppage = angular.fromJson(response.page);
  129. var totalPage = Math.ceil(temppage.totalCount / 10);
  130. if ($scope.hasmore[1].currentPage >= totalPage) {
  131. $scope.hasmore[1].isload = false;
  132. } else {
  133. $scope.hasmore[1].isload = true;
  134. }
  135. $scope.hasmore[1].currentPage++;
  136. }, function () {
  137. UtilService.showMess("网络不给力,请重试");
  138. }).finally(function () {
  139. $scope.hideLoadingToast();
  140. $scope.$broadcast('scroll.infiniteScrollComplete');
  141. });
  142. };
  143. $scope.ttt = function (temptitle) {
  144. return $sce.trustAsHtml(temptitle)
  145. };
  146. //搜索用户
  147. var searchUser = function (key) {
  148. $scope.showbaidu = false;
  149. //加载动画Loading
  150. $scope.showLoadingToast();
  151. SearchResultService.searchUser(key).then(function (response) {
  152. // console.log(response);
  153. if (response.length == 0) {
  154. UtilService.showMess("未搜索到相关用户");
  155. }
  156. $scope.usersList = response;
  157. $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0);
  158. }, function () {
  159. UtilService.showMess("网络不给力,请重试");
  160. }).finally(function () {
  161. $scope.hideLoadingToast();
  162. $scope.$broadcast('scroll.refreshComplete');
  163. });
  164. };
  165. var selectComment = function (key) {
  166. $scope.showbaidu = false;
  167. $scope.showLoadingToast();
  168. ResourceLibraryService.selectComment(key, infoid, infotype).then(function (response) {
  169. // console.log(response);
  170. if (response.length == 0) {
  171. UtilService.showMess("未搜索到相关评论信息");
  172. }
  173. $scope.commentlist = response.res.comment;
  174. $scope.hideLoadingToast();
  175. }, function () {
  176. UtilService.showMess("网络不给力,请重试");
  177. }).finally(function () {
  178. $scope.hideLoadingToast();
  179. $scope.$broadcast('scroll.refreshComplete');
  180. });
  181. };
  182. if (UtilService.isDefined($scope.key)) {
  183. if ($scope.searchtype == 0) {
  184. $scope.searchResultByKey($scope.key);
  185. } else {
  186. selectComment($scope.key);
  187. }
  188. }
  189. $scope.loadMore = function () {
  190. if ($scope.choseTab == 0) {
  191. searchResourceLibary($scope.key);
  192. } else if ($scope.choseTab == 2) {
  193. searchUser($scope.key);
  194. } else {
  195. searchMoreResource($scope.key);
  196. }
  197. };
  198. //关注
  199. $scope.doFocus = function (user, index) {
  200. SearchResultService.doFocus(user.isFocus, user.userId).then(function (response) {
  201. if (response.status) {
  202. $scope.usersList[index].isFocus = user.isFocus == 1 ? 2 : 1;
  203. }
  204. }, function () {
  205. })
  206. };
  207. //评论点赞
  208. $scope.content_zan = function (comment, index) {
  209. CommentService.commentLike(comment.id, infotype).then(function (response) {
  210. // console.log(response);
  211. if (response.favourState == 1) {
  212. $scope.commentlist[index].favourcount++;
  213. $scope.commentlist[index].Like = true;
  214. } else {
  215. $scope.commentlist[index].favourcount--;
  216. $scope.commentlist[index].Like = false;
  217. }
  218. // UtilService.showMess(response.clickStatus);
  219. }, function () {
  220. })
  221. };
  222. //删除自己刚刚发布或者以后的评论
  223. $scope.delectToolDis = function (commentid) {
  224. $scope.showLoadingToast();
  225. CommentService.deleteComment(commentid).then(function () {
  226. UtilService.showMess("删除成功");
  227. $scope.searchResultByKey($scope.key);
  228. $scope.hideLoadingToast();
  229. }, function () {
  230. $scope.hideLoadingToast();
  231. });
  232. };
  233. //进入资源库详情
  234. $scope.goResorceLibaryDetail = function (reclib) {
  235. if (reclib.fixtype == 1) {
  236. $ionicHistory.clearCache(['publicResource']);
  237. $scope.go('publicResource', {reclibid: reclib.id, libtype: reclib.moduleid, name: reclib.name});
  238. } else {
  239. $scope.go('privateResource', {reclibid: reclib.id});
  240. }
  241. };
  242. //进入资源详情
  243. $scope.goResourceDetail = function (resource) {
  244. if (resource.groupid == "0") {
  245. $scope.go('resourceDetails', {
  246. recourceid: resource.unique,
  247. recourcetype: resource.type,
  248. recourcecomefrom: resource.source
  249. });
  250. } else {
  251. $scope.go('resourcePrivateDetails', {
  252. recourceid: resource.unique,
  253. recourcetype: resource.type,
  254. recourcecomefrom: resource.source,
  255. creator: resource.clickthrough
  256. });
  257. }
  258. };
  259. $scope.goCommentDetail = function (comment) {
  260. $scope.go('resourceCommentReply', {
  261. comment: angular.toJson(comment),
  262. infoid: infoid,
  263. infotype: infotype,
  264. recourcecomefrom: comment.source,
  265. isedit: $scope.isedit
  266. });
  267. };
  268. $scope.gobackback = function () {
  269. $timeout(function () {
  270. $scope.goback();
  271. }, 350)
  272. };
  273. //清空搜索内容
  274. $scope.clearSearch = function () {
  275. $scope.key = "";
  276. };
  277. $scope.showFunc = function () {
  278. $scope.showbaidu = true;
  279. };
  280. //监测key变化,即时匹配词库
  281. $scope.fixKey = function () {
  282. if (angular.isDefined($scope.key) && $scope.key.length > 0) {
  283. $scope.searchKey($scope.key);
  284. }
  285. };
  286. $scope.data = [];
  287. //百度词库
  288. $scope.searchKey = function (searchName) {
  289. var search_history = angular.element(document.getElementById("his_search"));
  290. if (search_history.val().length != 0) {
  291. var baidu = angular.element(document.getElementById("baidu_search"));
  292. baidu.css("display", "block");
  293. }
  294. $http({
  295. method: 'JSONP',
  296. url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + searchName + '&cb=JSON_CALLBACK'
  297. }).success(function (data) {
  298. $scope.data = data.s;
  299. });
  300. };
  301. });