angular.module('push') .controller('resourceSearchResultCtrl', function ($scope, $state, $timeout, $ionicTabsDelegate, $stateParams, $http, UtilService, $ionicScrollDelegate, ResourceLibraryService, SearchResultService, $ionicHistory, $sce, CommentService, UserService) { $scope.key = $stateParams.key; $scope.searchtype = $stateParams.searchtype; var infoid = $stateParams.infoid; var infotype = $stateParams.infotype; var reclibid = $stateParams.reclibid; $scope.isedit = $stateParams.isedit; $scope.choseTab = $stateParams.tabindex; $scope.oldtabindex = angular.copy($stateParams.tabindex); $scope.userid = UserService.id; $scope.showbaidu = false; var libtype = 1001; if ($scope.choseTab == 4) { libtype = 1; } else if ($scope.choseTab == 3) { libtype = 2; } else if ($scope.choseTab == 5) { libtype = 6; } else if ($scope.choseTab == 6) { libtype = 8; } var checked = { SortType: 0, classificationType: libtype, starType: 0, MaturityType: 0, RightType: 0, ModelType: 0, BudgetType: 0, ScaleType: 0, EnterpriseType: 0, DegreeType: 0, sexType: 0, TitleType: 0, UniversityType: 0 }; $scope.hasmore = [{currentPage: 1, isload: false}, {currentPage: 1, isload: false}, { currentPage: 1, isload: false }]; $scope.changeAct = function (index) { $scope.choseTab = index; if ($scope.choseTab == 4) { checked.classificationType = 1; } else if ($scope.choseTab == 3) { checked.classificationType = 2; } else if ($scope.choseTab == 5) { checked.classificationType = 6; } else if ($scope.choseTab == 6) { checked.classificationType = 8; } else { checked.classificationType = 1001; } $scope.searchResultByKey($scope.key); }; //根据关键字搜索综合、用户信息 $scope.searchResultByKey = function (key) { if (!UtilService.isDefined(key)) { return; } if ($scope.searchtype == 0) { if ($scope.choseTab == 0) { searchResourceLibary(key); } else if ($scope.choseTab == 2) { searchUser(key); } else { searchResource(key); } } else { selectComment($scope.key); } }; //搜索资源库 var searchResourceLibary = function (key) { $scope.showbaidu = false; $scope.showLoadingToast(); ResourceLibraryService.getResourceLibrary(key).then(function (response) { // console.log(response); if (response.length == 0) { UtilService.showMess("未搜索到相关信息"); } $scope.resourcelibrarylist = response; $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0); $scope.hideLoadingToast(); }, function () { UtilService.showMess("网络不给力,请重试"); }).finally(function () { $scope.hideLoadingToast(); $scope.$broadcast('scroll.refreshComplete'); }); }; //搜索资源 var searchResource = function (key) { $scope.showbaidu = false; $scope.showLoadingToast(); ResourceLibraryService.getFirstResourceList(reclibid, checked, "", "", key, reclibid, 0).then(function (response) { $scope.resourcelist = angular.fromJson(response.resourcelibrary); // console.log($scope.resourcelist); var temppage = angular.fromJson(response.page); var totalPage = Math.ceil(temppage.totalCount / 10); if ($scope.hasmore[1].currentPage >= totalPage) { $scope.hasmore[1].isload = false; } else { $scope.hasmore[1].isload = true; } $scope.hasmore[1].currentPage = 2; $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0); }, function () { UtilService.showMess("网络不给力,请重试"); }).finally(function () { $scope.hideLoadingToast(); $scope.$broadcast('scroll.refreshComplete'); }); }; //加载更多资源 var searchMoreResource = function (key) { $scope.showbaidu = false; $scope.showLoadingToast(); ResourceLibraryService.getSecondResourceList(reclibid, checked, "", "", key, $scope.hasmore[1].currentPage, reclibid, 0).then(function (response) { var tempreslib = angular.fromJson(response.resourcelibrary); //加载数据,更新当前页数 if (tempreslib.length > 0) { $scope.resourcelist = $scope.resourcelist.concat(tempreslib); } // console.log($scope.resourcelist); var temppage = angular.fromJson(response.page); var totalPage = Math.ceil(temppage.totalCount / 10); if ($scope.hasmore[1].currentPage >= totalPage) { $scope.hasmore[1].isload = false; } else { $scope.hasmore[1].isload = true; } $scope.hasmore[1].currentPage++; }, function () { UtilService.showMess("网络不给力,请重试"); }).finally(function () { $scope.hideLoadingToast(); $scope.$broadcast('scroll.infiniteScrollComplete'); }); }; $scope.ttt = function (temptitle) { return $sce.trustAsHtml(temptitle) }; //搜索用户 var searchUser = function (key) { $scope.showbaidu = false; //加载动画Loading $scope.showLoadingToast(); SearchResultService.searchUser(key).then(function (response) { // console.log(response); if (response.length == 0) { UtilService.showMess("未搜索到相关用户"); } $scope.usersList = response; $ionicScrollDelegate.$getByHandle("resourceSearchContent").scrollTo(0, 0); }, function () { UtilService.showMess("网络不给力,请重试"); }).finally(function () { $scope.hideLoadingToast(); $scope.$broadcast('scroll.refreshComplete'); }); }; var selectComment = function (key) { $scope.showbaidu = false; $scope.showLoadingToast(); ResourceLibraryService.selectComment(key, infoid, infotype).then(function (response) { // console.log(response); if (response.length == 0) { UtilService.showMess("未搜索到相关评论信息"); } $scope.commentlist = response.res.comment; $scope.hideLoadingToast(); }, function () { UtilService.showMess("网络不给力,请重试"); }).finally(function () { $scope.hideLoadingToast(); $scope.$broadcast('scroll.refreshComplete'); }); }; if (UtilService.isDefined($scope.key)) { if ($scope.searchtype == 0) { $scope.searchResultByKey($scope.key); } else { selectComment($scope.key); } } $scope.loadMore = function () { if ($scope.choseTab == 0) { searchResourceLibary($scope.key); } else if ($scope.choseTab == 2) { searchUser($scope.key); } else { searchMoreResource($scope.key); } }; //关注 $scope.doFocus = function (user, index) { SearchResultService.doFocus(user.isFocus, user.userId).then(function (response) { if (response.status) { $scope.usersList[index].isFocus = user.isFocus == 1 ? 2 : 1; } }, function () { }) }; //评论点赞 $scope.content_zan = function (comment, index) { CommentService.commentLike(comment.id, infotype).then(function (response) { // console.log(response); if (response.favourState == 1) { $scope.commentlist[index].favourcount++; $scope.commentlist[index].Like = true; } else { $scope.commentlist[index].favourcount--; $scope.commentlist[index].Like = false; } // UtilService.showMess(response.clickStatus); }, function () { }) }; //删除自己刚刚发布或者以后的评论 $scope.delectToolDis = function (commentid) { $scope.showLoadingToast(); CommentService.deleteComment(commentid).then(function () { UtilService.showMess("删除成功"); $scope.searchResultByKey($scope.key); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; //进入资源库详情 $scope.goResorceLibaryDetail = function (reclib) { if (reclib.fixtype == 1) { $ionicHistory.clearCache(['publicResource']); $scope.go('publicResource', {reclibid: reclib.id, libtype: reclib.moduleid, name: reclib.name}); } else { $scope.go('privateResource', {reclibid: reclib.id}); } }; //进入资源详情 $scope.goResourceDetail = function (resource) { if (resource.groupid == "0") { $scope.go('resourceDetails', { recourceid: resource.unique, recourcetype: resource.type, recourcecomefrom: resource.source }); } else { $scope.go('resourcePrivateDetails', { recourceid: resource.unique, recourcetype: resource.type, recourcecomefrom: resource.source, creator: resource.clickthrough }); } }; $scope.goCommentDetail = function (comment) { $scope.go('resourceCommentReply', { comment: angular.toJson(comment), infoid: infoid, infotype: infotype, recourcecomefrom: comment.source, isedit: $scope.isedit }); }; $scope.gobackback = function () { $timeout(function () { $scope.goback(); }, 350) }; //清空搜索内容 $scope.clearSearch = function () { $scope.key = ""; }; $scope.showFunc = function () { $scope.showbaidu = true; }; //监测key变化,即时匹配词库 $scope.fixKey = function () { if (angular.isDefined($scope.key) && $scope.key.length > 0) { $scope.searchKey($scope.key); } }; $scope.data = []; //百度词库 $scope.searchKey = function (searchName) { var search_history = angular.element(document.getElementById("his_search")); if (search_history.val().length != 0) { var baidu = angular.element(document.getElementById("baidu_search")); baidu.css("display", "block"); } $http({ method: 'JSONP', url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + searchName + '&cb=JSON_CALLBACK' }).success(function (data) { $scope.data = data.s; }); }; });