add.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. (function (app) {
  2. app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate", "$ionicModal", "$ionicHistory", "common", "config"
  3. , function ($scope, $state, dreamService, msg, $ionicTabsDelegate, $ionicNavBarDelegate, $ionicModal, $ionicHistory, common, config) {
  4. $ionicModal.fromTemplateUrl('my-modal.html', {
  5. scope: $scope,
  6. animation: 'slide-in-up'
  7. }).then(function (modal) {
  8. $scope.modal = modal;
  9. });
  10. $scope.openModal = function () {
  11. $scope.modal.show();
  12. };
  13. $scope.closeModal = function () {
  14. $scope.modal.hide();
  15. };
  16. $scope.$on('$ionicView.beforeEnter', function () {
  17. $scope.vm={
  18. dream:'',
  19. about:'',
  20. money:''
  21. };
  22. $scope.imgServer = config.imgServer;
  23. $scope.imgs = [];
  24. $scope.video = {
  25. isOK: false,
  26. path: '',
  27. server:''
  28. };
  29. });
  30. $scope.addpict = function () {
  31. common.chooseImage().then(function (img) {
  32. common.uploadFiles(img,1).then(function (result) {
  33. var response = JSON.parse(result.response);
  34. var file = response.data.file;
  35. $scope.imgs.push(file);
  36. }, function (error) {
  37. msg.error('图片上传失败');
  38. });
  39. }, function (error) {
  40. console.log('图片选择失败');
  41. });
  42. };
  43. $scope.addvideo = function () {
  44. common.chooseVideo().then(function (file) {
  45. $scope.video.path = file;
  46. $scope.video.isOK = true;
  47. common.uploadFiles(file, 2).then(function (result) {
  48. var response = JSON.parse(result.response);
  49. var file = response.data.file;
  50. $scope.video.server = file;
  51. }, function (error) {
  52. msg.error('视频上传失败');
  53. });
  54. }, function (erro) {
  55. msg.error('选择视频失败');
  56. });
  57. };
  58. $scope.deletefile = function (file) {
  59. var index = $scope.imgs.indexOf(file);
  60. $scope.imgs.splice(index, 1);
  61. common.deletefile(file).then(function () {
  62. })
  63. };
  64. $scope.add = function () {
  65. var data = {
  66. pics: $scope.imgs,
  67. video:$scope.video.server,
  68. dream: $scope.vm.dream,
  69. about: $scope.vm.about,
  70. time: 21, //默认21
  71. money: $scope.vm.money
  72. };
  73. msg.loading('保存中...');
  74. dreamService.addDream(data).then(function (result) {
  75. msg.hide();
  76. $state.go('app.home');
  77. }, function (error) {
  78. msg.hide();
  79. msg.error(error.data.message);
  80. });
  81. };
  82. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  83. $ionicTabsDelegate.showBar(false);
  84. $ionicNavBarDelegate.showBackButton(true);
  85. });
  86. $scope.$on('$ionicView.leave', function () {
  87. $ionicTabsDelegate.showBar(true);
  88. });
  89. }]);
  90. })(angular.module('app.controllers'));