my.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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('paySuccessCtrl', ["$scope","$stateParams","$ionicTabsDelegate","$ionicHistory", "$state", "myService", "msg","storage"
  219. , function ($scope,$stateParams,$ionicTabsDelegate,$ionicHistory, $state,myService, msg, storage) {
  220. var item = $stateParams.item;
  221. alert(item.out_trade_no);
  222. $scope.goBack = function(){
  223. $ionicHistory.goBack();
  224. }
  225. }]);
  226. app.controller('explainCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  227. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  228. }]);
  229. app.controller('contactCtrl', ["$scope","$ionicTabsDelegate", "$timeout","$state", "myService", "msg","storage"
  230. , function ($scope,$ionicTabsDelegate, $timeout,$state,myService, msg, storage) {
  231. $scope.vm={
  232. content:"",
  233. email:""
  234. };
  235. $scope.contact = function(){
  236. var data={
  237. data:{
  238. content:$scope.vm.content,
  239. email:$scope.vm.email
  240. }
  241. };
  242. myService.contact(data).then(function(result){
  243. msg.text("发送成功");
  244. $timeout(function(){
  245. $state.go("app.my");
  246. },1000);
  247. },function(error){
  248. msg.error(error.data.message);
  249. })
  250. }
  251. }]);
  252. app.controller('attentionCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  253. , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  254. $scope.$on('$ionicView.beforeEnter', function () {
  255. myService.attention().then(function(result){
  256. $scope.users = result.data.data;
  257. },function(error){
  258. })
  259. });
  260. $scope.toMyUserDetail = function (id) {
  261. myService.toMyUserDetail(id).then(function(result){
  262. $scope.items = result.data.data;
  263. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  264. },function(error){
  265. //msg.error(msg.data.error)
  266. })
  267. };
  268. }]);
  269. app.controller('careCtrl', ["$scope","$ionicTabsDelegate",'$ionicModal',"$state", "myService", "msg","storage"
  270. , function ($scope,$ionicTabsDelegate,$ionicModal, $state,myService, msg, storage) {
  271. $scope.$on('$ionicView.beforeEnter', function () {
  272. myService.careMe().then(function(result){
  273. $scope.users = result.data.data;
  274. },function(error){
  275. })
  276. });
  277. $scope.toMyUserDetail = function (id) {
  278. myService.toMyUserDetail(id).then(function(result){
  279. $scope.items = result.data.data;
  280. $state.go('app.attention_Detail',{id:id,items:$scope.items});
  281. },function(error){
  282. //msg.error(msg.data.error)
  283. })
  284. };
  285. $ionicModal.fromTemplateUrl('my-modal.html', {
  286. scope: $scope,
  287. animation: 'slide-in-up'
  288. }).then(function (modal) {
  289. $scope.modal = modal;
  290. });
  291. //发私信
  292. $scope.vm={
  293. content:"",
  294. comment_id:""
  295. };
  296. $scope.closeModal = function () {
  297. var data = {
  298. content: $scope.vm.content,
  299. to_user_id: $scope.item.id
  300. };
  301. myService.sendLetter(data).then(function (result) {
  302. msg.success('回复成功');
  303. $scope.vm.content = '';
  304. $scope.item = null;
  305. $scope.modal.hide();
  306. }, function (error) {
  307. msg.error('回复失败');
  308. });
  309. };
  310. $scope.hideModal = function(){
  311. $scope.modal.hide();
  312. };
  313. $scope.reply = function (user) {
  314. event.stopPropagation();
  315. $scope.item = user;
  316. $scope.modal.show();
  317. }
  318. }]);
  319. app.controller('mySupportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  320. , function ($scope,homeService,$stateParams, $state, msg) {
  321. var user_id = $stateParams.user_id;
  322. $scope.$on('$ionicView.beforeEnter',function(){
  323. $scope.toUserDetail(user_id);
  324. });
  325. $scope.toUserDetail = function(user_id){
  326. homeService.toUserDetail(user_id).then(function(result){
  327. $scope.items = result.data.data;
  328. $scope.user = result.data.data.user;
  329. $scope.dreams = $scope.user.sup_dream;
  330. },function(error){
  331. })
  332. };
  333. $scope.toDetail = function(){
  334. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  335. }
  336. }]);
  337. app.controller('myOldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  338. , function ($scope,homeService,$stateParams, $state, msg) {
  339. var user_id = $stateParams.user_id;
  340. $scope.$on('$ionicView.beforeEnter',function(){
  341. $scope.toUserDetail(user_id);
  342. });
  343. $scope.toUserDetail = function(user_id){
  344. homeService.toUserDetail(user_id).then(function(result){
  345. $scope.items = result.data.data;
  346. $scope.user = result.data.data.user;
  347. $scope.dreams = $scope.user.dreams;
  348. },function(error){
  349. })
  350. };
  351. $scope.toDetail = function(){
  352. $state.go("app.attention_Detail",{user_id:user_id,items:$scope.items})
  353. };
  354. }]);
  355. //app.controller('messageReplyCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg","storage"
  356. // , function ($scope,$ionicTabsDelegate, $state,myService, msg, storage) {
  357. //
  358. // }]);
  359. app.controller('personalLetterCtrl', ["$scope","$ionicTabsDelegate", '$location',"$state", "myService", "msg","storage"
  360. , function ($scope,$ionicTabsDelegate,$location, $state,myService, msg, storage) {
  361. $scope.$on('$ionicView.beforeEnter', function () {
  362. myService.letter().then(function(result){
  363. $scope.items = result.data.data;
  364. },function(error){
  365. });
  366. });
  367. $scope.toLetter = function(id){
  368. if($location.path()=="/app/home/message/letter"){
  369. console.log($location.path());
  370. $state.go('app.letterDetail')
  371. }
  372. else {
  373. $state.go('app.myLetterDetail')
  374. }
  375. }
  376. }]);
  377. app.controller('letterDetailCtrl', ["$scope","$ionicTabsDelegate",'$stateParams',"$state", "myService", "msg","storage"
  378. , function ($scope,$ionicTabsDelegate,$stateParams, $state,myService, msg, storage) {
  379. var id = $stateParams.id;
  380. $scope.$on('$ionicView.beforeEnter', function () {
  381. myService.letter().then(function(result){
  382. $scope.items = result.data.data;
  383. },function(error){
  384. });
  385. });
  386. }]);
  387. app.controller('rechargeCtrl', ["$scope","$ionicModal","$timeout","$ionicHistory","$ionicTabsDelegate", "$state", "myService", "msg"
  388. , function ($scope,$ionicModal,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService, msg) {
  389. $scope.$on('$ionicView.beforeEnter', function () {
  390. $ionicTabsDelegate.showBar(false);
  391. $scope.vm = {}
  392. myService.myInfo().then(function(result){
  393. $scope.vm = result.data.data;
  394. $scope.vm.number = '';
  395. $scope.vm.payType = 2;
  396. })
  397. });
  398. $scope.payExplain = function(){
  399. $state.go("app.payExplain")
  400. };
  401. $scope.withdraw = function(){
  402. $state.go("app.withdraw")
  403. };
  404. $scope.testcharge = function(number){
  405. if (!number) {
  406. msg.text('请输入充值金额');
  407. return;
  408. }
  409. myService.testcharge(number,2).then(function (result) {
  410. msg.text("充值成功");
  411. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  412. // $timeout(function(){
  413. // $ionicHistory.goBack();
  414. // },500)
  415. });
  416. };
  417. $ionicModal.fromTemplateUrl('paysuccess-modal.html', {
  418. scope: $scope,
  419. animation: 'slide-in-up'
  420. }).then(function(modal) {
  421. $scope.modal = modal;
  422. });
  423. $scope.openModal = function() {
  424. $scope.modal.show();
  425. };
  426. $scope.closeModal = function() {
  427. $scope.modal.hide();
  428. };
  429. //当我们用到模型时,清除它!
  430. $scope.$on('$destroy', function() {
  431. $scope.modal.remove();
  432. });
  433. //充值
  434. $scope.charge = function(number){
  435. if (!number) {
  436. msg.text('请输入充值金额');
  437. return;
  438. }
  439. myService.charge(number,2).then(function (result) {
  440. //todo:result需要返回支付宝或者微信的签名信息
  441. console.log("result: " + JSON.stringify(result));
  442. var payInfo = result.data.data;
  443. var orderID = payInfo.transaction_id
  444. $scope.vm.transaction_id = payInfo.transaction_id;
  445. $scope.vm.price = payInfo.price;
  446. if ($scope.vm.payType == 1) { //支付宝
  447. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  448. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  449. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  450. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  451. //当e.resultStatus为9000时,请去服务端验证支付结果
  452. $scope.clicksub = false;
  453. if (e.resultStatus == '9000') {
  454. alert(orderID);
  455. //支付成功
  456. // $state.go('app.my');
  457. } else {
  458. msg.error("支付失败");
  459. // msg.error("支付失败:" + JSON.stringify(e));
  460. }
  461. }, function error(e) {
  462. $scope.clicksub = false;
  463. // msg.error("支付失败:" + JSON.stringify(e));
  464. msg.error("支付失败");
  465. });
  466. }
  467. if ($scope.vm.payType == 2) { //微信
  468. // var obj = JSON.parse(payInfo);
  469. var obj = payInfo.orderString;
  470. // console.log("obj: " + JSON.stringify(obj));
  471. var params = {
  472. partnerid: obj.partnerid, // merchant id
  473. prepayid: obj.prepayid, // prepay id
  474. noncestr: obj.noncestr, // nonce
  475. timestamp: obj.timestamp, // timestamp
  476. sign: obj.sign, // signed string
  477. };
  478. // console.log("result: " + JSON.stringify(params));
  479. Wechat.sendPaymentRequest(params, function (r) {
  480. $scope.clicksub = false;
  481. // $state.go("app.paySuccess")
  482. // $state.go('app.paySuccess',{item:payInfo})
  483. $scope.openModal();
  484. // alert(orderID);
  485. myService.orderStatus(orderID).then(function (result) {
  486. // alert(result);
  487. //支付成功
  488. // $state.go('app.my');
  489. }, function (erro) {
  490. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  491. });
  492. }, function (reason) {
  493. $scope.clicksub = false;
  494. // msg.alert("支付失败:" + JSON.stringify(reason));
  495. });
  496. }
  497. // msg.text("充值成功");
  498. // $state.go('app.my');
  499. });
  500. }
  501. }]);
  502. app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  503. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  504. $scope.$on('$ionicView.beforeEnter', function () {
  505. $ionicTabsDelegate.showBar(false);
  506. $scope.showAccount();
  507. });
  508. $scope.showAccount = function(){
  509. myService.showAccount().then(function(result){
  510. $scope.items = result.data.data;
  511. },function(error){
  512. msg.error(error.data.message);
  513. })
  514. };
  515. $scope.destroyAccount = function(id){
  516. myService.destroyAccount(id).then(function(result){
  517. msg.text("删除成功");
  518. $scope.showAccount();
  519. },function(error){
  520. msg.error(error.data.message);
  521. })
  522. }
  523. }]);
  524. app.controller('my_account_addCtrl', ["$scope","config","common","$timeout","$ionicTabsDelegate", "$state", "myService", "msg"
  525. , function ($scope,config,common,$timeout,$ionicTabsDelegate, $state, myService, msg) {
  526. $scope.addpict = function () {
  527. common.chooseImage().then(function (qrcode) {
  528. common.uploadFiles(qrcode,1).then(function (result) {
  529. var response = JSON.parse(result.response);
  530. var file = config.imgServer+response.data.file;
  531. $scope.vm.file = file;
  532. $scope.qrcode.push(file);
  533. }, function (error) {
  534. msg.error('图片上传失败');
  535. });
  536. }, function (error) {
  537. console.log('图片选择失败');
  538. });
  539. };
  540. $scope.qrcode=[];
  541. $scope.deletefile = function (file) {
  542. var index = $scope.qrcode.indexOf(file);
  543. $scope.qrcode.splice(index, 1);
  544. common.deletefile(file).then(function () {
  545. })
  546. };
  547. $scope.vm={
  548. bank_name:'',
  549. bank_number:'',
  550. bank_phone:'',
  551. bank_user:'',
  552. type:""
  553. };
  554. $scope.addAccount = function () {
  555. var data = {
  556. data:{
  557. bank_name:$scope.vm.bank_name,
  558. bank_number:$scope.vm.bank_number,
  559. bank_phone:$scope.vm.bank_phone,
  560. bank_user:$scope.vm.bank_user
  561. }
  562. };
  563. //msg.loading('保存中...');
  564. msg.loading();
  565. myService.addAccount(data).then(function (result) {
  566. msg.hide();
  567. $state.go('app.my_account');
  568. }, function (error) {
  569. msg.hide();
  570. msg.error(error.data.message);
  571. });
  572. };
  573. $scope.addQrcode = function(){
  574. var data = {
  575. data:{
  576. type:$scope.vm.type,
  577. qrcode:$scope.vm.file
  578. //qrcode:"https://www.baidu.com/img/bd_logo1.png"
  579. }
  580. };
  581. myService.addQrcode(data).then(function(result){
  582. msg.text("添加成功",true);
  583. $state.go("app.my_account");
  584. },function(error){
  585. msg.error(error.data.message);
  586. })
  587. }
  588. }]);
  589. app.controller('messageCtrl', ["$scope", "$location","$ionicTabsDelegate","$state", "myService", "msg"
  590. , function ($scope,$location,$ionicTabsDelegate, $state, myService, msg) {
  591. $scope.$on('$ionicView.beforeEnter', function () {
  592. $ionicTabsDelegate.showBar(false);
  593. myService.messageInfo().then(function(result){
  594. $scope.infos = result.data.data;
  595. },function(error){
  596. });
  597. });
  598. $scope.notRead = function(){
  599. myService.notRead().then(function(result){
  600. myService.messageInfo().then(function(result){
  601. $scope.infos = result.data.data;
  602. },function(error){
  603. });
  604. },function(error){
  605. })
  606. };
  607. //梦想消息
  608. $scope.systemInfo = function(){
  609. if($location.path()=='/app/my/message'){
  610. $state.go("app.my_message_sys");
  611. }
  612. else {
  613. $state.go("app.message_sys");
  614. }
  615. };
  616. //支持消息
  617. $scope.replyMy = function(){
  618. if($location.path()=='/app/my/message'){
  619. $state.go("app.my_message_reply");
  620. }
  621. else {
  622. $state.go("app.message_reply");
  623. }
  624. };
  625. //通知
  626. $scope.personalLetter = function(){
  627. if($location.path()=='/app/my/message'){
  628. $state.go("app.personalLetter");
  629. }
  630. else {
  631. $state.go("app.letter");
  632. }
  633. };
  634. }]);
  635. app.controller('dreamCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  636. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  637. $scope.$on('$ionicView.beforeEnter', function () {
  638. $ionicTabsDelegate.showBar(false);
  639. $scope.load(true);
  640. myService.myInfo().then(function(result){
  641. $scope.user = result.data.data
  642. });
  643. });
  644. $scope.filter = {
  645. hasMore: false,
  646. pageIndex: 1,
  647. pageSize: 25
  648. };
  649. $scope.load = function (init) {
  650. if (init) {
  651. $scope.filter.pageIndex = 1;
  652. $scope.dreams = [];
  653. }
  654. msg.loading();
  655. myService.myDream($scope.filter.pageIndex).then(function(result){
  656. msg.hide();
  657. $scope.filter.pageIndex++;
  658. var more = (result.data.data.data.length >= $scope.filter.pageSize);
  659. $scope.filter.hasMore = more;
  660. $scope.dreams = $scope.dreams.concat(result.data.data.data);
  661. if (init) {
  662. $scope.$broadcast('scroll.refreshComplete');
  663. } else {
  664. $scope.$broadcast('scroll.infiniteScrollComplete');
  665. }
  666. },function(error){
  667. msg.hide();
  668. });
  669. };
  670. $scope.toDetail = function (id) {
  671. $state.go('app.my_dreamdetail',{id:id});
  672. };
  673. $scope.time = function(){
  674. }
  675. }]);
  676. app.controller('collectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  677. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  678. $scope.$on('$ionicView.beforeEnter', function () {
  679. $ionicTabsDelegate.showBar(false);
  680. myService.collect().then(function(result){
  681. $scope.dreams = result.data.data.dreams;
  682. });
  683. });
  684. $scope.toDetail = function (id) {
  685. $state.go('app.my_dreamdetail',{id:id});
  686. };
  687. }]);
  688. app.controller('messageSysCtrl', ["$scope","$ionicPopup","$location", "$ionicTabsDelegate","$state", "myService", "msg"
  689. , function ($scope,$ionicPopup,$location,$ionicTabsDelegate, $state, myService, msg) {
  690. $scope.$on('$ionicView.beforeEnter', function () {
  691. myService.systemInfo().then(function(result){
  692. $scope.sysInfos = result.data.data;
  693. },function(error){
  694. });
  695. });
  696. $scope.vm = {
  697. content:""
  698. };
  699. $scope.imgs = [];
  700. $scope.video = {};
  701. $scope.addpict = function () {
  702. alert('选择图片');
  703. common.chooseImage().then(function (img) {
  704. common.uploadFiles(img,1).then(function (result) {
  705. var response = JSON.parse(result.response);
  706. var file = config.imgServer + response.data.file;
  707. $scope.imgs.push(file);
  708. }, function (error) {
  709. msg.error('图片上传失败');
  710. });
  711. }, function (error) {
  712. console.log('图片选择失败');
  713. });
  714. };
  715. $scope.deletefile = function (file) {
  716. var index = $scope.imgs.indexOf(file);
  717. $scope.imgs.splice(index, 1);
  718. common.deletefile(file).then(function () {
  719. })
  720. };
  721. $scope.addvideo = function () {
  722. alert('选择视频');
  723. common.chooseVideo().then(function (file) {
  724. common.uploadFiles(file, 2).then(function (result) {
  725. var response = JSON.parse(result.response);
  726. var file = config.imgServer+response.data.file;
  727. $scope.video.isOK = true;
  728. $scope.video.file = response.data.file;
  729. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  730. }, function (error) {
  731. msg.error('视频上传失败');
  732. });
  733. }, function (erro) {
  734. console.log('选择视频失败');
  735. });
  736. };
  737. $scope.deletevideo = function (file) {
  738. common.deletefile(file).then(function (res) {
  739. },function(erro){
  740. alert(JSON.stringify(erro));
  741. })
  742. };
  743. $scope.goMes = function(is_reply,is_url,dream_id,is_end,message,user_id,info,attr_id){
  744. //发送私信
  745. if(is_reply==1){
  746. var myPopup = $ionicPopup.show({
  747. template : '<div>' +
  748. '<textarea autofocus style="border: 1px solid #D0D0D0" name="" id="" cols="30" rows="8" ng-model="vm.content" placeholder="对他的好意给予感谢的回复"></textarea onf>' +
  749. '<a class="btn-file-up" ng-click="addpict()">' +
  750. '<img src="img/icon_photo.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  751. '<em style="font-size: 16px">添加图片</em>' +
  752. '</a>' +
  753. '<a class="btn-file-up" ng-click="addvideo()">' +
  754. '<img src="img/icon_video.svg" style="height: 40px; width: 40px; text-align: center; line-height: 40px" /><br>' +
  755. '<em style="font-size: 16px">添加视频</em>' +
  756. '</a>' +
  757. '<a ng-repeat="item in imgs" ng-click="showImages(item)" class="img-file-up">' +
  758. '<b style="background-image:url({{item}});"><em ng-click="deletefile(item)" class="ion-ios-close-outline"></em></b>' +
  759. '</a>' +
  760. '<div class="img-file-up" ng-if="video.isOK">' +
  761. '<div style="position:relative;">' +
  762. '<em ng-click="deletevideo(video.file)" class="ion-ios-close-outline"></em>' +
  763. '<video ng-src="{{video.file | trustUrl}}" style="width: 100px; height: 100px" poster="{{video.vpic}}" controls="controls"></video>' +
  764. '</div>' +
  765. '</div>' +
  766. '</div>',
  767. title: message,
  768. //subTitle: 'Please use normal things',
  769. scope: $scope,
  770. buttons: [
  771. { text: '取消' },
  772. {
  773. text: '<b>确定</b>',
  774. type: 'button-positive',
  775. onTap: function(e) {
  776. var data = {
  777. to_user_id:user_id,
  778. content:$scope.vm.content,
  779. video:$scope.video.file,
  780. image:$scope.imgs,
  781. //image:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg']
  782. };
  783. myService.sendLetter(data).then(function(result){
  784. if(result.data.status_code==0){
  785. msg.success('发送成功');
  786. }
  787. })
  788. }
  789. }
  790. ]
  791. });
  792. }
  793. //跳转
  794. else if(is_url==1){
  795. if($location.path()=="/app/home/message/sys"){
  796. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  797. }
  798. else {
  799. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  800. }
  801. }
  802. //梦想结束
  803. else if(is_end==1&&attr_id==6){
  804. var endTemplate = '<div style="text-align: center"><p>恭喜你成功地你的梦想迈出最大的一步,</p>' +
  805. '<p>要取出全部梦想资金,</p>' +
  806. '<p>你需要亲自问候你的梦主</p>' +
  807. '<p>致出最诚挚的感谢</p>' +
  808. '<p>点击《确定》我们会提供</p>' +
  809. '<p>《梦主》的资料</p>' +
  810. '<p>如果你觉得不合适,你可以点击《取消》,但是《梦主》的资金会被退还给他</p>' +
  811. '<p>你以后创建梦想也会比较难</p>' +
  812. '</div>';
  813. msg.confirm('恭喜你!',endTemplate).then(function(result){
  814. if(result==true){
  815. myService.sure_meet(dream_id,1).then(function(res){
  816. if(res.data.status_code==0){
  817. if(res.data.data==0){
  818. msg.success('该梦想暂无梦主!');
  819. }
  820. else {
  821. msg.success('确定见面,期待相见吧!');
  822. }
  823. }
  824. })
  825. }
  826. else {
  827. myService.sure_meet(dream_id,0).then(function(res){
  828. if(res.data.status_code==0){
  829. msg.success('已取消见面!');
  830. }
  831. })
  832. }
  833. })
  834. }
  835. }
  836. }]);
  837. app.controller('messageReplyCtrl', ["$scope","$location","$ionicPopup","$ionicTabsDelegate", "$state", "myService", "msg", "$ionicModal"
  838. , function ($scope,$location,$ionicPopup,$ionicTabsDelegate, $state, myService, msg, $ionicModal) {
  839. $scope.$on('$ionicView.beforeEnter', function () {
  840. $scope.load();
  841. });
  842. $scope.load = function () {
  843. myService.replyMy().then(function (result) {
  844. $scope.comments = result.data.data;
  845. }, function (error) {
  846. });
  847. };
  848. $scope.goMes = function(info,img,is_max,mes,video,attr_id,dream_id,to_user_id,is_end,is_url){
  849. //收到私信
  850. if(attr_id==7){
  851. if(video!=null){
  852. var letterTemplate = '<div style="text-align: center">' +
  853. '<img src="'+img+'" style="border-radius: 100%">' +
  854. '<video src="'+video+'"></video>' +
  855. '<p>'+info+'</p>' +
  856. '</div>';
  857. }
  858. else {
  859. var letterTemplate = '<div style="text-align: center">' +
  860. '<img src="'+img+'" style="border-radius: 100%">' +
  861. '<p>'+info+'</p>' +
  862. '</div>';
  863. }
  864. msg.confirm('私信',letterTemplate,'梦想页').then(function(result){
  865. if(result==true){
  866. if($location.path()=="/app/home/message/reply"){
  867. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  868. }
  869. else {
  870. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  871. }
  872. }
  873. })
  874. }
  875. //成为梦主
  876. else if(is_max==1&&is_end==1){
  877. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  878. '<p>'+ info +'</p>' +
  879. '</div>';
  880. msg.confirm('恭喜你!',maxTemplate).then(function(result){
  881. if(result==true){
  882. myService.sure_meet2(to_user_id,1).then(function(res){
  883. if(res.data.status_code==0) {
  884. msg.success('确定见面,期待相见吧!');
  885. }
  886. })
  887. }
  888. else {
  889. myService.sure_meet2(to_user_id,0).then(function(res){
  890. if(res.data.status_code==0){
  891. msg.success('已取消见面!');
  892. }
  893. })
  894. }
  895. })
  896. }//确认见面/扫一扫
  897. else if(is_max==0&&is_url==0){
  898. var maxTemplate = '<div style="text-align: center"><p>'+ mes +'</p>' +
  899. '</div>';
  900. msg.alert('恭喜你!',maxTemplate).then(function(result){
  901. })
  902. }
  903. else if(is_end==0&&is_url==0){
  904. }
  905. else {
  906. if($location.path()=="/app/home/message/reply"){
  907. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  908. }
  909. else {
  910. $state.go('app.my_dreamdetail',{id:dream_id,type:2});
  911. }
  912. }
  913. };
  914. //我的回复
  915. $scope.vm = {
  916. content: ""
  917. };
  918. $ionicModal.fromTemplateUrl('my-modal.html', {
  919. scope: $scope,
  920. animation: 'slide-in-up'
  921. }).then(function (modal) {
  922. $scope.modal = modal;
  923. });
  924. //$ionicModal.fromTemplateUrl('my-modal.html', {
  925. // scope: $scope,
  926. // animation: 'slide-in-up'
  927. //}).then(function (modal) {
  928. // $scope.modal = modal;
  929. //});
  930. //$scope.openModal = function () {
  931. // $scope.modal.show();
  932. //};
  933. //$scope.closeModal = function () {
  934. // $scope.modal.hide();
  935. //
  936. //};
  937. $scope.goDetail = function (id,interaction_id){
  938. $state.go('app.home_dreamdetail',{id:id,interaction_id:interaction_id,type:2});
  939. };
  940. //我的回复
  941. //$scope.vm={
  942. // content:"",
  943. // comment_id:""
  944. //};
  945. //$scope.closeModal = function () {
  946. // var data = {
  947. // content: $scope.vm.content,
  948. // comment_id: $scope.item.id,
  949. // interaction_id: $scope.item.interaction_id
  950. // };
  951. // myService.myReplay(data).then(function (result) {
  952. // msg.success('回复成功');
  953. // $scope.load();
  954. // }, function (error) {
  955. // msg.error('回复失败');
  956. // });
  957. // $scope.vm.content = '';
  958. // $scope.item = null;
  959. // $scope.modal.hide();
  960. //};
  961. //
  962. //$scope.reply = function (item) {
  963. // $scope.item = item;
  964. // $scope.modal.show();
  965. //}
  966. }]);
  967. })(angular.module('app.controllers'));