importOrgInfoCtrl.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. angular.module('push')
  2. .controller('importOrgInfoCtrl', function ($scope, $ionicPopup, $stateParams, UserService, taskModuleService, ConfigService, CommentService, UtilService, $timeout, CommonService) {
  3. $scope.restype = $stateParams.restype;
  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.sendOrgInfoToDB = 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. params.restype = $scope.restype;
  57. $scope.showLoadingToast();
  58. //企业信息导入数据库
  59. taskModuleService.importOrgInfoToDB(params).then(function (res) {
  60. $scope.hideLoadingToast();
  61. if (res.code == 3350) {
  62. $ionicPopup.alert({
  63. title: '提示',
  64. template: '导入成功!'
  65. })
  66. } else {
  67. $ionicPopup.alert({
  68. title: '提示',
  69. template: '导入失败!'
  70. })
  71. return;
  72. }
  73. })
  74. }
  75. $scope.addImage = function (index) {
  76. listIndex = index;
  77. if ($scope.app) {
  78. var list = [
  79. {text: '<a class="action-sheet-push">拍照</a>'},
  80. {text: '<a class="action-sheet-push">从相册上传</a>'},
  81. ];
  82. var clickfunction = function (indx) {
  83. if (indx == 0) {
  84. $scope.openCamera();
  85. } else {
  86. getPictures();
  87. }
  88. return true;
  89. }
  90. } else {
  91. var files = document.getElementById('file');
  92. files.click();
  93. $(files).unbind().on('change', function (e) {
  94. // console.log(e);
  95. if ($scope.formList[listIndex].imagelist.length > 8) {
  96. $ionicPopup.alert({
  97. title: '提示',
  98. template: '最多只能上传9个文件!'
  99. });
  100. return;
  101. }
  102. $.each(e.target.files, function (i, file) {
  103. var url = null;
  104. if (window.createObjectURL != undefined) { // basic
  105. url = window.createObjectURL(file);
  106. } else if (window.URL != undefined) { // mozilla(firefox)
  107. url = window.URL.createObjectURL(file);
  108. } else if (window.webkitURL != undefined) { // webkit or chrome
  109. url = window.webkitURL.createObjectURL(file);
  110. }
  111. $scope.formList[listIndex].imagelist.push({title: file.name, photoName: url, originalName: url});
  112. });
  113. $scope.showLoadingToast();
  114. var data = new FormData();
  115. $.each(e.target.files, function (i, file) {
  116. data.append('file', file);
  117. });
  118. CommonService.mutipleUploadImage(data).then(function (res) {
  119. if (res.code == 3350) {
  120. angular.forEach(res.data, function (value) {
  121. $scope.formList[listIndex].imageSaveList.push({
  122. id: 0,
  123. title: value.title,
  124. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  125. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  126. photoName: value.photoName,
  127. originalName: value.originalName,
  128. sourceName: value.sourceName,
  129. sourceSize: value.sourceSize
  130. })
  131. })
  132. }
  133. // console.log(temp);
  134. // console.log($scope.formList[listIndex]);
  135. })
  136. })
  137. $scope.hideLoadingToast();
  138. return true;
  139. }
  140. $ionicActionSheet.show({
  141. buttons: list,
  142. cancelText: '取消',
  143. buttonClicked: clickfunction
  144. })
  145. }
  146. $scope.openCamera = function () {
  147. if ($scope.formList[listIndex].imagelist.length >= 9) {
  148. if ($scope.app) {
  149. UtilService.showMess("最多选取9张图片");
  150. } else {
  151. CommonService.showMessage("最多选取9张图片", $scope)
  152. }
  153. return;
  154. }
  155. UtilService.getPicture(1).then(function (results) {
  156. $scope.showLoadingToast();
  157. $scope.formList[listIndex].imagelist.push({photoName: results, originalName: results})
  158. UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) {
  159. angular.forEach(response, function (value) {
  160. $scope.formList[listIndex].imageSaveList.push({
  161. id: 0,
  162. title: value.title,
  163. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  164. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  165. photoName: value.photoName,
  166. originalName: value.originalName,
  167. sourceName: value.sourceName,
  168. sourceSize: value.sourceSize
  169. })
  170. })
  171. $scope.hideLoadingToast();
  172. }, function () {
  173. $scope.hideLoadingToast();
  174. if ($scope.app) {
  175. UtilService.showMess("网络不给力,请重试");
  176. } else {
  177. CommonService.showMessage("网络不给力,请重试", $scope)
  178. }
  179. });
  180. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  181. }, function (err) {
  182. });
  183. }
  184. var getPictures = function () {
  185. if (device.platform == "Android") {
  186. verifyStorage();
  187. } else {
  188. getPic();
  189. }
  190. };
  191. var verifyStorage = function () {
  192. window.imagePicker.verifyStorage(
  193. function (results) {
  194. if (results == "1") {
  195. getPic();
  196. }
  197. }, function (error) {
  198. }
  199. );
  200. };
  201. var getPic = function () {
  202. var imagelistLength = $scope.formList[listIndex].imagelist.length;
  203. if (imagelistLength >= 9) {
  204. if ($scope.app) {
  205. UtilService.showMess("最多选取9个文件");
  206. } else {
  207. CommonService.showMessage("最多选取9个文件", $scope)
  208. }
  209. return;
  210. }
  211. UtilService.getPictureList(9 - imagelistLength).then(function (results) {
  212. $scope.showLoadingToast();
  213. angular.forEach(results, function (val, i) {
  214. $scope.formList[listIndex].imagelist.push({photoName: val, originalName: val});
  215. })
  216. UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) {
  217. angular.forEach(response, function (value) {
  218. if (value.status) {
  219. $scope.formList[listIndex].imageSaveList.push({
  220. id: 0,
  221. title: "",
  222. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  223. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  224. photoName: value.photoName,
  225. originalName: value.originalName,
  226. sourceName: value.sourceName,
  227. sourceSize: value.sourceSize
  228. });
  229. }
  230. })
  231. $scope.hideLoadingToast();
  232. }, function () {
  233. $scope.hideLoadingToast();
  234. if ($scope.app) {
  235. UtilService.showMess("网络不给力,请重试");
  236. } else {
  237. CommonService.showMessage("网络不给力,请重试", $scope)
  238. }
  239. });
  240. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  241. }, function (err) {
  242. });
  243. };
  244. //删除图片
  245. $scope.deletePhoto = function (index, outerIndex) {
  246. console.log($scope.formList[outerIndex]);
  247. if ($scope.formList[outerIndex].imageSaveList[index].id != 0) {
  248. $scope.formList[outerIndex].imageSaveList[index].isenabled = 2;
  249. $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]);
  250. }
  251. $scope.formList[outerIndex].imagelist.splice(index, 1);
  252. $scope.formList[outerIndex].imageSaveList.splice(index, 1);
  253. // console.log($scope.formList[outerIndex].imagelist);
  254. // console.log($scope.formList[outerIndex].imageSaveList);
  255. // console.log($scope.formList[outerIndex].imageDeleteList);
  256. }
  257. });