@model Com._9pm2.ClientWeb.Models.OrderList
@{ViewBag.Title = "客户订单查询"; }

<script src="~/Scripts/ordercommon.js?vn=20180813"></script>
<script src="~/Scripts/orderworkflow.js?vn=20180813"></script>
<script src="../../Scripts/order.js?vn=20180813"></script>

<style>

</style>
<div class="divSearch">
    <form method="post" action="/Order/Index">
        <div>
            @Html.DropDownList("sWorkFlow", new SelectList(Model.DdlWorkFlow, "ItemValue", "ItemText"))
            @Html.DropDownList("sStatus", new SelectList(Model.DdlStatus, "ItemValue", "ItemText"))
            @Html.DropDownList("sPaymentStatus", new SelectList(Model.DdlPaymentStatus, "ItemValue", "ItemText"))
            @Html.DropDownList("sInvoiceStatus", new SelectList(Model.DdlInvoiceStatus, "ItemValue", "ItemText"))
            @Html.DropDownList("sDueDay", new SelectList(Model.DdlDueDay, "ItemValue", "ItemText"))
            @Html.DropDownList("sCustomerNo", new SelectList(Model.DdlCustomer, "ItemValue", "ItemText"), new { @class = "max-width-180" })
            <input type="text" placeholder="客户索引" class="form-control" style="width:80px" id="txtCustomer" />
            @Html.TextBox("sContact", null, new { maxlength = "50", @Style = "width:80px", placeholder = "联系人" })
            <div class="div-search-select2">
                @Html.DropDownList("sMaterialId", new SelectList(Model.DdlMaterial, "ItemValue", "ItemText"), new { @class = "max-width-180" })
            </div>
            @Html.DropDownList("sFactoryNo", new SelectList(Model.DdlFactory, "ItemValue", "ItemText"), new { @class = "max-width-180", style = "display:none" })
            @Html.TextBox("sBeginDate", null, new { maxlength = "50", @class = "text-date", placeholder = "交易日期" }) ~@Html.TextBox("sEndDate", null, new { maxlength = "50", @class = "text-date", placeholder = "交易日期" })
            @Html.TextBox("sCompletionBDate", null, new { maxlength = "50", @class = "text-date", placeholder = "完成日期" }) ~@Html.TextBox("sCompletionEDate", null, new { maxlength = "50", @class = "text-date", placeholder = "完成日期" })
            @Html.TextBox("sUserName", null, new { maxlength = "50", @Style = "width:80px", placeholder = "经办人" })
            @Html.TextBox("sKey", null, new { maxlength = "50", @Style = "width:130px", placeholder = "关键字" })
            <button class="btn btn-default">搜索</button>
        </div>
    </form>
</div>

@{
    Com._9pm2.ClientWeb.Models.LoginUser user = Session["LoginUser"] as Com._9pm2.ClientWeb.Models.LoginUser;
}

