toolDiscussCtrl.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. angular.module('push')
  2. .controller('toolDiscussCtrl', function ($scope, $stateParams, CommentService, UtilService, $rootScope, UserService, $timeout, $ionicSlideBoxDelegate) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. //1:需求,2:成果,6:企业,8:人才
  7. var infoid = $stateParams.infoid;
  8. var infotype = $stateParams.infotype;
  9. $scope.infotype = infotype;
  10. var recourcecomefrom = $stateParams.recourcecomefrom;
  11. $rootScope.comlen = $stateParams.comlen;
  12. $scope.isedit = $stateParams.isedit;
  13. $scope.userid = UserService.id;
  14. $scope.comment = {content: ""};
  15. $scope.maxlength = 7;
  16. $scope.progressLabels = [];
  17. var first = true;
  18. $scope.choseindex = -1;
  19. //评分
  20. $scope.starnum = 0;
  21. $scope.evaluateNum = function (num) {
  22. $scope.starnum = num;
  23. };
  24. //获取评论列表
  25. var getCommentList = function (tagid) {
  26. $scope.showLoadingToast();
  27. CommentService.getCommentList(infoid, infotype, tagid).then(function (response) {
  28. // console.log(response);
  29. if (first) {
  30. $scope.progressLabels = response.tag;
  31. first = false;
  32. }
  33. $scope.commentlist = response.res.comment;
  34. $scope.hideLoadingToast();
  35. }, function () {
  36. $scope.hideLoadingToast();
  37. UtilService.showMess("网络不给力,请重试");
  38. })
  39. };
  40. getCommentList(-1);
  41. $scope.filterTag = function (tagid, index) {
  42. $scope.choseindex = index;
  43. getCommentList(tagid);
  44. };
  45. $scope.showAllLabel = function () {
  46. $scope.maxlength = $scope.progressLabels.length;
  47. };
  48. //评论点赞
  49. var pldianzanflg = 0;
  50. $scope.content_zan = function (comment, index) {
  51. if (pldianzanflg != 0) {
  52. return;
  53. }
  54. pldianzanflg = 1;
  55. CommentService.commentLike(comment.id, infotype).then(function (response) {
  56. // console.log(response);
  57. if (response.favourState == 1) {
  58. $scope.commentlist[index].favourcount++;
  59. $scope.commentlist[index].Like = true;
  60. } else {
  61. $scope.commentlist[index].favourcount--;
  62. $scope.commentlist[index].Like = false;
  63. }
  64. $timeout(function () {
  65. pldianzanflg = 0;
  66. }, 500);
  67. }, function () {
  68. pldianzanflg = 0;
  69. UtilService.showMess("网络不给力,请重试");
  70. })
  71. };
  72. $scope.goCommentDetail = function (comment) {
  73. $scope.go('resourceCommentReply', {
  74. comment: angular.toJson(comment),
  75. infoid: infoid,
  76. infotype: infotype,
  77. recourcecomefrom: recourcecomefrom,
  78. isedit: $scope.isedit
  79. });
  80. };
  81. //发表详细评论
  82. $scope.releaseComment = function () {
  83. $scope.go('releaseComment', {infoid: infoid, infotype: infotype, recourcecomefrom: recourcecomefrom})
  84. };
  85. $scope.goResourceSearch = function () {
  86. $timeout(function () {
  87. $scope.go('resourceSearchResult', {infoid: infoid, infotype: infotype, searchtype: 1, isedit: $scope.isedit})
  88. }, 350);
  89. };
  90. $scope.showComment = true;
  91. $scope.publishComment = function () {
  92. $scope.showComment = true;
  93. var content = $scope.comment.content;
  94. //提交评论信息
  95. $scope.showLoadingToast();
  96. CommentService.publishComment(0, infoid, infotype, "", "", content, recourcecomefrom, $scope.starnum).then(function () {
  97. getCommentList(-1);
  98. $scope.comment.content = "";
  99. $scope.starnum = 0;
  100. $scope.hideLoadingToast();
  101. }, function () {
  102. $scope.hideLoadingToast();
  103. });
  104. };
  105. $scope.backview = function () {
  106. if ($rootScope.comlen >= 3) {
  107. $scope.backViews(-2);
  108. } else {
  109. $scope.goback();
  110. }
  111. };
  112. //点击强沙发
  113. $scope.hadSoft = function () {
  114. $timeout(function () {
  115. $scope.showComment = false;
  116. }, 350);
  117. };
  118. $scope.focus_write = function () {
  119. $scope.showComment = false;
  120. $(".my_comment").focus();
  121. };
  122. $scope.hiddenComment = function () {
  123. $scope.showComment = true;
  124. };
  125. //弹出评论框
  126. $scope.commentValue = function () {
  127. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  128. if ($scope.comment.content.length > 1000) {
  129. UtilService.showMess("您的评论已超过1000字!");
  130. $scope.comment.content = $scope.comment.content.substr(0, 1000);
  131. }
  132. if (search_history.val.length != 0) {
  133. $scope.commentNotnull = {
  134. "background-color": "#2a90d7",
  135. "text-decoration": "underline"
  136. };
  137. }
  138. };
  139. //删除自己刚刚发布或者以后的评论
  140. $scope.delectToolDis = function (commentid) {
  141. $scope.showLoadingToast();
  142. CommentService.deleteComment(commentid).then(function () {
  143. UtilService.showMess("删除成功");
  144. getCommentList(-1);
  145. $scope.hideLoadingToast();
  146. }, function () {
  147. $scope.hideLoadingToast();
  148. });
  149. };
  150. //点击图片放大
  151. $scope.bigImage = false; //初始默认大图是隐藏的
  152. $scope.hideBigImage = function () {
  153. $timeout(function () {
  154. $scope.bigImage = false;
  155. }, 400);
  156. };
  157. $scope.shouBigImage = function (piclist, index) { //传递一个参数(图片的URl)
  158. $scope.bigImage = true; //显示大图
  159. $scope.commentpiclist = piclist;
  160. // console.log(index);
  161. $(function () {
  162. $('div.pinch-zoom').each(function () {
  163. new RTP.PinchZoom($(this), {});
  164. });
  165. });
  166. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  167. //图片总数量
  168. setTimeout(function () {
  169. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  170. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  171. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -5);
  172. // var nowIndex=parseInt($ionicSlideBoxDelegate.currentIndex());
  173. var totalIndex = parseInt($ionicSlideBoxDelegate.slidesCount());
  174. // console.log(index);
  175. $scope.nowIndex = index + 1;
  176. $scope.totalIndex = totalIndex;
  177. //获取图片
  178. var imgObj = document.getElementsByClassName('bigimage');
  179. var n;
  180. for (n = 0; n < imgObj.length; n++) {
  181. // 获取图片的原始高度和宽度
  182. var oldWid = imgObj[n].naturalWidth;
  183. var oldHei = imgObj[n].naturalHeight;
  184. var screen = document.body.offsetWidth;
  185. var screenH = window.innerHeight;
  186. // console.log(oldWid / oldHei);
  187. // console.log(screen);
  188. var cc = screen / (oldWid / oldHei);
  189. imgObj[n].style.height = cc + 'px';
  190. if (cc < screenH) {
  191. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  192. // console.log("e:" + imgObj[n].style.marginTop);
  193. } else {
  194. imgObj[n].style.marginTop = 0 + 'px';
  195. // console.log((cc - screenH) + 'px')
  196. }
  197. }
  198. }, 0);
  199. };
  200. //查看原图
  201. $scope.viewOldImg = function (index) {
  202. // console.log($scope.commentpiclist[index]);
  203. // console.log("查看原图" + index);
  204. var url = UtilService.isDefined($scope.commentpiclist[index].source_name) ? $scope.commentpiclist[index].source_name : $scope.commentpiclist[index].photo_name;
  205. $(".bigimage").eq(index).attr("src", $scope.imgUrl + url);
  206. $timeout(function () {
  207. $scope.commentpiclist[index].loadsource = true;
  208. }, 20);
  209. };
  210. //请求SDK权限
  211. $scope.loadImg = function (image) {
  212. if (UtilService.checkPlatform()) {
  213. window.imagePicker.verifyStorage(
  214. function (results) {
  215. if (results == "1") {
  216. downloadPicture(image);
  217. }
  218. }, function (error) {
  219. }
  220. );
  221. } else {
  222. downloadPicture(image);
  223. }
  224. };
  225. //图片下载
  226. var downloadPicture = function (image) {
  227. $scope.showLoadingToast();
  228. var fileTransfer = new FileTransfer();
  229. var url = UtilService.isDefined(image.source_name) ? image.source_name : image.photo_name;
  230. var imgname = url.substring(url.lastIndexOf('/') + 1);//图片名称
  231. var loadurl = $scope.imgUrl + url;//图片下载地址
  232. var fileURL = "";//下载后的地址
  233. if (UtilService.checkPlatform()) {
  234. fileURL = cordova.file.externalRootDirectory + "pushpicture/" + imgname;
  235. } else {
  236. fileURL = cordova.file.documentsDirectory + imgname;
  237. }
  238. // console.log(loadurl);
  239. // console.log(fileURL);
  240. fileTransfer.download(
  241. loadurl,
  242. fileURL,
  243. function (entry) {
  244. // console.log(entry);
  245. if (UtilService.checkPlatform()) {
  246. var tempstr = entry.toURL().replace("file://", "");
  247. UtilService.showMess("图片下载成功,地址:" + tempstr);
  248. } else {
  249. UtilService.showMess("图片下载成功");
  250. }
  251. $scope.hideLoadingToast();
  252. },
  253. function (error) {
  254. // console.log(error);
  255. $scope.hideLoadingToast();
  256. UtilService.showMess("网络不给力,请重试");
  257. },
  258. null, // or, pass false
  259. {
  260. //headers: {
  261. // "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
  262. //}
  263. }
  264. );
  265. };
  266. $scope.slideHasChanged = function (index) {
  267. // console.log(index);
  268. $scope.nowIndex = index + 1;
  269. };
  270. });