personIdentifyCtrl.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. angular.module('push')
  2. .controller('personIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, accountModel) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. $scope.authenstatus = -1;// 认证状态:0未认证 1认证中 2已认证 3认证失败
  7. var ditypelist = [];//证件类型
  8. var oldimageidlist = [0, 0];//旧附件di集合
  9. // 证件图片信息
  10. $scope.imagelist = [
  11. {
  12. id: 0,
  13. doctype: 6,//正面
  14. title: "",
  15. photo_name: ""
  16. }, {
  17. id: 0,
  18. doctype: 7,//反面
  19. title: "",
  20. photo_name: ""
  21. }
  22. ];
  23. var getAuthInfo = function () {
  24. $scope.showLoadingToast();
  25. AccountService.getAuthInfo(0).then(function (response) {
  26. console.log(1);
  27. console.log(response);
  28. ditypelist = response.idtype;
  29. accountModel.setOrgtypeList(response.orgtype);
  30. accountModel.setPositionalTitles(response.titles);//保存职称集合
  31. if (angular.isDefined(response.info)) {
  32. $scope.person = {
  33. type: response.info.type,
  34. name: response.info.name,
  35. idtype: response.info.idtype,
  36. idtypename: response.info.idtypename,
  37. cardno: response.info.cardno
  38. };
  39. accountModel.setOldUserAuthInfo(response.info);
  40. // 遍历找出证件类型名称
  41. angular.forEach(ditypelist, function (val, ind) {
  42. if (val.itemvalue == response.info.idtype) {
  43. $scope.person.idtypename = val.itemkey;
  44. }
  45. });
  46. $scope.authenstatus = response.info.authenstatus;
  47. $scope.postscript = response.info.postscript;
  48. // 遍历找出身份证正反面
  49. if (angular.isDefined(response.info.imagelist) && response.info.imagelist.length > 0) {
  50. angular.forEach(response.info.imagelist, function (val, ind) {
  51. if (val.doctype == 6) {
  52. $scope.imagelist[0] = val;
  53. oldimageidlist[0] = val.id;
  54. }
  55. if (val.doctype == 7) {
  56. $scope.imagelist[1] = val;
  57. oldimageidlist[1] = val.id;
  58. }
  59. })
  60. }
  61. accountModel.setSaveFlg(1);
  62. } else {
  63. initInfo();
  64. accountModel.setSaveFlg(0);
  65. }
  66. $scope.hideLoadingToast();
  67. }, function () {
  68. initInfo();
  69. $scope.hideLoadingToast();
  70. })
  71. };
  72. if(UtilService.isDefined(accountModel.getUserAuthInfo().name)){
  73. console.log(2);
  74. $scope.person = accountModel.getUserAuthInfo();
  75. $scope.imagelist = accountModel.getInfoImageList();
  76. }else {
  77. getAuthInfo();
  78. }
  79. // 初始化空信息
  80. var initInfo = function () {
  81. // 个人信息
  82. $scope.person = {
  83. name: "",
  84. type: 1,
  85. idtype: "",
  86. idtypename: "",
  87. cardno: ""
  88. };
  89. accountModel.setOldUserAuthInfo("");
  90. };
  91. //删除图片
  92. $scope.delectImg = function (imgind) {
  93. $scope.imagelist[imgind] = {};
  94. };
  95. // 选取身份证
  96. $scope.show_identify = function (imgind) {
  97. // 选取身份证弹框
  98. $ionicActionSheet.show({
  99. buttons: [
  100. {text: '<a class="action-sheet-push">拍照</a>'},
  101. {text: '<a class="action-sheet-push">从相册中添加</a>'}
  102. ],
  103. cancelText: '取消',
  104. buttonClicked: function (index) {
  105. if (index == 0) {
  106. openCamera(imgind);
  107. } else if (index == 1) {
  108. getPictures(imgind);
  109. }
  110. return true;
  111. }
  112. });
  113. };
  114. //拍照
  115. var openCamera = function (imgind) {
  116. UtilService.getPicture(1).then(function (results) {
  117. // console.log(results);
  118. $scope.imagelist[imgind].id = oldimageidlist[imgind];
  119. $scope.imagelist[imgind].photo_name = results;
  120. $scope.imagelist[imgind].original_name = results;
  121. $scope.imagelist[imgind].source_name = results;
  122. }, function (err) {
  123. });
  124. };
  125. //检测权限
  126. var verifyStorage = function (imgind) {
  127. window.imagePicker.verifyStorage(
  128. function (results) {
  129. if (results == "1") {
  130. getPic(imgind);
  131. }
  132. }, function (error) {
  133. }
  134. );
  135. };
  136. //打开相册
  137. var getPic = function (imgind) {
  138. var count = 1;
  139. if (imgind == 0) {
  140. count = 2;
  141. }
  142. UtilService.getPictureList(count).then(function (results) {
  143. // console.log(results);
  144. if (imgind == 0) {
  145. if (results.length == 1) {
  146. $scope.imagelist[0].id = oldimageidlist[0];
  147. $scope.imagelist[0].photo_name = results[0];
  148. $scope.imagelist[0].original_name = results[0];
  149. $scope.imagelist[0].source_name = results[0];
  150. }
  151. if (results.length == 2) {
  152. $scope.imagelist[0].id = oldimageidlist[0];
  153. $scope.imagelist[0].photo_name = results[0];
  154. $scope.imagelist[0].original_name = results[0];
  155. $scope.imagelist[0].source_name = results[0];
  156. $scope.imagelist[1].id = oldimageidlist[1];
  157. $scope.imagelist[1].photo_name = results[1];
  158. $scope.imagelist[1].original_name = results[1];
  159. $scope.imagelist[1].source_name = results[1];
  160. }
  161. } else {
  162. $scope.imagelist[1].id = oldimageidlist[1];
  163. $scope.imagelist[1].photo_name = results[0];
  164. $scope.imagelist[1].original_name = results[0];
  165. $scope.imagelist[1].source_name = results[0];
  166. }
  167. }, function (err) {
  168. });
  169. };
  170. var getPictures = function (imgind) {
  171. if (device.platform == "Android") {
  172. verifyStorage(imgind);
  173. } else {
  174. getPic(imgind);
  175. }
  176. };
  177. // 下一步
  178. $scope.nextStep = function () {
  179. if (!UtilService.isDefined($scope.person.name)) {
  180. UtilService.showMess("姓名不能为空");
  181. return;
  182. }
  183. if (!UtilService.isDefined($scope.person.idtype)) {
  184. UtilService.showMess("证件类型不能为空");
  185. return;
  186. }
  187. if (!UtilService.isDefined($scope.person.cardno)) {
  188. UtilService.showMess("证件号码不能为空");
  189. return;
  190. }
  191. /*if (!UtilService.isIdentityNumber($scope.person.cardno)) {
  192. UtilService.showMess("请输入正确的身份证号");
  193. return;
  194. }*/
  195. if (UtilService.isDefined($scope.person.orgemail) && (!UtilService.isEmail($scope.person.orgemail))) {
  196. UtilService.showMess("请输入正确的邮箱");
  197. return;
  198. }
  199. if ($scope.imagelist[0].photo_name == "" || $scope.imagelist[1].photo_name == "") {
  200. UtilService.showMess("请上传本人二代身份证正反照");
  201. return;
  202. }
  203. // console.log($scope.person);
  204. accountModel.setUserAuthInfo($scope.person);
  205. accountModel.setInfoImageList($scope.imagelist);
  206. $scope.go("chooseUnitType");
  207. };
  208. //证件类型
  209. $scope.showCardType = function () {
  210. var buttons = [];
  211. angular.forEach(ditypelist, function (value, index) {
  212. buttons.push({
  213. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  214. type: value.itemvalue,
  215. name: value.itemkey
  216. })
  217. });
  218. $ionicActionSheet.show({
  219. buttons: buttons,
  220. cancelText: '取消',
  221. buttonClicked: function (index) {
  222. $scope.person.idtype = buttons[index].type;
  223. $scope.person.idtypename = buttons[index].name;
  224. return true;
  225. }
  226. });
  227. };
  228. $scope.againAuth = function () {
  229. $scope.authenstatus = -1;
  230. }
  231. });