my.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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.vm.number = 'apple10001';
  463. $scope.showWithdraw = false;
  464. $scope.products = products;
  465. console.log('products:'+JSON.stringify(products));
  466. })
  467. .catch(function (err) {
  468. msg.hide();
  469. });
  470. }
  471. else{
  472. $scope.showWithdraw = true;
  473. }
  474. }
  475. })
  476. });
  477. $scope.payExplain = function(){
  478. $state.go("app.payExplain")
  479. };
  480. $scope.withdraw = function(){
  481. $state.go("app.withdraw")
  482. };
  483. $scope.testcharge = function(number){
  484. if (!number) {
  485. msg.text('请输入充值金额');
  486. return;
  487. }
  488. myService.testcharge(number,2).then(function (result) {
  489. msg.text("充值成功");
  490. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  491. // $timeout(function(){
  492. // $ionicHistory.goBack();
  493. // },500)
  494. });
  495. };
  496. $ionicModal.fromTemplateUrl('paysuccess-modal.html', {
  497. scope: $scope,
  498. animation: 'slide-in-up'
  499. }).then(function(modal) {
  500. $scope.modal = modal;
  501. });
  502. $scope.openModal = function() {
  503. $scope.modal.show();
  504. };
  505. $scope.closeModal = function() {
  506. $scope.modal.hide();
  507. };
  508. //当我们用到模型时,清除它!
  509. $scope.$on('$destroy', function() {
  510. $scope.modal.remove();
  511. });
  512. $scope.ios={
  513. isIOS:ionic.Platform.isIOS(),
  514. productid:'apple100001'
  515. }
  516. //充值
  517. $scope.charge = function(number){
  518. if($scope.ios.isIOS){
  519. if (number<2){
  520. msg.text('请选择充值金额');
  521. return;
  522. }
  523. console.log('购买productid:'+number);
  524. msg.loading();
  525. inAppPurchase
  526. .buy(number)
  527. .then(function (data) {
  528. msg.hide();
  529. console.log('购买then:'+JSON.stringify(data));
  530. return inAppPurchase.consume(data.productType, data.receipt, data.signature);
  531. })
  532. .then(function (data) {
  533. msg.hide();
  534. myService.orderIos(number).then(function (result) {
  535. console.log('服务器端购买成功:'+number);
  536. }, function (erro) {
  537. });
  538. console.log('购买成功:'+number);
  539. msg.success('购买成功');
  540. $ionicHistory.goBack();
  541. })
  542. .catch(function (err) {
  543. msg.hide();
  544. console.log('购买失败:'+JSON.stringify(err));
  545. msg.text('购买失败:'+err.errorMessage);
  546. });
  547. }else{
  548. if (!number) {
  549. msg.text('请输入充值金额');
  550. return;
  551. }
  552. myService.charge(number,2).then(function (result) {
  553. //todo:result需要返回支付宝或者微信的签名信息
  554. console.log("result: " + JSON.stringify(result));
  555. var payInfo = result.data.data;
  556. var orderID = payInfo.transaction_id
  557. $scope.vm.transaction_id = payInfo.transaction_id;
  558. $scope.vm.price = payInfo.price;
  559. if ($scope.vm.payType == 1) { //支付宝
  560. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  561. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  562. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  563. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  564. //当e.resultStatus为9000时,请去服务端验证支付结果
  565. $scope.clicksub = false;
  566. if (e.resultStatus == '9000') {
  567. alert(orderID);
  568. //支付成功
  569. // $state.go('app.my');
  570. } else {
  571. msg.error("支付失败");
  572. // msg.error("支付失败:" + JSON.stringify(e));
  573. }
  574. }, function error(e) {
  575. $scope.clicksub = false;
  576. // msg.error("支付失败:" + JSON.stringify(e));
  577. msg.error("支付失败");
  578. });
  579. }
  580. if ($scope.vm.payType == 2) { //微信
  581. // var obj = JSON.parse(payInfo);
  582. var obj = payInfo.orderString;
  583. // console.log("obj: " + JSON.stringify(obj));
  584. var params = {
  585. partnerid: obj.partnerid, // merchant id
  586. prepayid: obj.prepayid, // prepay id
  587. noncestr: obj.noncestr, // nonce
  588. timestamp: obj.timestamp, // timestamp
  589. sign: obj.sign, // signed string
  590. };
  591. // console.log("result: " + JSON.stringify(params));
  592. Wechat.sendPaymentRequest(params, function (r) {
  593. $scope.clicksub = false;
  594. // $state.go("app.paySuccess")
  595. // $state.go('app.paySuccess',{item:payInfo})
  596. $scope.openModal();
  597. // alert(orderID);
  598. myService.orderStatus(orderID).then(function (result) {
  599. // alert(result);
  600. //支付成功
  601. // $state.go('app.my');
  602. }, function (erro) {
  603. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  604. });
  605. }, function (reason) {
  606. $scope.clicksub = false;
  607. // msg.alert("支付失败:" + JSON.stringify(reason));
  608. });
  609. }
  610. // msg.text("充值成功");
  611. // $state.go('app.my');
  612. });
  613. }
  614. }
  615. }]);
  616. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  617. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  618. $scope.$on('$ionicView.beforeEnter', function () {
  619. $ionicTabsDelegate.showBar(false);
  620. $scope.showAccount();
  621. });
  622. $scope.showAccount = function(){
  623. myService.showAccount().then(function(result){
  624. $scope.items = result.data.data;
  625. },function(error){
  626. msg.error(error.data.message);
  627. })
  628. };
  629. $scope.destroyAccount = function(id){
  630. myService.destroyAccount(id).then(function(result){
  631. msg.text("删除成功");
  632. $scope.showAccount();
  633. },function(error){
  634. msg.error(error.data.message);
  635. })
  636. }
  637. }]);
  638. app.controller('my_account_addCtrl', ["$scope","config","common","$timeout","$ionicTabsDelegate", "$state", "myService", "msg"
  639. , function ($scope,config,common,$timeout,$ionicTabsDelegate, $state, myService, msg) {
  640. $scope.addpict = function () {
  641. common.chooseImage().then(function (qrcode) {
  642. common.uploadFiles(qrcode,1).then(function (result) {
  643. var response = JSON.parse(result.response);
  644. var file = config.imgServer+response.data.file;
  645. $scope.vm.file = file;
  646. $scope.qrcode.push(file);
  647. }, function (error) {
  648. msg.error('图片上传失败');
  649. });
  650. }, function (error) {
  651. console.log('图片选择失败');
  652. });
  653. };
  654. $scope.qrcode=[];
  655. $scope.deletefile = function (file) {
  656. var index = $scope.qrcode.indexOf(file);
  657. $scope.qrcode.splice(index, 1);
  658. common.deletefile(file).then(function () {
  659. })
  660. };
  661. $scope.vm={
  662. bank_name:'',
  663. bank_number:'',
  664. bank_phone:'',
  665. bank_user:'',
  666. type:""
  667. };
  668. $scope.addAccount = function () {
  669. var data = {
  670. data:{
  671. bank_name:$scope.vm.bank_name,
  672. bank_number:$scope.vm.bank_number,
  673. bank_phone:$scope.vm.bank_phone,
  674. bank_user:$scope.vm.bank_user
  675. }
  676. };
  677. //msg.loading('保存中...');
  678. msg.loading();
  679. myService.addAccount(data).then(function (result) {
  680. msg.hide();
  681. $state.go('app.my_account');
  682. }, function (error) {
  683. msg.hide();
  684. msg.error(error.data.message);
  685. });
  686. };
  687. $scope.addQrcode = function(){
  688. var data = {
  689. data:{
  690. type:$scope.vm.type,
  691. qrcode:$scope.vm.file
  692. //qrcode:"https://www.baidu.com/img/bd_logo1.png"
  693. }
  694. };
  695. myService.addQrcode(data).then(function(result){
  696. msg.text("添加成功",true);
  697. $state.go("app.my_account");
  698. },function(error){
  699. msg.error(error.data.message);
  700. })
  701. }
  702. }]);
  703. app.controller('messageCtrl', ["$scope", "$location","$ionicTabsDelegate","$state", "myService", "msg"
  704. , function ($scope,$location,$ionicTabsDelegate, $state, myService, msg) {
  705. $scope.$on('$ionicView.beforeEnter', function () {
  706. $ionicTabsDelegate.showBar(false);
  707. myService.messageInfo().then(function(result){
  708. $scope.infos = result.data.data;
  709. },function(error){
  710. });
  711. });
  712. $scope.notRead = function(){
  713. myService.notRead().then(function(result){
  714. myService.messageInfo().then(function(result){
  715. $scope.infos = result.data.data;
  716. },function(error){
  717. });
  718. },function(error){
  719. })
  720. };
  721. //梦想消息
  722. $scope.systemInfo = function(){
  723. if($location.path()=='/app/my/message'){
  724. $state.go("app.my_message_sys");
  725. }
  726. else {
  727. $state.go("app.message_sys");
  728. }
  729. };
  730. //支持消息
  731. $scope.replyMy = function(){
  732. if($location.path()=='/app/my/message'){
  733. $state.go("app.my_message_reply");
  734. }
  735. else {
  736. $state.go("app.message_reply");
  737. }
  738. };
  739. //通知
  740. $scope.personalLetter = function(){
  741. if($location.path()=='/app/my/message'){
  742. $state.go("app.personalLetter");
  743. }
  744. else {
  745. $state.go("app.letter");
  746. }
  747. };
  748. }]);
  749. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  750. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  751. $scope.$on('$ionicView.beforeEnter', function () {
  752. $ionicTabsDelegate.showBar(false);
  753. $scope.load(true);
  754. myService.myInfo().then(function(result){
  755. $scope.user = result.data.data
  756. });
  757. });
  758. $scope.filter = {
  759. hasMore: false,
  760. pageIndex: 1,
  761. pageSize: 25
  762. };
  763. $scope.load = function (init) {
  764. if (init) {
  765. $scope.filter.pageIndex = 1;
  766. $scope.dreams = [];
  767. }
  768. msg.loading();
  769. myService.myDream($scope.filter.pageIndex).then(function(result){
  770. msg.hide();
  771. $scope.filter.pageIndex++;
  772. var more = (result.data.data.data.length >= $scope.filter.pageSize);
  773. $scope.filter.hasMore = more;
  774. $scope.dreams = $scope.dreams.concat(result.data.data.data);
  775. if (init) {
  776. $scope.$broadcast('scroll.refreshComplete');
  777. } else {
  778. $scope.$broadcast('scroll.infiniteScrollComplete');
  779. }
  780. },function(error){
  781. msg.hide();
  782. });
  783. };
  784. $scope.toDetail = function (id) {
  785. $state.go('app.my_dreamdetail',{id:id});
  786. };
  787. $scope.time = function(){
  788. }
  789. }]);
  790. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  791. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  792. $scope.$on('$ionicView.beforeEnter', function () {
  793. $ionicTabsDelegate.showBar(false);
  794. myService.collect().then(function(result){
  795. $scope.dreams = result.data.data.dreams;
  796. });
  797. });
  798. $scope.toDetail = function (id) {
  799. $state.go('app.my_dreamdetail',{id:id});
  800. };
  801. }]);
  802. app.controller('messageSysCtrl', ["$scope","common","config","$ionicPopup","$location", "$ionicTabsDelegate","$state", "myService", "msg"
  803. , function ($scope,common,config,$ionicPopup,$location,$ionicTabsDelegate, $state, myService, msg) {
  804. $scope.$on('$ionicView.beforeEnter', function () {
  805. $scope.loaddata(true);
  806. });
  807. $scope.vm = {
  808. content:""
  809. };
  810. $scope.imgs = [];
  811. $scope.video = {};
  812. $scope.loaddata = function(init){
  813. myService.systemInfo().then(function(result){
  814. $scope.sysInfos = result.data.data;
  815. if (init) {
  816. $scope.$broadcast('scroll.refreshComplete');
  817. } else {
  818. $scope.$broadcast('scroll.infiniteScrollComplete');
  819. }
  820. },function(error){
  821. });
  822. }
  823. $scope.addpict = function () {
  824. common.chooseImage().then(function (img) {
  825. common.uploadFiles(img,1).then(function (result) {
  826. var response = JSON.parse(result.response);
  827. var file = config.imgServer + response.data.file;
  828. $scope.imgs.push(file);
  829. }, function (error) {
  830. msg.error('图片上传失败');
  831. });
  832. }, function (error) {
  833. console.log('图片选择失败');
  834. });
  835. };
  836. $scope.deletefile = function (file) {
  837. var index = $scope.imgs.indexOf(file);
  838. $scope.imgs.splice(index, 1);
  839. common.deletefile(file).then(function () {
  840. })
  841. };
  842. $scope.addvideo = function () {
  843. common.chooseVideo().then(function (file) {
  844. msg.loading();
  845. common.uploadFiles(file, 2).then(function (result) {
  846. msg.hide();
  847. var response = JSON.parse(result.response);
  848. // var file = config.imgServer+response.data.file;
  849. // $scope.video.file = response.data.file;
  850. $scope.video.server = response.data.file;
  851. var file = response.data.file;
  852. $scope.video.isOK = true;
  853. $scope.video.file = file;
  854. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  855. }, function (error) {
  856. //msg.error('视频上传失败');
  857. msg.hide();
  858. msg.error(JSON.stringify(error));
  859. });
  860. }, function (erro) {
  861. console.log('选择视频失败');
  862. });
  863. };
  864. $scope.deletevideo = function (file) {
  865. $scope.video = {};
  866. common.deletefile(file).then(function (res) {
  867. },function(erro){
  868. //alert(JSON.stringify(erro));
  869. })
  870. };
  871. $scope.goMes = function(is_reply,is_url,dream_id,is_end,message,user_id,info,attr_id){
  872. //发送私信
  873. if(is_reply==1){
  874. $scope.vm.content='';
  875. $scope.imgs=[];
  876. $scope.video = {};
  877. var myPopup = $ionicPopup.show({
  878. template : '<div>' +
  879. '<textarea autofocus style="border: 1px solid #D0D0D0" name="" id="" cols="30" rows="8" ng-model="vm.content" placeholder="对他的好意给予感谢的回复"></textarea onf>' +
  880. '<a ng-if="!video.isOK&&imgs.length==0" class="btn-file-up" ng-click="addpict()">' +
  881. '<img src="img/icon_photo.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  882. '<em style="font-size: 16px">添加图片</em>' +
  883. '</a>' +
  884. '<a ng-if="imgs.length==0&&!video.isOK" class="btn-file-up" ng-click="addvideo()">' +
  885. '<img src="img/icon_video.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  886. '<em style="font-size: 16px">添加视频</em>' +
  887. '</a>' +
  888. '<a ng-repeat="item in imgs" ng-click="showImages(item)" class="img-file-up">' +
  889. '<b style="background-image:url({{item}});"><em ng-click="deletefile(item)" class="ion-ios-close-outline"></em></b>' +
  890. '</a>' +
  891. '<div class="img-file-up" ng-if="video.isOK">' +
  892. '<div style="position:relative;">' +
  893. '<em ng-click="deletevideo(video.file)" class="ion-ios-close-outline"></em>' +
  894. '<video ng-src="{{video.file | trustUrl}}" style="width: 100px; height: 100px; border: 1px solid #D0D0D0" poster="{{video.vpic}}" controls="controls"></video>' +
  895. '</div>' +
  896. '</div>' +
  897. '</div>',
  898. title: message,
  899. scope: $scope,
  900. buttons: [
  901. { text: '取消' },
  902. {
  903. text: '<b>确定</b>',
  904. type: 'button-positive',
  905. onTap: function(e) {
  906. var data = {
  907. to_user_id:user_id,
  908. content:$scope.vm.content,
  909. video:$scope.video.file,
  910. image:$scope.imgs,
  911. //image:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'],
  912. };
  913. myService.sendLetter(data).then(function(result){
  914. if(result.data.status_code==0){
  915. msg.success('发送成功');
  916. }
  917. })
  918. }
  919. }
  920. ]
  921. });
  922. }
  923. //跳转
  924. else if(is_url==1){
  925. if($location.path()=="/app/home/message/sys"){
  926. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  927. }
  928. else {
  929. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  930. }
  931. }
  932. //梦想结束
  933. else if(is_end==1&&attr_id==6){
  934. var endTemplate = '<div style="text-align: center"><p>恭喜你成功地你的梦想迈出最大的一步,</p>' +
  935. '<p>要取出全部梦想资金,</p>' +
  936. '<p>你需要亲自问候你的梦主</p>' +
  937. '<p>致出最诚挚的感谢</p>' +
  938. '<p>点击《确定》我们会提供</p>' +
  939. '<p>《梦主》的资料</p>' +
  940. '<p>如果你觉得不合适,你可以点击《取消》,但是《梦主》的资金会被退还给他</p>' +
  941. '<p>你以后创建梦想也会比较难</p>' +
  942. '</div>';
  943. msg.confirm('恭喜你!',endTemplate,'拒绝').then(function(result){
  944. if(result==true){
  945. myService.sure_meet(dream_id,1).then(function(res){
  946. if(res.data.status_code==0){
  947. if(res.data.data==0){
  948. msg.success('该梦想暂无梦主!');
  949. }
  950. else {
  951. msg.success('确定见面,期待相见吧!');
  952. }
  953. }
  954. })
  955. }
  956. else {
  957. myService.sure_meet(dream_id,0).then(function(res){
  958. if(res.data.status_code==0){
  959. msg.success('已拒绝见面!');
  960. }
  961. })
  962. }
  963. })
  964. }
  965. }
  966. }]);
  967. app.controller('messageReplyCtrl', ["$scope","$location","$ionicPopup","$ionicTabsDelegate", "$state","config", "myService", "msg", "$ionicModal"
  968. , function ($scope,$location,$ionicPopup,$ionicTabsDelegate, $state,config, myService, msg, $ionicModal) {
  969. $scope.$on('$ionicView.beforeEnter', function () {
  970. $scope.load(true);
  971. });
  972. $scope.load = function (init) {
  973. myService.replyMy().then(function (result) {
  974. $scope.comments = result.data.data;
  975. if (init) {
  976. $scope.$broadcast('scroll.refreshComplete');
  977. } else {
  978. $scope.$broadcast('scroll.infiniteScrollComplete');
  979. }
  980. }, function (error) {
  981. });
  982. };
  983. $scope.goMes = function(info,img,is_max,mes,video,attr_id,dream_id,to_user_id,is_end,is_url){
  984. //收到私信
  985. if(attr_id==7){
  986. if(video!=null){
  987. var letterTemplate = '<div style="text-align: center">' +
  988. '<video ng-src=" ' +config.imgServer+video+' " width="100%" style="height: 350px;" class="centerme" controls="controls" ></video>' +
  989. '<p>'+info+'</p>' +
  990. '</div>';
  991. }
  992. else if(img!='') {
  993. var letterTemplate = '<div style="text-align: center;">' +
  994. '<img src="'+img+'" style="width:100%; height: 100%;">' +
  995. '<p>'+info+'</p>' +
  996. '</div>';
  997. }
  998. else {
  999. var letterTemplate = '<div style="text-align: center">' +
  1000. '<p>'+info+'</p>' +
  1001. '</div>';
  1002. }
  1003. msg.confirm('私信',letterTemplate,'','梦想页').then(function(result){
  1004. if(result==true){
  1005. if($location.path()=="/app/home/message/reply"){
  1006. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1007. }
  1008. else {
  1009. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1010. }
  1011. }
  1012. })
  1013. }
  1014. else if(attr_id==10){
  1015. if($location.path()=="/app/home/message/reply"){
  1016. $state.go('app.home_dreamdetail',{id:dream_id,type:3});
  1017. }
  1018. else {
  1019. $state.go('app.my_dreamdetail',{id:dream_id,type:3});
  1020. }
  1021. }
  1022. //成为梦主
  1023. else if(is_max==1&&is_end==1){
  1024. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1025. '<p>'+ info +'</p>' +
  1026. '</div>';
  1027. msg.confirm('恭喜你!',maxTemplate).then(function(result){
  1028. if(result==true){
  1029. myService.sure_meet2(to_user_id,1).then(function(res){
  1030. if(res.data.status_code==0) {
  1031. msg.success('确定见面,期待相见吧!');
  1032. }
  1033. })
  1034. }
  1035. else {
  1036. myService.sure_meet2(to_user_id,0).then(function(res){
  1037. if(res.data.status_code==0){
  1038. msg.success('已取消见面!');
  1039. }
  1040. })
  1041. }
  1042. })
  1043. }//确认见面/扫一扫
  1044. else if(is_max==0&&is_url==0){
  1045. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  1046. '</div>';
  1047. msg.alert('恭喜你!',maxTemplate).then(function(result){
  1048. })
  1049. }
  1050. else if(is_end==0&&is_url==0){
  1051. }
  1052. else {
  1053. if($location.path()=="/app/home/message/reply"){
  1054. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  1055. }
  1056. else {
  1057. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  1058. }
  1059. }
  1060. };
  1061. //我的回复
  1062. $scope.vm = {
  1063. content: ""
  1064. };
  1065. $ionicModal.fromTemplateUrl('my-modal.html', {
  1066. scope: $scope,
  1067. animation: 'slide-in-up'
  1068. }).then(function (modal) {
  1069. $scope.modal = modal;
  1070. });
  1071. //$ionicModal.fromTemplateUrl('my-modal.html', {
  1072. // scope: $scope,
  1073. // animation: 'slide-in-up'
  1074. //}).then(function (modal) {
  1075. // $scope.modal = modal;
  1076. //});
  1077. //$scope.openModal = function () {
  1078. // $scope.modal.show();
  1079. //};
  1080. //$scope.closeModal = function () {
  1081. // $scope.modal.hide();
  1082. //
  1083. //};
  1084. $scope.goDetail = function (id,interaction_id){
  1085. $state.go('app.home_dreamdetail',{id:id,interaction_id:interaction_id,type:2});
  1086. };
  1087. //我的回复
  1088. //$scope.vm={
  1089. // content:"",
  1090. // comment_id:""
  1091. //};
  1092. //$scope.closeModal = function () {
  1093. // var data = {
  1094. // content: $scope.vm.content,
  1095. // comment_id: $scope.item.id,
  1096. // interaction_id: $scope.item.interaction_id
  1097. // };
  1098. // myService.myReplay(data).then(function (result) {
  1099. // msg.success('回复成功');
  1100. // $scope.load();
  1101. // }, function (error) {
  1102. // msg.error('回复失败');
  1103. // });
  1104. // $scope.vm.content = '';
  1105. // $scope.item = null;
  1106. // $scope.modal.hide();
  1107. //};
  1108. //
  1109. //$scope.reply = function (item) {
  1110. // $scope.item = item;
  1111. // $scope.modal.show();
  1112. //}
  1113. }]);
  1114. })(angular.module('app.controllers'));