addListCardCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. angular.module('push')
  2. .controller('addListCardCtrl', function ($scope, $stateParams, ModelService, $ionicActionSheet, UtilService, UserService, ConfigService, DockingService, $timeout) {
  3. //空人员信息
  4. var person = {
  5. infoid: 0,
  6. contact: "",
  7. phone: "",
  8. email: "",
  9. rank: "",
  10. categoryid: 0,
  11. introduce: ""
  12. };
  13. //空主题信息
  14. var theme = {
  15. infoid: 0,
  16. type: 0,
  17. title: "",
  18. content: ""
  19. };
  20. //空产品信息
  21. var product = {
  22. infoid: 0,
  23. productname: "",
  24. productdescription: ""
  25. };
  26. //空产学研经历
  27. var iur1 = {
  28. infoid: 0,
  29. cooperateschool: "",
  30. cooperatedetail: ""
  31. };
  32. //空重大科研项目
  33. var iur2 = {
  34. infoid: 0,
  35. productname: "",
  36. productyear: ""
  37. };
  38. //空历年申报项目
  39. var yearproject = {
  40. year: "",
  41. name: "",
  42. money: "",
  43. description: ""
  44. };
  45. var addperflg = true;
  46. var addtheflg = true;
  47. var addproflg = true;
  48. var addiur1flg = true;
  49. var addiur2flg = true;
  50. var addyearprojectflg = true;
  51. //编辑或新增 卡片
  52. var index = $stateParams.index;
  53. if (index == -1) {
  54. $scope.card = {
  55. name: "",
  56. categoryid: 0,
  57. categorydetail: "",
  58. type: -1,
  59. address: "",
  60. presentation: "",
  61. synchrotype: 1,
  62. creator: UserService.id,
  63. creatorcomefrom: ConfigService.comefrom,
  64. personlist: [],
  65. themelist: [],
  66. productlist: [],
  67. iur1list: [],
  68. iur2list: [],
  69. calendarlist:[]
  70. };
  71. } else {
  72. $scope.card = angular.copy(ModelService.getCardList()[index]);
  73. if ($scope.card.personlist.length > 0) {
  74. addperflg = false;
  75. }
  76. if ($scope.card.themelist.length > 0) {
  77. addtheflg = false;
  78. }
  79. if ($scope.card.productlist.length > 0) {
  80. addproflg = false;
  81. }
  82. if ($scope.card.iur1list.length > 0) {
  83. addiur1flg = false;
  84. }
  85. if ($scope.card.iur2list.length > 0) {
  86. addiur2flg = false;
  87. }
  88. if ($scope.card.calendarlist.length > 0) {
  89. addyearprojectflg = false;
  90. }
  91. }
  92. // console.log($scope.card);
  93. //添加人员
  94. $scope.addPerson = function () {
  95. $scope.card.personlist.push(angular.copy(person));
  96. };
  97. //添加主题
  98. $scope.addTheme = function () {
  99. $scope.card.themelist.push(angular.copy(theme));
  100. };
  101. //添加产品
  102. $scope.addProduct = function () {
  103. $scope.card.productlist.push(angular.copy(product));
  104. };
  105. //添加产学研
  106. $scope.addProductStudy = function () {
  107. $scope.card.iur1list.push(angular.copy(iur1));
  108. };
  109. //添加重大科研项目
  110. $scope.addProject = function () {
  111. $scope.card.iur2list.push(angular.copy(iur2));
  112. };
  113. //添加历年申报项目
  114. $scope.addYearProject = function () {
  115. $timeout(function () {
  116. $scope.card.calendarlist.push(angular.copy(yearproject));
  117. },300);
  118. };
  119. //保存或修改 卡片
  120. $scope.addCard = function () {
  121. // console.log($scope.card);
  122. if (!UtilService.isDefined($scope.card.name)) {
  123. UtilService.showMess("单位名称不能为空");
  124. return;
  125. }
  126. //有人员信息且有手机信息,验证手机号
  127. if ($scope.card.personlist.length > 0) {
  128. var pflg = -1;//第几个人员的姓名未填写
  129. var perdel = [];//需要删除人员的索引数组
  130. var tflg = -1;//第几个人员的手机格式错误
  131. //判断人员是否必填(其他信息均未填写,姓名也未填写则删除该条人员;若其他信息有一项填写,判断姓名不能为空)
  132. var perindex = $scope.card.personlist.length - 1;
  133. var templist1 = angular.copy($scope.card.personlist);
  134. for (var i = perindex; i >= 0; i--) {
  135. 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)) {
  136. if (!UtilService.isDefined(templist1[i].contact)) {
  137. pflg = i;
  138. }
  139. } else {
  140. if (!UtilService.isDefined(templist1[i].contact)) {
  141. perdel.push(i);
  142. }
  143. }
  144. if (UtilService.isDefined(templist1[i].phone)) {
  145. if (!(UtilService.isMobilePhone(templist1[i].phone) || UtilService.isTelePhone(templist1[i].phone))) {
  146. tflg = index;
  147. }
  148. }
  149. }
  150. if (pflg != -1) {
  151. UtilService.showMess('第' + (pflg + 1) + '个人员姓名不能为空');
  152. return;
  153. }
  154. if (tflg != -1) {
  155. UtilService.showMess('人员"' + $scope.card.personlist[tflg].contact + '"的手机输入有误');
  156. return;
  157. }
  158. //存在均未填写的,删除-->
  159. if (pflg == -1) {
  160. angular.forEach(perdel, function (value) {
  161. $scope.card.personlist.splice(value, 1);
  162. });
  163. }
  164. }
  165. // console.log($scope.card.personlist);
  166. //有主题信息
  167. if ($scope.card.themelist.length > 0) {
  168. var hflg = -1;//第几个主题名称未填写
  169. var thedel = [];//需要删除主题的索引数组
  170. //判断主题名称是否必填(其他信息均未填写,主题名称也未填写则删除该条主题;若其他信息有一项填写,判断主题名称不能为空)
  171. var theindex = $scope.card.themelist.length - 1;
  172. var templist2 = angular.copy($scope.card.themelist);
  173. for (var j = theindex; j >= 0; j--) {
  174. if (UtilService.isDefined(templist2[j].title) || UtilService.isDefined(templist2[j].content) || templist2[j].type != 0) {
  175. if (!UtilService.isDefined(templist2[j].title)) {
  176. hflg = j;
  177. }
  178. } else {
  179. if (!UtilService.isDefined(templist2[j].title)) {
  180. thedel.push(j);
  181. }
  182. }
  183. }
  184. if (hflg != -1) {
  185. UtilService.showMess('第' + (hflg + 1) + '个主题名称不能为空');
  186. return;
  187. }
  188. //存在均未填写的,删除-->
  189. if (hflg == -1) {
  190. angular.forEach(thedel, function (value) {
  191. $scope.card.themelist.splice(value, 1);
  192. });
  193. }
  194. }
  195. //有产品信息
  196. if ($scope.card.productlist.length > 0) {
  197. var proflg = -1;//第几个产品名称未填写
  198. var prodel = [];//需要删除产品的索引数组
  199. //判断产品名称是否必填(其他信息均未填写,产品名称也未填写则删除该条产品;若其他信息有一项填写,判断产品名称不能为空)
  200. var proindex = $scope.card.productlist.length - 1;
  201. var templist3 = angular.copy($scope.card.productlist);
  202. for (var k = proindex; k >= 0; k--) {
  203. if (UtilService.isDefined(templist3[k].productname) || UtilService.isDefined(templist3[k].productdescription)) {
  204. if (!UtilService.isDefined(templist3[k].productname)) {
  205. proflg = k;
  206. }
  207. } else {
  208. if (!UtilService.isDefined(templist3[k].productname)) {
  209. prodel.push(k);
  210. }
  211. }
  212. }
  213. if (proflg != -1) {
  214. UtilService.showMess('第' + (proflg + 1) + '个产品名称不能为空');
  215. return;
  216. }
  217. //存在均未填写的,删除-->
  218. if (proflg == -1) {
  219. angular.forEach(prodel, function (value) {
  220. $scope.card.productlist.splice(value, 1);
  221. });
  222. }
  223. }
  224. //有产学研经历信息
  225. if ($scope.card.iur1list.length > 0) {
  226. var iur1flg = -1;//第几个产学研经历的合作单位未填写
  227. var iur1del = [];//需要删除产学研经历的索引数组
  228. //判断产学研经历的合作单位是否必填(其他信息均未填写,产学研经历的合作单位也未填写则删除该条产学研经历;若其他信息有一项填写,判断产学研经历的合作单位不能为空)
  229. var iur1index = $scope.card.iur1list.length - 1;
  230. var templist4 = angular.copy($scope.card.iur1list);
  231. for (var k = iur1index; k >= 0; k--) {
  232. if (UtilService.isDefined(templist4[k].cooperateschool) || UtilService.isDefined(templist4[k].cooperatedetail)) {
  233. if (!UtilService.isDefined(templist4[k].cooperateschool)) {
  234. iur1flg = k;
  235. }
  236. } else {
  237. if (!UtilService.isDefined(templist4[k].cooperateschool)) {
  238. iur1del.push(k);
  239. }
  240. }
  241. }
  242. if (iur1flg != -1) {
  243. UtilService.showMess('第' + (iur1flg + 1) + '个产学研经历的合作单位不能为空');
  244. return;
  245. }
  246. //存在均未填写的,删除-->
  247. if (iur1flg == -1) {
  248. angular.forEach(iur1del, function (value) {
  249. $scope.card.iur1list.splice(value, 1);
  250. });
  251. }
  252. }
  253. //有重大科研项目信息
  254. if ($scope.card.iur2list.length > 0) {
  255. var iur2flg = -1;//第几个重大科研项目名称未填写
  256. var iur2del = [];//需要删除重大科研项目的索引数组
  257. //判断重大科研项目名称是否必填(其他信息均未填写,重大科研项目名称也未填写则删除该条重大科研项目;若其他信息有一项填写,判断重大科研项目名称不能为空)
  258. var iur2index = $scope.card.iur2list.length - 1;
  259. var templist5 = angular.copy($scope.card.iur2list);
  260. for (var k = iur2index; k >= 0; k--) {
  261. if (UtilService.isDefined(templist5[k].productname) || UtilService.isDefined(templist5[k].productyear)) {
  262. if (!UtilService.isDefined(templist5[k].productname)) {
  263. iur2flg = k;
  264. }
  265. } else {
  266. if (!UtilService.isDefined(templist5[k].productname)) {
  267. iur2del.push(k);
  268. }
  269. }
  270. }
  271. if (iur2flg != -1) {
  272. UtilService.showMess('第' + (iur2flg + 1) + '个重大科研项目名称不能为空');
  273. return;
  274. }
  275. //存在均未填写的,删除-->
  276. if (iur2flg == -1) {
  277. angular.forEach(iur2del, function (value) {
  278. $scope.card.iur2list.splice(value, 1);
  279. });
  280. }
  281. }
  282. //有历年申报项目信息
  283. if ($scope.card.calendarlist.length > 0) {
  284. var calendarflg = -1;//第几个历年申报项目名称未填写
  285. var calendardel = [];//需要删除历年申报项目的索引数组
  286. //判断历年申报项目名称是否必填(其他信息均未填写,历年申报项目名称也未填写则删除该条历年申报项目;若其他信息有一项填写,判断历年申报项目名称不能为空)
  287. var calendarindex = $scope.card.calendarlist.length - 1;
  288. var templist6 = angular.copy($scope.card.calendarlist);
  289. for (var k = calendarindex; k >= 0; k--) {
  290. if (UtilService.isDefined(templist6[k].year) || UtilService.isDefined(templist6[k].money) || UtilService.isDefined(templist6[k].description)) {
  291. if (!UtilService.isDefined(templist6[k].name)) {
  292. calendarflg = k;
  293. }
  294. } else {
  295. if (!UtilService.isDefined(templist6[k].name)) {
  296. calendardel.push(k);
  297. }
  298. }
  299. }
  300. if (calendarflg != -1) {
  301. UtilService.showMess('第' + (calendarflg + 1) + '个历年申报项目名称不能为空');
  302. return;
  303. }
  304. //存在均未填写的,删除-->
  305. if (calendarflg == -1) {
  306. angular.forEach(calendardel, function (value) {
  307. $scope.card.calendarlist.splice(value, 1);
  308. });
  309. }
  310. }
  311. //区分修改还是新增
  312. if (index == -1) {
  313. ModelService.addCardList($scope.card);
  314. } else {
  315. ModelService.setCardListByIndex(index, $scope.card);
  316. }
  317. $scope.goback();
  318. };
  319. //展开/收起 单位信息
  320. $scope.UnitInfotoggleDiv = function () {
  321. $(".UnitInfo").fadeToggle(0);
  322. $(".UnitInfoEm").toggleClass("arrowChange");
  323. };
  324. //展开/收起 人员信息
  325. $scope.PersonnelInfotoggleDiv = function () {
  326. //是否有人员信息
  327. if (addperflg) {
  328. $scope.card.personlist.push(angular.copy(person));
  329. addperflg = false;
  330. }
  331. $(".PersonnelInfo").fadeToggle(0);
  332. $(".PersonnelInfoEm").toggleClass("arrowChange");
  333. };
  334. //展开/收起 主题
  335. $scope.DockingThemetoggleDiv = function () {
  336. //是否有主题信息
  337. if (addtheflg) {
  338. $scope.card.themelist.push(angular.copy(theme));
  339. addtheflg = false;
  340. }
  341. $(".DockingTheme").fadeToggle(0);
  342. $(".DockingThemeEm").toggleClass("arrowChange");
  343. };
  344. //展开/收起 产品
  345. $scope.ProductNametoggleDiv = function () {
  346. //是否有产品信息
  347. if (addproflg) {
  348. $scope.card.productlist.push(angular.copy(product));
  349. addproflg = false;
  350. }
  351. $(".ProductName").fadeToggle(0);
  352. $(".ProductNameEm").toggleClass("arrowChange");
  353. };
  354. //展开/收起 产学研究经历
  355. $scope.ProductStudytoggleDiv = function () {
  356. //是否有产学研究经历信息
  357. if (addiur1flg) {
  358. $scope.card.iur1list.push(angular.copy(iur1));
  359. addiur1flg = false;
  360. }
  361. $(".ProductStudy").fadeToggle(0);
  362. $(".ProductStudyEm").toggleClass("arrowChange");
  363. };
  364. //展开/收起 重大科研项目
  365. $scope.ImportantSciencetoggleDiv = function () {
  366. //是否有重大科研项目信息
  367. if (addiur2flg) {
  368. $scope.card.iur2list.push(angular.copy(iur2));
  369. addiur2flg = false;
  370. }
  371. $(".ImportantScience").fadeToggle(0);
  372. $(".ImportantScienceEm").toggleClass("arrowChange");
  373. };
  374. //展开/收起 历年申报项目
  375. $scope.yearProjectToggleDiv = function () {
  376. $timeout(function () {
  377. //是否有历年申报项目信息
  378. if (addyearprojectflg) {
  379. $scope.card.calendarlist.push(angular.copy(yearproject));
  380. addyearprojectflg = false;
  381. }
  382. $(".yearproject").fadeToggle(0);
  383. $(".yearprojectEm").toggleClass("arrowChange");
  384. },300);
  385. };
  386. //打开通讯录
  387. $scope.getContact = function (ind) {
  388. navigator.contacts.pickContact(function (contact) {
  389. // console.log(contact);
  390. var name = "";
  391. if (device.platform == "Android") {
  392. name = contact.displayName;
  393. } else {
  394. name = contact.name.formatted;
  395. }
  396. $scope.card.personlist[ind].contact = name;
  397. var tempdate = UtilService.formatDate();
  398. var templocalid = tempdate.timestamp + "";
  399. //判断人员联系方式个数,大于1弹窗选择
  400. if (angular.isDefined(contact.phoneNumbers) && contact.phoneNumbers.length > 1) {
  401. var buttons = [];
  402. angular.forEach(contact.phoneNumbers, function (data) {
  403. buttons.push({text: '<a class="action-sheet-push ">' + data.value + '</a>'})
  404. });
  405. $ionicActionSheet.show({
  406. buttons: buttons,
  407. cancelText: '取消',
  408. buttonClicked: function (index) {
  409. var str =
  410. $scope.card.personlist[ind].phone = contact.phoneNumbers[index].value.replace(/\s/g, "");
  411. return true;
  412. }
  413. });
  414. } else {
  415. var str = contact.phoneNumbers[0].value.replace(/\s/g, "");
  416. $scope.$apply(function () {
  417. $scope.card.personlist[ind].phone = str;
  418. });
  419. }
  420. }, function (err) {
  421. });
  422. };
  423. //单位行业
  424. $scope.showCategory = function (boo, ind) {
  425. $ionicActionSheet.show({
  426. buttons: [
  427. {text: '<a class="action-sheet-push">汽车制造</a>'},
  428. {text: '<a class="action-sheet-push">能源及节能技术</a>'},
  429. {text: '<a class="action-sheet-push">新材料</a>'},
  430. {text: '<a class="action-sheet-push">生物与新医药</a>'},
  431. {text: '<a class="action-sheet-push">电子信息</a>'},
  432. {text: '<a class="action-sheet-push">先进制造及高端装备</a>'},
  433. {text: '<a class="action-sheet-push">资源及环境技术</a>'}
  434. ],
  435. cancelText: '取消',
  436. buttonClicked: function (index) {
  437. if (boo) {
  438. $scope.card.categoryid = index + 1;
  439. } else {
  440. $scope.card.personlist[ind].categoryid = index + 1;
  441. }
  442. return true;
  443. }
  444. });
  445. };
  446. //单位类型
  447. $scope.showCompanyType = function () {
  448. $ionicActionSheet.show({
  449. buttons: [
  450. {text: '<a class="action-sheet-push">高校</a>'},
  451. {text: '<a class="action-sheet-push">企业</a>'},
  452. {text: '<a class="action-sheet-push">机构</a>'},
  453. {text: '<a class="action-sheet-push">园区</a>'},
  454. {text: '<a class="action-sheet-push">政府</a>'},
  455. {text: '<a class="action-sheet-push">其他</a>'}
  456. ],
  457. cancelText: '取消',
  458. buttonClicked: function (index) {
  459. $scope.card.type = 5 - index;
  460. return true;
  461. }
  462. });
  463. };
  464. //主题类型
  465. $scope.showThemeType = function (ind) {
  466. $ionicActionSheet.show({
  467. buttons: [
  468. {text: '<a class="action-sheet-push">需求</a>'},
  469. {text: '<a class="action-sheet-push">成果</a>'},
  470. {text: '<a class="action-sheet-push">服务</a>'},
  471. {text: '<a class="action-sheet-push">其他</a>'}
  472. ],
  473. cancelText: '取消',
  474. buttonClicked: function (index) {
  475. $scope.card.themelist[ind].type = index + 1;
  476. return true;
  477. }
  478. });
  479. };
  480. //人员信息中删除已新增名片
  481. $scope.cardListDelect = function (index) {
  482. $scope.card.personlist.splice(index, 1);
  483. };
  484. //对接主题中中删除已新增名片
  485. $scope.cardThemeListDelect = function (index) {
  486. $scope.card.themelist.splice(index, 1);
  487. };
  488. //产品中删除已新增名片
  489. $scope.cardProductListDelect = function (index) {
  490. $scope.card.productlist.splice(index, 1);
  491. };
  492. //产学研中删除已新增名片
  493. $scope.cardProductStudyListDelect = function (index) {
  494. $scope.card.iur1list.splice(index, 1);
  495. };
  496. //重大科研项目中删除已新增名片
  497. $scope.cardProjectListDelect = function (index) {
  498. $scope.card.iur2list.splice(index, 1);
  499. };
  500. //历年申报项目中删除已新增名片
  501. $scope.cardYearProjectListDelete = function (index) {
  502. $scope.card.calendarlist.splice(index, 1);
  503. };
  504. //关联相关企业
  505. $scope.isRelateUl = false;
  506. $scope.queryLikeName = function () {
  507. if ($scope.card.name.length == 0) {
  508. $scope.companylist = [];
  509. $scope.isRelateUl = false;
  510. return;
  511. }
  512. DockingService.getCampanyListByName($scope.card.name).then(function (response) {
  513. // console.log(response);
  514. $scope.companylist = response.companylist;
  515. $scope.isRelateUl = true;
  516. }, function () {
  517. })
  518. };
  519. //选中企业
  520. $scope.setCompanyName = function (name) {
  521. //<b style='color:red;font-weight: normal;'>亚</b>
  522. name = name.replace("<b style='color:red;font-weight: normal;'>", "");
  523. name = name.replace("</b>", "");
  524. $scope.card.name = name;
  525. $scope.isRelateUl = false;
  526. };
  527. $scope.years = [];
  528. $scope.currentyear = new Date().getFullYear();//当前年份
  529. var startYear = $scope.currentyear - 50; //开始年份
  530. for (var i = $scope.currentyear; i >= startYear; i--) {
  531. $scope.years.push(i);
  532. }
  533. });