<div class="list">


    @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单支付))
    {
        <div class="btn-group">
            <button type="button" class="btn btn-default" onclick="btnBatchPayment();">批量支付</button>
            <button type="button" class="btn btn-default" onclick="btnBatchInvoice();">批量开票</button>
        </div>
    }
    else
    {
        <button type="button" class="btn btn-default" onclick="btnBatchPayment();">批量开票</button>
    }

    <div class="btn-group">
        <button type="button" class="btn btn-default" onclick="btnPrint(@user.PrintDeliveryMethod);">打印业务单</button>
        <button type="button" class="btn btn-default" onclick="btnPrintOrder(@user.PrintOrderMethod);">打印生产单</button>
        <button type="button" class="btn btn-default" onclick="btnPrintInstallation();">打印安装单</button>
    </div>


    <div class="error-msg"></div>

    <table id="tOrder">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" id="chkAll" onclick="SelectAll();" />
                </th>
                @if (Model.ShowCustomerFlag)
                {
                    <th class="th-customer-flag"></th>
                }      
                <th>订单编号</th>
                <th style="min-width:90px">交易日期</th>
                <th style="min-width:90px">客户</th>
                <th style="min-width:90px">订单名</th>                
                <th>明细</th>
                <th style="min-width:40px">数量</th>
                <th style="min-width:40px">单价</th>
                <th style="min-width:40px">金额</th>
                <th style="min-width:50px">总金额</th>
                <th style="min-width:70px">订单状态</th>
                <th style="min-width:70px">支付状态</th>
                @if (Model.ShowOrderDueDay)
                {
                    <th style="min-width:40px" title="距离预完工日期的天数">剩余</th>
                }

                <th style="min-width:40px">附件</th>
                <th style="width:100px">操作</th>
            </tr>
        </thead>
        <tbody id="orderList" class="spanTbody">
            @{
                int j = 0;

                foreach (var item in Model.Orders)
                {
                    int i = 0;

                    string className = j % 2 == 0 ? "odd" : "even";
                    string tilte = "";

                    if (!item.WorkFlowNo.HasValue)
                    {
                        className = className + " order-incompleted";
                        tilte = "此订单数据有待完善，请编辑并完善数据";
                    }

                    foreach (var o in item.Details)
                    {
                        if (i == 0)
                        {
                            <tr id="@item.OrderNo" data-paymenttype="@item.FirstPaymentType" class="@className" title="@tilte">
                                <td class="td-checkbox" rowspan="@item.Details.Count">
                                    <input type="checkbox" onclick="SelectOne();" />
                                </td>
                                @if (Model.ShowCustomerFlag)
                                {
                                    <td rowspan="@item.Details.Count">
                                        @if (!string.IsNullOrEmpty(item.CustomerFlagColor))
                                        {
                                            <div title="@item.CustomerCategoryName" class="customer-flag" style="background-color:@item.CustomerFlagColor ;"></div>
                                        }
                                    </td>
                                }
                                <td rowspan="@item.Details.Count">
                                    @Html.DisplayFor(modelItem => item.OrderNo)
                                </td>
                                <td rowspan="@item.Details.Count">
                                    @item.TransactionDate.ToString("yyyy-MM-dd")
                                </td>
                                <td class="client-name" rowspan="@item.Details.Count">
                                    @Html.DisplayFor(modelItem => item.CustomerShortName)
                                    <input type="hidden" value="@item.CustomerNo" />
                                </td>

                                <td>@o.OrderName</td>
                                @*<td>@o.CategoryName</td>*@
                                <td>
                                    <b>@o.CategoryName</b>
                                    @o.DetailText@(string.IsNullOrEmpty(o.Memo) ? "" : " 备注: " + o.Memo)
                                </td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Number)</td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Price)</td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Amount)</td>

                                <td rowspan="@item.Details.Count">@Com._9pm2.ClientWeb.Utilities.NFormat.Format(item.Amount)</td>
                                <td rowspan="@item.Details.Count">
                                    <span>@Html.DisplayFor(modelItem => item.StatusDescription)</span>
                                </td>

                                <td rowspan="@item.Details.Count">
                                    <span style="display:none" id="s1">@item.Paid</span>
                                    <span style="display:none" id="s2">@item.Unpaid</span>
                                    <span id="spanPaymentStatus">@Html.DisplayFor(modelItem => item.PaymentStatusDescription)</span>
                                </td>
                                @if (Model.ShowOrderDueDay)
                                {
                                    <td rowspan="@item.Details.Count" class="due-day" data-due="@item.DueDay"></td>
                                }
                                <td class="td-img" rowspan="@item.Details.Count">
                                    @if (item.AttachmentNumber > 0)
                                    {
                                        <img src="~/Images/grid/x.png" />
                                    }
                                </td>
                                <td style="text-align:center" class="td-last" rowspan="@item.Details.Count">

                                    <div class="operation-btns">
                                        <div>
                                            <button id="select">&nbsp;</button>
                                        </div>
                                        <ul>

                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单支付))
                                            {
                                                <li><a href="javascript:void(0);" onclick="AddPayment('@item.OrderNo','@item.FirstPaymentType')">支付</a></li>
                                            }

                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_附件上传))
                                            {
                                                <li><a href="javascript:void(0);" onclick="ShowAttachment('@item.OrderNo')">附件</a></li>
                                            }

                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单编辑))
                                            {
                                                <li><a href="javascript:void(0);" onclick="EditOrder('@item.OrderNo','@item.EditModel')">编辑 </a></li>
                                            }

                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单删除))
                                            {
                                                <li><a onclick="DeleteOrder('@item.OrderNo','@item.OrderNo','@item.OrderName')">删除</a></li>
                                            }

                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单创建))
                                            {
                                                <li><a onclick="quickCreate('@item.OrderNo',@item.EditModel)">快速创建</a></li>
                                            }
                                            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P1_客户订单_订单流转) && item.StatusDescription != "已完成" && item.WorkFlowNo.HasValue)
                                            {
                                                <li><a href="javascript:void(0);" onclick="NextStep('@item.OrderNo',false)">流程流转</a></li>
                                            }

                                            @*<li><a href="javascript:void(0);" onclick="Print('@item.OrderNo')">打印配送单</a></li>
                                                <li><a href="javascript:void(0);" onclick="PrintOrder('@item.OrderNo')">打印生产单</a></li>*@

                                        </ul>
                                    </div>                                    
                                </td>
                            </tr>
                        }
                        else
                        {
                            <tr id="@item.OrderNo" class="@className" title="@tilte">
                                <td>@o.OrderName</td>
                                @*<td>@o.CategoryName</td>*@

                                <td>
                                    <b>@o.CategoryName</b>
                                    @o.DetailText@(string.IsNullOrEmpty(o.Memo) ? "" : " 备注: " + o.Memo)
                                </td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Number)</td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Price)</td>
                                <td>@Com._9pm2.ClientWeb.Utilities.NFormat.Format(o.Amount)</td>

                            </tr>
                        }

                        i++;
                    }

                    j++;

                }
            }


            @if (Model.Orders.Count() > 0 && user.ShowOrderTotalAmount)
            {
                <tr class="totalTd">
                    <td colspan="@(Model.ShowCustomerFlag?3:2)">
                        <span>总计(所有页):</span>
                    </td>
                    @*<td></td>*@
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="oderAmountTotal">@Com._9pm2.ClientWeb.Utilities.NFormat.Format(Model.TotalAmount) </td>
                    <td></td>
                    <td></td>
                    @if (Model.ShowOrderDueDay)
                    {
                        <td></td>
                    }   
                    <td></td>
                    <td></td>
                </tr>
            }
        </tbody>
    </table>
    @Html.Pager("Index", "Order", Model.RouterDirectory, Model.PagerConfig, "pagerDiv", "pagerDiv", 8, true, false, true, true, false)
