add.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. common.uploadFiles(file, 2).then(function (result) {
  20. var response = JSON.parse(result.response);
  21. $scope.video.server = response.data.file;
  22. var file = config.imgServer+response.data.file;
  23. console.log("file:"+file);
  24. $scope.video.isOK = true;
  25. $scope.video.file = file;
  26. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  27. console.log("vpic:"+$scope.video.vpic);
  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: ["https://www.ba/idu.com/img/bd_logo1.png"],
  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. msg.loading();
  53. dreamService.addDream(data).then(function (result) {
  54. msg.hide();
  55. msg.text("梦想发布成功");
  56. $state.go('app.home');
  57. }, function (error) {
  58. msg.hide();
  59. msg.error(error.data.message);
  60. });
  61. };
  62. $scope.$on('$ionicView.beforeEnter', function () {
  63. $scope.imgs=[];
  64. $scope.video = {};
  65. $scope.vm={
  66. name:'',
  67. about:'',
  68. coin:''
  69. };
  70. $ionicTabsDelegate.showBar(false);
  71. });
  72. }]);
  73. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  74. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  75. }]);
  76. })(angular.module('app.controllers'));