add.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. (function (app) {
  2. app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate","$ionicHistory", "common", "config"
  3. , function ($scope, $state, dreamService, msg, $ionicTabsDelegate, $ionicNavBarDelegate,$ionicHistory, common, config) {
  4. $scope.addpict = function () {
  5. $scope.imgs=new Array();
  6. common.chooseImage().then(function (img) {
  7. common.uploadFiles(img,1).then(function (result) {
  8. var response = JSON.parse(result.response);
  9. var file = response.data.file;
  10. $scope.imgs.push(file);
  11. }, function (error) {
  12. msg.error('图片上传失败');
  13. });
  14. }, function (error) {
  15. console.log('图片选择失败');
  16. });
  17. };
  18. $scope.video = {};
  19. $scope.addvideo = function () {
  20. common.chooseVideo().then(function (file) {
  21. $scope.video.path = file;
  22. $scope.video.isOK = true;
  23. common.uploadFiles(file, 2).then(function (result) {
  24. var response = JSON.parse(result.response);
  25. var file = response.data.file;
  26. $scope.video.server = file;
  27. }, function (error) {
  28. msg.error('视频上传失败');
  29. });
  30. }, function (erro) {
  31. console.log('选择视频失败');
  32. });
  33. };
  34. $scope.deletefile = function (file) {
  35. var index = $scope.imgs.indexOf(file);
  36. $scope.imgs.splice(index, 1);
  37. common.deletefile(file).then(function () {
  38. })
  39. };
  40. $scope.add = function () {
  41. var data = {
  42. pics: $scope.imgs,
  43. video:$scope.video.server,
  44. dream: $scope.vm.dream,
  45. about: $scope.vm.about,
  46. time: 21, //默认21
  47. money: $scope.vm.money
  48. };
  49. msg.loading('保存中...');
  50. dreamService.addDream(data).then(function (result) {
  51. msg.hide();
  52. $state.go('app.home');
  53. }, function (error) {
  54. msg.hide();
  55. msg.error(error.data.message);
  56. });
  57. };
  58. $scope.$on('$ionicView.leave', function () {
  59. $ionicTabsDelegate.showBar(true);
  60. });
  61. }]);
  62. })(angular.module('app.controllers'));