add.js 3.1 KB

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