123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- 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: '<a class="action-sheet-push">汽车制造</a>'},
- {text: '<a class="action-sheet-push">能源及节能技术</a>'},
- {text: '<a class="action-sheet-push">新材料</a>'},
- {text: '<a class="action-sheet-push">生物与新医药</a>'},
- {text: '<a class="action-sheet-push">电子信息</a>'},
- {text: '<a class="action-sheet-push">先进制造及高端装备</a>'},
- {text: '<a class="action-sheet-push">资源及环境技术</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.categoryid = index + 1;
- return true;
- }
- });
- };
- /*选择企业类型*/
- $scope.selectEnterpriseType = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">国有企业</a>'},
- {text: '<a class="action-sheet-push">集体所有制企业</a>'},
- {text: '<a class="action-sheet-push">私营企业</a>'},
- {text: '<a class="action-sheet-push">股份制企业</a>'},
- {text: '<a class="action-sheet-push">联营企业</a>'},
- {text: '<a class="action-sheet-push">外商投资企业</a>'},
- {text: '<a class="action-sheet-push">港澳台企业</a>'},
- {text: '<a class="action-sheet-push">股份制企业</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.enterprisetype = index + 1;
- return true;
- }
- });
- };
- /*选择企业规模*/
- $scope.selectEnterpriseScale = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">少于50人</a>'},
- {text: '<a class="action-sheet-push">50-150人</a>'},
- {text: '<a class="action-sheet-push">150-500人</a>'},
- {text: '<a class="action-sheet-push">500-1000人</a>'},
- {text: '<a class="action-sheet-push">1000-5000人</a>'},
- {text: '<a class="action-sheet-push">5000-10000人</a>'},
- {text: '<a class="action-sheet-push">10000人以上</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.enterprisescale = index + 1;
- return true;
- }
- });
- };
- /*选择知识产权*/
- $scope.selectRight = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">有</a>'},
- {text: '<a class="action-sheet-push">无</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.isipr = 1 - index;
- return true;
- }
- });
- };
- /*选择成熟度*/
- $scope.selectMaturity = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">正在研发</a>'},
- {text: '<a class="action-sheet-push">已有小样</a>'},
- {text: '<a class="action-sheet-push">通过小试</a>'},
- {text: '<a class="action-sheet-push">通过中试</a>'},
- {text: '<a class="action-sheet-push">可以量产</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.proficiency = index + 1;
- return true;
- }
- });
- };
- /*选择合作模式*/
- $scope.selectCperid = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">委托开发</a>'},
- {text: '<a class="action-sheet-push">合作研发</a>'},
- {text: '<a class="action-sheet-push">成果转让</a>'},
- {text: '<a class="action-sheet-push">技术入股</a>'},
- {text: '<a class="action-sheet-push">技术咨询</a>'},
- {text: '<a class="action-sheet-push">其他</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.cperid = index + 1;
- return true;
- }
- });
- };
- /*选择性别*/
- $scope.selectSex = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">男</a>'},
- {text: '<a class="action-sheet-push">女</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.sex = index + 1;
- return true;
- }
- });
- };
- /*选择学位*/
- $scope.selectAcademicDegree = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">学士</a>'},
- {text: '<a class="action-sheet-push">硕士</a>'},
- {text: '<a class="action-sheet-push">博士</a>'},
- {text: '<a class="action-sheet-push">博士后</a>'},
- {text: '<a class="action-sheet-push">其他</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.academicdegree = index + 1;
- return true;
- }
- });
- };
- /*选择职称*/
- $scope.selectPositionalTitles = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">正高</a>'},
- {text: '<a class="action-sheet-push">副高</a>'},
- {text: '<a class="action-sheet-push">中级</a>'},
- {text: '<a class="action-sheet-push">副级</a>'},
- {text: '<a class="action-sheet-push">无</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.resource.positionaltitles = index + 1;
- return true;
- }
- });
- };
- /*选取照片*/
- $scope.showPicture = 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) {
- 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<screenH){
- imgObj[n].style.width = tw + 'px';
- imgObj[n].style.height = th + 'px';
- imgObj[n].style.marginTop=(screenH-th)/2+ 'px';
- }else{
- imgObj[n].style.width = screenH*rate + 'px';
- imgObj[n].style.height = screenH + 'px';
- imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
- }
- }else if(oldWid>=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);
- };
- });
|