123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- angular.module('push')
- .controller('DetailsCtrl', function ($scope, $stateParams, $timeout, $ionicPopover, $ionicHistory, $ionicActionSheet, DetailsService, ShareService, ConfigService, UtilService, SearchResultService, $ionicScrollDelegate) {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- //参数初始化
- var id = $scope.id = $stateParams.id;
- var type = $stateParams.type;
- var title = $scope.title = $stateParams.title;
- var siteName = $scope.siteName = $stateParams.siteName;
- var time = $scope.time = $stateParams.time;
- var url = $stateParams.url;
- var moduleId = $scope.moduleId = $stateParams.moduleId;
- var content = $scope.content = $stateParams.content;
- $scope.creatorId = $stateParams.creatorId;
- //提交的评论
- $scope.comment = {say: ""};
- $scope.showbutton = true;
- if (ConfigService.islogin) {
- //判断是否点赞收藏
- DetailsService.checkStatus(id, moduleId).then(function (response) {
- $scope.detailstatus = response;
- if (angular.isUndefined($scope.detailstatus.total)) {
- $scope.detailstatus.total = 0;
- }
- }, function () {
- });
- //当有用户ID是判断是否关注
- if (UtilService.isDefined($stateParams.creatorId) && $stateParams.creatorId != 0) {
- $scope.tofocus = true;
- DetailsService.isFocusOn($stateParams.creatorId).then(function (response) {
- $scope.isfocus = response.status;
- }, function () {
- });
- }
- }
- //进详情记录访问痕迹(infoid问题暂时先影藏)
- DetailsService.trackLog(id, moduleId, url).then(function () {
- }, function () {
- });
- /*alert(id);*/
- //进详情加载评论列表
- DetailsService.commentList(id, moduleId).then(function (response) {
- $scope.comments = response.res.comment;
- }, function () {
- });
- // 关注
- $scope.attention = function () {
- if (!ConfigService.islogin) {
- UtilService.showMess("请登录");
- return;
- }
- SearchResultService.doFocus(2, $stateParams.creatorId).then(function (response) {
- if (response.status == true) {
- $scope.isfocus = true;
- UtilService.showMess("关注成功");
- } else {
- UtilService.showMess("网络不给力,请重试");
- }
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- });
- };
- // 点赞评论
- $scope.content_zan = function (discuss) {
- var like_pus = angular.element(document.getElementById("like_discuss" + discuss.id));
- like_pus.addClass("zan_discuss");
- var w_discuss = angular.element(document.getElementsByClassName("content-zan" + discuss.id));
- w_discuss.addClass("w_zan");
- };
- //详情页评论
- $scope.appComment = function () {
- $scope.showComment = true;
- var islogin = ConfigService.islogin;
- if (!islogin) {
- UtilService.showMess("请登录");
- } else {
- /* alert(id);
- alert(moduleId);*/
- var content = $scope.comment.say;
- /*alert(content);*/
- //提交评论信息
- $scope.showLoadingToast();
- DetailsService.appComment(id, moduleId, content, siteName).then(function () {
- //评论成功后重新获取评论列表
- DetailsService.commentList(id, moduleId).then(function (response) {
- $scope.comments = response.res.comment;
- }, function () {
- }).finally(function () {
- $scope.hideLoadingToast();
- });
- //重置评论内容为空
- $scope.comment.say = "";
- }, function () {
- });
- }
- };
- //点赞
- $scope.clickFavour = function () {
- if (!ConfigService.islogin) {
- UtilService.showMess("请登录");
- return;
- }
- if ($scope.detailstatus.favourState == 1) {
- return;
- }
- $scope.showLoadingToast();
- DetailsService.clickFavour(siteName, url, id, moduleId).then(function (response) {
- if (response.status == true) {
- $scope.detailstatus.favourState = 1;
- $scope.detailstatus.total++;
- } else {
- UtilService.showMess("网络不给力,请重试");
- }
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- }).finally(function () {
- $scope.hideLoadingToast();
- });
- };
- //收藏
- $scope.favorite = function () {
- if (!ConfigService.islogin) {
- UtilService.showMess("请登录");
- return;
- }
- $scope.showLoadingToast();
- DetailsService.store(siteName, url, id, moduleId, 0).then(function (response) {
- if (response.status == true) {
- if (response.clickStatus == "收藏成功") {
- UtilService.showMess("收藏成功");
- $scope.detailstatus.storeState = 1;
- } else {
- $scope.detailstatus.storeState = 0;
- UtilService.showMess("取消收藏");
- }
- } else {
- UtilService.showMess("网络不给力,请重试");
- }
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- }).finally(function () {
- $scope.hideLoadingToast();
- });
- };
- //点击抢沙发
- $scope.hadSoft = function () {
- $scope.showComment = false;
- $(".my_comment").focus();
- };
- $scope.showComment = true;
- $scope.focus_write = function () {
- scrollToBottom();//滚动至底部
- $scope.showComment = false;
- $(".my_comment").focus();
- };
- $scope.hiddenComment = function () {
- $scope.showComment = true;
- };
- //弹出评论框
- $scope.commentValue = function () {
- var search_history = angular.element(document.getElementsByClassName("my_comment"));
- if ($scope.comment.say.length > 1000) {
- UtilService.showMess("您的评论已超过1000字!");
- $scope.comment.say = $scope.comment.say.substr(0, 1000);
- }
- if (search_history.val.length != 0) {
- $scope.commentNotnull = {
- "background-color": "#2a90d7",
- "text-decoration": "underline"
- };
- }
- };
- //发表底色判断
- var search_history = angular.element(document.getElementsByClassName("my_comment"));
- if (search_history.val.length != 0) {
- $scope.commentNotnull = {
- "background-color": "#cacaca"
- };
- }
- //跳转到评论详情页comment
- $scope.goComment = function (comment) {
- $scope.go("Reply", {Comment: comment, infoType: moduleId, infoId: id})
- };
- $scope.goPublisher = function () {
- if ($scope.creatorId != 0) {
- $scope.go('publisher', {Id: $scope.creatorId});
- }
- };
- $scope.hastask = false;//控制标题栏内容是否显示
- $scope.getScrollPosition = function () {
- var position = $ionicScrollDelegate.getScrollPosition().top;//取这个ion-content滑动TOP值
- var domScroll = $("#dash_scroll_container").offset().top;//距离页面顶部的距离
- if (position <= domScroll) {
- $scope.hastask = false;
- } else if (position <= 200) {
- $scope.hastask = true;
- } else {
- $scope.hastask = true;
- }
- $scope.$apply();//触发用以更新view
- };
- $timeout(function () {
- try {
- $('.my_comment').focus();
- } catch (e) {
- }
- }, 200);
- //进入评论列表页
- $scope.goCommentList = function () {
- $timeout(function () {
- $scope.go('comment', {infoId: id, infoType: moduleId, siteName: siteName});
- }, 350);
- };
- //分享
- $scope.shareflg = false;
- $scope.openShare = function () {
- $scope.shareflg = true;
- };
- $scope.closeShare = function () {
- $scope.shareflg = false;
- };
- //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博
- $scope.shareMessage = function (type) {
- $scope.shareflg = false;
- $scope.showLoadingToast();
- var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg";
- var message = {
- title: $scope.resource.title,
- description: $scope.resource.title.substring(0,19),
- url: sharelink,
- imageurl: imagurl
- };
- switch (type) {
- case 0:
- case 1:
- ShareService.shareToQQ(type, message).then(function () {
- UtilService.showMess("QQ分享成功");
- $scope.hideLoadingToast();
- }, function (error) {
- UtilService.showMess(error);
- $scope.hideLoadingToast();
- });
- break;
- case 2:
- case 3:
- ShareService.shareToWechat(0, message).then(function () {
- UtilService.showMess("微信分享成功");
- $scope.hideLoadingToast();
- }, function (error) {
- UtilService.showMess(error);
- $scope.hideLoadingToast();
- });
- break;
- case 4:
- ShareService.shareToWeibo(message).then(function () {
- UtilService.showMess("新浪微博分享成功");
- $scope.hideLoadingToast();
- }, function (error) {
- UtilService.showMess(error);
- $scope.hideLoadingToast();
- });
- break;
- default:
- break;
- }
- $timeout(function () {
- $scope.hideLoadingToast();
- }, 10000);
- };
- // 滚动至底部
- var scrollToBottom = function () {
- $timeout(function () {
- $ionicScrollDelegate.$getByHandle("detailSimpleContent").scrollBottom();
- }, 0);
- };
- });
|