</div>

<div id="divPayment" title="订单支付信息" style="display:none">
    <div id="divPaymentContent" class="">
        <div id="paymentStatusDiv" class="FL" style="margin-bottom:5px;">
            <span class="OrderStatus">支付状态：</span>
            <span id="pdPaymentStatus" class="OrderStatus" ></span>
        </div>
        <div id="" class="FR" style="margin-bottom:5px;">
            <span class="OrderStatus">账户余额：</span>
            <span id="pdBalance" class="money-red"></span>
        </div>
        <div class="gray clear">提示：支付记录不可删除。如果录入错误，可以随后补录一笔负数冲抵。</div>
        <table class="tableEdit">
            <tr>
                <td class="label">
                    支付记录
                </td>
                <td colspan="3" id="PaymentHistory"></td>
            </tr>
            <tr>
                <td class="label">
                    标价金额
                </td>
                <td class='money' id="MarketAmount"></td>
                <td class="label">
                    实际金额
                </td>
                <td class='money' id="Amount"></td>
            </tr>
            <tr>
                <td class="label">
                    已付金额
                </td>
                <td class='money' id="Paid"></td>
                <td class="label">
                    未付金额
                </td>
                <td class='money-red' id="UnPaid"></td>
            </tr>
            <tr>
                <td class="label">
                    折扣金额
                </td>
                <td>
                    <input type="text" id="Discount" class="text-money" />
                </td>
                <td class="label">
                    支付金额
                </td>
                <td>
                    <input type="text" id="PaymentAmount" class="text-money" /> &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr id="trAddPayment2">
                <td class="label">
                    支付方式
                </td>
                <td>
                   @Html.DropDownList("PaymentType", new SelectList(Model.DdlPaymentType, "ItemValue", "ItemText"), new { @style = "width:160px;" }) &nbsp;<span class="redStar">*</span>
                </td>
                <td class="label">
                    备注
                </td>
                <td>
                    <input type="text" style="width: 98%" id="PaymentMemo" />
                </td>
            </tr>         
        </table>
    </div>
    <div style="text-align: right;">
        <div class="error-msg"></div>
        <button type="button" class="btn btn-primary" id="btnAddPayment" onclick="PaymentSubmit()">支付</button>
        <button type="button" class="btn btn-default" onclick="$('#divPayment').dialog('close');">关闭</button>
    </div>
