my.js 47 KB

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