my.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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.$on('$ionicView.beforeEnter', function () {
  137. $ionicTabsDelegate.showBar(false);
  138. });
  139. $scope.cancelSupport = function () {
  140. $scope.tosupport = false;
  141. $scope.toshare = false;
  142. };
  143. $scope.toshare = false;
  144. $scope.share = function ($event) {
  145. $event.stopPropagation();
  146. $scope.toshare = true;
  147. };
  148. $scope.shareDream = function(){
  149. $state.go("app.my_shareDream",{item:$scope.user});
  150. };
  151. $scope.toDetail = function (id) {
  152. $state.go('app.my_dreamdetail',{id:id});
  153. };
  154. $scope.toOldDream = function(){
  155. $state.go("app.myOldDream");
  156. };
  157. $scope.toSupportDream = function(){
  158. $state.go("app.mySupportDream");
  159. };
  160. $scope.collectionDream = function(is_collection){
  161. homeService.collectionDream(id,is_collection).then(function(result){
  162. $scope.user.is_collection=result.data.data;
  163. })
  164. };
  165. }]);
  166. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  167. , function ($scope,homeService,$stateParams, $state, msg) {
  168. $scope.toDetail = function(){
  169. $state.go("app.attention_Detail")
  170. }
  171. }]);
  172. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  173. , function ($scope,homeService,$stateParams, $state, msg) {
  174. $scope.toDetail = function(){
  175. $state.go("app.attention_Detail")
  176. }
  177. }]);
  178. app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  179. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  180. }]);
  181. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  182. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  183. }]);
  184. app.controller('rechargeCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  185. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  186. $scope.$on('$ionicView.beforeEnter', function () {
  187. $ionicTabsDelegate.showBar(false);
  188. myService.myInfo().then(function(result){
  189. $scope.vm = result.data.data;
  190. $scope.vm.money = '';
  191. $scope.vm.payType = 1;
  192. })
  193. });
  194. $scope.payExplain = function(){
  195. $state.go("app.payExplain")
  196. };
  197. $scope.withdraw = function(){
  198. $state.go("app.withdraw")
  199. };
  200. //充值
  201. $scope.recharge = function(money){
  202. if (!$scope.vm.money) {
  203. msg.text('请输入充值金额');
  204. return;
  205. }
  206. myService.recharge(money).then(function (result) {
  207. //todo:result需要返回支付宝或者微信的签名信息
  208. var payInfo = result.data;
  209. if ($scope.vm.payType == 1) { //支付宝
  210. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  211. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  212. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  213. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  214. //当e.resultStatus为9000时,请去服务端验证支付结果
  215. $scope.clicksub = false;
  216. if (e.resultStatus == '9000') {
  217. alert(orderID);
  218. //支付成功
  219. // $state.go('app.my');
  220. } else {
  221. msg.error("支付失败");
  222. // msg.error("支付失败:" + JSON.stringify(e));
  223. }
  224. }, function error(e) {
  225. $scope.clicksub = false;
  226. // msg.error("支付失败:" + JSON.stringify(e));
  227. msg.error("支付失败");
  228. });
  229. }
  230. if ($scope.vm.payType == 2) { //微信
  231. var obj = JSON.parse(payInfo);
  232. var params = {
  233. partnerid: obj.partnerid, // merchant id
  234. prepayid: obj.prepayid, // prepay id
  235. noncestr: obj.noncestr, // nonce
  236. timestamp: obj.timestamp, // timestamp
  237. sign: obj.sign, // signed string
  238. };
  239. Wechat.sendPaymentRequest(params, function (r) {
  240. $scope.clicksub = false;
  241. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  242. // alert(result);
  243. //支付成功
  244. // $state.go('app.my');
  245. }, function (erro) {
  246. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  247. });
  248. }, function (reason) {
  249. $scope.clicksub = false;
  250. msg.alert("支付失败:" + JSON.stringify(reason));
  251. });
  252. }
  253. // msg.text("充值成功");
  254. // $state.go('app.my');
  255. });
  256. }
  257. }]);
  258. app.controller('payCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  259. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  260. $scope.$on('$ionicView.beforeEnter', function () {
  261. myService.myInfo().then(function(result){
  262. $scope.vm = result.data.data;
  263. $scope.vm.money = '';
  264. })
  265. });
  266. $scope.payExplain = function(){
  267. $state.go("app.explain")
  268. };
  269. $scope.withdraw = function(){
  270. $state.go("app.payout")
  271. };
  272. //充值
  273. $scope.recharge = function(money){
  274. myService.recharge(money).then(function(result){
  275. msg.text("充值成功");
  276. $state.go('app.my');
  277. });
  278. }
  279. }]);
  280. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  281. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  282. $scope.$on('$ionicView.beforeEnter', function () {
  283. $ionicTabsDelegate.showBar(false);
  284. });
  285. }]);
  286. app.controller('my_account_addCtrl', ["$scope","common","$ionicTabsDelegate", "$state", "myService", "msg"
  287. , function ($scope,common,$ionicTabsDelegate, $state, myService, msg) {
  288. $scope.addpict = function () {
  289. common.chooseImage().then(function (img) {
  290. common.uploadFiles(img,1).then(function (result) {
  291. var response = JSON.parse(result.response);
  292. var file = response.data.file;
  293. $scope.imgs.push(config.imgServer+file);
  294. }, function (error) {
  295. msg.error('图片上传失败');
  296. });
  297. }, function (error) {
  298. console.log('图片选择失败');
  299. });
  300. };
  301. $scope.addvideo = function () {
  302. common.chooseVideo().then(function (file) {
  303. $scope.video.path = file;
  304. common.uploadFiles(file, 2).then(function (result) {
  305. var response = JSON.parse(result.response);
  306. var file = response.data.file;
  307. console.log("file:"+config.imgServer+file);
  308. $scope.video.isOK = true;
  309. $scope.video.server = config.imgServer+file;
  310. }, function (error) {
  311. msg.error('视频上传失败');
  312. });
  313. }, function (erro) {
  314. console.log('选择视频失败');
  315. });
  316. };
  317. $scope.deletefile = function (file) {
  318. var index = $scope.imgs.indexOf(file);
  319. $scope.imgs.splice(index, 1);
  320. common.deletefile(file).then(function () {
  321. })
  322. };
  323. }]);
  324. app.controller('messageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  325. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  326. $scope.$on('$ionicView.beforeEnter', function () {
  327. $ionicTabsDelegate.showBar(false);
  328. });
  329. //系统消息
  330. $scope.systemInfo = function(){
  331. $state.go("app.my_message_sys");
  332. myService.systemInfo().then(function(result){
  333. },function(error){
  334. });
  335. };
  336. //回复我的
  337. $scope.replyMy = function(){
  338. $state.go("app.my_message_reply");
  339. myService.replyMy().then(function(result){
  340. //$scope.comments = result;
  341. },function(error){
  342. });
  343. };
  344. $scope.personalLetter = function(){
  345. $state.go("app.personalLetter");
  346. }
  347. }]);
  348. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  349. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  350. $scope.$on('$ionicView.beforeEnter', function () {
  351. $ionicTabsDelegate.showBar(false);
  352. });
  353. //系统消息
  354. $scope.systemInfo = function(){
  355. $state.go("app.message_sys");
  356. myService.systemInfo().then(function(result){
  357. },function(error){
  358. });
  359. };
  360. //回复我的
  361. $scope.replyMy = function(){
  362. $state.go("app.message_reply");
  363. myService.replyMy().then(function(result){
  364. //$scope.comments = result;
  365. },function(error){
  366. });
  367. };
  368. $scope.personalLetter = function(){
  369. $state.go("app.letter");
  370. }
  371. }]);
  372. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  373. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  374. $scope.$on('$ionicView.beforeEnter', function () {
  375. $ionicTabsDelegate.showBar(false);
  376. myService.myDream().then(function(result){
  377. $scope.dreams = result.data.data;
  378. });
  379. myService.myInfo().then(function(result){
  380. $scope.user = result.data.data
  381. });
  382. });
  383. $scope.toDetail = function (id) {
  384. $state.go('app.my_dreamdetail',{id:id});
  385. };
  386. }]);
  387. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  388. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  389. $scope.$on('$ionicView.beforeEnter', function () {
  390. $ionicTabsDelegate.showBar(false);
  391. myService.collect().then(function(result){
  392. $scope.dreams = result.data.data.dreams;
  393. $scope.users = result.data.data.users;
  394. });
  395. });
  396. $scope.toDetail = function (id) {
  397. $state.go('app.my_dreamdetail',{id:id});
  398. };
  399. }]);
  400. app.controller('messageSysCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  401. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  402. }]);
  403. app.controller('sysCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  404. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  405. }]);
  406. app.controller('letterCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  407. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  408. }]);
  409. app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg", "$ionicModal"
  410. , function ($scope,$ionicTabsDelegate, $state, myService, msg, $ionicModal) {
  411. $ionicModal.fromTemplateUrl('my-modal.html', {
  412. scope: $scope,
  413. animation: 'slide-in-up'
  414. }).then(function (modal) {
  415. $scope.modal = modal;
  416. });
  417. $scope.openModal = function () {
  418. $scope.modal.show();
  419. };
  420. $scope.closeModal = function () {
  421. $scope.modal.hide();
  422. };
  423. //我的回复
  424. $scope.vm={
  425. content:"",
  426. comment_id:""
  427. };
  428. $scope.myReplay = function(){
  429. var data = {
  430. content:$scope.vm.content,
  431. comment_id:$scope.vm.id
  432. };
  433. myService.myReplay(data).then(function(result){
  434. },function(error){
  435. });
  436. $scope.modal.hide();
  437. }
  438. }]);
  439. })(angular.module('app.controllers'));