ImportCtrl.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. angular.module('push')
  2. .controller('ImportCtrl', function ($scope,MyCollectionService,$ionicPopup,$ionicModal,$state,$stateParams,CommonService){
  3. //选择框api
  4. $scope.page=1
  5. $scope.tableData=[]
  6. $scope.pagedata={}
  7. $scope.pafileType=$stateParams.listparams
  8. MyCollectionService.getentrytypes().then(function (res) {
  9. if(res.code==3350){
  10. if( $scope.pafileType){
  11. res.data.filter(function (res){
  12. if(res.fileType==$scope.pafileType){
  13. $scope.selectedtypes=res
  14. }
  15. })
  16. console.log($scope.selectedtypes)
  17. }else {
  18. $scope.selectedtypes=res.data[0]
  19. }
  20. $scope.types=res.data
  21. entrylist($scope.page)
  22. }else {
  23. $ionicPopup.alert({
  24. title: '提示',
  25. template: res.message
  26. });
  27. }
  28. })
  29. //获取文件列表
  30. function entrylist(){
  31. var listparams={
  32. nodeId :localStorage.node,
  33. uid :localStorage.uid,
  34. fileType : $scope.selectedtypes.fileType,
  35. currPage : $scope.page
  36. }
  37. MyCollectionService. postentrylist(listparams).then(function (res) {
  38. if(res.code==3350){
  39. if( $scope.page==1){
  40. $scope.pagedata=res.page
  41. $scope.tableData= res.data.uploadResults
  42. }else {
  43. $scope.tableData.push.apply($scope.tableData,res.data.uploadResults)
  44. $scope.$broadcast('scroll.infiniteScrollComplete');
  45. }
  46. $scope.page++
  47. }else {
  48. $ionicPopup.alert({
  49. title: '提示',
  50. template: res.message
  51. });
  52. }
  53. })
  54. }
  55. //分页
  56. $scope.loadMore=function () {
  57. if( $scope.page>$scope.pagedata.totalPage){
  58. $scope.nomore=true
  59. return
  60. }
  61. entrylist($scope.page)
  62. }
  63. //选择框回调
  64. $scope.handletypes=function (item) {
  65. $scope.selectedtypes=item
  66. $scope.page=1
  67. $scope.nomore=false
  68. entrylist($scope.page)
  69. }
  70. //下载模板
  71. $scope.handleDownload=function (item) {
  72. var data={
  73. fileType: item.fileType,
  74. node:localStorage.node,
  75. uid: localStorage.uid,
  76. }
  77. MyCollectionService.getentrydownload(data).then(function (res) {
  78. console.log(res)
  79. var aEle = document.createElement("a");// 创建a标签
  80. var blob = new Blob([res],{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  81. aEle.download = item.modelName;// 设置下载文件的文件名
  82. aEle.href = URL.createObjectURL(blob);
  83. aEle.click();// 设置点击事件
  84. })
  85. }
  86. //详情
  87. $scope.ImportEdit=function(row,item){
  88. console.log(item)
  89. var data={
  90. type:row,
  91. params:{
  92. fileType: item.fileType,
  93. fileId:item.reqId,
  94. fileName:item.fileName,
  95. }
  96. }
  97. $state.go("ImportEdit", {listparams : JSON.stringify(data)});
  98. }
  99. //返回
  100. $scope.goback=function(){
  101. $scope.go('tab.account');
  102. }
  103. //导入文件
  104. $scope.ImportFile=function () {
  105. var files = document.getElementById('file');
  106. files.click();
  107. $(files).unbind().on('change',function (e) {
  108. console.log(files.value)
  109. if(files.files.length<=1){
  110. var data=new FormData()
  111. data.append("file",files.files[0])
  112. data.append("fileType",$scope.selectedtypes.fileType)
  113. data.append("nodeId",localStorage.node)
  114. data.append("uId",localStorage.uid)
  115. // $ionicPopup.alert({
  116. // title: '提示',
  117. // template: " <progress/>",
  118. // buttons:[]
  119. // });
  120. var x = document.getElementById("myProgress");
  121. var v = document.getElementById("myProgressval");
  122. $scope.myCheck=true
  123. $scope.filesName=files.files[0].name
  124. var time=10
  125. function run() {
  126. if(x.value<50) {
  127. x.value = x.value + 1
  128. v.innerHTML=x.value+"%"
  129. }
  130. if(x.value==50){
  131. if(time!=8){
  132. time=1000
  133. clearInterval(timeout)
  134. timeout= setInterval(run,time)
  135. }
  136. }
  137. if ( x.value>=50) {
  138. x.value = x.value + 1
  139. v.innerHTML=x.value+"%"
  140. }
  141. if(x.value==80){
  142. if(time!=8){
  143. clearInterval(timeout)
  144. }
  145. }
  146. if(x.value>=80){
  147. x.value = x.value + 1
  148. v.innerHTML=x.value+"%"
  149. }
  150. if(x.value==100){
  151. clearInterval(timeout)
  152. $scope.$apply(function () {
  153. $scope.filesName=""
  154. $scope.myCheck=false
  155. });
  156. x.value=0
  157. v.innerHTML=""
  158. if($scope.impData.code==3350){
  159. CommonService.showMessage($scope.impData.message, $scope);
  160. $scope.page=1
  161. entrylist()
  162. }else {
  163. try {
  164. $scope.PopupData=JSON.parse($scope.impData.message)
  165. $ionicPopup.alert({
  166. title: '提示',
  167. template: '<table class="table" style="bo">' +
  168. '<tr>' +
  169. '<th>企业名称</th>'+
  170. '<th>错误信息</th>'+
  171. '</tr>' +
  172. '<tr ng-repeat="item in PopupData">' +
  173. '<td>{{item.orgName}}</td>'+
  174. '<td ng-bind="item.errorMsg"></td>'+
  175. '</tr>' +
  176. '</table>',
  177. scope: $scope
  178. });
  179. }catch (e) {
  180. $ionicPopup.alert({
  181. title: '提示',
  182. template:'<soan>{{impData.message}}</soan>',
  183. scope: $scope
  184. });
  185. }
  186. }
  187. }
  188. }
  189. var timeout= setInterval(run,time)
  190. MyCollectionService.postentryimport(data).then(function (res) {
  191. console.log(res)
  192. files.value=""
  193. time=8
  194. clearInterval(timeout)
  195. timeout= setInterval(run,time)
  196. $scope.impData=res
  197. // setTimeout(function(){
  198. // time=8
  199. // clearInterval(timeout)
  200. // timeout= setInterval(run,time)
  201. // }, 4000)
  202. }).catch(function (res){
  203. $scope.hideLoadingToast();
  204. $ionicPopup.alert({
  205. title: '提示',
  206. template: "服务器错误"
  207. });
  208. })
  209. }else {
  210. $ionicPopup.alert({
  211. title: '提示',
  212. template: "只能上传一个文件"
  213. });
  214. }
  215. })
  216. }
  217. $scope.change=function (item) {
  218. console.log(item)
  219. }
  220. })