add.js 3.0 KB

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