123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- 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"
- };
- }
- };
- });
|