my.js 47 KB

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