add.js 3.2 KB

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