#@layout()
#define main()
<style>
     .class-22 td {
         vertical-align: middle;
     }
</style>
<div>
    <div class="line"></div>
    <header>
        <style media="screen">
            table{
                border-collapse: collapse;
            }
        </style>
    </header>
    <body>
    <button style="float: right;margin-right: 50px;margin-bottom: 10px" type="button" onclick="tableToExcel('item','图书分类统计')" class="layui-btn layui-btn-sm">导出</button>
    <table border="1px" class="layui-table class-22" id="item">
        <tr>
            <td colspan="1">五大部类</td>
            <td colspan="1">22个基本类</td>
            <td colspan="1">种数</td>
            <td colspan="1">总册数</td>
            <td colspan="1">图书分类比例</td>
        </tr>
        <tr>
        <td colspan="1">第一大类</td>
        <td colspan="1">A马克思主义、列宁主义、毛泽东思想、邓小平理论</td>
        <td colspan="1" id="A">0</td>
        <td colspan="1" id="A1">0</td>
        <td colspan="1" id="ratio0">0</td>
    </tr>
        <tr>
            <td colspan="1">第二大类</td>
            <td colspan="1">B哲学、宗教</td>
            <td colspan="1" id="B">0</td>
            <td colspan="1" id="B1">0</td>
            <td colspan="1" id="ratio1">0</td>
        </tr>
        <tr>
            <td rowspan="9">第三大类</td>
            <td colspan="1">C社会科学总论</td>
            <td colspan="1" id="C">0</td>
            <td colspan="1" id="C1">0</td>
            <td rowspan="9" id="ratio2">0</td>
        </tr>
        <tr>
            <td colspan="1">D政治法律</td>
            <td colspan="1" id="D">0</td>
            <td colspan="1" id="D1">0</td>
        </tr>
        <tr>
            <td colspan="1">E军事</td>
            <td colspan="1" id="E">0</td>
            <td colspan="1" id="E1">0</td>
        </tr>
        <tr>
            <td colspan="1">F经济</td>
            <td colspan="1" id="F">0</td>
            <td colspan="1" id="F1">0</td>
        </tr>
        <tr>
            <td colspan="1">G文化科学、教育、体育</td>
            <td colspan="1" id="G">0</td>
            <td colspan="1" id="G1">0</td>
        </tr>
        <tr>
            <td colspan="1">H语言、文字</td>
            <td colspan="1" id="H">0</td>
            <td colspan="1" id="H1">0</td>
        </tr>
        <tr>
            <td colspan="1">I文学</td>
            <td colspan="1" id="I">0</td>
            <td colspan="1" id="I1">0</td>
        </tr>
        <tr>
            <td colspan="1">J艺术</td>
            <td colspan="1" id="J">0</td>
            <td colspan="1" id="J1">0</td>
        </tr>
        <tr>
            <td colspan="1">K历史、地理</td>
            <td colspan="1" id="K">0</td>
            <td colspan="1" id="K1">0</td>
        </tr>
        <tr>
            <td rowspan="10">第四大类</td>
            <td colspan="1">N自然科学总论</td>
            <td colspan="1" id="N">0</td>
            <td colspan="1" id="N1">0</td>
            <td rowspan="10" id="ratio3">0</td>
        </tr>
        <tr>
            <td colspan="1">O数理科学和化学</td>
            <td colspan="1" id="O">0</td>
            <td colspan="1" id="O1">0</td>
        </tr>
        <tr>
            <td colspan="1">P天文学、地球科学</td>
            <td colspan="1" id="P">0</td>
            <td colspan="1" id="P1">0</td>
        </tr>
        <tr>
            <td colspan="1">Q生物科学</td>
            <td colspan="1" id="Q">0</td>
            <td colspan="1" id="Q1">0</td>
        </tr>
        <tr>
            <td colspan="1">R医药、卫生</td>
            <td colspan="1" id="R">0</td>
            <td colspan="1" id="R1">0</td>
        </tr>
        <tr>
            <td colspan="1">S农业科学</td>
            <td colspan="1" id="S">0</td>
            <td colspan="1" id="S1">0</td>
        </tr>
        <tr>
            <td colspan="1">T工业技术</td>
            <td colspan="1" id="T">0</td>
            <td colspan="1" id="T1">0</td>
        </tr>
        <tr>
            <td colspan="1">U交通运输</td>
            <td colspan="1" id="U">0</td>
            <td colspan="1" id="U1">0</td>
        </tr>
        <tr>
            <td colspan="1">V航空、航天</td>
            <td colspan="1" id="V">0</td>
            <td colspan="1" id="V1">0</td>
        </tr>
        <tr>
            <td colspan="1">X环境科学、安全科学</td>
            <td colspan="1" id="X">0</td>
            <td colspan="1" id="X1">0</td>
        </tr>
        <tr>
            <td rowspan="1">第五大类</td>
            <td colspan="1">Z综合性图书</td>
            <td colspan="1" id="Z">0</td>
            <td colspan="1" id="Z1">0</td>
            <td rowspan="1" id="ratio4">0</td>
        </tr>
        <tr style="color: red">
            <td rowspan="1">合计</td>
            <td colspan="1"></td>
            <td colspan="1" id="zs">0</td>
            <td colspan="1" id="cs">0</td>
            <td rowspan="1"></td>
        </tr>
    </table>
    </body>

