angular.module('push') .controller('exportFieldCtrl', function ($scope, CommentService, $ionicPopup, ConfigService, ResourceLibraryService, $stateParams) { console.log($stateParams) $scope.reslist = JSON.parse($stateParams.reslist); $scope.uniquelist =JSON.parse($stateParams.reslist).unique; //获取资源库导出字段列表 ResourceLibraryService.getExportFieldList($scope.reslist.type, $scope.reslist.source).then(function (res) { if (res.code == 3350 && res.data.length > 0) { $scope.fieldList = res.data; } }) $scope.changeToggle = function (list) { if (list.toggle == 0 || !list.toggle) { list.toggle = false; } list.toggle = !list.toggle; } $scope.showExportFlag = false; $scope.choiceAllFieldTrue = function () { $scope.showExportFlag = !$scope.showExportFlag; angular.forEach($scope.fieldList, function (val) { val.firstPageSetting.toggle = true; angular.forEach(val.secondPageSettingList, function (val1) { val1.toggle = true; }) }) } $scope.choiceAllFieldFalse = function () { $scope.showExportFlag = !$scope.showExportFlag; angular.forEach($scope.fieldList, function (val) { val.firstPageSetting.toggle = false; angular.forEach(val.secondPageSettingList, function (val1) { val1.toggle = false; }) }) } $scope.changeFieldFlag = function(list){ list.fieldFlag = !list.fieldFlag; } //导出 $scope.exportResource = function () { $scope.data = {}; $scope.indexMapList = []; $scope.indexbackuplist = []; angular.forEach($scope.fieldList, function (val) { $scope.indexlist = []; angular.forEach(val.secondPageSettingList, function (val1) { if (val1.toggle) { $scope.indexlist.push(val1); $scope.indexbackuplist.push(val1); } }) $scope.indexMapList.push({"title":val.firstPageSetting.title,"secondPageSettingList":$scope.indexlist}); }) $scope.data.uniqueList = $scope.uniquelist; $scope.data.indexMapList = $scope.indexMapList; if ($scope.indexbackuplist.length == 0) { $ionicPopup.alert({ title: '提示', template: "请选择需要导出的字段" }) return; } $scope.showLoadingToastUtilEnd(); ResourceLibraryService.exportResourceList($scope.data).then(function (res) { $scope.hideLoadingToast(); if (res.code == 3350) { var file = res.data; // window.open(ConfigService.imgurl + file.sourceName); let a = document.createElement('a'); a.href = ConfigService.imgurl + file.sourceName; a.download = file.sourceName; a.click() a.remove(); $ionicPopup.alert({ title: '提示', template: '导出成功' }) } else { $ionicPopup.alert({ title: '提示', template: '导出失败!' }) } }).catch((res)=>{ $scope.hideLoadingToast(); $ionicPopup.alert({ title: '提示', template: '服务器错误稍后请重试' }) }) } $scope.choiceAllField = function(list){ if(list.firstPageSetting.toggle == 0){ list.firstPageSetting.toggle = false; } list.firstPageSetting.toggle = !list.firstPageSetting.toggle; if(list.firstPageSetting.toggle){ angular.forEach(list.secondPageSettingList, function(res){ res.toggle = true; }) }else{ angular.forEach(list.secondPageSettingList, function(res){ res.toggle = false; }) } } });