commentCtrl.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. angular.module('push')
  2. .controller('CommentCtrl', function ($scope, $stateParams, ConfigService, UserService , DetailsService, $timeout, $ionicLoading, UtilService, CommentService, ConstantService,CommonService) {
  3. //提交的评论
  4. $scope.comment = {say: ""};
  5. $scope.comment.isCommentZan=false;
  6. // 点赞
  7. $scope.TRACE_TYPE_2615 = ConstantService.TRACE_TYPE_2615;
  8. // 取消点赞
  9. $scope.TRACE_TYPE_2616 = ConstantService.TRACE_TYPE_2616;
  10. // 评论表 info_comment
  11. $scope.TABLE_CODE_30002 = ConstantService.TABLE_CODE_30002;
  12. //拿到之前内页的信息id和type
  13. var moduleId = $scope.moduleId = $stateParams.infotype;
  14. var id = $scope.id = $stateParams.infoid;
  15. // var moduleId = $scope.moduleId = 6;
  16. // var id = $scope.id = 1;
  17. var siteName = "";
  18. // 评论/评论回复的传参
  19. $scope.infoComment=
  20. {
  21. infoid: id,//资源id
  22. infotype:moduleId,// 资源类别
  23. parentid:0,// 评论回复时,记录父评论的id
  24. parentuserid:0,// 评论回复时,记录父评论的创建者
  25. content:"",// 评论/回复内容
  26. //TODO
  27. creator:UserService.id,// 创建者
  28. updater:UserService.id// 更新者
  29. // creator:1,// 创建者
  30. // updater:1// 更新者
  31. };
  32. // 点赞、收藏、分享的传参
  33. $scope.clickRecord=
  34. {
  35. //TODO
  36. targetid: $stateParams.recourceid,
  37. // targetid: 124,
  38. moduleid: ConstantService.TABLE_CODE_30002,
  39. userid:UserService.id,
  40. // userid:1,
  41. clicktype:1
  42. };
  43. // 获取评论列表的传参
  44. $scope.paramsForInfoCommentList=
  45. {
  46. mode: 2,// 显示样式:1热门 2全部
  47. infoid: id,// 资源id
  48. infotype:moduleId,// 资源类型
  49. sortkey:0,// 排序字段
  50. sorttype:"ASC",// 排序方式
  51. moduleid:ConstantService.TABLE_CODE_30002,// 评论表对应的code
  52. //TODO
  53. userid:UserService.id// 登录者id
  54. // userid:1// 登录者id
  55. };
  56. //进详情加载评论列表
  57. var getInfoCommentList = function () {
  58. CommentService.getInfoCommentList($scope.paramsForInfoCommentList).then(function (response) {
  59. console.log(response);
  60. // 评论列表
  61. $scope.comments = response.data;
  62. }, function () {
  63. })
  64. };
  65. getInfoCommentList();
  66. //详情页评论
  67. $scope.appComment = function () {
  68. $scope.showComment = true;
  69. var islogin = ConfigService.islogin;
  70. if (!islogin) {
  71. $ionicLoading.show({
  72. template: '请登录!',
  73. noBackdrop: true
  74. });
  75. $timeout(function () {
  76. $ionicLoading.hide();
  77. }, 1000);
  78. return;
  79. } else {
  80. var content = $scope.comment.say;
  81. //提交评论信息
  82. console.log(content);
  83. DetailsService.appComment(id, moduleId, content, siteName).then(function () {
  84. //评论成功后重新获取评论列表
  85. DetailsService.commentList(id, moduleId).then(function (response) {
  86. $scope.comments = response.res.comment;
  87. }, function () {
  88. });
  89. //重置评论内容为空
  90. $scope.comment.say = "";
  91. }, function () {
  92. });
  93. }
  94. };
  95. // 控制重复点击
  96. var flag = 1;
  97. // 操作:点赞
  98. $scope.commentPraiseAction=function (comment, ind, clicktype, recourceid, moduleid) {
  99. if(flag == 0){
  100. return;
  101. }
  102. flag = 0;
  103. $scope.clickRecord.targetid = recourceid;
  104. $scope.clickRecord.clicktype = clicktype;
  105. $scope.clickRecord.moduleid = moduleid;
  106. CommentService.postClickFavour($scope.clickRecord).then(function (response) {
  107. console.log(response);
  108. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  109. // 点赞
  110. if(clicktype == $scope.TRACE_TYPE_2615) {
  111. if (!comment.favour) {
  112. $scope.comments[ind].favourcount = $scope.comments[ind].favourcount + 1;
  113. $scope.comments[ind].isCommentZan=true;
  114. }
  115. }else
  116. // 取消点赞
  117. if(clicktype == $scope.TRACE_TYPE_2616) {
  118. if (comment.favour) {
  119. $scope.comments[ind].favourcount = $scope.comments[ind].favourcount - 1;
  120. $scope.comments[ind].isCommentZan=false;
  121. }
  122. }
  123. $scope.comments[ind].favour=!$scope.comments[ind].favour;
  124. }
  125. // 恢复可用
  126. flag = 1;
  127. }, function () {
  128. // 恢复可用
  129. flag = 1;
  130. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  131. });
  132. };
  133. //跳转到评论详情页comment
  134. $scope.goComment = function (comment) {
  135. $scope.go("Reply", {comment: comment, infotype: comment.infotype, infoid: comment.infoid})
  136. };
  137. //发布普通评论
  138. $scope.publishComment = function (type, comment) {
  139. $scope.showComment = true;
  140. var content = $scope.comment.say;
  141. $scope.infoComment.content = content;
  142. // 评论
  143. if(type == 1){
  144. $scope.infoComment.parentid = 0;// 评论回复时,记录父评论的id
  145. $scope.infoComment.parentuserid = 0;// 评论回复时,记录父评论的创建者
  146. }
  147. // 评论回复
  148. else if(type == 2){
  149. $scope.infoComment.parentid = comment.id;// 评论回复时,记录父评论的id
  150. $scope.infoComment.parentuserid = comment.creator;// 评论回复时,记录父评论的创建者
  151. }
  152. //提交评论信息
  153. $scope.showLoadingToast();
  154. console.log($stateParams);
  155. console.log($scope.infoComment);
  156. if($stateParams.comfrom=='task'){
  157. $scope.infoComment.contenttype='任务详情页';
  158. }
  159. CommentService.publishSimpleComment($scope.infoComment).then(function () {
  160. if($scope.app){
  161. UtilService.showMess("评论成功");
  162. }else{
  163. CommonService.showMessage("评论成功",$scope);
  164. }
  165. $scope.infoComment.content = "";
  166. getInfoCommentList();
  167. /*if ($scope.comments.length >= 3) {
  168. $timeout(function () {
  169. $scope.getInfoCommentList();
  170. }, 650);
  171. }*/
  172. $scope.hideLoadingToast();
  173. }, function () {
  174. $scope.hideLoadingToast();
  175. });
  176. };
  177. $scope.showComment = true;
  178. $scope.focus_write = function () {
  179. $scope.showComment = false;
  180. };
  181. $scope.hiddenComment = function () {
  182. $scope.showComment = true;
  183. };
  184. $scope.commentValue = function () {
  185. if (UtilService.isDefined($scope.comment.say) && $scope.comment.say.length > 1000) {
  186. if($scope.app){
  187. UtilService.showMess("您的评论已超过1000字!");
  188. }else{
  189. CommonService.showMessage("您的评论已超过1000字!",$scope);
  190. }
  191. $scope.comment.say = $scope.comment.say.substr(0, 1000);
  192. }
  193. if (UtilService.isDefined($scope.comment.say) && $scope.comment.say.length != 0) {
  194. $scope.commentNotnull = {
  195. "background-color": "#2a90d7",
  196. "text-decoration": "underline"
  197. }
  198. }else{
  199. $scope.commentNotnull = {
  200. "background-color": "#ccc"
  201. };
  202. }
  203. };
  204. });