<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工位合格率统计')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">

            <div class="ui-layout-west">
                <div class="box box-main">
                    <div class="box-header">
                        <div class="box-title">
                            <i class="fa icon-grid"></i> 工位名称
                        </div>
                        <div class="box-tools pull-right">
<!--                            <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="工位信息"><i class="fa fa-edit"></i></a>-->
<!--                            <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>-->
<!--                            <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>-->
                            <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新工位"><i class="fa fa-refresh"></i></button>
                        </div>
                    </div>
                    <div class="ui-layout-content">
                        <div id="tree" class="ztree"></div>
                    </div>
                </div>
            </div>

            <div class="ui-layout-center">
                <div class="container-div">
                    <div class="row">
                        <div class="col-sm-12 search-collapse">
                            <form id="formId">
                                <input type="hidden" id="stationId" name="stationId">
                                <input type="hidden" id="parentId" name="parentId">
                                <div class="select-list">
                                    <ul>
                                        <li class="select-time">
                                            <label>时间区间： </label>
                                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginTime" required/>
                                            <span>-</span>
                                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime" required/>
                                        </li>
                                        <li>
                                            <label>机种类型：</label>
                                            <select name="productId" id="product">
                                                <option value="ALL">所有</option>
                                                <option th:each="ls:${list}" th:value="${ls.productID}" th:text="${ls.productName}"></option>
                                            </select>
                                        </li>

                                        <li>
                                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchAll()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                            <!--                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;查询全部</a>-->
<!--                                            <a class="btn btn-info btn-rounded btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="nanjing:QsProduct:export"><i class="fa fa-download"></i> 导出</a>-->
                                        </li>
                                    </ul>
                                </div>
                            </form>
                        </div>
                        <div class="col-sm-12 select-table table-striped">
                            <table id="bootstrap-table"></table>
                        </div>
                    </div>
                </div>
            </div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var prefix = ctx + "nanjing/StatisticStation";
    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        // queryList();
        queryDeptTree();
    });

    // function queryList(url) {
    //     console.log(url);
    //     var options = {
    //         // url: url,
    //         // exportUrl: prefix + "/export",
    //         modalName: "工位合格率统计",
    //         columns: [
    //             {
    //                 field: 'productTp',
    //                 title: '机种类型'
    //             },
    //             {
    //                 field: 'inputNum',
    //                 title: '投入量'
    //             },
    //             {
    //                 field: 'okNum',
    //                 title: '合格品'
    //             },
    //             {
    //                 field:'noNum',
    //                 title:'不合格品'
    //             },
    //             {
    //                 field:'ero',
    //                 title:'异常'
    //             },
    //             {
    //                 field: 'allRate',
    //                 title: '综合合格率',
    //             }
    //         ]
    //     };
    //     $.table.init(options);
    // }

    function searchAll(){
        // console.log("点击查询按钮事件执行...");
        var url = ctx + "nanjing/StatisticStation/listAll";
        // queryList(url);
        $('#bootstrap-table').bootstrapTable('destroy');
        $('#bootstrap-table').bootstrapTable({
            method:"post",
            url: url,
            pagination: true,
            search: true,
            contentType : "application/x-www-form-urlencoded",
            queryParams:  {
                begin:$('#startTime').val(),
                end:$('#endTime').val()
            },
            modalName: "工位合格率统计",
            columns: [
                 {
                     field: 'productTp',
                     title: '机种类型'
                 },
                 {
                     field: 'inputNum',
                     title: '投入量'
                 },
                 {
                     field: 'okNum',
                     title: '合格品'
                 },
                 {
                     field:'noNum',
                     title:'不合格品'
                 },
                 {
                     field:'ero',
                     title:'异常'
                 },
                 {
                     field: 'allRate',
                     title: '综合合格率',
                 }
            ]
        })
    }

    function queryDeptTree()
    {
        // console.log("加载树执行。。。。。。");
        var url = ctx + "nanjing/SubStation/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            // queryList(prefix + "/list");
            console.log("点击节点工位ID"+treeNode.id);
            $("#stationId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            // $.table.search();
            $('#bootstrap-table').bootstrapTable('destroy');
            $('#bootstrap-table').bootstrapTable({
                method:"post",
                url: prefix+"/nodeClick",
                pagination: true,
                search: true,
                contentType : "application/x-www-form-urlencoded",
                queryParams:
                {
                    begin:$('#startTime').val(),
                    end:$('#endTime').val(),
                    node:$('#stationId').val()
                },
                modalName: "工位合格率统计",
                columns: [
                    {
                        field: 'stationCode',
                        title: '工位代码'
                    },
                    {
                        field: 'stationName',
                        title: '工位名称'
                    },
                    {
                        field: 'inputNum',
                        title: '总数量'
                    },
                    {
                        field: 'okNum',
                        title: '合格数量'
                    },
                    {
                        field:'ero',
                        title:'异常数量'
                    },
                    {
                        field: 'allRate',
                        title: '合格率',
                    }
                ]
            })

        }
    }

    /* 工位信息 */
    function dept() {
        var url = ctx + "nanjing/SubStation/list";
        $.modal.openTab("工位信息", url);
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryDeptTree();
    });
</script>
</body>
</html>