(function (app) { app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", '$ionicModal',"$ionicNavBarDelegate","$ionicHistory", "common", "config", "userService" , function ($scope, $state, dreamService, msg, $ionicTabsDelegate,$ionicModal, $ionicNavBarDelegate,$ionicHistory, common, config, userService) { $scope.addpict = function () { common.chooseImage().then(function (img) { msg.loading(); common.uploadFiles(img,1).then(function (result) { msg.hide(); var response = JSON.parse(result.response); var file = config.imgServer + response.data.file; $scope.imgs.push(file); }, function (error) { msg.hide(); msg.error('图片上传失败'); }); }, function (error) { console.log('图片选择失败'); }); }; $scope.addvideo = function () { common.chooseVideo().then(function (file) { msg.loading(); common.uploadFiles(file, 2).then(function (result) { msg.hide(); var response = JSON.parse(result.response); $scope.video.server = response.data.file; var file = config.imgServer+response.data.file; //console.log("file:"+file); $scope.video.isOK = true; $scope.video.file = file; $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg'; //console.log("vpic:"+$scope.video.vpic); }, function (error) { msg.hide(); msg.error(JSON.stringify(error)); }); }, function (erro) { console.log('选择视频失败'); }); }; $scope.deletefile = function (file) { var index = $scope.imgs.indexOf(file); $scope.imgs.splice(index, 1); common.deletefile(file).then(function () { }) }; $scope.deletevideo = function (file) { $scope.video = {}; common.deletefile(file).then(function () { }) }; $scope.add = function () { if(document.getElementById('read').checked){ var data = { // pics:['http://img0.imgtn.bdimg.com/it/u=2398075737,160631337&fm=214&gp=0.jpg'], pics: $scope.imgs, video: $scope.video.server, name: $scope.vm.name, about: $scope.vm.about, days: 21, //默认21 coin: $scope.vm.coin }; //msg.loading('保存中...'); msg.loading(); dreamService.addDream(data).then(function (result) { msg.hide(); msg.text("梦想发布成功"); $state.go('app.home'); }, function (error) { msg.hide(); msg.error(error.data.message); }); } else{ msg.error('请同意用户隐私条款'); } }; $scope.$on('$ionicView.beforeEnter', function () { $scope.imgs=[]; $scope.video = {}; $scope.vm={ name:'', about:'', coin:'' }; $ionicTabsDelegate.showBar(false); }); // 隐私条款 $ionicModal.fromTemplateUrl('readClause.html', { scope: $scope, animation: 'slide-in-up' }).then(function(modal) { $scope.readClauseModal = modal; }); $scope.readClause = function($event){ debugger; userService.info(type=1).then(function(res){ debugger; $scope.info = res.data.data; }) $event.stopPropagation(); $scope.readClauseModal.show(); } $scope.closeClause = function() { $scope.readClauseModal.hide(); }; }]); app.controller('addExplainCtrl', ["$scope","$ionicTabsDelegate", "$state", "dreamService", "msg","storage" , function ($scope,$ionicTabsDelegate, $state,dreamService, msg, storage) { }]); })(angular.module('app.controllers'));