angular.module('push')
.controller('personIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, accountModel) {
if($scope.app){
$scope.setStatusBar(0);
}
$scope.authenstatus = -1;// 认证状态:0未认证 1认证中 2已认证 3认证失败
var ditypelist = [];//证件类型
var oldimageidlist = [0, 0];//旧附件di集合
// 证件图片信息
$scope.imagelist = [
{
id: 0,
doctype: 6,//正面
title: "",
photo_name: ""
}, {
id: 0,
doctype: 7,//反面
title: "",
photo_name: ""
}
];
var getAuthInfo = function () {
$scope.showLoadingToast();
AccountService.getAuthInfo(0).then(function (response) {
console.log(1);
console.log(response);
ditypelist = response.idtype;
accountModel.setOrgtypeList(response.orgtype);
accountModel.setPositionalTitles(response.titles);//保存职称集合
if (angular.isDefined(response.info)) {
$scope.person = {
type: response.info.type,
name: response.info.name,
idtype: response.info.idtype,
idtypename: response.info.idtypename,
cardno: response.info.cardno
};
accountModel.setOldUserAuthInfo(response.info);
// 遍历找出证件类型名称
angular.forEach(ditypelist, function (val, ind) {
if (val.itemvalue == response.info.idtype) {
$scope.person.idtypename = val.itemkey;
}
});
$scope.authenstatus = response.info.authenstatus;
$scope.postscript = response.info.postscript;
// 遍历找出身份证正反面
if (angular.isDefined(response.info.imagelist) && response.info.imagelist.length > 0) {
angular.forEach(response.info.imagelist, function (val, ind) {
if (val.doctype == 6) {
$scope.imagelist[0] = val;
oldimageidlist[0] = val.id;
}
if (val.doctype == 7) {
$scope.imagelist[1] = val;
oldimageidlist[1] = val.id;
}
})
}
accountModel.setSaveFlg(1);
} else {
initInfo();
accountModel.setSaveFlg(0);
}
$scope.hideLoadingToast();
}, function () {
initInfo();
$scope.hideLoadingToast();
})
};
if(UtilService.isDefined(accountModel.getUserAuthInfo().name)){
console.log(2);
$scope.person = accountModel.getUserAuthInfo();
$scope.imagelist = accountModel.getInfoImageList();
}else {
getAuthInfo();
}
// 初始化空信息
var initInfo = function () {
// 个人信息
$scope.person = {
name: "",
type: 1,
idtype: "",
idtypename: "",
cardno: ""
};
accountModel.setOldUserAuthInfo("");
};
//删除图片
$scope.delectImg = function (imgind) {
$scope.imagelist[imgind] = {};
};
// 选取身份证
$scope.show_identify = function (imgind) {
// 选取身份证弹框
$ionicActionSheet.show({
buttons: [
{text: '拍照'},
{text: '从相册中添加'}
],
cancelText: '取消',
buttonClicked: function (index) {
if (index == 0) {
openCamera(imgind);
} else if (index == 1) {
getPictures(imgind);
}
return true;
}
});
};
//拍照
var openCamera = function (imgind) {
UtilService.getPicture(1).then(function (results) {
// console.log(results);
$scope.imagelist[imgind].id = oldimageidlist[imgind];
$scope.imagelist[imgind].photo_name = results;
$scope.imagelist[imgind].original_name = results;
$scope.imagelist[imgind].source_name = results;
}, function (err) {
});
};
//检测权限
var verifyStorage = function (imgind) {
window.imagePicker.verifyStorage(
function (results) {
if (results == "1") {
getPic(imgind);
}
}, function (error) {
}
);
};
//打开相册
var getPic = function (imgind) {
var count = 1;
if (imgind == 0) {
count = 2;
}
UtilService.getPictureList(count).then(function (results) {
// console.log(results);
if (imgind == 0) {
if (results.length == 1) {
$scope.imagelist[0].id = oldimageidlist[0];
$scope.imagelist[0].photo_name = results[0];
$scope.imagelist[0].original_name = results[0];
$scope.imagelist[0].source_name = results[0];
}
if (results.length == 2) {
$scope.imagelist[0].id = oldimageidlist[0];
$scope.imagelist[0].photo_name = results[0];
$scope.imagelist[0].original_name = results[0];
$scope.imagelist[0].source_name = results[0];
$scope.imagelist[1].id = oldimageidlist[1];
$scope.imagelist[1].photo_name = results[1];
$scope.imagelist[1].original_name = results[1];
$scope.imagelist[1].source_name = results[1];
}
} else {
$scope.imagelist[1].id = oldimageidlist[1];
$scope.imagelist[1].photo_name = results[0];
$scope.imagelist[1].original_name = results[0];
$scope.imagelist[1].source_name = results[0];
}
}, function (err) {
});
};
var getPictures = function (imgind) {
if (device.platform == "Android") {
verifyStorage(imgind);
} else {
getPic(imgind);
}
};
// 下一步
$scope.nextStep = function () {
if (!UtilService.isDefined($scope.person.name)) {
UtilService.showMess("姓名不能为空");
return;
}
if (!UtilService.isDefined($scope.person.idtype)) {
UtilService.showMess("证件类型不能为空");
return;
}
if (!UtilService.isDefined($scope.person.cardno)) {
UtilService.showMess("证件号码不能为空");
return;
}
/*if (!UtilService.isIdentityNumber($scope.person.cardno)) {
UtilService.showMess("请输入正确的身份证号");
return;
}*/
if (UtilService.isDefined($scope.person.orgemail) && (!UtilService.isEmail($scope.person.orgemail))) {
UtilService.showMess("请输入正确的邮箱");
return;
}
if ($scope.imagelist[0].photo_name == "" || $scope.imagelist[1].photo_name == "") {
UtilService.showMess("请上传本人二代身份证正反照");
return;
}
// console.log($scope.person);
accountModel.setUserAuthInfo($scope.person);
accountModel.setInfoImageList($scope.imagelist);
$scope.go("chooseUnitType");
};
//证件类型
$scope.showCardType = function () {
var buttons = [];
angular.forEach(ditypelist, function (value, index) {
buttons.push({
text: '' + value.itemkey + '',
type: value.itemvalue,
name: value.itemkey
})
});
$ionicActionSheet.show({
buttons: buttons,
cancelText: '取消',
buttonClicked: function (index) {
$scope.person.idtype = buttons[index].type;
$scope.person.idtypename = buttons[index].name;
return true;
}
});
};
$scope.againAuth = function () {
$scope.authenstatus = -1;
}
});