</div>
#end
#define methods()

<script>

    //22大类
    var totalcs =0;
    var totalzs =0;
    var cs_1 = 0;
    var zs_1 = 0;
    var zs_2 = 0;
    var cs_2 = 0;
    var zs_3 = 0;
    var cs_3 = 0;
    var zs_4 = 0;
    var cs_4 = 0;
    var zs_5 = 0;
    var cs_5 = 0;

    $.ajax({
        url: "/classificationStatistics/bookClassificationStatistics",
        type: "POST",
        data:{orgid:JSON.parse(sessionStorage.loginData).orgid,token:JSON.parse(sessionStorage.loginData).token},
        traditional: true,
        success: function(result) {
            if(result.code==200){
                for(var i=0;i<result.data.length;i++){
                    var id = result.data[i].id;
                    if(id != null){
                        $("#"+id).text(result.data[i].zs);
                        $("#"+id+"1").text(result.data[i].cs);
                        totalcs+=result.data[i].cs;
                        totalzs +=result.data[i].zs;
                        if(id == 'A'){
                            zs_1+=result.data[i].zs;
                            cs_1+=result.data[i].cs;
                        }else if(id == 'B'){
                            zs_2+=result.data[i].zs;
                            cs_2+=result.data[i].cs;
                        }else if(id == 'C' || id=='D' || id=='E' || id=='F' || id=='G' || id=='H' || id=='I' || id=='J' || id=='K'){
                            zs_3+=result.data[i].zs;
                            cs_3+=result.data[i].cs;
                        }else if(id == 'N' || id=='O' || id=='P' || id=='Q' || id=='R' || id=='S' || id=='T' || id=='U' || id=='V' || id=='X'){
                            zs_4+=result.data[i].zs;
                            cs_4+=result.data[i].cs;
                        }else if(id == 'Z'){
                            zs_5+=result.data[i].zs;
                            cs_5+=result.data[i].cs;
                        }
                    }
                }
                $("#zs").text(totalzs);
                $("#cs").text(totalcs);
                if(totalcs == 0){
                    $("#ratio0").text("0%");
                    $("#ratio1").text("0%");
                    $("#ratio2").text("0%");
                    $("#ratio3").text("0%");
                    $("#ratio4").text("0%");
                }else{
                    $("#ratio0").text(((cs_1 / totalcs) * 100).toFixed(2)+"%");
                    $("#ratio1").text(((cs_2 / totalcs) * 100).toFixed(2)+"%");
                    $("#ratio2").text(((cs_3 / totalcs) * 100).toFixed(2)+"%");
                    $("#ratio3").text(((cs_4 / totalcs) * 100).toFixed(2)+"%");
                    $("#ratio4").text(((cs_5 / totalcs) * 100).toFixed(2)+"%");
                }

            }
        }
    });


    /*//比例
    $.ajax({
        url: "/classificationStatistics/bookFiveClassificationStatistics",
        type: "POST",
        data:{orgid:JSON.parse(sessionStorage.loginData).orgid,token:JSON.parse(sessionStorage.loginData).token},
        traditional: true,
        success: function(result) {
            if(result.code==200){
                for(var i=0;i<result.data.length;i++){
                    var cs = result.data[i].cs;
                    var ratio = (cs / zcs).toFixed(2) * 100;
                    var ratios = ratio+"%";
                    $("#ratio"+i).text(ratios);
                }
            }
        }
    });*/

    function base64 (content) {
        return window.btoa(unescape(encodeURIComponent(content)));
    }
    /*
    *@tableId: table的Id
    *@fileName: 要生成excel文件的名字（不包括后缀，可随意填写）
    */
    function tableToExcel(tableID,fileName){
        var table = document.getElementById(tableID);
        var excelContent = table.innerHTML;
        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
        excelFile += "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>";
        excelFile += "<body><table>";
        excelFile += excelContent;
        excelFile += "</table></body>";
        excelFile += "</html>";
        var link = "data:application/vnd.ms-excel;base64," + base64(excelFile);
        var a = document.createElement("a");
        a.download = fileName+".xlsx";
        a.href = link;
        a.click();
    }

</script>
#end
