addAppealCtrl.js 5.04 KB
(function (angular) {
    function addAppealCtrl($scope,complainSuggestService,$stateParams,$state,$http,$sce,Upload) {
    	$scope.param = $stateParams;
    	$scope.saveSubmiting = false;
    	
    	$scope.imageArr = [];
    	$scope.videoUrl = null;


    	$scope.saveInfo=function(){
    		var infoForm = $scope.infoForm;
    		// console.log(infoForm)
            if(!$scope.hasSelectTag && $scope.complainSuggestType == 1){
                $scope.isInValidate = true;
                return false;
            }
            if($scope.complainSuggestType == 1 && $scope.imageArr.length == 0 && !$scope.videoUrl){
                $scope.isInValidate = true;
                return false;
            }
    		if(infoForm.$invalid){
                $scope.isInValidate = true;
                return false;
            }
    		$scope.submitInfo();
    	};
    	
    	$scope.submitInfo = function(){
    		if($scope.saveSubmiting){
    			return;
    		}
    		$scope.saveSubmiting = true;
    		var params = {};
    		params.orderCode = $scope.param.orderCode;
    		params.productCode = $scope.param.productCode;
            params.type = 3;
            params.userPhone = $scope.info.supplierPhone;
    		params.description = $scope.info.description;
    		var imgList = [];
    		for(var i = 0;i<$scope.imageArr.length;i++){
    			imgList.push($scope.imageArr[i].imgSrc);
    		}
    		params.imgList = imgList;
    		params.videoUrl = $scope.videoUrl;
    		params.loss = $scope.info.loss;
    		complainSuggestService.add(params,function(res){
    			$scope.saveSubmiting = false;
    			if(res.returnCode == 0){
    				swal({type: 'success',title: '',text: res.message||'提交成功',showConfirmButton:false,timer: 1500,allowOutsideClick: false},function(){
                        window.sweetAlert.close();
                        $scope.backTo();
                    });
    			}else{
    				swal({type: 'error',title: '',text: res.message||'操作失败',timer: 1500,allowOutsideClick: false},function(){
                        window.sweetAlert.close();
                    });
    			}
            });
    	};
		// 统一弹窗
		function popTips(type, text, timer) {
			timer = timer || 1000
			swal({
				type: type,
				title: '',
				html: true,
				text: text,
				showConfirmButton: false,
				timer: timer
			  });
		}
        /**
		 * 上传图片
		 * */
		$scope.uploadImage=function(file, errFiles){
			if(file == null){
				if(errFiles != null && errFiles.length > 0){
					console.log(errFiles)
					// $scope.imgError = true;
					popTips('error', '只能上传800KB以内的PNG,JPG格式的图片')
				}
				return;
			}
            if(file.size > 800 * 1024 || !/^image\/(jpg|png|jpeg)+$/.test(file.type)){
				// $scope.imgError = true;
				popTips('error', '只能上传800KB以内的PNG,JPG格式的图片')
                return;
            }
			// $scope.imgError = false;
			$scope.showLoadingImg = true;
			Upload.upload({
                url: 'common/uploadImage',
                //上传的同时带的参数
                //data: { 'username': $scope.username },
                file: file
            }).success(function (data, status, headers, config) {
            	if(data.returnCode == 0){
            		$scope.imageArr.push({'imgSrc':data.data});//data.data
            	}
                $scope.showLoadingImg = false;
            }).error(function (data, status, headers, config) {
                $scope.showLoadingImg = false;
            });
		};
		/**
		 * 删除图片
		 */
		$scope.delImg = index => {
			$scope.imageArr.splice(index,1)
		}
		$scope.uploadVideo=function(file, errFiles){
			if(file == null){
				if(errFiles != null && errFiles.length > 0){
					console.log(errFiles);
					// $scope.videoError = true;
					popTips('error', '只能上传20MB以内的mp4,AVI,wma,rmvb格式的视频')
				}
				return;
			}
            if(file.size > 20 * 1024 * 1024){
				// $scope.videoError = true;
				popTips('error', '只能上传20MB以内的mp4,AVI,wma,rmvb格式的视频')
                return;
            }
			$scope.showLoadingVideo = true;
			Upload.upload({
                url: 'common/uploadVideo',
                //上传的同时带的参数
                //data: { 'username': $scope.username },
                file: file
            }).success(function (data, status, headers, config) {
            	if(data.returnCode == 0){
            		$scope.videoUrl = data.data;
            	}
                $scope.showLoadingVideo = false;
            }).error(function (data, status, headers, config) {
                $scope.showLoadingVideo = false;
            });
		};
		/**
		 * 删除视频
		 */
		$scope.delVideo = function() {
			$scope.videoUrl = null
		}
		$scope.trustUrl =function(url){
			return $sce.trustAsResourceUrl(url);
		}
		$scope.backTo=function(){
			$state.go('electronicDirectory.opinionFeedbackMaintenance');//2表示产品查看页
		}
    	$scope.init=function(){
    	};
    	$scope.init();
    }
    
    angular.module('electronicDirectory',['ngFileUpload','ngSanitize'])
        .controller('addAppealCtrl', addAppealCtrl);
})(angular);