add.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 = config.imgServer + response.data.file;
  9. $scope.imgs.push(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 = config.imgServer+response.data.file;
  23. console.log("file:"+file);
  24. $scope.video.isOK = true;
  25. $scope.video.server = 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=['http://miao.beiyuesi.com/attachment/85aff9f4c92890104b34c2a878312009'];
  59. $scope.video = {};
  60. $scope.vm={
  61. name:'',
  62. about:'',
  63. coin:''
  64. };
  65. $ionicTabsDelegate.showBar(false);
  66. });
  67. }]);
  68. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  69. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  70. }]);
  71. })(angular.module('app.controllers'));