<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EarningTotal.aspx.cs" Inherits="Medical.MQuery.SysCharge.EarningTotal" %>

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="../../css/style.css?v=20150603" 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>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" style="display:none" >
        <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0"></embed>
    </object>
    <script src="../../Scripts/LodopFuncs.js" type="text/javascript"></script>
    <script src="../../js/myLib/Print.js" type="text/javascript"></script>
    <script src="../../js/myLib/helper.js" type="text/javascript"></script>
    <script src="../../js/myLib/jsHelper_Base.js" type="text/javascript"></script>
</head>
<body>
    <div class="pt-panel">
        <strong>门诊收入统计</strong>
        <div class="frmtop">
            <table style="padding: 0px; margin: 0px; height: 100%;" cellpadding="0" cellspacing="0">
                <tr>
                    <td id="menutab" style="vertical-align: bottom;">
                        <div id="tab1" class="Tabsel" >财务报表</div>
                        <div id="tab2" class="Tabremovesel">按科室</div>
                        <div id="tab3" class="Tabremovesel">按医生</div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pt-padding">
            <input type="button" id="btnQuery" class="pt-button active" value="查询" />
            <input type="button" id="btnPrint" class="pt-button active" value="打印" />
        </div>
        <div class="frmbottom">
            <dl id="condition21">
                <dt>科室名称</dt>
                <dd><input type="text" id="department" /></dd>
            </dl>
            <dl id="condition31">
                <dt>医生姓名</dt>
                <dd><input type="text" id="docotor" /></dd>
            </dl>
            <dl>
                <dt>起始日期</dt>
                <dd><input type="text" id="txtStart" onclick="WdatePicker()" runat="server" /></dd>
            </dl>
            <dl>
                <dt>截止日期</dt>
                <dd><input type="text" id="txtEnd" onclick="WdatePicker()" runat="server" /></dd>
            </dl>
        </div>
        <div class="pt-grid_frame" style="height:550px">
            <!--财务报表-->
            <table class="pt-grid" id="grid1" style="width:420px">
                <thead>
                    <tr>
                        <th colspan='2' style="width:150px">项目</th>
                        <th style="width:60px">金额</th>
                        <th colspan='2' style="width:150px">项目</th>
                        <th style="width:60px">金额</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <!--按科室-->
            <table class="pt-grid" id="grid2" style="width:1300px">
                <thead>
                    <tr>
                        <th rowspan='2'>科室名称</th>
                        <th rowspan='2'>处方数</th>
                        <th colspan='2'>药品费</th>
                        <th rowspan='2'>一般诊疗费</th>
                        <th rowspan='2'>床位费</th>
                        <th rowspan='2'>检验费</th>
                        <th rowspan='2'>材料费</th>
                        <th colspan='4'>检查费</th>
                        <th colspan='2'>治疗费</th>
                        <th rowspan='2'>手术费</th>
                        <th rowspan='2'>其他</th>
                        <th rowspan='2'>应收合计</th>
                        <th rowspan='2'>实收合计</th>
                        <%--<th rowspan='2'>新农合报销</th>--%>
                    </tr>
                    <tr>
                        <%--<th>合计</th>
                        <th>新农合</th>
                        <th>普通</th>--%>
                        <th>西药</th>
                        <th>中药</th>
                        <th>心电图</th>
                        <th>B超</th>
                        <th>X线</th>
                        <th>其他</th>
                        <th>西医治疗费</th>
                        <th>中医治疗费</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <!--按医生-->
            <table class="pt-grid" id="grid3" style="width:1300px">
                <thead>
                    <tr>
                        <th rowspan='2'>医生姓名</th>
                        <th rowspan='2'>处方数</th>
                        <th colspan='2'>药品费</th>
                        <th rowspan='2'>一般诊疗费</th>
                        <th rowspan='2'>床位费</th>
                        <th rowspan='2'>检验费</th>
                        <th rowspan='2'>材料费</th>
                        <th colspan='4'>检查费</th>
                        <th colspan='2'>治疗费</th>
                        <th rowspan='2'>手术费</th>
                        <th rowspan='2'>其他</th>
                        <th rowspan='2'>应收合计</th>
                        <th rowspan='2'>实收合计</th>
                        <%--<th rowspan='2'>新农合报销</th>--%>
                    </tr>
                    <tr>
                        <%--<th>合计</th>
                        <th>新农合</th>
                        <th>普通</th>--%>
                        <th>西药</th>
                        <th>中药</th>
                        <th>心电图</th>
                        <th>B超</th>
                        <th>X线</th>
                        <th>其他</th>
                        <th>西医治疗费</th>
                        <th>中医治疗费</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <script>
        (function(){
            var flag=1,
            url = "EarningTotal.aspx",
            printModule = new Print({point: ["10mm", "10mm"]});
            function init(){
                DateValidate(document.getElementById("txtStart"), document.getElementById("txtEnd"));
                $("#grid2").hide();
                $("#grid3").hide();
                
                $("#condition21").hide();
                $('#condition31').hide();
                query();
                bindEvents();
            }
            
            function panel(index){
                flag=index;
                if (index == 1) {
                    $('#grid1').show();
                    $('#grid2').hide();
                    $('#grid3').hide();
                    
                    $("#btnPrint").show();
                    $("#condition21").hide();
                    $('#condition31').hide();
                }else if(index==2){
                    $('#grid1').hide();
                    $('#grid2').show();
                    $('#grid3').hide();
                    
                    $("#btnPrint").hide();
                    $("#condition21").show();
                    $('#condition31').hide();
                }else if(index==3){
                    $('#grid1').hide();
                    $('#grid2').hide();
                    $('#grid3').show();
                    
                    $("#btnPrint").hide();
                    $("#condition21").hide();
                    $('#condition31').show();
                }
            }
            //Tab标签切换
            function GetTabClick(e) {
                $("#menutab div").each(function () {
                    this.className = "Tabremovesel";
                });
                e.className = "Tabsel";
            }
            function query() {
                top.Loading(true);
                var parms={ action: "query", flag:flag, start: $("#txtStart").val(), end: $("#txtEnd").val() };
                if(flag==2){
                    parms={ action: "query", flag:flag, start: $("#txtStart").val(), end: $("#txtEnd").val(), department:$("#department").val() };
                }
                if(flag==3){
                    parms={ action: "query", flag:flag, start: $("#txtStart").val(), end: $("#txtEnd").val(), doctor:$("#docotor").val() };
                }
                $.get(url, parms , function(data) {
                    if (data.length > 0) {
                        switch(flag){
                            case 1:
                                $("#grid1 tbody").html(data);
                                break;
                            case 2:
                                bindGrid("#grid2",data);
                                break;
                            case 3:
                                bindGrid("#grid3",data);
                                break;
                        }
                    }
                });
                top.Loading(false);
            }
            //绑定[按科室]和[按医生]
            function bindGrid(id,data){
                data = eval('('+ data +')'); 
                var container = $("<div>");   
                for (var i in data) {
                    var tr = $("<tr>").data("data", data[i]);
                        for (var j in data[i]) {
                            tr.append($("<td>").html(data[i][j]));
                        }
                    container.append(tr);
                }
                $(id+" tbody").html(container.html());
                //最后一行的合计行字体加粗
                $(id+" tbody tr:last td").css("font-weight","bold");
            }
            function print() {
                $.get(url, { action: "print",start: $("#txtStart").val(), end: $("#txtEnd").val() }, function(data) {
                    printModule.print(data, false);
                });
            }
            function bindEvents(){
                $("#btnPrint").click(function() {
                    print();
                });
                $("#btnQuery").click(function() {
                    query();
                });
                /**
                选项卡
                **/
                $("#tab1").click(function(){
                    GetTabClick(this);
                    panel(1);
                    query();
                });
                $("#tab2").click(function(){
                    GetTabClick(this);
                    panel(2);
                    query();
                });
                $("#tab3").click(function(){
                    GetTabClick(this);
                    panel(3);
                    query();
                });
            }
            init();
        })();
        
    </script>
</body>
</html>
