123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- angular.module('push')
- .controller('resourceCommentReplyCtrl', function ($scope, $stateParams, $timeout, ConfigService, UtilService, $ionicLoading, CommentService, UserService, $ionicSlideBoxDelegate) {
- //提交的回复
- $scope.replay = {say: ""};
- $scope.userid = UserService.id;
- $scope.comment = angular.fromJson($stateParams.comment);
- $scope.commentpiclist = $scope.comment.pic;
- $scope.isedit = $stateParams.isedit;
- $scope.dianzanlist = [];
- // console.log($scope.comment);
- //回复的父id(也就是评论的id)
- var commentid = $scope.comment.id;
- //回复的那条评论的用户id
- var parentUserId = $scope.comment.userId;
- //拿到之前内页的信息id和type
- var infotype = $stateParams.infotype;
- var infoid = $stateParams.infoid;
- var recourcecomefrom = $stateParams.recourcecomefrom;
- //加载评论的回复列表
- var getReplyList = function () {
- $scope.showLoadingToast();
- CommentService.getReplyList(commentid, infotype).then(function (response) {
- // console.log(response);
- $scope.replys = response.comment;
- $scope.dianzanlist = response.clickList;
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- });
- };
- getReplyList();
- //评论详情页回复提交
- $scope.appreplay = function () {
- $scope.showComment = true;
- var content = $scope.replay.say;
- //提交评论信息
- $scope.showLoadingToast();
- CommentService.publishComment(1, infoid, infotype, commentid, parentUserId, content, recourcecomefrom).then(function (response) {
- // console.log(response);
- getReplyList();
- //重置评论内容为空
- $scope.replay.say = "";
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- });
- };
- // 点赞评论
- var pldianzanflg = 0;
- $scope.content_zan = function () {
- if (pldianzanflg != 0) {
- return;
- }
- pldianzanflg = 1;
- CommentService.commentLike($scope.comment.id, infotype).then(function (response) {
- // console.log(response);
- if (response.favourState == 1) {
- $scope.comment.favourcount++;
- $scope.comment.Like = true;
- } else {
- $scope.comment.favourcount--;
- $scope.comment.Like = false;
- }
- $timeout(function () {
- pldianzanflg = 0;
- }, 500);
- }, function () {
- pldianzanflg = 0;
- UtilService.showMess("网络不给力,请重试");
- });
- };
- $scope.goDianZanDetail = function () {
- $scope.go('resourceCommentReplyClickDetail', {dianzanlist: angular.toJson($scope.dianzanlist)})
- };
- $scope.showComment = true;
- $scope.focus_write = function () {
- $scope.showComment = false;
- };
- $scope.hiddenComment = function () {
- $scope.showComment = true;
- };
- $scope.commentValue = function () {
- var search_history = angular.element(document.getElementsByClassName("my_comment"));
- if ($scope.replay.say.length > 1000) {
- UtilService.showMess("您的评论已超过1000字!");
- $scope.replay.say = $scope.replay.say.substr(0, 1000);
- }
- if (search_history.val.length != 0) {
- $scope.commentNotnull = {
- "background-color": "#2a90d7",
- "text-decoration": "underline"
- };
- }
- };
- var search_history = angular.element(document.getElementsByClassName("my_comment"));
- if (search_history.val.length != 0) {
- $scope.commentNotnull = {
- "background-color": "#cacaca"
- };
- }
- //删除自己的回复
- $scope.delectToolDis = function (commentid) {
- $scope.showLoadingToast();
- CommentService.deleteComment(commentid).then(function () {
- getReplyList();
- UtilService.showMess("删除成功");
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- });
- };
- //点击图片放大
- $scope.bigImage = false; //初始默认大图是隐藏的
- $scope.hideBigImage = function () {
- $timeout(function () {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $scope.bigImage = false;
- }, 400);
- };
- $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
- if($scope.app){
- $scope.setStatusBar(1);
- }
- $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, 0);
- //获取图片
- 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);
- };
- //查看原图
- $scope.viewOldImg = function (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 (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=="
- //}
- }
- );
- };
- });
|