//star
var mapData;
$(document).ready(function(){
	var arry;
    var stepW = 32;
    var description = new Array("");
    var stars = $("#star > li");
    var descriptionTemp;
    $("#showb").css("width",0);
    stars.each(function(i){
        $(stars[i]).click(function(e){
            var n = i+1;
            $("#showb").css({"width":stepW*n});
            descriptionTemp = description[i];
            $(this).find('a').blur();
            $("#score").val(n);
            return stopDefault(e);
            return descriptionTemp;
        });
    });
    var contextPath=$("#contextPath").val();
    var organizationId = $("#organizationId").val();
	$.ajax({
		type: "post",
		url: contextPath+"/wechat/appuser/getpjdesc",
		data:{organizationId:organizationId},
		async: false,
		success: function(data){
			mapData=data;
		},
		error: function(){
		}
	});
    
});

function stopDefault(e){
    if(e && e.preventDefault)
           e.preventDefault();
    else
           window.event.returnValue = false;
    return false;
};

function savePingjia(){
	var contextPath=$("#contextPath").val();
	var score = $("#score").val();
	var remark = $("#remark").val();
	var orderNum = $("#orderNum").val();
	var description=""
	var descriptionINfo=$(".description");
	$.each(descriptionINfo,function(index,obj){
		var this_=$(obj);
		if(this_.hasClass("xz")){
			description += this_.attr("inf")+","
		}
	});
	if(!score){
		alert("您还未对师傅评分，请评分之后再提交。");
		return false;
	}else{
		if("1"==score || "2"==score || "3"==score){
			if(description==""){
				alert("您还未对师傅评价，请评价之后再提交。");
				return false;
			}
		}
		
		$.ajax({
			type: "post",
			url: contextPath+"/wechat/appuser/savaPingjia",
			data:{"score":score,
				  "remark":remark,
				  "orderNum":orderNum,
				  "description":description},
			traditional: true,
			success: function(data){
				if(data.data == "success"){
					/* if(data.id!=null&&data.id!=""){
						alert("评价成功,获取优惠券成功!");
						window.location.href="<c:url value='/wechat/appuser/oneyhq?couponsId="+data.id+"&type=1&userid="+data.userid+"'></c:url>";
					}else{
						alert("评价成功,优惠券已经领完了，敬请期待!");
						WeixinJSBridge.call('closeWindow');	
					} */
					alert("评价成功!");
					WeixinJSBridge.call('closeWindow');
				}else{
					alert("评价失败，请稍后再评价!");
					WeixinJSBridge.call('closeWindow');
				}
			},
			error: function(){
				//请求出错处理
				alert("评价失败，请稍后再评价!");
			}
		});
	}
	$("#saveInfo").attr("disabled","disabled");
	$("#saveInfo").css("background-color","#E6E6E6");
}

function getPingjiaDesc(star){
	var str="";
	var thisMap="";
	if(star==1){
		thisMap=mapData.star1;
	}
	if(star==2){
		thisMap=mapData.star2;
	}
	if(star==3){
		thisMap=mapData.star3;
	}
	if(star==4){
		thisMap=mapData.star4;
	}
	if(star==5){
		thisMap=mapData.star5;
	}
	$(".clearfix").html("");
	$.each(thisMap,function(index,obj){
		str+="<li><a href='javascript: void(0);'class='description' inf="+obj.description+">"+obj.description+"</a></li>";
	})
	$(".clearfix").html(str);
	$(".clearfix").css("display","block");
	$(".description").click(function(){
    	var this_=$(this);
  		if(this_.hasClass("xz")){
  			this_.removeClass("xz");
  		}
  		else{
  			this_.addClass("xz");
  		}
	});
}

