detailsCtrl.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. angular.module('push')
  2. .controller('DetailsCtrl', function ($scope, $stateParams, $timeout, $ionicPopover, $ionicHistory, $ionicActionSheet, DetailsService, ShareService, ConfigService, UtilService, SearchResultService, $ionicScrollDelegate) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. //参数初始化
  7. var id = $scope.id = $stateParams.id;
  8. var type = $stateParams.type;
  9. var title = $scope.title = $stateParams.title;
  10. var siteName = $scope.siteName = $stateParams.siteName;
  11. var time = $scope.time = $stateParams.time;
  12. var url = $stateParams.url;
  13. var moduleId = $scope.moduleId = $stateParams.moduleId;
  14. var content = $scope.content = $stateParams.content;
  15. $scope.creatorId = $stateParams.creatorId;
  16. //提交的评论
  17. $scope.comment = {say: ""};
  18. $scope.showbutton = true;
  19. if (ConfigService.islogin) {
  20. //判断是否点赞收藏
  21. DetailsService.checkStatus(id, moduleId).then(function (response) {
  22. $scope.detailstatus = response;
  23. if (angular.isUndefined($scope.detailstatus.total)) {
  24. $scope.detailstatus.total = 0;
  25. }
  26. }, function () {
  27. });
  28. //当有用户ID是判断是否关注
  29. if (UtilService.isDefined($stateParams.creatorId) && $stateParams.creatorId != 0) {
  30. $scope.tofocus = true;
  31. DetailsService.isFocusOn($stateParams.creatorId).then(function (response) {
  32. $scope.isfocus = response.status;
  33. }, function () {
  34. });
  35. }
  36. }
  37. //进详情记录访问痕迹(infoid问题暂时先影藏)
  38. DetailsService.trackLog(id, moduleId, url).then(function () {
  39. }, function () {
  40. });
  41. /*alert(id);*/
  42. //进详情加载评论列表
  43. DetailsService.commentList(id, moduleId).then(function (response) {
  44. $scope.comments = response.res.comment;
  45. }, function () {
  46. });
  47. // 关注
  48. $scope.attention = function () {
  49. if (!ConfigService.islogin) {
  50. UtilService.showMess("请登录");
  51. return;
  52. }
  53. SearchResultService.doFocus(2, $stateParams.creatorId).then(function (response) {
  54. if (response.status == true) {
  55. $scope.isfocus = true;
  56. UtilService.showMess("关注成功");
  57. } else {
  58. UtilService.showMess("网络不给力,请重试");
  59. }
  60. }, function () {
  61. UtilService.showMess("网络不给力,请重试");
  62. });
  63. };
  64. // 点赞评论
  65. $scope.content_zan = function (discuss) {
  66. var like_pus = angular.element(document.getElementById("like_discuss" + discuss.id));
  67. like_pus.addClass("zan_discuss");
  68. var w_discuss = angular.element(document.getElementsByClassName("content-zan" + discuss.id));
  69. w_discuss.addClass("w_zan");
  70. };
  71. //详情页评论
  72. $scope.appComment = function () {
  73. $scope.showComment = true;
  74. var islogin = ConfigService.islogin;
  75. if (!islogin) {
  76. UtilService.showMess("请登录");
  77. } else {
  78. /* alert(id);
  79. alert(moduleId);*/
  80. var content = $scope.comment.say;
  81. /*alert(content);*/
  82. //提交评论信息
  83. $scope.showLoadingToast();
  84. DetailsService.appComment(id, moduleId, content, siteName).then(function () {
  85. //评论成功后重新获取评论列表
  86. DetailsService.commentList(id, moduleId).then(function (response) {
  87. $scope.comments = response.res.comment;
  88. }, function () {
  89. }).finally(function () {
  90. $scope.hideLoadingToast();
  91. });
  92. //重置评论内容为空
  93. $scope.comment.say = "";
  94. }, function () {
  95. });
  96. }
  97. };
  98. //点赞
  99. $scope.clickFavour = function () {
  100. if (!ConfigService.islogin) {
  101. UtilService.showMess("请登录");
  102. return;
  103. }
  104. if ($scope.detailstatus.favourState == 1) {
  105. return;
  106. }
  107. $scope.showLoadingToast();
  108. DetailsService.clickFavour(siteName, url, id, moduleId).then(function (response) {
  109. if (response.status == true) {
  110. $scope.detailstatus.favourState = 1;
  111. $scope.detailstatus.total++;
  112. } else {
  113. UtilService.showMess("网络不给力,请重试");
  114. }
  115. }, function () {
  116. UtilService.showMess("网络不给力,请重试");
  117. }).finally(function () {
  118. $scope.hideLoadingToast();
  119. });
  120. };
  121. //收藏
  122. $scope.favorite = function () {
  123. if (!ConfigService.islogin) {
  124. UtilService.showMess("请登录");
  125. return;
  126. }
  127. $scope.showLoadingToast();
  128. DetailsService.store(siteName, url, id, moduleId, 0).then(function (response) {
  129. if (response.status == true) {
  130. if (response.clickStatus == "收藏成功") {
  131. UtilService.showMess("收藏成功");
  132. $scope.detailstatus.storeState = 1;
  133. } else {
  134. $scope.detailstatus.storeState = 0;
  135. UtilService.showMess("取消收藏");
  136. }
  137. } else {
  138. UtilService.showMess("网络不给力,请重试");
  139. }
  140. }, function () {
  141. UtilService.showMess("网络不给力,请重试");
  142. }).finally(function () {
  143. $scope.hideLoadingToast();
  144. });
  145. };
  146. //点击抢沙发
  147. $scope.hadSoft = function () {
  148. $scope.showComment = false;
  149. $(".my_comment").focus();
  150. };
  151. $scope.showComment = true;
  152. $scope.focus_write = function () {
  153. scrollToBottom();//滚动至底部
  154. $scope.showComment = false;
  155. $(".my_comment").focus();
  156. };
  157. $scope.hiddenComment = function () {
  158. $scope.showComment = true;
  159. };
  160. //弹出评论框
  161. $scope.commentValue = function () {
  162. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  163. if ($scope.comment.say.length > 1000) {
  164. UtilService.showMess("您的评论已超过1000字!");
  165. $scope.comment.say = $scope.comment.say.substr(0, 1000);
  166. }
  167. if (search_history.val.length != 0) {
  168. $scope.commentNotnull = {
  169. "background-color": "#2a90d7",
  170. "text-decoration": "underline"
  171. };
  172. }
  173. };
  174. //发表底色判断
  175. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  176. if (search_history.val.length != 0) {
  177. $scope.commentNotnull = {
  178. "background-color": "#cacaca"
  179. };
  180. }
  181. //跳转到评论详情页comment
  182. $scope.goComment = function (comment) {
  183. $scope.go("Reply", {Comment: comment, infoType: moduleId, infoId: id})
  184. };
  185. $scope.goPublisher = function () {
  186. if ($scope.creatorId != 0) {
  187. $scope.go('publisher', {Id: $scope.creatorId});
  188. }
  189. };
  190. $scope.hastask = false;//控制标题栏内容是否显示
  191. $scope.getScrollPosition = function () {
  192. var position = $ionicScrollDelegate.getScrollPosition().top;//取这个ion-content滑动TOP值
  193. var domScroll = $("#dash_scroll_container").offset().top;//距离页面顶部的距离
  194. if (position <= domScroll) {
  195. $scope.hastask = false;
  196. } else if (position <= 200) {
  197. $scope.hastask = true;
  198. } else {
  199. $scope.hastask = true;
  200. }
  201. $scope.$apply();//触发用以更新view
  202. };
  203. $timeout(function () {
  204. try {
  205. $('.my_comment').focus();
  206. } catch (e) {
  207. }
  208. }, 200);
  209. //进入评论列表页
  210. $scope.goCommentList = function () {
  211. $timeout(function () {
  212. $scope.go('comment', {infoId: id, infoType: moduleId, siteName: siteName});
  213. }, 350);
  214. };
  215. //分享
  216. $scope.shareflg = false;
  217. $scope.openShare = function () {
  218. $scope.shareflg = true;
  219. };
  220. $scope.closeShare = function () {
  221. $scope.shareflg = false;
  222. };
  223. //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博
  224. $scope.shareMessage = function (type) {
  225. $scope.shareflg = false;
  226. $scope.showLoadingToast();
  227. var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg";
  228. var message = {
  229. title: $scope.resource.title,
  230. description: $scope.resource.title.substring(0,19),
  231. url: sharelink,
  232. imageurl: imagurl
  233. };
  234. switch (type) {
  235. case 0:
  236. case 1:
  237. ShareService.shareToQQ(type, message).then(function () {
  238. UtilService.showMess("QQ分享成功");
  239. $scope.hideLoadingToast();
  240. }, function (error) {
  241. UtilService.showMess(error);
  242. $scope.hideLoadingToast();
  243. });
  244. break;
  245. case 2:
  246. case 3:
  247. ShareService.shareToWechat(0, message).then(function () {
  248. UtilService.showMess("微信分享成功");
  249. $scope.hideLoadingToast();
  250. }, function (error) {
  251. UtilService.showMess(error);
  252. $scope.hideLoadingToast();
  253. });
  254. break;
  255. case 4:
  256. ShareService.shareToWeibo(message).then(function () {
  257. UtilService.showMess("新浪微博分享成功");
  258. $scope.hideLoadingToast();
  259. }, function (error) {
  260. UtilService.showMess(error);
  261. $scope.hideLoadingToast();
  262. });
  263. break;
  264. default:
  265. break;
  266. }
  267. $timeout(function () {
  268. $scope.hideLoadingToast();
  269. }, 10000);
  270. };
  271. // 滚动至底部
  272. var scrollToBottom = function () {
  273. $timeout(function () {
  274. $ionicScrollDelegate.$getByHandle("detailSimpleContent").scrollBottom();
  275. }, 0);
  276. };
  277. });