my.js 19 KB

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