my.js 20 KB

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