angular.module('push') .controller('unitOrPersonalBaseInfoCtrl', function ($scope,$stateParams,$timeout,$ionicActionSheet,$ionicScrollDelegate, UtilService,dataToolsService,ConstantService,UserService) { //默认选择类型为企业 $scope.selectBaseInfoStyle='企业'; $scope.isTapChange=true; // 获取走访录入界面的传参 $scope.rolePageModel= { //TODO id: $stateParams.pageid,// 模版id orgtype: ConstantService.UNITTYPE_10104// 走访对应的机构类型 // id: 2,// 模版id // orgtype: 2,// 模版id }; // 对应的是0新增/1编辑 $scope.isedit = $stateParams.isedit; if($scope.isedit == 0){ $scope.pagetitle = "录入信息"; }else if($scope.isedit == 1){ $scope.pagetitle = "编辑信息"; $timeout(function () { $("#orgname").prop("disabled", true); },300); if($stateParams.pageid == 9){ $scope.selectBaseInfoStyle='高校'; $scope.isTapChange=true; $scope.rolePageModel.id = $stateParams.pageid;// 模版id $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10105; } }else // 复制并新建 if($scope.isedit == 2){ $scope.pagetitle = "复制并新建信息"; $timeout(function () { $("#orgname").prop("disabled", true); },300); if($stateParams.pageid == 9){ $scope.selectBaseInfoStyle='高校'; $scope.isTapChange=true; $scope.rolePageModel.id = $stateParams.pageid;// 模版id $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10105; } } $scope.changeInfoStyle=function () { $scope.isTapChange=! $scope.isTapChange; // 选取身份证弹框 $ionicActionSheet.show({ buttons: [ {text: '企业'}, {text: '高校'} ], cancelText: '取消', buttonClicked: function (index) { switch (index){ case 0: $scope.selectBaseInfoStyle='企业'; $scope.isTapChange=true; $scope.rolePageModel.id = $stateParams.pageid;// 模版id console.log($stateParams.pageid); $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10104; break; case 1: $scope.selectBaseInfoStyle='高校'; $scope.isTapChange=true; $scope.rolePageModel.id = 9;// 模版id $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10105; break; default: return; } return true; } }); }; //企业基本信息 $scope.connEnterpriseModuleModel = { id: 0, userid: 0, usercomefrom: "", claid: 0,// 选中的文件夹id taskid: 0,// 任务id yearsetupid: 0, yearsetupname: "", templettype: $stateParams.pageid,// 模板id orgname: "", orglogo: "",// 企业logo orgtype: ConstantService.UNITTYPE_10104,//机构类型:默认企业 orgcontent: "",// 企业简介 orgcontact: "", orgcontactnum: "", categoryid: "", categoryname: "", orggradecode: 0,// 企业研发机构等级 rdinstitutiontypename: "",// 企业研发机构等级名称 ishigh: 0,// 是否高企 high:true, ishighInfo:"是", remark: "",// 备注 images: "",// 传到后台的图片json delimages: "",// 删除的图片 imagelist: [],// app端图片插件进行传递的变量 userModel: { userid: 0 // 用户id }, organizationInfo: { id: 0, orgtype: ConstantService.UNITTYPE_10104,//机构类型 name: "", about: "",// 机构简介 contact: "", contactnum: "", categoryid: "", categoryname: "", rdinstitutiontype: 0,// 企业研发机构等级 rdinstitutiontypename: "",// 企业研发机构等级 ishigh: 0,// 是否高企 logo: "",// 企业logo high:true, ishighInfo:"是", images: "",// 传到后台的图片json delimages: "",// 删除的图片 imagelist: []// app端图片插件进行传递的变量 }, organizationInfoJson:'' }; $scope.imagelist = []; $scope.delimagelist = [];//删除的图片 $scope.sourceimagelist = [];//复制时存储的图片 // 保存基本信息需要的格式 $scope.requestModel = { data: {}, node: "" }; //选择研发机构等级 var buttonsResearchStatus = [ { text: "国家级", ResearchStatusName:"国家级", ResearchStatusId: "10201" }, { text: "省级", ResearchStatusName:"省级", ResearchStatusId: "10202" }, { text: "市级", ResearchStatusName:"市级", ResearchStatusId: "10203" }, { text: "区级", ResearchStatusName:"区级", ResearchStatusId: "10204" } ]; //选择产业领域 var buttonsIndustryStatus = [ {text: "汽车制造", stausName:"汽车制造", stausId: "A" }, {text: "能源及节能技术", stausName:"能源及节能技术", stausId: "B" }, {text: "新材料", stausName:"新材料", stausId: "C" }, {text: "生物与新医药", stausName:"生物与新医药", stausId: "D" }, {text: "电子信息", stausName:"电子信息", stausId: "E" }, {text: "先进制造及高端装备", stausName:"先进制造及高端装备", stausId: "F" }, {text: "资源及环境技术", stausName:"资源及环境技术", stausId: "G" } ]; // 清空列表中的id,置为0 var clearIdinList = function (datalist) { if(UtilService.isDefined(datalist) && datalist.length > 0){ angular.forEach(datalist, function (value, index) { value.id = 0; }); } } // 编辑时获取走访详情 var getPublicResourceList = function () { //TODO $scope.connid = $stateParams.connid; // $scope.connid = 179; dataToolsService.getConnectioninfoDetailByConnid($scope.connid).then(function (response) { console.log("============编辑时获取走访详情=================="); console.log(response); // 基本信息 $scope.connEnterpriseModuleModel = response.data; if($scope.connEnterpriseModuleModel.ishigh==1){ $scope.connEnterpriseModuleModel.ishighInfo="是"; $scope.connEnterpriseModuleModel.high=true; }else if($scope.connEnterpriseModuleModel.ishigh==0){ $scope.connEnterpriseModuleModel.ishighInfo="否"; $scope.connEnterpriseModuleModel.high=false; } $scope.imagelist = response.data.imagelist; // 复制并新增时,清空所有的id if($scope.isedit == 2){ $scope.connEnterpriseModuleModel.id = 0; } }, function () { }); }; // 编辑时才获取 if($scope.isedit == 1){ getPublicResourceList(); }else if($scope.isedit == 0){ // 新增时 默认模版id $scope.connEnterpriseModuleModel.templettype = $stateParams.pageid; }else if($scope.isedit == 2){ // 复制并新增时 默认模版id getPublicResourceList(); } // 获取高校等级 var schtagbuttons = []; var getSchtagList = function () { dataToolsService.getTypeEntryListByTypeName("schtag").then(function (response) { if (UtilService.isDefined(response.data) && response.data.length > 0) { angular.forEach(response.data, function (value, index) { var temphtml = { text: '' + value.itemkey + '', rdinstitutiontype: value.itemvalue, rdinstitutiontypename: value.itemkey }; schtagbuttons.push(temphtml); }); console.log("schtagbuttons:"); console.log(schtagbuttons); } }, function () { }) }; getSchtagList(); //切换选择是否高企 $scope.watchIsChange=function () { if($scope.connEnterpriseModuleModel.high==true){ $scope.connEnterpriseModuleModel.ishighInfo="是"; $scope.connEnterpriseModuleModel.ishigh=1; }else{ $scope.connEnterpriseModuleModel.ishighInfo="否"; $scope.connEnterpriseModuleModel.ishigh=0; } }; // 弹出获取企业logo $scope.show_logo = function () { $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: [ {text: "拍照"}, {text: "从相册上传"} ], buttonClicked: function (index) { if (index == 0) { openCamera(1,1); } else { openCamera(0,1); } return true; }, destructiveButtonClicked: function () { return true; } }); }; //获取设备相机 var openCamera = function (srcType) { var options = { // Some common settings are 20, 50, and 100 quality: 50, destinationType: Camera.DestinationType.FILE_URI, // In this app, dynamically set the picture source, Camera or photo gallery sourceType: srcType, encodingType: Camera.EncodingType.JPEG, mediaType: Camera.MediaType.PICTURE, allowEdit: false, correctOrientation: true //Corrects Android orientation quirks }; navigator.camera.getPicture(function (imageData) { $scope.imgurl = imageData; $scope.showLoadingToast(); UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) { // 企业logo $scope.connEnterpriseModuleModel.orglogo = response[0].photoName; $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }); }, function (message) { }, options); }; // ****** 单信息图片 ****** $scope.openCamera = function () { if ($scope.imagelist.length >= 9) { UtilService.showMess("最多选取9张图片"); return; } UtilService.getPicture(1).then(function (results) { // console.log(results); $scope.imagelist.push({photoName: results, originalName: results}); $scope.totalImglength = 600 * $scope.imagelist.length; $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; $scope.show = function () { $ionicActionSheet.show({ buttons: [ {text: '相册中添加照片'}, {text: '拍照'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { getPictures(); } else if (index == 1) { $scope.openCamera(); } return true; } }); }; 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({photoName: value, originalName: value}) }); $scope.totalImglength = 600 * $scope.imagelist.length; $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; var getPictures = function () { if (device.platform == "Android") { verifyStorage(); } else { getPic(); } }; //点击图片放大 $scope.bigImage = false; //初始默认大图是隐藏的 $scope.hideBigImage = function () { if($scope.app){ $scope.setStatusBar(0); } $timeout(function () { $scope.bigImage = false; }, 400); }; $scope.shouBigImage = function (index) { //传递一个参数(图片的URl) if($scope.app){ $scope.setStatusBar(1); } $(function () { $('div.pinch-zoom').each(function () { new RTP.PinchZoom($(this), {}); }); }); $scope.bigImage = true;//显示大图 $ionicSlideBoxDelegate.update();//重绘,让图片显示出来 //图片总数量 setTimeout(function () { $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 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') } } }, 10); }; //删除图片 $scope.deletePhoto = function (index) { if ($scope.imagelist[index].id != 0) { // 将删除的加入删除列表,再从图片数组里删除 $scope.imagelist[index].isenabled = 2;//若删除,则置为不可用,调用通用update $scope.delimagelist.push($scope.imagelist[index]); $scope.imagelist.splice(index, 1); }else{ $scope.imagelist.splice(index, 1); } }; //关联相关企业 $scope.isRelateUl = false; $scope.queryLikeName = function () { if ($scope.connEnterpriseModuleModel.orgname.length == 0) { $scope.companylist = []; $scope.isRelateUl = false; return; } // 全部置空 $scope.connEnterpriseModuleModel.organizationInfo.id = 0; $scope.connEnterpriseModuleModel.orglogo = ""; $scope.connEnterpriseModuleModel.orgcontact = ""; $scope.connEnterpriseModuleModel.orgcontactnum = ""; $scope.connEnterpriseModuleModel.categoryid = 0; $scope.connEnterpriseModuleModel.categoryname = ""; $scope.connEnterpriseModuleModel.orggradecode = 0; $scope.connEnterpriseModuleModel.rdinstitutiontypename = ""; $scope.connEnterpriseModuleModel.ishigh = 0; $scope.connEnterpriseModuleModel.ishighInfo="否"; $scope.connEnterpriseModuleModel.high=false; $scope.connEnterpriseModuleModel.remark=""; dataToolsService.getOrganizationModelByOrgname($scope.connEnterpriseModuleModel.orgname).then(function (response) { // console.log(response); $scope.companylist = response.data; $scope.isRelateUl = true; }, function () { }) }; //选中企业 $scope.setCompanyName = function (organizationInfo) { // organizationInfo.name = organizationInfo.name.replace("", ""); organizationInfo.name = organizationInfo.name.replace("", ""); $scope.connEnterpriseModuleModel.organizationInfo.id = organizationInfo.id; $scope.connEnterpriseModuleModel.orgname = organizationInfo.name; $scope.connEnterpriseModuleModel.orglogo = organizationInfo.logo; $scope.connEnterpriseModuleModel.orgcontact = organizationInfo.contact; $scope.connEnterpriseModuleModel.orgcontactnum = organizationInfo.contactnum; $scope.connEnterpriseModuleModel.categoryid = organizationInfo.categoryid; $scope.connEnterpriseModuleModel.categoryname = organizationInfo.categoryname; $scope.connEnterpriseModuleModel.orggradecode = organizationInfo.rdinstitutiontype; $scope.connEnterpriseModuleModel.rdinstitutiontypename = organizationInfo.rdinstitutiontypename; $scope.connEnterpriseModuleModel.ishigh = organizationInfo.ishigh; if($scope.connEnterpriseModuleModel.ishigh==1){ $scope.connEnterpriseModuleModel.ishighInfo="是"; $scope.connEnterpriseModuleModel.high=true; }else if($scope.connEnterpriseModuleModel.ishigh==0){ $scope.connEnterpriseModuleModel.ishighInfo="否"; $scope.connEnterpriseModuleModel.high=false; } $scope.isRelateUl = false; }; //获得研发机构等级 $scope.showResearchStatus=function () { $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: buttonsResearchStatus, buttonClicked: function (index) { $scope.connEnterpriseModuleModel.orggradecode = buttonsResearchStatus[index].ResearchStatusId; $scope.connEnterpriseModuleModel.rdinstitutiontypename = buttonsResearchStatus[index].ResearchStatusName; return true; }, destructiveButtonClicked: function () { return true; } }); }; //获得产业领域 $scope.showIndustryStatus=function () { $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: buttonsIndustryStatus, buttonClicked: function (index) { $scope.connEnterpriseModuleModel.categoryid = buttonsIndustryStatus[index].stausId; $scope.connEnterpriseModuleModel.categoryname = buttonsIndustryStatus[index].stausName; return true; }, destructiveButtonClicked: function () { return true; } }); }; //选择高校的高校等级 $scope.showSchtag = function (ind) { $ionicActionSheet.show({ buttons: schtagbuttons, cancelText: '取消', buttonClicked: function (index) { $scope.connEnterpriseModuleModel.orggradecode = schtagbuttons[index].rdinstitutiontype; $scope.connEnterpriseModuleModel.rdinstitutiontypename = schtagbuttons[index].rdinstitutiontypename; return true; } }); }; //获得专家研究领域 $scope.showTalentStatus=function () { $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: buttonsIndustryStatus, buttonClicked: function (index) { $scope.talentModuleModel.talent.categoryid = buttonsIndustryStatus[index].stausId; $scope.talentModuleModel.talent.responsible = buttonsIndustryStatus[index].stausName; return true; }, destructiveButtonClicked: function () { return true; } }); }; var saveflg = 0;//只允许保存触发一次,多次触发无效,默认未提交 var tempimages = []; //保存企业信息表 $scope.saveCompanyInfo = function () { // 基本信息 if (!UtilService.isDefined($scope.connEnterpriseModuleModel.orgname)) { UtilService.showMess("请填写企业名称"); return; } if ($scope.connEnterpriseModuleModel.orgname.length > 50) { UtilService.showMess("企业名称不能超过50个字"); return; } if (UtilService.isDefined($scope.connEnterpriseModuleModel.remark) && $scope.connEnterpriseModuleModel.remark.length > 1000) { UtilService.showMess("备注不能超过1000个字"); return; } if (saveflg != 0) { return; } saveflg = 1; $scope.showLoadingToast(); if ($scope.imagelist.length > 0) { uploadImages(); } else { saveInfo(); } }; //保存高校信息表 $scope.saveSchoolInfo = function () { // 基本信息 if (!UtilService.isDefined($scope.connEnterpriseModuleModel.orgname)) { UtilService.showMess("请填写高校名称"); return; } if ($scope.connEnterpriseModuleModel.orgname.length > 50) { UtilService.showMess("高校名称不能超过50个字"); return; } if ($scope.connEnterpriseModuleModel.orgcontent.length > 200) { UtilService.showMess("高校简介不能超过100个字"); return; } if (UtilService.isDefined($scope.connEnterpriseModuleModel.remark) && $scope.connEnterpriseModuleModel.remark.length > 1000) { UtilService.showMess("备注不能超过1000个字"); return; } if (saveflg != 0) { return; } saveflg = 1; $scope.showLoadingToast(); saveSchoolInfo(); }; var uploadImages = function () { tempimages = []; var upimages = []; angular.forEach($scope.imagelist, function (data) { upimages.push(data.photoName); // 复制时,将不上传的另外保存,需保存至数据库 if($scope.isedit == 2 && UtilService.isDefined(data.id)){ $scope.sourceimagelist.push(data); } }); UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) { // console.log(response); angular.forEach(response, function (value) { if (value.status) { tempimages.push({ id: 0, title: "", doctype: value.doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: value.photoName, originalName: value.originalName, sourceName: value.sourceName, sourceSize: value.sourceSize }); } }); $timeout(function () { saveInfo(); }, 100); }, function () { $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); saveflg = 0; }); }; // 保存企业信息 var saveInfo = function () { // 企业图片 // 将删除的一起提交 if($scope.delimagelist.length > 0) { angular.forEach($scope.delimagelist, function (val, ind) { tempimages.push(val); }); } // 将复制时临时保存的一起提交 if($scope.sourceimagelist.length > 0){ angular.forEach($scope.sourceimagelist, function (val, ind) { tempimages.push(val); }); } $scope.connEnterpriseModuleModel.images = JSON.stringify(tempimages); // 保存走访基本信息 $scope.connEnterpriseModuleModel.userModel.userid = UserService.id; // 走访履历表中需记录机构信息 $scope.connEnterpriseModuleModel.organizationInfo.name = $scope.connEnterpriseModuleModel.orgname; $scope.connEnterpriseModuleModel.title = $scope.connEnterpriseModuleModel.organizationInfo.name; $scope.connEnterpriseModuleModel.templettype = $scope.rolePageModel.id; $scope.connEnterpriseModuleModel.organizationInfo.logo = $scope.connEnterpriseModuleModel.orglogo;// 企业logo $scope.connEnterpriseModuleModel.organizationInfo.about = $scope.connEnterpriseModuleModel.orgcontent;// 企业logo $scope.connEnterpriseModuleModel.orgtype = $scope.rolePageModel.orgtype;// 机构类型 $scope.connEnterpriseModuleModel.organizationInfo.orgtype = $scope.rolePageModel.orgtype;// 机构类型 $scope.connEnterpriseModuleModel.organizationInfo.contact = $scope.connEnterpriseModuleModel.orgcontact; $scope.connEnterpriseModuleModel.organizationInfo.contactnum = $scope.connEnterpriseModuleModel.orgcontactnum; $scope.connEnterpriseModuleModel.organizationInfo.categoryid = $scope.connEnterpriseModuleModel.categoryid; $scope.connEnterpriseModuleModel.organizationInfo.categoryname = $scope.connEnterpriseModuleModel.categoryname; $scope.connEnterpriseModuleModel.organizationInfo.rdinstitutiontype = $scope.connEnterpriseModuleModel.orggradecode;// 企业研发机构等级 $scope.connEnterpriseModuleModel.organizationInfo.ishigh = $scope.connEnterpriseModuleModel.ishigh;// 是否高企 // 传参格式 $scope.requestModel.data = $scope.connEnterpriseModuleModel; $scope.requestModel.node = UserService.node; dataToolsService.saveOrganizationInfo($scope.requestModel).then(function (response) { console.log(response); if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){ UtilService.showMess("添加成功"); $timeout(function () { // 保存走访基本信息 后保存其他内容 // 取得记录id var connid = response.data.id; $scope.connEnterpriseModuleModel.id = connid; // 取得机构id var orgid = response.data.organizationInfo.id; $scope.connEnterpriseModuleModel.organizationInfo.id = orgid; // $scope.goback(); // 添加成功后跳入我的录入 $scope.go("recordInfoAccount"); }, 500); } else { UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); } $scope.hideLoadingToast(); saveflg = 0; }, function () { UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); $scope.hideLoadingToast(); saveflg = 0; }); }; //进入资源详情 $scope.jumpResourceDetail = function (company) { // 先预设信息 $scope.setCompanyName(company); // 再跳转到资源详情页 $scope.go('resourceCommonDetailsPage', { recourceid: company.resourcelibrary.id, recourcetype: company.resourcelibrary.restype, recourcecomefrom: company.resourcelibrary.comefrom, creator: company.resourcelibrary.creator }); }; });