my.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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. // alert(JSON.stringify(result.data.data));
  25. $scope.vm = result.data.data;
  26. console.log($scope.vm.avatar);
  27. $scope.vm.sex = $scope.vm.sex+'';
  28. $scope.vm.emotion = $scope.vm.emotion+'';
  29. if($scope.vm.birthday){
  30. var arr1 = $scope.vm.birthday.split("-");
  31. $scope.vm.birthday1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]);
  32. }
  33. msg.hide();
  34. },function(error){
  35. msg.hide();
  36. // msg.error(error.data.message);
  37. })
  38. });
  39. $scope.setAvator = function () {
  40. common.setAvator().then(function (result) {
  41. var response = JSON.parse(result.response);
  42. $scope.vm.avatar = config.imgServer + response.data.file;
  43. });
  44. };
  45. //保存个人信息
  46. $scope.vm={
  47. pic:"",
  48. sex:"",
  49. signture:"",
  50. emotion:"",
  51. job:"",
  52. tall:"",
  53. nickname:"",
  54. birthday1:""
  55. };
  56. $scope.saveMaterial = function(){
  57. var data = {
  58. sex:$scope.vm.sex,
  59. signture:$scope.vm.signture,
  60. emotion:$scope.vm.emotion,
  61. work:$scope.vm.work,
  62. height:$scope.vm.height,
  63. city:$scope.vm.city,
  64. nickname:$scope.vm.nickname,
  65. birthday:$scope.vm.birthday1
  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. msg.loading();
  75. myService.saveMaterial(data).then(function(result){
  76. msg.hide();
  77. msg.success("保存成功!");
  78. $state.go('app.my');
  79. myService.myInfo();
  80. },function(error){
  81. msg.hide();
  82. msg.error(error.data.message);
  83. })
  84. }
  85. }]);
  86. app.controller('settingCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  87. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  88. $scope.$on('$ionicView.beforeEnter', function () {
  89. $ionicTabsDelegate.showBar(false);
  90. });
  91. //退出登陆
  92. $scope.logout = function(){
  93. storage.remove("token");
  94. storage.remove("user");
  95. $state.go("login");
  96. }
  97. }]);
  98. app.controller('aboutMiaoCtrl', ["$scope","$ionicTabsDelegate","$timeout", "$state", "myService", "msg","storage"
  99. , function ($scope,$ionicTabsDelegate,$timeout, $state,myService, msg, storage) {
  100. $scope.$on('$ionicView.beforeEnter', function () {
  101. $scope.aboutMiao();
  102. });
  103. $scope.aboutMiao = function(){
  104. myService.aboutMiao().then(function(result){
  105. $scope.items = result.data.data;
  106. },function(error){
  107. msg.error(error.data.message)
  108. })
  109. };
  110. }]);
  111. app.controller('withdrawCtrl', ["$scope","$ionicTabsDelegate","$ionicHistory","$timeout", "$state", "myService", "msg","storage"
  112. , function ($scope,$ionicTabsDelegate, $ionicHistory,$timeout,$state,myService, msg, storage) {
  113. $scope.vm={
  114. pay:"",
  115. cash:""
  116. };
  117. $scope.$on("$ionicView.enter",function(){
  118. myService.showAccount().then(function(result){
  119. $scope.accountId = result.data.data;
  120. var items = result.data.data;
  121. if(items.length==0){
  122. msg.text("请先添加账户");
  123. $state.go("app.my_account_add");
  124. return
  125. }
  126. $scope.pays=[];
  127. angular.forEach(items,function(item){
  128. if(item.bank_name!=null) {
  129. var value=item.bank_name+"(";
  130. var len=item.bank_number.length;
  131. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  132. var txt2=item.bank_number.substr(len-4,4);
  133. value=value+txt1+txt2+")";
  134. }
  135. else {
  136. value=item.type;
  137. }
  138. $scope.pays.push({id:item.id,value:value});
  139. });
  140. $scope.vm.pay = $scope.pays[0]
  141. },function(error){
  142. msg.error(error.data.message)
  143. })
  144. });
  145. $scope.withdraw = function(){
  146. var data = {
  147. data:{
  148. bank_id:$scope.vm.pay.id,
  149. cash:$scope.vm.cash
  150. }
  151. };
  152. myService.withdraw(data).then(function(result){
  153. msg.text("提现申请已提交");
  154. $timeout(function () {
  155. $ionicHistory.goBack();
  156. },1000);
  157. },function(error){
  158. })
  159. }
  160. }]);
  161. app.controller('payoutCtrl', ["$scope","$ionicTabsDelegate","$timeout","$ionicHistory", "$state", "myService", "msg","storage"
  162. , function ($scope,$ionicTabsDelegate, $timeout, $ionicHistory,$state,myService, msg, storage) {
  163. $scope.vm={
  164. pay:"",
  165. cash:""
  166. };
  167. $scope.$on("$ionicView.enter",function(){
  168. myService.showAccount().then(function(result){
  169. $scope.accountId = result.data.data;
  170. var items = result.data.data;
  171. $scope.pays=[];
  172. angular.forEach(items,function(item){
  173. if(item.bank_name!=null) {
  174. var value=item.bank_name+"(";
  175. var len=item.bank_number.length;
  176. var txt1=item.bank_number.substr(0,len-4).replace(/\d+/g,'**');
  177. var txt2=item.bank_number.substr(len-4,4);
  178. value=value+txt1+txt2+")";
  179. }
  180. else {
  181. value=item.type;
  182. }
  183. $scope.pays.push({id:item.id,value:value});
  184. })
  185. },function(error){
  186. msg.error(error.data.message)
  187. })
  188. });
  189. $scope.withdraw = function(){
  190. var data = {
  191. data:{
  192. bank_id:$scope.vm.pay.id,
  193. cash:$scope.vm.cash
  194. }
  195. };
  196. myService.withdraw(data).then(function(result){
  197. msg.text("提现申请已提交");
  198. $timeout(function () {
  199. $ionicHistory.goBack();
  200. },1000);
  201. },function(error){
  202. })
  203. }
  204. }]);
  205. app.controller('payExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  206. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  207. $scope.$on('$ionicView.beforeEnter', function () {
  208. $scope.payExplain();
  209. });
  210. $scope.payExplain = function(){
  211. myService.payExplain().then(function(result){
  212. $scope.items = result.data.data;
  213. },function(error){
  214. msg.error(error.data.message)
  215. })
  216. };
  217. }]);
  218. app.controller('explainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  219. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  220. }]);
  221. app.controller('payDetailCtrl', ["$scope","$ionicTabsDelegate","$ionicHistory", "$state", "myService", "msg","storage"
  222. , function ($scope,$ionicTabsDelegate,$ionicHistory, $state,myService, msg, storage) {
  223. $scope.goBack = function(){
  224. $ionicHistory.goBack();
  225. }
  226. }]);
  227. app.controller('contactCtrl', ["$scope","$ionicTabsDelegate", "$timeout","$state", "myService", "msg","storage"
  228. , function ($scope,$ionicTabsDelegate, $timeout,$state,myService, msg, storage) {
  229. $scope.vm={
  230. content:"",
  231. email:""
  232. };
  233. $scope.contact = function(){
  234. var data={
  235. data:{
  236. content:$scope.vm.content,
  237. email:$scope.vm.email
  238. }
  239. };
  240. myService.contact(data).then(function(result){
  241. msg.text("发送成功");
  242. $timeout(function(){
  243. $state.go("app.my");
  244. },1000);
  245. },function(error){
  246. msg.error(error.data.message);
  247. })
  248. }
  249. }]);
  250. app.controller('attentionCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  251. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  252. $scope.$on('$ionicView.beforeEnter', function () {
  253. myService.attention().then(function(result){
  254. $scope.users = result.data.data;
  255. },function(error){
  256. })
  257. });
  258. $scope.toMyUserDetail = function (id) {
  259. myService.toMyUserDetail(id).then(function(result){
  260. $scope.items = result.data.data;
  261. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  262. },function(error){
  263. //msg.error(msg.data.error)
  264. })
  265. };
  266. }]);
  267. app.controller('careCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  268. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  269. $scope.$on('$ionicView.beforeEnter', function () {
  270. myService.careMe().then(function(result){
  271. $scope.users = result.data.data;
  272. },function(error){
  273. })
  274. });
  275. $scope.toMyUserDetail = function (id) {
  276. myService.toMyUserDetail(id).then(function(result){
  277. $scope.items = result.data.data;
  278. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  279. },function(error){
  280. //msg.error(msg.data.error)
  281. })
  282. };
  283. $ionicModal.fromTemplateUrl('my-modal.html', {
  284. scope: $scope,
  285. animation: 'slide-in-up'
  286. }).then(function (modal) {
  287. $scope.modal = modal;
  288. });
  289. //发私信
  290. $scope.vm={
  291. content:"",
  292. comment_id:""
  293. };
  294. $scope.closeModal = function () {
  295. var data = {
  296. content: $scope.vm.content,
  297. to_user_id: $scope.item.id
  298. };
  299. myService.sendLetter(data).then(function (result) {
  300. msg.success('回复成功');
  301. $scope.vm.content = '';
  302. $scope.item = null;
  303. $scope.modal.hide();
  304. }, function (error) {
  305. msg.error('回复失败');
  306. });
  307. };
  308. $scope.hideModal = function(){
  309. $scope.modal.hide();
  310. };
  311. $scope.reply = function (user) {
  312. event.stopPropagation();
  313. $scope.item = user;
  314. $scope.modal.show();
  315. }
  316. }]);
  317. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  318. , function ($scope,homeService,$stateParams, $state, msg) {
  319. var user_id = $stateParams.user_id;
  320. $scope.$on('$ionicView.beforeEnter',function(){
  321. $scope.toUserDetail(user_id);
  322. });
  323. $scope.toUserDetail = function(user_id){
  324. homeService.toUserDetail(user_id).then(function(result){
  325. $scope.items = result.data.data;
  326. $scope.user = result.data.data.user;
  327. $scope.dreams = $scope.user.sup_dream;
  328. },function(error){
  329. })
  330. };
  331. $scope.toDetail = function(){
  332. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  333. }
  334. }]);
  335. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  336. , function ($scope,homeService,$stateParams, $state, msg) {
  337. var user_id = $stateParams.user_id;
  338. $scope.$on('$ionicView.beforeEnter',function(){
  339. $scope.toUserDetail(user_id);
  340. });
  341. $scope.toUserDetail = function(user_id){
  342. homeService.toUserDetail(user_id).then(function(result){
  343. $scope.items = result.data.data;
  344. $scope.user = result.data.data.user;
  345. $scope.dreams = $scope.user.dreams;
  346. },function(error){
  347. })
  348. };
  349. $scope.toDetail = function(){
  350. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  351. };
  352. }]);
  353. //app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  354. // , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  355. //
  356. // }]);
  357. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", '$location',"$state", "myService", "msg","storage"
  358. , function ($scope,$ionicTabsDelegate,$location, $state,myService, msg, storage) {
  359. $scope.$on('$ionicView.beforeEnter', function () {
  360. myService.letter().then(function(result){
  361. $scope.items = result.data.data;
  362. },function(error){
  363. });
  364. });
  365. $scope.toLetter = function(id){
  366. if($location.path()=="/app/home/message/letter"){
  367. console.log($location.path());
  368. $state.go('app.letterDetail')
  369. }
  370. else {
  371. $state.go('app.myLetterDetail')
  372. }
  373. }
  374. }]);
  375. app.controller('letterDetailCtrl', ["$scope","$ionicTabsDelegate",'$stateParams',"$state", "myService", "msg","storage"
  376. , function ($scope,$ionicTabsDelegate,$stateParams, $state,myService, msg, storage) {
  377. var id = $stateParams.id;
  378. $scope.$on('$ionicView.beforeEnter', function () {
  379. myService.letter().then(function(result){
  380. $scope.items = result.data.data;
  381. },function(error){
  382. });
  383. });
  384. }]);
  385. app.controller('rechargeCtrl', ["$scope","$timeout","$ionicHistory","$ionicTabsDelegate", "$state", "myService", "msg"
  386. , function ($scope,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService, msg) {
  387. $scope.$on('$ionicView.beforeEnter', function () {
  388. $ionicTabsDelegate.showBar(false);
  389. myService.myInfo().then(function(result){
  390. $scope.vm = result.data.data;
  391. $scope.vm.number = '';
  392. $scope.vm.payType = 2;
  393. })
  394. });
  395. $scope.payExplain = function(){
  396. $state.go("app.payExplain")
  397. };
  398. $scope.withdraw = function(){
  399. $state.go("app.withdraw")
  400. };
  401. $scope.testcharge = function(number){
  402. if (!number) {
  403. msg.text('请输入充值金额');
  404. return;
  405. }
  406. myService.testcharge(number,2).then(function (result) {
  407. msg.text("充值成功");
  408. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  409. // $timeout(function(){
  410. // $ionicHistory.goBack();
  411. // },500)
  412. });
  413. };
  414. //充值
  415. $scope.charge = function(number){
  416. if (!number) {
  417. msg.text('请输入充值金额');
  418. return;
  419. }
  420. myService.charge(number,2).then(function (result) {
  421. //todo:result需要返回支付宝或者微信的签名信息
  422. console.log("result: " + JSON.stringify(result));
  423. var payInfo = result.data.data;
  424. if ($scope.vm.payType == 1) { //支付宝
  425. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  426. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  427. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  428. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  429. //当e.resultStatus为9000时,请去服务端验证支付结果
  430. $scope.clicksub = false;
  431. if (e.resultStatus == '9000') {
  432. alert(orderID);
  433. //支付成功
  434. // $state.go('app.my');
  435. } else {
  436. msg.error("支付失败");
  437. // msg.error("支付失败:" + JSON.stringify(e));
  438. }
  439. }, function error(e) {
  440. $scope.clicksub = false;
  441. // msg.error("支付失败:" + JSON.stringify(e));
  442. msg.error("支付失败");
  443. });
  444. }
  445. if ($scope.vm.payType == 2) { //微信
  446. // var obj = JSON.parse(payInfo);
  447. var obj = payInfo.orderString;
  448. // console.log("obj: " + JSON.stringify(obj));
  449. var params = {
  450. partnerid: obj.partnerid, // merchant id
  451. prepayid: obj.prepayid, // prepay id
  452. noncestr: obj.noncestr, // nonce
  453. timestamp: obj.timestamp, // timestamp
  454. sign: obj.sign, // signed string
  455. };
  456. // console.log("result: " + JSON.stringify(params));
  457. Wechat.sendPaymentRequest(params, function (r) {
  458. $scope.clicksub = false;
  459. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  460. // alert(result);
  461. //支付成功
  462. // $state.go('app.my');
  463. }, function (erro) {
  464. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  465. });
  466. }, function (reason) {
  467. $scope.clicksub = false;
  468. // msg.alert("支付失败:" + JSON.stringify(reason));
  469. });
  470. }
  471. // msg.text("充值成功");
  472. // $state.go('app.my');
  473. });
  474. }
  475. }]);
  476. app.controller('payCtrl', ["$scope","$timeout","$ionicHistory","$ionicTabsDelegate", "$timeout","$ionicHistory","$state", "myService", "msg"
  477. , function ($scope,$timeout,$ionicHistory,$ionicTabsDelegate, $timeout,$ionicHistory,$state, myService, msg) {
  478. $scope.$on('$ionicView.beforeEnter', function () {
  479. myService.myInfo().then(function(result){
  480. $scope.vm = result.data.data;
  481. $scope.vm.money = '';
  482. $scope.vm.payType = 2;
  483. })
  484. });
  485. $scope.payExplain = function(){
  486. $state.go("app.explain")
  487. };
  488. $scope.withdraw = function(){
  489. $state.go("app.payout")
  490. };
  491. //充值
  492. $scope.testcharge = function(number){
  493. if (!number) {
  494. msg.text('请输入充值金额');
  495. return;
  496. }
  497. myService.testcharge(number,2).then(function (result) {
  498. msg.text("充值成功");
  499. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  500. $timeout(function(){
  501. $ionicHistory.goBack();
  502. },500)
  503. });
  504. }
  505. //充值
  506. $scope.charge = function(number){
  507. if (!number) {
  508. msg.text('请输入充值金额');
  509. return;
  510. }
  511. myService.charge(number,2).then(function (result) {
  512. //todo:result需要返回支付宝或者微信的签名信息
  513. console.log("result: " + JSON.stringify(result));
  514. var payInfo = result.data;
  515. if ($scope.vm.payType == 1) { //支付宝
  516. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  517. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  518. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  519. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  520. //当e.resultStatus为9000时,请去服务端验证支付结果
  521. $scope.clicksub = false;
  522. if (e.resultStatus == '9000') {
  523. alert(orderID);
  524. //支付成功
  525. // $state.go('app.my');
  526. } else {
  527. msg.error("支付失败");
  528. // msg.error("支付失败:" + JSON.stringify(e));
  529. }
  530. }, function error(e) {
  531. $scope.clicksub = false;
  532. // msg.error("支付失败:" + JSON.stringify(e));
  533. msg.error("支付失败");
  534. });
  535. }
  536. if ($scope.vm.payType == 2) { //微信
  537. var obj = JSON.parse(payInfo);
  538. var params = {
  539. partnerid: obj.partnerid, // merchant id
  540. prepayid: obj.prepayid, // prepay id
  541. noncestr: obj.noncestr, // nonce
  542. timestamp: obj.timestamp, // timestamp
  543. sign: obj.sign, // signed string
  544. };
  545. Wechat.sendPaymentRequest(params, function (r) {
  546. $scope.clicksub = false;
  547. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  548. // alert(result);
  549. //支付成功
  550. // $state.go('app.my');
  551. }, function (erro) {
  552. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  553. });
  554. }, function (reason) {
  555. $scope.clicksub = false;
  556. msg.alert("支付失败:" + JSON.stringify(reason));
  557. });
  558. }
  559. // msg.text("充值成功");
  560. // $state.go('app.my');
  561. });
  562. }
  563. }]);
  564. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  565. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  566. $scope.$on('$ionicView.beforeEnter', function () {
  567. $ionicTabsDelegate.showBar(false);
  568. $scope.showAccount();
  569. });
  570. $scope.showAccount = function(){
  571. myService.showAccount().then(function(result){
  572. $scope.items = result.data.data;
  573. },function(error){
  574. msg.error(error.data.message);
  575. })
  576. };
  577. $scope.destroyAccount = function(id){
  578. myService.destroyAccount(id).then(function(result){
  579. msg.text("删除成功");
  580. $scope.showAccount();
  581. },function(error){
  582. msg.error(error.data.message);
  583. })
  584. }
  585. }]);
  586. app.controller('my_account_addCtrl', ["$scope","config","common","$timeout","$ionicTabsDelegate", "$state", "myService", "msg"
  587. , function ($scope,config,common,$timeout,$ionicTabsDelegate, $state, myService, msg) {
  588. $scope.addpict = function () {
  589. common.chooseImage().then(function (qrcode) {
  590. common.uploadFiles(qrcode,1).then(function (result) {
  591. var response = JSON.parse(result.response);
  592. var file = config.imgServer+response.data.file;
  593. $scope.vm.file = file;
  594. $scope.qrcode.push(file);
  595. }, function (error) {
  596. msg.error('图片上传失败');
  597. });
  598. }, function (error) {
  599. console.log('图片选择失败');
  600. });
  601. };
  602. $scope.qrcode=[];
  603. $scope.deletefile = function (file) {
  604. var index = $scope.qrcode.indexOf(file);
  605. $scope.qrcode.splice(index, 1);
  606. common.deletefile(file).then(function () {
  607. })
  608. };
  609. $scope.vm={
  610. bank_name:'',
  611. bank_number:'',
  612. bank_phone:'',
  613. bank_user:'',
  614. type:""
  615. };
  616. $scope.addAccount = function () {
  617. var data = {
  618. data:{
  619. bank_name:$scope.vm.bank_name,
  620. bank_number:$scope.vm.bank_number,
  621. bank_phone:$scope.vm.bank_phone,
  622. bank_user:$scope.vm.bank_user
  623. }
  624. };
  625. //msg.loading('保存中...');
  626. msg.loading();
  627. myService.addAccount(data).then(function (result) {
  628. msg.hide();
  629. $state.go('app.my_account');
  630. }, function (error) {
  631. msg.hide();
  632. msg.error(error.data.message);
  633. });
  634. };
  635. $scope.addQrcode = function(){
  636. var data = {
  637. data:{
  638. type:$scope.vm.type,
  639. qrcode:$scope.vm.file
  640. //qrcode:"https://www.baidu.com/img/bd_logo1.png"
  641. }
  642. };
  643. myService.addQrcode(data).then(function(result){
  644. msg.text("添加成功",true);
  645. $state.go("app.my_account");
  646. },function(error){
  647. msg.error(error.data.message);
  648. })
  649. }
  650. }]);
  651. app.controller('messageCtrl', ["$scope", "$location","$ionicTabsDelegate","$state", "myService", "msg"
  652. , function ($scope,$location,$ionicTabsDelegate, $state, myService, msg) {
  653. $scope.$on('$ionicView.beforeEnter', function () {
  654. $ionicTabsDelegate.showBar(false);
  655. myService.messageInfo().then(function(result){
  656. $scope.infos = result.data.data;
  657. },function(error){
  658. });
  659. });
  660. $scope.notRead = function(){
  661. myService.notRead().then(function(result){
  662. myService.messageInfo().then(function(result){
  663. $scope.infos = result.data.data;
  664. },function(error){
  665. });
  666. },function(error){
  667. })
  668. };
  669. //梦想消息
  670. $scope.systemInfo = function(){
  671. if($location.path()=='/app/my/message'){
  672. $state.go("app.my_message_sys");
  673. }
  674. else {
  675. $state.go("app.message_sys");
  676. //myService.systemInfo().then(function(result){
  677. //},function(error){
  678. //
  679. //});
  680. }
  681. };
  682. //支持消息
  683. $scope.replyMy = function(){
  684. if($location.path()=='/app/my/message'){
  685. $state.go("app.my_message_reply");
  686. }
  687. else {
  688. $state.go("app.message_reply");
  689. }
  690. };
  691. //通知
  692. $scope.personalLetter = function(){
  693. if($location.path()=='/app/my/message'){
  694. $state.go("app.personalLetter");
  695. }
  696. else {
  697. $state.go("app.letter");
  698. }
  699. };
  700. }]);
  701. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  702. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  703. $scope.$on('$ionicView.beforeEnter', function () {
  704. $ionicTabsDelegate.showBar(false);
  705. $scope.load(true);
  706. myService.myInfo().then(function(result){
  707. $scope.user = result.data.data
  708. });
  709. });
  710. $scope.filter = {
  711. hasMore: false,
  712. pageIndex: 1,
  713. pageSize: 25
  714. };
  715. $scope.load = function (init) {
  716. if (init) {
  717. $scope.filter.pageIndex = 1;
  718. $scope.dreams = [];
  719. }
  720. msg.loading();
  721. myService.myDream($scope.filter.pageIndex).then(function(result){
  722. msg.hide();
  723. $scope.filter.pageIndex++;
  724. var more = (result.data.data.data.length >= $scope.filter.pageSize);
  725. $scope.filter.hasMore = more;
  726. $scope.dreams = $scope.dreams.concat(result.data.data.data);
  727. if (init) {
  728. $scope.$broadcast('scroll.refreshComplete');
  729. } else {
  730. $scope.$broadcast('scroll.infiniteScrollComplete');
  731. }
  732. },function(error){
  733. msg.hide();
  734. });
  735. };
  736. $scope.toDetail = function (id) {
  737. $state.go('app.my_dreamdetail',{id:id});
  738. };
  739. $scope.time = function(){
  740. }
  741. }]);
  742. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  743. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  744. $scope.$on('$ionicView.beforeEnter', function () {
  745. $ionicTabsDelegate.showBar(false);
  746. myService.collect().then(function(result){
  747. $scope.dreams = result.data.data.dreams;
  748. });
  749. });
  750. $scope.toDetail = function (id) {
  751. $state.go('app.my_dreamdetail',{id:id});
  752. };
  753. }]);
  754. app.controller('messageSysCtrl', ["$scope","$ionicPopup","$location", "$ionicTabsDelegate","$state", "myService", "msg"
  755. , function ($scope,$ionicPopup,$location,$ionicTabsDelegate, $state, myService, msg) {
  756. $scope.$on('$ionicView.beforeEnter', function () {
  757. myService.systemInfo().then(function(result){
  758. $scope.sysInfos = result.data.data;
  759. },function(error){
  760. });
  761. });
  762. $scope.vm = {
  763. content:""
  764. };
  765. $scope.imgs = [];
  766. $scope.video = {};
  767. $scope.addpict = function () {
  768. common.chooseImage().then(function (img) {
  769. common.uploadFiles(img,1).then(function (result) {
  770. var response = JSON.parse(result.response);
  771. var file = config.imgServer + response.data.file;
  772. $scope.imgs.push(file);
  773. }, function (error) {
  774. msg.error('图片上传失败');
  775. });
  776. }, function (error) {
  777. console.log('图片选择失败');
  778. });
  779. };
  780. $scope.deletefile = function (file) {
  781. var index = $scope.imgs.indexOf(file);
  782. $scope.imgs.splice(index, 1);
  783. common.deletefile(file).then(function () {
  784. })
  785. };
  786. $scope.addvideo = function () {
  787. common.chooseVideo().then(function (file) {
  788. common.uploadFiles(file, 2).then(function (result) {
  789. var response = JSON.parse(result.response);
  790. var file = config.imgServer+response.data.file;
  791. $scope.video.isOK = true;
  792. $scope.video.file = response.data.file;
  793. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  794. }, function (error) {
  795. msg.error('视频上传失败');
  796. });
  797. }, function (erro) {
  798. console.log('选择视频失败');
  799. });
  800. };
  801. $scope.deletevideo = function (file) {
  802. common.deletefile(file).then(function (res) {
  803. },function(erro){
  804. alert(JSON.stringify(erro));
  805. })
  806. };
  807. $scope.goMes = function(is_reply,is_url,dream_id,is_end,message,user_id){
  808. //发送私信
  809. if(is_reply==1){
  810. var myPopup = $ionicPopup.show({
  811. template : '<div>' +
  812. '<textarea autofocus style="border: 1px solid #D0D0D0" name="" id="" cols="30" rows="8" ng-model="vm.content" placeholder="对他的好意给予感谢的回复"></textarea onf>' +
  813. '<a class="btn-file-up" ng-click="addpict()">' +
  814. '<img src="img/icon_photo.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  815. '<em style="font-size: 16px">添加图片</em>' +
  816. '</a>' +
  817. '<a class="btn-file-up" ng-click="addvideo()">' +
  818. '<img src="img/icon_video.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  819. '<em style="font-size: 16px">添加视频</em>' +
  820. '</a>' +
  821. '<a ng-repeat="item in imgs" ng-click="showImages(item)" class="img-file-up">' +
  822. '<b style="background-image:url({{item}});"><em ng-click="deletefile(item)" class="ion-ios-close-outline"></em></b>' +
  823. '</a>' +
  824. '<div class="img-file-up" ng-if="video.isOK">' +
  825. '<div style="position:relative;">' +
  826. '<em ng-click="deletevideo(video.file)" class="ion-ios-close-outline"></em>' +
  827. '<video ng-src="{{video.file | trustUrl}}" poster="{{video.vpic}}" controls="controls"></video>' +
  828. '</div>' +
  829. '</div>' +
  830. '</div>',
  831. title: message,
  832. //subTitle: 'Please use normal things',
  833. scope: $scope,
  834. buttons: [
  835. { text: '取消' },
  836. {
  837. text: '<b>确定</b>',
  838. type: 'button-positive',
  839. onTap: function(e) {
  840. var data = {
  841. to_user_id:user_id,
  842. content:$scope.vm.content,
  843. image:$scope.imgs,
  844. video:$scope.video.file,
  845. //image:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg']
  846. };
  847. myService.sendLetter(data).then(function(result){
  848. if(result.data.status_code==0){
  849. msg.success('发送成功');
  850. }
  851. })
  852. }
  853. }
  854. ]
  855. });
  856. }
  857. //跳转
  858. else if(is_url==1){
  859. if($location.path()=="/app/home/message/sys"){
  860. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  861. }
  862. else {
  863. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  864. }
  865. }
  866. //梦想结束
  867. else if(is_end==1){
  868. var endTemplate = '<div style="text-align: center"><p>恭喜你成功地向你的梦想迈出最大的一步,照接下来的步骤做就可以领取你的梦想资金啦!</p>' +
  869. '<p>要取出全部梦想资金,</p>' +
  870. '<p>你需要亲自问候你的梦主</p>' +
  871. '<p>致出最诚挚的感谢</p>' +
  872. '<p>点击《确定》我们会提供</p>' +
  873. '<p>《梦主》的资料</p>' +
  874. '<p>如果你觉得不合适,你可以点击《取消》,但是《梦主》的资金会被退还给他</p>' +
  875. '<p>你以后创建梦想也会比较难</p>' +
  876. '</div>';
  877. msg.confirm('恭喜你!',endTemplate).then(function(result){
  878. if(result==true){
  879. myService.sure_meet(dream_id,1).then(function(res){
  880. if(res.data.status_code==0){
  881. if(res.data.data==0){
  882. msg.success('该梦想暂无梦主!');
  883. }
  884. else {
  885. msg.success('确定见面,期待与梦主的相见吧!');
  886. }
  887. }
  888. })
  889. }
  890. else {
  891. myService.sure_meet(dream_id,0).then(function(res){
  892. if(res.data.status_code==0){
  893. msg.success('已取消见面!');
  894. }
  895. })
  896. }
  897. })
  898. }
  899. }
  900. }]);
  901. app.controller('messageReplyCtrl', ["$scope","$location","$ionicPopup","$ionicTabsDelegate", "$state", "myService", "msg", "$ionicModal"
  902. , function ($scope,$location,$ionicPopup,$ionicTabsDelegate, $state, myService, msg, $ionicModal) {
  903. $scope.$on('$ionicView.beforeEnter', function () {
  904. $scope.load();
  905. });
  906. $scope.load = function () {
  907. myService.replyMy().then(function (result) {
  908. $scope.comments = result.data.data;
  909. }, function (error) {
  910. });
  911. };
  912. $scope.goMes = function(info,img,is_max,mes,video,attr_id,dream_id){
  913. //收到私信
  914. if(attr_id==7){
  915. if(video!=null){
  916. var letterTemplate = '<div style="text-align: center">' +
  917. '<img src="'+img+'" style="border-radius: 100%">' +
  918. '<video src="'+video+'"></video>' +
  919. '<p>'+info+'</p>' +
  920. '</div>';
  921. }
  922. else {
  923. var letterTemplate = '<div style="text-align: center">' +
  924. '<img src="'+img+'" style="border-radius: 100%">' +
  925. '<p>'+info+'</p>' +
  926. '</div>';
  927. }
  928. msg.confirm('私信',letterTemplate,'梦想页').then(function(){
  929. if($location.path()=="/app/home/message/reply"){
  930. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  931. }
  932. else {
  933. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  934. }
  935. })
  936. }
  937. //成为梦主
  938. else if(is_max==1){
  939. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  940. '<p>'+ info +'</p>' +
  941. //'<p>小蝶将以你提供的微信/电话联系你,并到你越好的地点亲自感谢你给予的支持和鼓励。</p>' +
  942. //'<p>如果你不希望见面或者不想要梦想者拥有你的联系方式,请按《不要见面的按钮或者联系客服》</p>' +
  943. //'<p>请按《不要见面的按钮或者联系客服》</p>' +
  944. '</div>';
  945. msg.confirm('恭喜你!',maxTemplate);
  946. }
  947. else {
  948. if($location.path()=="/app/home/message/reply"){
  949. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  950. }
  951. else {
  952. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  953. }
  954. }
  955. };
  956. //我的回复
  957. $scope.vm = {
  958. content: ""
  959. };
  960. $ionicModal.fromTemplateUrl('my-modal.html', {
  961. scope: $scope,
  962. animation: 'slide-in-up'
  963. }).then(function (modal) {
  964. $scope.modal = modal;
  965. });
  966. //$ionicModal.fromTemplateUrl('my-modal.html', {
  967. // scope: $scope,
  968. // animation: 'slide-in-up'
  969. //}).then(function (modal) {
  970. // $scope.modal = modal;
  971. //});
  972. //$scope.openModal = function () {
  973. // $scope.modal.show();
  974. //};
  975. //$scope.closeModal = function () {
  976. // $scope.modal.hide();
  977. //
  978. //};
  979. $scope.goDetail = function (id,interaction_id){
  980. $state.go('app.home_dreamdetail',{id:id,interaction_id:interaction_id,type:2});
  981. };
  982. //我的回复
  983. //$scope.vm={
  984. // content:"",
  985. // comment_id:""
  986. //};
  987. //$scope.closeModal = function () {
  988. // var data = {
  989. // content: $scope.vm.content,
  990. // comment_id: $scope.item.id,
  991. // interaction_id: $scope.item.interaction_id
  992. // };
  993. // myService.myReplay(data).then(function (result) {
  994. // msg.success('回复成功');
  995. // $scope.load();
  996. // }, function (error) {
  997. // msg.error('回复失败');
  998. // });
  999. // $scope.vm.content = '';
  1000. // $scope.item = null;
  1001. // $scope.modal.hide();
  1002. //};
  1003. //
  1004. //$scope.reply = function (item) {
  1005. // $scope.item = item;
  1006. // $scope.modal.show();
  1007. //}
  1008. }]);
  1009. })(angular.module('app.controllers'));