productDetailCtrl.js 4.8 KB
(function (angular) {
    function productDetailCtrl($scope,productService,$stateParams,$state,$http,$sce,$uibModal) {
    	$scope.productId = $stateParams.id;
    	$scope.type = $stateParams.type;
    	$scope.showEdit = false;
    	$scope.qrCodeCheck = false;
        switch($scope.type){
            case '1':
                $scope.source = '产品管理';
                $scope.name = '查看与修改';
                break;
            case '2':
                $scope.source = '产品查看';
                $scope.name = '查看';
                break;
            case '3':
                $scope.source = '产品维护';
                $scope.name = '查看';
                break;
        }


    	$scope.getProductById=function(){
    		productService.getProductById({'id':$scope.productId},function(res){
    			$scope.productInfo = res.data;
    			if ($scope.type == 3 && $scope.productInfo.status == 5) {
    				$scope.qrCodeCheck = true;
    			}
    			
    			if($scope.productInfo.status == 5){
    				// 已经上架不给修改
    				$scope.showEdit = false;
    			}else if($scope.type == 2 || ($scope.type == 3 && ($scope.productInfo.status != 1 && $scope.productInfo.status != 3))){
					// 产品查看不行 产品维护时候不是待供应商完善和审核不通过不给修改
    				$scope.showEdit = false;
				}else{
					$scope.showEdit = true;
				}
    		$scope.productInfo.description = $sce.trustAsHtml($scope.productInfo.description);
    		});
    	};
    	
    	
    	/*$scope.toPreview = function (){
    		console.log("点击图像")
    	}
    	*/
    	//点击图片时放大显示图片
        $scope.changePic=function($event){
        	var img=$event.srcElement || $event.target;
        	angular.element("#bigimage")[0].src=img.src;
        	// console.log("点击"+angular.element("#bigimage")[0]);
        	angular.element("#js-imgview")[0].style.display="block";
        	angular.element("#js-imgview-mask")[0].style.display="block";
        }
      //点击图片时放小显示图片
        $scope.closePic =function(){
        	angular.element("#js-imgview")[0].style.display="none";
        	angular.element("#js-imgview-mask")[0].style.display="none";
        	
        }
    	
    	$scope.toEdit = function(){
    		$state.go('electronicDirectory.productUpdate',{id:$scope.productId,type:$scope.type});
    	};

        $scope.openAuditDialog = function(id){
        	console.log(id)
            var params = {};
            params.ids = id;
            var modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'productDetailAuditModal',
                controller: 'productDetailAuditCtrl',
                size: '40sm',
                resolve: {
                    params: params
                }
            }).result.then(function(){
                $scope.getProductById();
            });
        };

    	$scope.backClickEvent=function(){
    		switch($scope.type){
    			case '1':
    				$state.go('electronicDirectory.productManager',{supplierCode:''});
    				break;
    			case '2':
                    $state.go('electronicDirectory.productView');
                    break;
    			case '3':
    				$state.go('electronicDirectory.productMaintenance');
    				break;
    		}
        };
        
        $scope.qrCodeCheckOut = function () {
        	if ($scope.type == 2) {
        		$scope.qrCodeCheck = true;
        	} 
        }
        
    	$scope.init=function(){
    		$scope.getProductById();
    		 $scope.qrCodeCheckOut();
    		$scope.qrImage = 'setmining/productInfo/qrcode?id='+$scope.productId;
    	};
    	$scope.init();
    }

    function productDetailAuditCtrl($scope, $uibModalInstance, productService, params){
        $scope.auditSelect = '4';
        $scope.confirm = function(queryParams) {
            $scope.isWorking = true;
            params.status = $scope.auditSelect;
            params.auditReason = $scope.auditReason;
            productService.changeStatus(params, function(result){
                if(result.returnCode == '0'){
                    $uibModalInstance.close();
                    swal({type: 'success',title: '',text: result.message,closeOnConfirm: false,confirmButtonText: "确定",timer: 3000});
                }else{
                    $uibModalInstance.close();
                    swal({type: 'error',title: '',text: result.message,closeOnConfirm: false,confirmButtonText: "确定",timer: 3000 });
                }
                $scope.isWorking = false;
            });

        };
        $scope.cancel = function() {
            $uibModalInstance.dismiss('cancel');
            dtInstance.query();
        };
    }
    angular.module('electronicDirectory',['ngSanitize'])
        .controller('productDetailCtrl', productDetailCtrl)
    	.controller('productDetailAuditCtrl', productDetailAuditCtrl);
})(angular);