my.js 46 KB

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