123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- angular.module('push')
- .controller('ImportCtrl', function ($scope,MyCollectionService,$ionicPopup,$ionicModal,$state,$stateParams,CommonService){
- //选择框api
- $scope.page=1
- $scope.tableData=[]
- $scope.pagedata={}
- $scope.pafileType=$stateParams.listparams
- MyCollectionService.getentrytypes().then(function (res) {
- if(res.code==3350){
- if( $scope.pafileType){
- res.data.filter(function (res){
- if(res.fileType==$scope.pafileType){
- $scope.selectedtypes=res
- }
- })
- console.log($scope.selectedtypes)
- }else {
- $scope.selectedtypes=res.data[0]
- }
- $scope.types=res.data
- entrylist($scope.page)
- }else {
- $ionicPopup.alert({
- title: '提示',
- template: res.message
- });
- }
- })
- //获取文件列表
- function entrylist(){
- var listparams={
- nodeId :localStorage.node,
- uid :localStorage.uid,
- fileType : $scope.selectedtypes.fileType,
- currPage : $scope.page
- }
- MyCollectionService. postentrylist(listparams).then(function (res) {
- if(res.code==3350){
- if( $scope.page==1){
- $scope.pagedata=res.page
- $scope.tableData= res.data.uploadResults
- }else {
- $scope.tableData.push.apply($scope.tableData,res.data.uploadResults)
- $scope.$broadcast('scroll.infiniteScrollComplete');
- }
- $scope.page++
- }else {
- $ionicPopup.alert({
- title: '提示',
- template: res.message
- });
- }
- })
- }
- //分页
- $scope.loadMore=function () {
- if( $scope.page>$scope.pagedata.totalPage){
- $scope.nomore=true
- return
- }
- entrylist($scope.page)
- }
- //选择框回调
- $scope.handletypes=function (item) {
- $scope.selectedtypes=item
- $scope.page=1
- $scope.nomore=false
- entrylist($scope.page)
- }
- //下载模板
- $scope.handleDownload=function (item) {
- var data={
- fileType: item.fileType,
- node:localStorage.node,
- uid: localStorage.uid,
- }
- MyCollectionService.getentrydownload(data).then(function (res) {
- console.log(res)
- var aEle = document.createElement("a");// 创建a标签
- var blob = new Blob([res],{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
- aEle.download = item.modelName;// 设置下载文件的文件名
- aEle.href = URL.createObjectURL(blob);
- aEle.click();// 设置点击事件
- })
- }
- //详情
- $scope.ImportEdit=function(row,item){
- console.log(item)
- var data={
- type:row,
- params:{
- fileType: item.fileType,
- fileId:item.reqId,
- fileName:item.fileName,
- }
- }
- $state.go("ImportEdit", {listparams : JSON.stringify(data)});
- }
- //返回
- $scope.goback=function(){
- $scope.go('tab.account');
- }
- //导入文件
- $scope.ImportFile=function () {
- var files = document.getElementById('file');
- files.click();
- $(files).unbind().on('change',function (e) {
- console.log(files.value)
- if(files.files.length<=1){
- var data=new FormData()
- data.append("file",files.files[0])
- data.append("fileType",$scope.selectedtypes.fileType)
- data.append("nodeId",localStorage.node)
- data.append("uId",localStorage.uid)
- // $ionicPopup.alert({
- // title: '提示',
- // template: " <progress/>",
- // buttons:[]
- // });
- var x = document.getElementById("myProgress");
- var v = document.getElementById("myProgressval");
- $scope.myCheck=true
- $scope.filesName=files.files[0].name
- var time=10
- function run() {
- if(x.value<50) {
- x.value = x.value + 1
- v.innerHTML=x.value+"%"
- }
- if(x.value==50){
- if(time!=8){
- time=1000
- clearInterval(timeout)
- timeout= setInterval(run,time)
- }
- }
- if ( x.value>=50) {
- x.value = x.value + 1
- v.innerHTML=x.value+"%"
- }
- if(x.value==80){
- if(time!=8){
- clearInterval(timeout)
- }
- }
- if(x.value>=80){
- x.value = x.value + 1
- v.innerHTML=x.value+"%"
- }
- if(x.value==100){
- clearInterval(timeout)
- $scope.$apply(function () {
- $scope.filesName=""
- $scope.myCheck=false
- });
- x.value=0
- v.innerHTML=""
- if($scope.impData.code==3350){
- CommonService.showMessage($scope.impData.message, $scope);
- $scope.page=1
- entrylist()
- }else {
- try {
- $scope.PopupData=JSON.parse($scope.impData.message)
- $ionicPopup.alert({
- title: '提示',
- template: '<table class="table" style="bo">' +
- '<tr>' +
- '<th>企业名称</th>'+
- '<th>错误信息</th>'+
- '</tr>' +
- '<tr ng-repeat="item in PopupData">' +
- '<td>{{item.orgName}}</td>'+
- '<td ng-bind="item.errorMsg"></td>'+
- '</tr>' +
- '</table>',
- scope: $scope
- });
- }catch (e) {
- $ionicPopup.alert({
- title: '提示',
- template:'<soan>{{impData.message}}</soan>',
- scope: $scope
- });
- }
- }
- }
- }
- var timeout= setInterval(run,time)
- MyCollectionService.postentryimport(data).then(function (res) {
- console.log(res)
- files.value=""
- time=8
- clearInterval(timeout)
- timeout= setInterval(run,time)
- $scope.impData=res
- // setTimeout(function(){
- // time=8
- // clearInterval(timeout)
- // timeout= setInterval(run,time)
- // }, 4000)
- }).catch(function (res){
- $scope.hideLoadingToast();
- $ionicPopup.alert({
- title: '提示',
- template: "服务器错误"
- });
- })
- }else {
- $ionicPopup.alert({
- title: '提示',
- template: "只能上传一个文件"
- });
- }
- })
- }
- $scope.change=function (item) {
- console.log(item)
- }
- })
|