opinionController.js 1.42 KB
angular.module('myApp')
	.controller('opinionController',['$scope','$rootScope','dingdaService','$state','globalService','$stateParams',
	function($scope,$rootScope,dingdaService,$state,globalService,$stateParams){
		
		$scope.opinion = "";
        
		$scope.submit = function() {
			if($scope.opinion.length == 0) {
				return;
			}
			if($scope.opinion.length > 200) {
	            layer.open({
	                content: "超出字数限制",
	                time:2
	            });
			} else {
				var phoneType = navigator.userAgent.match(/\(.*?\)/);
				var wx = navigator.userAgent.match(/MicroMessenger\/.*?[ ]/);
				
//				alert(phoneType)
				var data = {
					content : $scope.opinion ,
          			latitude : $stateParams.latitude ,
        			longitude : $stateParams.longitude ,
					phoneType : phoneType[0] ,
					systemType : wx[0]
				}
				
				
				dingdaService.comment(data).success(function(data , status) {
					if(data.meta.code != 200) {
						layer.open({
			                content: data.meta.message,
			                time:2
			            });
			            return;
					}
		            layer.open({
		                content: "评论成功",
		                time:2
		            });
                    setTimeout(function() {
                    	location.reload();
                    } , 300);
					history.back();
				}).error(function(data , status){
					alert(JSON.stringify(data))
					
				})
			}
		}
		
}]);