add.js 3.6 KB

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