add.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. $state.go('app.home');
  56. }, function (error) {
  57. msg.hide();
  58. msg.error(error.data.message);
  59. });
  60. };
  61. $scope.$on('$ionicView.beforeEnter', function () {
  62. $scope.imgs=[];
  63. $scope.video = {};
  64. $scope.vm={
  65. name:'',
  66. about:'',
  67. coin:''
  68. };
  69. $ionicTabsDelegate.showBar(false);
  70. });
  71. }]);
  72. app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage"
  73. , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) {
  74. }]);
  75. })(angular.module('app.controllers'));