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: '拍照'},
{text: '从相册中选择'}
],
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;
};
});