add.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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('视频上传失败');
  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.add = function () {
  48. //if($scope.video.server){
  49. // $scope.imgs=[];
  50. //}
  51. var data = {
  52. //pics: ["https://www.baidu.com/img/bd_logo1.png"],
  53. pics: $scope.imgs,
  54. video: $scope.video.server,
  55. name: $scope.vm.name,
  56. about: $scope.vm.about,
  57. days: 21, //默认21
  58. coin: $scope.vm.coin
  59. };
  60. //msg.loading('保存中...');
  61. msg.loading();
  62. dreamService.addDream(data).then(function (result) {
  63. msg.hide();
  64. msg.text("梦想发布成功");
  65. $state.go('app.home');
  66. }, function (error) {
  67. msg.hide();
  68. msg.error(error.data.message);
  69. });
  70. };
  71. $scope.$on('$ionicView.beforeEnter', function () {
  72. $scope.imgs=[];
  73. $scope.video = {};
  74. $scope.vm={
  75. name:'',
  76. about:'',
  77. coin:''
  78. };
  79. $ionicTabsDelegate.showBar(false);
  80. });
  81. }]);
  82. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  83. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  84. }]);
  85. })(angular.module('app.controllers'));