angular.module('push') .controller('CloudDockingdetailsCtrl', function ($scope, DockingService, UtilService, $stateParams, $sce, ShareService, $timeout, UserService, $ionicModal, SearchResultService, $ionicSlideBoxDelegate, CommentService, $ionicActionSheet, ResourceLibraryService, AuthorityService) { if($scope.app){ $scope.setStatusBar(0); } $scope.user = UserService.user.user; $scope.userid = UserService.id; $scope.viplevel = UserService.viplevel; var infoid = $stateParams.infoid; var infotype = 81; var infocomefrom = $stateParams.infocomefrom; var creator = $stateParams.creator; //获取相关资源 $scope.getRelativeResource = function () { CommentService.getRelativeResource(0, $scope.conninfo.title, "", "", "", infoid).then(function (response) { // console.log(response); $scope.relativelist = response.resourcelibrary; $scope.relativerecord = response.connectioninfoEntity; }, function () { }) }; var getConninfoDetail = function () { DockingService.newGetConnInfoDetails(infoid).then(function (response) { // console.log(response); $scope.conninfo = response; $scope.starwidth = ($scope.conninfo.totalpoint / 10) * 100 + "%"; $scope.picturelist = response.picture; $scope.picturelisttt = angular.copy(response.picture); $scope.cardlist = response.unit; $scope.content = $sce.trustAsHtml(response.content); $scope.getRelativeResource(); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }); }; $scope.showactivityinfo = false; $scope.showrecon = false; var getActivityInfo = function (isCreator) { if (isCreator == 3) { DockingService.getAdminActivitiesFollowupList(infoid).then(function (response) { if (angular.isDefined(response.returnlist)) { $scope.showactivityinfo = response.returnlist.length > 0; } else { $scope.showactivityinfo = false; } }, function () { }); DockingService.getKeeponRecordList(infoid, 3).then(function (response) { if (angular.isDefined(response.list)) { $scope.showrecon = response.list.length > 0; } else { $scope.showrecon = false; } }, function () { }); } else { DockingService.getMyActivityFollowUpList(infoid).then(function (response) { if (angular.isDefined(response.list)) { $scope.showactivityinfo = response.list.length > 0; } else { $scope.showactivityinfo = false; } }, function () { }); DockingService.getKeeponRecordList(infoid, 0).then(function (response) { if (angular.isDefined(response.list)) { $scope.showrecon = response.list.length > 0; } else { $scope.showrecon = false; } }, function () { }); } }; //提取当前用户是否有 查看/编辑 本记录权限 var getVisitAuthority = function () { $scope.showLoadingToast(); ResourceLibraryService.getVisitAuthority(0, infoid, creator, infocomefrom, infotype).then(function (response) { // console.log(response); getConninfoDetail(); // isedit:是否可以编辑资源,isset:是否可以设置权限,bl:是否可以访问 $scope.roler = response; getActivityInfo($scope.roler.isCreator) }, function () { $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }) }; getVisitAuthority(); //获取热门评论 var checkflg = 0; var getHotCommentList = function () { CommentService.getHotCommentList(infoid, infotype).then(function (response) { // console.log(response); $scope.commentlist = response.res.comment; $scope.MoreComment = response.MoreComment; if (checkflg != 0) { $scope.conninfo.totalpoint = response.totalpoint; $scope.starwidth = (response.totalpoint / 10) * 100 + "%"; } checkflg = 1; }, function () { }) }; getHotCommentList(); //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博 $scope.shareMessage = function (type) { $scope.softTap = false; $scope.showLoadingToast(); CommentService.createShareRecord($scope.conninfo.share_url, infoid, infocomefrom, infotype).then(function (response) { // console.log(response); var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg"; if ($scope.picturelist.length > 0) { imagurl = $scope.imgUrl + $scope.picturelist[0].photo_name; } var message = { title: $scope.conninfo.title, description: $scope.conninfo.content.substring(0, 19), 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.shareflg = false; $scope.openShare = function () { $scope.shareflg = true; }; $scope.closeShare = function () { $scope.shareflg = false; }; //编辑对接详情 $scope.editorButton = function () { $scope.go("cloudEditconninfo", {infoid: infoid}); }; $scope.relativelist2 = []; $scope.goPrivateResource = function (tempobj) { if (tempobj.length > 1) { $scope.showModel(); $scope.relativelist2 = tempobj; } else { $scope.go('resourcePrivateDetails', { recourceid: tempobj[0].unique, recourcetype: tempobj[0].type, recourcecomefrom: tempobj[0].source, creator: tempobj[0].clickthrough }); } }; //关注用户 --已经关注是1,未关注是2 var focusflg = 0; $scope.focusUser = function () { if (focusflg != 0) { return; } focusflg = 1; var status = $scope.conninfo.isFocus == 2 ? 1 : 2; SearchResultService.doFocus($scope.conninfo.isFocus, $scope.conninfo.creator).then(function (response) { // console.log(response); if (response.status == true) { if ($scope.conninfo.isFocus == 1) { $scope.conninfo.isFocus = 2; UtilService.showMess("取消关注成功"); } else { $scope.conninfo.isFocus = 1; UtilService.showMess("关注成功"); } } else { UtilService.showMess("网络不给力,请重试"); } $timeout(function () { focusflg = 0; }, 500); }, function () { focusflg = 0; UtilService.showMess("网络不给力,请重试"); }); }; //评分 $scope.starnum = 0; $scope.evaluateNum = function (num) { $scope.starnum = num; }; //详情页评论 $scope.showComment = true; $scope.publishComment = function () { $scope.showComment = true; var content = $scope.comment.content; //提交评论信息 $scope.showLoadingToast(); CommentService.publishComment(0, infoid, infotype, "", "", content, infocomefrom, $scope.starnum).then(function () { UtilService.showMess("评论成功"); $scope.comment.content = ""; $scope.starnum = 0; getHotCommentList(); if ($scope.commentlist.length >= 3) { $timeout(function () { $scope.goCommentList(); }, 650); } $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }; //发表详细评论 $scope.releaseComment = function () { $scope.go('releaseComment', { infoid: infoid, infotype: infotype, comlen: $scope.commentlist.length, recourcecomefrom: infocomefrom }) }; //进入评论列表页 $scope.goCommentList = function () { $timeout(function () { $scope.go('toolDiscuss', { infoid: infoid, infotype: infotype, recourcecomefrom: infocomefrom, isedit: $scope.roler.isedit }); }, 350); }; //资源点赞 var zydianzanflg = 0; $scope.dianZan = function () { if (zydianzanflg != 0) { return; } zydianzanflg = 1; CommentService.clickFavour(infoid, infotype, infocomefrom).then(function (response) { // console.log(response); if (response.favourState == 1) { $scope.conninfo.favourcount++; $scope.conninfo.Like = true; } else { $scope.conninfo.favourcount--; $scope.conninfo.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, 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; } // 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(infoid, infotype, infocomefrom, 2).then(function (response) { // console.log(response); if (response.clickStatus == "收藏成功") { $scope.conninfo.Enshrine = true; } else { $scope.conninfo.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: infoid, infotype: infotype, recourcecomefrom: infocomefrom, isedit: $scope.roler.isedit }); }; $scope.comment = { content: "" }; //弹出评论框 $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.openActionSheet = function () { // isedit:是否可以编辑资源,isset:是否可以设置权限 var buttonlist = []; if ($scope.roler.isedit) { buttonlist.push({text: '编辑', type: "edit"}); } if ($scope.roler.isset) { buttonlist.push({text: '设置', type: "set"}); if ($scope.cardlist.length > 0) { buttonlist.push({text: '需求跟进', type: "schedule"}); } } $ionicActionSheet.show({ buttons: buttonlist, cancelText: '取消', buttonClicked: function (index) { if (buttonlist[index].type == "edit") { $scope.go("cloudEditconninfo", {infoid: infoid}); } else if (buttonlist[index].type == "set") { var tempdata1 = { title: $scope.conninfo.title, recourceid: infoid, recourcetype: infotype, recourcecomefrom: infocomefrom, creator: creator }; $scope.go("authorityRecordSet", {authoritydata: angular.toJson(tempdata1)}); } else if (buttonlist[index].type == "schedule") { var tempcompanylist = []; var tmepreqlist = []; angular.forEach($scope.cardlist, function (value, index) { tempcompanylist.push(value.name); if (angular.isDefined(value.themelist)) { angular.forEach(value.themelist, function (val, ind) { tmepreqlist.push(val.title); }) } }); $scope.go("ActivitySchedule", {infoid: infoid, companylist: tempcompanylist, reqlist: tmepreqlist}) } /*if (buttonlist.length > 1) { if (index == 0) { $scope.go("cloudEditconninfo", {infoid: infoid}); } else if (index == 1) { var tempdata1 = { title: $scope.conninfo.title, recourceid: infoid, recourcetype: infotype, recourcecomefrom: infocomefrom, creator: creator }; $scope.go("authorityRecordSet", {authoritydata: angular.toJson(tempdata1)}); } } else { if ($scope.roler.isedit) { $scope.go("cloudEditconninfo", {infoid: infoid}); } if ($scope.roler.isset) { var tempdata2 = { title: $scope.conninfo.title, recourceid: infoid, recourcetype: infotype, recourcecomefrom: infocomefrom, creator: creator }; $scope.go("authorityRecordSet", {authoritydata: angular.toJson(tempdata2)}); } }*/ return true; } }); }; //显示更多名片部分 $scope.showMoreCard = function (index) { $(".parentWrapCard").eq(index).toggle(); $(".showCardWrap").eq(index).toggle(); $(".changeArrowButton").eq(index).toggleClass("upArrow"); var cardText = $(".downArrow").eq(index).text(); // if (cardText == '展开') { // $(".downArrow").eq(index).text("收起"); // } else { // $(".downArrow").eq(index).text("展开"); // } }; //点击图片放大 $scope.bigImage = false; //初始默认大图是隐藏的 $scope.hideBigImage = function () { $timeout(function () { if($scope.app){ $scope.setStatusBar(0); } $scope.bigImage = false; }, 400); }; $scope.shouBigImage = function (index, piclist) {//传递一个参数(图片的URl) if($scope.app){ $scope.setStatusBar(1); } $scope.bigImage = true; //显示大图 $scope.picturelisttt = 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.slideHasChanged = function (index) { // console.log(index); $scope.nowIndex = index + 1; }; $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.goRelativeResource = function (relative) { if (relative.type == 81) { $scope.go('cloudDockingdetail', { infoid: relative.id, infocomefrom: relative.creatorcomefrom, creator: relative.creator }); } else { if (relative.groupid == "0") { $scope.go('resourceDetails', { recourceid: relative.unique, recourcetype: relative.type, recourcecomefrom: relative.source, categorylabel: "" }); } else { $scope.go('resourcePrivateDetails', { recourceid: relative.unique, recourcetype: relative.type, recourcecomefrom: relative.source, creator: relative.clickthrough }); } } $scope.hideModel(); }; //进入相关资源列表 $scope.goResourceMatch = function (relative) { $scope.go('resourceMatch', { type: relative.type, title: $scope.conninfo.title, categorylabel: "", recordid: infoid }); }; $scope.goResourceApply = function () { if ($scope.viplevel == 1) { AuthorityService.isHasEnoughCount(1).then(function (response) { if (response.isHasEnoughCount == 1) { var tempdata = { title: $scope.conninfo.title, recourceid: infoid, recourcetype: infotype, recourcecomefrom: infocomefrom }; $scope.go("resourceApply", {authoritydata: angular.toJson(tempdata)}) } else { UtilService.showMess("本月申请次数已用完"); } }, function () { }); } else { var tempdata = { title: $scope.conninfo.title, recourceid: infoid, recourcetype: infotype, recourcecomefrom: infocomefrom }; $scope.go("resourceApply", {authoritydata: angular.toJson(tempdata)}) } }; //分享到我的资源库 $scope.openCollectShare = function () { var tempres = [{ infoid: infoid, infocomefrom: infocomefrom, infoType: infotype }]; $scope.go('chooseShareFolder', {chereslist: angular.toJson(tempres), folderid: $scope.conninfo.claid}); }; //查看原图 $scope.viewOldImg = function (index) { // console.log($scope.picturelisttt[index]); // console.log("查看原图" + index); var url = UtilService.isDefined($scope.picturelisttt[index].source_name) ? $scope.picturelisttt[index].source_name : $scope.picturelisttt[index].photo_name; $(".bigimage").eq(index).attr("src", $scope.imgUrl + url); $timeout(function () { $scope.picturelisttt[index].loadsource = true; }, 20); }; //请求SDK权限 $scope.loadImg = function (pic) { if (UtilService.checkPlatform()) { window.imagePicker.verifyStorage( function (results) { if (results == "1") { downloadPicture(pic); } }, function (error) { } ); } else { downloadPicture(pic); } }; //图片下载 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.loadPercent = "40%"; //拨打电话 $scope.openTel = function (tel) { window.open("tel:" + tel); }; //关联跳转列表页 $ionicModal.fromTemplateUrl('templates/relativelist.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.modal = modal; }); //关闭关联列表 $scope.hideModel = function () { $scope.modal.hide(); $scope.relativelist2 = []; }; //打开关联列表 $scope.showModel = function () { $scope.modal.show(); }; //跳转我的跟进 $scope.goActivtyScheduleHome = function () { var tempcompanylist = []; var tmepreqlist = []; angular.forEach($scope.cardlist, function (value, index) { tempcompanylist.push(value.name); if (angular.isDefined(value.themelist)) { angular.forEach(value.themelist, function (val, ind) { tmepreqlist.push(val.title); }) } }); if ($scope.roler.isCreator == 3) { $scope.go("ActivityScheduleAccount", {infoid: infoid}); } else { $scope.go("ActivtyScheduleHome", {infoid: infoid, companylist: tempcompanylist, reqlist: tmepreqlist}); } }; $scope.goActivityReportAccount = function () { var role = $scope.roler.isCreator == 3 ? 3 : 0; $scope.go("ActivityReportAccount", {infoid: infoid, role: role}); }; });