warehouseCtrl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. angular.module('app.basic')
  2. .controller("warehouseCtrl", function($scope, $rootScope, $uibModal, $http, $location, $state, $stateParams, warehouseService, enumService, StorehouseService, agentStorehouseService ) {
  3. $scope.ware = {storehouseId:"",warehouseName:""};
  4. //判断是否是代储点货物信息
  5. if($stateParams.libraryType == '1'){
  6. $scope.libraryType = $stateParams.libraryType;
  7. }else{
  8. $scope.libraryType = '0';
  9. }
  10. $scope.getStorehouseDate = function() {
  11. StorehouseService.getPageInfo(null, null, null, $rootScope.orgInfo.orgId, $scope.libraryType,null).then(function(data){
  12. $scope.storeHouseList = data.list;
  13. },function(data){
  14. console.log(data);
  15. });
  16. // 获取仓房列表
  17. StorehouseService.getStorehouseList($rootScope.orgInfo.orgId, $scope.libraryType).then(function(data){
  18. $scope.storehouseObj = data.houseObj;
  19. },function(data){
  20. console.log(data);
  21. });
  22. }
  23. $scope.getStorehouseDate();
  24. $scope.loadWare = function(houseId) {
  25. warehouseService.getStorehouse($rootScope.orgInfo.orgId, houseId, $scope.libraryType).then(function(data){
  26. $scope.warelist = data.wareList; //下拉列表数据
  27. $scope.warehouseObj = data.wares; //查询数据列表货位信息转换
  28. },function (data) {
  29. console.log(data);
  30. });
  31. }
  32. $scope.loadWare(null);
  33. // 获取货位列表数据
  34. $scope.pageInfo = {pageNum : 1, pageSize : 10};
  35. $scope.loadData = function() {
  36. if($scope.libraryType == '1'){
  37. // 获取货位列表
  38. agentStorehouseService.getWareList($scope.pageInfo.pageNum, $scope.pageInfo.pageSize,$scope.agentDepotName).then(function(data){
  39. $scope.pageInfo = data;
  40. },function(data){
  41. console.log(data);
  42. });
  43. }else {
  44. warehouseService.getPageInfo($scope.pageInfo.pageNum, $scope.pageInfo.pageSize,
  45. $scope.ware, $rootScope.orgInfo.orgId, $scope.libraryType, null).then(function (data) {
  46. $scope.pageInfo = data;
  47. }, function (data) {
  48. console.log(data);
  49. });
  50. }
  51. }
  52. $scope.loadData();
  53. // 点击新增或者修改时弹出模态窗
  54. $scope.edit = function(id, btnType) {
  55. var uibModalInstance = $uibModal.open({
  56. size:'md',
  57. templateUrl: 'app/basic/warehouse/views/warehouse-edit.html',
  58. controller: 'warehouseCtrlEdit',
  59. resolve: {
  60. id : id,
  61. btnType : function(){return btnType;},
  62. libraryType : function(){return $scope.libraryType;}
  63. }
  64. });
  65. uibModalInstance.result.then(function (result) {
  66. $scope.loadData(); // 关闭模态框时刷新页面数据
  67. }, function (reason) {
  68. console.log(reason);
  69. });
  70. };
  71. // 删除一条记录
  72. $scope.remove = function(id,storehouseId) {
  73. // if (!confirm("确定要删除吗?")) {
  74. // return;
  75. // }
  76. warehouseService.remove(id,storehouseId).then(function(data){
  77. if (data.status == 'success') {
  78. alert("操作成功!");
  79. // 重新加载数据
  80. $scope.loadData();
  81. } else {
  82. alert("操作失败!");
  83. }
  84. },function(data){
  85. console.log(data);
  86. });
  87. };
  88. // 删除一条已有代储仓房
  89. $scope.removeAgentWare = function(id) {
  90. agentStorehouseService.removeAgentWare(id).then(function(data){
  91. if (data.status == 'success') {
  92. alert("操作成功!");
  93. // 重新加载数据
  94. $scope.loadData();
  95. } else {
  96. alert("操作失败!");
  97. }
  98. },function(data){
  99. console.log(data);
  100. });
  101. };
  102. // 翻页
  103. $scope.goPage = function(pageNum) {
  104. if ($scope.pageInfo.pageNum != pageNum && pageNum > 0) {
  105. $scope.pageInfo.pageNum = pageNum;
  106. $scope.loadData();
  107. }
  108. }
  109. })
  110. .controller("warehouseCtrlEdit", function(FileUploader, $scope, $rootScope, $http, $filter, $location, $uibModalInstance, $stateParams, id,
  111. agentDepotService, btnType, libraryType, warehouseService, StorehouseService, enumService, APP_CONFIG) {
  112. $scope.storehouseList;//仓房信息
  113. $scope.warehouse = {};//货物信息
  114. $scope.depotList = {};//粮库信息
  115. // 获取基础数据
  116. $scope.getBasicData = function() {
  117. $scope.pageInfo = {pageNum : 1, pageSize : 100};
  118. $scope.search = {storehouseId:""};
  119. //判断是否是代储点仓房信息
  120. if(libraryType == '1'){
  121. $scope.warehouse.libraryType = libraryType;
  122. agentDepotService.getAgentDepotHouse("","").then(function(data){
  123. $scope.depotList = data.map(function(item) {
  124. return {
  125. depotId: item.id,
  126. depotName: item.agentDepotName
  127. }
  128. });
  129. $scope.getHouseList($scope.warehouse.depotId);
  130. },function(data){
  131. console.log();
  132. });
  133. }else{
  134. libraryType = '0';
  135. StorehouseService.getPageInfo(null, null, null, $rootScope.orgInfo.orgId, $scope.libraryType, 1).then(function(data){
  136. $scope.storehouseList = data.list;
  137. },function(data){
  138. console.log(data);
  139. });
  140. $scope.warehouse.depotName = $rootScope.orgInfo.orgName;
  141. $scope.warehouse.depotId = $rootScope.orgInfo.orgId;
  142. $scope.warehouse.libraryType = "0";
  143. $scope.depotList = [{depotId: $rootScope.orgInfo.orgId, depotName: $rootScope.orgInfo.orgName}];
  144. }
  145. };
  146. //根据代储库获取仓房列表
  147. $scope.getHouseList = function(depotId) {
  148. StorehouseService.getAgentList(depotId,$rootScope.orgInfo.orgId,libraryType).then(function(data){
  149. $scope.storehouseList = data;
  150. },function(data){
  151. console.log(data);
  152. });
  153. };
  154. $scope.wlist = [];
  155. $scope.warehouseObj = function(houseId) {
  156. warehouseService.getStorehouse($rootScope.orgInfo.orgId, houseId, "0").then(function(data){
  157. $scope.wlist = data.wareList; //下拉列表数据
  158. },function(data){
  159. console.log(data);
  160. });
  161. }
  162. $scope.gethouse = function(houseId) {
  163. StorehouseService.findByStorehouse(houseId, $rootScope.orgInfo.orgId).then(function(data){
  164. $scope.basicStorehouse = data;
  165. },function(datas){
  166. console.log(datas);
  167. });
  168. }
  169. // 初始化模态窗口数据
  170. $scope.edit = function() {
  171. warehouseService.findByWarehouse(id).then(function(datas){
  172. $scope.warehouse = datas;
  173. $scope.warehouse.warehouseUseTime = $filter('date')($scope.warehouse.warehouseUseTime, "yyyy-MM-dd");
  174. if (btnType == '1') {
  175. $scope.isNotEdit = true;
  176. }
  177. $scope.getBasicData();
  178. if (id != "" && id != undefined) {
  179. $scope.warehouseObj($scope.warehouse.storehouseId);
  180. $scope.gethouse($scope.warehouse.storehouseId);
  181. }
  182. },function(datas){
  183. console.log(datas);
  184. });
  185. }
  186. $scope.edit();
  187. //去重
  188. $scope.warehouseCode = function(){
  189. if (id == "" || id == undefined) {
  190. id = 0;
  191. }
  192. warehouseService.findWarehouseCode($scope.warehouse.storehouseId, $scope.warehouse.warehouseCode, id, libraryType).then(function(data){
  193. if(data == '0'){
  194. alert("编码重复");
  195. $scope.warehouse.warehouseCode = "";
  196. }
  197. },function(data){
  198. console.log(data);
  199. });
  200. }
  201. // 货位编码最多只能输入2位数字
  202. $scope.checkUp = function() {
  203. var text = $scope.warehouse.warehouseCode;
  204. if (text != null && text != "") {
  205. var a = text.substring(text.length - 1, text.length);
  206. var reg = /^\d$/g;
  207. if (!reg.test(a)) {
  208. $scope.warehouse.warehouseCode = text.replace(a, "");
  209. }
  210. }
  211. }
  212. // 文件上传实例
  213. $scope.uploader = new FileUploader({
  214. url : APP_CONFIG.basicUrl + '/fileUpload/uploadFile',
  215. autoUpload : true, // 将文件添加到队列后自动上传
  216. formData : [{fileType:'image'}], // 与文件一起发送的数据
  217. removeAfterUpload : true, // 从队列上传后删除文件
  218. // 上传进度
  219. onProgressItem : function(fileItem, progress) {
  220. console.info("正在上传:" + progress + "%");
  221. },
  222. // 回调函数,在一个文件上传成功后触发
  223. onSuccessItem : function(fileItem, response, status, headers) {
  224. $scope.warehouse.wareImg = response;
  225. }
  226. });
  227. $.validator.addMethod("validThan0",function(value,element, params) {
  228. if(value == 0){
  229. return this.optional(element);
  230. }else{
  231. return this.optional(element) || true;
  232. }
  233. },"请输大于0的数!");
  234. $.validator.addMethod("validCapacity",function(value,element, params) {
  235. if(value == 0){
  236. return this.optional(element);
  237. }else{
  238. if($scope.warehouse.storehouseId != null && $scope.warehouse.storehouseId != ""){
  239. //先查询当前仓房下的货位数据
  240. $scope.warehouseObj($scope.warehouse.storehouseId);
  241. //除当前货位之外的其它货位容量之和
  242. var ware_sum = 0;
  243. //当前仓房的设计容量
  244. var cf_sum = $scope.basicStorehouse.designCapacity;
  245. for (var i = 0; i < $scope.wlist.length; i++) {
  246. if ($scope.warehouse.warehouseId != $scope.wlist[i].warehouseId) {
  247. ware_sum = parseFloat(ware_sum) + parseFloat($scope.wlist[i].warehouseCapacity);
  248. }
  249. }
  250. //新的货位总容量 = 除当前货位之外的其它货位容量之和 + 当前货位容量
  251. var this_sum_cr = parseFloat(ware_sum) + $scope.warehouse.warehouseCapacity;
  252. //如果新的总容量超过了仓房的设计容量,那么返回false
  253. if (parseFloat(this_sum_cr) >= parseFloat(cf_sum)) {
  254. return this.optional(element) || false;
  255. } else {
  256. return this.optional(element) || true;
  257. }
  258. }else{
  259. return this.optional(element) || true;
  260. }
  261. }
  262. },"请输大于0的数且要小于仓房的设计容量!");
  263. $.validator.addMethod("wareCode",function(value,element, params) {
  264. if(value == 0){
  265. return this.optional(element);
  266. }else{
  267. var text = $scope.warehouse.warehouseCode;
  268. var reg = /^[0-9]{2}/g;
  269. if (!reg.test(text)) {
  270. return this.optional(element) || false;
  271. } else {
  272. return this.optional(element) || true;
  273. }
  274. }
  275. },"货位编码必须是两位数字!");
  276. var validator;
  277. // 提交表单
  278. $scope.save = function() {
  279. validator = $("#warehouse-form").validate();
  280. if (validator.form()) {
  281. warehouseService.save($scope.warehouse, $rootScope.userInfo).then(function(data){
  282. if (data.status == 'success') {
  283. alert("保存成功!");
  284. } else {
  285. alert("保存失败!");
  286. }
  287. $scope.cancel();
  288. },function(data){
  289. console.log(data);
  290. });
  291. }
  292. }
  293. $scope.change = function(){
  294. validator = $("#warehouse-form").validate();
  295. }
  296. $.validator.addMethod("validThan0",function(value,element, params) {
  297. if(value == 0){
  298. return this.optional(element);
  299. }else{
  300. return this.optional(element) || true;
  301. }
  302. },"请输大于0的数!");
  303. // 关闭模态窗口
  304. $scope.cancel = function() {
  305. $uibModalInstance.close();
  306. }
  307. //出入库状态
  308. $scope.crkzt = [
  309. {"id":"1","name":"空仓"},
  310. {"id":"2","name":"入库中"},
  311. {"id":"3","name":"封仓"},
  312. {"id":"4","name":"出库中"}
  313. ];
  314. })