add.js 3.0 KB

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