<%@ Page Title="" Language="C#" MasterPageFile="~/Package/package.Master" AutoEventWireup="true" CodeBehind="InternationalPackageEnter.aspx.cs" Inherits="GxHub.Wms.Abroad.Web.Package.InternationalPackageEnter" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     <title>
        新增直发包裹明细界面
     </title>
<script language="javascript" src="../lodop/LodopFuncs.js"></script>
<object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0">
    <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0" pluginspage="../lodop/install_lodop.exe"></embed>
</object>

<script src="../Scripts/layer/layer.js"></script>
<link href="../Scripts/bootstrap_3.3.7_css_bootstrap.min[1].css" rel="stylesheet" />
<link href="../Scripts/bootstrap-select.min.css" rel="stylesheet" />
 
<script src="../Scripts/jquery-3.3.1.min.js"></script>
<script src="../Scripts/bootstrap_3.3.7_js_bootstrap.min.js"></script>
<script src="../Scripts/bootstrap-select.min.js"></script>

<script src="../Scripts/jquery-1.6.3.js"></script>
<script src="../Scripts/jqueryUI/ui/jquery-ui-1.8.24.custom.js"></script>

<script type="text/javascript">
 
    function getParameter(sProp) {
        var re = new RegExp(sProp + "=([^\&]*)", "i");
        var a = re.exec(document.location.search);
        if (a == null)
            return null;
        return a[1];
    };
    
    function changetwodecimal(x) {
        var f_x = parsefloat(x);
        if (isnan(f_x)) {
            alert('function:changetwodecimal->parameter error');
            return false;
        }
        var f_x = math.round(x * 10000) / 10000;
        return f_x;
    }

    function CheckConfirm(str) {
        if (confirm(str) != true) {
            return false;
        }
        else {
            return true;
        }
    }

    function ChoseMap() {
        var lat = "";
        var lng = "";
        $("#EditIframe").attr("src", "/map2.html");
        $("#iframeEdit").dialog({
            autoOpen: true,
            resizable: false,
            width: 700,
            height: 600,
            modal: true,
            title: "选中map",
            buttons: {
                "确认": function () {
                    choseSize();
                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            },
        });
        return false;
    }

    function choseSize() {
        var lat = $("#EditIframe").contents().find("#lat").text();
        $("#hfLatSize").val(lat);
        var lng = $("#EditIframe").contents().find("#lng").text();
        $("#hfLngSize").val(lng);
        var address = $("#EditIframe").contents().find("#address").text();
        $("#txtReceAddress").text(address);
        // 重新绑定下拉列表的改变事件
        bindDropdownChange();
    };

    

    function loadDropDownList(lat, lng) {
        $.ajax({
            url: "GetWarehouseByLatLng.ashx",
            data: { lat: lat, lng: lng },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                // 清空下拉列表
                $("#<%=ddlUserWare.ClientID%>").empty();
                // 添加默认选项
                $("#<%=ddlUserWare.ClientID%>").append($('<option></option>').val('').text('--请选择--'));
                // 绑定数据
                $.each(response.d, function (index, item) {
                    $("#<%=ddlUserWare.ClientID%>").append(
                        $('<option></option>').val(item.WarehouseId).text(item.WarehouseName)
                    );
                });
            },
            error: function (xhr, textStatus, errorThrown) {
                alert("获取数据失败！");
            }
        });
    };

    // 根据链接解析纬度和经度信息
    function AnalyzingMap() {
        // 原始 URL
        const text = $("#<%=txtReceiverLink.ClientID%>").val(); 

        // 验证 text 是否为 10.234234234,103.234234234234 这种格式
        const urlPattern = /^-?\d+\.\d+,-?\d+\.\d+$/;
        const isValidFormat = urlPattern.test(text);
        if (!isValidFormat) {
            alert("请输入正确的纬度和经度格式，例如：10.234234234,103.234234234234");
            return false;
        }
        var latlng = text.split(",");
        var lat = latlng[0];
        var lng = latlng[1];

        $("#hfLatSize").val(lat);
        $("#hfLngSize").val(lng);
        //lat = 11.53862789015746;
        //lng = 104.90815310622384;
        const geocoder2 = new google.maps.Geocoder();
        geocoder2.geocode({ location: { lat, lng } }, (results, status) => {
            if (status === "OK" && results[0]) {
                const address = results[0].formatted_address;
                document.getElementById('txtReceAddress').textContent = address;
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
        // 重新绑定下拉列表的改变事件
        bindDropdownChange();
        return false;
    };

    // 绑定下拉列表的改变事件
    function bindDropdownChange() {
        // 执行加载提货仓按钮
        document.getElementById('<%= btnWare.ClientID %>').click();
    }

    function closeModal() {
        var modal = document.querySelector('div[style*="position: fixed"]');
        if (modal) {
            document.body.removeChild(modal);
        }
    }

  // 选择地址列表
  function ChooseAddress() {
      var customerCode = "KH" + $("#<% =txtCustomerCode.ClientID%>").val();
      //var url = "/Package/InternationalPackageChoiseAddress.aspx?CustomerCode=" + customerCode;
      var url = $("#hfAddressUrl").val() + customerCode;
      
      $("#EditIframe").attr("src", url);
      $("#iframeEdit").dialog({
          autoOpen: true,
          resizable: false,
          width: 800,
          height: 600,
          modal: true,
          title: "客户地址信息列表",
          buttons: {
              "确认": function () {
                  addressCallback();
                  $(this).dialog("close");
              },
              "取消": function () {
                  $(this).dialog("close");
              }
          },
      });
      return false;
  }

  function addressCallback() {
      var lat = $("#EditIframe").contents().find("#hfLatSize").val();
      $("#hfLatSize").val(lat);
      var lng = $("#EditIframe").contents().find("#hfLngSize").val();
      $("#hfLngSize").val(lng);
      var address = $("#EditIframe").contents().find("#hfAddress").val();
      $("#txtReceAddress").text(address);

      $("#<%=txtReceiver.ClientID%>").val($("#EditIframe").contents().find("#hfReceiverName").val());
      $("#<% =txtReceMobile.ClientID%>").val($("#EditIframe").contents().find("#hfMobile").val());
      var addressUniqueId = $("#EditIframe").contents().find("#hfAddressId").val();
      $("#hfAddressId").val(addressUniqueId);
      // 重新绑定下拉列表的改变事件
      bindDropdownChange();
  };

  // 新增地址
  function CreateAddress(){
    var customerCode = "KH" + $("#<% =txtCustomerCode.ClientID%>").val();
    //var url = "/Package/InternationalPackageCreateAddress.aspx?CustomerCode=" + customerCode;
    var url = $("#hfCreateAddressUrl").val() + customerCode;
    window.location.href = url;
  }

  
  function CreateAddressOld() {
      var customerCode = "KH" + $("#<% =txtCustomerCode.ClientID%>").val();
      var url = "/Package/InternationalPackageCreateAddress.aspx?CustomerCode=" + customerCode;
      $("#EditIframe").attr("src", url);
      $("#iframeEdit").dialog({
          autoOpen: true,
          resizable: false,
          width: 800,
          height: 600,
          modal: true,
          title: "新增地址",
          buttons: {
              "确认": function () {
                  //addressCreateCallback();
                  $(this).dialog("close");
              },
              "取消": function () {
                  $(this).dialog("close");
              }
          },
      });
      return false;
  }

  function addressCreateCallback() {
      var lat = $("#EditIframe").contents().find("#hfLatSize").val();
      $("#hfLatSize").val(lat);
      var lng = $("#EditIframe").contents().find("#hfLngSize").val();
      $("#hfLngSize").val(lng);
      var address = $("#EditIframe").contents().find("#hfAddress").val();
      $("#txtReceAddress").text(address);
  
      $("#<%=txtReceiver.ClientID%>").val($("#EditIframe").contents().find("#hfReceiverName").val());
      $("#<% =txtReceMobile.ClientID%>").val($("#EditIframe").contents().find("#hfMobile").val());
      var addressUniqueId = $("#EditIframe").contents().find("#hfAddressId").val();
      $("#hfAddressId").val(addressUniqueId);
      // 重新绑定下拉列表的改变事件
      bindDropdownChange();
    };

    // 加载客户的信息
    function LoadCustomerInfo(){
      var customerCode = $("#<%=txtCustomerCode.ClientID %>").val();
        if(customerCode!=null && customerCode!=''){
             // 执行按钮
             document.getElementById('<%= btnReturnBagList.ClientID %>').click();
        }
    }

    function TurnToCreateAddress()
    {
        CreateAddress();
        return false;
    }

</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   <yee:MessageBox ID="msg" runat="server">
    </yee:MessageBox>
    <yee:PageTitle ID="pgTitle" runat="server">
        <ShortCuts>
            <!--<a href="AbroadReceiveList.aspx">返回</a> 
            <a href="javascript:CreateAddress()" title="新增地址">新增地址</a>
            <a href="javascript:ReturnBagList()" title="末端包裹列表">末端包裹列表</a>-->
        </ShortCuts>
    </yee:PageTitle>

    
    <div class="query">
        <table cellpadding="0" cellspacing="0" border="0" class="table">
            <tr style="display:none">
                <td class="tbpostheader" >
                   <%=GetText("末端包裹编号") %>
                </td>
                <td class="tbpost">
                    <asp:TextBox ID="txtEndParcelNo" runat="server" ></asp:TextBox>
                </td>
            </tr> 
            <tr>
                <td class="tbpostheader" style="font-size: large;width:150px">
                   <%=GetText("快递单号") %>
                </td>
                <td class="tbpost">
                    <asp:TextBox ID="txtExpressNo" runat="server" style ="width:220px;" ></asp:TextBox>
                    <asp:Button ID="btnExpressNo" CssClass="button" runat="server" OnClick="btnExpressNo_Click" Text="扫描"/>
                </td>
            </tr>
            <tr>
                <td class="tbpostheader">
                    <%=GetText("客户代号KH") %>
                </td>
                <td class="tbpost">
                    <asp:TextBox ID="txtCustomerCode" runat="server" Width="220" Height="50" ForeColor="Red" Font-Size="XX-Large" Font-Bold="true" onblur="LoadCustomerInfo()">
                    </asp:TextBox>( <%=GetText("请勿输入前缀KH") %>)
                </td>
            </tr>
            <tr>
                 <td class="tbpostheader">
                     <%=GetText("寄货仓") %>
                 </td>
                 <td class="tbpost" style="font-size: large;">
                     <asp:Literal ID="litWarehouseName" runat="server" ></asp:Literal>
                 </td>
            </tr>

            <tr>
                <td class="tbpostheader"><%=GetText("提货方") %>
                </td>
                <td class="tbpost">
                    <table>
                        <tr style="display: none;">
                            <td><%=GetText("坐标位置链接") %>：</td>
                            <td>
                                <asp:TextBox ID="txtReceiverLink" runat="server" style="width:600px"></asp:TextBox>
                                <asp:Button ID="btnMapLink" runat="server" CssClass="button" OnClientClick="return AnalyzingMap();" text="解析定位" /> 
                            </td>
                        </tr>
                        <tr>
                            <td><%=GetText("提货网点") %>：</td>
                            <td>
                                 <asp:DropDownList ID="ddlUserWare" runat="server" data-live-search="true" CssClass="selectpicker"></asp:DropDownList> 
                                 <asp:Button ID="btnSelectAddress" runat="server" CssClass="button" OnClientClick="return ChooseAddress();" text="选择地址"/> 
                                 <input runat="server" type="submit" name="inputbtnCreateAddress" value="新增地址" id="inputbtnCreateAddress" class="button" onclick="return TurnToCreateAddress()" />
                                 <asp:Button ID="btnMap" runat="server" CssClass="button" OnClientClick="return ChoseMap();" text="定位选择" style ="display:none"/> 
                                 <yee:Button ID="btnWare" runat="server" style="display: none;" CssClass="button" OnClick="btnWare_Click" Text="加载最近的提货仓" />
                            </td>
                        </tr>
                        <tr>
                            <td><%=GetText("提货人") %>：</td>
                            <td>
                                <asp:TextBox ID="txtReceiver" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td><%=GetText("电话") %>：</td>
                            <td>
                                <asp:TextBox ID="txtReceMobile" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td><%=GetText("地址") %>：</td>
                            <td>
                                <asp:TextBox ID="txtReceAddress" runat="server" TextMode="MultiLine" ClientIDMode="Static"  Width="150px" Height="80px"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <tr>
                <td class="tbpostheader" width="100px"><%=GetText("长宽高") %>(CM)
                </td>
                <td class="tbpost">
                    <asp:Repeater ID="rptPackage" runat="server" OnItemCommand="rptPackage_ItemCommand" ClientIDMode="Static" OnItemDataBound="rptPackage_ItemDataBound">
                        <ItemTemplate>
                            <%=GetText("包裹名称") %>：<asp:TextBox ID="txtPacName" runat="server" Width="80px" Text='<%#Eval("ItemName") %>' ClientIDMode="Static"></asp:TextBox>
                            <%=GetText("重量") %>(Kg)：<asp:TextBox ID="txtWeight" runat="server" Width="80px" Text='<%#Eval("TotalWeight") %>' ClientIDMode="Static" onchange="click_volume()"></asp:TextBox>
                            <%=GetText("包裹数") %>：<asp:TextBox ID="txtCount" runat="server" Width="80px" Text='<%#Eval("PackageCount") %>' CssClass="count" ClientIDMode="Static" onchange="click_volume()"></asp:TextBox>
                            <%=GetText("尺寸") %>(CM*CM*CM):<asp:TextBox ID="txtLength" runat="server" Width="80px" Text='<%#Eval("PackageLength") %>' ClientIDMode="Static" onchange="click_volume()" />-
                                    <asp:TextBox ID="txtWidth" runat="server" Width="80px" Text='<%#Eval("PackageWidth") %>' ClientIDMode="Static" onchange="click_volume()"></asp:TextBox>-
                                    <asp:TextBox ID="txtHeight" runat="server" Width="80px" Text='<%#Eval("PackageHeight") %>' ClientIDMode="Static" onchange="click_volume()"></asp:TextBox>
                            <asp:LinkButton ID="lbnAdd" runat="server" CommandArgument='<%#Eval("UniqueId") %>' CommandName="add"></asp:LinkButton>
                            <asp:LinkButton ID="lbnDelete" runat="server" CommandArgument='<%#Eval("UniqueId") %>' CommandName="delete"></asp:LinkButton>
                            <asp:HiddenField ID="hfUniqueId" runat="server" ClientIDMode="Static" Value='<%#Eval("UniqueId") %>' />
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                    <br/>
                </td>
            </tr>

            <tr>
                <td class="tbfooter" width="100px"></td>
                <td class="tbfooter">
                    <asp:Button ID="btSubmit" runat="server" CssClass="button" Text="提交" OnClick="btnSubmit_Click" />
                </td>
            </tr>
        </table>
    </div>

    <div class="subheader">
        <div class="title">
            <%=GetText("已录入数据") %> 
        </div>
        <div style="clear: both">
        </div>
    </div>
    
    <div>
        <asp:Repeater ID="rptAddPackageList" runat="server">
            <HeaderTemplate>
                <table cellpadding="0" class="table" cellspacing="0" border="0" id="table2">
                    <tr>
                        <td class="tbheader" align="center" width="100px">
                            <%=GetText("直发包裹编号") %>
                        </td>
                        <td class="tbheader" align="center" width="100px">
                            <%=GetText("快递单号") %>
                        </td>
                        <td class="tbheader" align="center" width="100px">
                            <%=GetText("客户代号") %>
                        </td>
                        <td class="tbheader" align="center" width="200px">
                            <%=GetText("寄货仓") %>
                        </td>
                        <td class="tbheader" align="center" width="100px">
                            <%=GetText("提货仓") %>
                        </td>
                        <td class="tbheader" align="center" width="200px">
                            <%=GetText("包裹名称") %>
                        </td>

                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr class="tbrow">
                    <td class="tbpost">
                        <%# Eval("BigBagNo")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("ExpressNo")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("CustomerCode")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("WarehouseName")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("TargetWarehouseName")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("PackageName")%>
                    </td>
                </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr class="tbrowalter">
                    <td class="tbpost">
                        <%# Eval("BigBagNo")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("ExpressNo")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("CustomerCode")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("WarehouseName")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("TargetWarehouseName")%>
                    </td>
                    <td class="tbpost">
                        <%# Eval("PackageName")%>
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
        </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>
 
    <asp:HiddenField runat="server" ID="hfLatSize" ClientIDMode="Static" />
    <asp:HiddenField runat="server" ID="hfLngSize" ClientIDMode="Static" />
    <asp:HiddenField runat="server" ID="hfAddressId" ClientIDMode="Static" />
    <asp:HiddenField runat="server" ID="hfAddressUrl" ClientIDMode="Static" />
    <asp:HiddenField runat="server" ID="hfCreateAddressUrl" ClientIDMode="Static" />
    <asp:HiddenField runat="server" ID="hfEndParcelId" ClientIDMode="Static" />

    <asp:Button ID="btnReturnBagList" runat="server" style="display: none;" CssClass="button" OnClick="btnReturnBagList_Click" Text="加载客户信息" />
    <div id="iframeEdit" class="iframeEdit" style ="display:none">
        <iframe id="EditIframe" frameborder="0" class="EditIframe" style="width: 100%; min-height: 0px; height: 480px;"></iframe>
    </div>

    <script language="javascript" type="text/javascript">

        var LODOP; //声明为全局变量
        
   function PrintBox2022(serialNo, customerCode, orderNo, printName, enprintName,freighttype, rece_name, rece_mobie, rece_address, ware_group){

       if (needCLodop()) {
           window.On_CLodop_Opened = function () {
               PrintBox2022New(serialNo, customerCode, orderNo, printName, enprintName,freighttype, rece_name, rece_mobie, rece_address, ware_group);
               window.On_CLodop_Opened = null;
           }
       }
       else {
           PrintBox2022New(serialNo, customerCode, orderNo, printName, enprintName,freighttype, rece_name, rece_mobie, rece_address, ware_group);
       }
      
   };

        function PrintBox2022New(serialNo, customerCode, orderNo, printName, enprintName,freighttype, rece_name, rece_mobie, rece_address, ware_group)
        {
            LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));

            var customer_info = rece_name + "(Receive)\r\n" + rece_mobie + "\r\n" + rece_address;
 


LODOP.PRINT_INITA(0,0,383,246,"");
LODOP.SET_PRINT_PAGESIZE(0,700,500,"A4");
LODOP.SET_PRINT_MODE("RESELECT_PRINTER",true);
LODOP.ADD_PRINT_BARCODE(57,13,161,45,"128A",serialNo);
LODOP.ADD_PRINT_TEXT(5,11,101,25,freighttype);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
LODOP.SET_PRINT_STYLEA(0,"Bold",1);
LODOP.ADD_PRINT_TEXT(26,10,128,25,orderNo);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.SET_PRINT_STYLEA(0,"Bold",1);
LODOP.ADD_PRINT_TEXT(147,144,135,38,enprintName);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
LODOP.SET_PRINT_STYLEA(0,"Bold",1);
LODOP.ADD_PRINT_TEXT(108,144,133,38,printName);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
LODOP.SET_PRINT_STYLEA(0,"Bold",1);
LODOP.ADD_PRINT_TEXT(3,113,158,51,customerCode);
LODOP.SET_PRINT_STYLEA(0,"FontName","Tahoma");
LODOP.SET_PRINT_STYLEA(0,"FontSize",21);
LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
LODOP.SET_PRINT_STYLEA(0,"Bold",1);
LODOP.ADD_PRINT_TEXT(110,8,156,79,customer_info);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.ADD_PRINT_TEXT(58,164,109,35,ware_group);
LODOP.SET_PRINT_STYLEA(0,"FontName","等线");
LODOP.SET_PRINT_STYLEA(0,"FontSize",15);
LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
LODOP.SET_PRINT_STYLEA(0,"Bold",1);


            LODOP.SET_PRINTER_INDEXA("outPrinterGK888t");

            LODOP.PRINT();
           //LODOP.PREVIEW();

           //LODOP.PRINT_DESIGN();
        };

    </script>

</asp:Content>
