upload.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $rootScope.ajaxRequest({
  9. url : '../enrol/log.htm',
  10. data : {
  11. logType:'WebPageUploadPhoto'
  12. }
  13. }, function(response) {
  14. });
  15. $scope.getEnrol = function() {
  16. $rootScope.ajaxRequest({
  17. url : '../enrol/std/enrol/find.htm',
  18. data : {
  19. enrol_id : $stateParams.enrol_id,
  20. aspect_batch : 1
  21. }
  22. }, function(response) {
  23. $scope.EnrolMap = response.map.StdEnrol;
  24. });
  25. }
  26. $scope.getEnrol();
  27. $scope.uploadFile = function(photo_type){
  28. var file = document.getElementById(photo_type).files[0];
  29. if(document.getElementById(photo_type).files==null||file==null){
  30. $.alert('请选择照片!');
  31. return;
  32. }
  33. var data = new FormData();
  34. data.append('file', file);
  35. data.append('enrol_id',$stateParams.enrol_id);
  36. data.append('photo_type',photo_type);
  37. $rootScope.ajaxRequest({
  38. url: '../enrol/exam/upload.htm',
  39. data:data,
  40. headers: {'Content-Type': undefined},
  41. transformRequest: angular.identity
  42. }, function(response) {
  43. if('photo_file'==photo_type){
  44. $scope.EnrolMap.photo_file=response.entity;
  45. console.log($scope.EnrolMap.photo_file);
  46. }else if('photo_file1'==photo_type){
  47. $scope.EnrolMap.photo_file1=response.entity;
  48. console.log($scope.EnrolMap.photo_file1);
  49. }else if('photo_file2'==photo_type){
  50. $scope.EnrolMap.photo_file2=response.entity;
  51. console.log($scope.EnrolMap.photo_file2);
  52. }
  53. });
  54. }
  55. $scope.uploadAllFile = function(){
  56. 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)){
  57. $.alert('请同时选择三张照片后,再上传!!');
  58. return;
  59. }
  60. var file0=document.getElementById('photo_file').files[0];
  61. var file1=document.getElementById('photo_file1').files[0];
  62. var file2=document.getElementById('photo_file2').files[0];
  63. // if (file0.name==file1.name||file0.name==file2.name||file2.file==file1.name){
  64. //
  65. // $.alert('选择照片中存在相同的文件!');
  66. // return;
  67. // }
  68. if(!$scope.EnrolMap.photo_file)
  69. $scope.uploadFile('photo_file');
  70. if(!$scope.EnrolMap.photo_file1)
  71. $scope.uploadFile('photo_file1');
  72. if(!$scope.EnrolMap.photo_file2)
  73. $scope.uploadFile('photo_file2');
  74. }
  75. $scope.goBack = function(){
  76. $rootScope.goLocation('exam/voide/' + $stateParams.enrol_id +'/true');
  77. }
  78. } ])