add.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. msg.error('图片选择失败');
  39. });
  40. }
  41. $scope.addvideo = function () {
  42. var options = { limit: 1, duration:20};
  43. navigator.device.capture.captureVideo(function (videos) {
  44. $scope.video.path = videos[0].fullPath;
  45. $scope.video.isOK = true;
  46. common.uploadFiles(videos[0].fullPath, 2).then(function (result) {
  47. var response = JSON.parse(result.response);
  48. var file = response.data.file;
  49. $scope.video.server = file;
  50. }, function (error) {
  51. msg.error('视频上传失败');
  52. });
  53. }, function (error) {
  54. msg.error('视频上传失败');
  55. }, options);
  56. }
  57. $scope.deletefile = function (file) {
  58. var index = $scope.imgs.indexOf(file);
  59. $scope.imgs.splice(index, 1);
  60. common.deletefile(file).then(function () {
  61. })
  62. }
  63. $scope.add = function () {
  64. var data = {
  65. pics: $scope.imgs,
  66. video:$scope.video.server,
  67. dream: $scope.vm.dream,
  68. about: $scope.vm.about,
  69. time: 21, //默认21
  70. money: $scope.vm.money
  71. };
  72. msg.loading('保存中...');
  73. dreamService.addDream(data).then(function (result) {
  74. msg.hide();
  75. $state.go('app.home');
  76. }, function (error) {
  77. msg.hide();
  78. msg.error(error.data.message);
  79. });
  80. }
  81. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  82. $ionicTabsDelegate.showBar(false);
  83. $ionicNavBarDelegate.showBackButton(true);
  84. });
  85. $scope.$on('$ionicView.leave', function () {
  86. $ionicTabsDelegate.showBar(true);
  87. });
  88. }]);
  89. })(angular.module('app.controllers'));