quarterlyImportCtrl.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. angular.module('push')
  2. .controller('quarterlyImportCtrl', function ($scope, $stateParams, ConfigService, UserService, taskModuleService, $ionicPopup, CommentService, UtilService, $timeout, CommonService) {
  3. $scope.importsuccess = $stateParams.importsuccess;
  4. var enterprise = [
  5. {
  6. title: '上传季报文件',
  7. content: '[]',
  8. type: 'upload',
  9. needed: false,
  10. imagelist: [],
  11. imageSaveList: [],
  12. imageDeleteList: [],
  13. doctype: 4908,
  14. remarkType: 'normal'
  15. }
  16. ];
  17. $scope.formList = enterprise;
  18. taskModuleService.getOrgStatsDataList().then(function (res) {
  19. if (res.code == 3350) {
  20. $scope.orgnamelist = res.data;
  21. }
  22. })
  23. $scope.sendAnalysisToDB = function () {
  24. angular.forEach($scope.formList, function (val) {
  25. if (val.type == "upload") {
  26. if (val.imageSaveList.length == 0 && val.imagelist.length != 0) {
  27. val.imageSaveList = val.imagelist;
  28. }
  29. }
  30. })
  31. if (!$scope.formList[0].imageSaveList || $scope.formList[0].imageSaveList.length == 0) {
  32. $ionicPopup.alert({
  33. title: '提示',
  34. template: '没有文件需要导入!'
  35. })
  36. return;
  37. }
  38. var imagelist = $scope.formList[0].imageSaveList;
  39. for (var i = 0; i < imagelist.length; i++) {
  40. var fileDiveded = imagelist[i].title.split(".");
  41. if (fileDiveded.length > 0 ) {
  42. if (fileDiveded[fileDiveded.length - 1] != "xls" && fileDiveded[fileDiveded.length - 1] != "xlsx") {
  43. $ionicPopup.alert({
  44. title: '提示',
  45. template: '只能上传excel文件!'
  46. })
  47. return;
  48. }
  49. }
  50. }
  51. var params = {};
  52. params.data = $scope.formList;
  53. params.node = UserService.node;
  54. params.userid = UserService.id;
  55. params.path = ConfigService.imgurl;
  56. $scope.showLoadingToastUtilEnd();
  57. taskModuleService.sendAnalysisToDB(params).then(function (res) {
  58. $scope.hideLoadingToast();
  59. if (res.code == 3350) {
  60. $ionicPopup.alert({
  61. title: '提示',
  62. template: '导入成功!'
  63. })
  64. $scope.go('quarterlyAnalysis');
  65. } else {
  66. $ionicPopup.alert({
  67. title: '提示',
  68. template: '导入失败!'
  69. })
  70. return;
  71. }
  72. })
  73. }
  74. $scope.addImage = function (index) {
  75. listIndex = index;
  76. if ($scope.app) {
  77. var list = [
  78. {text: '<a class="action-sheet-push">拍照</a>'},
  79. {text: '<a class="action-sheet-push">从相册上传</a>'},
  80. ];
  81. var clickfunction = function (indx) {
  82. if (indx == 0) {
  83. $scope.openCamera();
  84. } else {
  85. getPictures();
  86. }
  87. return true;
  88. }
  89. } else {
  90. var files = document.getElementById('file');
  91. files.click();
  92. $(files).unbind().on('change', function (e) {
  93. // console.log(e);
  94. if ($scope.formList[listIndex].imagelist.length > 8) {
  95. $ionicPopup.alert({
  96. title: '提示',
  97. template: '最多只能上传9个文件!'
  98. });
  99. return;
  100. }
  101. $.each(e.target.files, function (i, file) {
  102. var url = null;
  103. if (window.createObjectURL != undefined) { // basic
  104. url = window.createObjectURL(file);
  105. } else if (window.URL != undefined) { // mozilla(firefox)
  106. url = window.URL.createObjectURL(file);
  107. } else if (window.webkitURL != undefined) { // webkit or chrome
  108. url = window.webkitURL.createObjectURL(file);
  109. }
  110. $scope.formList[listIndex].imagelist.push({title: file.name, photoName: url, originalName: url});
  111. });
  112. $scope.showLoadingToast();
  113. var data = new FormData();
  114. $.each(e.target.files, function (i, file) {
  115. data.append('file', file);
  116. });
  117. CommonService.mutipleUploadImage(data).then(function (res) {
  118. if (res.code == 3350) {
  119. angular.forEach(res.data, function (value) {
  120. $scope.formList[listIndex].imageSaveList.push({
  121. id: 0,
  122. title: value.title,
  123. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  124. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  125. photoName: value.photoName,
  126. originalName: value.originalName,
  127. sourceName: value.sourceName,
  128. sourceSize: value.sourceSize
  129. })
  130. })
  131. }
  132. // console.log(temp);
  133. // console.log($scope.formList[listIndex]);
  134. })
  135. })
  136. $scope.hideLoadingToast();
  137. return true;
  138. }
  139. $ionicActionSheet.show({
  140. buttons: list,
  141. cancelText: '取消',
  142. buttonClicked: clickfunction
  143. })
  144. }
  145. $scope.openCamera = function () {
  146. if ($scope.formList[listIndex].imagelist.length >= 9) {
  147. if ($scope.app) {
  148. UtilService.showMess("最多选取9张图片");
  149. } else {
  150. CommonService.showMessage("最多选取9张图片", $scope)
  151. }
  152. return;
  153. }
  154. UtilService.getPicture(1).then(function (results) {
  155. $scope.showLoadingToast();
  156. $scope.formList[listIndex].imagelist.push({photoName: results, originalName: results})
  157. UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) {
  158. angular.forEach(response, function (value) {
  159. $scope.formList[listIndex].imageSaveList.push({
  160. id: 0,
  161. title: value.title,
  162. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  163. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  164. photoName: value.photoName,
  165. originalName: value.originalName,
  166. sourceName: value.sourceName,
  167. sourceSize: value.sourceSize
  168. })
  169. })
  170. $scope.hideLoadingToast();
  171. }, function () {
  172. $scope.hideLoadingToast();
  173. if ($scope.app) {
  174. UtilService.showMess("网络不给力,请重试");
  175. } else {
  176. CommonService.showMessage("网络不给力,请重试", $scope)
  177. }
  178. });
  179. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  180. }, function (err) {
  181. });
  182. }
  183. var getPictures = function () {
  184. if (device.platform == "Android") {
  185. verifyStorage();
  186. } else {
  187. getPic();
  188. }
  189. };
  190. var verifyStorage = function () {
  191. window.imagePicker.verifyStorage(
  192. function (results) {
  193. if (results == "1") {
  194. getPic();
  195. }
  196. }, function (error) {
  197. }
  198. );
  199. };
  200. var getPic = function () {
  201. var imagelistLength = $scope.formList[listIndex].imagelist.length;
  202. if (imagelistLength >= 9) {
  203. if ($scope.app) {
  204. UtilService.showMess("最多选取9个文件");
  205. } else {
  206. CommonService.showMessage("最多选取9个文件", $scope)
  207. }
  208. return;
  209. }
  210. UtilService.getPictureList(9 - imagelistLength).then(function (results) {
  211. $scope.showLoadingToast();
  212. angular.forEach(results, function (val, i) {
  213. $scope.formList[listIndex].imagelist.push({photoName: val, originalName: val});
  214. })
  215. UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) {
  216. angular.forEach(response, function (value) {
  217. if (value.status) {
  218. $scope.formList[listIndex].imageSaveList.push({
  219. id: 0,
  220. title: "",
  221. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  222. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  223. photoName: value.photoName,
  224. originalName: value.originalName,
  225. sourceName: value.sourceName,
  226. sourceSize: value.sourceSize
  227. });
  228. }
  229. })
  230. $scope.hideLoadingToast();
  231. }, function () {
  232. $scope.hideLoadingToast();
  233. if ($scope.app) {
  234. UtilService.showMess("网络不给力,请重试");
  235. } else {
  236. CommonService.showMessage("网络不给力,请重试", $scope)
  237. }
  238. });
  239. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  240. }, function (err) {
  241. });
  242. };
  243. //删除图片
  244. $scope.deletePhoto = function (index, outerIndex) {
  245. console.log($scope.formList[outerIndex]);
  246. if ($scope.formList[outerIndex].imageSaveList[index].id != 0) {
  247. $scope.formList[outerIndex].imageSaveList[index].isenabled = 2;
  248. $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]);
  249. }
  250. $scope.formList[outerIndex].imagelist.splice(index, 1);
  251. $scope.formList[outerIndex].imageSaveList.splice(index, 1);
  252. // console.log($scope.formList[outerIndex].imagelist);
  253. // console.log($scope.formList[outerIndex].imageSaveList);
  254. // console.log($scope.formList[outerIndex].imageDeleteList);
  255. }
  256. if ($scope.importsuccess == 1) {
  257. $scope.formList[0].imagelist = [];
  258. $scope.formList[0].imageSaveList = [];
  259. $scope.formList[0].imageDeleteList = [];
  260. $scope.orgnamelist = [];
  261. angular.forEach($stateParams.orgdatalist, function(val){
  262. $scope.orgnamelist.push(val.orgName);
  263. })
  264. }
  265. });