simImport.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. app.controller('simImportCtrl', ['$scope', '$http', '$state', 'FileUploader', 'toaster', function ($scope, $http, $state, FileUploader, toaster) {
  2. $scope.simBrand = ''
  3. $scope.simBrandName = '请选择卡商'
  4. $scope.changeCardBrand = function ($event, value, name) {
  5. $scope.simBrand = value
  6. $scope.simBrandName = name
  7. }
  8. $scope.file = ''
  9. /***********excel上传工具*******************/
  10. //文件提交控件
  11. var uploader2 = $scope.uploader2 = new FileUploader({
  12. url: '/common/upload?type=simCardImport',
  13. queueLimit: 1, //文件个数
  14. removeAfterUpload: true //上传后删除文件
  15. });
  16. //注册上传事件
  17. uploader2.onCompleteItem = function (fileItem, response, status, headers) {
  18. if (response.payload) {
  19. toaster.pop("success", "提示", "上传成功!");
  20. $scope.file = response.payload
  21. }
  22. clearUploader2();
  23. };
  24. uploader2.onErrorItem = function (fileItem, response, status, headers) {
  25. toaster.pop("error", "提示", "上传失败,请重试");
  26. clearUploader2();
  27. };
  28. /*恢复上传框初始状态*/
  29. function clearUploader2() {
  30. $("#fileUpload2").val("");
  31. uploader2.clearQueue();
  32. uploader2.cancelAll();
  33. }
  34. $scope.saveCardMission = function () {
  35. if (!$scope.simBrand) {
  36. toaster.pop("warning", "提示", "请选择卡商");
  37. return
  38. }
  39. if (!$scope.file) {
  40. toaster.pop("warning", "提示", "请上传文件");
  41. return
  42. }
  43. $http({
  44. method: 'POST',
  45. url: '/superadmin/importSim',
  46. data: {
  47. file: $scope.file,
  48. source: $scope.simBrand
  49. }
  50. }).then(function (response) {
  51. toaster.pop("success", "提示", "保存成功!");
  52. $state.go('app.tool.offlineTask', {
  53. searchKey: response.data.payload
  54. });
  55. }, function (response) {
  56. toaster.pop("error", "提示", "保存失败!");
  57. });
  58. }
  59. }]);