123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- angular.module('push')
- .controller('SearchResultCtrl', function ($scope, $state, $timeout, $ionicTabsDelegate, $stateParams, SearchResultService, $http, UtilService) {
- $scope.key = $stateParams.key;
- $scope.showbaidu = false;
- //综合、用户
- $scope.act = $stateParams.actype;
- $scope.changeAct = function () {
- $scope.act = !$scope.act;
- $scope.searchResultByKey($scope.key);
- };
- //取本地存储已选择的频道信息
- var channellist = JSON.parse(localStorage.getItem("mychannel"));
- //搜索结果频道与本地已选择频道匹配
- var checkIsAddChannel = function (channel) {
- $scope.channellist = [];
- angular.forEach(channel, function (data, index) {
- angular.forEach(channellist, function (value, key) {
- if (value.title == data.title) {
- channel[index].isadd = true;
- }
- });
- });
- $scope.channellist = channel;
- };
- //根据关键字搜索综合、用户信息
- $scope.searchResultByKey = function (key) {
- if(!UtilService.isDefined(key)){
- return;
- }
- if ($scope.act) {
- searchKey(key);
- } else {
- searchUser(key);
- }
- };
- var searchKey = function (key) {
- $scope.showbaidu = false;
- //加载动画Loading
- $scope.showLoadingToast();
- SearchResultService.searchResult(key).then(function (response) {
- if (response.tngou.length == 0) {
- UtilService.showMess("未搜索到相关信息");
- }
- $scope.items = response.tngou;
- //返回结果中有频道信息,则与本地匹配
- if (angular.isDefined(response.channel)) {
- checkIsAddChannel(response.channel)
- }
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- })
- };
- if ($scope.act) {
- $scope.searchResultByKey($scope.key);
- }
- 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;
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- })
- };
- //添加频道至本地
- $scope.addSearchChannel = function (item, index) {
- channellist.push(item);
- $scope.channellist[index].isadd = true;
- localStorage.setItem("mychannel", JSON.stringify(channellist));
- };
- //关注
- $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.goDetails = function (item) {
- var module = item.moduleId;
- var id = "";
- var url = "";
- if (module == 9 || module == 10 || module == 100) {
- url = item.siteUrl;
- id = item.id;
- } else {
- id = item.infoId;
- }
- $scope.go('detail', {
- url: url,
- creatorId: item.creator,
- id: id,
- title: item.title,
- siteName: item.siteName,
- time: item.time,
- content: item.content,
- moduleId: item.moduleId,
- favourCount: item.favourCount
- });
- };
- //清空搜索内容
- $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;
- });
- };
- });
|