123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- angular.module('push')
- .controller('unitIdentifyCtrl', function ($scope, $stateParams, $ionicActionSheet, UtilService, AccountService, $timeout, accountModel) {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $scope.defaultLan = UserService.defaultLan;
- //单位类型 1企业 2高校 3政府 4机构 5园区
- $scope.orgtype = $stateParams.orgtype;
- var saveflg = accountModel.getSaveFlg();//获取修改标志
- var personimagelist = accountModel.getInfoImageList();//获取个人附件信息
- var personauthinfo = accountModel.getUserAuthInfo();
- var positionaltitlelist = accountModel.getPositionalTitles();
- console.log(personauthinfo);
- // 判断是否存在历史信息
- if (accountModel.getOldUserAuthInfo() == "") {
- $scope.authinfo = {
- orgcode: "",
- orgtype: $scope.orgtype,
- title: "",
- legalperson: "",
- areaid: "",
- district: "",
- detailaddress: "",
- domain: "",
- university: "",
- positionaltitles: "",
- department: ""
- };
- $scope.oldimagelist = [];
- } else {
- var oldauthinfo = accountModel.getOldUserAuthInfo();
- $scope.authinfo = {
- orgcode: oldauthinfo.orgcode,
- orgtype: $scope.orgtype,
- title: oldauthinfo.title,
- legalperson: oldauthinfo.legalperson,
- areaid: oldauthinfo.areaid,
- district: oldauthinfo.district,
- detailaddress: oldauthinfo.detailaddress,
- domain: oldauthinfo.domain,
- university: oldauthinfo.university,
- positionaltitles: oldauthinfo.positionaltitles,
- department: oldauthinfo.department
- };
- console.log($scope.authinfo);
- if (angular.isDefined($scope.authinfo.district) && $scope.authinfo.district.length > 0) {
- var str = $scope.authinfo.district.replace(/\//g, "");
- $timeout(function () {
- $scope.$broadcast("recregistplace", str);
- }, 100);
- }
- // 判断单位信息中是否有图片信息
- if (angular.isDefined(oldauthinfo.imagelist) && oldauthinfo.imagelist.length > 0) {
- $scope.oldimagelist = oldauthinfo.imagelist;
- }
- }
- if (UtilService.isDefined($scope.authinfo.positionaltitles)) {
- angular.forEach(positionaltitlelist, function (val, ind) {
- if (val.itemvalue == $scope.authinfo.positionaltitles) {
- $scope.authinfo.positionaltitlename = val.itemkey;
- }
- });
- }
- // 初始化证件图片信息 doctype: 3在职证明 4组织机构代码 5营业执照
- $scope.imagelist = [
- {
- id: 0,
- doctype: 3,
- title: "",
- photo_name: ""
- }, {
- id: 0,
- doctype: 5,
- title: "",
- photo_name: ""
- }
- ];
- // 遍历历史附件提取对应图片
- var oldimageidlist = [0, 0, 0];
- angular.forEach($scope.oldimagelist, function (val, ind) {
- if (val.doctype == 3) {
- $scope.imagelist[0] = val;
- oldimageidlist[0] = val.id;
- }
- if (val.doctype == 5) {
- $scope.imagelist[1] = val;
- oldimageidlist[1] = val.id;
- }
- });
- //删除图片
- $scope.delectImg = function (imgind) {
- $scope.imagelist[imgind] = {};
- };
- // 选取身份证
- $scope.show_identify = function (imgind) {
- // 选取身份证弹框
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">拍照</a>'},
- {text: '<a class="action-sheet-push">从相册中添加</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- $timeout(function () {
- openCamera(imgind);
- },350);
- } else if (index == 1) {
- $timeout(function () {
- getPictures(imgind);
- },350);
- }
- 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) {
- UtilService.getPictureList(1).then(function (results) {
- console.log(results);
- $scope.imagelist[imgind].id = oldimageidlist[imgind];
- $scope.imagelist[imgind].photo_name = results[0];
- $scope.imagelist[imgind].original_name = results[0];
- $scope.imagelist[imgind].source_name = results[0];
- }, function (err) {
- });
- };
- var getPictures = function (imgind) {
- if (device.platform == "Android") {
- verifyStorage(imgind);
- } else {
- getPic(imgind);
- }
- };
- //上传图片
- var tempimages = [];
- var uploadImages = function () {
- if ($scope.orgtype == 1) {
- personimagelist.push($scope.imagelist[1]);
- }
- if ($scope.orgtype == 2 || $scope.orgtype == 3 || $scope.orgtype == 5) {
- personimagelist.push($scope.imagelist[0]);
- }
- if ($scope.orgtype == 4) {
- if (UtilService.isDefined($scope.imagelist[0].photo_name)) {
- personimagelist.push($scope.imagelist[0]);
- }
- if (UtilService.isDefined($scope.imagelist[1].photo_name)) {
- personimagelist.push($scope.imagelist[1]);
- }
- }
- tempimages = [];//附件总集合
- var upimages = [];//上传附件集合
- var doctypelist = [];//上传附件对应doctype集合
- var oldidlist = [0, 0, 0, 0, 0];
- angular.forEach(personimagelist, function (data, ind) {
- if (data.photo_name.indexOf("file:") != -1) {
- upimages.push(data.photo_name);
- doctypelist.push(data.doctype);
- oldidlist[ind] = data.id;
- } else {
- tempimages.push(data);
- }
- });
- // console.log("--------附件类型集合--------");
- // console.log(personimagelist);
- UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
- console.log(response);
- angular.forEach(response, function (value, index) {
- if (value.status) {
- tempimages.push({
- id: oldidlist[index],
- title: "",
- doctype: doctypelist[index],
- 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 () {
- var params = UtilService.concatJson(personauthinfo, $scope.authinfo);
- params.images = angular.toJson(tempimages);//重新拼接附件
- if (saveflg == 0) {
- AccountService.subAuthInfo(params).then(function (response) {
- UtilService.showMess("认证信息已提交,请您耐心等待……");
- $timeout(function () {
- $scope.go("tab.account");
- }, 1000);
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- })
- } else {
- AccountService.updateAuthInfo(params).then(function (response) {
- // console.log(response);
- UtilService.showMess("修改认证申请成功");
- $timeout(function () {
- $scope.go("tab.account");
- }, 1000);
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- })
- }
- };
- // 提交认证信息
- $scope.applyIdentifyAuth = function () {
- if ($scope.orgtype == 2 && !UtilService.isDefined($scope.authinfo.university)) {
- UtilService.showMess("院校名称不能为空");
- return;
- }
- if (($scope.orgtype != 3 && $scope.orgtype != 5) && !UtilService.isDefined($scope.authinfo.title)) {
- UtilService.showMess("职务不能为空");
- return;
- }
- if ($scope.orgtype == 1 && !UtilService.isDefined($scope.authinfo.orgcode)) {
- UtilService.showMess("组织机构代码不能为空");
- return;
- }
- if (($scope.orgtype == 3 || $scope.orgtype == 5) && !UtilService.isDefined($scope.authinfo.department)) {
- UtilService.showMess("部门不能为空");
- return;
- }
- if ($scope.orgtype == 1 && (!UtilService.isDefined($scope.imagelist[1].photo_name))) {
- UtilService.showMess("请上传单位的营业执照");
- return;
- }
- if (($scope.orgtype == 2 || $scope.orgtype == 3 || $scope.orgtype == 5) && !UtilService.isDefined($scope.imagelist[0].photo_name)) {
- UtilService.showMess("请上传工作证明照片");
- return;
- }
- if ($scope.orgtype == 4 && (!UtilService.isDefined($scope.imagelist[0].photo_name) && !UtilService.isDefined($scope.imagelist[1].photo_name))) {
- UtilService.showMess("请上传工作证明或营业执照照片");
- return;
- }
- uploadImages();
- $scope.showLoadingToast();
- };
- // 职称类型
- $scope.showCardType = function () {
- var buttons = [];
- angular.forEach(positionaltitlelist, function (value, index) {
- buttons.push({
- text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
- type: value.itemvalue,
- name: value.itemkey
- })
- });
- $ionicActionSheet.show({
- buttons: buttons,
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.authinfo.positionaltitles = buttons[index].type;
- $scope.authinfo.positionaltitlename = buttons[index].name;
- return true;
- }
- });
- };
- //接收城市选择数据
- var reciveregplace = $scope.$on("registplace", function (event, data) {
- $scope.authinfo.areaid = data.areaid;
- $scope.authinfo.district = data.registplace;
- });
- //页面销毁时 回收广播
- $scope.$on('$destroy', function () {
- reciveregplace();
- });
- });
|