my.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. (function (app) {
  2. app.controller('myCtrl', ["$scope","$ionicTabsDelegate", "$state", "$http", "storage", "myService", "common","userService", "config", "msg"
  3. , function ($scope,$ionicTabsDelegate, $state, $http, storage, myService, common,userService, config, msg) {
  4. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  5. $ionicTabsDelegate.showBar(true);
  6. myService.myInfo().then(function(result){
  7. $scope.user = result.data.data
  8. });
  9. $scope.showWithdraw = true;
  10. userService.isTest().then(function(res){
  11. if(res.data.data){
  12. $scope.showWithdraw = true;
  13. }
  14. else{
  15. $scope.showWithdraw = false;
  16. }
  17. })
  18. });
  19. $scope.setAvator = function () {
  20. common.setAvator().then(function (result) {
  21. var response = JSON.parse(result.response);
  22. console.log(response.data.file);
  23. $scope.user.avatar = config.imgServer + response.data.file;
  24. });
  25. };
  26. }]);
  27. app.controller('profileCtrl', ["$scope","$ionicTabsDelegate","$state","$filter", "storage", "myService", "msg", "config", "common"
  28. , function ($scope, $ionicTabsDelegate, $state, $filter, storage, myService, msg, config, common) {
  29. $scope.$on('$ionicView.beforeEnter', function () {
  30. $ionicTabsDelegate.showBar(false);
  31. msg.loading();
  32. myService.myInfo().then(function(result){
  33. $scope.vm = result.data.data;
  34. console.log($scope.vm.avatar);
  35. $scope.vm.sex = $scope.vm.sex+'';
  36. $scope.vm.emotion = $scope.vm.emotion+'';
  37. if($scope.vm.birthday){
  38. var arr1 = $scope.vm.birthday.split("-");
  39. $scope.vm.birthday1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]);
  40. }
  41. msg.hide();
  42. },function(error){
  43. msg.hide();
  44. // msg.error(error.data.message);
  45. })
  46. });
  47. $scope.setAvator = function () {
  48. common.setAvator().then(function (result) {
  49. var response = JSON.parse(result.response);
  50. $scope.vm.avatar = config.imgServer + response.data.file;
  51. });
  52. };
  53. //保存个人信息
  54. $scope.vm={
  55. pic:"",
  56. sex:"",
  57. signture:"",
  58. emotion:"",
  59. job:"",
  60. tall:"",
  61. nickname:"",
  62. birthday1:""
  63. };
  64. $scope.saveMaterial = function(){
  65. var data = {
  66. sex:$scope.vm.sex,
  67. signture:$scope.vm.signture,
  68. emotion:$scope.vm.emotion,
  69. work:$scope.vm.work,
  70. height:$scope.vm.height,
  71. city:$scope.vm.city,
  72. nickname:$scope.vm.nickname,
  73. birthday:$scope.vm.birthday1
  74. };
  75. if($scope.vm.birthday1){
  76. data.birthday = $filter('date')($scope.vm.birthday1, "yyyy-MM-dd");
  77. }
  78. if($scope.vm.avatar){
  79. data.pic = $scope.vm.avatar;
  80. }
  81. //msg.loading('提交中...');
  82. msg.loading();
  83. myService.saveMaterial(data).then(function(result){
  84. msg.hide();
  85. msg.success("保存成功!");
  86. $state.go('app.my');
  87. myService.myInfo();
  88. },function(error){
  89. msg.hide();
  90. msg.error(error.data.message);
  91. })
  92. }
  93. }]);
  94. app.controller('settingCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  95. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  96. $scope.$on('$ionicView.beforeEnter', function () {
  97. $ionicTabsDelegate.showBar(false);
  98. });
  99. //退出登陆
  100. $scope.logout = function(){
  101. storage.remove("token");
  102. storage.remove("user");
  103. $state.go("login");
  104. }
  105. }]);
  106. app.controller('aboutMiaoCtrl', ["$scope","$ionicTabsDelegate","$timeout", "$state", "myService", "msg","storage"
  107. , function ($scope,$ionicTabsDelegate,$timeout, $state,myService, msg, storage) {
  108. $scope.$on('$ionicView.beforeEnter', function () {
  109. $scope.aboutMiao();
  110. });
  111. $scope.aboutMiao = function(){
  112. // myService.aboutMiao().then(function(result){
  113. // $scope.items = result.data.data;
  114. // },function(error){
  115. // msg.error(error.data.message)
  116. // })
  117. myService.info(type=2).then(function(res){
  118. $scope.info = res.data.data;
  119. })
  120. };
  121. }]);
  122. app.controller('withdrawCtrl', ["$scope","$ionicTabsDelegate","$ionicHistory","$timeout", "$state", "myService", "msg","storage"
  123. , function ($scope,$ionicTabsDelegate, $ionicHistory,$timeout,$state,myService, msg, storage) {
  124. $scope.vm={
  125. pay:"",
  126. cash:""
  127. };
  128. $scope.$on("$ionicView.enter",function(){
  129. myService.showAccount().then(function(result){
  130. $scope.accountId = result.data.data;
  131. var items = result.data.data;
  132. //if(items.length==0){
  133. // msg.text("请先添加账户");
  134. // $state.go("app.my_account_add");
  135. // return
  136. //}
  137. $scope.pays=[];
  138. angular.forEach(items,function(item){
  139. if(item.bank_name!=null) {
  140. var value=item.bank_name+"(";
  141. var len=item.bank_number.length;
  142. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  143. var txt2=item.bank_number.substr(len-4,4);
  144. value=value+txt1+txt2+")";
  145. }
  146. else {
  147. value=item.type;
  148. }
  149. $scope.pays.push({id:item.id,value:value});
  150. });
  151. $scope.vm.pay = $scope.pays[0]
  152. },function(error){
  153. msg.error(error.data.message)
  154. })
  155. });
  156. $scope.withdraw = function(){
  157. var data = {
  158. data:{
  159. bank_id:$scope.vm.pay.id,
  160. cash:$scope.vm.cash
  161. }
  162. };
  163. myService.withdraw(data).then(function(result){
  164. msg.text("提现申请已提交");
  165. $timeout(function () {
  166. $ionicHistory.goBack();
  167. },1000);
  168. },function(error){
  169. })
  170. }
  171. }]);
  172. app.controller('payoutCtrl', ["$scope","$ionicTabsDelegate","$timeout","$ionicHistory", "$state", "myService", "msg","storage"
  173. , function ($scope,$ionicTabsDelegate, $timeout, $ionicHistory,$state,myService, msg, storage) {
  174. $scope.vm={
  175. pay:"",
  176. cash:""
  177. };
  178. $scope.$on("$ionicView.enter",function(){
  179. myService.showAccount().then(function(result){
  180. $scope.accountId = result.data.data;
  181. var items = result.data.data;
  182. $scope.pays=[];
  183. angular.forEach(items,function(item){
  184. if(item.bank_name!=null) {
  185. var value=item.bank_name+"(";
  186. var len=item.bank_number.length;
  187. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  188. var txt2=item.bank_number.substr(len-4,4);
  189. value=value+txt1+txt2+")";
  190. }
  191. else {
  192. value=item.type;
  193. }
  194. $scope.pays.push({id:item.id,value:value});
  195. })
  196. },function(error){
  197. msg.error(error.data.message)
  198. })
  199. });
  200. $scope.withdraw = function(){
  201. var data = {
  202. data:{
  203. bank_id:$scope.vm.pay.id,
  204. cash:$scope.vm.cash
  205. }
  206. };
  207. myService.withdraw(data).then(function(result){
  208. msg.text("提现申请已提交");
  209. $timeout(function () {
  210. $ionicHistory.goBack();
  211. },1000);
  212. },function(error){
  213. })
  214. }
  215. }]);
  216. app.controller('payExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  217. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  218. $scope.$on('$ionicView.beforeEnter', function () {
  219. $scope.payExplain();
  220. });
  221. $scope.payExplain = function(){
  222. myService.payExplain().then(function(result){
  223. $scope.items = result.data.data;
  224. },function(error){
  225. msg.error(error.data.message)
  226. })
  227. };
  228. }]);
  229. app.controller('paySuccessCtrl', ["$scope","$stateParams","$ionicTabsDelegate","$ionicHistory", "$state", "myService", "msg","storage"
  230. , function ($scope,$stateParams,$ionicTabsDelegate,$ionicHistory, $state,myService, msg, storage) {
  231. var item = $stateParams.item;
  232. alert(item.out_trade_no);
  233. $scope.goBack = function(){
  234. $ionicHistory.goBack();
  235. }
  236. }]);
  237. app.controller('contactCtrl', ["$scope","$ionicTabsDelegate","$location", "$ionicHistory","$timeout","$state", "myService", "msg","storage"
  238. , function ($scope,$ionicTabsDelegate,$location,$ionicHistory, $timeout,$state,myService, msg, storage) {
  239. $scope.vm={
  240. content:"",
  241. email:""
  242. };
  243. $scope.contact = function(){
  244. var data={
  245. data:{
  246. content:$scope.vm.content,
  247. email:$scope.vm.email
  248. }
  249. };
  250. myService.contact(data).then(function(result){
  251. msg.text("发送成功");
  252. $timeout(function(){
  253. if($location.path()=='/app/home/contact'){
  254. $ionicHistory.goBack();
  255. }
  256. else{
  257. $state.go("app.my");
  258. }
  259. },1000);
  260. $scope.vm={
  261. content:"",
  262. email:""
  263. }
  264. },function(error){
  265. msg.error(error.data.message);
  266. })
  267. }
  268. }]);
  269. app.controller('attentionCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  270. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  271. $scope.$on('$ionicView.beforeEnter', function () {
  272. $ionicTabsDelegate.showBar(false);
  273. myService.attention().then(function(result){
  274. $scope.users = result.data.data;
  275. },function(error){
  276. })
  277. });
  278. $scope.toMyUserDetail = function (id) {
  279. myService.toMyUserDetail(id).then(function(result){
  280. $scope.items = result.data.data;
  281. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  282. },function(error){
  283. //msg.error(msg.data.error)
  284. })
  285. };
  286. }]);
  287. app.controller('careCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  288. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  289. $scope.$on('$ionicView.beforeEnter', function () {
  290. $ionicTabsDelegate.showBar(false);
  291. myService.careMe().then(function(result){
  292. $scope.users = result.data.data;
  293. },function(error){
  294. })
  295. });
  296. $scope.toMyUserDetail = function (id) {
  297. myService.toMyUserDetail(id).then(function(result){
  298. $scope.items = result.data.data;
  299. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  300. },function(error){
  301. //msg.error(msg.data.error)
  302. })
  303. };
  304. $ionicModal.fromTemplateUrl('my-modal.html', {
  305. scope: $scope,
  306. animation: 'slide-in-up'
  307. }).then(function (modal) {
  308. $scope.modal = modal;
  309. });
  310. //发私信
  311. $scope.vm={
  312. content:"",
  313. comment_id:""
  314. };
  315. $scope.closeModal = function () {
  316. var data = {
  317. content: $scope.vm.content,
  318. to_user_id: $scope.item.id
  319. };
  320. myService.sendLetter(data).then(function (result) {
  321. msg.success('发送成功');
  322. $scope.vm.content = '';
  323. $scope.item = null;
  324. $scope.modal.hide();
  325. }, function (error) {
  326. msg.error('发送失败');
  327. });
  328. };
  329. $scope.hideModal = function(){
  330. $scope.modal.hide();
  331. };
  332. $scope.reply = function (user) {
  333. event.stopPropagation();
  334. $scope.item = user;
  335. $scope.modal.show();
  336. }
  337. }]);
  338. app.controller('blacklistCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  339. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  340. $scope.$on('$ionicView.beforeEnter', function () {
  341. $ionicTabsDelegate.showBar(false);
  342. $scope.users = storage.getObject("blackUsers");
  343. // $scope.reportUser = storage.getObject("reportUser");
  344. });
  345. $scope.cancelReport = function(id){
  346. var reportUser = storage.getObject("reportUser");
  347. var blackUsers = storage.getObject("blackUsers");
  348. for(var i = 0; i < reportUser.length; i++){
  349. if(reportUser[i] == id){
  350. reportUser.splice(i,1);
  351. }
  352. }
  353. for(var j = 0; j < blackUsers.length; j++){
  354. if(blackUsers[j].id == id){
  355. blackUsers.splice(j,1);
  356. }
  357. }
  358. msg.text('已取消');
  359. $scope.users = blackUsers;
  360. storage.setObject('reportUser',reportUser);
  361. storage.setObject('blackUsers',blackUsers);
  362. }
  363. }]);
  364. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  365. , function ($scope,homeService,$stateParams, $state, msg) {
  366. var user_id = $stateParams.user_id;
  367. $scope.$on('$ionicView.beforeEnter',function(){
  368. $scope.toUserDetail(user_id);
  369. });
  370. $scope.toUserDetail = function(user_id){
  371. homeService.toUserDetail(user_id).then(function(result){
  372. $scope.items = result.data.data;
  373. $scope.user = result.data.data.user;
  374. $scope.dreams = $scope.user.sup_dream;
  375. },function(error){
  376. })
  377. };
  378. $scope.toDetail = function(id){
  379. $state.go('app.my_dreamdetail',{id:id});
  380. // $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  381. }
  382. }]);
  383. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  384. , function ($scope,homeService,$stateParams, $state, msg) {
  385. var user_id = $stateParams.user_id;
  386. $scope.$on('$ionicView.beforeEnter',function(){
  387. $scope.toUserDetail(user_id);
  388. });
  389. $scope.toUserDetail = function(user_id){
  390. homeService.toUserDetail(user_id).then(function(result){
  391. $scope.items = result.data.data;
  392. $scope.user = result.data.data.user;
  393. $scope.dreams = $scope.user.dreams;
  394. },function(error){
  395. })
  396. };
  397. $scope.toDetail = function(id){
  398. $state.go('app.my_dreamdetail',{id:id});
  399. // $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  400. };
  401. }]);
  402. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", '$location',"$state", "myService", "msg","storage"
  403. , function ($scope,$ionicTabsDelegate,$location, $state,myService, msg, storage) {
  404. $scope.$on('$ionicView.beforeEnter', function () {
  405. $scope.loaddata(true);
  406. });
  407. $scope.loaddata = function(init){
  408. myService.letter().then(function(result){
  409. $scope.items = result.data.data;
  410. if (init) {
  411. $scope.$broadcast('scroll.refreshComplete');
  412. } else {
  413. $scope.$broadcast('scroll.infiniteScrollComplete');
  414. }
  415. },function(error){
  416. });
  417. }
  418. $scope.toLetter = function(id){
  419. if($location.path()=="/app/home/message/letter"){
  420. console.log($location.path());
  421. $state.go('app.letterDetail')
  422. }
  423. else {
  424. $state.go('app.myLetterDetail')
  425. }
  426. }
  427. }]);
  428. app.controller('letterDetailCtrl', ["$scope","$ionicTabsDelegate",'$stateParams',"$state", "myService", "msg","storage"
  429. , function ($scope,$ionicTabsDelegate,$stateParams, $state,myService, msg, storage) {
  430. var id = $stateParams.id;
  431. $scope.$on('$ionicView.beforeEnter', function () {
  432. myService.letter().then(function(result){
  433. $scope.items = result.data.data;
  434. },function(error){
  435. });
  436. });
  437. }]);
  438. app.controller('rechargeCtrl', ["$scope","$ionicModal","$timeout","$ionicHistory","$ionicTabsDelegate", "$state", "myService","userService", "msg"
  439. , function ($scope,$ionicModal,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService,userService, msg) {
  440. $scope.$on('$ionicView.beforeEnter', function () {
  441. $scope.showWithdraw = false;
  442. $ionicTabsDelegate.showBar(false);
  443. $scope.vm = {
  444. }
  445. myService.myInfo().then(function(result){
  446. $scope.vm = result.data.data;
  447. $scope.vm.number = '';
  448. $scope.vm.payType = 2;
  449. });
  450. userService.isTest().then(function(res){
  451. if(res.data.data){
  452. $scope.showWithdraw = true;
  453. }
  454. else{
  455. if($scope.ios.isIOS){
  456. var productIds = ['apple10001','apple102','apple103','apple104']; // <- Add your product Ids here
  457. msg.loading();
  458. inAppPurchase
  459. .getProducts(productIds)
  460. .then(function (products) {
  461. msg.hide();
  462. $scope.showWithdraw = false;
  463. $scope.products = products;
  464. console.log('products:'+JSON.stringify(products));
  465. })
  466. .catch(function (err) {
  467. msg.hide();
  468. });
  469. }
  470. else{
  471. $scope.showWithdraw = true;
  472. }
  473. }
  474. })
  475. });
  476. $scope.payExplain = function(){
  477. $state.go("app.payExplain")
  478. };
  479. $scope.withdraw = function(){
  480. $state.go("app.withdraw")
  481. };
  482. $scope.testcharge = function(number){
  483. if (!number) {
  484. msg.text('请输入充值金额');
  485. return;
  486. }
  487. myService.testcharge(number,2).then(function (result) {
  488. msg.text("充值成功");
  489. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  490. // $timeout(function(){
  491. // $ionicHistory.goBack();
  492. // },500)
  493. });
  494. };
  495. $ionicModal.fromTemplateUrl('paysuccess-modal.html', {
  496. scope: $scope,
  497. animation: 'slide-in-up'
  498. }).then(function(modal) {
  499. $scope.modal = modal;
  500. });
  501. $scope.openModal = function() {
  502. $scope.modal.show();
  503. };
  504. $scope.closeModal = function() {
  505. $scope.modal.hide();
  506. };
  507. //当我们用到模型时,清除它!
  508. $scope.$on('$destroy', function() {
  509. $scope.modal.remove();
  510. });
  511. $scope.ios={
  512. isIOS:ionic.Platform.isIOS(),
  513. productid:'apple100001'
  514. }
  515. //充值
  516. $scope.charge = function(number){
  517. if($scope.ios.isIOS){
  518. if (number<2){
  519. msg.text('请选择充值金额');
  520. return;
  521. }
  522. console.log('购买productid:'+number);
  523. msg.loading();
  524. inAppPurchase
  525. .buy(number)
  526. .then(function (data) {
  527. msg.hide();
  528. console.log('购买then:'+JSON.stringify(data));
  529. return inAppPurchase.consume(data.productType, data.receipt, data.signature);
  530. })
  531. .then(function (data) {
  532. msg.hide();
  533. myService.orderIos(number).then(function (result) {
  534. console.log('服务器端购买成功:'+number);
  535. }, function (erro) {
  536. });
  537. console.log('购买成功:'+number);
  538. msg.success('购买成功');
  539. $ionicHistory.goBack();
  540. })
  541. .catch(function (err) {
  542. msg.hide();
  543. console.log('购买失败:'+JSON.stringify(err));
  544. // alert('购买失败:'+JSON.stringify(err));
  545. });
  546. }else{
  547. if (!number) {
  548. msg.text('请输入充值金额');
  549. return;
  550. }
  551. myService.charge(number,2).then(function (result) {
  552. //todo:result需要返回支付宝或者微信的签名信息
  553. console.log("result: " + JSON.stringify(result));
  554. var payInfo = result.data.data;
  555. var orderID = payInfo.transaction_id
  556. $scope.vm.transaction_id = payInfo.transaction_id;
  557. $scope.vm.price = payInfo.price;
  558. if ($scope.vm.payType == 1) { //支付宝
  559. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  560. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  561. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  562. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  563. //当e.resultStatus为9000时,请去服务端验证支付结果
  564. $scope.clicksub = false;
  565. if (e.resultStatus == '9000') {
  566. alert(orderID);
  567. //支付成功
  568. // $state.go('app.my');
  569. } else {
  570. msg.error("支付失败");
  571. // msg.error("支付失败:" + JSON.stringify(e));
  572. }
  573. }, function error(e) {
  574. $scope.clicksub = false;
  575. // msg.error("支付失败:" + JSON.stringify(e));
  576. msg.error("支付失败");
  577. });
  578. }
  579. if ($scope.vm.payType == 2) { //微信
  580. // var obj = JSON.parse(payInfo);
  581. var obj = payInfo.orderString;
  582. // console.log("obj: " + JSON.stringify(obj));
  583. var params = {
  584. partnerid: obj.partnerid, // merchant id
  585. prepayid: obj.prepayid, // prepay id
  586. noncestr: obj.noncestr, // nonce
  587. timestamp: obj.timestamp, // timestamp
  588. sign: obj.sign, // signed string
  589. };
  590. // console.log("result: " + JSON.stringify(params));
  591. Wechat.sendPaymentRequest(params, function (r) {
  592. $scope.clicksub = false;
  593. // $state.go("app.paySuccess")
  594. // $state.go('app.paySuccess',{item:payInfo})
  595. $scope.openModal();
  596. // alert(orderID);
  597. myService.orderStatus(orderID).then(function (result) {
  598. // alert(result);
  599. //支付成功
  600. // $state.go('app.my');
  601. }, function (erro) {
  602. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  603. });
  604. }, function (reason) {
  605. $scope.clicksub = false;
  606. // msg.alert("支付失败:" + JSON.stringify(reason));
  607. });
  608. }
  609. // msg.text("充值成功");
  610. // $state.go('app.my');
  611. });
  612. }
  613. }
  614. }]);
  615. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  616. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  617. $scope.$on('$ionicView.beforeEnter', function () {
  618. $ionicTabsDelegate.showBar(false);
  619. $scope.showAccount();
  620. });
  621. $scope.showAccount = function(){
  622. myService.showAccount().then(function(result){
  623. $scope.items = result.data.data;
  624. },function(error){
  625. msg.error(error.data.message);
  626. })
  627. };
  628. $scope.destroyAccount = function(id){
  629. myService.destroyAccount(id).then(function(result){
  630. msg.text("删除成功");
  631. $scope.showAccount();
  632. },function(error){
  633. msg.error(error.data.message);
  634. })
  635. }
  636. }]);
  637. app.controller('my_account_addCtrl', ["$scope","config","common","$timeout","$ionicTabsDelegate", "$state", "myService", "msg"
  638. , function ($scope,config,common,$timeout,$ionicTabsDelegate, $state, myService, msg) {
  639. $scope.addpict = function () {
  640. common.chooseImage().then(function (qrcode) {
  641. common.uploadFiles(qrcode,1).then(function (result) {
  642. var response = JSON.parse(result.response);
  643. var file = config.imgServer+response.data.file;
  644. $scope.vm.file = file;
  645. $scope.qrcode.push(file);
  646. }, function (error) {
  647. msg.error('图片上传失败');
  648. });
  649. }, function (error) {
  650. console.log('图片选择失败');
  651. });
  652. };
  653. $scope.qrcode=[];
  654. $scope.deletefile = function (file) {
  655. var index = $scope.qrcode.indexOf(file);
  656. $scope.qrcode.splice(index, 1);
  657. common.deletefile(file).then(function () {
  658. })
  659. };
  660. $scope.vm={
  661. bank_name:'',
  662. bank_number:'',
  663. bank_phone:'',
  664. bank_user:'',
  665. type:""
  666. };
  667. $scope.addAccount = function () {
  668. var data = {
  669. data:{
  670. bank_name:$scope.vm.bank_name,
  671. bank_number:$scope.vm.bank_number,
  672. bank_phone:$scope.vm.bank_phone,
  673. bank_user:$scope.vm.bank_user
  674. }
  675. };
  676. //msg.loading('保存中...');
  677. msg.loading();
  678. myService.addAccount(data).then(function (result) {
  679. msg.hide();
  680. $state.go('app.my_account');
  681. }, function (error) {
  682. msg.hide();
  683. msg.error(error.data.message);
  684. });
  685. };
  686. $scope.addQrcode = function(){
  687. var data = {
  688. data:{
  689. type:$scope.vm.type,
  690. qrcode:$scope.vm.file
  691. //qrcode:"https://www.baidu.com/img/bd_logo1.png"
  692. }
  693. };
  694. myService.addQrcode(data).then(function(result){
  695. msg.text("添加成功",true);
  696. $state.go("app.my_account");
  697. },function(error){
  698. msg.error(error.data.message);
  699. })
  700. }
  701. }]);
  702. app.controller('messageCtrl', ["$scope", "$location","$ionicTabsDelegate","$state", "myService", "msg"
  703. , function ($scope,$location,$ionicTabsDelegate, $state, myService, msg) {
  704. $scope.$on('$ionicView.beforeEnter', function () {
  705. $ionicTabsDelegate.showBar(false);
  706. myService.messageInfo().then(function(result){
  707. $scope.infos = result.data.data;
  708. },function(error){
  709. });
  710. });
  711. $scope.notRead = function(){
  712. myService.notRead().then(function(result){
  713. myService.messageInfo().then(function(result){
  714. $scope.infos = result.data.data;
  715. },function(error){
  716. });
  717. },function(error){
  718. })
  719. };
  720. //梦想消息
  721. $scope.systemInfo = function(){
  722. if($location.path()=='/app/my/message'){
  723. $state.go("app.my_message_sys");
  724. }
  725. else {
  726. $state.go("app.message_sys");
  727. }
  728. };
  729. //支持消息
  730. $scope.replyMy = function(){
  731. if($location.path()=='/app/my/message'){
  732. $state.go("app.my_message_reply");
  733. }
  734. else {
  735. $state.go("app.message_reply");
  736. }
  737. };
  738. //通知
  739. $scope.personalLetter = function(){
  740. if($location.path()=='/app/my/message'){
  741. $state.go("app.personalLetter");
  742. }
  743. else {
  744. $state.go("app.letter");
  745. }
  746. };
  747. }]);
  748. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  749. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  750. $scope.$on('$ionicView.beforeEnter', function () {
  751. $ionicTabsDelegate.showBar(false);
  752. $scope.load(true);
  753. myService.myInfo().then(function(result){
  754. $scope.user = result.data.data
  755. });
  756. });
  757. $scope.filter = {
  758. hasMore: false,
  759. pageIndex: 1,
  760. pageSize: 25
  761. };
  762. $scope.load = function (init) {
  763. if (init) {
  764. $scope.filter.pageIndex = 1;
  765. $scope.dreams = [];
  766. }
  767. msg.loading();
  768. myService.myDream($scope.filter.pageIndex).then(function(result){
  769. msg.hide();
  770. $scope.filter.pageIndex++;
  771. var more = (result.data.data.data.length >= $scope.filter.pageSize);
  772. $scope.filter.hasMore = more;
  773. $scope.dreams = $scope.dreams.concat(result.data.data.data);
  774. if (init) {
  775. $scope.$broadcast('scroll.refreshComplete');
  776. } else {
  777. $scope.$broadcast('scroll.infiniteScrollComplete');
  778. }
  779. },function(error){
  780. msg.hide();
  781. });
  782. };
  783. $scope.toDetail = function (id) {
  784. $state.go('app.my_dreamdetail',{id:id});
  785. };
  786. $scope.time = function(){
  787. }
  788. }]);
  789. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  790. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  791. $scope.$on('$ionicView.beforeEnter', function () {
  792. $ionicTabsDelegate.showBar(false);
  793. myService.collect().then(function(result){
  794. $scope.dreams = result.data.data.dreams;
  795. });
  796. });
  797. $scope.toDetail = function (id) {
  798. $state.go('app.my_dreamdetail',{id:id});
  799. };
  800. }]);
  801. app.controller('messageSysCtrl', ["$scope","common","config","$ionicPopup","$location", "$ionicTabsDelegate","$state", "myService", "msg"
  802. , function ($scope,common,config,$ionicPopup,$location,$ionicTabsDelegate, $state, myService, msg) {
  803. $scope.$on('$ionicView.beforeEnter', function () {
  804. $scope.loaddata(true);
  805. });
  806. $scope.vm = {
  807. content:""
  808. };
  809. $scope.imgs = [];
  810. $scope.video = {};
  811. $scope.loaddata = function(init){
  812. myService.systemInfo().then(function(result){
  813. $scope.sysInfos = result.data.data;
  814. if (init) {
  815. $scope.$broadcast('scroll.refreshComplete');
  816. } else {
  817. $scope.$broadcast('scroll.infiniteScrollComplete');
  818. }
  819. },function(error){
  820. });
  821. }
  822. $scope.addpict = function () {
  823. common.chooseImage().then(function (img) {
  824. common.uploadFiles(img,1).then(function (result) {
  825. var response = JSON.parse(result.response);
  826. var file = config.imgServer + response.data.file;
  827. $scope.imgs.push(file);
  828. }, function (error) {
  829. msg.error('图片上传失败');
  830. });
  831. }, function (error) {
  832. console.log('图片选择失败');
  833. });
  834. };
  835. $scope.deletefile = function (file) {
  836. var index = $scope.imgs.indexOf(file);
  837. $scope.imgs.splice(index, 1);
  838. common.deletefile(file).then(function () {
  839. })
  840. };
  841. $scope.addvideo = function () {
  842. common.chooseVideo().then(function (file) {
  843. msg.loading();
  844. common.uploadFiles(file, 2).then(function (result) {
  845. msg.hide();
  846. var response = JSON.parse(result.response);
  847. // var file = config.imgServer+response.data.file;
  848. // $scope.video.file = response.data.file;
  849. $scope.video.server = response.data.file;
  850. var file = response.data.file;
  851. $scope.video.isOK = true;
  852. $scope.video.file = file;
  853. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  854. }, function (error) {
  855. //msg.error('视频上传失败');
  856. msg.hide();
  857. msg.error(JSON.stringify(error));
  858. });
  859. }, function (erro) {
  860. console.log('选择视频失败');
  861. });
  862. };
  863. $scope.deletevideo = function (file) {
  864. $scope.video = {};
  865. common.deletefile(file).then(function (res) {
  866. },function(erro){
  867. //alert(JSON.stringify(erro));
  868. })
  869. };
  870. $scope.goMes = function(is_reply,is_url,dream_id,is_end,message,user_id,info,attr_id){
  871. //发送私信
  872. if(is_reply==1){
  873. $scope.vm.content='';
  874. $scope.imgs=[];
  875. $scope.video = {};
  876. var myPopup = $ionicPopup.show({
  877. template : '<div>' +
  878. '<textarea autofocus style="border: 1px solid #D0D0D0" name="" id="" cols="30" rows="8" ng-model="vm.content" placeholder="对他的好意给予感谢的回复"></textarea onf>' +
  879. '<a ng-if="!video.isOK&&imgs.length==0" class="btn-file-up" ng-click="addpict()">' +
  880. '<img src="img/icon_photo.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  881. '<em style="font-size: 16px">添加图片</em>' +
  882. '</a>' +
  883. '<a ng-if="imgs.length==0&&!video.isOK" class="btn-file-up" ng-click="addvideo()">' +
  884. '<img src="img/icon_video.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  885. '<em style="font-size: 16px">添加视频</em>' +
  886. '</a>' +
  887. '<a ng-repeat="item in imgs" ng-click="showImages(item)" class="img-file-up">' +
  888. '<b style="background-image:url({{item}});"><em ng-click="deletefile(item)" class="ion-ios-close-outline"></em></b>' +
  889. '</a>' +
  890. '<div class="img-file-up" ng-if="video.isOK">' +
  891. '<div style="position:relative;">' +
  892. '<em ng-click="deletevideo(video.file)" class="ion-ios-close-outline"></em>' +
  893. '<video ng-src="{{video.file | trustUrl}}" style="width: 100px; height: 100px; border: 1px solid #D0D0D0" poster="{{video.vpic}}" controls="controls"></video>' +
  894. '</div>' +
  895. '</div>' +
  896. '</div>',
  897. title: message,
  898. scope: $scope,
  899. buttons: [
  900. { text: '取消' },
  901. {
  902. text: '<b>确定</b>',
  903. type: 'button-positive',
  904. onTap: function(e) {
  905. var data = {
  906. to_user_id:user_id,
  907. content:$scope.vm.content,
  908. video:$scope.video.file,
  909. image:$scope.imgs,
  910. //image:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'],
  911. };
  912. myService.sendLetter(data).then(function(result){
  913. if(result.data.status_code==0){
  914. msg.success('发送成功');
  915. }
  916. })
  917. }
  918. }
  919. ]
  920. });
  921. }
  922. //跳转
  923. else if(is_url==1){
  924. if($location.path()=="/app/home/message/sys"){
  925. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  926. }
  927. else {
  928. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  929. }
  930. }
  931. //梦想结束
  932. else if(is_end==1&&attr_id==6){
  933. var endTemplate = '<div style="text-align: center"><p>恭喜你成功地你的梦想迈出最大的一步,</p>' +
  934. '<p>要取出全部梦想资金,</p>' +
  935. '<p>你需要亲自问候你的梦主</p>' +
  936. '<p>致出最诚挚的感谢</p>' +
  937. '<p>点击《确定》我们会提供</p>' +
  938. '<p>《梦主》的资料</p>' +
  939. '<p>如果你觉得不合适,你可以点击《取消》,但是《梦主》的资金会被退还给他</p>' +
  940. '<p>你以后创建梦想也会比较难</p>' +
  941. '</div>';
  942. msg.confirm('恭喜你!',endTemplate,'拒绝').then(function(result){
  943. if(result==true){
  944. myService.sure_meet(dream_id,1).then(function(res){
  945. if(res.data.status_code==0){
  946. if(res.data.data==0){
  947. msg.success('该梦想暂无梦主!');
  948. }
  949. else {
  950. msg.success('确定见面,期待相见吧!');
  951. }
  952. }
  953. })
  954. }
  955. else {
  956. myService.sure_meet(dream_id,0).then(function(res){
  957. if(res.data.status_code==0){
  958. msg.success('已拒绝见面!');
  959. }
  960. })
  961. }
  962. })
  963. }
  964. }
  965. }]);
  966. app.controller('messageReplyCtrl', ["$scope","$location","$ionicPopup","$ionicTabsDelegate", "$state","config", "myService", "msg", "$ionicModal"
  967. , function ($scope,$location,$ionicPopup,$ionicTabsDelegate, $state,config, myService, msg, $ionicModal) {
  968. $scope.$on('$ionicView.beforeEnter', function () {
  969. $scope.load(true);
  970. });
  971. $scope.load = function (init) {
  972. myService.replyMy().then(function (result) {
  973. $scope.comments = result.data.data;
  974. if (init) {
  975. $scope.$broadcast('scroll.refreshComplete');
  976. } else {
  977. $scope.$broadcast('scroll.infiniteScrollComplete');
  978. }
  979. }, function (error) {
  980. });
  981. };
  982. $scope.goMes = function(info,img,is_max,mes,video,attr_id,dream_id,to_user_id,is_end,is_url){
  983. //收到私信
  984. if(attr_id==7){
  985. if(video!=null){
  986. var letterTemplate = '<div style="text-align: center">' +
  987. '<video ng-src=" ' +config.imgServer+video+' " width="100%" style="height: 350px;" class="centerme" controls="controls" ></video>' +
  988. '<p>'+info+'</p>' +
  989. '</div>';
  990. }
  991. else if(img!='') {
  992. var letterTemplate = '<div style="text-align: center;">' +
  993. '<img src="'+img+'" style="width:100%; height: 100%;">' +
  994. '<p>'+info+'</p>' +
  995. '</div>';
  996. }
  997. else {
  998. var letterTemplate = '<div style="text-align: center">' +
  999. '<p>'+info+'</p>' +
  1000. '</div>';
  1001. }
  1002. msg.confirm('私信',letterTemplate,'','梦想页').then(function(result){
  1003. if(result==true){
  1004. if($location.path()=="/app/home/message/reply"){
  1005. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1006. }
  1007. else {
  1008. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1009. }
  1010. }
  1011. })
  1012. }
  1013. else if(attr_id==10){
  1014. if($location.path()=="/app/home/message/reply"){
  1015. $state.go('app.home_dreamdetail',{id:dream_id,type:3});
  1016. }
  1017. else {
  1018. $state.go('app.my_dreamdetail',{id:dream_id,type:3});
  1019. }
  1020. }
  1021. //成为梦主
  1022. else if(is_max==1&&is_end==1){
  1023. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1024. '<p>'+ info +'</p>' +
  1025. '</div>';
  1026. msg.confirm('恭喜你!',maxTemplate).then(function(result){
  1027. if(result==true){
  1028. myService.sure_meet2(to_user_id,1).then(function(res){
  1029. if(res.data.status_code==0) {
  1030. msg.success('确定见面,期待相见吧!');
  1031. }
  1032. })
  1033. }
  1034. else {
  1035. myService.sure_meet2(to_user_id,0).then(function(res){
  1036. if(res.data.status_code==0){
  1037. msg.success('已取消见面!');
  1038. }
  1039. })
  1040. }
  1041. })
  1042. }//确认见面/扫一扫
  1043. else if(is_max==0&&is_url==0){
  1044. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1045. '</div>';
  1046. msg.alert('恭喜你!',maxTemplate).then(function(result){
  1047. })
  1048. }
  1049. else if(is_end==0&&is_url==0){
  1050. }
  1051. else {
  1052. if($location.path()=="/app/home/message/reply"){
  1053. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1054. }
  1055. else {
  1056. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1057. }
  1058. }
  1059. };
  1060. //我的回复
  1061. $scope.vm = {
  1062. content: ""
  1063. };
  1064. $ionicModal.fromTemplateUrl('my-modal.html', {
  1065. scope: $scope,
  1066. animation: 'slide-in-up'
  1067. }).then(function (modal) {
  1068. $scope.modal = modal;
  1069. });
  1070. //$ionicModal.fromTemplateUrl('my-modal.html', {
  1071. // scope: $scope,
  1072. // animation: 'slide-in-up'
  1073. //}).then(function (modal) {
  1074. // $scope.modal = modal;
  1075. //});
  1076. //$scope.openModal = function () {
  1077. // $scope.modal.show();
  1078. //};
  1079. //$scope.closeModal = function () {
  1080. // $scope.modal.hide();
  1081. //
  1082. //};
  1083. $scope.goDetail = function (id,interaction_id){
  1084. $state.go('app.home_dreamdetail',{id:id,interaction_id:interaction_id,type:2});
  1085. };
  1086. //我的回复
  1087. //$scope.vm={
  1088. // content:"",
  1089. // comment_id:""
  1090. //};
  1091. //$scope.closeModal = function () {
  1092. // var data = {
  1093. // content: $scope.vm.content,
  1094. // comment_id: $scope.item.id,
  1095. // interaction_id: $scope.item.interaction_id
  1096. // };
  1097. // myService.myReplay(data).then(function (result) {
  1098. // msg.success('回复成功');
  1099. // $scope.load();
  1100. // }, function (error) {
  1101. // msg.error('回复失败');
  1102. // });
  1103. // $scope.vm.content = '';
  1104. // $scope.item = null;
  1105. // $scope.modal.hide();
  1106. //};
  1107. //
  1108. //$scope.reply = function (item) {
  1109. // $scope.item = item;
  1110. // $scope.modal.show();
  1111. //}
  1112. }]);
  1113. })(angular.module('app.controllers'));