std_base_info.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. app.controller('StdBaseInfoCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster, Upload) {
  2. if(!$rootScope.stdExamNoticeConfirmed){
  3. $rootScope.dialogMsg("请先确认诚信承诺书。", function(){});
  4. $state.go('examNotice');
  5. }
  6. }).controller('StdBaseInfoBasicCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster, $q) {
  7. $scope.load = function(){
  8. $scope.myPromise = $http({
  9. url : myConfig.url + '/acquire/baseInfo?session=' + $rootScope.session,
  10. method : 'GET'
  11. }).success(function(data) {
  12. if(data.code == 0){
  13. $rootScope.stdData = data.result;
  14. // if($rootScope.stdData && $rootScope.stdData.exam_id){
  15. // $rootScope.stdData.exam_id = $rootScope.stdData.exam_id.substr(2,12);
  16. // }
  17. }
  18. }).error(function() {
  19. });
  20. $scope.provinces = $rootScope.provinceAll;
  21. $scope.areas = $rootScope.areaAll;
  22. $scope.cities = $rootScope.cityAll;
  23. }
  24. $scope.load();
  25. $scope.submitForm = function(isValid) {
  26. var card = document.getElementById('cert_id').value;
  27. //是否为空
  28. if(card === '')
  29. {
  30. // alert('请输入身份证号,身份证号不能为空');
  31. document.getElementById('cert_id').focus();
  32. document.getElementById('cert_id_info').innerHTML = '<font color="#a94442">请输入身份证号,身份证号不能为空</font>';
  33. return false;
  34. }
  35. if(card == 'M856539(8)') {
  36. }else{
  37. //校验长度,类型
  38. if(isCardNo(card) === false || checkProvince(card) === false || checkBirthday(card) === false || checkParity(card) === false ||checkParity(card) === false)
  39. {
  40. //alert('您输入的身份证号码不正确,请重新输入');
  41. document.getElementById('cert_id').focus();
  42. document.getElementById('cert_id_info').innerHTML = '<font color="#a94442">您输入的身份证号码不正确,请重新输入</font>';
  43. return false;
  44. }
  45. }
  46. $scope.submitted = true
  47. // check to make sure the form is completely valid
  48. if (isValid) {
  49. // if($scope.stdData.exam_id.length == 12){
  50. // $scope.stdData.exam_id = '20' + $scope.stdData.exam_id;
  51. // }
  52. $scope.myPromise = $http({
  53. url : myConfig.url + '/acquire/baseInfo?session=' + $rootScope.session,
  54. method : 'POST',
  55. data : angular.toJson($scope.stdData)
  56. }).success(function(data) {
  57. if(data.code == 0){
  58. toaster.pop('success', '保存成功');
  59. // $scope.stdData.exam_id = $scope.stdData.exam_id.substr(2,12);
  60. $scope.form.$setPristine();
  61. }else{
  62. toaster.pop('error', data.message);
  63. }
  64. }).error(function() {
  65. $scope.load();
  66. });
  67. }
  68. };
  69. var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",
  70. 21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",
  71. 33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",
  72. 42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",
  73. 51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",
  74. 63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"
  75. };
  76. //检查号码是否符合规范,包括长度,类型
  77. isCardNo = function(card)
  78. {
  79. //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  80. var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
  81. if(reg.test(card) === false)
  82. {
  83. return false;
  84. }
  85. return true;
  86. };
  87. //取身份证前两位,校验省份
  88. checkProvince = function(card)
  89. {
  90. var province = card.substr(0,2);
  91. if(vcity[province] == undefined)
  92. {
  93. return false;
  94. }
  95. return true;
  96. };
  97. //检查生日是否正确
  98. checkBirthday = function(card)
  99. {
  100. var len = card.length;
  101. //身份证15位时,次序为省(3位)市(3位)年(2位)月(2位)日(2位)校验位(3位),皆为数字
  102. if(len == '15')
  103. {
  104. var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
  105. var arr_data = card.match(re_fifteen);
  106. var year = arr_data[2];
  107. var month = arr_data[3];
  108. var day = arr_data[4];
  109. var birthday = new Date('19'+year+'/'+month+'/'+day);
  110. return verifyBirthday('19'+year,month,day,birthday);
  111. }
  112. //身份证18位时,次序为省(3位)市(3位)年(4位)月(2位)日(2位)校验位(4位),校验位末尾可能为X
  113. if(len == '18')
  114. {
  115. var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
  116. var arr_data = card.match(re_eighteen);
  117. var year = arr_data[2];
  118. var month = arr_data[3];
  119. var day = arr_data[4];
  120. var birthday = new Date(year+'/'+month+'/'+day);
  121. return verifyBirthday(year,month,day,birthday);
  122. }
  123. return false;
  124. };
  125. //校验日期
  126. verifyBirthday = function(year,month,day,birthday)
  127. {
  128. var now = new Date();
  129. var now_year = now.getFullYear();
  130. //年月日是否合理
  131. if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day)
  132. {
  133. //判断年份的范围(3岁到100岁之间)
  134. var time = now_year - year;
  135. if(time >= 3 && time <= 100)
  136. {
  137. return true;
  138. }
  139. return false;
  140. }
  141. return false;
  142. };
  143. //校验位的检测
  144. checkParity = function(card)
  145. {
  146. //15位转18位
  147. card = changeFivteenToEighteen(card);
  148. var len = card.length;
  149. if(len == '18')
  150. {
  151. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  152. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  153. var cardTemp = 0, i, valnum;
  154. for(i = 0; i < 17; i ++)
  155. {
  156. cardTemp += card.substr(i, 1) * arrInt[i];
  157. }
  158. valnum = arrCh[cardTemp % 11];
  159. if (valnum == card.substr(17, 1))
  160. {
  161. return true;
  162. }
  163. return false;
  164. }
  165. return false;
  166. };
  167. //15位转18位身份证号
  168. changeFivteenToEighteen = function(card)
  169. {
  170. if(card.length == '15')
  171. {
  172. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  173. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  174. var cardTemp = 0, i;
  175. card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
  176. for(i = 0; i < 17; i ++)
  177. {
  178. cardTemp += card.substr(i, 1) * arrInt[i];
  179. }
  180. card += arrCh[cardTemp % 11];
  181. return card;
  182. }
  183. document.getElementById('cert_id_info').innerHTML = '';
  184. return card;
  185. };
  186. $scope.refreshArea = function(){
  187. $scope.stdData.area = null;
  188. $scope.stdData.city = null;
  189. $scope.myPromise = $http({
  190. url : myConfig.url + '/frame/area/' + $scope.stdData.province,
  191. method : 'GET'
  192. }).success(function(data) {
  193. if(data.code == 0){
  194. $scope.areas = data.result;
  195. }
  196. }).error(function() {
  197. });
  198. }
  199. $scope.refreshCity = function(){
  200. $scope.stdData.city = null;
  201. $scope.myPromise = $http({
  202. url : myConfig.url + '/frame/city/' + $scope.stdData.area,
  203. method : 'GET'
  204. }).success(function(data) {
  205. if(data.code == 0){
  206. $scope.cities = data.result;
  207. }
  208. }).error(function() {
  209. });
  210. }
  211. }).controller('StdBaseInfoContactCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster) {
  212. $scope.load = function(){
  213. $scope.myPromise = $http({
  214. url : myConfig.url + '/acquire/baseInfo?session=' + $rootScope.session,
  215. method : 'GET'
  216. }).success(function(data) {
  217. if(data.code == 0){
  218. $rootScope.stdData = data.result;
  219. // if($rootScope.stdData && $rootScope.stdData.exam_id){
  220. // $rootScope.stdData.exam_id = $rootScope.stdData.exam_id.substr(2,12);
  221. // }
  222. }
  223. }).error(function() {
  224. });
  225. $scope.provinces = $rootScope.provinceAll;
  226. $scope.home_areas = $rootScope.areaAll;
  227. $scope.home_cities = $rootScope.cityAll;
  228. $scope.mail_areas = $rootScope.areaAll;
  229. $scope.mail_cities = $rootScope.cityAll;
  230. }
  231. $scope.load();
  232. $scope.submitForm = function(isValid) {
  233. $scope.submitted = true
  234. // check to make sure the form is completely valid
  235. if (isValid) {
  236. $scope.myPromise = $http({
  237. url : myConfig.url + '/acquire/baseInfoContact?session=' + $rootScope.session,
  238. method : 'POST',
  239. data : angular.toJson($scope.stdData)
  240. }).success(function(data) {
  241. if(data.code == 0){
  242. toaster.pop('success', '保存成功');
  243. $scope.form.$setPristine();
  244. }else{
  245. toaster.pop('error', data.message);
  246. }
  247. }).error(function() {
  248. $scope.load();
  249. });
  250. }
  251. };
  252. $scope.refreshHomeArea = function(){
  253. $scope.stdData.home_area = null;
  254. $scope.stdData.home_city = null;
  255. $scope.myPromise = $http({
  256. url : myConfig.url + '/frame/area/' + $scope.stdData.home_province,
  257. method : 'GET'
  258. }).success(function(data) {
  259. if(data.code == 0){
  260. $scope.home_areas = data.result;
  261. }
  262. }).error(function() {
  263. });
  264. }
  265. $scope.refreshHomeCity = function(){
  266. $scope.stdData.home_city = null;
  267. $scope.myPromise = $http({
  268. url : myConfig.url + '/frame/city/' + $scope.stdData.home_area,
  269. method : 'GET'
  270. }).success(function(data) {
  271. if(data.code == 0){
  272. $scope.home_cities = data.result;
  273. }
  274. }).error(function() {
  275. });
  276. }
  277. $scope.refreshMailArea = function(){
  278. $scope.stdData.mail_area = null;
  279. $scope.stdData.mail_city = null;
  280. $scope.myPromise = $http({
  281. url : myConfig.url + '/frame/area/' + $scope.stdData.mail_province,
  282. method : 'GET'
  283. }).success(function(data) {
  284. if(data.code == 0){
  285. $scope.mail_areas = data.result;
  286. }
  287. }).error(function() {
  288. });
  289. }
  290. $scope.refreshMailCity = function(){
  291. $scope.stdData.mail_city = null;
  292. $scope.myPromise = $http({
  293. url : myConfig.url + '/frame/city/' + $scope.stdData.mail_area,
  294. method : 'GET'
  295. }).success(function(data) {
  296. if(data.code == 0){
  297. $scope.mail_cities = data.result;
  298. }
  299. }).error(function() {
  300. });
  301. }
  302. }).controller('StdBaseInfoExperienceCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster) {
  303. $scope.load = function(){
  304. $scope.myPromise = $http({
  305. url : myConfig.url + '/acquire/experiences?session=' + $rootScope.session,
  306. method : 'GET'
  307. }).success(function(data) {
  308. if(data.code == 0){
  309. $scope.experiences = data.result;
  310. if($scope.experiences.length == 0){
  311. $scope.experiences = [{period_name: '高中'}, {period_name: '初中'}, {period_name: '小学'}];
  312. }
  313. }
  314. }).error(function() {
  315. });
  316. }
  317. $scope.load();
  318. $scope.add = function(){
  319. $scope.experiences.push({});
  320. }
  321. $scope.remove = function(index){
  322. $scope.experiences.splice(index, 1);
  323. }
  324. $scope.submitExperienceForm = function(){
  325. $scope.experienceFormSubmitted = true;
  326. var isValid = true;
  327. for(var i = 0; i < $scope.experiences.length; i++){
  328. var item = $scope.experiences[i];
  329. isValid = isValid && item.start_date && item.end_date && item.school && item.certifier
  330. }
  331. if (isValid) {
  332. $scope.myPromise = $http({
  333. url : myConfig.url + '/acquire/experiences?session=' + $rootScope.session,
  334. method : 'POST',
  335. data : angular.toJson($scope.experiences)
  336. }).success(function(data) {
  337. if(data.code == 0){
  338. toaster.pop('success', '保存成功');
  339. }else{
  340. toaster.pop('error', data.message);
  341. }
  342. }).error(function() {
  343. $scope.load();
  344. });
  345. }
  346. }
  347. }).controller('StdBaseInfoPicCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster, Upload) {
  348. // upload on file select or drop
  349. $scope.upload = function (file, invalidFiles) {
  350. if(invalidFiles && invalidFiles.length > 0){
  351. if(invalidFiles[0].$error == 'maxSize'){
  352. toaster.pop('error', '文件大小超过2M');
  353. }else{
  354. toaster.pop('error', '上传失败,请重试');
  355. }
  356. }
  357. if(!file)
  358. return;
  359. Upload.upload({
  360. url: myConfig.url + '/upload?session=' + $rootScope.session,
  361. data: {file: file}
  362. }).then(function (resp) {
  363. var path = resp.data.result.path;
  364. $scope.myPromise = $http({
  365. url : myConfig.url + '/acquire/headPhoto?session=' + $rootScope.session,
  366. method : 'POST',
  367. data : angular.toJson({path: path, id: resp.data.result.fileId})
  368. }).success(function(data) {
  369. if(data.code == 0){
  370. $scope.stdData.head_photo = path;
  371. toaster.pop('success', '保存成功');
  372. }else{
  373. toaster.pop('error', data.message);
  374. }
  375. }).error(function() {
  376. });
  377. }, function (resp) {
  378. console.log('Error status: ' + resp.status);
  379. }, function (evt) {
  380. });
  381. };
  382. }).controller('StdBaseInfoBkQualificationCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, toaster) {
  383. $scope.load = function(){
  384. $scope.myPromise = $http({
  385. url : myConfig.url + '/acquire/baseInfo?session=' + $rootScope.session,
  386. method : 'GET'
  387. }).success(function(data) {
  388. if(data.code == 0){
  389. $rootScope.stdData = data.result;
  390. // if($rootScope.stdData && $rootScope.stdData.exam_id){
  391. // $rootScope.stdData.exam_id = $rootScope.stdData.exam_id.substr(2,12);
  392. // }
  393. }
  394. }).error(function() {
  395. });
  396. }
  397. $scope.load();
  398. $scope.submitForm = function(isValid) {
  399. $scope.submitted = true
  400. // check to make sure the form is completely valid
  401. if (isValid) {
  402. $scope.myPromise = $http({
  403. url : myConfig.url + '/acquire/baseInfoBkQualification?session=' + $rootScope.session,
  404. method : 'POST',
  405. data : angular.toJson($scope.stdData)
  406. }).success(function(data) {
  407. if(data.code == 0){
  408. toaster.pop('success', '保存成功');
  409. $scope.form.$setPristine();
  410. }else{
  411. toaster.pop('error', data.message);
  412. }
  413. }).error(function() {
  414. $scope.load();
  415. });
  416. }
  417. };
  418. });