﻿$(function() {

    $("#btn_so").click(function() {
        var orderID = $("#SearchOrder").val();
        if (orderID != null && orderID != "") {
            $.ajax({
                url: "/FrontwebHandler.ashx",
                type: "GET",
                data: "action=SearchOrder&OrderID=" + orderID + "&t=" + (new Date().getMilliseconds()),
                success: function(result) {
                    if (result != null && result != "") {
                        // var josn = eval("(" + result + ")");
                        //  showSearchOrderInfo(josn);
                        var str = "";
                        var orderid = result.toString().split(',')[0];
                        str += "<a href='http://my.wagest.com/DetailOrder.aspx?id=" + orderid + "'>" + orderid + "</a>";
                        str += "<br />当前状态:" + result.toString().split(',')[1];


                        $("#showOrderResult").html(str);
                        $("#showOrderResult").css("display", "block");
                        $("#btn_so").css("display", "none");
                        $("#SearchOrder").css("display", "none");
                        setTimeout("DisText()", 5000);
                    } else {
                        DisText();
                    }
                }

            })
        }
    });


})


//显示区县 查询邮费

//=====================
function ListQu(id) {
    try {
        $.ajax({
            url: "/FrontwebHandler.ashx",
            datatype: "JOSN",
            contentType: "application/json;charset=utf-8",
            type: "GET",
            data: "itemid=" + $("#itemid").val() + "&qu=1&childID=" + $("#fID").val() + " &action=210&t=" + new Date().getMilliseconds(),
            success: function(result) {
                if (result != null && result != "") {
                    var josn = eval("(" + result + ")");

                    GetQuListHtml(josn);
                }

            }
        });
    } catch (e) { }
}

function GetQuListHtml(josn) {//市区点击 获取区县 要查询费用


    var str = "";
    str += "<ul style=' padding-left:15px;'>";
    for (var i = 0; i < josn.length; i++) {
        var item = josn[i];
        if (item != null && item.Id != null) {
            str += "<li class='lit_li'>";
            str += "<a  href='javascript:showQuClick(\"" + item.Id + "\", \"" + item.AreaName + "\");'>";
            str += item.AreaName;
            str += "</a>";
            // str += "&nbsp;&nbsp;";
            // str += "  |   ";
            str += "</li>";
        }
    }

    $("#lit_test").html(str);

    $("#lit_test").show();
    //   $("#lit_test").css("display", "block");
}
function showQuClick(value, name) {

    var expID = $("#Select1").val();
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&areaId=" + encodeURI(value) + "&itemWeight=" + $("#itemWeight").val() + "&action=209&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {

                if (result == "")
                    $("#strMoney").html("<span style='color:red;'>不到</span>");
                else
                    $("#strMoney").html(result.toString().split(',')[0]);
            }

        }
    });
    str = "<a id='quID' href='javascript:void(0)' onmouseover='ListQu(0);'>";
    str += name;
    str += "</a>";
    $("#QuId").html(str);


}
//===========================================================================

function showPriceByIP() {

    var fID = $("#fID").val();

    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&itemWeight=" + $("#itemWeight").val() + "&action=208&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {

                var str = "";
                $("#strZhi").html(result.toString().split(',')[0]);

                str = "<a href='#' id='priID' onmouseover='priIDClick()'>"
                str += result.toString().split(',')[1];
                str += "</a>";
                $("#privinceID").html(str); //省

                $("#fID").val(result.toString().split(',')[4]); //areaID


                str = "<a href='#' id='cityID' onmouseover='ListCity(" + fID + ");'>"
                str += result.toString().split(',')[2];
                str += "</a>";
                $("#cityID").html(str); //市



                str = "<a href='#' id='qid' onmouseover='ListQu(" + result.toString().split(',')[4] + ");'>"
                str += result.toString().split(',')[3];
                str += "</a>";
                $("#QuId").html(str); //区
                if (result.toString().split(',')[5] != "")
                    $("#strMoney").html(result.toString().split(',')[5]);
                else $("#strMoney").html("不到");


            }

        }
    });
}
function priIDClick() { ListPrivice(); }

