function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}
$(function () {
    GetEvaluation();
   });
///声明常用变量
var PageIndex = 1;
var PageSize = 5;
var Order = "Evaluation_Date";
var OrderType = "desc";
var count = 0;
///异步查询评价
function GetEvaluation() {
    $("#log").show();
    var tid = $("#Tid").val();
    var sqlwhere = " and Evaluation_TCID='"+tid+"'" ;
    var para = "sqlwhere=" + sqlwhere + "&&PageIndex=" + PageIndex + "&&PageSize=" + PageSize + "&&orderfile=" + Order + "&&ordertype=" + OrderType + "&&status=2";
    getAjax("/Mall/Evaluation.ashx", para, function (data) {
        if (data != "0") {
            var obj = eval('(' + data + ')')
            count = obj.count;
            var json = eval('(' + obj.str + ')')
            $("#Page").show();
            textHtml(json);
            $("#log").hide();
        } else {
            $("#Page").hide();
            $("#Evaltext").html("<tr><td  colspan='2'>暂无信息</td></tr>");
            $("#log").hide();
        }
    });
}

///数据转换成html
function textHtml(data) {
    var str = "";
    for (var i = 0; i < data.length; i++) {
        var img = starImg(data[i].Evaluation_Star);

        str += "<li><div class=\"noter-pic\"><img class=\"picImg\" src=\"/Mall/User_Image.ashx?id=" + data[i].Evaluation_UserID + "\" height=\"50\" width=\"50\"></div><div class=\"of\"><span class=\"fl\"><font class=\"fsize12 c-blue\">"+data[i].Evaluation_UserName+"</font><font class=\"fsize12 c-999 ml5\">评论：</font></span></div>";
        str += "<div class=\"noter-txt mt5\"><p>" + data[i].Evaluation_Content + "</p></div><div class=\"of mt5\"><span class=\"fr\"><font class=\"fsize12 c-999 ml5\">" + ChangeDateFormat(data[i].Evaluation_Date) + "</font></span></div></li>";
//        str += "<tr>";
//        str += "<td class=\"td1\"> <img style=\"margin-bottom: 5px;\" src=\"/Mall/User_Image.ashx?id=" + data[i].Evaluation_UserID + "\" width='59' height='59' /><br /> <span>" + data[i].Evaluation_UserName + "</span></td><td valign='top'><img  src=\"" + img + "\" /><br /><br /> <span>" + data[i].Evaluation_Content + "</span></td>";
//        str += "</tr>";
    }
    if (str=="") {
    $("#Page").hide();
        str = "<li>暂无消息！</li>";
    }

    $("#Evaltext").html(str);
    //document.getElementById("Evaltext").innerHTML=str;
   // alert(document.getElementById("Evaltext").innerHTML);
    $("#page_input").val(PageIndex);
}
///判断星级 显示图片
function starImg(value) {
    if (value == 1) {
        return "/Template/default/Images/start_04.gif";
    } else if (value == 2) {
        return "/Template/default/Images/no_01.gif";
    }else if (value == 3) {
        return "/Template/default/Images/no_02.gif";
    }
    else if (value == 4) {
        return "/Template/default/Images/no_03.gif";
    }
    else {
        return "/Template/default/Images/sm_025.gif";
    }
}

$("#very").hide();
var star = "";
//鼠标移出
function imgreplay() {
    imgover(star);
}
//鼠标点击
function onclickimg(value) {
    star = value;
    imgover(value);
}
//鼠标滑过
function imgover(value) {
    $("#imgul").find('li').each(function () { $(this).find('img').attr('src', "/Template/default/Images/bai.png"); });
    $("#very").show();
    var src = "";
    //小于3时
    if (value < 3) {
        src = "/Template/default/Images/hei.png";
        $("#very").html("不满意");
        replaceImg(value, src);
    } else if (value > 2 && value < 5) {
        src = "/Template/default/Images/huang.gif";
        $("#very").html("一般");
        replaceImg(value, src);
    } else {
        src = "/Template/default/Images/hong.gif";
        $("#very").html("很满意");
        replaceImg(value, src);
    }
}
//图片替换
function replaceImg(value, src) {
    for (var i = 1; i <= value; i++) {
        $("#img" + i).attr("src", src);
    }
}
//添加评价
function AddEval() {
    var log = $("#login").html();
    if (log != undefined) {
        if (log.indexOf("您好") < 0) {
            return LoginShow();
         
        }
    }
   
    var Evaluation_TCID = $("#Tid").val();
    var Evaluation_TCName = $("#name").html();
    if (Evaluation_TCName == undefined) {
        Evaluation_TCName = "1";
    }
    var Evaluation_Content = $("#Evaluation_Content").val();
//    if (star == "") {
//        return alert("请选择满意度");
//    }
    if (Evaluation_Content.length <= 0) {
        return alert("评价不能为空!");
    }
    var param = "Evaluation_TCID=" + Evaluation_TCID + "&&Evaluation_TCName=" + Evaluation_TCName + "&&status=1&&Evaluation_Star=5&&Evaluation_Content=" + Evaluation_Content;
    getAjax("/Mall/Evaluation.ashx", param, function (rs) {
        if (rs == "1") {
            alert("评论成功");
            $("#Evaluation_Content").val("");
            GetEvaluation();
            //location.reload();
        } else if (rs == "3") {
            alert("评论成功,管理员已开启审核功能,请等待管理员审核");
            $("#Evaluation_Content").val("");
            GetEvaluation();
            //location.reload();
        }
        else {
            alert("评价失败,请稍后再试");
        }
    });
}

///上一页
function PageUp() {
    if (PageIndex > 1) {
        PageIndex--;
    }
    GetEvaluation();
}
///下一页
function PageDown() {
    var PageCount = count / PageSize;
    if ((count % PageSize)!=0) {
        PageCount++;
    }
    if (PageIndex + 1 > PageCount) {
        alert("已经是最后一页");
        return ;
    }
    if (PageIndex >0) {
        PageIndex++
    }
    GetEvaluation();
}
///页面跳转
function goPage() {
    var pagenum = $("#page_input").val();
    if (pagenum <= 0) {
        alert("页码不能小于等于0"); return;
    }
    PageIndex = pagenum;
    GetEvaluation();
}

//时间转换
function ChangeDateFormat(cellval) {
    try {
        var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate;
    } catch (e) {
        return "";
    }
}


