angular.module('push') .controller('indexSearchReasultCtrl', function ($scope, $state, $timeout, $http, UtilService, ActivityService, $sce, ModelService, $ionicModal, UserService, $ionicActionSheet, ConfigService, ConnSearchService) { $scope.search = {key: ""}; $scope.searchtype = 2;//0全部 1节点 2资源 3资源库 4记录 5文件夹 6活动 7用户 var hiskey = ""; $scope.showSearchWrapFloor=false; $scope.defaultLan = UserService.defaultLan; if ($scope.defaultLan == 'Chinese') { $scope.searchtypeTxt='资源'; } else { $scope.searchtypeTxt='Resource'; } // 数组 index:0 1 2 3 4 依次对应以上(资源开始) var index = 0; $scope.loadind = 0;//是否继续加载的索引 $scope.alllist = [{curpage: 1, list: [], hasmore: false, hiskey: ""}, { curpage: 1, list: [], hasmore: false, hiskey: "" }, {curpage: 1, list: [], hasmore: false, hiskey: ""}, {curpage: 1, list: [], hasmore: false, hiskey: ""}, {curpage: 1, list: [], hasmore: false, hiskey: ""}, {curpage: 1, list: [], hasmore: false, hiskey: ""}, {curpage: 1, list: [], hasmore: false, hiskey: ""}, {curpage: 1, list: [], hasmore: false, hiskey: ""}]; // 综合搜索各种类型信息 $scope.searchAllInfo = function () { if (!UtilService.isDefined($scope.search.key)) { return; } if (index == 3) { searchCloudFolder(); return; } $scope.alllist[index].hiskey = angular.copy($scope.search.key); $scope.showLoadingToast(); $scope.alllist[index].curpage = 1; ActivityService.searchAllInfo($scope.search.key, $scope.searchtype, $scope.alllist[index].curpage).then(function (response) { if (angular.isDefined(response.data)) { $scope.alllist[index].list = response.data.result; } else { $scope.alllist[index].list = []; } if (angular.isDefined(response.data.page) && angular.isDefined(response.data.page.totalPage)) { if ($scope.alllist[index].curpage >= response.data.page.totalPage) { $scope.alllist[index].hasmore = false; } else { $scope.alllist[index].curpage++; $scope.alllist[index].hasmore = true; } } else { $scope.alllist[index].hasmore = false; } $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) }; // 加载更多 $scope.loadMore = function () { $scope.showLoadingToast(); $scope.alllist[index].hasmore = false; ActivityService.searchAllInfo($scope.search.key, $scope.searchtype, $scope.alllist[index].curpage).then(function (response) { if (response.data.result.length > 0) { $scope.alllist[index].list = $scope.alllist[index].list.concat(response.data.result); } $timeout(function () { if (angular.isDefined(response.data.page.totalPage)) { if ($scope.alllist[index].curpage >= response.data.page.totalPage) { $scope.alllist[index].hasmore = false; } else { $scope.alllist[index].curpage++; $scope.alllist[index].hasmore = true; } } }, 1500); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }).finally(function () { $scope.$broadcast('scroll.infiniteScrollComplete'); }); }; $scope.selectSearchTag=function () { $scope.showSearchWrapFloor=!$scope.showSearchWrapFloor; }; // 切换页签 $scope.changeAct = function (type) { $scope.showSearchWrapFloor=false; $scope.searchtype = type; index = type - 2; $scope.loadind = type - 2; if (($scope.search.key.length > 0 && $scope.alllist[index].list.length <= 0) || hiskey != $scope.alllist[index].hiskey) { if (index == 3) { searchCloudFolder(); } else { $scope.searchAllInfo(); } } if ($scope.defaultLan == 'Chinese') { switch (type) { case 2: $scope.searchtypeTxt = '资源'; break; /*case 3: $scope.searchtypeTxt='资源库'; break; case 6: $scope.searchtypeTxt='活动'; break; case 5: $scope.searchtypeTxt='文件夹'; break;*/ case 4: $scope.searchtypeTxt = '记录'; break; case 7: $scope.searchtypeTxt = '用户'; break; } } else { switch (type) { case 2: $scope.searchtypeTxt = 'Resource'; break; case 4: $scope.searchtypeTxt = 'Record'; break; case 7: $scope.searchtypeTxt = 'User'; break; } } }; var searchCloudFolder = function () { $scope.alllist[index].hiskey = angular.copy($scope.search.key); $scope.showLoadingToast(); ConnSearchService.searchCloudFolder($scope.search.key, 0).then(function (response) { $scope.alllist[index].list = response.list; $scope.alllist[index].hasmore = false; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; $scope.goActivityDetail = function (actid) { $scope.go("activityIntroduction", {activityid: actid}); }; //进入分类详情,记录列表 $scope.queryFolder = function (folder) { ModelService.setCheckdeFolder(folder); if (UtilService.isDefined(folder.localid)) { //本地文件夹记录列表 $scope.go('conninfolist', {folder: angular.toJson(folder)}); } else { //云文件夹记录列表 $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)}); } }; //进入记录详情 $scope.goDockingdetails = function (rec) { $scope.islogin = ConfigService.islogin; if(!$scope.islogin){ if (localStorage.wxFlag == "true") { if (localStorage.isUserFocusXW == 0) { var title = localStorage.appidStr; $ionicPopup.alert({ title: '提示', template: '请先关注微信公众号"' + title + '"!' }); return; } else { if (localStorage.isUserBindWx == 0) { var wxFlag = JSON.parse(localStorage.params); if (wxFlag.weChatModel) { $scope.go('bindPhone', { params: localStorage.params, comfrom: 'maincontroller', url: window.location.href.split('#/')[1] }); } else { $scope.go('login'); return; } } else { $scope.go('login'); return; } } } else { $scope.go('login'); return; } }else{ $scope.go('resourceCommonInfoDetailsPage', {resid: rec.id, isAllVisitor: 1,node:UserService.node}); } }; //进入资源库详情 $scope.goResorceLibaryDetail = function (reclib) { reclib.id = reclib.unique; reclib.name = reclib.title; $scope.islogin = ConfigService.islogin; if(!$scope.islogin){ if (localStorage.wxFlag == "true") { if (localStorage.isUserFocusXW == 0) { var title = localStorage.appidStr; $ionicPopup.alert({ title: '提示', template: '请先关注微信公众号"' + title + '"!' }); return; } else { if (localStorage.isUserBindWx == 0) { var wxFlag = JSON.parse(localStorage.params); if (wxFlag.weChatModel) { $scope.go('bindPhone', { params: localStorage.params, comfrom: 'maincontroller', url: window.location.href.split('#/')[1] }); } else { $scope.go('login'); return; } } else { $scope.go('login'); return; } } } else { $scope.go('login'); return; } }else{ $scope.go('resourceLibraryPrivate', {reclib: angular.toJson(reclib)}); } }; //进入资源详情 $scope.goResourceDetail = function (resource) { $scope.islogin = ConfigService.islogin; if(!$scope.islogin){ if (localStorage.wxFlag == "true") { if (localStorage.isUserFocusXW == 0) { var title = localStorage.appidStr; $ionicPopup.alert({ title: '提示', template: '请先关注微信公众号"' + title + '"!' }); return; } else { if (localStorage.isUserBindWx == 0) { var wxFlag = JSON.parse(localStorage.params); if (wxFlag.weChatModel) { $scope.go('bindPhone', { params: localStorage.params, comfrom: 'maincontroller', url: window.location.href.split('#/')[1] }); } else { $scope.go('login'); return; } } else { $scope.go('login'); return; } } } else { $scope.go('login'); return; } }else{ if (resource.groupid == "0") { $scope.go('resourceDetails', { recourceid: resource.unique, recourcetype: resource.type, recourcecomefrom: resource.source }); } else { $scope.go('resourceCommonDetailsPage', { recourceid: resource.unique, recourcetype: resource.type, recourcecomefrom: resource.source, creator: resource.clickthrough, title:resource.title }); } } }; // 搜索关键字标红 $scope.badge = function (title) { var re = eval("/" + $scope.search.key + "/g"); title = title.replace(re, '' + $scope.search.key + ''); return $sce.trustAsHtml(title) }; $scope.gobackback = function () { if($scope.app){ cordova.plugins.Keyboard.close(); } $timeout(function () { $scope.goback(); }, 350); $scope.closeKeyboard(); }; //清空搜索内容 $scope.clearSearch = function () { $scope.search.key = ""; }; $scope.showFunc = function () { $scope.showbaidu = true; }; //监测key变化,即时匹配词库 $scope.fixKey = function () { if (angular.isDefined($scope.search.key) && $scope.search.key.length > 0) { $scope.searchKey($scope.search.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; }); }; $scope.searchInfoByKey = function (d) { $scope.search.key = d; searchAllInfo(); }; /*---------------------------------------------------------------------------*/ var authstatus = 0;// 0 未认证 1 认证 ActivityService.getUserAuth().then(function (response) { authstatus = response.result; }, function () { }); // 活动页面快捷入口路由跳转 $scope.goNextPage = function (index, act) { switch (index) { case 1: // 通知 $scope.go("activityNotice", {activityid: act.id, title: act.title}); break; case 2: // 通知管理 $scope.go("activityNoticeManger", { activityid: act.id, title: act.title, status: act.status, days: act.activityLeaveDays }); break; case 3: // 报名 if (authstatus == 1 || authstatus == 2) { $scope.go("activitySignUpConfirm", {activityid: act.id}); } else { UtilService.showMess("您还未认证!"); $timeout(function () { $scope.go('personIdentify'); }, 1000); } break; case 4: // 高校报名管理 $scope.go("activitySchoolSignUpManger", { activityid: act.id, title: act.title, visittime: act.visitclosingdate }); break; case 5: // 企业报名管理 $scope.go("activityCompanySignUpManger", { activityid: act.id, title: act.title, visittime: act.visitclosingdate }); break; case 6: // 参与企业 if (authstatus == 1 || authstatus == 2) { $scope.go("activityCompanyList", {activityid: act.id}); } else { UtilService.showMess("您还未认证!"); $timeout(function () { $scope.go('personIdentify'); }, 1000); } break; case 7: // 活动统计 $scope.go("activityStatistics", {activityid: act.id}); break; case 8: // 活动安排管理 $scope.go("activityArrangeManger", {activityid: act.id}); break; case 9: // 签到 checkIntime(act.id); break; case 10: // 反馈(1、非企业用户:1.1 未填写过进入填写页面,1.2 已填写过进入列表 2、企业用户:填写本企业的走访反馈列表) if (UserService.role[0] <= 8 && UserService.role[0] != 1) { ActivityService.checkFollowupInfo(act.id).then(function (response) { if (response.result == 0) { $scope.go("activityFeedBack", {activityid: act.id, title: act.title}); } else { $scope.go("activityFeedBackList", {activityid: act.id, title: act.title}); } }, function () { }); } else { $scope.go("activityCompanyViewFeedList", {activityid: act.id}); } break; case 11: // 活动安排 if (UserService.role[0] <= 8 && UserService.role[0] != 1) { $scope.go("activityArrange", {activityid: act.id}); } else { $scope.go("activityCompanyArrange", {activityid: act.id}); } break; case 12: // 反馈管理 $scope.go("activityBackManger", {activityid: act.id}); break; case 13: // 签到管理 $scope.go("activitySignManger", {activityid: act.id}); break; case 14: // 备案 $scope.go("activityRecord"); break; case 15: // 备案管理 $scope.go("activityReacordManger"); break; case 16: // 选择企业 $scope.go("activityChooseCompany", {activityid: act.id}); break; case 17: // 报名信息 $scope.go("activitySignUpInfo", {activityid: act.id}); break; case 18: // 选择专家 $scope.go("activityChooseTeacher", {activityid: act.id}); break; default: break; } }; // 活动是否弹出签到弹窗(否临时人员:弹窗,已报名:直接签到) var activityid = 0; var checkIntime = function (actid) { activityid = actid; $scope.showLoadingToast(); ActivityService.checkIntime(activityid).then(function (response) { if (response.result == 1) { $scope.userinfo = response.userinfo; $scope.categoryModal.show(); $scope.hideLoadingToast(); } else { checkIn(); } }, function () { $scope.hideLoadingToast(); }) }; // 签到 var checkIn = function () { ActivityService.getCheckInStatus(activityid).then(function (response) { // 0未签到,1已签到 if (response.result == 0) { ActivityService.checkIn(activityid, ConfigService.location.lat, ConfigService.location.lng).then(function (response) { if (response.result == 1) { UtilService.showMess("签到成功"); } else { UtilService.showMess("网络不给力,请重试"); } $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }); } else { UtilService.showMess("您已成功签到"); $scope.hideLoadingToast(); } }, function () { UtilService.showMess("网络不给力,请重试"); $scope.hideLoadingToast(); }); }; // 临时人员签到 $scope.tempCheckin = function () { if (!UtilService.isDefined($scope.userinfo.name)) { UtilService.showMess("姓名不能为空"); return; } if (!UtilService.isDefined($scope.userinfo.university)) { UtilService.showMess("所属院校不能为空"); return; } $scope.showLoadingToast(); ActivityService.tempCheckIn(activityid, ConfigService.location.lat, ConfigService.location.lng, $scope.userinfo).then(function (response) { if (response.result == 1) { UtilService.showMess("签到成功"); $timeout(function () { $scope.categoryModal.hide(); }, 300); } else { UtilService.showMess("网络不给力,请重试"); } $scope.hideLoadingToast(); }, function () { UtilService.showMess("网络不给力,请重试"); $scope.hideLoadingToast(); }); }; //关闭报名入口 $scope.closeCategoryModal = function () { $scope.categoryModal.hide(); }; $ionicModal.fromTemplateUrl("templates/modal.html", { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.categoryModal = modal; }); //获取研究领域标签 var buttons = []; var getLabelList = function () { ActivityService.getCategory().then(function (response) { angular.forEach(response, function (value, index) { var temphtml = { text: '' + value.name + '', category: value.name, id: value.id }; buttons.push(temphtml); }); }, function () { }) }; getLabelList(); //选择研究领域 $scope.showDockingStatus = function () { $ionicActionSheet.show({ buttons: buttons, cancelText: '取消', buttonClicked: function (index) { $scope.userinfo.categoryid = buttons[index].id; $scope.userinfo.category = buttons[index].category; return true; } }); }; // 进入个人主页 $scope.goPublisher = function (userid) { $scope.islogin = ConfigService.islogin; if(!$scope.islogin){ if (localStorage.wxFlag == "true") { if (localStorage.isUserFocusXW == 0) { var title = localStorage.appidStr; $ionicPopup.alert({ title: '提示', template: '请先关注微信公众号"' + title + '"!' }); return; } else { if (localStorage.isUserBindWx == 0) { var wxFlag = JSON.parse(localStorage.params); if (wxFlag.weChatModel) { $scope.go('bindPhone', { params: localStorage.params, comfrom: 'maincontroller', url: window.location.href.split('#/')[1] }); } else { $scope.go('login'); return; } } else { $scope.go('login'); return; } } } else { $scope.go('login'); return; } }else{ $scope.go('publisher', {Id: userid}); } }; });