function ListPrivice() {//列表省

    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&action=206&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {
                var josn = eval("(" + result + ")");
                GetPrivinceListHtml(josn);
            }

        }
    });
}
//参数要改
function showPriIDClick(valu, name) {
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&areaId=" + encodeURI(valu) + "&itemWeight=" + $("#itemWeight").val() + "&action=209&t=" + new Date().getMilliseconds(),
        success: function(result) {

            if (result != null && result != "") {
                $("#fID").val(result.toString().split(',')[1]);
                if (result.toString().split(',')[0] != "") {
                    $("#strMoney").html(result.toString().split(',')[0]);
                }
                else $("#strMoney").html("不到");

                str = "<a id='QuId' href='javascript:void(0)' onmouseover='ListQu(0);'>";
                str += result.toString().split(',')[3] == 0 ? "" : result.toString().split(',')[3];
                str += "</a>";
                $("#QuId").html(str);

                str = "<a id='cityID' href='javascript:void(0)' onmouseover='ListCity(0);'>";
                str += result.toString().split(',')[2] == 0 ? "" : result.toString().split(',')[2];
                str += "</a>";
                $("#cityID").html(str);
                //  $("#strMoney").html(result.toString().split(',')[0]);



                ListCity(0);
            } else
                $("#strMoney").html("<span style='color:red;'>不到</span>");


        }
    });
    str = "<a id='priID' href='javascript:void(0)' onmouseover='priIDClick();'>";
    str += name;
    str += "</a>";
    $("#privinceID").html(str);
}

function GetPrivinceListHtml(josn) {

    var str = "";
    str += "<ul style=' padding-left:20px;'>";
    for (var i = 0; i < josn.length; i++) {
        var item = josn[i];
        if (item != null && item.Id != null) {
            str += "<li class='lit_li'>";
            str += "<a  href='javascript:showPriIDClick(\"" + item.Id + "\", \"" + item.AreaName + "\");'>";
            str += item.AreaName;
            str += "</a>";
            // str += "&nbsp;&nbsp;";
            // str += "  |   ";
            str += "</li>";

        }
    } str += "</ul>";

    $("#lit_test").html(str);
    //   $("#lit_test").css("display", "block");
}
//=====================
function ListCity(id) {

    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&childID=" + $("#fID").val() + " &action=210&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {
                var josn = eval("(" + result + ")");

                GetCityListHtml(josn);
            }

        }
    });
}

