add.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. (function (app) {
  2. app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", '$ionicModal',"$ionicNavBarDelegate","$ionicHistory", "common", "config", "userService"
  3. , function ($scope, $state, dreamService, msg, $ionicTabsDelegate,$ionicModal, $ionicNavBarDelegate,$ionicHistory, common, config, userService) {
  4. $scope.addpict = function () {
  5. common.chooseImage().then(function (img) {
  6. msg.loading();
  7. common.uploadFiles(img,1).then(function (result) {
  8. msg.hide();
  9. var response = JSON.parse(result.response);
  10. var file = config.imgServer + response.data.file;
  11. $scope.imgs.push(file);
  12. }, function (error) {
  13. msg.hide();
  14. msg.error('图片上传失败');
  15. });
  16. }, function (error) {
  17. console.log('图片选择失败');
  18. });
  19. };
  20. $scope.addvideo = function () {
  21. common.chooseVideo().then(function (file) {
  22. msg.loading();
  23. common.uploadFiles(file, 2).then(function (result) {
  24. msg.hide();
  25. var response = JSON.parse(result.response);
  26. $scope.video.server = response.data.file;
  27. var file = config.imgServer+response.data.file;
  28. //console.log("file:"+file);
  29. $scope.video.isOK = true;
  30. $scope.video.file = file;
  31. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  32. //console.log("vpic:"+$scope.video.vpic);
  33. }, function (error) {
  34. msg.hide();
  35. msg.error(JSON.stringify(error));
  36. });
  37. }, function (erro) {
  38. console.log('选择视频失败');
  39. });
  40. };
  41. $scope.deletefile = function (file) {
  42. var index = $scope.imgs.indexOf(file);
  43. $scope.imgs.splice(index, 1);
  44. common.deletefile(file).then(function () {
  45. })
  46. };
  47. $scope.deletevideo = function (file) {
  48. $scope.video = {};
  49. common.deletefile(file).then(function () {
  50. })
  51. };
  52. $scope.add = function () {
  53. if(document.getElementById('read').checked){
  54. var data = {
  55. // pics:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'],
  56. pics: $scope.imgs,
  57. video: $scope.video.server,
  58. name: $scope.vm.name,
  59. about: $scope.vm.about,
  60. days: 21, //默认21
  61. coin: $scope.vm.coin
  62. };
  63. //msg.loading('保存中...');
  64. msg.loading();
  65. dreamService.addDream(data).then(function (result) {
  66. msg.hide();
  67. msg.text("梦想发布成功");
  68. $state.go('app.home');
  69. }, function (error) {
  70. msg.hide();
  71. msg.error(error.data.message);
  72. });
  73. }
  74. else{
  75. msg.error('请同意用户隐私条款');
  76. }
  77. };
  78. $scope.$on('$ionicView.beforeEnter', function () {
  79. $scope.imgs=[];
  80. $scope.video = {};
  81. $scope.vm={
  82. name:'',
  83. about:'',
  84. coin:''
  85. };
  86. $ionicTabsDelegate.showBar(false);
  87. });
  88. // 隐私条款
  89. $ionicModal.fromTemplateUrl('readClause.html', {
  90. scope: $scope,
  91. animation: 'slide-in-up'
  92. }).then(function(modal) {
  93. $scope.readClauseModal = modal;
  94. });
  95. $scope.readClause = function($event){
  96. debugger;
  97. userService.info(type=1).then(function(res){
  98. debugger;
  99. $scope.info = res.data.data;
  100. })
  101. $event.stopPropagation();
  102. $scope.readClauseModal.show();
  103. }
  104. $scope.closeClause = function() {
  105. $scope.readClauseModal.hide();
  106. };
  107. }]);
  108. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  109. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  110. }]);
  111. })(angular.module('app.controllers'));