exportFieldCtrl.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. angular.module('push')
  2. .controller('exportFieldCtrl', function ($scope, CommentService, $ionicPopup, ConfigService, ResourceLibraryService, $stateParams) {
  3. console.log($stateParams)
  4. $scope.reslist = JSON.parse($stateParams.reslist);
  5. $scope.uniquelist =JSON.parse($stateParams.reslist).unique;
  6. //获取资源库导出字段列表
  7. ResourceLibraryService.getExportFieldList($scope.reslist.type, $scope.reslist.source).then(function (res) {
  8. if (res.code == 3350 && res.data.length > 0) {
  9. $scope.fieldList = res.data;
  10. }
  11. })
  12. $scope.changeToggle = function (list) {
  13. if (list.toggle == 0 || !list.toggle) {
  14. list.toggle = false;
  15. }
  16. list.toggle = !list.toggle;
  17. }
  18. $scope.showExportFlag = false;
  19. $scope.choiceAllFieldTrue = function () {
  20. $scope.showExportFlag = !$scope.showExportFlag;
  21. angular.forEach($scope.fieldList, function (val) {
  22. val.firstPageSetting.toggle = true;
  23. angular.forEach(val.secondPageSettingList, function (val1) {
  24. val1.toggle = true;
  25. })
  26. })
  27. }
  28. $scope.choiceAllFieldFalse = function () {
  29. $scope.showExportFlag = !$scope.showExportFlag;
  30. angular.forEach($scope.fieldList, function (val) {
  31. val.firstPageSetting.toggle = false;
  32. angular.forEach(val.secondPageSettingList, function (val1) {
  33. val1.toggle = false;
  34. })
  35. })
  36. }
  37. $scope.changeFieldFlag = function(list){
  38. list.fieldFlag = !list.fieldFlag;
  39. }
  40. //导出
  41. $scope.exportResource = function () {
  42. $scope.data = {};
  43. $scope.indexMapList = [];
  44. $scope.indexbackuplist = [];
  45. angular.forEach($scope.fieldList, function (val) {
  46. $scope.indexlist = [];
  47. angular.forEach(val.secondPageSettingList, function (val1) {
  48. if (val1.toggle) {
  49. $scope.indexlist.push(val1);
  50. $scope.indexbackuplist.push(val1);
  51. }
  52. })
  53. $scope.indexMapList.push({"title":val.firstPageSetting.title,"secondPageSettingList":$scope.indexlist});
  54. })
  55. $scope.data.uniqueList = $scope.uniquelist;
  56. $scope.data.indexMapList = $scope.indexMapList;
  57. if ($scope.indexbackuplist.length == 0) {
  58. $ionicPopup.alert({
  59. title: '提示',
  60. template: "请选择需要导出的字段"
  61. })
  62. return;
  63. }
  64. $scope.showLoadingToastUtilEnd();
  65. ResourceLibraryService.exportResourceList($scope.data).then(function (res) {
  66. $scope.hideLoadingToast();
  67. if (res.code == 3350) {
  68. var file = res.data;
  69. // window.open(ConfigService.imgurl + file.sourceName);
  70. let a = document.createElement('a');
  71. a.href = ConfigService.imgurl + file.sourceName;
  72. a.download = file.sourceName;
  73. a.click()
  74. a.remove();
  75. $ionicPopup.alert({
  76. title: '提示',
  77. template: '导出成功'
  78. })
  79. } else {
  80. $ionicPopup.alert({
  81. title: '提示',
  82. template: '导出失败!'
  83. })
  84. }
  85. }).catch((res)=>{
  86. $scope.hideLoadingToast();
  87. $ionicPopup.alert({
  88. title: '提示',
  89. template: '服务器错误稍后请重试'
  90. })
  91. })
  92. }
  93. $scope.choiceAllField = function(list){
  94. if(list.firstPageSetting.toggle == 0){
  95. list.firstPageSetting.toggle = false;
  96. }
  97. list.firstPageSetting.toggle = !list.firstPageSetting.toggle;
  98. if(list.firstPageSetting.toggle){
  99. angular.forEach(list.secondPageSettingList, function(res){
  100. res.toggle = true;
  101. })
  102. }else{
  103. angular.forEach(list.secondPageSettingList, function(res){
  104. res.toggle = false;
  105. })
  106. }
  107. }
  108. });