function GetCityListHtml(josn) {//市区点击 要查询费用

    var str = "";
    var fName = $("#privinceID").val();
    str += "<ul style=' padding-left:15px;'>";
    for (var i = 0; i < josn.length; i++) {
        var item = josn[i];
        if (item != null && item.Id != null) {
            str += "<li class='lit_li'>";
            str += "<a  href='javascript:showCityIDClick(\"" + item.Id + "\", \"" + fName + " " + item.AreaName + "\");'>";
            str += item.AreaName;
            str += "</a>";
            str += "</li>";
        }
    } str += "</ul>";

    $("#lit_test").html(str);
    //   $("#lit_test").css("display", "block");
}
function showCityIDClick(value, name) {

    var expID = $("#Select1").val();
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&areaId=" + encodeURI(value) + "&itemWeight=" + $("#itemWeight").val() + "&action=209&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {


                if (result.toString().split(',')[3] != 0) {
                    str = "<a id='QuId' onmouseover='ListQu(0);' href='javascript:void(0)'>";
                    str += result.toString().split(',')[3];
                    str += "</a>";
                    $("#QuId").html(str);
                }

                $("#fID").val(result.toString().split(',')[1]);

                $("#strMoney").html(result.toString().split(',')[0]);


                ListQu(result.toString().split(',')[1]);
            }

        }
    });
    str = "<a id='priID' href='javascript:void(0)' onmouseover='ListCity();'>";
    str += name;
    str += "</a>";
    $("#cityID").html(str);


}
//=====================
///查询显示积分商城的积分活动
function SearchDisSocreList(n) {

    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "itemid=" + $("#itemid").val() + "&n=" + n + "&productID=0&action=119&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {
                var josn = eval("(" + result + ")");

                GetScoreListHtml(josn);
            }

        }
    });


}
///查出积分活动 并默认选中型号
if ($("#ScoreAIID").val() != null && $("#ScoreAIID").val() != "") {
    CheckIsHaveScoreByPID();
}
function CheckIsHaveScoreByPID() {
    var scoreAID = 0;
    scoreAID = $("#ScoreAIID").val();

    if (scoreAID > 0) {//型号并选中
        $.ajax({
            url: "/FrontwebHandler.ashx",
            datatype: "JOSN",
            contentType: "application/json;charset=utf-8",
            type: "GET",
            data: "ScoreAID=" + scoreAID + "&action=200&ItemID=" + $("#itemid").val() + "&t=" + new Date().getMilliseconds(),
            success: function(result) {
                if (result != null && result != "") {
                    var josn = eval("(" + result + ")");
                    if (josn != null && josn.length > 0) {
                        //                        $("ul.product_model>li a").each(function(index, domEle) {
                        //                            if (josn.Value == domEle.innerText) {
                        //                                $(domEle).css("border", "1px solid red").css("background", "url(/images/s.gif) right bottom no-repeat").css("color", "#ff5500");
                        //                            } else {
                        //                                $(domEle).css("border", "1px dashed #dcdddd").css("background-position", "100px 100px").css("color", "#999999");
                        //                            }
                        //                        });
                        $("ul.product_model>li a").css("border", "1px dashed #dcdddd").css("background-position", "100px 100px").css("color", "#999999");
                        for (var i = 0; i < josn.length; ++i) {
                            GetModel(josn[i].MNId, josn[i].Id, this);
                            $("ul.product_model>li a").each(function(index, domEle) {
                                if (josn[i].Value == domEle.innerText) {
                                    $(domEle).css("border", "1px solid red").css("background", "url(/images/s.gif) right bottom no-repeat").css("color", "#ff5500");
                                }
                            });
                        }
                    }
                }
            }
        });
    }


}
//型号点击事件
function ClickByModelChoose(productID) {
    if (productID > 0) {

        $.ajax({
            url: "/FrontwebHandler.ashx",
            datatype: "JOSN",
            contentType: "application/json;charset=utf-8",
            type: "GET",
            data: "productID=" + productID + "&itemid=" + $("#itemid").val() + "&action=119&t=" + new Date().getMilliseconds(),
            success: function(result) {
                if (result != null && result != "") {
                    var josn = eval("(" + result + ")");
                    GetScoreListHtml(josn);
                    //  alert('型号点击事件调用ShowPrivilege');
                } else {//这里要查出itemid 是否有 
                    $("#litScoreList").css("display", "none");
                }
            }
        });
    }

}
//获得积分列表
function GetScoreListHtml(josn) {
    var str = "";
    var strList = "";
    //这里的现在要修改样式

    if (josn.length > 1) {

        for (var i = 0; i < josn.length; i++) {
            var item = josn[i];
            if (item != null && item.ID != null) {
                strList += "<a id=\\'ScoreID\\' href=\\'http://www.wagest.com/product/" + $("#itemid").val() + ".html?ScoreA_ID=" + item.ID + "\\'>";
                // strList += "用" + josn.PreMoney + "+" + item.UseScore + "积分购买";
                strList += "用" + item.UseScore + "积分购买";
                strList += "</a>";
                strList += "<br/>";
            }
        }
        str = "<a href='#' onmouseover=\"showScoreListMouseOver('" + (strList) + "')\" > 使用积分购买该商品</a>";
    } else
        str = "<a id='ScoreID' href='http://www.wagest.com/product/" + $("#itemid").val() + ".html?ScoreA_ID=" + josn[0].ID + "'>使用积分购买该商品</a>";

    if ($("#ScoreAIID").val() <= 0) {
        $("#litScoreList").html(str);
        $("#litScoreList").css("display", "inline-block");
    }
    else
        $("#litScoreList").html("");

}
function showScoreListMouseOver(s) {
    $("#ScoreList").html(s);
    $("#ScoreList").css("display", "block");
}
///获取productID 并 计算出 优惠额
function ShowPrivilege(productID, m_price, regPrice, savePrice) {
    var htmls = "";
    var uintprice = $("#itemLowPrice").val();
    var sID = $("#ScoreAIID").val();
    // alert(m_price);
    //  var privilegePrice = $("#privilegeID").val();
    $.ajax({
        url: "/FrontwebHandler.ashx",
        contentType: "application/json;charset=utf-8",
        type: "GET",
        data: "productID=" + productID + "&itemid=" + $("#itemid") + "&ScoreID=" + $("#ScoreAIID").val() + "&Unitprice=" + uintprice + "&action=203&t=" + new Date().getMilliseconds(),
        success: function(result) {
            if (result != null && result != "") {
               // alert("result为NULL");
                var josn = eval("(" + result + ")");

                if (josn.ActivitMoney > 0)//优惠额
                {
                    var privilege = m_price - josn.ActivitMoney;

                    htmls += privilege.toFixed(2);
                    if (josn.NeedScore > 0) {
                        htmls += "+" + josn.NeedScore + "积分";
                    } else
                    { SearchDisSocreList(productID); }

                    $("#sellName").html("活动价格：");
                    $("#d_mallprice").html(htmls);

                } else {

                    $("#sellName").html("哇哇价格：");
                    $("#d_mallprice").html(m_price);
                    $("#d_regprice").html("¥" + regPrice);
                }

            } else {
               // alert("result不为NULL");
                $("#sellName").html("哇哇价格：");
                $("#d_mallprice").html(m_price);
                $("#d_regprice").html("¥" + regPrice);

            }
        }

    });

}
//--------------------------------------------------------------
//--------------------------
function showSearchOrderInfo(josn) {

    //  alert("单号" + josn.ID + "当前状态：" + josn.Status);
    var str = "";

    str += "<a href='http://my.wagest.com/DetailOrder.aspx?id=" + josn.ID + "'>" + josn.ID + "</a>";
    str += "<br />当前状态:" + josn.PayModeName;


    $("#showOrderResult").html(str);
    $("#showOrderResult").css("display", "block");
    $("#btn_so").css("display", "none");
    $("#SearchOrder").css("display", "none");
    setTimeout("DisText()", 5000);
}
function DisText() {
    $("#btn_so").css("display", "block");
    $("#SearchOrder").css("display", "block");
    $("#showOrderResult").css("display", "none");


}

