<%@ Page Language="C#" MasterPageFile="~/Package/package.Master" AutoEventWireup="true" CodeBehind="ClaimUnownedPackagesList.aspx.cs" Inherits="GxHub.Wms.Abroad.Web.Package.ClaimUnownedPackagesList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title><%=GetText("无主包裹列表") %></title>
    
    <script type="text/javascript" src="../Scripts/jquery-1.6.3.js"></script>
    <script type="text/javascript" src="../Scripts/jquery-ui-1.8.24.custom.min.js"></script>
    <script src="../Scripts/SignalR/jquery.signalR.js"></script>
    <!--自动生成的代理脚本 -->
    <script src="../signalr/hubs"></script>
    <link type="text/css" href="../Styles/jqueryUI/smoothness/jquery-ui-1.8.24.custom.css" rel="stylesheet" />
    <script language="javascript" src="../lodop/LodopFuncs.js"></script>
    <script language="javascript" src="../lodop/CLodopfuncs.js"></script>
    <script language="javascript" type="text/javascript" src="../Scripts/PrintTemplate.js"></script>
    <style>
        @font-face {
            font-family: 'KhmerOSFont';
            src: url('../Scripts/KhmerOS.ttf') format('truetype');
        }
    </style>
    <script type="text/javascript">
    var currentPicList = [];
    $(function () {
        currentPicList = [];
        var pic = $(".pic").html();
        $("#assignWinCancel").dialog({
            title: pic,
            autoOpen: false,
            resizable: false,
            //height: 600,
            width: 800,
            modal: true
        });
    });
    
    
    // 接收 Signal 消息
    $(function () {
        var connection = $.hubConnection();
        connection.url = '/abroadwms' + connection.url;
        console.log(connection);
        var notificationHub = connection.createHubProxy('notificationHub');
        var isConnected = false;
        var STORAGE_KEY = 'autoPrintEnabled';
        
        // 从localStorage获取初始值并设置复选框状态
        function initCheckboxFromStorage() {
            var storedValue = localStorage.getItem(STORAGE_KEY);
            var autoPrintCheckbox = $("#<%= chkAutoPrint.ClientID %>");
            
            if (storedValue === null) {
                // 存储值不存在，默认设为否
                autoPrintCheckbox.prop('checked', false);
                localStorage.setItem(STORAGE_KEY, 'false');
            } else {
                // 根据存储值设置复选框
                autoPrintCheckbox.prop('checked', storedValue === 'true');
            }
        }
        
        // 监听自动打印复选框变化
        $("#<%= chkAutoPrint.ClientID %>").change(function() {
            var isChecked = $(this).is(":checked");
            // 保存选择状态到localStorage
            localStorage.setItem(STORAGE_KEY, isChecked.toString());
            
            if (isChecked) {
                if (!isConnected) {
                    start();
                }
            } else {
                if (isConnected) {
                    connection.stop();
                }
            }
        });
    
        // 定义客户端方法
        notificationHub.on('executeJs', function (msg) {
            var res = $.parseJSON(msg);
            try {
                // 确认消息已收到
                notificationHub.invoke('ConfirmMessage', res.Id).fail(function(error) {
                    console.error('Unable to confirm message: ' + error);
                });
                // 执行打印
                PrintBox(res.BoxNo, res.ExpressNo, res.CustomerCode, res.Weight, res.Size);            
            } catch (error) {
                // 发生错误时通知服务器
                notificationHub.invoke('ReportError', msg).fail(function(error) {
                    console.error('Unable to report error: ' + error);
                });
            }
        });
    
        // 开始连接，并添加重连逻辑
        function start() {
            connection.start().done(function () {
                console.log("Connected to notification hub.");
                isConnected = true;
            }).fail(function (error) {
                console.error('Could not connect: ' + error);
                isConnected = false;
                if ($("#<%= chkAutoPrint.ClientID %>").is(":checked")) {
                    setTimeout(start, 5000);
                }
            });
        }
    
        // 处理重新连接尝试
        connection.disconnected(function () {
            console.log('Disconnected.');
            isConnected = false;
            if ($("#<%= chkAutoPrint.ClientID %>").is(":checked")) {
                console.log('Attempting to reconnect...');
                setTimeout(function() {
                    if (!connection.state && $("#<%= chkAutoPrint.ClientID %>").is(":checked")) {
                        start();
                    }
                }, 5000);
            }
        });
    
        // 初始化复选框状态并根据状态决定是否连接
        initCheckboxFromStorage();
        if ($("#<%= chkAutoPrint.ClientID %>").is(":checked")) {
            start();
        }
    });
    
    function GetPackagePic(id) {
        ShowPicData(id);
        $("#assignWinCancel").dialog("open");
        $("#assignWinCancel").parent().appendTo("#iframeassignCancel");
        return false;
    }
    
    function ShowPicData(id) {
        var txtPic = $(".currentPic").val();
        if (txtPic.length > 3) {
            currentPicList = JSON.parse(txtPic)
        }
        
        //var lastResult = currentPicList.find(p => p.PackageId == id);
        var html = '';
        for (var i = 0; i < currentPicList.length; i++) {
            //alert(currentPicList[i].PackageId);
            if (currentPicList[i].PackageId == id) {
                html += "<img src='" + currentPicList[i].PicOssPath + "' height ='370' />";
            }
           
        }
        $(".ShowPic").html(html);
    }

    //使用checkbox当做全选反选
    function check_all_not() {
        var check = document.getElementById("checkboxAll").checked;
        //alert(check);
        if (check == true) {
            checkAll();
        }
        else {
            checkReverse();
        }
    
    }
    function checkAll() {
        $(".check").each(function () {
            $(this).attr("checked", true);
        });
    }
    //反选
    function checkReverse() {
        $(".check").each(function () {
            $(this).attr("checked", !($(this).attr("checked")));
        });
    }
    function checkRemove() {
        $(".check").each(function () {
            $(this).attr("checked", false);
        });
    }
    function PrintBox(BoxNo, ExpressNo, Code, Weight, Size){
        var printData = [{ 
            BoxNo: BoxNo,
            ExpressNo: ExpressNo,
            CustomerCode: Code,
            Size: Size,
            Weight: Weight,
        }];
        var pageSize = {IntOrient:0,PageWidth:700,PageHeight:500,StrPageName:'A4'};
        PrintWithTemplate('outPrinterGK888t',['PrintUnclaimedBox'],printData,true,pageSize);
    }
    </script>
    <style>
    .lblBackCustomer {
        border: 1px solid #C0C0C0 !important;
        padding: 5px 15px 5px 15px !important;
        color: #e1e1e1 !important;
        background-color: Green !important;
        text-decoration:none !important;
    }
    .buttonGetPic {
         border: 1px solid #C0C0C0 !important;
        padding: 5px 15px 5px 15px !important;
         color: #e1e1e1 !important;
        background-color:#4a4642
    }
    .color {
        background: yellow !important;
    }

    .trColor {
        background: #f7d60c !important;
    }
    </style>
</asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
      <yee:PageTitle ID="pgTitle" runat="server" >
          <ShortCuts>
               <asp:HyperLink ID="hlReport" runat="server" NavigateUrl="ClaimUnownedPackages.aspx">认领无主包裹</asp:HyperLink>
          </ShortCuts>
      </yee:PageTitle>
      <yee:MessageBox ID="msg" runat="server"></yee:MessageBox>
        <div style="display:none"><%--style="display:none"--%>
      <div class="pic"><%=GetText("图片") %></div>
            
      <asp:TextBox ID="txtPic" runat="server" Text="" TextMode="MultiLine" CssClass="currentPic"></asp:TextBox>

        </div>
     <div class="query">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
               
                <td class="queryLeft">
                    <%=GetText("客户代号") %>：
                </td>
                <td class="queryRigth">
                    <asp:TextBox ID="txtCustomerCode" style="width:79px" runat="server"></asp:TextBox> 
                </td>
                <td class="queryLeft">
                    <%=GetText("下单日期") %>：
                </td>
                <td class="queryRigth" >
                    <yee:DatePicker ID="dpFrom" runat="server" CssClass="input-small" IsRequired="false" />
                    -
                    <yee:DatePicker ID="dpTo" runat="server" CssClass="input-small" IsRequired="false" />
                </td>

                 <td class="queryLeft">
                    <%=GetText("快递单号") %>：
                </td>
                <td class="queryRigth">
                    <asp:TextBox ID="txtExpressNo" CssClass="input-big" runat="server"></asp:TextBox> 
                </td>

            <td class="queryLeft">
                    <%=GetText("审核状态") %>：
                </td>
                <td class="queryRigth">
             
                    <asp:RadioButtonList ID="rblAuditStatus" runat="server" RepeatDirection="Horizontal">
                      
                    </asp:RadioButtonList>
                </td>
               
               
                <td  class="queryLeft">
                    <asp:Button ID="btnQuery" Text="搜索" runat="server" CssClass="button" OnClick="btnQuery_Click" />
                    
                </td>
              
            </tr>
            <tr>
                <td class="queryLeft">
                    箱子状态
                </td>
                <td class="queryRigth">
                    <yee:DictionaryDropDownList ID="ddlStatu" Dictionary="InStockStatus" runat="server"  IsShowAllAtFirst="true"></yee:DictionaryDropDownList>
                </td>
                 <td class="queryLeft">
                    库区
                </td>
                <td class="queryRigth" colspan="6">
                      <asp:RadioButtonList ID="rblStorage" runat="server" RepeatDirection="Horizontal" ></asp:RadioButtonList>
                </td>
            </tr>
        </table>
    </div>
    <asp:Button ID="btPrint" runat="server" Text="批量打印" OnClick="btPrint_Click" CssClass="button" />
    <asp:CheckBox ID="chkAutoPrint" runat="server" Text="是否自动打印" CssClass="checkbox" AutoPostBack="false" />
    <asp:Repeater ID="rptMaster" runat="server" OnItemCommand="rptMaster_ItemCommand">
        <HeaderTemplate>
            <table class="table" cellpadding="0" cellspacing="0" border="0">
                <thead>
                    <tr>
                        <td class="tbheader" width="15px" rowspan="2">
                            <input type="checkbox" id="checkboxAll" onclick="check_all_not()" />
                        </td>
                        <td class="tbheader"><%=GetText("日期") %></td>
                        <td class="tbheader"><%=GetText("客户代号") %></td>
                        <td class="tbheader"><%=GetText("快递单号") %></td>
                        <td class="tbheader"><%=GetText("箱子号") %></td> 
                        <td class="tbheader"><%=GetText("箱子库区") %></td> 
                        <td class="tbheader"><%=GetText("箱子客户代号") %></td>
                        <td class="tbheader"><%=GetText("包裹状态") %></td>
                        <td class="tbheader"><%=GetText("包内品名") %></td>
                        <td class="tbheader"><%=GetText("包裹图片") %></td>
                        <td class="tbheader"><%=GetText("操作") %></td>
                    </tr>
                </thead>
        </HeaderTemplate>
           <ItemTemplate>
                <tr class="tbrow">
                    <td class="tbpost">
                        <input type="checkbox" runat="server" id="cb" class="check" value='<%#Eval("Id") %>'/>
                        <asp:HiddenField ID="hfBoxNo" runat="server" Value='<%#Eval("BoxSerialNo") %>' />
                        <asp:HiddenField ID="hfExpressNo" runat="server" Value='<%#Eval("ExpressNo") %>' />
                        <asp:HiddenField ID="hfCode" runat="server" Value='<%#Eval("CustomerCode") %>' />
                         <asp:HiddenField ID="hfWeight" runat="server" Value='<%#Eval("AbroadBoxWeight") %>' />
                     <asp:HiddenField ID="hfSize" runat="server" Value='<%#Eval("Size") %>' />
                        <input type="hidden" id="hfPrint" value='<%#Eval("PrintedById") %>' runat="server" class="hfPri" />    
                    </td>
                    <td class="tbpost" style="text-align: center">
                    <%#Eval("CreatedOn") %>
                    </td>
                    <td class="tbpost" style="text-align: center"><%#Eval("CustomerCode") %></td>
                    <td class="tbpost" style="text-align: center"><%#Eval("ExpressNo") %></td>
                    <td class="tbpost" style="text-align: center"><%#Eval("BoxSerialNo") %></td>
                    <td class="tbpost" style="text-align: center"><%#Eval("BoxStatuName") %>  </td>
                    <td class="tbpost" style="text-align: center"><%#Eval("BoxCustomerCode") %></td>
                    <td class="tbpost" style="text-align: center"><%#Eval("StatuName") %></td>
                    <td class="tbpost" style="text-align: center"><%#Eval("PackageName") %></td>
                    <td class="tbpost" style="text-align: center">
                        <a Class="buttonGetPic" onclick="return GetPackagePic('<%#Eval("Id").ToString()%>')">查看图片</a>
                        <%--<asp:LinkButton ID="btnGetPic" CssClass="buttonGetPic" OnClientClick='GetPackagePic(<%#Eval("Id").ToString() %>)'  Text="查看图片"  runat="server"></asp:LinkButton>--%>
                    </td>
                    <td class="tbpost" style="text-align: center">
                        <asp:LinkButton ID="lbnDetail" runat="server" CommandName="detail" CommandArgument='<%#Eval("Id") %>'  ><%=GetText("详情") %></asp:LinkButton>  
                    </td>
                 </tr>
           </ItemTemplate>
            <AlternatingItemTemplate>
            <tr class="tbrowalter">
                <td class="tbpost">
                    <input type="checkbox" runat="server" id="cb" class="check" value='<%#Eval("Id") %>'/>
                    <asp:HiddenField ID="hfBoxNo" runat="server" Value='<%#Eval("BoxSerialNo") %>' />
                    <asp:HiddenField ID="hfExpressNo" runat="server" Value='<%#Eval("ExpressNo") %>' />
                    <asp:HiddenField ID="hfCode" runat="server" Value='<%#Eval("CustomerCode") %>' />
                     <asp:HiddenField ID="hfWeight" runat="server" Value='<%#Eval("AbroadBoxWeight") %>' />
                     <asp:HiddenField ID="hfSize" runat="server" Value='<%#Eval("Size") %>' />
                 <input type="hidden" id="hfPrint" value='<%#Eval("PrintedById") %>' runat="server" class="hfPri" />    
                </td>
                 <td class="tbpost" style="text-align: center">
                   <%#Eval("CreatedOn") %>
                </td>
                <td class="tbpost" style="text-align: center">
                    <%#Eval("CustomerCode") %>
                </td>
                <td class="tbpost" style="text-align: center">
                        <%#Eval("ExpressNo") %>
                  </td>
                 <td class="tbpost" style="text-align: center">
                          <%#Eval("BoxSerialNo") %>
                    </td>
                 <td class="tbpost" style="text-align: center">
                          <%#Eval("BoxStatuName") %>  
                    </td>
                 <td class="tbpost" style="text-align: center">
                          <%#Eval("BoxCustomerCode") %>
                    </td>
                <td class="tbpost" style="text-align: center">
                        <%#Eval("StatuName") %>
                    </td>
                <td class="tbpost" style="text-align: center">
                        <%#Eval("PackageName") %>
                    </td>
                <td class="tbpost" style="text-align: center">
                      <a Class="buttonGetPic" onclick="return GetPackagePic('<%#Eval("Id").ToString()%>')">查看图片</a>
                    </td>
                   <td class="tbpost" style="text-align: center">
                                             <asp:LinkButton ID="lbnDetail" runat="server" CommandName="detail" CommandArgument='<%#Eval("Id") %>'  ><%=GetText("详情") %></asp:LinkButton>
                  </td>
            </tr>
            </AlternatingItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    <div id="iframeassignCancel">
        <div id="assignWinCancel">
            <table cellpadding="0" cellspacing="0" class="table" border="0">
                <tr>
                    <td class="tbpost"><div class="ShowPic"></div></td>
                </tr>
                <tr>
                    <td class="tbpostheader"></td>
                    <td class="tbpost"></td>
                </tr>
                <tr>
                    <td class="tbpostheader"></td>
                    <td class="tbpost"></td>
                </tr>
            </table>
        </div>
    </div>
    <yee:Pager ID="Pager1" runat="server" PageSize="10" PagerType="1" OnPageIndex_Changed="Pager1_PageIndex_Changed" />
    <script language="javascript" type="text/javascript">
            $(function () {
                $(".hfPri").each(function () {
                    var id = $(this).val();

                    if (id!='') {
                        $(this).parent().nextAll().addClass("trColor");

                    }
                })

            })
    </script>
</asp:Content>

