<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SysRecipeCheckList.aspx.cs" Inherits="Medical.MBusiness.SysRecipeCheck.SysRecipeCheckList" %>

<%@ Register Src="../../Controls/Date.ascx" TagName="Date" TagPrefix="ucDate" %>
<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/LoadButton.ascx" TagName="LoadButton" TagPrefix="ucLoadButton" %>
<!DOCTYPE html>
<html>
<head>
    <title><%=ModuleName%></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/My97DatePicker/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../js/myLib/jsHelper_Form.js" type="text/javascript"></script>
    <script src="../../js/myLib/Pager.js" type="text/javascript"></script>
    <script src="../../js/myLib/Grid.js" type="text/javascript"></script>
</head>
<body>
    <form id="fCondition" name="fCondition" >
    <div class="pt-panel">
        <strong><%=ModuleName%></strong>
            <ucLoadButton:LoadButton ID="LoadButton1" runat="server"/>
            <dl>
                <dt>处方编号</dt>
                <dd><input type="text" name="num" /></dd>
                
            </dl>
            <ucDate:Date ID="ucDate" runat="server" />
            <dl>
                <dt><input type="checkbox" name="isNoCheck" checked="checked" value="1" /></dt>
                <dd>只显示未确认</dd>
            </dl>
            <dl>
                <dt>金额合计：</dt>
                <dd><span id="totalMoney" class="pt-tip">0.00</span>元</dd>
            </dl>
    </div>
    <div class="pt-panel pt-below">
        <strong>查询一览</strong>
        <div class="pt-grid_frame">
            <table id="grid" class="pt-grid">
                <thead>
                    <tr>
                        <th style="width:120px">操作</th>
                        <th>姓名</th>
                        <th>开具日期</th>
                        <th>处方编号</th>
                        <th>诊断</th>
                        <th>医生</th>
                        <th>是否确认</th>
                        <th>实收金额</th>
                    </tr>                    
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <ucPager:Pager ID="gridPager" runat="server" />
    </div>
    <script>
        (function() {
            var url = "SysRecipeCheckList.aspx",
            dialogUrl = "/MBusiness/SysDispensing/DispensingForm.aspx",
            dialogFormName = "Dispensing_Form",
            listbutton = '<%=Medical.MCommon.PageHelper.GetListButton() %>',
            button = $("<div>").append(listbutton),
            grid = new Grid({ id: "grid", url: url, pager: new Pager("gridPager"), bindFun: bindData }),
            title = '<%=ModuleName %>';

            function init() {
                grid.search();
                bindMoney();
                bindEvents();
            }

            function bindEvents() {
                $("#btnQuery").click(function() {
                    grid.search(true);
                    bindMoney();
                });
                $('input[type="text"]').keydown(function(e) {
                    if (e.keyCode == 13) {
                        grid.search(true);
                        bindMoney();
                    }
                });
                grid.control.click(function(e) {
                    var target = $(e.target);
                    if (target.is("input") && !target.is(":disabled")) {
                        var data = target.parent().parent().data("data");
                        switch (target.val()) {
                            case "查看":
                                top.openDialog(dialogUrl + "?type=view&key=" + data.wNum, dialogFormName, title + ' - 查看', 1000, 650, 50, 50);
                                break;
                            case "确认":
                                top.showConfirmMsg("要确认吗?", function(r) {
                                    if (r) {
                                        confirm(data.wNum);
                                    }
                                });
                                break;
                        }
                    }
                });
            }
            function bindMoney() {
                var parms = { action: "getMoney" };
                $.get(url, $.parseJSON(form2JsonString(fCondition, parms)), function(data) {
                    $("#totalMoney").text(data);
                });
            }
            function confirm(num) {
                $.get(url, { action: "confirm", num: num }, function(data) {
                    if (parseInt(data, 10) >0) {
                        top.showTipsMsg('确认成功!', 0, 3000);
                        grid.search();
                    } else {
                        top.showTipsMsg("操作失败!", 1, 4000);
                    }
                });
            }
            function bindData(tr, data) {
                var confirm = data.wCheckState == "已确认", buttonTemp = button.clone();
                if (confirm) {
                    buttonTemp.find('[value="确认"]').removeClass("pt-button active").addClass("pt-button-disabled").attr("disabled", true);
                }
                tr.append($("<td>").html(buttonTemp.html()))
                .append($("<td>").html(data.wName))
                .append($("<td>").html(data.wDate))
                .append($("<td>").html(data.wNum))
                .append($("<td>").html(data.wDiagnosis))
                .append($("<td>").html(data.wDoctor))
                .append($("<td>").html(data.wCheckState))
                .append($("<td>").html(data.cReal));
            }
            init();
        })();
    </script>
    </form>
</body>
</html>