//回复
function replayCosult(cosultID) {

    AssID = cosultID;
    var divAssess = $("#ReAssessForm");
    if (divAssess.length == 0) {
        divAssess = $("<div id='ReAssessForm' style='display:none;position:absolute;background-color:Gray;left:10px;top:20px;'></div>");
        divAssess.appendTo("#consultContent");
    }
    if (divAssess.find("#btnReAssess").length == 0) {
        var html = "<table style=' text-align:left;'>"
               + "<tr><td>回复内容</td><td><textarea id='txtReAssessContent' rows=7  style=width:400px' cols=50></textarea></td></tr>"
               + "</table>";
        divAssess.html(html);
    }
    $.weeboxs.open('#ReAssessForm', { title: '评论回复', width:
            500, height: 150,
        onok: function() {
            SaveReCosult(cosultID);
            $.weeboxs.close();
        }
    });


}
function SaveReCosult(cosultID) {
    //alert(cosultID);
    //保存
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        cache: false,
        type: "Get",
        data: "action=211&assessid=" + cosultID + "&content=" + encodeURI($("#txtReAssessContent").val()),
        success: function(result) {
            //$.weeboxs.close();
            if (result != null && result != "") {
                alert(result.toString());
                showAllReCosult(cosultID);
            }


        }
    });
}

//查看全部回复
function showAllReCosult(cosultID) {
    //Ext.alert(1234);
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        cache: false,
        type: "Get",
        data: "action=213&assessid=" + cosultID + "&pageindex=1&pagesize=3",
        success: function(result) {
            $("#ReAssessDiv_" + cosultID).html(result);
        }
    });
}

//查看全部回复_分页
function showAllCosultPager(cosultID, pagesize, pageindex) {
    $.ajax({
        url: "/FrontwebHandler.ashx",
        datatype: "JOSN",
        contentType: "application/json;charset=utf-8",
        cache: false,
        type: "Get",
        data: "action=213&assessid=" + cosultID + "&pageindex=" + pageindex + "&pagesize=" + pagesize,
        success: function(result) {

            $("#ReAssessDiv_" + cosultID).html(result);
        }
    });
}

