my.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. (function (app) {
  2. app.controller('myCtrl', ["$scope","$ionicTabsDelegate", "$state", "$http", "storage", "myService", "common", "config", "msg","$timeout"
  3. , function ($scope,$ionicTabsDelegate, $state, $http, storage, myService, common, config, msg, $timeout) {
  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. $timeout(function () {
  14. $scope.user.avatar = config.imgServer + response.data.md5;
  15. });
  16. });
  17. };
  18. }]);
  19. app.controller('profileCtrl', ["$scope", "$timeout","$ionicTabsDelegate","$state","$filter", "storage", "myService", "msg", "common"
  20. , function ($scope, $timeout, $ionicTabsDelegate, $state, $filter, storage, myService, msg, common) {
  21. $scope.$on('$ionicView.beforeEnter', function () {
  22. $ionicTabsDelegate.showBar(false);
  23. });
  24. $scope.setAvator = function () {
  25. common.setAvator().then(function (result) {
  26. var response = JSON.parse(result.response);
  27. $timeout(function () {
  28. $scope.vm.avatar = config.imgServer + response.data.md5;
  29. });
  30. });
  31. };
  32. //保存个人信息
  33. $scope.vm={
  34. pic:"",
  35. sex:"",
  36. signture:"",
  37. emotion:"",
  38. job:"",
  39. tall:""
  40. };
  41. $scope.$on('$ionicView.beforeEnter', function () {
  42. msg.loading();
  43. myService.myInfo().then(function(result){
  44. // alert(JSON.stringify(result.data.data));
  45. $scope.vm = result.data.data;
  46. $scope.vm.sex = $scope.vm.sex+'';
  47. $scope.vm.emotion = $scope.vm.emotion+'';
  48. if($scope.vm.birthday){
  49. var arr1 = $scope.vm.birthday.split("-");
  50. $scope.vm.birthday1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]);
  51. }
  52. msg.hide();
  53. },function(error){
  54. msg.hide();
  55. // msg.error(error.data.message);
  56. })
  57. });
  58. $scope.saveMaterial = function(){
  59. var data = {
  60. sex:$scope.vm.sex,
  61. signture:$scope.vm.signture,
  62. emotion:$scope.vm.emotion,
  63. work:$scope.vm.work,
  64. height:$scope.vm.height,
  65. city:$scope.vm.city
  66. };
  67. if($scope.vm.birthday1){
  68. data.birthday = $filter('date')($scope.vm.birthday1, "yyyy-MM-dd");
  69. }
  70. if($scope.vm.avatar){
  71. data.pic = $scope.vm.avatar;
  72. }
  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", "$state", "myService", "msg","storage"
  98. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  99. }]);
  100. app.controller('withdrawCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  101. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  102. }]);
  103. app.controller('payoutCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  104. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  105. }]);
  106. app.controller('payExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  107. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  108. }]);
  109. app.controller('explainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  110. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  111. }]);
  112. app.controller('contactCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  113. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  114. }]);
  115. app.controller('attentionCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  116. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  117. $scope.$on('$ionicView.beforeEnter', function () {
  118. myService.attention().then(function(result){
  119. $scope.users = result.data.data;
  120. },function(error){
  121. })
  122. });
  123. $scope.toMyUserDetail = function (id) {
  124. myService.toMyUserDetail(id).then(function(result){
  125. $scope.items = result.data.data;
  126. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  127. },function(error){
  128. //msg.error(msg.data.error)
  129. })
  130. };
  131. }]);
  132. app.controller('attention_DetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  133. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  134. var id = $stateParams.id;
  135. $scope.items = $stateParams.items;
  136. $scope.dream_id = $scope.items.near_dream.id;
  137. $scope.$on('$ionicView.beforeEnter', function () {
  138. $ionicTabsDelegate.showBar(false);
  139. });
  140. $scope.attentionUser = function(id,is_care){
  141. homeService.attentionUser(id,is_care).then(function(result){
  142. $scope.items.is_care=result.data.data;
  143. })
  144. };
  145. $scope.cancelSupport = function () {
  146. $scope.tosupport = false;
  147. $scope.toshare = false;
  148. };
  149. $scope.toshare = false;
  150. $scope.share = function ($event) {
  151. $event.stopPropagation();
  152. $scope.toshare = true;
  153. };
  154. $scope.shareDream = function(){
  155. $state.go("app.my_shareDream",{item:$scope.user});
  156. };
  157. $scope.toDetail = function (dream_id) {
  158. $state.go('app.my_dreamdetail',{id:dream_id});
  159. };
  160. $scope.toOldDream = function(){
  161. $state.go("app.myOldDream");
  162. };
  163. $scope.toSupportDream = function(){
  164. $state.go("app.mySupportDream",{user_id:$scope.items.user.id});
  165. };
  166. $scope.collectionDream = function(is_collection){
  167. homeService.collectionDream(id,is_collection).then(function(result){
  168. $scope.user.is_collection=result.data.data;
  169. })
  170. };
  171. }]);
  172. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  173. , function ($scope,homeService,$stateParams, $state, msg) {
  174. var user_id = $stateParams.user_id;
  175. $scope.$on('$ionicView.beforeEnter',function(){
  176. $scope.toUserDetail(user_id);
  177. });
  178. $scope.toUserDetail = function(user_id){
  179. homeService.toUserDetail(user_id).then(function(result){
  180. $scope.items = result.data.data;
  181. $scope.user = result.data.data.user;
  182. $scope.dreams = $scope.user.sup_dream;
  183. },function(error){
  184. })
  185. };
  186. $scope.toDetail = function(){
  187. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  188. }
  189. }]);
  190. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  191. , function ($scope,homeService,$stateParams, $state, msg) {
  192. var user_id = $stateParams.user_id;
  193. $scope.$on('$ionicView.beforeEnter',function(){
  194. $scope.toUserDetail(user_id);
  195. });
  196. $scope.toUserDetail = function(user_id){
  197. homeService.toUserDetail(user_id).then(function(result){
  198. $scope.items = result.data.data;
  199. $scope.user = result.data.data.user;
  200. $scope.dreams = $scope.user.sup_dream;
  201. },function(error){
  202. })
  203. };
  204. $scope.toDetail = function(){
  205. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  206. };
  207. }]);
  208. app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  209. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  210. }]);
  211. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  212. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  213. }]);
  214. app.controller('rechargeCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  215. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  216. $scope.$on('$ionicView.beforeEnter', function () {
  217. $ionicTabsDelegate.showBar(false);
  218. myService.myInfo().then(function(result){
  219. $scope.vm = result.data.data;
  220. $scope.vm.money = '';
  221. $scope.vm.payType = 1;
  222. })
  223. });
  224. $scope.payExplain = function(){
  225. $state.go("app.payExplain")
  226. };
  227. $scope.withdraw = function(){
  228. $state.go("app.withdraw")
  229. };
  230. //充值
  231. $scope.recharge = function(money){
  232. if (!$scope.vm.money) {
  233. msg.text('请输入充值金额');
  234. return;
  235. }
  236. myService.recharge(money).then(function (result) {
  237. //todo:result需要返回支付宝或者微信的签名信息
  238. var payInfo = result.data;
  239. if ($scope.vm.payType == 1) { //支付宝
  240. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  241. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  242. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  243. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  244. //当e.resultStatus为9000时,请去服务端验证支付结果
  245. $scope.clicksub = false;
  246. if (e.resultStatus == '9000') {
  247. alert(orderID);
  248. //支付成功
  249. // $state.go('app.my');
  250. } else {
  251. msg.error("支付失败");
  252. // msg.error("支付失败:" + JSON.stringify(e));
  253. }
  254. }, function error(e) {
  255. $scope.clicksub = false;
  256. // msg.error("支付失败:" + JSON.stringify(e));
  257. msg.error("支付失败");
  258. });
  259. }
  260. if ($scope.vm.payType == 2) { //微信
  261. var obj = JSON.parse(payInfo);
  262. var params = {
  263. partnerid: obj.partnerid, // merchant id
  264. prepayid: obj.prepayid, // prepay id
  265. noncestr: obj.noncestr, // nonce
  266. timestamp: obj.timestamp, // timestamp
  267. sign: obj.sign, // signed string
  268. };
  269. Wechat.sendPaymentRequest(params, function (r) {
  270. $scope.clicksub = false;
  271. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  272. // alert(result);
  273. //支付成功
  274. // $state.go('app.my');
  275. }, function (erro) {
  276. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  277. });
  278. }, function (reason) {
  279. $scope.clicksub = false;
  280. msg.alert("支付失败:" + JSON.stringify(reason));
  281. });
  282. }
  283. // msg.text("充值成功");
  284. // $state.go('app.my');
  285. });
  286. }
  287. }]);
  288. app.controller('payCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  289. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  290. $scope.$on('$ionicView.beforeEnter', function () {
  291. myService.myInfo().then(function(result){
  292. $scope.vm = result.data.data;
  293. $scope.vm.money = '';
  294. })
  295. });
  296. $scope.payExplain = function(){
  297. $state.go("app.explain")
  298. };
  299. $scope.withdraw = function(){
  300. $state.go("app.payout")
  301. };
  302. //充值
  303. $scope.recharge = function(money){
  304. myService.recharge(money).then(function(result){
  305. msg.text("充值成功");
  306. $state.go('app.my');
  307. });
  308. }
  309. }]);
  310. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  311. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  312. $scope.$on('$ionicView.beforeEnter', function () {
  313. $ionicTabsDelegate.showBar(false);
  314. });
  315. }]);
  316. app.controller('my_account_addCtrl', ["$scope","common","$ionicTabsDelegate", "$state", "myService", "msg"
  317. , function ($scope,common,$ionicTabsDelegate, $state, myService, msg) {
  318. $scope.addpict = function () {
  319. common.chooseImage().then(function (img) {
  320. common.uploadFiles(img,1).then(function (result) {
  321. var response = JSON.parse(result.response);
  322. var file = response.data.file;
  323. $scope.imgs.push(config.imgServer+file);
  324. }, function (error) {
  325. msg.error('图片上传失败');
  326. });
  327. }, function (error) {
  328. console.log('图片选择失败');
  329. });
  330. };
  331. $scope.deletefile = function (file) {
  332. var index = $scope.imgs.indexOf(file);
  333. $scope.imgs.splice(index, 1);
  334. common.deletefile(file).then(function () {
  335. })
  336. };
  337. $scope.vm={
  338. name:'',
  339. about:'',
  340. coin:''
  341. };
  342. $scope.add = function () {
  343. var data = {
  344. pics: $scope.imgs,
  345. video:$scope.video.server,
  346. name: $scope.vm.name,
  347. about: $scope.vm.about,
  348. days: 21, //默认21
  349. coin: $scope.vm.coin
  350. };
  351. msg.loading('保存中...');
  352. dreamService.addDream(data).then(function (result) {
  353. msg.hide();
  354. $state.go('app.home');
  355. }, function (error) {
  356. msg.hide();
  357. msg.error(error.data.message);
  358. });
  359. };
  360. }]);
  361. app.controller('messageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  362. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  363. $scope.$on('$ionicView.beforeEnter', function () {
  364. $ionicTabsDelegate.showBar(false);
  365. });
  366. //系统消息
  367. $scope.systemInfo = function(){
  368. $state.go("app.my_message_sys");
  369. myService.systemInfo().then(function(result){
  370. },function(error){
  371. });
  372. };
  373. //回复我的
  374. $scope.replyMy = function(){
  375. $state.go("app.my_message_reply");
  376. myService.replyMy().then(function(result){
  377. //$scope.comments = result;
  378. },function(error){
  379. });
  380. };
  381. $scope.personalLetter = function(){
  382. $state.go("app.personalLetter");
  383. }
  384. }]);
  385. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  386. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  387. $scope.$on('$ionicView.beforeEnter', function () {
  388. $ionicTabsDelegate.showBar(false);
  389. });
  390. //系统消息
  391. $scope.systemInfo = function(){
  392. $state.go("app.message_sys");
  393. myService.systemInfo().then(function(result){
  394. },function(error){
  395. });
  396. };
  397. //回复我的
  398. $scope.replyMy = function(){
  399. $state.go("app.message_reply");
  400. myService.replyMy().then(function(result){
  401. //$scope.comments = result;
  402. },function(error){
  403. });
  404. };
  405. $scope.personalLetter = function(){
  406. $state.go("app.letter");
  407. }
  408. }]);
  409. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  410. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  411. $scope.$on('$ionicView.beforeEnter', function () {
  412. $ionicTabsDelegate.showBar(false);
  413. myService.myDream().then(function(result){
  414. $scope.dreams = result.data.data;
  415. });
  416. myService.myInfo().then(function(result){
  417. $scope.user = result.data.data
  418. });
  419. });
  420. $scope.toDetail = function (id) {
  421. $state.go('app.my_dreamdetail',{id:id});
  422. };
  423. }]);
  424. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  425. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  426. $scope.$on('$ionicView.beforeEnter', function () {
  427. $ionicTabsDelegate.showBar(false);
  428. myService.collect().then(function(result){
  429. $scope.dreams = result.data.data.dreams;
  430. });
  431. });
  432. $scope.toDetail = function (id) {
  433. $state.go('app.my_dreamdetail',{id:id});
  434. };
  435. }]);
  436. app.controller('messageSysCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  437. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  438. }]);
  439. app.controller('sysCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  440. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  441. }]);
  442. app.controller('letterCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  443. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  444. }]);
  445. app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg", "$ionicModal"
  446. , function ($scope,$ionicTabsDelegate, $state, myService, msg, $ionicModal) {
  447. $ionicModal.fromTemplateUrl('my-modal.html', {
  448. scope: $scope,
  449. animation: 'slide-in-up'
  450. }).then(function (modal) {
  451. $scope.modal = modal;
  452. });
  453. $scope.openModal = function () {
  454. $scope.modal.show();
  455. };
  456. $scope.closeModal = function () {
  457. $scope.modal.hide();
  458. };
  459. //我的回复
  460. $scope.vm={
  461. content:"",
  462. comment_id:""
  463. };
  464. $scope.myReplay = function(){
  465. var data = {
  466. content:$scope.vm.content,
  467. comment_id:$scope.vm.id
  468. };
  469. myService.myReplay(data).then(function(result){
  470. },function(error){
  471. });
  472. $scope.modal.hide();
  473. }
  474. }]);
  475. })(angular.module('app.controllers'));