<!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('产品条码信息')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label>时间区间： </label>
                            <input type="text" class="time-input" id="beginTime" placeholder="开始时间" name="beginTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <label>产品条码:</label>
                            <input type="text"  id="barcode" name="barcode"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchpara()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<!--                            <a class="btn btn-warning btn-rounded btn-sm" onclick="expro()"><i class="fa fa-download"></i>&nbsp;导出</a>-->
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
            </table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-export-js" />
<script th:inline="javascript">
    var stateDatas = [[${@dict.getType('is_not_yx')}]];
    function searchpara(){
        // console.log("点击查询按钮事件执行...");
        //     //方式1：行转列

        var formData = new FormData();
        formData.append("begin",$('#beginTime').val());
        formData.append("end",$('#endTime').val());
        formData.append("barcode",$('#barcode').val());
        $.ajax({
            type: "post",
            url: ctx + "nanjing/reportData/report",
            data: formData,
            // contentType: "application/json;charset=utf-8",
            dataType: "json",
            json: 'callback',
            processData: false,
            contentType: false,
            success: function (json) {
                console.log(json)
                var columnsArray = [];
                columnsArray.push({field : "Barcode",title : "产品条码",colspan: 1,rowspan: 1});
                if(json.total>0){
                    for (var i = 0; i < (Object.keys(json.rows[0])).length; i++) {//Object.keys(obj) 获取key名称
                        var property = (Object.keys(json.rows[0]))[i];
                        console.log(property)

                        if(property!='Barcode' && property!="ProductBarcode"){
                            columnsArray.push({
                                    "title": property,
                                    "field": property,
                                    switchable: true,
                                    align:"center",
                                }
                            );

                    }

                    }
                }
                // coulmnsData.push(columnsArray);
                // coulmnsData.push(columns);
                console.log(columnsArray);
                $('#bootstrap-table').bootstrapTable('destroy').bootstrapTable({
                    id: "bootstrap-table",
                    data:json,
                    toolbar: "#toolbar",
                    singleSelect: false,
                    // clickToSelect: true,
                    sortName: "barcode",
                    sortOrder: "desc",
                    pageSize: 15,
                    pageNumber: 1,
                    pageList: "[10, 15,25, 50, 100, All]",
                    // showToggle: true,
                    // showRefresh: true,
                    // showColumns: true,
                    search: false,
                    pagination: true,
                    showExport: true,//工具栏上显示导出按钮
                    exportOptions: {
                        ignoreColumn: false  //忽略第一列和最后一列
                    },
                    // exportDataType: 'all',
                    fixedColumns: true,
                    fixedNumber: 4,
                    fixedLeftNumber: 4,
                    columns: columnsArray
                });
                // columnsArray.push();
            },
            error: function () {
                alert("错误");
            }
        });
        // 方式2 不进行行转列
        //     var url =  ctx + "nanjing/reportData/report";
        //     $('#bootstrap-table').bootstrapTable('destroy');
        //     $('#bootstrap-table').bootstrapTable({
        //         method:"post",
        //         url: url,
        //         pagination: true,
        //         search: true,
        //         contentType : "application/x-www-form-urlencoded",
        //         queryParams:  {
        //             begin:$('#beginTime').val(),
        //             end:$('#endTime').val(),
        //             barcode:$('#barcode').val()
        //         },
        //         modalName: "条码信息查询",
        //         columns: [
        //             {
        //                 field: 'id',
        //                 title: '序号'
        //             },
        //             {
        //                 field: 'barcode',
        //                 title: '系统条码'
        //             },
        //             {
        //                 field: 'parameaning',
        //                 title: '参数名'
        //             },
        //             {
        //                 field:'value',
        //                 title:'参数值'
        //             },
        //         ],
        //     })

    }
    function expro() {
        var formData = new FormData();
        formData.append("begin",$('#beginTime').val());
        formData.append("end",$('#endTime').val());
        formData.append("barcode",$('#barcode').val());
        $.modal.confirm("确定导出所有" + "信息" + "吗？", function() {
            $.modal.loading("正在导出数据，请稍后...");
            $.ajax({
                type: "post",
                url: ctx + "nanjing/reportData/export",
                data: formData,
                // contentType: "application/json;charset=utf-8",
                dataType: "json",
                json: 'callback',
                processData: false,
                contentType: false,
                success: function (result){
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    }
                    $.modal.closeLoading();
                }
            })
        })
    }
</script>
</body>
</html>