add.js 3.1 KB

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