angular.module('push') .controller('jobIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, $ionicModal) { if($scope.app){ $scope.setStatusBar(0); } var doctype = 0;//附件类型:0其他 1工牌 2名片 3在职证明 8企业邮箱 var saveflg = 0;//提交数据标志:0 新增 1 修改 var docid; if ($stateParams.job == "") { saveflg = 0; $scope.job = { industry: "", title: "", imagelist: [{photo_name: ""}] }; } else { saveflg = 1; var tempjob = angular.fromJson($stateParams.job); $scope.job = angular.copy(tempjob); if (angular.isUndefined(tempjob.imagelist)) { $scope.job.imagelist = [{photo_name: ""}] } else { docid = tempjob.imagelist[0].id; } } //删除图片 $scope.delectImg = function () { $scope.job.imagelist[0] = {}; }; // 选取身份证 $scope.show_identify = function (type) { $scope.closeModal(); doctype = type; // 选取身份证弹框 $ionicActionSheet.show({ buttons: [ {text: '拍照'}, {text: '从相册中添加'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { openCamera(); } else if (index == 1) { getPictures(); } return true; } }); }; //拍照 var openCamera = function () { UtilService.getPicture(1).then(function (results) { // console.log(results); $scope.job.imagelist[0] = { photo_name: results, original_name: results, source_name: results }; }, function (err) { }); }; //检测权限 var verifyStorage = function () { window.imagePicker.verifyStorage( function (results) { if (results == "1") { getPic(); } }, function (error) { } ); }; //打开相册 var getPic = function () { UtilService.getPictureList(1).then(function (results) { // console.log(results); $scope.job.imagelist[0] = { photo_name: results[0], original_name: results[0], source_name: results[0] }; }, function (err) { }); }; var getPictures = function () { if (device.platform == "Android") { verifyStorage(); } else { getPic(); } }; //上传图片 var tempimages = []; var uploadImages = function () { tempimages = []; var upimages = []; angular.forEach($scope.job.imagelist, function (data) { if (data.photo_name.indexOf("file:") != -1) { upimages.push(data.photo_name); } else { tempimages.push(data); } }); UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) { // console.log(response); angular.forEach(response, function (value) { if (value.status) { tempimages.push({ id: docid, doctype: doctype, title: "", photo_name: value.userPhoto, original_name: value.originalPhoto, source_name: value.sourcePhoto, source_size: value.source_size }); } }); applyI() }, function () { UtilService.showMess("网络不给力,请重试"); $scope.hideLoadingToast(); }) }; //接口请求 var applyI = function () { if (saveflg == 0) { AccountService.InsertSysUsersAuthen(2, $scope.job, tempimages).then(function (response) { UtilService.showMess("认证信息已提交,请您耐心等待……"); $timeout(function () { $scope.goback(); }, 1000); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) } else { AccountService.updateSysUsersAuthen(2, $scope.job, tempimages).then(function (response) { // console.log(response); UtilService.showMess("修改认证申请成功"); $timeout(function () { $scope.goback(); }, 1000); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) } }; //申请职业认证 $scope.applyJobAuth = function () { if (!UtilService.isDefined($scope.job.industry)) { UtilService.showMess("行业不能为空"); return; } if (!UtilService.isDefined($scope.job.title)) { UtilService.showMess("职位不能为空"); return; } if (angular.isUndefined($scope.job.imagelist[0].photo_name) || $scope.job.imagelist[0].photo_name == "") { UtilService.showMess("请上传一张职业身份证明"); return; } uploadImages(); $scope.showLoadingToast(); // console.log($scope.job); }; $ionicModal.fromTemplateUrl('identifyImg.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.modal = modal; }); $scope.openModal = function () { $scope.modal.show(); }; $scope.closeModal = function () { $scope.modal.hide(); }; //Cleanup the modal when we're done with it! $scope.$on('$destroy', function () { $scope.modal.remove(); }); // Execute action on hide modal $scope.$on('modal.hidden', function () { // Execute action }); // Execute action on remove modal $scope.$on('modal.removed', function () { // Execute action }); });