ReplyCtrl.js 6.6 KB

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