my.js 44 KB

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