add.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. (function (app) {
  2. app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate","$ionicHistory", "common", "config"
  3. , function ($scope, $state, dreamService, msg, $ionicTabsDelegate, $ionicNavBarDelegate,$ionicHistory, common, config) {
  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. var data = {
  54. //pics:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'],
  55. pics: $scope.imgs,
  56. video: $scope.video.server,
  57. name: $scope.vm.name,
  58. about: $scope.vm.about,
  59. days: 21, //默认21
  60. coin: $scope.vm.coin
  61. };
  62. //msg.loading('保存中...');
  63. msg.loading();
  64. dreamService.addDream(data).then(function (result) {
  65. msg.hide();
  66. msg.text("梦想发布成功");
  67. $state.go('app.home');
  68. }, function (error) {
  69. msg.hide();
  70. msg.error(error.data.message);
  71. });
  72. };
  73. $scope.$on('$ionicView.beforeEnter', function () {
  74. $scope.imgs=[];
  75. $scope.video = {};
  76. $scope.vm={
  77. name:'',
  78. about:'',
  79. coin:''
  80. };
  81. $ionicTabsDelegate.showBar(false);
  82. });
  83. }]);
  84. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  85. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  86. }]);
  87. })(angular.module('app.controllers'));