123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- angular.module('push')
- .controller('releaseCommentCtrl', function ($scope, CommentService, $stateParams, UtilService, $timeout, $ionicActionSheet, $ionicPopup,$ionicSlideBoxDelegate) {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- var infoid = $stateParams.infoid;
- var infotype = $stateParams.infotype;
- $scope.infotype = infotype;
- var recourcecomefrom = $stateParams.recourcecomefrom;
- var comlen = $stateParams.comlen;
- $scope.maxlength = 8;
- $scope.progressLabels = [];
- $scope.imagelist = [];
- var tagid = 0;
- $scope.comment = {content: ""};
- $scope.choseindex = -1;
- $scope.blue = "";
- //评分
- $scope.starnum = 0;
- $scope.evaluateNum = function (num) {
- $scope.starnum = num;
- };
- //获取标签列表
- var getLabelList = function () {
- CommentService.getLabelList().then(function (response) {
- // console.log(response);
- $scope.progressLabels = response;
- }, function () {
- })
- };
- getLabelList();
- //展示所有标签
- $scope.showAllLabel = function () {
- $scope.maxlength = $scope.progressLabels.length;
- };
- $scope.checklength = function () {
- if ($scope.comment.content.length > 0) {
- $scope.blue = "toolReleaseButton_blue";
- } else {
- $scope.blue = "";
- }
- };
- //上传图片
- var tempimages = [];
- var uploadImages = function () {
- UtilService.uploadFile($scope.imagelist, 0, "image/jpeg").then(function (response) {
- // console.log(response);
- angular.forEach(response, function (value, index) {
- if (value.status) {
- tempimages.push({
- photo_name: value.userPhoto,
- original_name: value.originalPhoto,
- source_name: value.sourcePhoto,
- source_size:value.source_size
- });
- }
- });
- $timeout(function () {
- appDetailComment();
- }, 100)
- }, function () {
- relflg = 0;
- $scope.hideLoadingToast();
- UtilService.showMess("网络不给力,请重试");
- })
- };
- //发表评论
- var appDetailComment = function () {
- CommentService.appDetailComment(infoid, infotype, tagid, tempimages, $scope.comment.content, recourcecomefrom, $scope.starnum).then(function (response) {
- // console.log(response);
- UtilService.showMess("发布成功");
- $scope.starnum = 0;
- $timeout(function () {
- if (comlen < 3) {
- $scope.goback();
- } else {
- $scope.go('toolDiscuss', {infoid: infoid, infotype: infotype, comlen: comlen})
- }
- relflg = 0;
- }, 1500);
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- relflg = 0;
- UtilService.showMess("网络不给力,请重试");
- })
- };
- //点击发表
- var relflg = 0;
- $scope.releaseComment = function () {
- if ($scope.comment.content.length < 1) {
- return;
- }
- if (relflg != 0) {
- return;
- }
- relflg = 1;
- $scope.showLoadingToast();
- if ($scope.imagelist.length > 0) {
- uploadImages();
- } else {
- appDetailComment();
- }
- };
- //打开相机
- var openCamera = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- return;
- }
- UtilService.getPicture(1).then(function (results) {
- $scope.imagelist.push(results);
- $scope.totalImglength = 600 * $scope.imagelist.length;
- }, function (err) {
- });
- };
- //检测相册权限
- var verifyStorage = function () {
- window.imagePicker.verifyStorage(
- function (results) {
- if (results == "1") {
- getPic();
- }
- }, function (error) {
- }
- );
- };
- //打开相册
- var getPic = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- return;
- }
- UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
- // console.log(results);
- angular.forEach(results, function (value, index) {
- $scope.imagelist.push(value)
- });
- $scope.totalImglength = 600 * $scope.imagelist.length;
- }, function (err) {
- });
- };
- var getPictures = function () {
- if (device.platform == "Android") {
- verifyStorage();
- } else {
- getPic();
- }
- };
- //选择标签
- $scope.checkLable = function (id, index) {
- tagid = id;
- $scope.choseindex = index;
- };
- //添加照片
- $scope.toolPhotoAdd = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">拍照</a>'},
- {text: '<a class="action-sheet-push">从相册中选择</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- openCamera();
- } else {
- getPictures();
- }
- return true;
- }
- });
- };
- //删除图片
- $scope.deletePhoto = function (index) {
- $scope.imagelist.splice(index, 1);
- };
- //点击图片放大
- $scope.bigImage = false; //初始默认大图是隐藏的
- $scope.hideBigImage = function () {
- $timeout(function () {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $scope.bigImage = false;
- }, 400);
- };
- $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $(function () {
- $('div.pinch-zoom').each(function () {
- new RTP.PinchZoom($(this), {});
- });
- });
- $scope.bigImage = true; //显示大图
- // console.log(index);
- $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
- //图片总数量
- setTimeout(function () {
- // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
- // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
- $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -5);
- // var nowIndex=parseInt($ionicSlideBoxDelegate.currentIndex());
- var totalIndex=parseInt($ionicSlideBoxDelegate.slidesCount());
- // console.log(index);
- $scope.nowIndex=index+1;
- $scope.totalIndex=totalIndex;
- //获取图片
- var imgObj = document.getElementsByClassName('bigimage');
- var n;
- for (n = 0; n < imgObj.length; n++) {
- // 获取图片的原始高度和宽度
- var oldWid = imgObj[n].naturalWidth;
- var oldHei = imgObj[n].naturalHeight;
- var screen = document.body.offsetWidth;
- var screenH = window.innerHeight;
- // console.log(oldWid/oldHei);
- // console.log(screen );
- var cc = screen / (oldWid / oldHei);
- imgObj[n].style.height = cc + 'px';
- if (cc < screenH) {
- imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
- // console.log("e:" + imgObj[n].style.marginTop);
- } else {
- imgObj[n].style.marginTop = 0 + 'px';
- // console.log((cc - screenH) + 'px')
- }
- }
- }, 0);
- };
- $scope.slideHasChanged=function(index){
- // console.log(index);
- $scope.nowIndex=index+1;
- };
- });
|