| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- angular.module('app.basic')
- .controller("warehouseCtrl", function($scope, $rootScope, $uibModal, $http, $location, $state, $stateParams, warehouseService, enumService, StorehouseService, agentStorehouseService ) {
- $scope.ware = {storehouseId:"",warehouseName:""};
- //判断是否是代储点货物信息
- if($stateParams.libraryType == '1'){
- $scope.libraryType = $stateParams.libraryType;
- }else{
- $scope.libraryType = '0';
- }
- $scope.getStorehouseDate = function() {
- StorehouseService.getPageInfo(null, null, null, $rootScope.orgInfo.orgId, $scope.libraryType,null).then(function(data){
- $scope.storeHouseList = data.list;
- },function(data){
- console.log(data);
- });
- // 获取仓房列表
- StorehouseService.getStorehouseList($rootScope.orgInfo.orgId, $scope.libraryType).then(function(data){
- $scope.storehouseObj = data.houseObj;
- },function(data){
- console.log(data);
- });
- }
- $scope.getStorehouseDate();
- $scope.loadWare = function(houseId) {
- warehouseService.getStorehouse($rootScope.orgInfo.orgId, houseId, $scope.libraryType).then(function(data){
- $scope.warelist = data.wareList; //下拉列表数据
- $scope.warehouseObj = data.wares; //查询数据列表货位信息转换
- },function (data) {
- console.log(data);
- });
- }
- $scope.loadWare(null);
- // 获取货位列表数据
- $scope.pageInfo = {pageNum : 1, pageSize : 10};
- $scope.loadData = function() {
- if($scope.libraryType == '1'){
- // 获取货位列表
- agentStorehouseService.getWareList($scope.pageInfo.pageNum, $scope.pageInfo.pageSize,$scope.agentDepotName).then(function(data){
- $scope.pageInfo = data;
- },function(data){
- console.log(data);
- });
- }else {
- warehouseService.getPageInfo($scope.pageInfo.pageNum, $scope.pageInfo.pageSize,
- $scope.ware, $rootScope.orgInfo.orgId, $scope.libraryType, null).then(function (data) {
- $scope.pageInfo = data;
- }, function (data) {
- console.log(data);
- });
- }
- }
- $scope.loadData();
- // 点击新增或者修改时弹出模态窗
- $scope.edit = function(id, btnType) {
- var uibModalInstance = $uibModal.open({
- size:'md',
- templateUrl: 'app/basic/warehouse/views/warehouse-edit.html',
- controller: 'warehouseCtrlEdit',
- resolve: {
- id : id,
- btnType : function(){return btnType;},
- libraryType : function(){return $scope.libraryType;}
- }
- });
- uibModalInstance.result.then(function (result) {
- $scope.loadData(); // 关闭模态框时刷新页面数据
- }, function (reason) {
- console.log(reason);
- });
- };
- // 删除一条记录
- $scope.remove = function(id,storehouseId) {
- // if (!confirm("确定要删除吗?")) {
- // return;
- // }
- warehouseService.remove(id,storehouseId).then(function(data){
- if (data.status == 'success') {
- alert("操作成功!");
- // 重新加载数据
- $scope.loadData();
- } else {
- alert("操作失败!");
- }
- },function(data){
- console.log(data);
- });
- };
- // 删除一条已有代储仓房
- $scope.removeAgentWare = function(id) {
- agentStorehouseService.removeAgentWare(id).then(function(data){
- if (data.status == 'success') {
- alert("操作成功!");
- // 重新加载数据
- $scope.loadData();
- } else {
- alert("操作失败!");
- }
- },function(data){
- console.log(data);
- });
- };
-
- // 翻页
- $scope.goPage = function(pageNum) {
- if ($scope.pageInfo.pageNum != pageNum && pageNum > 0) {
- $scope.pageInfo.pageNum = pageNum;
- $scope.loadData();
- }
- }
- })
- .controller("warehouseCtrlEdit", function(FileUploader, $scope, $rootScope, $http, $filter, $location, $uibModalInstance, $stateParams, id,
- agentDepotService, btnType, libraryType, warehouseService, StorehouseService, enumService, APP_CONFIG) {
- $scope.storehouseList;//仓房信息
- $scope.warehouse = {};//货物信息
- $scope.depotList = {};//粮库信息
- // 获取基础数据
- $scope.getBasicData = function() {
- $scope.pageInfo = {pageNum : 1, pageSize : 100};
- $scope.search = {storehouseId:""};
- //判断是否是代储点仓房信息
- if(libraryType == '1'){
- $scope.warehouse.libraryType = libraryType;
- agentDepotService.getAgentDepotHouse("","").then(function(data){
- $scope.depotList = data.map(function(item) {
- return {
- depotId: item.id,
- depotName: item.agentDepotName
- }
- });
- $scope.getHouseList($scope.warehouse.depotId);
- },function(data){
- console.log();
- });
- }else{
- libraryType = '0';
- StorehouseService.getPageInfo(null, null, null, $rootScope.orgInfo.orgId, $scope.libraryType, 1).then(function(data){
- $scope.storehouseList = data.list;
- },function(data){
- console.log(data);
- });
- $scope.warehouse.depotName = $rootScope.orgInfo.orgName;
- $scope.warehouse.depotId = $rootScope.orgInfo.orgId;
- $scope.warehouse.libraryType = "0";
- $scope.depotList = [{depotId: $rootScope.orgInfo.orgId, depotName: $rootScope.orgInfo.orgName}];
- }
- };
- //根据代储库获取仓房列表
- $scope.getHouseList = function(depotId) {
- StorehouseService.getAgentList(depotId,$rootScope.orgInfo.orgId,libraryType).then(function(data){
- $scope.storehouseList = data;
- },function(data){
- console.log(data);
- });
- };
- $scope.wlist = [];
- $scope.warehouseObj = function(houseId) {
- warehouseService.getStorehouse($rootScope.orgInfo.orgId, houseId, "0").then(function(data){
- $scope.wlist = data.wareList; //下拉列表数据
- },function(data){
- console.log(data);
- });
- }
- $scope.gethouse = function(houseId) {
- StorehouseService.findByStorehouse(houseId, $rootScope.orgInfo.orgId).then(function(data){
- $scope.basicStorehouse = data;
- },function(datas){
- console.log(datas);
- });
- }
- // 初始化模态窗口数据
- $scope.edit = function() {
- warehouseService.findByWarehouse(id).then(function(datas){
- $scope.warehouse = datas;
- $scope.warehouse.warehouseUseTime = $filter('date')($scope.warehouse.warehouseUseTime, "yyyy-MM-dd");
- if (btnType == '1') {
- $scope.isNotEdit = true;
- }
- $scope.getBasicData();
- if (id != "" && id != undefined) {
- $scope.warehouseObj($scope.warehouse.storehouseId);
- $scope.gethouse($scope.warehouse.storehouseId);
- }
- },function(datas){
- console.log(datas);
- });
- }
- $scope.edit();
- //去重
- $scope.warehouseCode = function(){
- if (id == "" || id == undefined) {
- id = 0;
- }
- warehouseService.findWarehouseCode($scope.warehouse.storehouseId, $scope.warehouse.warehouseCode, id, libraryType).then(function(data){
- if(data == '0'){
- alert("编码重复");
- $scope.warehouse.warehouseCode = "";
- }
- },function(data){
- console.log(data);
- });
- }
-
- // 货位编码最多只能输入2位数字
- $scope.checkUp = function() {
- var text = $scope.warehouse.warehouseCode;
- if (text != null && text != "") {
- var a = text.substring(text.length - 1, text.length);
- var reg = /^\d$/g;
- if (!reg.test(a)) {
- $scope.warehouse.warehouseCode = text.replace(a, "");
- }
- }
- }
-
- // 文件上传实例
- $scope.uploader = new FileUploader({
- url : APP_CONFIG.basicUrl + '/fileUpload/uploadFile',
- autoUpload : true, // 将文件添加到队列后自动上传
- formData : [{fileType:'image'}], // 与文件一起发送的数据
- removeAfterUpload : true, // 从队列上传后删除文件
- // 上传进度
- onProgressItem : function(fileItem, progress) {
- console.info("正在上传:" + progress + "%");
- },
- // 回调函数,在一个文件上传成功后触发
- onSuccessItem : function(fileItem, response, status, headers) {
- $scope.warehouse.wareImg = response;
- }
- });
-
- $.validator.addMethod("validThan0",function(value,element, params) {
- if(value == 0){
- return this.optional(element);
- }else{
- return this.optional(element) || true;
- }
- },"请输大于0的数!");
-
- $.validator.addMethod("validCapacity",function(value,element, params) {
- if(value == 0){
- return this.optional(element);
- }else{
- if($scope.warehouse.storehouseId != null && $scope.warehouse.storehouseId != ""){
- //先查询当前仓房下的货位数据
- $scope.warehouseObj($scope.warehouse.storehouseId);
- //除当前货位之外的其它货位容量之和
- var ware_sum = 0;
- //当前仓房的设计容量
- var cf_sum = $scope.basicStorehouse.designCapacity;
- for (var i = 0; i < $scope.wlist.length; i++) {
- if ($scope.warehouse.warehouseId != $scope.wlist[i].warehouseId) {
- ware_sum = parseFloat(ware_sum) + parseFloat($scope.wlist[i].warehouseCapacity);
- }
- }
- //新的货位总容量 = 除当前货位之外的其它货位容量之和 + 当前货位容量
- var this_sum_cr = parseFloat(ware_sum) + $scope.warehouse.warehouseCapacity;
- //如果新的总容量超过了仓房的设计容量,那么返回false
- if (parseFloat(this_sum_cr) >= parseFloat(cf_sum)) {
- return this.optional(element) || false;
- } else {
- return this.optional(element) || true;
- }
- }else{
- return this.optional(element) || true;
- }
- }
- },"请输大于0的数且要小于仓房的设计容量!");
- $.validator.addMethod("wareCode",function(value,element, params) {
- if(value == 0){
- return this.optional(element);
- }else{
- var text = $scope.warehouse.warehouseCode;
- var reg = /^[0-9]{2}/g;
- if (!reg.test(text)) {
- return this.optional(element) || false;
- } else {
- return this.optional(element) || true;
- }
- }
- },"货位编码必须是两位数字!");
- var validator;
- // 提交表单
- $scope.save = function() {
- validator = $("#warehouse-form").validate();
- if (validator.form()) {
- warehouseService.save($scope.warehouse, $rootScope.userInfo).then(function(data){
- if (data.status == 'success') {
- alert("保存成功!");
- } else {
- alert("保存失败!");
- }
- $scope.cancel();
- },function(data){
- console.log(data);
- });
- }
- }
-
- $scope.change = function(){
- validator = $("#warehouse-form").validate();
- }
-
- $.validator.addMethod("validThan0",function(value,element, params) {
- if(value == 0){
- return this.optional(element);
- }else{
- return this.optional(element) || true;
- }
- },"请输大于0的数!");
-
- // 关闭模态窗口
- $scope.cancel = function() {
- $uibModalInstance.close();
- }
- //出入库状态
- $scope.crkzt = [
- {"id":"1","name":"空仓"},
- {"id":"2","name":"入库中"},
- {"id":"3","name":"封仓"},
- {"id":"4","name":"出库中"}
- ];
- })
|