angular.module('push') .controller('resourceDetailsCtrl', function ($scope, ResourceLibraryService, $stateParams, SearchResultService, UtilService, ShareService, CommentService, $sce, $timeout, UserService, $ionicSlideBoxDelegate) { if ($scope.app) { $scope.setStatusBar(0); } //显示详情的资源库资源出现在列表中的次序 $scope.order = $stateParams.order; $scope.reclib = $stateParams.reclib; //1:需求,2:成果,6:企业,8:人才 var recourceid = $stateParams.recourceid; var recourcetype = $scope.type = $stateParams.recourcetype; var recourcecomefrom = $stateParams.recourcecomefrom; var categorylabel = $stateParams.categorylabel; $scope.userid = UserService.id; $scope.comment = {content: ""}; // console.log($scope.imgUrl+$scope.image.$scope.photo_name); //获取相关资源 $scope.getRelativeResource = function () { CommentService.getRelativeResource(0, $scope.resource.title, categorylabel, "", recourceid, "").then(function (response) { // console.log(response); $scope.relativelist = response.resourcelibrary; $scope.relativerecord = response.connectioninfoEntity; }, function () { }) }; var sharelink = ""; //获取资源库列表 var getPublicResourceList = function () { ResourceLibraryService.getResourceDetail(recourceid, recourcetype, recourcecomefrom).then(function (response) { // console.log(response); $scope.resource = response.res; $scope.getRelativeResource(); $scope.contenthtml = $sce.trustAsHtml($scope.resource.content); if (angular.isDefined($scope.resource.cperlist) && $scope.resource.cperlist.length > 0) { $scope.modelstr = $scope.resource.cperlist.join(","); } else { $scope.modelstr = ""; } sharelink = response.sharelink; }, function () { }) }; getPublicResourceList(); //获取热门评论 var getHotCommentList = function () { CommentService.getHotCommentList(recourceid, recourcetype).then(function (response) { // console.log(response); $scope.commentlist = response.res.comment; $scope.MoreComment = response.MoreComment; }, function () { }) }; getHotCommentList(); $scope.shareflg = false; $scope.openShare = function () { $scope.shareflg = true; }; $scope.closeShare = function () { $scope.shareflg = false; }; //关注用户 --已经关注是1,未关注是2 var focusflg = 0; $scope.focusUser = function () { if (focusflg != 0) { return; } focusflg = 1; var status = $scope.resource.Focus ? 1 : 2; SearchResultService.doFocus(status, $scope.resource.creator).then(function (response) { // console.log(response); if (response.status == true) { if ($scope.resource.Focus) { $scope.resource.Focus = false; UtilService.showMess("取消关注成功"); } else { $scope.resource.Focus = true; UtilService.showMess("关注成功"); } } else { UtilService.showMess("网络不给力,请重试"); } $timeout(function () { focusflg = 0; }, 500); }, function () { focusflg = 0; UtilService.showMess("网络不给力,请重试"); }); }; //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博 $scope.shareMessage = function (type) { $scope.shareflg = false; $scope.showLoadingToast(); CommentService.createShareRecord(sharelink, recourceid, recourcecomefrom, recourcetype).then(function (response) { // console.log(response); var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg"; var tempcontent = $scope.resource.content.substring(0, 19); var message = { title: $scope.resource.title, description: tempcontent, url: response.shareurl, imageurl: imagurl }; switch (type) { case 0: case 1: ShareService.shareToQQ(type, message).then(function () { UtilService.showMess("QQ分享成功"); getCurrencyFromShare(response.clickid); $scope.hideLoadingToast(); }, function (error) { UtilService.showMess(error); $scope.hideLoadingToast(); }); break; case 2: case 3: ShareService.shareToWechat(0, message).then(function () { UtilService.showMess("微信分享成功"); getCurrencyFromShare(response.clickid); $scope.hideLoadingToast(); }, function (error) { UtilService.showMess(error); $scope.hideLoadingToast(); }); break; case 4: ShareService.shareToWeibo(message).then(function () { UtilService.showMess("新浪微博分享成功"); getCurrencyFromShare(response.clickid); $scope.hideLoadingToast(); }, function (error) { UtilService.showMess(error); $scope.hideLoadingToast(); }); break; default: break; } $timeout(function () { $scope.hideLoadingToast(); }, 10000); }, function () { $scope.hideLoadingToast(); }) }; var getCurrencyFromShare = function (clickid) { CommentService.getCurrencyFromShare(clickid); }; $scope.showbutton = true; //详情页评论 $scope.showComment = true; $scope.publishComment = function () { $scope.showComment = true; var content = $scope.comment.content; //提交评论信息 $scope.showLoadingToast(); CommentService.publishComment(0, recourceid, recourcetype, "", "", content, recourcecomefrom).then(function () { UtilService.showMess("评论成功"); $scope.comment.content = ""; getHotCommentList(); if ($scope.commentlist.length >= 3) { $timeout(function () { $scope.goCommentList(); }, 650); } $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; //发表详细评论 $scope.releaseComment = function () { $scope.go('releaseComment', { infoid: recourceid, infotype: recourcetype, comlen: $scope.commentlist.length, recourcecomefrom: recourcecomefrom }) }; //进入评论列表页 $scope.goCommentList = function () { $timeout(function () { $scope.go('toolDiscuss', { infoid: recourceid, infotype: recourcetype, recourcecomefrom: recourcecomefrom }); }, 350); }; //进入相关资源详情 $scope.goRelativeResource = function (relative) { if (relative.type == 81) { $scope.go('cloudDockingdetail', {infoid: relative.id, creator: relative.creator}); } else { if (relative.groupid == "0") { $scope.go('resourceDetails', { recourceid: relative.unique, recourcetype: relative.type, recourcecomefrom: relative.source, categorylabel: categorylabel }); } else { $scope.go('resourcePrivateDetails', { recourceid: relative.unique, recourcetype: relative.type, recourcecomefrom: relative.source, creator: relative.clickthrough }); } } }; //进入相关资源列表 $scope.goResourceMatch = function (relative) { $scope.go('resourceMatch', { type: relative.type, title: $scope.resource.title, categorylabel: categorylabel }); }; //资源点赞 var zydianzanflg = 0; $scope.dianZan = function () { if (zydianzanflg != 0) { return; } zydianzanflg = 1; CommentService.clickFavour(recourceid, recourcetype, $scope.resource.source, recourcecomefrom).then(function (response) { // console.log(response); if (response.favourState == 1) { $scope.resource.favourcount++; $scope.resource.Like = true; } else { $scope.resource.favourcount--; $scope.resource.Like = false; } // UtilService.showMess(response.clickStatus); $timeout(function () { zydianzanflg = 0; }, 500); }, function () { zydianzanflg = 0; UtilService.showMess("网络不给力,请重试"); }) }; //评论点赞 var pldianzanflg = 0; $scope.content_zan = function (comment, index) { if (pldianzanflg != 0) { return; } pldianzanflg = 1; CommentService.commentLike(comment.id, recourcetype).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; } // UtilService.showMess(response.clickStatus); $timeout(function () { pldianzanflg = 0; }, 500); }, function () { pldianzanflg = 0; UtilService.showMess("网络不给力,请重试"); }) }; //收藏 var storeflg = 0; $scope.collectResource = function () { if (storeflg != 0) { return; } storeflg = 1; CommentService.collectResource(recourceid, recourcetype, $scope.resource.source, 1).then(function (response) { // console.log(response); if (response.clickStatus == "收藏成功") { $scope.resource.Enshrine = true; } else { $scope.resource.Enshrine = false; } UtilService.showMess(response.clickStatus); $timeout(function () { storeflg = 0; }, 500); }, function () { storeflg = 0; UtilService.showMess("网络不给力,请重试"); }) }; //进入评论详情页 $scope.goCommentDetail = function (comment) { $scope.go('resourceCommentReply', { comment: angular.toJson(comment), infoid: recourceid, infotype: recourcetype, recourcecomefrom: recourcecomefrom }); }; //点击强沙发 $scope.hadSoft = function () { $scope.showComment = false; }; $scope.showComment = true; $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("删除成功"); getHotCommentList(); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; //分享到我的资源库 $scope.openCollectShare = function () { var tempres = [{ infoid: recourceid, infocomefrom: recourcecomefrom, infoType: recourcetype }]; $scope.go('chooseShareResource', {chereslist: angular.toJson(tempres)}); }; //点击图片放大 $scope.bigImage = false; //初始默认大图是隐藏的 $scope.hideBigImage = function () { $timeout(function () { if ($scope.app) { $scope.setStatusBar(0); } $scope.bigImage = false; }, 400); }; $scope.shouBigImage = function (piclist, index) { //传递一个参数(图片的URl) if ($scope.app) { $scope.setStatusBar(1); } // console.log(piclist); // console.log(index); $scope.commentpiclist = piclist; $scope.bigImage = true; //显示大图 // 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, -10); //获取图片 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 rate = oldWid / oldHei; if (oldWid >= screen && oldHei >= screenH) { var tw = screen; var th = tw / rate; if (th < screenH) { imgObj[n].style.width = tw + 'px'; imgObj[n].style.height = th + 'px'; imgObj[n].style.marginTop = (screenH - th) / 2 + 'px'; } else { imgObj[n].style.width = screenH * rate + 'px'; imgObj[n].style.height = screenH + 'px'; imgObj[n].style.marginLeft = (screen - screenH * rate) / 2 + 'px'; } } else if (oldWid >= screen && oldHei <= screenH) { imgObj[n].style.width = screen + 'px'; imgObj[n].style.height = screen / rate + 'px'; imgObj[n].style.marginTop = (screenH - screen / rate) / 2 + 'px'; } else if (oldWid <= screen && oldHei >= screenH) { // var hh=screenH; // var ww=screenH*rate; imgObj[n].style.width = screenH * rate + 'px'; imgObj[n].style.height = screenH + 'px'; imgObj[n].style.marginLeft = (screen - screenH * rate) / 2 + 'px'; } else { imgObj[n].style.width = oldWid + 'px'; imgObj[n].style.height = oldHei + 'px'; imgObj[n].style.marginLeft = (screen - oldWid) / 2 + 'px'; imgObj[n].style.marginTop = (screenH - oldHei) / 2 + 'px'; } } }, 0); }; //请求SDK权限 $scope.loadImg = function (pic) { if (UtilService.checkPlatform()) { window.imagePicker.verifyStorage( function (results) { if (results == "1") { downloadPicture(pic); } }, function (error) { } ); } else { downloadPicture(pic); } }; //查看原图 $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); }; //图片下载 var downloadPicture = function (pic) { $scope.showLoadingToast(); var fileTransfer = new FileTransfer(); var url = UtilService.isDefined(pic.source_name) ? pic.source_name : pic.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.openTel = function (tel) { window.open("tel:" + tel); }; $scope.resDetailGoback = function () { if ($stateParams.comfrom == "privateResource") { $scope.go('privateResource', { libtype: $stateParams.reclibid, modlibid: $stateParams.moduleid, filterList: $stateParams.filterList }) } else { $scope.goback(); } } });