angular.module('push')
.controller('recordDemandInfoCtrl', function ($scope,$stateParams,dataToolsService,UtilService,ConstantService,
$timeout,$ionicActionSheet,UserService) {
// 对应的是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);
}else
// 复制并新建
if($scope.isedit == 2){
$scope.pagetitle = "复制并新建需求信息";
$timeout(function () {
$("#orgname").prop("disabled", true);
},300);
}
//企业基本信息
$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,// 企业研发机构等级
ishigh: 0,// 是否高企
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端图片插件进行传递的变量
}
};
$scope.deldemandInfo = "";
// 保存基本信息需要的格式
$scope.requestModel= {
data: {},
node: ""
};
// 获取走访录入界面的传参
$scope.rolePageModel=
{
//TODO
id: $stateParams.pageid,// 模版id
orgtype: ConstantService.UNITTYPE_10104// 走访对应的机构类型
// id: 2,// 模版id
// orgtype: 2,// 模版id
};
//需求信息
$scope.demandInfoList = [{
id: 0,
connid: 0,
companyid: 0,
creator: 0,
updater: 0,
isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
techtype: 0,
techtypename: "",
techrequirementname: "",
cooperationmodel: "",
cooperationmodelname: "",// 合作模式名称
capitalScale: 0,
techrequirementdetail: "",
remark: "",// 备注
techrequirementsolution: "",// 问题解决方案
images: "", // 图片
}];
//添加、删除更多需求信息
$scope.AddOrDelDemandInfo = function (ind) {
if (ind == 0) {
$scope.demandInfoList.push({
id: 0,
connid: 0,
companyid: 0,
creator: 0,
updater: 0,
isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
techtype: 0,
techtypename: "",
techrequirementname: "",
cooperationmodel: "",
cooperationmodelname: "",// 合作模式名称
capitalScale: 0,
techrequirementdetail: "",
remark: "",// 备注
techrequirementsolution: "",// 问题解决方案
images: "", // 图片
});
} else {
if ($scope.demandInfoList[ind].id != 0) {
deldemandInfo.push($scope.demandInfoList[ind].id);
}
$scope.demandInfoList.splice(ind, 1);
}
};
// 清空列表中的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.demandInfoList = $scope.connEnterpriseModuleModel.techrequirementLkList;
// 复制并新增时,清空所有的id
if($scope.isedit == 2){
$scope.connEnterpriseModuleModel.id = 0;
clearIdinList($scope.demandInfoList);
}
}, function () {
});
};
// 编辑时才获取
if($scope.isedit == 1){
getPublicResourceList();
}else
if($scope.isedit == 0){
// 新增时 默认模版id
$scope.connEnterpriseModuleModel.templettype = $stateParams.pageid;
}
else
if($scope.isedit == 2){
// 复制并新增时 默认模版id
getPublicResourceList();
}
//关联相关企业
$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="";
$scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10104;// 默认机构类型:企业
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.rolePageModel.orgtype = organizationInfo.orgtype;// 取得选中的机构类型
$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;
};
// 获取需求的合作模式列表
var cooperationmodelbuttons = [];
var getCooperationmodelList = function () {
dataToolsService.getTypeEntryListByTypeName("cooperationmodel").then(function (response) {
if (UtilService.isDefined(response.data) && response.data.length > 0) {
angular.forEach(response.data, function (value, index) {
var temphtml = {
text: '' + value.itemkey + '',
cooperationmodel: value.itemvalue,
cooperationmodelname: value.itemkey
};
cooperationmodelbuttons.push(temphtml);
});
// console.log(cooperationmodelbuttons);
}
}, function () {
})
};
getCooperationmodelList();
// 获取需求的需求类型列表
var techtypebuttons = [];
var getTechtypeList = function () {
dataToolsService.getTypeEntryListByTypeName("techtype").then(function (response) {
if (UtilService.isDefined(response.data) && response.data.length > 0) {
angular.forEach(response.data, function (value, index) {
var temphtml = {
text: '' + value.itemkey + '',
techtype: value.itemvalue,
techtypename: value.itemkey
};
techtypebuttons.push(temphtml);
});
// console.log(cooperationmodelbuttons);
}
}, function () {
})
};
getTechtypeList();
//选择需求的合作模式列表
$scope.showCooperationmodelStatus = function (ind) {
$ionicActionSheet.show({
buttons: cooperationmodelbuttons,
cancelText: '取消',
buttonClicked: function (index) {
$scope.demandInfoList[ind].cooperationmodel = cooperationmodelbuttons[index].cooperationmodel;
$scope.demandInfoList[ind].cooperationmodelname = cooperationmodelbuttons[index].cooperationmodelname;
return true;
}
});
};
//选择需求的需求类型
$scope.showTechtype = function (ind) {
$ionicActionSheet.show({
buttons: techtypebuttons,
cancelText: '取消',
buttonClicked: function (index) {
$scope.demandInfoList[ind].techtype = techtypebuttons[index].techtype;
$scope.demandInfoList[ind].techtypename = techtypebuttons[index].techtypename;
return true;
}
});
};
// 保存企业信息
var saveInfo = function () {
// 需求信息
if ($scope.demandInfoList.length > 0) {
angular.forEach($scope.demandInfoList, function (demandInfoList, $index) {
if (!UtilService.isDefined($scope.demandInfoList[$index].techrequirementname)
&& !UtilService.isDefined($scope.demandInfoList[$index].techrequirementdetail)) {
$scope.demandInfoList.splice($index, 1);
}
});
}
// 保存走访基本信息
$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;
// 保存公司需求
if ($scope.demandInfoList.length > 0) {
angular.forEach($scope.demandInfoList, function (value, index) {
value.connid = $scope.connEnterpriseModuleModel.id;
value.companyid = $scope.connEnterpriseModuleModel.organizationInfo.id;
value.creator = UserService.id;
value.updater = UserService.id;
});
// 传参格式
$scope.requestModel.data = $scope.demandInfoList;
$scope.requestModel.node = UserService.node;
dataToolsService.insertOrUpdateCompanyTechrequirement($scope.requestModel).then(function (response) {
}, function () {
UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
});
}
// 添加成功后跳入我的录入
$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;
});
};
var saveflg = 0;//只允许保存触发一次,多次触发无效,默认未提交
$scope.saveDemandInfo=function () {
// 需求信息
if (!UtilService.isDefined($scope.connEnterpriseModuleModel.orgname)) {
UtilService.showMess("请填写单位名称");
return;
}
if ($scope.connEnterpriseModuleModel.orgname.length > 50) {
UtilService.showMess("单位名称不能超过50个字");
return;
}
if (saveflg != 0) {
return;
}
var result = 1;
// 需求信息
if ($scope.demandInfoList.length > 0) {
angular.forEach($scope.demandInfoList, function (demandInfoList,index) {
if (!UtilService.isDefined($scope.demandInfoList[index].techrequirementname)
|| $scope.demandInfoList[index].techrequirementname.length == 0) {
result = 2;
}
if (result == 1 && $scope.demandInfoList[index].techrequirementname.length > 255) {
result = 0;
}
if (result == 1 && UtilService.isDefined($scope.demandInfoList[index].remark) && $scope.demandInfoList[index].remark.length > 1000) {
result = 3;
}
});
if(result == 0){
UtilService.showMess("需求名称不能超过255个字");
saveflg = 0;
return;
}else
if(result == 2){
UtilService.showMess("需求名称不能为空");
saveflg = 0;
return;
}else
if(result == 3){
UtilService.showMess("需求备注不能超过1000个字");
saveflg = 0;
return;
}
$scope.showLoadingToast();
saveInfo();
console.log($scope.demandInfoList);
saveflg = 1;
}
};
//进入资源详情
$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
});
};
});