123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- angular.module('push')
- .controller('addListCardCtrl', 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 index = $stateParams.index;
- if (index == -1) {
- $scope.card = {
- name: "",
- categoryid: 0,
- categorydetail: "",
- type: -1,
- address: "",
- presentation: "",
- synchrotype: 1,
- creator: UserService.id,
- creatorcomefrom: ConfigService.comefrom,
- 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;
- }
- }
- // 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 {
- ModelService.setCardListByIndex(index, $scope.card);
- }
- $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: '<a class="action-sheet-push ">' + data.value + '</a>'})
- });
- $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: '<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) {
- if (boo) {
- $scope.card.categoryid = index + 1;
- } else {
- $scope.card.personlist[ind].categoryid = index + 1;
- }
- return true;
- }
- });
- };
- //单位类型
- $scope.showCompanyType = 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.card.type = 5 - index;
- return true;
- }
- });
- };
- //主题类型
- $scope.showThemeType = function (ind) {
- $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>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.card.themelist[ind].type = index + 1;
- return true;
- }
- });
- };
- //人员信息中删除已新增名片
- $scope.cardListDelect = function (index) {
- $scope.card.personlist.splice(index, 1);
- };
- //对接主题中中删除已新增名片
- $scope.cardThemeListDelect = function (index) {
- $scope.card.themelist.splice(index, 1);
- };
- //产品中删除已新增名片
- $scope.cardProductListDelect = function (index) {
- $scope.card.productlist.splice(index, 1);
- };
- //产学研中删除已新增名片
- $scope.cardProductStudyListDelect = function (index) {
- $scope.card.iur1list.splice(index, 1);
- };
- //重大科研项目中删除已新增名片
- $scope.cardProjectListDelect = function (index) {
- $scope.card.iur2list.splice(index, 1);
- };
- //历年申报项目中删除已新增名片
- $scope.cardYearProjectListDelete = function (index) {
- $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) {
- //<b style='color:red;font-weight: normal;'>亚</b>
- name = name.replace("<b style='color:red;font-weight: normal;'>", "");
- name = name.replace("</b>", "");
- $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);
- }
- });
|