unitIdentifyCtrl.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. angular.module('push')
  2. .controller('unitIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, accountModel) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. $scope.defaultLan = UserService.defaultLan;
  7. //单位类型 1企业 2高校 3政府 4机构 5园区
  8. $scope.orgtype = $stateParams.orgtype;
  9. var saveflg = accountModel.getSaveFlg();//获取修改标志
  10. var personimagelist = accountModel.getInfoImageList();//获取个人附件信息
  11. var personauthinfo = accountModel.getUserAuthInfo();
  12. var positionaltitlelist = accountModel.getPositionalTitles();
  13. console.log(personauthinfo);
  14. // 判断是否存在历史信息
  15. if (accountModel.getOldUserAuthInfo() == "") {
  16. $scope.authinfo = {
  17. orgcode: "",
  18. orgtype: $scope.orgtype,
  19. title: "",
  20. legalperson: "",
  21. areaid: "",
  22. district: "",
  23. detailaddress: "",
  24. domain: "",
  25. university: "",
  26. positionaltitles: "",
  27. department: ""
  28. };
  29. $scope.oldimagelist = [];
  30. } else {
  31. var oldauthinfo = accountModel.getOldUserAuthInfo();
  32. $scope.authinfo = {
  33. orgcode: oldauthinfo.orgcode,
  34. orgtype: $scope.orgtype,
  35. title: oldauthinfo.title,
  36. legalperson: oldauthinfo.legalperson,
  37. areaid: oldauthinfo.areaid,
  38. district: oldauthinfo.district,
  39. detailaddress: oldauthinfo.detailaddress,
  40. domain: oldauthinfo.domain,
  41. university: oldauthinfo.university,
  42. positionaltitles: oldauthinfo.positionaltitles,
  43. department: oldauthinfo.department
  44. };
  45. console.log($scope.authinfo);
  46. if (angular.isDefined($scope.authinfo.district) && $scope.authinfo.district.length > 0) {
  47. var str = $scope.authinfo.district.replace(/\//g, "");
  48. $timeout(function () {
  49. $scope.$broadcast("recregistplace", str);
  50. }, 100);
  51. }
  52. // 判断单位信息中是否有图片信息
  53. if (angular.isDefined(oldauthinfo.imagelist) && oldauthinfo.imagelist.length > 0) {
  54. $scope.oldimagelist = oldauthinfo.imagelist;
  55. }
  56. }
  57. if (UtilService.isDefined($scope.authinfo.positionaltitles)) {
  58. angular.forEach(positionaltitlelist, function (val, ind) {
  59. if (val.itemvalue == $scope.authinfo.positionaltitles) {
  60. $scope.authinfo.positionaltitlename = val.itemkey;
  61. }
  62. });
  63. }
  64. // 初始化证件图片信息 doctype: 3在职证明 4组织机构代码 5营业执照
  65. $scope.imagelist = [
  66. {
  67. id: 0,
  68. doctype: 3,
  69. title: "",
  70. photo_name: ""
  71. }, {
  72. id: 0,
  73. doctype: 5,
  74. title: "",
  75. photo_name: ""
  76. }
  77. ];
  78. // 遍历历史附件提取对应图片
  79. var oldimageidlist = [0, 0, 0];
  80. angular.forEach($scope.oldimagelist, function (val, ind) {
  81. if (val.doctype == 3) {
  82. $scope.imagelist[0] = val;
  83. oldimageidlist[0] = val.id;
  84. }
  85. if (val.doctype == 5) {
  86. $scope.imagelist[1] = val;
  87. oldimageidlist[1] = val.id;
  88. }
  89. });
  90. //删除图片
  91. $scope.delectImg = function (imgind) {
  92. $scope.imagelist[imgind] = {};
  93. };
  94. // 选取身份证
  95. $scope.show_identify = function (imgind) {
  96. // 选取身份证弹框
  97. $ionicActionSheet.show({
  98. buttons: [
  99. {text: '<a class="action-sheet-push">拍照</a>'},
  100. {text: '<a class="action-sheet-push">从相册中添加</a>'}
  101. ],
  102. cancelText: '取消',
  103. buttonClicked: function (index) {
  104. if (index == 0) {
  105. $timeout(function () {
  106. openCamera(imgind);
  107. },350);
  108. } else if (index == 1) {
  109. $timeout(function () {
  110. getPictures(imgind);
  111. },350);
  112. }
  113. return true;
  114. }
  115. });
  116. };
  117. //拍照
  118. var openCamera = function (imgind) {
  119. UtilService.getPicture(1).then(function (results) {
  120. // console.log(results);
  121. $scope.imagelist[imgind].id = oldimageidlist[imgind];
  122. $scope.imagelist[imgind].photo_name = results;
  123. $scope.imagelist[imgind].original_name = results;
  124. $scope.imagelist[imgind].source_name = results;
  125. }, function (err) {
  126. });
  127. };
  128. //检测权限
  129. var verifyStorage = function (imgind) {
  130. window.imagePicker.verifyStorage(
  131. function (results) {
  132. if (results == "1") {
  133. getPic(imgind);
  134. }
  135. }, function (error) {
  136. }
  137. );
  138. };
  139. //打开相册
  140. var getPic = function (imgind) {
  141. UtilService.getPictureList(1).then(function (results) {
  142. console.log(results);
  143. $scope.imagelist[imgind].id = oldimageidlist[imgind];
  144. $scope.imagelist[imgind].photo_name = results[0];
  145. $scope.imagelist[imgind].original_name = results[0];
  146. $scope.imagelist[imgind].source_name = results[0];
  147. }, function (err) {
  148. });
  149. };
  150. var getPictures = function (imgind) {
  151. if (device.platform == "Android") {
  152. verifyStorage(imgind);
  153. } else {
  154. getPic(imgind);
  155. }
  156. };
  157. //上传图片
  158. var tempimages = [];
  159. var uploadImages = function () {
  160. if ($scope.orgtype == 1) {
  161. personimagelist.push($scope.imagelist[1]);
  162. }
  163. if ($scope.orgtype == 2 || $scope.orgtype == 3 || $scope.orgtype == 5) {
  164. personimagelist.push($scope.imagelist[0]);
  165. }
  166. if ($scope.orgtype == 4) {
  167. if (UtilService.isDefined($scope.imagelist[0].photo_name)) {
  168. personimagelist.push($scope.imagelist[0]);
  169. }
  170. if (UtilService.isDefined($scope.imagelist[1].photo_name)) {
  171. personimagelist.push($scope.imagelist[1]);
  172. }
  173. }
  174. tempimages = [];//附件总集合
  175. var upimages = [];//上传附件集合
  176. var doctypelist = [];//上传附件对应doctype集合
  177. var oldidlist = [0, 0, 0, 0, 0];
  178. angular.forEach(personimagelist, function (data, ind) {
  179. if (data.photo_name.indexOf("file:") != -1) {
  180. upimages.push(data.photo_name);
  181. doctypelist.push(data.doctype);
  182. oldidlist[ind] = data.id;
  183. } else {
  184. tempimages.push(data);
  185. }
  186. });
  187. // console.log("--------附件类型集合--------");
  188. // console.log(personimagelist);
  189. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  190. console.log(response);
  191. angular.forEach(response, function (value, index) {
  192. if (value.status) {
  193. tempimages.push({
  194. id: oldidlist[index],
  195. title: "",
  196. doctype: doctypelist[index],
  197. photo_name: value.userPhoto,
  198. original_name: value.originalPhoto,
  199. source_name: value.sourcePhoto,
  200. source_size: value.source_size
  201. });
  202. }
  203. });
  204. applyI()
  205. }, function () {
  206. UtilService.showMess("网络不给力,请重试");
  207. $scope.hideLoadingToast();
  208. })
  209. };
  210. //接口请求
  211. var applyI = function () {
  212. var params = UtilService.concatJson(personauthinfo, $scope.authinfo);
  213. params.images = angular.toJson(tempimages);//重新拼接附件
  214. if (saveflg == 0) {
  215. AccountService.subAuthInfo(params).then(function (response) {
  216. UtilService.showMess("认证信息已提交,请您耐心等待……");
  217. $timeout(function () {
  218. $scope.go("tab.account");
  219. }, 1000);
  220. $scope.hideLoadingToast();
  221. }, function () {
  222. $scope.hideLoadingToast();
  223. })
  224. } else {
  225. AccountService.updateAuthInfo(params).then(function (response) {
  226. // console.log(response);
  227. UtilService.showMess("修改认证申请成功");
  228. $timeout(function () {
  229. $scope.go("tab.account");
  230. }, 1000);
  231. $scope.hideLoadingToast();
  232. }, function () {
  233. $scope.hideLoadingToast();
  234. })
  235. }
  236. };
  237. // 提交认证信息
  238. $scope.applyIdentifyAuth = function () {
  239. if ($scope.orgtype == 2 && !UtilService.isDefined($scope.authinfo.university)) {
  240. UtilService.showMess("院校名称不能为空");
  241. return;
  242. }
  243. if (($scope.orgtype != 3 && $scope.orgtype != 5) && !UtilService.isDefined($scope.authinfo.title)) {
  244. UtilService.showMess("职务不能为空");
  245. return;
  246. }
  247. if ($scope.orgtype == 1 && !UtilService.isDefined($scope.authinfo.orgcode)) {
  248. UtilService.showMess("组织机构代码不能为空");
  249. return;
  250. }
  251. if (($scope.orgtype == 3 || $scope.orgtype == 5) && !UtilService.isDefined($scope.authinfo.department)) {
  252. UtilService.showMess("部门不能为空");
  253. return;
  254. }
  255. if ($scope.orgtype == 1 && (!UtilService.isDefined($scope.imagelist[1].photo_name))) {
  256. UtilService.showMess("请上传单位的营业执照");
  257. return;
  258. }
  259. if (($scope.orgtype == 2 || $scope.orgtype == 3 || $scope.orgtype == 5) && !UtilService.isDefined($scope.imagelist[0].photo_name)) {
  260. UtilService.showMess("请上传工作证明照片");
  261. return;
  262. }
  263. if ($scope.orgtype == 4 && (!UtilService.isDefined($scope.imagelist[0].photo_name) && !UtilService.isDefined($scope.imagelist[1].photo_name))) {
  264. UtilService.showMess("请上传工作证明或营业执照照片");
  265. return;
  266. }
  267. uploadImages();
  268. $scope.showLoadingToast();
  269. };
  270. // 职称类型
  271. $scope.showCardType = function () {
  272. var buttons = [];
  273. angular.forEach(positionaltitlelist, function (value, index) {
  274. buttons.push({
  275. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  276. type: value.itemvalue,
  277. name: value.itemkey
  278. })
  279. });
  280. $ionicActionSheet.show({
  281. buttons: buttons,
  282. cancelText: '取消',
  283. buttonClicked: function (index) {
  284. $scope.authinfo.positionaltitles = buttons[index].type;
  285. $scope.authinfo.positionaltitlename = buttons[index].name;
  286. return true;
  287. }
  288. });
  289. };
  290. //接收城市选择数据
  291. var reciveregplace = $scope.$on("registplace", function (event, data) {
  292. $scope.authinfo.areaid = data.areaid;
  293. $scope.authinfo.district = data.registplace;
  294. });
  295. //页面销毁时 回收广播
  296. $scope.$on('$destroy', function () {
  297. reciveregplace();
  298. });
  299. });