upload.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. app.controller('UploadCtrl', [ '$rootScope', '$scope', '$stateParams', '$timeout', function($rootScope, $scope, $stateParams, $timeout) {
  2. if ($stateParams == undefined || $stateParams.enrol_id == undefined) {
  3. $.alert('参数错误,无法获取报考详细信息', function() {
  4. $rootScope.goWechat();
  5. });
  6. return;
  7. }
  8. $scope.getEnrol = function() {
  9. $rootScope.ajaxRequest({
  10. url : '../enrol/std/enrol/find.htm',
  11. data : {
  12. enrol_id : $stateParams.enrol_id,
  13. aspect_batch : 1
  14. }
  15. }, function(response) {
  16. $scope.EnrolMap = response.map.StdEnrol;
  17. });
  18. }
  19. $scope.getEnrol();
  20. $scope.uploadFile = function(photo_type){
  21. var file = document.getElementById(photo_type).files[0];
  22. if(document.getElementById(photo_type).files==null||file==null){
  23. $.alert('请选择照片!');
  24. return;
  25. }
  26. debugger;
  27. var data = new FormData();
  28. data.append('file', file);
  29. data.append('enrol_id',$stateParams.enrol_id);
  30. data.append('photo_type',photo_type);
  31. $rootScope.ajaxRequest({
  32. url: '../enrol/exam/upload.htm',
  33. data:data,
  34. headers: {'Content-Type': undefined},
  35. transformRequest: angular.identity
  36. }, function(response) {
  37. if('photo_file'==photo_type){
  38. $scope.EnrolMap.photo_file=response.entity;
  39. console.log($scope.EnrolMap.photo_file);
  40. }else if('photo_file1'==photo_type){
  41. $scope.EnrolMap.photo_file1=response.entity;
  42. console.log($scope.EnrolMap.photo_file1);
  43. }else if('photo_file2'==photo_type){
  44. $scope.EnrolMap.photo_file2=response.entity;
  45. console.log($scope.EnrolMap.photo_file2);
  46. }
  47. });
  48. }
  49. $scope.uploadAllFile = function(){
  50. debugger;
  51. if((!$scope.EnrolMap.photo_file &&document.getElementById('photo_file').files.length==0)||(!$scope.EnrolMap.photo_file1&&document.getElementById('photo_file1').files.length==0)||(!$scope.EnrolMap.photo_file2&&document.getElementById('photo_file2').files.length==0)){
  52. $.alert('请同时选择三张照片后,再上传!!');
  53. return;
  54. }
  55. var file0=document.getElementById('photo_file').files[0];
  56. var file1=document.getElementById('photo_file1').files[0];
  57. var file2=document.getElementById('photo_file2').files[0];
  58. // if (file0.name==file1.name||file0.name==file2.name||file2.file==file1.name){
  59. //
  60. // $.alert('选择照片中存在相同的文件!');
  61. // return;
  62. // }
  63. if(!$scope.EnrolMap.photo_file)
  64. $scope.uploadFile('photo_file');
  65. if(!$scope.EnrolMap.photo_file1)
  66. $scope.uploadFile('photo_file1');
  67. if(!$scope.EnrolMap.photo_file2)
  68. $scope.uploadFile('photo_file2');
  69. }
  70. $scope.goBack = function(){
  71. $rootScope.goLocation('exam/voide/' + $stateParams.enrol_id +'/true');
  72. }
  73. } ])