angular.module('push') .controller('toolDiscussCtrl', function ($scope, $stateParams, CommentService, UtilService, $rootScope, UserService, $timeout, $ionicSlideBoxDelegate) { if($scope.app){ $scope.setStatusBar(0); } //1:需求,2:成果,6:企业,8:人才 var infoid = $stateParams.infoid; var infotype = $stateParams.infotype; $scope.infotype = infotype; var recourcecomefrom = $stateParams.recourcecomefrom; $rootScope.comlen = $stateParams.comlen; $scope.isedit = $stateParams.isedit; $scope.userid = UserService.id; $scope.comment = {content: ""}; $scope.maxlength = 7; $scope.progressLabels = []; var first = true; $scope.choseindex = -1; //评分 $scope.starnum = 0; $scope.evaluateNum = function (num) { $scope.starnum = num; }; //获取评论列表 var getCommentList = function (tagid) { $scope.showLoadingToast(); CommentService.getCommentList(infoid, infotype, tagid).then(function (response) { // console.log(response); if (first) { $scope.progressLabels = response.tag; first = false; } $scope.commentlist = response.res.comment; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }) }; getCommentList(-1); $scope.filterTag = function (tagid, index) { $scope.choseindex = index; getCommentList(tagid); }; $scope.showAllLabel = function () { $scope.maxlength = $scope.progressLabels.length; }; //评论点赞 var pldianzanflg = 0; $scope.content_zan = function (comment, index) { if (pldianzanflg != 0) { return; } pldianzanflg = 1; CommentService.commentLike(comment.id, infotype).then(function (response) { // console.log(response); if (response.favourState == 1) { $scope.commentlist[index].favourcount++; $scope.commentlist[index].Like = true; } else { $scope.commentlist[index].favourcount--; $scope.commentlist[index].Like = false; } $timeout(function () { pldianzanflg = 0; }, 500); }, function () { pldianzanflg = 0; UtilService.showMess("网络不给力,请重试"); }) }; $scope.goCommentDetail = function (comment) { $scope.go('resourceCommentReply', { comment: angular.toJson(comment), infoid: infoid, infotype: infotype, recourcecomefrom: recourcecomefrom, isedit: $scope.isedit }); }; //发表详细评论 $scope.releaseComment = function () { $scope.go('releaseComment', {infoid: infoid, infotype: infotype, recourcecomefrom: recourcecomefrom}) }; $scope.goResourceSearch = function () { $timeout(function () { $scope.go('resourceSearchResult', {infoid: infoid, infotype: infotype, searchtype: 1, isedit: $scope.isedit}) }, 350); }; $scope.showComment = true; $scope.publishComment = function () { $scope.showComment = true; var content = $scope.comment.content; //提交评论信息 $scope.showLoadingToast(); CommentService.publishComment(0, infoid, infotype, "", "", content, recourcecomefrom, $scope.starnum).then(function () { getCommentList(-1); $scope.comment.content = ""; $scope.starnum = 0; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; $scope.backview = function () { if ($rootScope.comlen >= 3) { $scope.backViews(-2); } else { $scope.goback(); } }; //点击强沙发 $scope.hadSoft = function () { $timeout(function () { $scope.showComment = false; }, 350); }; $scope.focus_write = function () { $scope.showComment = false; $(".my_comment").focus(); }; $scope.hiddenComment = function () { $scope.showComment = true; }; //弹出评论框 $scope.commentValue = function () { var search_history = angular.element(document.getElementsByClassName("my_comment")); if ($scope.comment.content.length > 1000) { UtilService.showMess("您的评论已超过1000字!"); $scope.comment.content = $scope.comment.content.substr(0, 1000); } if (search_history.val.length != 0) { $scope.commentNotnull = { "background-color": "#2a90d7", "text-decoration": "underline" }; } }; //删除自己刚刚发布或者以后的评论 $scope.delectToolDis = function (commentid) { $scope.showLoadingToast(); CommentService.deleteComment(commentid).then(function () { UtilService.showMess("删除成功"); getCommentList(-1); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; //点击图片放大 $scope.bigImage = false; //初始默认大图是隐藏的 $scope.hideBigImage = function () { $timeout(function () { $scope.bigImage = false; }, 400); }; $scope.shouBigImage = function (piclist, index) { //传递一个参数(图片的URl) $scope.bigImage = true; //显示大图 $scope.commentpiclist = piclist; // console.log(index); $(function () { $('div.pinch-zoom').each(function () { new RTP.PinchZoom($(this), {}); }); }); $ionicSlideBoxDelegate.update();//重绘,让图片显示出来 //图片总数量 setTimeout(function () { // console.log(parseInt($ionicSlideBoxDelegate.slidesCount())); // console.log(parseInt($ionicSlideBoxDelegate.currentIndex())); $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -5); // var nowIndex=parseInt($ionicSlideBoxDelegate.currentIndex()); var totalIndex = parseInt($ionicSlideBoxDelegate.slidesCount()); // console.log(index); $scope.nowIndex = index + 1; $scope.totalIndex = totalIndex; //获取图片 var imgObj = document.getElementsByClassName('bigimage'); var n; for (n = 0; n < imgObj.length; n++) { // 获取图片的原始高度和宽度 var oldWid = imgObj[n].naturalWidth; var oldHei = imgObj[n].naturalHeight; var screen = document.body.offsetWidth; var screenH = window.innerHeight; // console.log(oldWid / oldHei); // console.log(screen); var cc = screen / (oldWid / oldHei); imgObj[n].style.height = cc + 'px'; if (cc < screenH) { imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px'; // console.log("e:" + imgObj[n].style.marginTop); } else { imgObj[n].style.marginTop = 0 + 'px'; // console.log((cc - screenH) + 'px') } } }, 0); }; //查看原图 $scope.viewOldImg = function (index) { // console.log($scope.commentpiclist[index]); // console.log("查看原图" + index); var url = UtilService.isDefined($scope.commentpiclist[index].source_name) ? $scope.commentpiclist[index].source_name : $scope.commentpiclist[index].photo_name; $(".bigimage").eq(index).attr("src", $scope.imgUrl + url); $timeout(function () { $scope.commentpiclist[index].loadsource = true; }, 20); }; //请求SDK权限 $scope.loadImg = function (image) { if (UtilService.checkPlatform()) { window.imagePicker.verifyStorage( function (results) { if (results == "1") { downloadPicture(image); } }, function (error) { } ); } else { downloadPicture(image); } }; //图片下载 var downloadPicture = function (image) { $scope.showLoadingToast(); var fileTransfer = new FileTransfer(); var url = UtilService.isDefined(image.source_name) ? image.source_name : image.photo_name; var imgname = url.substring(url.lastIndexOf('/') + 1);//图片名称 var loadurl = $scope.imgUrl + url;//图片下载地址 var fileURL = "";//下载后的地址 if (UtilService.checkPlatform()) { fileURL = cordova.file.externalRootDirectory + "pushpicture/" + imgname; } else { fileURL = cordova.file.documentsDirectory + imgname; } // console.log(loadurl); // console.log(fileURL); fileTransfer.download( loadurl, fileURL, function (entry) { // console.log(entry); if (UtilService.checkPlatform()) { var tempstr = entry.toURL().replace("file://", ""); UtilService.showMess("图片下载成功,地址:" + tempstr); } else { UtilService.showMess("图片下载成功"); } $scope.hideLoadingToast(); }, function (error) { // console.log(error); $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }, null, // or, pass false { //headers: { // "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" //} } ); }; $scope.slideHasChanged = function (index) { // console.log(index); $scope.nowIndex = index + 1; }; });