angular.module('push') .controller('typeinAllModalCtrl', function ($scope,$q, $stateParams, UserService, UtilService, roleService,$ionicActionSheet, ConstantService,$timeout, $ionicScrollDelegate, ActivityService, TechnicalBrokerPublishTrainService, dataToolsService,CommonService,$interval ) { //TODO 放开注释 if($scope.app){ if (device.platform != "Android") { $scope.isIos=true; }else{ $scope.isIos=false; } } $scope.showMess=function(msg){ if($scope.app){ UtilService.showMess(msg); }else{ CommonService.showMessage(msg,$scope); } } // 对应的是0新增/1编辑 $scope.isedit = $stateParams.isedit; //$scope.isedit = 1; if($scope.isedit == 0){ $scope.pagetitle = "新建录入"; }else if($scope.isedit == 1){ $scope.pagetitle = "编辑录入"; $timeout(function () { $("#orgname").prop("disabled", true); },300); }else // 复制并新建 if($scope.isedit == 2){ $scope.pagetitle = "复制并新建走访"; $timeout(function () { $("#orgname").prop("disabled", true); },300); } console.log($stateParams); // 获取走访录入界面的传参 $scope.rolePageModel= { //TODO id: $stateParams.pageid,// 模版id orgtype: $stateParams.orgtype// 走访对应的机构类型 // id: 1,// 模版id // orgtype: 10104,// 模版id }; //根据模版获取所有模块 console.log($stateParams); var hasSearchData=[]; var getAllData=function(){ var def=$q.defer(); dataToolsService.getDetailEdit($stateParams.connid,$stateParams.pagecode,$stateParams.node).then(function(res){ if(res.code==3350){ console.log(res.data); def.resolve(res.data); }else{ def.reject('错误'); } }) return def.promise; } // console.log($scope.rolePageModel); var getRolePageSectionList = function () { console.log($scope.rolePageModel); roleService.getRolePageSectionList($scope.rolePageModel).then(function (response) { // console.log("=============================="); console.log(response.data); // 基本信息 $scope.sectionList = response.data.sectionList; if (UtilService.isDefined($scope.sectionList)) { angular.forEach($scope.sectionList, function (value, index) { var baseactivity = { className:'', headerName:'', restype:'' }; // console.log(value); baseactivity.className = value.seccode;// 模块编号 baseactivity.headerName = value.secname;// 模块名称 baseactivity.restype = value.lktablecode;// 模块名称 $scope.activity.push(baseactivity); if ($scope.activity.length > 0) { $scope.act = $scope.activity[0].className; } }); for(var i=0;i<$scope.activity.length;i++){ hasSearchData[i]=true; } $scope.showLoadingToast(); if($scope.isedit==1||$scope.isedit==2){ getAllData().then(function(response){ console.log(response); angular.forEach($scope.activity,function(val,index){ getData(val.headerName,val.restype,index,response); }) }) }else{ angular.forEach($scope.activity,function(val,index){ getData(val.headerName,val.restype,index,val.headerName); }) } } }, function () { }) }; getRolePageSectionList(); //切换到对应页面 $scope.activity=[]; $scope.visitType=0;//0:高校走企业 ,1:政府走企业,2:术经纪人或服务机构走企业,3:企业走高校,4:政府走高校、技术经纪人或服务机构走高校 var lastNum=0; $scope.tempData=[]; //从后台获取数据 // 默认显示内容 $scope.getDataFromBackground={ detailList:[], addList:[], pagecode:0, title:'', tcname:'', itemvalue:'', tablename:'', templettype:0, }; $scope.getFirstPage=true; var getData=function(title,restype,num,response){ // console.log(restype); // console.log($stateParams); var tempArray={}; dataToolsService.getFormStructure($stateParams.pagecode,restype,0,$stateParams.node).then(function(res){ if(res.code==3350){ console.log(res.data.infoSectionList[0]); console.log(title); tempArray.detailList=res.data.infoSectionList[0].unitItems[0]; tempArray.addList=res.data.infoSectionList[0].subItems; tempArray.pagecode=$stateParams.pagecode; tempArray.title=title; tempArray.tcname=res.data.infoSectionList[0].tcname; tempArray.restype=restype; tempArray.tablename=res.data.infoSectionList[0].tablename; tempArray.orgid=0; if($scope.isedit==1||$scope.isedit==2){ var data=response.infoSectionList; tempArray.oid=response.baseInfoModel.oid; if(tempArray.addList&&tempArray.addList.length>0){ angular.forEach(tempArray.addList,function(ta){ var temp=data.filter(function(da){ if(da.innertype){ return da.itemvalue==ta.itemvalue&&da.innertype==ta.innertype; }else{ return da.itemvalue==ta.itemvalue; } }) if(temp.length>0){ angular.forEach(temp[0].unitlist,function(vv){ for(var i=0;i0){ var temp=data.filter(function(vv1){ return vv1.itemvalue==restype }) if(temp.length>0){ angular.forEach(temp[0].unitlist,function(vv2){ for(var i=0;i 0){ angular.forEach(datalist, function (value, index) { value.id = 0; }); } } // 编辑时才获取 if($scope.isedit == 1){ // getPublicResourceList(); }else if($scope.isedit == 0){ // 新增时 默认模版id $scope.connEnterpriseModuleModel.templettype = $stateParams.pageid; }else if($scope.isedit == 2){ // 复制并新增时 默认模版id // getPublicResourceList(); } //获取走访履历详情 var gotoSelectFieldsToSet = function () { $scope.go("selectFieldsToSet", {typecodemap: $scope.connInfoDetail.typecodemap, resid: $scope.connEnterpriseModuleModel.id, typecode: ConstantService.TABLE_CODE_30003}); }; //获取走访履历详情 var getConnInfo = function (connid) { }; //保存企业信息表 // 控制多次点击保存不触发 var saveflg = 0; var tempimages = []; var basicArr=[];//基本信息 // var projectInfo=[];//项目信息 // var comProduct=[];//企业产品 var basicOperate=[]; var basicIPR=[]; var basicContact=[]; var basicIUS={}; var temp={}; /************ sarah ****************/ // 处理数组 var handleArray=function(arr,delarr){ console.log(arr); if(delarr!='other'&&delarr&&delarr.length>0){ angular.forEach(delarr,function(v,i){ angular.forEach(v,function(vv){ if(vv.tcname=='isenabled'){ vv.content='2'; } }) arr.push(v); }) } if(arr&&arr.length>0){ var array=[]; // 全部为空,则舍弃该组数据 for(var i=0;i0)){ break; } } if(j==arr[i].length){ arr.splice(i,1); i--; }; } // 赋初始值 for(var i=0;i研发投入 var saveCompanyYearMultipleoptions1 = function () { $scope.requestModel = { data: [], node: UserService.node }; // 获取研发投入数据 if(basicArr.addList){ tempArr=basicArr.addList.filter(function(value,j,arr){ return value.title=='研发投入' })[0]; if(tempArr){ $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); } } // console.log($scope.requestModel.data); if(String($scope.requestModel.data)==''){ saveCompanyYearMultipleoptions2(); }else{ dataToolsService.insertOrUpdateCompanyYearMultipleoptions($scope.requestModel).then(function (response) { // 保存销售收入、净利润、上缴税收 saveCompanyYearMultipleoptions2(); // console.log(response); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // console.log(2); // 2保存走访销售收入、净利润、上缴税收 企业基本信息->实际收入/预计投入情况 var saveCompanyYearMultipleoptions2 = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // 保存走访销售收入、净利润、上缴税收 if(basicArr.addList){ tempArr=basicArr.addList.filter(function(value,j,arr){ return value.title=='实际收入/预计投入情况' })[0]; if(tempArr){ $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); } } // console.log(2); // console.log($scope.requestModel); if(String($scope.requestModel.data)==''){ saveCompanyYearMultipleoptions3(); }else{ dataToolsService.insertOrUpdateCompanyYearMultipleoptions($scope.requestModel).then(function (response) { // 保存走访工程中心情况 // console.log(response); saveCompanyYearMultipleoptions3(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 3保存走访工程中心情况 企业基本信息->工程中心信息 添加专利申请 var saveCompanyYearMultipleoptions3= function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; if(basicArr.addList){ tempArr=basicArr.addList.filter(function(value,j,arr){ return value.title=='工程中心信息' })[0]; if(tempArr){ $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); } } if(basicIPR){ var temp=basicIPR.addList.filter(function(val){ return val.title=='添加专利申请'; }) if(temp.length>0){ $scope.requestModel.data=handleArray(temp[0].unitItems,temp[0].deletUnitItems); } } // console.log('abc'); // console.log($scope.requestModel.data); if(String($scope.requestModel.data)==''){ saveCompanyTechrequirement(); }else{ dataToolsService.insertOrUpdateCompanyYearMultipleoptions($scope.requestModel).then(function (response) { // console.log(response); // 保存关联需求表 saveCompanyTechrequirement(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 4保存关联需求表 企业需求 var saveCompanyTechrequirement = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; var demand=$scope.tempData.filter(function(val,i,arr){ return val.title=='企业需求'; })[0]; if(demand){ $scope.requestModel.data=handleArray(demand.addList[0].unitItems,demand.addList[0].deletUnitItems); } // console.log(4); // console.log($scope.requestModel); if(String($scope.requestModel.data)==''){ saveCompanyDeclareproject(); }else{ dataToolsService.insertOrUpdateCompanyTechrequirement($scope.requestModel).then(function (response) { // console.log(response); // 5保存走访申报项目接口 saveCompanyDeclareproject(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 5保存走访申报项目接口 项目信息->项目建议 var saveCompanyDeclareproject = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // if(projectInfo){ // tempArr=projectInfo.addList.filter(function(value,j,arr){ // return value.title=='添加项目建议' // })[0]; // if(tempArr){ // $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); // } // } // console.log(5); if(String($scope.requestModel.data)==''){ saveCompanyHighleveltalents(); }else{ dataToolsService.insertOrUpdateCompanyDeclareproject($scope.requestModel).then(function (response) { // console.log(response); // 6保存高端人才信息表 saveCompanyHighleveltalents(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 6保存高端人才信息表 人才信息 var saveCompanyHighleveltalents = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; var talentPerson=$scope.tempData.filter(function(val,i,arr){ return val.title=='人才信息'; })[0]; if(talentPerson){ $scope.requestModel.data=handleArray(talentPerson.addList[0].unitItems,talentPerson.addList[0].deletUnitItems); } // console.log(6); if(String($scope.requestModel.data)==''){ saveCompanyHignendproduct(); }else{ dataToolsService.insertOrUpdateCompanyHighleveltalents($scope.requestModel).then(function (response) { // console.log(response); // 7保存高端产品 saveCompanyHignendproduct(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 7保存高端产品 企业产品->高新产品 var saveCompanyHignendproduct = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // if(comProduct){ // tempArr=comProduct.addList.filter(function(value,j,arr){ // return value.title=='添加高新产品' // })[0]; // if(tempArr){ // $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); // } // } // console.log(7); if(String($scope.requestModel.data)==''){ saveCompanyIur(); }else{ dataToolsService.insertOrUpdateCompanyHignendproduct($scope.requestModel).then(function (response) { // console.log(response); // 8保存产学研 saveCompanyIur(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; var saveIUSInfo=function(arr){ var def=$q.defer(); var saveStatus=[]; for(var i=0;i产学研经验 var saveCompanyIur = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; if($stateParams.pagecode==1000003){ tempArr=projectInfo.addList.filter(function(value,j,arr){ return value.title=='添加产学研经验' })[0]; if(tempArr){ $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); } // console.log(8); if(String($scope.requestModel.data)==''){ saveCompanyYearMultipleoptions4(); }else{ dataToolsService.insertOrUpdateCompanyIur($scope.requestModel).then(function (response) { // console.log(response); // 9保存重大科研项目 saveCompanyYearMultipleoptions4(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }else{ if(basicIUS){ // $scope.requestModel.data=handleArray(iurCooperation.addList[0].unitItems,iurCooperation.addList[0].deletUnitItems); saveIUSInfo(basicIUS.addList).then(function(data){ if(data){saveCompanyYearMultipleoptions4();} }) } } }; // 9保存重大科研项目 项目信息->重大科研项目 var saveCompanyYearMultipleoptions4 = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // if(projectInfo){ // tempArr=projectInfo.addList.filter(function(value,j,arr){ // return value.title=='添加重大科研项目' // })[0]; // if(tempArr){ // $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); // } // } // console.log(9); if(String($scope.requestModel.data)==''){ saveCompanyProduct(); }else{ dataToolsService.insertOrUpdateCompanyYearMultipleoptions($scope.requestModel).then(function (response) { // console.log(response); // 10保存公司产品 saveCompanyProduct(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 10保存公司产品 企业产品->产品 var saveCompanyProduct = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // if(comProduct){ // tempArr=comProduct.addList.filter(function(value,j,arr){ // return value.title=='添加产品' // })[0]; // if(tempArr){ // $scope.requestModel.data=handleArray(tempArr.unitItems,tempArr.deletUnitItems); // } // } // console.log(10); if(String($scope.requestModel.data)==''){ saveCompanyIntellectualproperty(); }else{ dataToolsService.insertOrUpdateCompanyProduct($scope.requestModel).then(function (response) { // console.log(response); // 11保存专利信息 saveCompanyIntellectualproperty(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 11保存专利信息 专利信息 知识产权 var saveCompanyIntellectualproperty = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; var patent=basicIPR.addList.filter(function(val){ return val.title=='添加知识产权' })[0]; if(patent){ $scope.requestModel.data=handleArray(patent.unitItems,patent.deletUnitItems); } // console.log(11); // console.log($scope.requestModel); if(String($scope.requestModel.data)==''){ saveCompanyResearchfinding(); }else{ dataToolsService.insertOrUpdateCompanyIntellectualproperty($scope.requestModel).then(function (response) { // console.log(response); // 12保存成果信息 saveCompanyResearchfinding(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 12保存成果信息 高校->成果 var saveCompanyResearchfinding = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; var achievement=$scope.tempData.filter(function(val,i,arr){ return val.title=='成果信息'; })[0]; if(achievement){ $scope.requestModel.data=handleArray(achievement.addList[0].unitItems,achievement.addList[0].deletUnitItems); } // console.log(12); if(String($scope.requestModel.data)==''){ saveCompanySpecialty(); }else{ dataToolsService.insertOrUpdateCompanyResearchfinding($scope.requestModel).then(function (response) { // console.log(response); // 13保存特色专业信息表 saveCompanySpecialty(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 13保存特色专业信息表 var saveCompanySpecialty = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // 保存特色专业信息 var specialty=$scope.tempData.filter(function(val,i,arr){ return val.title=='特色专业信息'; })[0]; if(specialty){ $scope.requestModel.data=handleArray(specialty.addList[0].unitItems,specialty.addList[0].deletUnitItems); } // console.log(13); if(String($scope.requestModel.data)==''){ savebusinessCircumstance(); }else{ dataToolsService.insertOrUpdateCompanySpecialty($scope.requestModel).then(function (response) { // console.log(response); // 14保存实验室信息表 savebusinessCircumstance(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 14保存经营情况 var savebusinessCircumstance = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; if(basicOperate){ $scope.requestModel.data=handleArray(basicOperate.addList[0].unitItems,basicOperate.addList[0].deletUnitItems); } // console.log(9); if(String($scope.requestModel.data)==''){ saveHR(); }else{ dataToolsService.insertOrUpdateCompanyYearMultipleoptions($scope.requestModel).then(function (response) { // console.log(response); // 10保存公司产品 saveHR(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 15保存人力资源 var saveHR = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; tempArr=$scope.tempData.filter(function(value,j,arr){ return value.title=='人力资源' })[0]; if(tempArr){ $scope.requestModel.data=handleArray([tempArr.detailList],'other'); } // console.log(9); // console.log($scope.requestModel.data); // console.log(String($scope.requestModel.data)); if(String($scope.requestModel.data)==''){ saveCompanyLab(); }else{ // console.log($scope.requestModel); dataToolsService.insertOrUpdateCompanyHR($scope.requestModel).then(function (response) { // console.log(response); // 10保存公司产品 saveCompanyLab(); }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; // 15保存实验室信息表 var saveCompanyLab = function () { // 保存多条信息需要的格式 $scope.requestModel = { data: [], node: UserService.node }; // 保存实验室信息表 var labInfo=$scope.tempData.filter(function(val,i,arr){ return val.title=='实验室信息'; })[0]; if(labInfo){ $scope.requestModel.data=handleArray(labInfo.addList[0].unitItems,labInfo.addList[0].deletUnitItems); } // console.log(14); if(String($scope.requestModel.data)==''){ $timeout(function () { // console.log($scope.connEnterpriseModuleModel.id); // console.log(15); dataToolsService.getConnectioninfoDetailByConnid($scope.connEnterpriseModuleModel.id,$stateParams.pagecode,0,UserService.node).then(function (response) { // console.log("=============================="); // console.log(response); $scope.hideLoadingToast(); // 走访履历详情 $scope.connInfoDetail = response.data; $timeout(function () { // gotoSelectFieldsToSet(); $scope.go("recordInfoAccount"); }, 500); }, 500); }, function () { }) }else{ dataToolsService.insertOrUpdateCompanyLab($scope.requestModel).then(function (response) { // 添加成功后先查询保存的走访履历,再把typecodemap传递并跳转到 设置权限 界面 // 获取走访履历详情 if($scope.app){ UtilService.showMess("添加成功"); }else{ CommonService.showMessage("添加成功",$scope); } $timeout(function () { // console.log($scope.connEnterpriseModuleModel.id); // console.log(15); dataToolsService.getConnectioninfoDetailByConnid($scope.connEnterpriseModuleModel.id,$stateParams.pagecode,0,UserService.node).then(function (response) { // console.log("=============================="); // console.log(response); $scope.hideLoadingToast(); // 走访履历详情 $scope.connInfoDetail = response.data; $timeout(function () { // gotoSelectFieldsToSet(); $scope.go("recordInfoAccount"); }, 500); }, 500); }, function () { }) }, function () { if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) } }; }).directive('stringToNumber', function() { return { require: 'ngModel', link: function(scope, element, attrs, ngModel) { ngModel.$parsers.push(function(value) { return '' + value; }); ngModel.$formatters.push(function(value) { return parseInt(value); }); } }; }).directive('stringToNumber2', function() { return { require: 'ngModel', link: function(scope, element, attrs, ngModel) { ngModel.$parsers.push(function(value) { return '' + value; }); ngModel.$formatters.push(function(value) { return parseInt(value); }); } }; });