resourceMatchSearch.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. angular.module('push')
  2. .controller('resourceMatchSearchCtrl', function ($scope, $state, $timeout, $ionicTabsDelegate, $stateParams, $http, UtilService, $ionicScrollDelegate,
  3. ResourceLibraryService, SearchResultService, $ionicHistory, $sce, CommentService, UserService) {
  4. var type = $stateParams.type;
  5. var title = $stateParams.title;
  6. var categorylabel = $stateParams.categorylabel;
  7. $scope.userid = UserService.id;
  8. $scope.key = "";
  9. $scope.showbaidu = false;
  10. $scope.isload = false;
  11. var currentPage = 1;
  12. //获取相关资源
  13. $scope.getRelativeResource = function (key) {
  14. $scope.showLoadingToast();
  15. CommentService.getRelativeResource(type, title, categorylabel, key, $stateParams.unique, $stateParams.recordid).then(function (response) {
  16. // console.log(response);
  17. $scope.relativelist = response.resourcelibrary;
  18. $timeout(function () {
  19. if (currentPage >= response.page.totalPage) {
  20. $scope.isload = false;
  21. } else {
  22. $scope.isload = true;
  23. }
  24. currentPage = 2;
  25. }, 1000);
  26. $scope.hideLoadingToast();
  27. }, function () {
  28. $scope.hideLoadingToast();
  29. }).finally(function () {
  30. $scope.$broadcast('scroll.refreshComplete');
  31. });
  32. };
  33. //加载更多资源列表
  34. $scope.loadMore = function () {
  35. $scope.isload = false;
  36. $scope.showLoadingToast();
  37. CommentService.loadMoreRelativeResource(type, title, categorylabel, $scope.key, currentPage, $stateParams.unique, $stateParams.recordid).then(function (response) {
  38. // console.log(response);
  39. if (response.resourcelibrary.length > 0) {
  40. currentPage++;
  41. $scope.relativelist = $scope.relativelist.concat(response.resourcelibrary);
  42. }
  43. //判断是否有下一页
  44. $timeout(function () {
  45. if (currentPage >= response.page.totalPage) {
  46. $scope.isload = false;
  47. } else {
  48. $scope.isload = true;
  49. }
  50. }, 1000);
  51. $scope.hideLoadingToast();
  52. }, function () {
  53. $scope.hideLoadingToast();
  54. }).finally(function () {
  55. $scope.$broadcast('scroll.infiniteScrollComplete');
  56. });
  57. };
  58. //进入资源详情
  59. $scope.goResourceDetail = function (resource) {
  60. if (resource.type == 81) {
  61. $scope.go('cloudDockingdetail', {infoid: resource.id, creator: resource.creator});
  62. } else {
  63. if(resource.groupid == "0"){
  64. $scope.go('resourceDetails', {
  65. recourceid: resource.unique,
  66. recourcetype: resource.type,
  67. recourcecomefrom: resource.source
  68. });
  69. }else {
  70. $scope.go('resourcePrivateDetails', {
  71. recourceid: resource.unique,
  72. recourcetype: resource.type,
  73. recourcecomefrom: resource.source,
  74. creator: resource.clickthrough
  75. });
  76. }
  77. }
  78. };
  79. $scope.gobackback = function () {
  80. $timeout(function () {
  81. $scope.goback();
  82. }, 350)
  83. };
  84. $scope.ttt = function (temptitle) {
  85. return $sce.trustAsHtml(temptitle)
  86. };
  87. //清空搜索内容
  88. $scope.clearSearch = function () {
  89. $scope.key = "";
  90. };
  91. $scope.showFunc = function () {
  92. $scope.showbaidu = true;
  93. };
  94. //监测key变化,即时匹配词库
  95. $scope.fixKey = function () {
  96. if (angular.isDefined($scope.key) && $scope.key.length > 0) {
  97. $scope.searchKey($scope.key);
  98. }
  99. };
  100. $scope.data = [];
  101. //百度词库
  102. $scope.searchKey = function (searchName) {
  103. var search_history = angular.element(document.getElementById("his_search"));
  104. if (search_history.val().length != 0) {
  105. var baidu = angular.element(document.getElementById("baidu_search"));
  106. baidu.css("display", "block");
  107. }
  108. $http({
  109. method: 'JSONP',
  110. url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + searchName + '&cb=JSON_CALLBACK'
  111. }).success(function (data) {
  112. $scope.data = data.s;
  113. });
  114. };
  115. });