resourceDetailsCtrl.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. angular.module('push')
  2. .controller('resourceDetailsCtrl', function ($scope, ResourceLibraryService, $stateParams, SearchResultService, UtilService,
  3. ShareService, CommentService, $sce, $timeout, UserService, $ionicSlideBoxDelegate) {
  4. if ($scope.app) {
  5. $scope.setStatusBar(0);
  6. }
  7. //显示详情的资源库资源出现在列表中的次序
  8. $scope.order = $stateParams.order;
  9. $scope.reclib = $stateParams.reclib;
  10. //1:需求,2:成果,6:企业,8:人才
  11. var recourceid = $stateParams.recourceid;
  12. var recourcetype = $scope.type = $stateParams.recourcetype;
  13. var recourcecomefrom = $stateParams.recourcecomefrom;
  14. var categorylabel = $stateParams.categorylabel;
  15. $scope.userid = UserService.id;
  16. $scope.comment = {content: ""};
  17. // console.log($scope.imgUrl+$scope.image.$scope.photo_name);
  18. //获取相关资源
  19. $scope.getRelativeResource = function () {
  20. CommentService.getRelativeResource(0, $scope.resource.title, categorylabel, "", recourceid, "").then(function (response) {
  21. // console.log(response);
  22. $scope.relativelist = response.resourcelibrary;
  23. $scope.relativerecord = response.connectioninfoEntity;
  24. }, function () {
  25. })
  26. };
  27. var sharelink = "";
  28. //获取资源库列表
  29. var getPublicResourceList = function () {
  30. ResourceLibraryService.getResourceDetail(recourceid, recourcetype, recourcecomefrom).then(function (response) {
  31. // console.log(response);
  32. $scope.resource = response.res;
  33. $scope.getRelativeResource();
  34. $scope.contenthtml = $sce.trustAsHtml($scope.resource.content);
  35. if (angular.isDefined($scope.resource.cperlist) && $scope.resource.cperlist.length > 0) {
  36. $scope.modelstr = $scope.resource.cperlist.join(",");
  37. } else {
  38. $scope.modelstr = "";
  39. }
  40. sharelink = response.sharelink;
  41. }, function () {
  42. })
  43. };
  44. getPublicResourceList();
  45. //获取热门评论
  46. var getHotCommentList = function () {
  47. CommentService.getHotCommentList(recourceid, recourcetype).then(function (response) {
  48. // console.log(response);
  49. $scope.commentlist = response.res.comment;
  50. $scope.MoreComment = response.MoreComment;
  51. }, function () {
  52. })
  53. };
  54. getHotCommentList();
  55. $scope.shareflg = false;
  56. $scope.openShare = function () {
  57. $scope.shareflg = true;
  58. };
  59. $scope.closeShare = function () {
  60. $scope.shareflg = false;
  61. };
  62. //关注用户 --已经关注是1,未关注是2
  63. var focusflg = 0;
  64. $scope.focusUser = function () {
  65. if (focusflg != 0) {
  66. return;
  67. }
  68. focusflg = 1;
  69. var status = $scope.resource.Focus ? 1 : 2;
  70. SearchResultService.doFocus(status, $scope.resource.creator).then(function (response) {
  71. // console.log(response);
  72. if (response.status == true) {
  73. if ($scope.resource.Focus) {
  74. $scope.resource.Focus = false;
  75. UtilService.showMess("取消关注成功");
  76. } else {
  77. $scope.resource.Focus = true;
  78. UtilService.showMess("关注成功");
  79. }
  80. } else {
  81. UtilService.showMess("网络不给力,请重试");
  82. }
  83. $timeout(function () {
  84. focusflg = 0;
  85. }, 500);
  86. }, function () {
  87. focusflg = 0;
  88. UtilService.showMess("网络不给力,请重试");
  89. });
  90. };
  91. //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博
  92. $scope.shareMessage = function (type) {
  93. $scope.shareflg = false;
  94. $scope.showLoadingToast();
  95. CommentService.createShareRecord(sharelink, recourceid, recourcecomefrom, recourcetype).then(function (response) {
  96. // console.log(response);
  97. var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg";
  98. var tempcontent = $scope.resource.content.substring(0, 19);
  99. var message = {
  100. title: $scope.resource.title,
  101. description: tempcontent,
  102. url: response.shareurl,
  103. imageurl: imagurl
  104. };
  105. switch (type) {
  106. case 0:
  107. case 1:
  108. ShareService.shareToQQ(type, message).then(function () {
  109. UtilService.showMess("QQ分享成功");
  110. getCurrencyFromShare(response.clickid);
  111. $scope.hideLoadingToast();
  112. }, function (error) {
  113. UtilService.showMess(error);
  114. $scope.hideLoadingToast();
  115. });
  116. break;
  117. case 2:
  118. case 3:
  119. ShareService.shareToWechat(0, message).then(function () {
  120. UtilService.showMess("微信分享成功");
  121. getCurrencyFromShare(response.clickid);
  122. $scope.hideLoadingToast();
  123. }, function (error) {
  124. UtilService.showMess(error);
  125. $scope.hideLoadingToast();
  126. });
  127. break;
  128. case 4:
  129. ShareService.shareToWeibo(message).then(function () {
  130. UtilService.showMess("新浪微博分享成功");
  131. getCurrencyFromShare(response.clickid);
  132. $scope.hideLoadingToast();
  133. }, function (error) {
  134. UtilService.showMess(error);
  135. $scope.hideLoadingToast();
  136. });
  137. break;
  138. default:
  139. break;
  140. }
  141. $timeout(function () {
  142. $scope.hideLoadingToast();
  143. }, 10000);
  144. }, function () {
  145. $scope.hideLoadingToast();
  146. })
  147. };
  148. var getCurrencyFromShare = function (clickid) {
  149. CommentService.getCurrencyFromShare(clickid);
  150. };
  151. $scope.showbutton = true;
  152. //详情页评论
  153. $scope.showComment = true;
  154. $scope.publishComment = function () {
  155. $scope.showComment = true;
  156. var content = $scope.comment.content;
  157. //提交评论信息
  158. $scope.showLoadingToast();
  159. CommentService.publishComment(0, recourceid, recourcetype, "", "", content, recourcecomefrom).then(function () {
  160. UtilService.showMess("评论成功");
  161. $scope.comment.content = "";
  162. getHotCommentList();
  163. if ($scope.commentlist.length >= 3) {
  164. $timeout(function () {
  165. $scope.goCommentList();
  166. }, 650);
  167. }
  168. $scope.hideLoadingToast();
  169. }, function () {
  170. $scope.hideLoadingToast();
  171. });
  172. };
  173. //发表详细评论
  174. $scope.releaseComment = function () {
  175. $scope.go('releaseComment', {
  176. infoid: recourceid,
  177. infotype: recourcetype,
  178. comlen: $scope.commentlist.length,
  179. recourcecomefrom: recourcecomefrom
  180. })
  181. };
  182. //进入评论列表页
  183. $scope.goCommentList = function () {
  184. $timeout(function () {
  185. $scope.go('toolDiscuss', {
  186. infoid: recourceid,
  187. infotype: recourcetype,
  188. recourcecomefrom: recourcecomefrom
  189. });
  190. }, 350);
  191. };
  192. //进入相关资源详情
  193. $scope.goRelativeResource = function (relative) {
  194. if (relative.type == 81) {
  195. $scope.go('cloudDockingdetail', {infoid: relative.id, creator: relative.creator});
  196. } else {
  197. if (relative.groupid == "0") {
  198. $scope.go('resourceDetails', {
  199. recourceid: relative.unique,
  200. recourcetype: relative.type,
  201. recourcecomefrom: relative.source,
  202. categorylabel: categorylabel
  203. });
  204. } else {
  205. $scope.go('resourcePrivateDetails', {
  206. recourceid: relative.unique,
  207. recourcetype: relative.type,
  208. recourcecomefrom: relative.source,
  209. creator: relative.clickthrough
  210. });
  211. }
  212. }
  213. };
  214. //进入相关资源列表
  215. $scope.goResourceMatch = function (relative) {
  216. $scope.go('resourceMatch', {
  217. type: relative.type,
  218. title: $scope.resource.title,
  219. categorylabel: categorylabel
  220. });
  221. };
  222. //资源点赞
  223. var zydianzanflg = 0;
  224. $scope.dianZan = function () {
  225. if (zydianzanflg != 0) {
  226. return;
  227. }
  228. zydianzanflg = 1;
  229. CommentService.clickFavour(recourceid, recourcetype, $scope.resource.source, recourcecomefrom).then(function (response) {
  230. // console.log(response);
  231. if (response.favourState == 1) {
  232. $scope.resource.favourcount++;
  233. $scope.resource.Like = true;
  234. } else {
  235. $scope.resource.favourcount--;
  236. $scope.resource.Like = false;
  237. }
  238. // UtilService.showMess(response.clickStatus);
  239. $timeout(function () {
  240. zydianzanflg = 0;
  241. }, 500);
  242. }, function () {
  243. zydianzanflg = 0;
  244. UtilService.showMess("网络不给力,请重试");
  245. })
  246. };
  247. //评论点赞
  248. var pldianzanflg = 0;
  249. $scope.content_zan = function (comment, index) {
  250. if (pldianzanflg != 0) {
  251. return;
  252. }
  253. pldianzanflg = 1;
  254. CommentService.commentLike(comment.id, recourcetype).then(function (response) {
  255. // console.log(response);
  256. if (response.favourState == 1) {
  257. $scope.commentlist[index].favourcount++;
  258. $scope.commentlist[index].Like = true;
  259. } else {
  260. $scope.commentlist[index].favourcount--;
  261. $scope.commentlist[index].Like = false;
  262. }
  263. // UtilService.showMess(response.clickStatus);
  264. $timeout(function () {
  265. pldianzanflg = 0;
  266. }, 500);
  267. }, function () {
  268. pldianzanflg = 0;
  269. UtilService.showMess("网络不给力,请重试");
  270. })
  271. };
  272. //收藏
  273. var storeflg = 0;
  274. $scope.collectResource = function () {
  275. if (storeflg != 0) {
  276. return;
  277. }
  278. storeflg = 1;
  279. CommentService.collectResource(recourceid, recourcetype, $scope.resource.source, 1).then(function (response) {
  280. // console.log(response);
  281. if (response.clickStatus == "收藏成功") {
  282. $scope.resource.Enshrine = true;
  283. } else {
  284. $scope.resource.Enshrine = false;
  285. }
  286. UtilService.showMess(response.clickStatus);
  287. $timeout(function () {
  288. storeflg = 0;
  289. }, 500);
  290. }, function () {
  291. storeflg = 0;
  292. UtilService.showMess("网络不给力,请重试");
  293. })
  294. };
  295. //进入评论详情页
  296. $scope.goCommentDetail = function (comment) {
  297. $scope.go('resourceCommentReply', {
  298. comment: angular.toJson(comment),
  299. infoid: recourceid,
  300. infotype: recourcetype,
  301. recourcecomefrom: recourcecomefrom
  302. });
  303. };
  304. //点击强沙发
  305. $scope.hadSoft = function () {
  306. $scope.showComment = false;
  307. };
  308. $scope.showComment = true;
  309. $scope.focus_write = function () {
  310. $scope.showComment = false;
  311. $(".my_comment").focus();
  312. };
  313. $scope.hiddenComment = function () {
  314. $scope.showComment = true;
  315. };
  316. //弹出评论框
  317. $scope.commentValue = function () {
  318. var search_history = angular.element(document.getElementsByClassName("my_comment"));
  319. if ($scope.comment.content.length > 1000) {
  320. UtilService.showMess("您的评论已超过1000字!");
  321. $scope.comment.content = $scope.comment.content.substr(0, 1000);
  322. }
  323. if (search_history.val.length != 0) {
  324. $scope.commentNotnull = {
  325. "background-color": "#2a90d7",
  326. "text-decoration": "underline"
  327. };
  328. }
  329. };
  330. //删除自己刚刚发布或者以后的评论
  331. $scope.delectToolDis = function (commentid) {
  332. $scope.showLoadingToast();
  333. CommentService.deleteComment(commentid).then(function () {
  334. UtilService.showMess("删除成功");
  335. getHotCommentList();
  336. $scope.hideLoadingToast();
  337. }, function () {
  338. $scope.hideLoadingToast();
  339. });
  340. };
  341. //分享到我的资源库
  342. $scope.openCollectShare = function () {
  343. var tempres = [{
  344. infoid: recourceid,
  345. infocomefrom: recourcecomefrom,
  346. infoType: recourcetype
  347. }];
  348. $scope.go('chooseShareResource', {chereslist: angular.toJson(tempres)});
  349. };
  350. //点击图片放大
  351. $scope.bigImage = false; //初始默认大图是隐藏的
  352. $scope.hideBigImage = function () {
  353. $timeout(function () {
  354. if ($scope.app) {
  355. $scope.setStatusBar(0);
  356. }
  357. $scope.bigImage = false;
  358. }, 400);
  359. };
  360. $scope.shouBigImage = function (piclist, index) { //传递一个参数(图片的URl)
  361. if ($scope.app) {
  362. $scope.setStatusBar(1);
  363. }
  364. // console.log(piclist);
  365. // console.log(index);
  366. $scope.commentpiclist = piclist;
  367. $scope.bigImage = true; //显示大图
  368. // console.log(index);
  369. $(function () {
  370. $('div.pinch-zoom').each(function () {
  371. new RTP.PinchZoom($(this), {});
  372. });
  373. });
  374. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  375. //图片总数量
  376. setTimeout(function () {
  377. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  378. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  379. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  380. //获取图片
  381. var imgObj = document.getElementsByClassName('bigimage');
  382. var n;
  383. for (n = 0; n < imgObj.length; n++) {
  384. // 获取图片的原始高度和宽度
  385. var oldWid = imgObj[n].naturalWidth;
  386. var oldHei = imgObj[n].naturalHeight;
  387. var screen = document.body.offsetWidth;
  388. var screenH = window.innerHeight;
  389. // console.log(oldWid/oldHei);
  390. // console.log(screen );
  391. var rate = oldWid / oldHei;
  392. if (oldWid >= screen && oldHei >= screenH) {
  393. var tw = screen;
  394. var th = tw / rate;
  395. if (th < screenH) {
  396. imgObj[n].style.width = tw + 'px';
  397. imgObj[n].style.height = th + 'px';
  398. imgObj[n].style.marginTop = (screenH - th) / 2 + 'px';
  399. } else {
  400. imgObj[n].style.width = screenH * rate + 'px';
  401. imgObj[n].style.height = screenH + 'px';
  402. imgObj[n].style.marginLeft = (screen - screenH * rate) / 2 + 'px';
  403. }
  404. } else if (oldWid >= screen && oldHei <= screenH) {
  405. imgObj[n].style.width = screen + 'px';
  406. imgObj[n].style.height = screen / rate + 'px';
  407. imgObj[n].style.marginTop = (screenH - screen / rate) / 2 + 'px';
  408. } else if (oldWid <= screen && oldHei >= screenH) {
  409. // var hh=screenH;
  410. // var ww=screenH*rate;
  411. imgObj[n].style.width = screenH * rate + 'px';
  412. imgObj[n].style.height = screenH + 'px';
  413. imgObj[n].style.marginLeft = (screen - screenH * rate) / 2 + 'px';
  414. } else {
  415. imgObj[n].style.width = oldWid + 'px';
  416. imgObj[n].style.height = oldHei + 'px';
  417. imgObj[n].style.marginLeft = (screen - oldWid) / 2 + 'px';
  418. imgObj[n].style.marginTop = (screenH - oldHei) / 2 + 'px';
  419. }
  420. }
  421. }, 0);
  422. };
  423. //请求SDK权限
  424. $scope.loadImg = function (pic) {
  425. if (UtilService.checkPlatform()) {
  426. window.imagePicker.verifyStorage(
  427. function (results) {
  428. if (results == "1") {
  429. downloadPicture(pic);
  430. }
  431. }, function (error) {
  432. }
  433. );
  434. } else {
  435. downloadPicture(pic);
  436. }
  437. };
  438. //查看原图
  439. $scope.viewOldImg = function (index) {
  440. // console.log($scope.commentpiclist[index]);
  441. // console.log("查看原图" + index);
  442. var url = UtilService.isDefined($scope.commentpiclist[index].source_name) ? $scope.commentpiclist[index].source_name : $scope.commentpiclist[index].photo_name;
  443. $(".bigimage").eq(index).attr("src", $scope.imgUrl + url);
  444. $timeout(function () {
  445. $scope.commentpiclist[index].loadsource = true;
  446. }, 20);
  447. };
  448. //图片下载
  449. var downloadPicture = function (pic) {
  450. $scope.showLoadingToast();
  451. var fileTransfer = new FileTransfer();
  452. var url = UtilService.isDefined(pic.source_name) ? pic.source_name : pic.photo_name;
  453. var imgname = url.substring(url.lastIndexOf('/') + 1);//图片名称
  454. var loadurl = $scope.imgUrl + url;//图片下载地址
  455. var fileURL = "";//下载后的地址
  456. if (UtilService.checkPlatform()) {
  457. fileURL = cordova.file.externalRootDirectory + "pushpicture/" + imgname;
  458. } else {
  459. fileURL = cordova.file.documentsDirectory + imgname;
  460. }
  461. // console.log(loadurl);
  462. // console.log(fileURL);
  463. fileTransfer.download(
  464. loadurl,
  465. fileURL,
  466. function (entry) {
  467. // console.log(entry);
  468. if (UtilService.checkPlatform()) {
  469. var tempstr = entry.toURL().replace("file://", "");
  470. UtilService.showMess("图片下载成功,地址:" + tempstr);
  471. } else {
  472. UtilService.showMess("图片下载成功");
  473. }
  474. $scope.hideLoadingToast();
  475. },
  476. function (error) {
  477. // console.log(error);
  478. $scope.hideLoadingToast();
  479. UtilService.showMess("网络不给力,请重试");
  480. },
  481. null, // or, pass false
  482. {
  483. //headers: {
  484. // "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
  485. //}
  486. }
  487. );
  488. };
  489. //拨打电话
  490. $scope.openTel = function (tel) {
  491. window.open("tel:" + tel);
  492. };
  493. $scope.resDetailGoback = function () {
  494. if ($stateParams.comfrom == "privateResource") {
  495. $scope.go('privateResource', {
  496. libtype: $stateParams.reclibid,
  497. modlibid: $stateParams.moduleid,
  498. filterList: $stateParams.filterList
  499. })
  500. } else {
  501. $scope.goback();
  502. }
  503. }
  504. });