my.js 46 KB

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