resourceCommentReplyCtrl.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. angular.module('push')
  2. .controller('resourceCommentReplyCtrl', function ($scope, $stateParams, $timeout, ConfigService, UtilService, $ionicLoading, CommentService, UserService, $ionicSlideBoxDelegate) {
  3. //提交的回复
  4. $scope.replay = {say: ""};
  5. $scope.userid = UserService.id;
  6. $scope.comment = angular.fromJson($stateParams.comment);
  7. $scope.commentpiclist = $scope.comment.pic;
  8. $scope.isedit = $stateParams.isedit;
  9. $scope.dianzanlist = [];
  10. // console.log($scope.comment);
  11. //回复的父id(也就是评论的id)
  12. var commentid = $scope.comment.id;
  13. //回复的那条评论的用户id
  14. var parentUserId = $scope.comment.userId;
  15. //拿到之前内页的信息id和type
  16. var infotype = $stateParams.infotype;
  17. var infoid = $stateParams.infoid;
  18. var recourcecomefrom = $stateParams.recourcecomefrom;
  19. //加载评论的回复列表
  20. var getReplyList = function () {
  21. $scope.showLoadingToast();
  22. CommentService.getReplyList(commentid, infotype).then(function (response) {
  23. // console.log(response);
  24. $scope.replys = response.comment;
  25. $scope.dianzanlist = response.clickList;
  26. $scope.hideLoadingToast();
  27. }, function () {
  28. $scope.hideLoadingToast();
  29. });
  30. };
  31. getReplyList();
  32. //评论详情页回复提交
  33. $scope.appreplay = function () {
  34. $scope.showComment = true;
  35. var content = $scope.replay.say;
  36. //提交评论信息
  37. $scope.showLoadingToast();
  38. CommentService.publishComment(1, infoid, infotype, commentid, parentUserId, content, recourcecomefrom).then(function (response) {
  39. // console.log(response);
  40. getReplyList();
  41. //重置评论内容为空
  42. $scope.replay.say = "";
  43. $scope.hideLoadingToast();
  44. }, function () {
  45. $scope.hideLoadingToast();
  46. });
  47. };
  48. // 点赞评论
  49. var pldianzanflg = 0;
  50. $scope.content_zan = function () {
  51. if (pldianzanflg != 0) {
  52. return;
  53. }
  54. pldianzanflg = 1;
  55. CommentService.commentLike($scope.comment.id, infotype).then(function (response) {
  56. // console.log(response);
  57. if (response.favourState == 1) {
  58. $scope.comment.favourcount++;
  59. $scope.comment.Like = true;
  60. } else {
  61. $scope.comment.favourcount--;
  62. $scope.comment.Like = false;
  63. }
  64. $timeout(function () {
  65. pldianzanflg = 0;
  66. }, 500);
  67. }, function () {
  68. pldianzanflg = 0;
  69. UtilService.showMess("网络不给力,请重试");
  70. });
  71. };
  72. $scope.goDianZanDetail = function () {
  73. $scope.go('resourceCommentReplyClickDetail', {dianzanlist: angular.toJson($scope.dianzanlist)})
  74. };
  75. $scope.showComment = true;
  76. $scope.focus_write = function () {
  77. $scope.showComment = false;
  78. };
  79. $scope.hiddenComment = function () {
  80. $scope.showComment = true;
  81. };
  82. $scope.commentValue = function () {
  83. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  84. if ($scope.replay.say.length > 1000) {
  85. UtilService.showMess("您的评论已超过1000字!");
  86. $scope.replay.say = $scope.replay.say.substr(0, 1000);
  87. }
  88. if (search_history.val.length != 0) {
  89. $scope.commentNotnull = {
  90. "background-color": "#2a90d7",
  91. "text-decoration": "underline"
  92. };
  93. }
  94. };
  95. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  96. if (search_history.val.length != 0) {
  97. $scope.commentNotnull = {
  98. "background-color": "#cacaca"
  99. };
  100. }
  101. //删除自己的回复
  102. $scope.delectToolDis = function (commentid) {
  103. $scope.showLoadingToast();
  104. CommentService.deleteComment(commentid).then(function () {
  105. getReplyList();
  106. UtilService.showMess("删除成功");
  107. $scope.hideLoadingToast();
  108. }, function () {
  109. $scope.hideLoadingToast();
  110. });
  111. };
  112. //点击图片放大
  113. $scope.bigImage = false; //初始默认大图是隐藏的
  114. $scope.hideBigImage = function () {
  115. $timeout(function () {
  116. if($scope.app){
  117. $scope.setStatusBar(0);
  118. }
  119. $scope.bigImage = false;
  120. }, 400);
  121. };
  122. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  123. if($scope.app){
  124. $scope.setStatusBar(1);
  125. }
  126. $scope.bigImage = true; //显示大图
  127. // console.log(index);
  128. $(function () {
  129. $('div.pinch-zoom').each(function () {
  130. new RTP.PinchZoom($(this), {});
  131. });
  132. });
  133. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  134. //图片总数量
  135. setTimeout(function () {
  136. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  137. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  138. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, 0);
  139. //获取图片
  140. var imgObj = document.getElementsByClassName('bigimage');
  141. var n;
  142. for (n = 0; n < imgObj.length; n++) {
  143. // 获取图片的原始高度和宽度
  144. var oldWid = imgObj[n].naturalWidth;
  145. var oldHei = imgObj[n].naturalHeight;
  146. var screen = document.body.offsetWidth;
  147. var screenH = window.innerHeight;
  148. // console.log(oldWid/oldHei);
  149. // console.log(screen );
  150. var rate=oldWid/oldHei;
  151. if(oldWid>=screen&&oldHei>=screenH){
  152. var tw=screen;
  153. var th=tw/rate;
  154. if(th<screenH){
  155. imgObj[n].style.width = tw + 'px';
  156. imgObj[n].style.height = th + 'px';
  157. imgObj[n].style.marginTop=(screenH-th)/2+ 'px';
  158. }else{
  159. imgObj[n].style.width = screenH*rate + 'px';
  160. imgObj[n].style.height = screenH + 'px';
  161. imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
  162. }
  163. }else if(oldWid>=screen&&oldHei<=screenH){
  164. imgObj[n].style.width = screen + 'px';
  165. imgObj[n].style.height = screen/rate + 'px';
  166. imgObj[n].style.marginTop=(screenH-screen/rate)/2+ 'px';
  167. }else if(oldWid<=screen&&oldHei>=screenH){
  168. // var hh=screenH;
  169. // var ww=screenH*rate;
  170. imgObj[n].style.width = screenH*rate + 'px';
  171. imgObj[n].style.height = screenH + 'px';
  172. imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
  173. }else{
  174. imgObj[n].style.width = oldWid + 'px';
  175. imgObj[n].style.height = oldHei + 'px';
  176. imgObj[n].style.marginLeft=(screen-oldWid)/2+ 'px';
  177. imgObj[n].style.marginTop=(screenH-oldHei)/2+ 'px';
  178. }
  179. }
  180. }, 0);
  181. };
  182. //查看原图
  183. $scope.viewOldImg = function (index) {
  184. // console.log("查看原图" + index);
  185. var url = UtilService.isDefined($scope.commentpiclist[index].source_name) ? $scope.commentpiclist[index].source_name : $scope.commentpiclist[index].photo_name;
  186. $(".bigimage").eq(index).attr("src", $scope.imgUrl + url);
  187. $timeout(function () {
  188. $scope.commentpiclist[index].loadsource = true;
  189. }, 20);
  190. };
  191. //请求SDK权限
  192. $scope.loadImg = function (pic) {
  193. if (UtilService.checkPlatform()) {
  194. window.imagePicker.verifyStorage(
  195. function (results) {
  196. if (results == "1") {
  197. downloadPicture(pic);
  198. }
  199. }, function (error) {
  200. }
  201. );
  202. } else {
  203. downloadPicture(pic);
  204. }
  205. };
  206. //图片下载
  207. var downloadPicture = function (pic) {
  208. $scope.showLoadingToast();
  209. var fileTransfer = new FileTransfer();
  210. var url = UtilService.isDefined(pic.source_name) ? pic.source_name : pic.photo_name;
  211. var imgname = url.substring(url.lastIndexOf('/') + 1);//图片名称
  212. var loadurl = $scope.imgUrl + url;//图片下载地址
  213. var fileURL = "";//下载后的地址
  214. if (UtilService.checkPlatform()) {
  215. fileURL = cordova.file.externalRootDirectory + "pushpicture/" + imgname;
  216. } else {
  217. fileURL = cordova.file.documentsDirectory + imgname;
  218. }
  219. // console.log(loadurl);
  220. // console.log(fileURL);
  221. fileTransfer.download(
  222. loadurl,
  223. fileURL,
  224. function (entry) {
  225. // console.log(entry);
  226. if (UtilService.checkPlatform()) {
  227. var tempstr = entry.toURL().replace("file://", "");
  228. UtilService.showMess("图片下载成功,地址:" + tempstr);
  229. } else {
  230. UtilService.showMess("图片下载成功");
  231. }
  232. $scope.hideLoadingToast();
  233. },
  234. function (error) {
  235. // console.log(error);
  236. $scope.hideLoadingToast();
  237. UtilService.showMess("网络不给力,请重试");
  238. },
  239. null, // or, pass false
  240. {
  241. //headers: {
  242. // "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
  243. //}
  244. }
  245. );
  246. };
  247. });