releaseCommentCtrl.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. angular.module('push')
  2. .controller('releaseCommentCtrl', function ($scope, CommentService, $stateParams, UtilService, $timeout, $ionicActionSheet, $ionicPopup,$ionicSlideBoxDelegate) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. var infoid = $stateParams.infoid;
  7. var infotype = $stateParams.infotype;
  8. $scope.infotype = infotype;
  9. var recourcecomefrom = $stateParams.recourcecomefrom;
  10. var comlen = $stateParams.comlen;
  11. $scope.maxlength = 8;
  12. $scope.progressLabels = [];
  13. $scope.imagelist = [];
  14. var tagid = 0;
  15. $scope.comment = {content: ""};
  16. $scope.choseindex = -1;
  17. $scope.blue = "";
  18. //评分
  19. $scope.starnum = 0;
  20. $scope.evaluateNum = function (num) {
  21. $scope.starnum = num;
  22. };
  23. //获取标签列表
  24. var getLabelList = function () {
  25. CommentService.getLabelList().then(function (response) {
  26. // console.log(response);
  27. $scope.progressLabels = response;
  28. }, function () {
  29. })
  30. };
  31. getLabelList();
  32. //展示所有标签
  33. $scope.showAllLabel = function () {
  34. $scope.maxlength = $scope.progressLabels.length;
  35. };
  36. $scope.checklength = function () {
  37. if ($scope.comment.content.length > 0) {
  38. $scope.blue = "toolReleaseButton_blue";
  39. } else {
  40. $scope.blue = "";
  41. }
  42. };
  43. //上传图片
  44. var tempimages = [];
  45. var uploadImages = function () {
  46. UtilService.uploadFile($scope.imagelist, 0, "image/jpeg").then(function (response) {
  47. // console.log(response);
  48. angular.forEach(response, function (value, index) {
  49. if (value.status) {
  50. tempimages.push({
  51. photo_name: value.userPhoto,
  52. original_name: value.originalPhoto,
  53. source_name: value.sourcePhoto,
  54. source_size:value.source_size
  55. });
  56. }
  57. });
  58. $timeout(function () {
  59. appDetailComment();
  60. }, 100)
  61. }, function () {
  62. relflg = 0;
  63. $scope.hideLoadingToast();
  64. UtilService.showMess("网络不给力,请重试");
  65. })
  66. };
  67. //发表评论
  68. var appDetailComment = function () {
  69. CommentService.appDetailComment(infoid, infotype, tagid, tempimages, $scope.comment.content, recourcecomefrom, $scope.starnum).then(function (response) {
  70. // console.log(response);
  71. UtilService.showMess("发布成功");
  72. $scope.starnum = 0;
  73. $timeout(function () {
  74. if (comlen < 3) {
  75. $scope.goback();
  76. } else {
  77. $scope.go('toolDiscuss', {infoid: infoid, infotype: infotype, comlen: comlen})
  78. }
  79. relflg = 0;
  80. }, 1500);
  81. $scope.hideLoadingToast();
  82. }, function () {
  83. $scope.hideLoadingToast();
  84. relflg = 0;
  85. UtilService.showMess("网络不给力,请重试");
  86. })
  87. };
  88. //点击发表
  89. var relflg = 0;
  90. $scope.releaseComment = function () {
  91. if ($scope.comment.content.length < 1) {
  92. return;
  93. }
  94. if (relflg != 0) {
  95. return;
  96. }
  97. relflg = 1;
  98. $scope.showLoadingToast();
  99. if ($scope.imagelist.length > 0) {
  100. uploadImages();
  101. } else {
  102. appDetailComment();
  103. }
  104. };
  105. //打开相机
  106. var openCamera = function () {
  107. if ($scope.imagelist.length >= 9) {
  108. UtilService.showMess("最多选取9张图片");
  109. return;
  110. }
  111. UtilService.getPicture(1).then(function (results) {
  112. $scope.imagelist.push(results);
  113. $scope.totalImglength = 600 * $scope.imagelist.length;
  114. }, function (err) {
  115. });
  116. };
  117. //检测相册权限
  118. var verifyStorage = function () {
  119. window.imagePicker.verifyStorage(
  120. function (results) {
  121. if (results == "1") {
  122. getPic();
  123. }
  124. }, function (error) {
  125. }
  126. );
  127. };
  128. //打开相册
  129. var getPic = function () {
  130. if ($scope.imagelist.length >= 9) {
  131. UtilService.showMess("最多选取9张图片");
  132. return;
  133. }
  134. UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
  135. // console.log(results);
  136. angular.forEach(results, function (value, index) {
  137. $scope.imagelist.push(value)
  138. });
  139. $scope.totalImglength = 600 * $scope.imagelist.length;
  140. }, function (err) {
  141. });
  142. };
  143. var getPictures = function () {
  144. if (device.platform == "Android") {
  145. verifyStorage();
  146. } else {
  147. getPic();
  148. }
  149. };
  150. //选择标签
  151. $scope.checkLable = function (id, index) {
  152. tagid = id;
  153. $scope.choseindex = index;
  154. };
  155. //添加照片
  156. $scope.toolPhotoAdd = function () {
  157. $ionicActionSheet.show({
  158. buttons: [
  159. {text: '<a class="action-sheet-push">拍照</a>'},
  160. {text: '<a class="action-sheet-push">从相册中选择</a>'}
  161. ],
  162. cancelText: '取消',
  163. buttonClicked: function (index) {
  164. if (index == 0) {
  165. openCamera();
  166. } else {
  167. getPictures();
  168. }
  169. return true;
  170. }
  171. });
  172. };
  173. //删除图片
  174. $scope.deletePhoto = function (index) {
  175. $scope.imagelist.splice(index, 1);
  176. };
  177. //点击图片放大
  178. $scope.bigImage = false; //初始默认大图是隐藏的
  179. $scope.hideBigImage = function () {
  180. $timeout(function () {
  181. if($scope.app){
  182. $scope.setStatusBar(0);
  183. }
  184. $scope.bigImage = false;
  185. }, 400);
  186. };
  187. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  188. if($scope.app){
  189. $scope.setStatusBar(0);
  190. }
  191. $(function () {
  192. $('div.pinch-zoom').each(function () {
  193. new RTP.PinchZoom($(this), {});
  194. });
  195. });
  196. $scope.bigImage = true; //显示大图
  197. // console.log(index);
  198. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  199. //图片总数量
  200. setTimeout(function () {
  201. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  202. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  203. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -5);
  204. // var nowIndex=parseInt($ionicSlideBoxDelegate.currentIndex());
  205. var totalIndex=parseInt($ionicSlideBoxDelegate.slidesCount());
  206. // console.log(index);
  207. $scope.nowIndex=index+1;
  208. $scope.totalIndex=totalIndex;
  209. //获取图片
  210. var imgObj = document.getElementsByClassName('bigimage');
  211. var n;
  212. for (n = 0; n < imgObj.length; n++) {
  213. // 获取图片的原始高度和宽度
  214. var oldWid = imgObj[n].naturalWidth;
  215. var oldHei = imgObj[n].naturalHeight;
  216. var screen = document.body.offsetWidth;
  217. var screenH = window.innerHeight;
  218. // console.log(oldWid/oldHei);
  219. // console.log(screen );
  220. var cc = screen / (oldWid / oldHei);
  221. imgObj[n].style.height = cc + 'px';
  222. if (cc < screenH) {
  223. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  224. // console.log("e:" + imgObj[n].style.marginTop);
  225. } else {
  226. imgObj[n].style.marginTop = 0 + 'px';
  227. // console.log((cc - screenH) + 'px')
  228. }
  229. }
  230. }, 0);
  231. };
  232. $scope.slideHasChanged=function(index){
  233. // console.log(index);
  234. $scope.nowIndex=index+1;
  235. };
  236. });