angular.module('push') .controller('editListCardCtrl', function ($scope, $stateParams, ModelService, $ionicActionSheet, UtilService, UserService, ConfigService, DockingService, $timeout) { //空人员信息 var person = { infoid: 0, contact: "", phone: "", email: "", rank: "", categoryid: 0, introduce: "" }; //空主题信息 var theme = { infoid: 0, type: 0, title: "", content: "" }; //空产品信息 var product = { infoid: 0, productname: "", productdescription: "" }; //空产学研经历 var iur1 = { infoid: 0, cooperateschool: "", cooperatedetail: "" }; //空重大科研项目 var iur2 = { infoid: 0, productname: "", productyear: "" }; //空历年申报项目 var yearproject = { year: "", name: "", money: "", description: "" }; var addperflg = true; var addtheflg = true; var addproflg = true; var addiur1flg = true; var addiur2flg = true; var addyearprojectflg = true; var deletememberids = ""; var deletethemeids = ""; var deleteproductids = ""; var deleteiur1ids = ""; var deleteiur2ids = ""; var deleteyearprojectids = ""; //编辑或新增 卡片 var index = $stateParams.index; if (index == -1) { $scope.card = { name: "", categoryid: 0, categorydetail: "", type: -1, address: "", presentation: "", synchrotype: 1, creator: UserService.id, creatorcomefrom: ConfigService.comefrom, isinsert: 0, personlist: [], themelist: [], productlist: [], iur1list: [], iur2list: [], calendarlist:[] }; } else { $scope.card = angular.copy(ModelService.getCardList()[index]); if ($scope.card.personlist.length > 0) { addperflg = false; } if ($scope.card.themelist.length > 0) { addtheflg = false; } if ($scope.card.productlist.length > 0) { addproflg = false; } if ($scope.card.iur1list.length > 0) { addiur1flg = false; } if ($scope.card.iur2list.length > 0) { addiur2flg = false; } if ($scope.card.calendarlist.length > 0) { addyearprojectflg = false; } deletememberids = ModelService.getDeleteMemberIds(); deletethemeids = ModelService.getDeleteThemeIds(); deleteproductids = ModelService.getDeleteProductIds(); deleteiur1ids = ModelService.getDeleteIur1Ids(); deleteiur2ids = ModelService.getDeleteIur2Ids(); deleteyearprojectids = ModelService.getDeleteYearProjectIds(); } // console.log($scope.card); //添加人员 $scope.addPerson = function () { $scope.card.personlist.push(angular.copy(person)); }; //添加主题 $scope.addTheme = function () { $scope.card.themelist.push(angular.copy(theme)); }; //添加产品 $scope.addProduct = function () { $scope.card.productlist.push(angular.copy(product)); }; //添加产学研 $scope.addProductStudy = function () { $scope.card.iur1list.push(angular.copy(iur1)); }; //添加重大科研项目 $scope.addProject = function () { $scope.card.iur2list.push(angular.copy(iur2)); }; //添加历年申报项目 $scope.addYearProject = function () { $timeout(function () { $scope.card.calendarlist.push(angular.copy(yearproject)); },300); }; //保存或修改 卡片 $scope.addCard = function () { // console.log($scope.card); if (!UtilService.isDefined($scope.card.name)) { UtilService.showMess("单位名称不能为空"); return; } //有人员信息且有手机信息,验证手机号 if ($scope.card.personlist.length > 0) { var pflg = -1;//第几个人员的姓名未填写 var perdel = [];//需要删除人员的索引数组 var tflg = -1;//第几个人员的手机格式错误 //判断人员是否必填(其他信息均未填写,姓名也未填写则删除该条人员;若其他信息有一项填写,判断姓名不能为空) var perindex = $scope.card.personlist.length - 1; var templist1 = angular.copy($scope.card.personlist); for (var i = perindex; i >= 0; i--) { if (UtilService.isDefined(templist1[i].phone) || UtilService.isDefined(templist1[i].email) || UtilService.isDefined(templist1[i].rank) || templist1[i].categoryid != 0 || UtilService.isDefined(templist1[i].introduce)) { if (!UtilService.isDefined(templist1[i].contact)) { pflg = i; } } else { if (!UtilService.isDefined(templist1[i].contact)) { perdel.push(i); } } if (UtilService.isDefined(templist1[i].phone)) { if (!(UtilService.isMobilePhone(templist1[i].phone) || UtilService.isTelePhone(templist1[i].phone))) { tflg = index; } } } if (pflg != -1) { UtilService.showMess('第' + (pflg + 1) + '个人员姓名不能为空'); return; } if (tflg != -1) { UtilService.showMess('人员"' + $scope.card.personlist[tflg].contact + '"的手机输入有误'); return; } //存在均未填写的,删除--> if (pflg == -1) { angular.forEach(perdel, function (value) { $scope.card.personlist.splice(value, 1); }); } } // console.log($scope.card.personlist); //有主题信息 if ($scope.card.themelist.length > 0) { var hflg = -1;//第几个主题名称未填写 var thedel = [];//需要删除主题的索引数组 //判断主题名称是否必填(其他信息均未填写,主题名称也未填写则删除该条主题;若其他信息有一项填写,判断主题名称不能为空) var theindex = $scope.card.themelist.length - 1; var templist2 = angular.copy($scope.card.themelist); for (var j = theindex; j >= 0; j--) { if (UtilService.isDefined(templist2[j].title) || UtilService.isDefined(templist2[j].content) || templist2[j].type != 0) { if (!UtilService.isDefined(templist2[j].title)) { hflg = j; } } else { if (!UtilService.isDefined(templist2[j].title)) { thedel.push(j); } } } if (hflg != -1) { UtilService.showMess('第' + (hflg + 1) + '个主题名称不能为空'); return; } //存在均未填写的,删除--> if (hflg == -1) { angular.forEach(thedel, function (value) { $scope.card.themelist.splice(value, 1); }); } } //有产品信息 if ($scope.card.productlist.length > 0) { var proflg = -1;//第几个产品名称未填写 var prodel = [];//需要删除产品的索引数组 //判断产品名称是否必填(其他信息均未填写,产品名称也未填写则删除该条产品;若其他信息有一项填写,判断产品名称不能为空) var proindex = $scope.card.productlist.length - 1; var templist3 = angular.copy($scope.card.productlist); for (var k = proindex; k >= 0; k--) { if (UtilService.isDefined(templist3[k].productname) || UtilService.isDefined(templist3[k].productdescription)) { if (!UtilService.isDefined(templist3[k].productname)) { proflg = k; } } else { if (!UtilService.isDefined(templist3[k].productname)) { prodel.push(k); } } } if (proflg != -1) { UtilService.showMess('第' + (proflg + 1) + '个产品名称不能为空'); return; } //存在均未填写的,删除--> if (proflg == -1) { angular.forEach(prodel, function (value) { $scope.card.productlist.splice(value, 1); }); } } //有产学研经历信息 if ($scope.card.iur1list.length > 0) { var iur1flg = -1;//第几个产学研经历的合作单位未填写 var iur1del = [];//需要删除产学研经历的索引数组 //判断产学研经历的合作单位是否必填(其他信息均未填写,产学研经历的合作单位也未填写则删除该条产学研经历;若其他信息有一项填写,判断产学研经历的合作单位不能为空) var iur1index = $scope.card.iur1list.length - 1; var templist4 = angular.copy($scope.card.iur1list); for (var k = iur1index; k >= 0; k--) { if (UtilService.isDefined(templist4[k].cooperateschool) || UtilService.isDefined(templist4[k].cooperatedetail)) { if (!UtilService.isDefined(templist4[k].cooperateschool)) { iur1flg = k; } } else { if (!UtilService.isDefined(templist4[k].cooperateschool)) { iur1del.push(k); } } } if (iur1flg != -1) { UtilService.showMess('第' + (iur1flg + 1) + '个产学研经历的合作单位不能为空'); return; } //存在均未填写的,删除--> if (iur1flg == -1) { angular.forEach(iur1del, function (value) { $scope.card.iur1list.splice(value, 1); }); } } //有产学研经历信息 if ($scope.card.iur2list.length > 0) { var iur2flg = -1;//第几个重大科研项目名称未填写 var iur2del = [];//需要删除重大科研项目的索引数组 //判断重大科研项目名称是否必填(其他信息均未填写,重大科研项目名称也未填写则删除该条重大科研项目;若其他信息有一项填写,判断重大科研项目名称不能为空) var iur2index = $scope.card.iur2list.length - 1; var templist5 = angular.copy($scope.card.iur2list); for (var k = iur2index; k >= 0; k--) { if (UtilService.isDefined(templist5[k].productname) || UtilService.isDefined(templist5[k].productyear)) { if (!UtilService.isDefined(templist5[k].productname)) { iur2flg = k; } } else { if (!UtilService.isDefined(templist5[k].productname)) { iur2del.push(k); } } } if (iur2flg != -1) { UtilService.showMess('第' + (iur2flg + 1) + '个重大科研项目名称不能为空'); return; } //存在均未填写的,删除--> if (iur2flg == -1) { angular.forEach(iur2del, function (value) { $scope.card.iur2list.splice(value, 1); }); } } //有历年申报项目信息 if ($scope.card.calendarlist.length > 0) { var calendarflg = -1;//第几个历年申报项目名称未填写 var calendardel = [];//需要删除历年申报项目的索引数组 //判断历年申报项目名称是否必填(其他信息均未填写,历年申报项目名称也未填写则删除该条历年申报项目;若其他信息有一项填写,判断历年申报项目名称不能为空) var calendarindex = $scope.card.calendarlist.length - 1; var templist6 = angular.copy($scope.card.calendarlist); for (var k = calendarindex; k >= 0; k--) { if (UtilService.isDefined(templist6[k].year) || UtilService.isDefined(templist6[k].money) || UtilService.isDefined(templist6[k].description)) { if (!UtilService.isDefined(templist6[k].name)) { calendarflg = k; } } else { if (!UtilService.isDefined(templist6[k].name)) { calendardel.push(k); } } } if (calendarflg != -1) { UtilService.showMess('第' + (calendarflg + 1) + '个历年申报项目名称不能为空'); return; } //存在均未填写的,删除--> if (calendarflg == -1) { angular.forEach(calendardel, function (value) { $scope.card.calendarlist.splice(value, 1); }); } } //区分修改还是新增 if (index == -1) { ModelService.addCardList($scope.card); } else { if ($scope.card.synchrotype != 1) { $scope.card.synchrotype = 2; } ModelService.setCardListByIndex(index, $scope.card); ModelService.setDeleteMemberIds(deletememberids); ModelService.setDeleteThemeIds(deletethemeids); ModelService.setDeleteProductIds(deleteproductids); ModelService.setDeleteIur1Ids(deleteiur1ids); ModelService.setDeleteIur2Ids(deleteiur2ids); ModelService.setDeleteYearProjectIds(deleteyearprojectids); } $scope.goback(); }; //展开/收起 单位信息 $scope.UnitInfotoggleDiv = function () { $(".UnitInfo").fadeToggle(0); $(".UnitInfoEm").toggleClass("arrowChange"); }; //展开/收起 人员信息 $scope.PersonnelInfotoggleDiv = function () { //是否有人员信息 if (addperflg) { $scope.card.personlist.push(angular.copy(person)); addperflg = false; } $(".PersonnelInfo").fadeToggle(0); $(".PersonnelInfoEm").toggleClass("arrowChange"); }; //展开/收起 主题 $scope.DockingThemetoggleDiv = function () { //是否有主题信息 if (addtheflg) { $scope.card.themelist.push(angular.copy(theme)); addtheflg = false; } $(".DockingTheme").fadeToggle(0); $(".DockingThemeEm").toggleClass("arrowChange"); }; //展开/收起 产品 $scope.ProductNametoggleDiv = function () { //是否有产品信息 if (addproflg) { $scope.card.productlist.push(angular.copy(product)); addproflg = false; } $(".ProductName").fadeToggle(0); $(".ProductNameEm").toggleClass("arrowChange"); }; //展开/收起 产学研究经历 $scope.ProductStudytoggleDiv = function () { //是否有产学研究经历信息 if (addiur1flg) { $scope.card.iur1list.push(angular.copy(iur1)); addiur1flg = false; } $(".ProductStudy").fadeToggle(0); $(".ProductStudyEm").toggleClass("arrowChange"); }; //展开/收起 重大科研项目 $scope.ImportantSciencetoggleDiv = function () { //是否有重大科研项目信息 if (addiur2flg) { $scope.card.iur2list.push(angular.copy(iur2)); addiur2flg = false; } $(".ImportantScience").fadeToggle(0); $(".ImportantScienceEm").toggleClass("arrowChange"); }; //展开/收起 历年申报项目 $scope.yearProjectToggleDiv = function () { $timeout(function () { //是否有历年申报项目信息 if (addyearprojectflg) { $scope.card.calendarlist.push(angular.copy(yearproject)); addyearprojectflg = false; } $(".yearproject").fadeToggle(0); $(".yearprojectEm").toggleClass("arrowChange"); },300); }; //打开通讯录 $scope.getContact = function (ind) { navigator.contacts.pickContact(function (contact) { // console.log(contact); var name = ""; if (device.platform == "Android") { name = contact.displayName; } else { name = contact.name.formatted; } $scope.card.personlist[ind].contact = name; var tempdate = UtilService.formatDate(); var templocalid = tempdate.timestamp + ""; //判断人员联系方式个数,大于1弹窗选择 if (angular.isDefined(contact.phoneNumbers) && contact.phoneNumbers.length > 1) { var buttons = []; angular.forEach(contact.phoneNumbers, function (data) { buttons.push({text: '' + data.value + ''}) }); $ionicActionSheet.show({ buttons: buttons, cancelText: '取消', buttonClicked: function (index) { var str = $scope.card.personlist[ind].phone = contact.phoneNumbers[index].value.replace(/\s/g, ""); return true; } }); } else { var str = contact.phoneNumbers[0].value.replace(/\s/g, ""); $scope.$apply(function () { $scope.card.personlist[ind].phone = str; }); } }, function (err) { }); }; //单位行业 $scope.showCategory = function (boo, ind) { $ionicActionSheet.show({ buttons: [ {text: '汽车制造'}, {text: '能源及节能技术'}, {text: '新材料'}, {text: '生物与新医药'}, {text: '电子信息'}, {text: '先进制造及高端装备'}, {text: '资源及环境技术'} ], cancelText: '取消', buttonClicked: function (index) { if (boo) { $scope.card.categoryid = index + 1; } else { $scope.card.personlist[ind].categoryid = index + 1; } return true; } }); }; //单位类型 $scope.showCompanyType = function () { $ionicActionSheet.show({ buttons: [ {text: '高校'}, {text: '企业'}, {text: '机构'}, {text: '园区'}, {text: '政府'}, {text: '其他'} ], cancelText: '取消', buttonClicked: function (index) { $scope.card.type = 5 - index; return true; } }); }; //主题类型 $scope.showThemeType = function (ind) { $ionicActionSheet.show({ buttons: [ {text: '需求'}, {text: '成果'}, {text: '服务'}, {text: '其他'} ], cancelText: '取消', buttonClicked: function (index) { $scope.card.themelist[ind].type = index + 1; return true; } }); }; //人员信息中删除已新增名片 $scope.cardListDelect = function (index) { //组装有id的已删除人员 if (UtilService.isDefined($scope.card.personlist[index].id)) { if (deletememberids.length == 0) { deletememberids = $scope.card.personlist[index].id; } else { deletememberids = deletememberids + "," + $scope.card.personlist[index].id; } } $scope.card.personlist.splice(index, 1); }; //对接主题中中删除已新增名片 $scope.cardThemeListDelect = function (index) { //组装有id的已删除主题 if (UtilService.isDefined($scope.card.themelist[index].id)) { if (deletethemeids.length == 0) { deletethemeids = $scope.card.themelist[index].id; } else { deletethemeids = deletethemeids + "," + $scope.card.themelist[index].id; } } $scope.card.themelist.splice(index, 1); }; //产品中删除已新增名片 $scope.cardProductListDelect = function (index) { //组装有id的已删除主题 if (UtilService.isDefined($scope.card.productlist[index].id)) { if (deleteproductids.length == 0) { deleteproductids = $scope.card.productlist[index].id; } else { deleteproductids = deleteproductids + "," + $scope.card.productlist[index].id; } } $scope.card.productlist.splice(index, 1); }; //产学研中删除已新增名片 $scope.cardProductStudyListDelect = function (index) { //组装有id的已删除主题 if (UtilService.isDefined($scope.card.iur1list[index].id)) { if (deleteiur1ids.length == 0) { deleteiur1ids = $scope.card.iur1list[index].id; } else { deleteiur1ids = deleteiur1ids + "," + $scope.card.iur1list[index].id; } } $scope.card.iur1list.splice(index, 1); }; //重大科研项目中删除已新增名片 $scope.cardProjectListDelect = function (index) { //组装有id的已删除主题 if (UtilService.isDefined($scope.card.iur2list[index].id)) { if (deleteiur2ids.length == 0) { deleteiur2ids = $scope.card.iur2list[index].id; } else { deleteiur2ids = deleteiur2ids + "," + $scope.card.iur2list[index].id; } } $scope.card.iur2list.splice(index, 1); }; //历年申报项目中删除已新增名片 $scope.cardYearProjectListDelete = function (index) { //组装有id的已删除主题 if (UtilService.isDefined($scope.card.calendarlist[index].id)) { if (deleteyearprojectids.length == 0) { deleteyearprojectids = $scope.card.calendarlist[index].id; } else { deleteyearprojectids = deleteyearprojectids + "," + $scope.card.calendarlist[index].id; } } $scope.card.calendarlist.splice(index, 1); }; //关联相关企业 $scope.isRelateUl = false; $scope.queryLikeName = function () { if ($scope.card.name.length == 0) { $scope.companylist = []; $scope.isRelateUl = false; return; } DockingService.getCampanyListByName($scope.card.name).then(function (response) { // console.log(response); $scope.companylist = response.companylist; $scope.isRelateUl = true; }, function () { }) }; //选中企业 $scope.setCompanyName = function (name) { name = name.replace("", ""); name = name.replace("", ""); $scope.card.name = name; $scope.isRelateUl = false; }; $scope.years = []; $scope.currentyear = new Date().getFullYear();//当前年份 var startYear = $scope.currentyear - 50; //开始年份 for (var i = $scope.currentyear; i >= startYear; i--) { $scope.years.push(i); } });