123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- angular.module('push')
- .controller('scienceCircleHomeCtrl', function ($scope, $timeout, IMChatService, IMChatTempData, $rootScope, $ionicPopup, ScienceCircleService,ConfigService,UserService) {
- //TODO
- document.title='科技圈';
- if (UserService.defaultLan == 'English') {
- document.title = 'Technology Circle';
- }
- if($scope.app){
- $scope.setStatusBar(1);
- }
- $scope.comfromWeb=sessionStorage.comfrom=='web';
- //加载等待页
- $scope.isloadingPageFloor=false;
- //加载失败页
- $scope.isloadingPageFail=false;
- $scope.defaultLan = UserService.defaultLan;
- //进入获取数据
- $scope.$on('$ionicView.beforeEnter', function () {
- console.log("$ionicView.beforeEnter");
- });
- $scope.islogin = ConfigService.islogin;
- $scope.goLogin = function () {
- if (localStorage.wxFlag == "true") {
- if (localStorage.isUserFocusXW == 0) {
- var title = localStorage.appidStr;
- $ionicPopup.alert({
- title: '提示',
- template: '请先关注微信公众号"' + title + '"!'
- });
- } 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');
- }
- } else {
- $scope.go('login');
- }
- }
- } else {
- $scope.go('login');
- }
- };
- // if(!$scope.islogin){
- // if (localStorage.wxFlag == "true") {
- // if (localStorage.isUserFocusXW == 0) {
- // var title = localStorage.appidStr;
- // $ionicPopup.alert({
- // title: '提示',
- // template: '请先关注微信公众号"' + title + '"!'
- // });
- // } 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');
- // }
- // } else {
- // $scope.go('login');
- // }
- // }
- // } else {
- // $scope.go('login');
- // }
- // }
- $scope.keyfilter = {key: ""};
- $scope.tabflg = 0;// 0 聊天,1 通讯录,2 动态
- $scope.changeTab = function (flg) {
- $scope.tabflg = flg;
- };
- // 本页面所有消息提示初始化
- $rootScope.msgBadge = "";//底部Tab页签新消息标志
- $scope.dynamicmsgflg = false;//动态新消息标志
- $scope.chatmsgflg = false;//聊天新消息标志
- $scope.contactmsgflg = false;//通讯录新消息标志
- //获取会话列表
- var getConversationList = function () {
- $scope.isloadingPageFloor=true;
- ScienceCircleService.getConversationList().then(function (response) {
- console.log(response);
- $scope.conversationList = response;
- $scope.isloadingPageFloor=false;
- $scope.isloadingPageFail=false;
- if (angular.isDefined(response) && response.length > 0) {
- handleNewMessage(1, []);
- }
- }, function () {
- $scope.isloadingPageFloor=false;
- $scope.isloadingPageFail=true;
- })
- };
- getConversationList();
- $scope.repeatLoad = function () {
- $scope.isloadingPageFail=false;
- getConversationList();
- };
- $scope.doRefresh = function () {
- getConversationList();
- $scope.$broadcast('scroll.refreshComplete');
- };
- // 处理新消息 1:第一次加载处理,2:接收到新消息处理
- var handleNewMessage = function (flg, data) {
- if (flg == 1) {
- angular.forEach($scope.conversationList, function (value, index) {
- angular.forEach(IMChatTempData.msgdata, function (val, ind) {
- if (value.topicname == val.topic) {
- value.msgcount = val.msglist.length;
- var len = val.msglist.length - 1;
- value.messagelist[0] = val.msglist[len];
- }
- });
- })
- }
- if (flg == 2) {
- var topicindex = -1;
- angular.forEach($scope.conversationList, function (value, index) {
- if (value.topicname == data.topicname) {
- value.msgcount = angular.isDefined(value.msgcount) ? ++value.msgcount : 1;
- value.messagelist[0] = data;
- topicindex = index;
- }
- });
- // 当接收到的新消息 不在会话列表 则重新刷新会话列表
- if (topicindex == -1) {
- getConversationList();
- }
- }
- };
- //进入个人聊天页面
- $scope.goSingleModel = function (con) {
- IMChatTempData.clearMsgDataByTopic(con.topicname);
- $scope.go('singleChatMode', {
- "topicid": con.topicid,
- "topicname": con.topicname,
- "username": con.userModel.username,
- "reciverid": con.reciverid,
- "isfocus": con.isfocus
- });
- };
- //科技圈搜索
- $scope.goResourceSearch = function () {
- $timeout(function () {
- $scope.go('resourceSearch');
- }, 350);
- };
- //顶部添加
- $scope.chatAddFlag = false;
- $scope.goShow = function () {
- if(!$scope.islogin){
- if (localStorage.wxFlag == "true") {
- if (localStorage.isUserFocusXW == 0) {
- var title = localStorage.appidStr;
- $ionicPopup.alert({
- title: '提示',
- template: '请先关注微信公众号"' + title + '"!'
- });
- } 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');
- }
- } else {
- $scope.go('login');
- }
- }
- } else {
- $scope.go('login');
- }
- }else {
- $timeout(function () {
- $scope.chatAddFlag = true;
- $(".tab_hide").show();
- }, 100);
- }
- };
- $scope.notGOShow = function () {
- $scope.chatAddFlag = false;
- $(".tab_hide").hide();
- };
- //进入通讯录
- $scope.goChatMailList = function () {
- if(!$scope.islogin){
- if (localStorage.wxFlag == "true") {
- if (localStorage.isUserFocusXW == 0) {
- var title = localStorage.appidStr;
- $ionicPopup.alert({
- title: '提示',
- template: '请先关注微信公众号"' + title + '"!'
- });
- } 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');
- }
- } else {
- $scope.go('login');
- }
- }
- } else {
- $scope.go('login');
- }
- }else {
- $scope.go('chatMailList');
- }
- };
- //接收新信息
- $scope.$on("recMessagePrompt", function (event, data) {
- console.log(data);
- handleNewMessage(2, data)
- });
- // 通讯录搜索
- $scope.goSearchChatMail = function () {
- $scope.go('chatSearchModel');
- };
- // 添加好友
- $scope.addChatFriends = function () {
- $scope.go('addChatFriends');
- };
- //虚拟搜索框
- $scope.isShowSearchButton = true;
- $scope.showSearchButtonLeft = function () {
- $scope.isShowSearchButton = false;
- // $(".showSearchInput").focus();
- $timeout(function(){
- $(".showSearchInput").focus();
- },300)
- };
- //清空搜索内容
- $scope.clearSearch = function () {
- $scope.isShowSearchButton = true;
- $scope.keyfilter.key = "";
- };
- });
|