angular.module('push')
.controller('editResourcePrivateDetailsCtrl', function ($scope, $stateParams, $ionicActionSheet, ModelService, UtilService, ResourceLibraryService, $timeout, $ionicScrollDelegate,$ionicSlideBoxDelegate) {
if($scope.app){
$scope.setStatusBar(0);
}
$scope.type = $stateParams.type;
var tempdate = angular.fromJson($stateParams.resource);
var recourceid = tempdate.unique;
var recourcecomefrom = tempdate.source;
$scope.resource = {
title: tempdate.title,//名称或姓名
type: tempdate.type,//1:需求,2:成果,6:企业,8:人才
categoryid: tempdate.categoryid,//行或领域
cperid: tempdate.cperid == undefined ? 0 : tempdate.cperid,//合作模式
content: tempdate.content == undefined ? "" : tempdate.content,
tel: tempdate.tel == undefined ? "" : tempdate.tel,//电话
orgName: tempdate.orgName == undefined ? "" : tempdate.orgName,//单位
//企业
enterprisetype: tempdate.enterprisetype == undefined ? 0 : tempdate.enterprisetype,//企业类型
enterprisescale: tempdate.enterprisescale == undefined ? 0 : tempdate.enterprisescale,//企业规模
address: tempdate.address == undefined ? "" : tempdate.address,//地址
contactor: tempdate.contactor == undefined ? "" : tempdate.contactor,//联系人
//人才
sex: tempdate.sex == undefined ? 0 : tempdate.sex,//性别
birthday: tempdate.birthday == undefined ? "" : tempdate.birthday,//出生年月
academicdegree: tempdate.academicdegree == undefined ? 0 : tempdate.academicdegree,//学位
positionaltitles: tempdate.positionaltitles == undefined ? 0 : tempdate.positionaltitles,//职称
email: tempdate.email == undefined ? "" : tempdate.email,//邮箱
//需求
capitalScale: tempdate.capitalScale == -1 ? "面议" : tempdate.capitalScale,//投入预算
//成果
isipr: tempdate.isipr == undefined ? 0 : tempdate.isipr,//知识产权
proficiency: tempdate.proficiency == undefined ? 0 : tempdate.proficiency//成熟度
};
$scope.imagelist = tempdate.picturelist == undefined ? [] : tempdate.picturelist;
// console.log($scope.resource);
// console.log($scope.imagelist);
/*选择行业*/
$scope.selectCategory = function () {
$ionicActionSheet.show({
buttons: [
{text: '汽车制造'},
{text: '能源及节能技术'},
{text: '新材料'},
{text: '生物与新医药'},
{text: '电子信息'},
{text: '先进制造及高端装备'},
{text: '资源及环境技术'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.categoryid = index + 1;
return true;
}
});
};
/*选择企业类型*/
$scope.selectEnterpriseType = function () {
$ionicActionSheet.show({
buttons: [
{text: '国有企业'},
{text: '集体所有制企业'},
{text: '私营企业'},
{text: '股份制企业'},
{text: '联营企业'},
{text: '外商投资企业'},
{text: '港澳台企业'},
{text: '股份制企业'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.enterprisetype = index + 1;
return true;
}
});
};
/*选择企业规模*/
$scope.selectEnterpriseScale = function () {
$ionicActionSheet.show({
buttons: [
{text: '少于50人'},
{text: '50-150人'},
{text: '150-500人'},
{text: '500-1000人'},
{text: '1000-5000人'},
{text: '5000-10000人'},
{text: '10000人以上'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.enterprisescale = index + 1;
return true;
}
});
};
/*选择知识产权*/
$scope.selectRight = function () {
$ionicActionSheet.show({
buttons: [
{text: '有'},
{text: '无'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.isipr = 1 - index;
return true;
}
});
};
/*选择成熟度*/
$scope.selectMaturity = function () {
$ionicActionSheet.show({
buttons: [
{text: '正在研发'},
{text: '已有小样'},
{text: '通过小试'},
{text: '通过中试'},
{text: '可以量产'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.proficiency = index + 1;
return true;
}
});
};
/*选择合作模式*/
$scope.selectCperid = function () {
$ionicActionSheet.show({
buttons: [
{text: '委托开发'},
{text: '合作研发'},
{text: '成果转让'},
{text: '技术入股'},
{text: '技术咨询'},
{text: '其他'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.cperid = index + 1;
return true;
}
});
};
/*选择性别*/
$scope.selectSex = function () {
$ionicActionSheet.show({
buttons: [
{text: '男'},
{text: '女'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.sex = index + 1;
return true;
}
});
};
/*选择学位*/
$scope.selectAcademicDegree = function () {
$ionicActionSheet.show({
buttons: [
{text: '学士'},
{text: '硕士'},
{text: '博士'},
{text: '博士后'},
{text: '其他'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.academicdegree = index + 1;
return true;
}
});
};
/*选择职称*/
$scope.selectPositionalTitles = function () {
$ionicActionSheet.show({
buttons: [
{text: '正高'},
{text: '副高'},
{text: '中级'},
{text: '副级'},
{text: '无'}
],
cancelText: '取消',
buttonClicked: function (index) {
$scope.resource.positionaltitles = index + 1;
return true;
}
});
};
/*选取照片*/
$scope.showPicture = function () {
$ionicActionSheet.show({
buttons: [
{text: '拍照'},
{text: '从相册中添加'}
],
cancelText: '取消',
buttonClicked: function (index) {
if (index == 0) {
if ($scope.imagelist.length >= 18) {
UtilService.showMess("最多选取18张图片");
return;
}
UtilService.getPicture(1).then(function (results) {
$scope.imagelist.push({photo_name: results, original_name: results, source_name: results});
$scope.totalImglength = 600 * $scope.imagelist.length;
$ionicScrollDelegate.$getByHandle("scrollimage").resize();
}, function (err) {
});
} else if (index == 1) {
getPictures();
}
return true;
}
});
};
var verifyStorage = function () {
window.imagePicker.verifyStorage(
function (results) {
if (results == "1") {
getPic();
}
}, function (error) {
}
);
};
var getPic = function () {
if ($scope.imagelist.length >= 18) {
UtilService.showMess("最多选取18张图片");
return;
}
UtilService.getPictureList(18 - $scope.imagelist.length).then(function (results) {
angular.forEach(results, function (value, index) {
$scope.imagelist.push({photo_name: value, original_name: value, source_name: value})
});
$scope.totalImglength = 600 * $scope.imagelist.length;
$ionicScrollDelegate.$getByHandle("scrollimage").resize();
}, function (err) {
});
};
var getPictures = function () {
if (device.platform == "Android") {
verifyStorage();
} else {
getPic();
}
};
var delpiclist = [];
$scope.deletePhoto = function (index) {
if (UtilService.isDefined($scope.imagelist[index].id)) {
delpiclist.push($scope.imagelist[index].id);
}
$scope.imagelist.splice(index, 1);
};
var addpiclist = [];
var uploadImages = function () {
var upimages = [];
angular.forEach($scope.imagelist, function (data) {
if (data.photo_name.indexOf("file:") != -1) {
upimages.push(data.photo_name);
}
});
if (upimages.length > 0) {
UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
// console.log(response);
angular.forEach(response, function (value, index) {
if (value.status) {
addpiclist.push({
id: 0,
photo_name: value.userPhoto,
original_name: value.originalPhoto,
source_name: value.sourcePhoto,
source_size:value.source_size,
title: "",
moduleid: $scope.type,
infoid: recourceid,
infocomefrom: recourcecomefrom
});
}
});
$timeout(function () {
editResource(addpiclist);
}, 100);
}, function () {
editResource([]);
})
} else {
editResource([]);
}
};
// 编辑资源
var editResource = function (addpiclist) {
ResourceLibraryService.editResource($scope.type, recourceid, recourcecomefrom, delpiclist, addpiclist, $scope.resource).then(function (response) {
// console.log(response);
UtilService.showMess("编辑成功");
$timeout(function () {
$scope.goback();
}, 1000);
}, function () {
UtilService.showMess("网络不给力,请重试");
})
};
$scope.saveResource = function () {
if (!UtilService.isDefined($scope.resource.title)) {
if ($scope.type == '8') {
UtilService.showMess("姓名不能为空");
} else {
UtilService.showMess("名称不能为空");
}
return;
}
if (UtilService.isDefined($scope.imagelist) && $scope.imagelist.length > 0) {
uploadImages();
} else {
editResource([])
}
};
//点击图片放大
$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(1);
}
$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, -10);
//获取图片
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 rate=oldWid/oldHei;
if(oldWid>=screen&&oldHei>=screenH){
var tw=screen;
var th=tw/rate;
if(th=screen&&oldHei<=screenH){
imgObj[n].style.width = screen + 'px';
imgObj[n].style.height = screen/rate + 'px';
imgObj[n].style.marginTop=(screenH-screen/rate)/2+ 'px';
}else if(oldWid<=screen&&oldHei>=screenH){
// var hh=screenH;
// var ww=screenH*rate;
imgObj[n].style.width = screenH*rate + 'px';
imgObj[n].style.height = screenH + 'px';
imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
}else{
imgObj[n].style.width = oldWid + 'px';
imgObj[n].style.height = oldHei + 'px';
imgObj[n].style.marginLeft=(screen-oldWid)/2+ 'px';
imgObj[n].style.marginTop=(screenH-oldHei)/2+ 'px';
}
}
}, 0);
};
//查看原图
$scope.viewOldImg = function (index) {
// console.log($scope.imagelist[index]);
// console.log("查看原图"+index);
var url = UtilService.isDefined($scope.imagelist[index].source_name) ? $scope.imagelist[index].source_name : $scope.imagelist[index].photo_name;
$(".bigimage").eq(index).attr("src", $scope.imgUrl + url);
$timeout(function () {
$scope.imagelist[index].loadsource = true;
},20);
};
});