jobIdentifyCtrl.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. angular.module('push')
  2. .controller('jobIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, $ionicModal) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. var doctype = 0;//附件类型:0其他 1工牌 2名片 3在职证明 8企业邮箱
  7. var saveflg = 0;//提交数据标志:0 新增 1 修改
  8. var docid;
  9. if ($stateParams.job == "") {
  10. saveflg = 0;
  11. $scope.job = {
  12. industry: "",
  13. title: "",
  14. imagelist: [{photo_name: ""}]
  15. };
  16. } else {
  17. saveflg = 1;
  18. var tempjob = angular.fromJson($stateParams.job);
  19. $scope.job = angular.copy(tempjob);
  20. if (angular.isUndefined(tempjob.imagelist)) {
  21. $scope.job.imagelist = [{photo_name: ""}]
  22. } else {
  23. docid = tempjob.imagelist[0].id;
  24. }
  25. }
  26. //删除图片
  27. $scope.delectImg = function () {
  28. $scope.job.imagelist[0] = {};
  29. };
  30. // 选取身份证
  31. $scope.show_identify = function (type) {
  32. $scope.closeModal();
  33. doctype = type;
  34. // 选取身份证弹框
  35. $ionicActionSheet.show({
  36. buttons: [
  37. {text: '<a class="action-sheet-push">拍照</a>'},
  38. {text: '<a class="action-sheet-push">从相册中添加</a>'}
  39. ],
  40. cancelText: '取消',
  41. buttonClicked: function (index) {
  42. if (index == 0) {
  43. openCamera();
  44. } else if (index == 1) {
  45. getPictures();
  46. }
  47. return true;
  48. }
  49. });
  50. };
  51. //拍照
  52. var openCamera = function () {
  53. UtilService.getPicture(1).then(function (results) {
  54. // console.log(results);
  55. $scope.job.imagelist[0] = {
  56. photo_name: results,
  57. original_name: results,
  58. source_name: results
  59. };
  60. }, function (err) {
  61. });
  62. };
  63. //检测权限
  64. var verifyStorage = function () {
  65. window.imagePicker.verifyStorage(
  66. function (results) {
  67. if (results == "1") {
  68. getPic();
  69. }
  70. }, function (error) {
  71. }
  72. );
  73. };
  74. //打开相册
  75. var getPic = function () {
  76. UtilService.getPictureList(1).then(function (results) {
  77. // console.log(results);
  78. $scope.job.imagelist[0] = {
  79. photo_name: results[0],
  80. original_name: results[0],
  81. source_name: results[0]
  82. };
  83. }, function (err) {
  84. });
  85. };
  86. var getPictures = function () {
  87. if (device.platform == "Android") {
  88. verifyStorage();
  89. } else {
  90. getPic();
  91. }
  92. };
  93. //上传图片
  94. var tempimages = [];
  95. var uploadImages = function () {
  96. tempimages = [];
  97. var upimages = [];
  98. angular.forEach($scope.job.imagelist, function (data) {
  99. if (data.photo_name.indexOf("file:") != -1) {
  100. upimages.push(data.photo_name);
  101. } else {
  102. tempimages.push(data);
  103. }
  104. });
  105. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  106. // console.log(response);
  107. angular.forEach(response, function (value) {
  108. if (value.status) {
  109. tempimages.push({
  110. id: docid,
  111. doctype: doctype,
  112. title: "",
  113. photo_name: value.userPhoto,
  114. original_name: value.originalPhoto,
  115. source_name: value.sourcePhoto,
  116. source_size: value.source_size
  117. });
  118. }
  119. });
  120. applyI()
  121. }, function () {
  122. UtilService.showMess("网络不给力,请重试");
  123. $scope.hideLoadingToast();
  124. })
  125. };
  126. //接口请求
  127. var applyI = function () {
  128. if (saveflg == 0) {
  129. AccountService.InsertSysUsersAuthen(2, $scope.job, tempimages).then(function (response) {
  130. UtilService.showMess("认证信息已提交,请您耐心等待……");
  131. $timeout(function () {
  132. $scope.goback();
  133. }, 1000);
  134. $scope.hideLoadingToast();
  135. }, function () {
  136. $scope.hideLoadingToast();
  137. })
  138. } else {
  139. AccountService.updateSysUsersAuthen(2, $scope.job, tempimages).then(function (response) {
  140. // console.log(response);
  141. UtilService.showMess("修改认证申请成功");
  142. $timeout(function () {
  143. $scope.goback();
  144. }, 1000);
  145. $scope.hideLoadingToast();
  146. }, function () {
  147. $scope.hideLoadingToast();
  148. })
  149. }
  150. };
  151. //申请职业认证
  152. $scope.applyJobAuth = function () {
  153. if (!UtilService.isDefined($scope.job.industry)) {
  154. UtilService.showMess("行业不能为空");
  155. return;
  156. }
  157. if (!UtilService.isDefined($scope.job.title)) {
  158. UtilService.showMess("职位不能为空");
  159. return;
  160. }
  161. if (angular.isUndefined($scope.job.imagelist[0].photo_name) || $scope.job.imagelist[0].photo_name == "") {
  162. UtilService.showMess("请上传一张职业身份证明");
  163. return;
  164. }
  165. uploadImages();
  166. $scope.showLoadingToast();
  167. // console.log($scope.job);
  168. };
  169. $ionicModal.fromTemplateUrl('identifyImg.html', {
  170. scope: $scope,
  171. animation: 'slide-in-up'
  172. }).then(function (modal) {
  173. $scope.modal = modal;
  174. });
  175. $scope.openModal = function () {
  176. $scope.modal.show();
  177. };
  178. $scope.closeModal = function () {
  179. $scope.modal.hide();
  180. };
  181. //Cleanup the modal when we're done with it!
  182. $scope.$on('$destroy', function () {
  183. $scope.modal.remove();
  184. });
  185. // Execute action on hide modal
  186. $scope.$on('modal.hidden', function () {
  187. // Execute action
  188. });
  189. // Execute action on remove modal
  190. $scope.$on('modal.removed', function () {
  191. // Execute action
  192. });
  193. });