home.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. (function (app) {
  2. app.controller('homeCtrl', ["$scope", "$ionicTabsDelegate", "$http", 'config', "$state", "msg", "$ionicPopover", "homeService", "$ionicPopup", "$timeout", "$ionicSideMenuDelegate"
  3. , function ($scope, $ionicTabsDelegate, $http, config, $state, msg, $ionicPopover, homeService, $ionicPopup, $timeout, $ionicSideMenuDelegate) {
  4. $scope.$on('$ionicView.beforeEnter', function () {
  5. $ionicTabsDelegate.showBar(true);
  6. $scope.load(true);
  7. homeService.messageInfo().then(function(result){
  8. $scope.infos = result.data.data;
  9. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  10. $scope.showMessage=0;
  11. }
  12. else {
  13. $scope.showMessage=1;
  14. }
  15. },function(error){
  16. });
  17. });
  18. $scope.type = 'hot';//tab切换
  19. //$scope.chosedIndex = 0;
  20. $scope.clickAvatar = function(id){
  21. homeService.toUserDetail(id).then(function(result){
  22. $scope.items = result.data.data;
  23. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  24. },function(error){
  25. //msg.error(msg.data.error)
  26. });
  27. };
  28. $ionicPopover.fromTemplateUrl('my-popover.html', {
  29. scope: $scope
  30. }).then(function (popover) {
  31. $scope.popover = popover;
  32. });
  33. $scope.toggleLeftSideMenu = function () {
  34. $ionicSideMenuDelegate.toggleLeft();
  35. };
  36. $scope.openPopover = function ($event) {
  37. $scope.popover.show($event);
  38. };
  39. $scope.closePopover = function () {
  40. $scope.popover.hide();
  41. };
  42. $scope.changetype = function (type) {
  43. $scope.type = type;
  44. $scope.load(true);
  45. };
  46. $scope.toDetail = function (id) {
  47. $state.go('app.home_dreamdetail',{id:id});
  48. };
  49. $scope.toUserDetail = function (id) {
  50. homeService.toUserDetail(id).then(function(result){
  51. $scope.items = result.data.data;
  52. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  53. },function(error){
  54. //msg.error(msg.data.error)
  55. })
  56. };
  57. $scope.changeFilter = function (input) {
  58. switch (input) {
  59. case '1':
  60. if ($scope.filter.sex == 1) {
  61. $scope.filter.sex = 0;
  62. } else {
  63. $scope.filter.sex = 1;
  64. }
  65. break;
  66. case '2':
  67. if ($scope.filter.sex == 2) {
  68. $scope.filter.sex = 0;
  69. } else {
  70. $scope.filter.sex = 2;
  71. }
  72. break;
  73. default:
  74. }
  75. };
  76. $scope.filter = {
  77. hasMore: false,
  78. pageIndex: 1,
  79. pageSize: 20,
  80. sex: 0,//1男,2女,0:全部,
  81. age: 0,//0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>38,
  82. city:''
  83. };
  84. $scope.doFilter = function () {
  85. homeService.doFilter($scope.filter.sex,$scope.filter.age,$scope.filter.city).then(function(result){
  86. $scope.index.dreams = result.data.data.dreams.data;
  87. },function(error){
  88. msg.error(data.error.message);
  89. });
  90. //$ionicSideMenuDelegate.toggleRight();
  91. };
  92. $scope.index = {
  93. banner: [],
  94. users: [],
  95. dreams:[]
  96. };
  97. $scope.next = function (type) {
  98. //type:1 前一个,type:2 后一个
  99. if($scope.index.users.length>0){
  100. if(type==1)
  101. {
  102. var temp= $scope.index.users.splice(0,1);
  103. $scope.index.users.push(temp[0]);
  104. }
  105. if (type==2){
  106. var temp= $scope.index.users.splice($scope.index.users.length-1,1);
  107. $scope.index.users.unshift(temp[0]);
  108. }
  109. }
  110. };
  111. $scope.load = function (init) {
  112. if (init) {
  113. $scope.filter.pageIndex = 1;
  114. $scope.index.dreams = [];
  115. }
  116. msg.loading();
  117. homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
  118. msg.hide();
  119. $scope.index.banners = result.data.data.banners;
  120. $scope.index.users = result.data.data.users;
  121. $scope.filter.pageIndex++;
  122. var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
  123. $scope.filter.hasMore = more;
  124. $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
  125. if (init) {
  126. $scope.$broadcast('scroll.refreshComplete');
  127. } else {
  128. $scope.$broadcast('scroll.infiniteScrollComplete');
  129. }
  130. }, function (error) {
  131. msg.hide();
  132. });
  133. };
  134. $scope.qrscan = function () {
  135. cordova.plugins.barcodeScanner.scan(
  136. function (result) {
  137. //扫码成功后执行的回调函数
  138. alert("收到一个二维码\n" +
  139. "扫码文字结果: " + result.text + "\n" +
  140. "格式: " + result.format + "\n" +
  141. "是否在扫码页面取消扫码: " + result.cancelled);
  142. },
  143. function (error) {
  144. //扫码失败执行的回调函数
  145. alert("Scanning failed: " + error);
  146. }, {
  147. preferFrontCamera: false, // iOS and Android 设置前置摄像头
  148. showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
  149. showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
  150. torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
  151. prompt: "在扫描区域内放置二维码", // Android提示语
  152. resultDisplayDuration: 500, // Android, display scanned text for X ms.
  153. //0 suppresses it entirely, default 1500 设置扫码时间的参数
  154. formats: "QR_CODE", // 二维码格式可设置多种类型
  155. orientation: "portrait", // Android only (portrait|landscape),
  156. //default unset so it rotates with the device在安卓上 landscape 是横屏状态
  157. disableAnimations: true, // iOS 是否禁止动画
  158. disableSuccessBeep: false // iOS 禁止成功后提示声音 “滴”
  159. }
  160. );
  161. };
  162. $scope.data = {};
  163. //$scope.load(true);
  164. $scope.$on('$ionicView.beforeLeave', function () {
  165. $scope.popover.hide();
  166. $scope.load(true);
  167. });
  168. }]);
  169. app.controller('dreamDetailCtrl', ["$scope","$ionicHistory","$timeout", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  170. , function ($scope, $ionicHistory,$timeout,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
  171. var id = $stateParams.id;
  172. var top3user = '';
  173. $scope.chosedIndex = 0;
  174. $scope.clickAvatar = function (index) {
  175. $scope.chosedIndex = index;
  176. homeService.myInfo().then(function (result) {
  177. $scope.user = result.data.data;
  178. });
  179. };
  180. // id=5;
  181. $scope.$on('$ionicView.beforeEnter', function () {
  182. $ionicTabsDelegate.showBar(false);
  183. $scope.load(id);
  184. $scope.thisUser = storage.getObject('user');
  185. $scope.vm.payType = 2;
  186. homeService.myInfo().then(function(result){
  187. $scope.user = result.data.data;
  188. });
  189. homeService.messageInfo().then(function(result){
  190. $scope.infos = result.data.data;
  191. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  192. $scope.showMessage=0;
  193. }
  194. else {
  195. $scope.showMessage=1;
  196. }
  197. },function(error){
  198. });
  199. });
  200. $scope.$on('$ionicView.leave', function () {
  201. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  202. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  203. });
  204. $scope.toSort = function(){
  205. //$scope.type = 3;
  206. $scope.changeType(3)
  207. };
  208. $scope.load = function (id) {
  209. msg.loading();
  210. homeService.dreamDetail(id).then(function (result) {
  211. msg.hide();
  212. console.log(result);
  213. $scope.showCode = function(codeName){
  214. $scope.url = codeName;
  215. $scope.code = true;
  216. };
  217. $scope.hideCode = function(){
  218. $scope.code = false;
  219. };
  220. $scope.dream = result.data.data;
  221. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  222. $scope.codeBtn = true;
  223. }
  224. if($scope.dream.video){
  225. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  226. $scope.dream.video = config.imgServer+$scope.dream.video;
  227. }
  228. var reg = new RegExp("\n", "g");
  229. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  230. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  231. var date = new Date();
  232. var inter = (end_time.getTime() - date.getTime()) / 1000;
  233. leftTimer(inter);
  234. $scope.multi.a = $scope.dream.a;
  235. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  236. $scope.multi.c = $scope.dream.c;
  237. $scope.multi.promise = $scope.dream.a;
  238. var newtop3user = '' ;
  239. angular.forEach($scope.dream.top3user, function(user) {
  240. newtop3user= newtop3user +user.id+","
  241. });
  242. if(top3user!=''&&newtop3user!=top3user){
  243. //测试动画切换
  244. $timeout(function() {
  245. $scope.sort.slide1 = 'list-grow-animation';
  246. $scope.sort.slide2 = 'slide-in-both-ways';
  247. $scope.sort.slide3 = 'bounce-animation';
  248. }, 50);
  249. }
  250. top3user = newtop3user;
  251. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  252. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  253. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  254. $scope.calcmultiplier();
  255. }, function (error) {
  256. msg.hide();
  257. });
  258. };
  259. $scope.openSupport = function () {
  260. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  261. };
  262. $scope.multi = {
  263. a: '',
  264. b: '',
  265. c: '',
  266. result: 1,
  267. promise:null
  268. };
  269. $scope.type = 1;//tab切换
  270. $scope.tosupport = false;
  271. $scope.support = function ($event) {
  272. $event.stopPropagation();
  273. $scope.tosupport = true;
  274. $scope.vm.coin = 0;
  275. $scope.index = 0;
  276. };
  277. $scope.cancelSupport = function () {
  278. $scope.tosupport = false;
  279. $scope.toshare = false;
  280. $scope.input.show = false;
  281. };
  282. $scope.toshare = false;
  283. $scope.toRecharge = function(){
  284. $state.go("app.recharge")
  285. };
  286. $scope.share = function (type,$event) {
  287. $scope.toshare = true;
  288. if (type==0) {//分享给朋友
  289. /* Wechat.share({
  290. text: "分享的文字",
  291. scene: Wechat.Scene.SESSION // share to 好友
  292. }, function () {
  293. alert("Success");
  294. }, function (reason) {
  295. alert("Failed: " + reason);
  296. });*/
  297. Wechat.share({
  298. message: {
  299. /*title:"瞄瞄",
  300. description:"HELLO,这是我的梦想,快来围观吧!",
  301. thumb:"img/icon_cat_h.png",*/
  302. title: $scope.dream.name,
  303. description: $scope.dream.about,
  304. thumb: "http://q8.9026.com/attachment//base/img/share/icon_cat_h.png",
  305. media: {
  306. type: Wechat.Type.WEBPAGE,
  307. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  308. }
  309. },
  310. scene: Wechat.Scene.SESSION
  311. }, function () {
  312. alert("Success");
  313. }, function (reason) {
  314. alert("Failed: " + reason);
  315. });
  316. }
  317. if(type==1){
  318. Wechat.share({
  319. message: {
  320. /*title:"瞄瞄",
  321. description:"HELLO,这是我的梦想,快来围观吧!",
  322. thumb:"img/icon_cat_h.png",*/
  323. title: $scope.dream.name,
  324. description: $scope.dream.about,
  325. thumb: "http://q8.9026.com/attachment//base/img/share/icon_cat_h.png",
  326. media: {
  327. type: Wechat.Type.WEBPAGE,
  328. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  329. }
  330. },
  331. scene: Wechat.Scene.TIMELINE
  332. }, function () {
  333. alert("Success");
  334. }, function (reason) {
  335. alert("Failed: " + reason);
  336. });
  337. }
  338. // $state.go("app.shareDream",{item:$scope.dream});
  339. };
  340. //实时排行
  341. $scope.sort = {
  342. slide: ''
  343. };
  344. $scope.changeType = function (type) {
  345. $ionicScrollDelegate.scrollTop(true);
  346. $scope.type = type;
  347. };
  348. $scope.index = 0;
  349. $scope.vm = {
  350. coin:"",
  351. title:""
  352. };
  353. $scope.timer = '';
  354. var leftTimer = function (countDown) {
  355. if (isNaN(countDown)) {
  356. $scope.timer = '已结束';
  357. return;
  358. }
  359. var day=parseInt(countDown/(24*60*60));
  360. var h=parseInt(countDown/(60*60)%24);
  361. var m=parseInt(countDown/60%60);
  362. var s=parseInt(countDown%60);
  363. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  364. if(day>0) $scope.timer = day+'天';
  365. if(day<0 && h>0) $scope.timer = h+'小时';
  366. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  367. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  368. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  369. $scope.leftTimer = $interval(function () {
  370. if (countDown >= 1) leftTimer(countDown - 1);
  371. },1000);*/
  372. /*if(countDown<=0){
  373. $scope.timer='结束';
  374. }*/
  375. };
  376. $scope.changeIndex = function (index) {
  377. $scope.index = index;
  378. $scope.vm.coin = index*10;
  379. };
  380. $scope.vidEnded = function () {
  381. alert('播放完毕');
  382. };
  383. //实时计算支持乘数
  384. $scope.calcmultiplier = function () {
  385. $scope.multi.promise = $interval(function () {
  386. var date = new Date();
  387. var inter = date.getTime() - $scope.multi.b.getTime();
  388. var minutes = Math.floor(inter / (60 * 1000));
  389. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  390. if (number<=1) {
  391. number = 1;
  392. }
  393. //$scope.multi.result = Math.round(number * 100) / 100;
  394. $scope.multi.result = Math.round(number * 100 / 100);
  395. },1000);
  396. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  397. };
  398. $scope.supportDream = function (data) {
  399. if(!$scope.vm.coin){
  400. msg.error("请选择梦想币数量!");
  401. return ;
  402. }
  403. var data = {
  404. id:id,
  405. coin:$scope.vm.coin
  406. };
  407. homeService.supportDream(data).then(function(result){
  408. $scope.tosupport = false;
  409. $scope.load(id);
  410. homeService.myInfo().then(function(result){
  411. $scope.user = result.data.data;
  412. });
  413. $interval.cancel($scope.multi.promise);
  414. msg.text("发送成功");
  415. })
  416. };
  417. $scope.collectionDream = function(is_collection){
  418. homeService.collectionDream(id,is_collection).then(function(result){
  419. $scope.dream.is_collection=result.data.data;
  420. })
  421. };
  422. $scope.add = function(is_collection){
  423. var data = {
  424. id:id,
  425. title:$scope.vm.title,
  426. pics:$scope.imgs,
  427. video:$scope.video.server
  428. };
  429. homeService.add_interaction(data).then(function(){
  430. $scope.load(id);
  431. $scope.closeModal();
  432. })
  433. };
  434. $scope.showAbout = true;
  435. $scope.hideAbout = false;
  436. $scope.showText = function(){
  437. $scope.aboutStyle = {
  438. "white-space" : "normal"
  439. };
  440. $scope.showAbout = false;
  441. $scope.hideAbout = true;
  442. };
  443. $scope.hideText = function(){
  444. $scope.aboutStyle = {
  445. "white-space" : "nowrap"
  446. };
  447. $scope.showAbout = true;
  448. $scope.hideAbout = false;
  449. };
  450. $scope.input = {
  451. placeholder: '评论',
  452. focus: false,
  453. show:false
  454. };
  455. $scope.showmore = function (index) {
  456. if ($scope.dream.interactions[index].showmore) {
  457. $scope.dream.interactions[index].showmore = false;
  458. } else {
  459. $scope.dream.interactions[index].showmore = true;
  460. }
  461. }
  462. $scope.replay = function ($event, name, index) {
  463. $event.stopPropagation();
  464. $scope.input.focus = true;
  465. $scope.input.show = true;
  466. angular.forEach($scope.dream.interactions, function (item) {
  467. item.show = false;
  468. })
  469. $scope.dream.interactions[index].show = true;
  470. $scope.input.placeholder = "评论" + name+":";
  471. $scope.vm.title='';
  472. }
  473. $scope.replayOther = function ($event, name, index,currentindex) {
  474. $event.stopPropagation();
  475. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  476. $scope.input.focus = true;
  477. $scope.input.show = true;
  478. angular.forEach($scope.dream.interactions, function (item) {
  479. item.show = false;
  480. })
  481. $scope.dream.interactions[index].show = true;
  482. $scope.input.placeholder = "评论" + name+":";
  483. $scope.vm.title='';
  484. }
  485. else {
  486. msg.confirm("评论","是否删除评论").then(function(result){
  487. if(result==true)
  488. {
  489. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  490. msg.text("删除成功");
  491. $scope.load(id);
  492. },function(error){
  493. msg.error(error.data.message);
  494. })
  495. }
  496. });
  497. }
  498. };
  499. $scope.testcharge = function(number){
  500. if (!number) {
  501. msg.text('请输入充值金额');
  502. return;
  503. }
  504. homeService.testcharge(number,2).then(function (result) {
  505. msg.text("充值成功");
  506. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  507. $timeout(function () {
  508. $scope.closeRechargeModal();
  509. }, 500);
  510. homeService.myInfo().then(function (result) {
  511. $scope.user = result.data.data;
  512. });
  513. })
  514. }
  515. //充值
  516. $scope.charge = function(number){
  517. if (!number) {
  518. msg.text('请输入充值金额');
  519. return;
  520. }
  521. homeService.charge(number,2).then(function (result) {
  522. //todo:result需要返回支付宝或者微信的签名信息
  523. console.log("result: " + JSON.stringify(result));
  524. var payInfo = result.data;
  525. if ($scope.vm.payType == 1) { //支付宝
  526. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  527. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  528. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  529. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  530. //当e.resultStatus为9000时,请去服务端验证支付结果
  531. $scope.clicksub = false;
  532. if (e.resultStatus == '9000') {
  533. alert(orderID);
  534. //支付成功
  535. // $state.go('app.my');
  536. } else {
  537. msg.error("支付失败");
  538. // msg.error("支付失败:" + JSON.stringify(e));
  539. }
  540. }, function error(e) {
  541. $scope.clicksub = false;
  542. // msg.error("支付失败:" + JSON.stringify(e));
  543. msg.error("支付失败");
  544. });
  545. }
  546. if ($scope.vm.payType == 2) { //微信
  547. var obj = JSON.parse(payInfo);
  548. var params = {
  549. partnerid: obj.partnerid, // merchant id
  550. prepayid: obj.prepayid, // prepay id
  551. noncestr: obj.noncestr, // nonce
  552. timestamp: obj.timestamp, // timestamp
  553. sign: obj.sign, // signed string
  554. };
  555. Wechat.sendPaymentRequest(params, function (r) {
  556. $scope.clicksub = false;
  557. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  558. // alert(result);
  559. //支付成功
  560. // $state.go('app.my');
  561. }, function (erro) {
  562. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  563. });
  564. }, function (reason) {
  565. $scope.clicksub = false;
  566. msg.alert("支付失败:" + JSON.stringify(reason));
  567. });
  568. }
  569. // msg.text("充值成功");
  570. // $state.go('app.my');
  571. });
  572. }
  573. $scope.submitComment = function (index) {
  574. var interaction = $scope.dream.interactions[index];
  575. var iid = interaction.id;
  576. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  577. $scope.input.focus = true;
  578. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  579. var data = {
  580. id:iid,
  581. content:$scope.vm.comment
  582. };
  583. console.log($scope.vm.comment+" "+iid);
  584. homeService.add_comment(data).then(function(){
  585. $scope.vm.comment = '' ;
  586. $scope.load(id);
  587. $scope.closeModal();
  588. })
  589. };
  590. $scope.bigImage = false;
  591. $scope.showBigImage = function ($event, imageName) {
  592. $event.stopPropagation();
  593. $scope.url = imageName;
  594. $scope.bigImage = true;
  595. };
  596. $scope.hideBigImage = function(){
  597. $scope.bigImage = false;
  598. };
  599. $ionicModal.fromTemplateUrl('qrCode.html', {
  600. scope: $scope,
  601. animation: 'slide-in-up'
  602. }).then(function(modal) {
  603. $scope.qrCodemodal = modal;
  604. });
  605. $scope.openCode = function() {
  606. $scope.qrCodemodal.show();
  607. $scope.vm.money = '';
  608. };
  609. $scope.closeCode = function() {
  610. $scope.qrCodemodal.hide();
  611. };
  612. $ionicModal.fromTemplateUrl('commentPic.html', {
  613. scope: $scope,
  614. animation: 'slide-in-up'
  615. }).then(function(modal) {
  616. $scope.CommentPicmodal = modal;
  617. });
  618. $scope.openCommentPic = function(pic) {
  619. $scope.CommentPicmodal.show();
  620. $scope.commentPicUrl = pic;
  621. };
  622. $scope.closeCommentPic = function() {
  623. $scope.CommentPicmodal.hide();
  624. };
  625. $scope.addpict = function () {
  626. common.chooseImage().then(function (img) {
  627. common.uploadFiles(img,1).then(function (result) {
  628. var response = JSON.parse(result.response);
  629. var file = response.data.file;
  630. $scope.imgs.push(config.imgServer+file);
  631. console.log(JSON.stringify(config.imgServer+file));
  632. }, function (error) {
  633. msg.error('图片上传失败');
  634. });
  635. }, function (error) {
  636. console.log('图片选择失败');
  637. });
  638. };
  639. $scope.deletefile = function (file) {
  640. var index = $scope.imgs.indexOf(file);
  641. $scope.imgs.splice(index, 1);
  642. common.deletefile(file).then(function () {
  643. })
  644. };
  645. $scope.addvideo = function () {
  646. common.chooseVideo().then(function (file) {
  647. common.uploadFiles(file, 2).then(function (result) {
  648. var response = JSON.parse(result.response);
  649. $scope.video.server = response.data.file;
  650. var file = config.imgServer+response.data.file;
  651. console.log("file:"+file);
  652. $scope.video.isOK = true;
  653. $scope.video.file = file;
  654. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  655. console.log("vpic:"+$scope.video.vpic);
  656. }, function (error) {
  657. msg.error('视频上传失败');
  658. });
  659. }, function (erro) {
  660. console.log('选择视频失败');
  661. });
  662. };
  663. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  664. scope: $scope,
  665. animation: 'slide-in-up'
  666. }).then(function(modal) {
  667. $scope.rechagemodal = modal;
  668. });
  669. $scope.openRechargeModal = function() {
  670. $scope.rechagemodal.show();
  671. $scope.vm.money = '';
  672. };
  673. $scope.closeRechargeModal = function() {
  674. $scope.rechagemodal.hide();
  675. };
  676. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  677. scope: $scope,
  678. animation: 'slide-in-up'
  679. }).then(function(modal) {
  680. $scope.modal = modal;
  681. });
  682. $scope.openModal = function() {
  683. $scope.modal.show();
  684. $scope.vm.title = '';
  685. $scope.imgs = [];
  686. $scope.video = {};
  687. };
  688. $scope.closeModal = function() {
  689. $scope.modal.hide();
  690. };
  691. //当我们用到模型时,清除它!
  692. $scope.$on('$destroy', function() {
  693. $scope.modal.remove();
  694. });
  695. $scope.toMessage = function(){
  696. $state.go("app.message");
  697. }
  698. }]);
  699. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  700. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  701. var id = $stateParams.id;
  702. var top3user = '';
  703. $scope.chosedIndex = 0;
  704. $scope.clickAvatar = function (index) {
  705. $scope.chosedIndex = index;
  706. homeService.myInfo().then(function (result) {
  707. $scope.user = result.data.data;
  708. });
  709. };
  710. // id=5;
  711. $scope.$on('$ionicView.beforeEnter', function () {
  712. $ionicTabsDelegate.showBar(false);
  713. $scope.load(id);
  714. $scope.thisUser = storage.getObject('user');
  715. $scope.vm.payType = 2;
  716. homeService.myInfo().then(function(result){
  717. $scope.user = result.data.data;
  718. });
  719. homeService.messageInfo().then(function(result){
  720. $scope.infos = result.data.data;
  721. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  722. $scope.showMessage=0;
  723. }
  724. else {
  725. $scope.showMessage=1;
  726. }
  727. },function(error){
  728. });
  729. });
  730. $scope.$on('$ionicView.leave', function () {
  731. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  732. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  733. });
  734. $scope.toSort = function(){
  735. //$scope.type = 3;
  736. $scope.changeType(3)
  737. };
  738. $scope.load = function (id) {
  739. msg.loading();
  740. homeService.dreamDetail(id).then(function (result) {
  741. msg.hide();
  742. console.log(result);
  743. $scope.showCode = function(codeName){
  744. $scope.url = codeName;
  745. $scope.code = true;
  746. };
  747. $scope.hideCode = function(){
  748. $scope.code = false;
  749. };
  750. $scope.dream = result.data.data;
  751. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  752. $scope.codeBtn = true;
  753. }
  754. if($scope.dream.video){
  755. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  756. $scope.dream.video = config.imgServer+$scope.dream.video;
  757. }
  758. var reg = new RegExp("\n", "g");
  759. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  760. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  761. var date = new Date();
  762. var inter = (end_time.getTime() - date.getTime()) / 1000;
  763. leftTimer(inter);
  764. $scope.multi.a = $scope.dream.a;
  765. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  766. $scope.multi.c = $scope.dream.c;
  767. $scope.multi.promise = $scope.dream.a;
  768. var newtop3user = '' ;
  769. angular.forEach($scope.dream.top3user, function(user) {
  770. newtop3user= newtop3user +user.id+","
  771. });
  772. if(top3user!=''&&newtop3user!=top3user){
  773. //测试动画切换
  774. $timeout(function() {
  775. $scope.sort.slide1 = 'list-grow-animation';
  776. $scope.sort.slide2 = 'slide-in-both-ways';
  777. $scope.sort.slide3 = 'bounce-animation';
  778. }, 50);
  779. }
  780. top3user = newtop3user;
  781. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  782. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  783. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  784. $scope.calcmultiplier();
  785. }, function (error) {
  786. msg.hide();
  787. });
  788. };
  789. $scope.openSupport = function () {
  790. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  791. };
  792. $scope.multi = {
  793. a: '',
  794. b: '',
  795. c: '',
  796. result: 1,
  797. promise:null
  798. };
  799. $scope.type = 1;//tab切换
  800. $scope.tosupport = false;
  801. $scope.support = function ($event) {
  802. $event.stopPropagation();
  803. $scope.tosupport = true;
  804. $scope.vm.coin = 0;
  805. $scope.index = 0;
  806. };
  807. $scope.cancelSupport = function () {
  808. $scope.tosupport = false;
  809. $scope.toshare = false;
  810. $scope.input.show = false;
  811. };
  812. $scope.toshare = false;
  813. $scope.toRecharge = function(){
  814. $state.go("app.recharge")
  815. };
  816. $scope.share = function (type,$event) {
  817. $scope.toshare = true;
  818. if (type==0) {//分享给朋友
  819. /* Wechat.share({
  820. text: "分享的文字",
  821. scene: Wechat.Scene.SESSION // share to 好友
  822. }, function () {
  823. alert("Success");
  824. }, function (reason) {
  825. alert("Failed: " + reason);
  826. });*/
  827. Wechat.share({
  828. message: {
  829. /*title:"瞄瞄",
  830. description:"HELLO,这是我的梦想,快来围观吧!",
  831. thumb:"img/icon_cat_h.png",*/
  832. title: $scope.dream.name,
  833. description: $scope.dream.about,
  834. thumb: "http://q8.9026.com/attachment//base/img/share/icon_cat_h.png",
  835. media: {
  836. type: Wechat.Type.WEBPAGE,
  837. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  838. }
  839. },
  840. scene: Wechat.Scene.SESSION
  841. }, function () {
  842. alert("Success");
  843. }, function (reason) {
  844. alert("Failed: " + reason);
  845. });
  846. }
  847. if(type==1){
  848. Wechat.share({
  849. message: {
  850. /*title:"瞄瞄",
  851. description:"HELLO,这是我的梦想,快来围观吧!",
  852. thumb:"img/icon_cat_h.png",*/
  853. title: $scope.dream.name,
  854. description: $scope.dream.about,
  855. thumb: "http://q8.9026.com/attachment//base/img/share/icon_cat_h.png",
  856. media: {
  857. type: Wechat.Type.WEBPAGE,
  858. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  859. }
  860. },
  861. scene: Wechat.Scene.TIMELINE
  862. }, function () {
  863. alert("Success");
  864. }, function (reason) {
  865. alert("Failed: " + reason);
  866. });
  867. }
  868. // $state.go("app.shareDream",{item:$scope.dream});
  869. };
  870. //实时排行
  871. $scope.sort = {
  872. slide: ''
  873. };
  874. $scope.changeType = function (type) {
  875. $ionicScrollDelegate.scrollTop(true);
  876. $scope.type = type;
  877. };
  878. $scope.index = 0;
  879. $scope.vm = {
  880. coin:"",
  881. title:""
  882. };
  883. $scope.timer = '';
  884. var leftTimer = function (countDown) {
  885. if (isNaN(countDown)) {
  886. $scope.timer = '已结束';
  887. return;
  888. }
  889. var day=parseInt(countDown/(24*60*60));
  890. var h=parseInt(countDown/(60*60)%24);
  891. var m=parseInt(countDown/60%60);
  892. var s=parseInt(countDown%60);
  893. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  894. if(day>0) $scope.timer = day+'天';
  895. if(day<0 && h>0) $scope.timer = h+'小时';
  896. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  897. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  898. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  899. $scope.leftTimer = $interval(function () {
  900. if (countDown >= 1) leftTimer(countDown - 1);
  901. },1000);*/
  902. /*if(countDown<=0){
  903. $scope.timer='结束';
  904. }*/
  905. };
  906. $scope.changeIndex = function (index) {
  907. $scope.index = index;
  908. $scope.vm.coin = index*10;
  909. };
  910. $scope.vidEnded = function () {
  911. alert('播放完毕');
  912. };
  913. //实时计算支持乘数
  914. $scope.calcmultiplier = function () {
  915. $scope.multi.promise = $interval(function () {
  916. var date = new Date();
  917. var inter = date.getTime() - $scope.multi.b.getTime();
  918. var minutes = Math.floor(inter / (60 * 1000));
  919. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  920. if (number<=1) {
  921. number = 1;
  922. }
  923. //$scope.multi.result = Math.round(number * 100) / 100;
  924. $scope.multi.result = Math.round(number * 100 / 100);
  925. },1000);
  926. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  927. };
  928. $scope.supportDream = function (data) {
  929. if(!$scope.vm.coin){
  930. msg.error("请选择梦想币数量!");
  931. return ;
  932. }
  933. var data = {
  934. id:id,
  935. coin:$scope.vm.coin
  936. };
  937. homeService.supportDream(data).then(function(result){
  938. $scope.tosupport = false;
  939. $scope.load(id);
  940. homeService.myInfo().then(function(result){
  941. $scope.user = result.data.data;
  942. });
  943. $interval.cancel($scope.multi.promise);
  944. msg.text("发送成功");
  945. })
  946. };
  947. $scope.collectionDream = function(is_collection){
  948. homeService.collectionDream(id,is_collection).then(function(result){
  949. $scope.dream.is_collection=result.data.data;
  950. })
  951. };
  952. $scope.add = function(is_collection){
  953. var data = {
  954. id:id,
  955. title:$scope.vm.title,
  956. pics:$scope.imgs,
  957. video:$scope.video.server
  958. };
  959. homeService.add_interaction(data).then(function(){
  960. $scope.load(id);
  961. $scope.closeModal();
  962. })
  963. };
  964. $scope.showAbout = true;
  965. $scope.hideAbout = false;
  966. $scope.showText = function(){
  967. $scope.aboutStyle = {
  968. "white-space" : "normal"
  969. };
  970. $scope.showAbout = false;
  971. $scope.hideAbout = true;
  972. };
  973. $scope.hideText = function(){
  974. $scope.aboutStyle = {
  975. "white-space" : "nowrap"
  976. };
  977. $scope.showAbout = true;
  978. $scope.hideAbout = false;
  979. };
  980. $scope.input = {
  981. placeholder: '评论',
  982. focus: false,
  983. show:false
  984. };
  985. $scope.showmore = function (index) {
  986. if ($scope.dream.interactions[index].showmore) {
  987. $scope.dream.interactions[index].showmore = false;
  988. } else {
  989. $scope.dream.interactions[index].showmore = true;
  990. }
  991. }
  992. $scope.replay = function ($event, name, index) {
  993. $event.stopPropagation();
  994. $scope.input.focus = true;
  995. $scope.input.show = true;
  996. angular.forEach($scope.dream.interactions, function (item) {
  997. item.show = false;
  998. })
  999. $scope.dream.interactions[index].show = true;
  1000. $scope.input.placeholder = "评论" + name+":";
  1001. $scope.vm.title='';
  1002. }
  1003. $scope.replayOther = function ($event, name, index,currentindex) {
  1004. $event.stopPropagation();
  1005. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  1006. $scope.input.focus = true;
  1007. $scope.input.show = true;
  1008. angular.forEach($scope.dream.interactions, function (item) {
  1009. item.show = false;
  1010. })
  1011. $scope.dream.interactions[index].show = true;
  1012. $scope.input.placeholder = "评论" + name+":";
  1013. $scope.vm.title='';
  1014. }
  1015. else {
  1016. msg.confirm("评论","是否删除评论").then(function(result){
  1017. if(result==true)
  1018. {
  1019. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  1020. msg.text("删除成功");
  1021. $scope.load(id);
  1022. },function(error){
  1023. msg.error(error.data.message);
  1024. })
  1025. }
  1026. });
  1027. }
  1028. };
  1029. $scope.testcharge = function(number){
  1030. if (!number) {
  1031. msg.text('请输入充值金额');
  1032. return;
  1033. }
  1034. homeService.testcharge(number,2).then(function (result) {
  1035. msg.text("充值成功");
  1036. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  1037. $timeout(function () {
  1038. $scope.closeRechargeModal();
  1039. }, 500);
  1040. homeService.myInfo().then(function (result) {
  1041. $scope.user = result.data.data;
  1042. });
  1043. })
  1044. }
  1045. //充值
  1046. $scope.charge = function(number){
  1047. if (!number) {
  1048. msg.text('请输入充值金额');
  1049. return;
  1050. }
  1051. homeService.charge(number,2).then(function (result) {
  1052. //todo:result需要返回支付宝或者微信的签名信息
  1053. console.log("result: " + JSON.stringify(result));
  1054. var payInfo = result.data;
  1055. if ($scope.vm.payType == 1) { //支付宝
  1056. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  1057. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  1058. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  1059. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  1060. //当e.resultStatus为9000时,请去服务端验证支付结果
  1061. $scope.clicksub = false;
  1062. if (e.resultStatus == '9000') {
  1063. alert(orderID);
  1064. //支付成功
  1065. // $state.go('app.my');
  1066. } else {
  1067. msg.error("支付失败");
  1068. // msg.error("支付失败:" + JSON.stringify(e));
  1069. }
  1070. }, function error(e) {
  1071. $scope.clicksub = false;
  1072. // msg.error("支付失败:" + JSON.stringify(e));
  1073. msg.error("支付失败");
  1074. });
  1075. }
  1076. if ($scope.vm.payType == 2) { //微信
  1077. var obj = JSON.parse(payInfo);
  1078. var params = {
  1079. partnerid: obj.partnerid, // merchant id
  1080. prepayid: obj.prepayid, // prepay id
  1081. noncestr: obj.noncestr, // nonce
  1082. timestamp: obj.timestamp, // timestamp
  1083. sign: obj.sign, // signed string
  1084. };
  1085. Wechat.sendPaymentRequest(params, function (r) {
  1086. $scope.clicksub = false;
  1087. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  1088. // alert(result);
  1089. //支付成功
  1090. // $state.go('app.my');
  1091. }, function (erro) {
  1092. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  1093. });
  1094. }, function (reason) {
  1095. $scope.clicksub = false;
  1096. msg.alert("支付失败:" + JSON.stringify(reason));
  1097. });
  1098. }
  1099. // msg.text("充值成功");
  1100. // $state.go('app.my');
  1101. });
  1102. }
  1103. $scope.submitComment = function (index) {
  1104. var interaction = $scope.dream.interactions[index];
  1105. var iid = interaction.id;
  1106. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  1107. $scope.input.focus = true;
  1108. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  1109. var data = {
  1110. id:iid,
  1111. content:$scope.vm.comment
  1112. };
  1113. console.log($scope.vm.comment+" "+iid);
  1114. homeService.add_comment(data).then(function(){
  1115. $scope.vm.comment = '' ;
  1116. $scope.load(id);
  1117. $scope.closeModal();
  1118. })
  1119. };
  1120. $scope.bigImage = false;
  1121. $scope.showBigImage = function ($event, imageName) {
  1122. $event.stopPropagation();
  1123. $scope.url = imageName;
  1124. $scope.bigImage = true;
  1125. };
  1126. $scope.hideBigImage = function(){
  1127. $scope.bigImage = false;
  1128. };
  1129. $ionicModal.fromTemplateUrl('qrCode.html', {
  1130. scope: $scope,
  1131. animation: 'slide-in-up'
  1132. }).then(function(modal) {
  1133. $scope.qrCodemodal = modal;
  1134. });
  1135. $scope.openCode = function() {
  1136. $scope.qrCodemodal.show();
  1137. $scope.vm.money = '';
  1138. };
  1139. $scope.closeCode = function() {
  1140. $scope.qrCodemodal.hide();
  1141. };
  1142. $ionicModal.fromTemplateUrl('commentPic.html', {
  1143. scope: $scope,
  1144. animation: 'slide-in-up'
  1145. }).then(function(modal) {
  1146. $scope.CommentPicmodal = modal;
  1147. });
  1148. $scope.openCommentPic = function(pic) {
  1149. $scope.CommentPicmodal.show();
  1150. $scope.commentPicUrl = pic;
  1151. };
  1152. $scope.closeCommentPic = function() {
  1153. $scope.CommentPicmodal.hide();
  1154. };
  1155. $scope.addpict = function () {
  1156. common.chooseImage().then(function (img) {
  1157. common.uploadFiles(img,1).then(function (result) {
  1158. var response = JSON.parse(result.response);
  1159. var file = response.data.file;
  1160. $scope.imgs.push(config.imgServer+file);
  1161. console.log(JSON.stringify(config.imgServer+file));
  1162. }, function (error) {
  1163. msg.error('图片上传失败');
  1164. });
  1165. }, function (error) {
  1166. console.log('图片选择失败');
  1167. });
  1168. };
  1169. $scope.deletefile = function (file) {
  1170. var index = $scope.imgs.indexOf(file);
  1171. $scope.imgs.splice(index, 1);
  1172. common.deletefile(file).then(function () {
  1173. })
  1174. };
  1175. $scope.addvideo = function () {
  1176. common.chooseVideo().then(function (file) {
  1177. common.uploadFiles(file, 2).then(function (result) {
  1178. var response = JSON.parse(result.response);
  1179. $scope.video.server = response.data.file;
  1180. var file = config.imgServer+response.data.file;
  1181. console.log("file:"+file);
  1182. $scope.video.isOK = true;
  1183. $scope.video.file = file;
  1184. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  1185. console.log("vpic:"+$scope.video.vpic);
  1186. }, function (error) {
  1187. msg.error('视频上传失败');
  1188. });
  1189. }, function (erro) {
  1190. console.log('选择视频失败');
  1191. });
  1192. };
  1193. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  1194. scope: $scope,
  1195. animation: 'slide-in-up'
  1196. }).then(function(modal) {
  1197. $scope.rechagemodal = modal;
  1198. });
  1199. $scope.openRechargeModal = function() {
  1200. $scope.rechagemodal.show();
  1201. $scope.vm.money = '';
  1202. };
  1203. $scope.closeRechargeModal = function() {
  1204. $scope.rechagemodal.hide();
  1205. };
  1206. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  1207. scope: $scope,
  1208. animation: 'slide-in-up'
  1209. }).then(function(modal) {
  1210. $scope.modal = modal;
  1211. });
  1212. $scope.openModal = function() {
  1213. $scope.modal.show();
  1214. $scope.vm.title = '';
  1215. $scope.imgs = [];
  1216. $scope.video = {};
  1217. };
  1218. $scope.closeModal = function() {
  1219. $scope.modal.hide();
  1220. };
  1221. //当我们用到模型时,清除它!
  1222. $scope.$on('$destroy', function() {
  1223. $scope.modal.remove();
  1224. });
  1225. $scope.toMessage = function(){
  1226. $state.go("app.my_message");
  1227. }
  1228. }]);
  1229. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  1230. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  1231. var id = $stateParams.id;
  1232. $scope.items = $stateParams.items;
  1233. $scope.$on('$ionicView.beforeEnter', function () {
  1234. $ionicTabsDelegate.showBar(false);
  1235. });
  1236. $scope.attentionUser = function(is_care){
  1237. homeService.attentionUser(id,is_care).then(function(result){
  1238. $scope.items.is_care=result.data.data;
  1239. })
  1240. };
  1241. $scope.next = function (type) {
  1242. //type:1 前一个,type:2 后一个
  1243. if($scope.items.imgs.length>0){
  1244. if(type==1)
  1245. {
  1246. var temp= $scope.items.imgs.splice(0,1);
  1247. $scope.items.imgs.push(temp[0]);
  1248. }
  1249. if (type==2){
  1250. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1251. $scope.items.imgs.unshift(temp[0]);
  1252. }
  1253. }
  1254. };
  1255. $scope.bigImage = false;
  1256. $scope.showBigImage = function(imageName){
  1257. $scope.url = imageName;
  1258. $scope.bigImage = true;
  1259. };
  1260. $scope.hideBigImage = function(){
  1261. $scope.bigImage = false;
  1262. };
  1263. $scope.cancelSupport = function () {
  1264. $scope.tosupport = false;
  1265. $scope.toshare = false;
  1266. };
  1267. $scope.toshare = false;
  1268. $scope.toshare = false;
  1269. $scope.toRecharge = function(){
  1270. $state.go("app.recharge")
  1271. };
  1272. $scope.toDetail = function (dream_id) {
  1273. if($scope.items.near_dream==null){
  1274. msg.alert("当前梦想","该用户没有当前梦想");
  1275. }
  1276. if($scope.items.near_dream!=null){
  1277. var dream_id = $scope.items.near_dream.id;
  1278. $state.go('app.home_dreamdetail',{id:dream_id});
  1279. }
  1280. };
  1281. $scope.toOldDream = function(){
  1282. if($scope.items.dreams.length<2){
  1283. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1284. }
  1285. if($scope.items.dreams.length>1){
  1286. $state.go("app.oldDream",{user_id:$scope.items.user.id});
  1287. }
  1288. };
  1289. $scope.toSupportDream = function(){
  1290. if($scope.items.sup_dreams.length==0){
  1291. msg.alert("支持的梦想","该用户没有支持的梦想");
  1292. }
  1293. if($scope.items.sup_dreams.length!=0){
  1294. $state.go("app.supportDream",{user_id:$scope.items.user.id});
  1295. }
  1296. };
  1297. $scope.collectionDream = function(is_collection){
  1298. homeService.collectionDream(id,is_collection).then(function(result){
  1299. $scope.user.is_collection=result.data.data;
  1300. })
  1301. };
  1302. }]);
  1303. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1304. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1305. $scope.$on('$ionicView.beforeEnter', function () {
  1306. $ionicTabsDelegate.showBar(false);
  1307. myService.collect().then(function(result){
  1308. $scope.dreams = result.data.data.dreams;
  1309. });
  1310. });
  1311. $scope.toDetail = function (id) {
  1312. $state.go('app.home_dreamdetail',{id:id});
  1313. };
  1314. }]);
  1315. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1316. , function ($scope,homeService,$stateParams, $state, msg) {
  1317. $scope.dream = $stateParams.item;
  1318. $scope.showAbout = true;
  1319. $scope.hideAbout = false;
  1320. $scope.showText = function(){
  1321. $scope.aboutStyle = {
  1322. "white-space" : "normal"
  1323. };
  1324. $scope.showAbout = false;
  1325. $scope.hideAbout = true;
  1326. };
  1327. $scope.hideText = function(){
  1328. $scope.aboutStyle = {
  1329. "white-space" : "nowrap"
  1330. };
  1331. $scope.showAbout = true;
  1332. $scope.hideAbout = false;
  1333. };
  1334. }]);
  1335. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1336. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1337. $scope.$on('$ionicView.beforeEnter', function () {
  1338. $ionicTabsDelegate.showBar(false);
  1339. myService.messageInfo().then(function(result){
  1340. $scope.infos = result.data.data;
  1341. },function(error){
  1342. });
  1343. });
  1344. $scope.notRead = function(){
  1345. myService.notRead().then(function(result){
  1346. myService.messageInfo().then(function(result){
  1347. $scope.infos = result.data.data;
  1348. },function(error){
  1349. });
  1350. },function(error){
  1351. })
  1352. };
  1353. //系统消息
  1354. $scope.systemInfo = function(){
  1355. $state.go("app.message_sys");
  1356. myService.systemInfo().then(function(result){
  1357. },function(error){
  1358. });
  1359. };
  1360. //回复我的
  1361. $scope.replyMy = function(){
  1362. $state.go("app.message_reply");
  1363. myService.replyMy().then(function(result){
  1364. },function(error){
  1365. });
  1366. };
  1367. $scope.personalLetter = function(){
  1368. $state.go("app.letter");
  1369. }
  1370. }]);
  1371. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1372. , function ($scope,homeService,$stateParams, $state, msg) {
  1373. var user_id = $stateParams.user_id;
  1374. $scope.$on('$ionicView.beforeEnter',function(){
  1375. $scope.toUserDetail(user_id);
  1376. });
  1377. $scope.toUserDetail = function(user_id){
  1378. homeService.toUserDetail(user_id).then(function(result){
  1379. $scope.items = result.data.data;
  1380. $scope.user = result.data.data.user;
  1381. $scope.dreams = $scope.user.dreams;
  1382. },function(error){
  1383. })
  1384. };
  1385. $scope.toDetail = function(){
  1386. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1387. };
  1388. }]);
  1389. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1390. , function ($scope,homeService,$stateParams, $state, msg) {
  1391. var user_id = $stateParams.user_id;
  1392. $scope.$on('$ionicView.beforeEnter',function(){
  1393. $scope.toUserDetail(user_id);
  1394. });
  1395. $scope.toUserDetail = function(user_id){
  1396. homeService.toUserDetail(user_id).then(function(result){
  1397. $scope.items = result.data.data;
  1398. $scope.user = result.data.data.user;
  1399. $scope.dreams = $scope.user.sup_dream;
  1400. },function(error){
  1401. })
  1402. };
  1403. $scope.toDetail = function(){
  1404. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1405. }
  1406. }]);
  1407. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1408. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1409. $scope.showMore = function (keyword,index) {
  1410. if(!keyword)return;
  1411. $scope.index = index;
  1412. $scope.search(keyword);
  1413. };
  1414. $scope.search = function (keyword) {
  1415. $scope.vm.keyword = keyword;
  1416. homeService.search(keyword).then(function(result){
  1417. $scope.isResult = true;
  1418. $scope.dream_infos = result.data.data.dream_infos;
  1419. $scope.user_infos = result.data.data.user_infos;
  1420. });
  1421. };
  1422. $scope.toUserDetail = function (id) {
  1423. homeService.toUserDetail(id).then(function(result){
  1424. $scope.items = result.data.data;
  1425. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1426. },function(error){
  1427. //msg.error(msg.data.error)
  1428. })
  1429. };
  1430. $scope.toDetail = function (id) {
  1431. $state.go('app.home_dreamdetail',{id:id});
  1432. };
  1433. $scope.$on('$ionicView.beforeEnter', function () {
  1434. $scope.isResult = false;
  1435. $scope.index = 0;
  1436. $scope.vm = {
  1437. keyword : ""
  1438. };
  1439. $ionicTabsDelegate.showBar(false);
  1440. // $ionicNavBarDelegate.showBackButton(false);
  1441. homeService.search('').then(function(result){
  1442. $scope.hot_searches = result.data.data.hot_searches;
  1443. $scope.history_searches = result.data.data.history_searches;
  1444. });
  1445. });
  1446. }]);
  1447. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1448. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1449. }]);
  1450. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1451. , function ($scope, $state, myService, msg) {
  1452. $scope.$on('$ionicView.beforeEnter', function () {
  1453. myService.myDream().then(function(result){
  1454. console.log(result.data.data);
  1455. $scope.dreams = result.data.data;
  1456. });
  1457. });
  1458. $scope.toDetail = function (id) {
  1459. $state.go('app.home_dreamdetail',{id:id});
  1460. };
  1461. }]);
  1462. })(angular.module('app.controllers'));