angular.module('push') .controller('CommentCtrl', function ($scope, $stateParams, ConfigService, UserService , DetailsService, $timeout, $ionicLoading, UtilService, CommentService, ConstantService,CommonService) { //提交的评论 $scope.comment = {say: ""}; $scope.comment.isCommentZan=false; // 点赞 $scope.TRACE_TYPE_2615 = ConstantService.TRACE_TYPE_2615; // 取消点赞 $scope.TRACE_TYPE_2616 = ConstantService.TRACE_TYPE_2616; // 评论表 info_comment $scope.TABLE_CODE_30002 = ConstantService.TABLE_CODE_30002; //拿到之前内页的信息id和type var moduleId = $scope.moduleId = $stateParams.infotype; var id = $scope.id = $stateParams.infoid; // var moduleId = $scope.moduleId = 6; // var id = $scope.id = 1; var siteName = ""; // 评论/评论回复的传参 $scope.infoComment= { infoid: id,//资源id infotype:moduleId,// 资源类别 parentid:0,// 评论回复时,记录父评论的id parentuserid:0,// 评论回复时,记录父评论的创建者 content:"",// 评论/回复内容 //TODO creator:UserService.id,// 创建者 updater:UserService.id// 更新者 // creator:1,// 创建者 // updater:1// 更新者 }; // 点赞、收藏、分享的传参 $scope.clickRecord= { //TODO targetid: $stateParams.recourceid, // targetid: 124, moduleid: ConstantService.TABLE_CODE_30002, userid:UserService.id, // userid:1, clicktype:1 }; // 获取评论列表的传参 $scope.paramsForInfoCommentList= { mode: 2,// 显示样式:1热门 2全部 infoid: id,// 资源id infotype:moduleId,// 资源类型 sortkey:0,// 排序字段 sorttype:"ASC",// 排序方式 moduleid:ConstantService.TABLE_CODE_30002,// 评论表对应的code //TODO userid:UserService.id// 登录者id // userid:1// 登录者id }; //进详情加载评论列表 var getInfoCommentList = function () { CommentService.getInfoCommentList($scope.paramsForInfoCommentList).then(function (response) { console.log(response); // 评论列表 $scope.comments = response.data; }, function () { }) }; getInfoCommentList(); //详情页评论 $scope.appComment = function () { $scope.showComment = true; var islogin = ConfigService.islogin; if (!islogin) { $ionicLoading.show({ template: '请登录!', noBackdrop: true }); $timeout(function () { $ionicLoading.hide(); }, 1000); return; } else { var content = $scope.comment.say; //提交评论信息 console.log(content); DetailsService.appComment(id, moduleId, content, siteName).then(function () { //评论成功后重新获取评论列表 DetailsService.commentList(id, moduleId).then(function (response) { $scope.comments = response.res.comment; }, function () { }); //重置评论内容为空 $scope.comment.say = ""; }, function () { }); } }; // 控制重复点击 var flag = 1; // 操作:点赞 $scope.commentPraiseAction=function (comment, ind, clicktype, recourceid, moduleid) { if(flag == 0){ return; } flag = 0; $scope.clickRecord.targetid = recourceid; $scope.clickRecord.clicktype = clicktype; $scope.clickRecord.moduleid = moduleid; CommentService.postClickFavour($scope.clickRecord).then(function (response) { console.log(response); if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { // 点赞 if(clicktype == $scope.TRACE_TYPE_2615) { if (!comment.favour) { $scope.comments[ind].favourcount = $scope.comments[ind].favourcount + 1; $scope.comments[ind].isCommentZan=true; } }else // 取消点赞 if(clicktype == $scope.TRACE_TYPE_2616) { if (comment.favour) { $scope.comments[ind].favourcount = $scope.comments[ind].favourcount - 1; $scope.comments[ind].isCommentZan=false; } } $scope.comments[ind].favour=!$scope.comments[ind].favour; } // 恢复可用 flag = 1; }, function () { // 恢复可用 flag = 1; UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }); }; //跳转到评论详情页comment $scope.goComment = function (comment) { $scope.go("Reply", {comment: comment, infotype: comment.infotype, infoid: comment.infoid}) }; //发布普通评论 $scope.publishComment = function (type, comment) { $scope.showComment = true; var content = $scope.comment.say; $scope.infoComment.content = content; // 评论 if(type == 1){ $scope.infoComment.parentid = 0;// 评论回复时,记录父评论的id $scope.infoComment.parentuserid = 0;// 评论回复时,记录父评论的创建者 } // 评论回复 else if(type == 2){ $scope.infoComment.parentid = comment.id;// 评论回复时,记录父评论的id $scope.infoComment.parentuserid = comment.creator;// 评论回复时,记录父评论的创建者 } //提交评论信息 $scope.showLoadingToast(); console.log($stateParams); console.log($scope.infoComment); if($stateParams.comfrom=='task'){ $scope.infoComment.contenttype='任务详情页'; } CommentService.publishSimpleComment($scope.infoComment).then(function () { if($scope.app){ UtilService.showMess("评论成功"); }else{ CommonService.showMessage("评论成功",$scope); } $scope.infoComment.content = ""; getInfoCommentList(); /*if ($scope.comments.length >= 3) { $timeout(function () { $scope.getInfoCommentList(); }, 650); }*/ $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; $scope.showComment = true; $scope.focus_write = function () { $scope.showComment = false; }; $scope.hiddenComment = function () { $scope.showComment = true; }; $scope.commentValue = function () { if (UtilService.isDefined($scope.comment.say) && $scope.comment.say.length > 1000) { if($scope.app){ UtilService.showMess("您的评论已超过1000字!"); }else{ CommonService.showMessage("您的评论已超过1000字!",$scope); } $scope.comment.say = $scope.comment.say.substr(0, 1000); } if (UtilService.isDefined($scope.comment.say) && $scope.comment.say.length != 0) { $scope.commentNotnull = { "background-color": "#2a90d7", "text-decoration": "underline" } }else{ $scope.commentNotnull = { "background-color": "#ccc" }; } }; });