</div>

<div id="divBatchPayment" title="批量支付" style="display: none">
    <div id="divBatchPaymentContent" class="list" style="overflow-y: auto;">
        <div class="text-red clear">提示：支付金额少于未付金额时，系统会优先支付早期订单。</div>
        <table class="tableEdit">
            <tr>
                <td class="label">
                    未付金额
                </td>
                <td class="money-red" id="batchUnpaidAmount"></td>
            </tr>
            <tr>
                <td class="label">
                    支付金额
                </td>
                <td >
                    <input type="text" id="PaymentAmount" class="text-money" /> &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    支付方式
                </td>
                <td>
                    @Html.DropDownList("batchPaymentType", new SelectList(Model.DdlPaymentType, "ItemValue", "ItemText"), new { @style = "width:160px;" }) &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    备注
                </td>
                <td>
                    <input style="width: 98%" type="text" id="batchPaymentMemo" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: right;">

        <div class="error-msg"></div>
        <button type="button" class="btn btn-primary" id="btnAddBatchPayment" onclick="BatchPaymentSubmit()">保存</button>
        <button type="button" class="btn btn-default" onclick="$('#divBatchPayment').dialog('close');">关闭</button>
    </div>
</div>

<div id="divPrintInstallation" title="打印安装单" style="display: none">
    <div id="divPrintInstallationContent" class="list" style="overflow-y: auto;">

        <table class="tableEdit">
            <tr>
                <td class="label">
                    订单名称
                </td>
                <td id="tdOrderNames" ></td>
            </tr>
            <tr>
                <td class="label">
                    安装地址
                </td>
                <td>
                    <input type="text" id="DeliveryAddress" style="width:90%;"/>
                </td>
            </tr>
            <tr>
                <td class="label">
                    安装要求
                </td>
                <td>
                    <textarea id="InstallMemo" style="width:90%;height:80px" ></textarea> 
                </td>
            </tr>
             
        </table>
    </div>
    <div style="text-align: right;">

        <div class="error-msg"></div>
        <button type="button" class="btn btn-primary" id="btnAddBatchPayment" onclick="PrintInstallation(@user.PrintInstallMethod)">打印</button>
        <button type="button" class="btn btn-default" onclick="$('#divPrintInstallation').dialog('close');">关闭</button>
    </div>
</div>

@Html.Partial("OrderDetail", Session["LoginUser"] as Com._9pm2.ClientWeb.Models.LoginUser)
@Html.Partial("OrderAttachment")
@Html.Partial("OrderTransfer")
@Html.Partial("OrderCurrentStep")
<input type="hidden" id="OrderNo" />
