<hi:common_wapheader runat="server" />
<!--<script src="/Utility/regionSeletor.js" type="text/javascript"></script>-->
<script src="/Utility/regionSelector_FileData.js" type="text/javascript"></script>
<div class="pbox">
    <input id="shipTo" type="text" class="form-control" placeholder="请填写收货人姓名">
    <input id="cellphone" type="tel" class="form-control bmargin" placeholder="请填写收货人手机号">
    <div class="btn-group">
        <div id="vshopRegion">
        </div>
        <input name="address" id="region" style="display: none;" />
    </div>
    <textarea id="address" class="form-control bmargin" rows="3" placeholder="请填写收货人详细地址"></textarea>
    <button type="button" onclick="AddShippingAddress()" class="btn btn-danger btn-block bmargin">
        保存收货地址
    </button>
</div>
<script type="text/javascript">
    var regionSelector = new vShop_RegionSelector('vshopRegion', function (address, code) {
        $("#address-check-btn").html(address + "<span class='caret'></span>");
        $('#region').val(code);
    });



    function AddShippingAddress() {
        var isValite = true;
        if ($("#shipTo").val() == "") {
            $("#shipTo").focus();
            $("#divShipToTip").show();
            alert_h($("#shipTo").attr('placeholder'));
            isValite = false;
            return false;
        }
        else {
            $("#divShipToTip").hide();
        }
        if ($("#address").val() == "") {
            $("#divAddressTip").show();
            $("#address").focus();
            alert_h($("#address").attr('placeholder'));
            isValite = false;
            return false;
        }
        else {
            $("#divAddressTip").hide();
        }
        if ($("#cellphone").val() == "") {
            $("#divCellphoneTip").show();
            alert_h($("#cellphone").attr('placeholder'));
            $("#cellphone").focus();
            isValite = false;
            return false;
        }
        else {
            $("#divCellphoneTip").hide();
        }
        if ($("#region").val() == "") {
            //判断详细地址
            isValite = false;
            alert_h('请选择省市区');
            return false;
        }
        else {

        }

        $.ajax({
            url: "/API/VshopProcess.ashx",
            type: 'post',
            dataType: 'json',
            timeout: 10000,
            data: {
                action: "AddShippingAddress",
                shipTo: $("#shipTo").val(),
                address: $("#address").val(),
                cellphone: $("#cellphone").val(),
                regionSelectorValue: $("#region").val()
            },
            success: function (resultData) {
                if (resultData.success) {
                    if (window.location.search.indexOf("returnUrl=") == -1) {
                        var urlref = document.referrer;
                        var currdomain = document.domain;
                        if (urlref != "" && urlref != undefined && urlref.indexOf(currdomain) > -1)
                            location.href = urlref;
                        else
                            location.href = "/Wapshop/ShippingAddresses.aspx";
                        return false;
                    }
                    var returnURL = window.location.search.substr(window.location.search.indexOf("returnUrl=") + 10);
                    if (returnURL == undefined) {
                        location.href = "/Wapshop/ShippingAddresses.aspx";
                        return false;
                    }
                    location.href = decodeURIComponent(returnURL);
                }
                else {
                    alert_h("添加失败,会员未登陆或者收货地址数量超过了5个！");
                }
            }
        });
    }

</script>
<script>
    //禁用右上角菜单
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    });
</script>
<hi:common_wapfooter runat="server" />
