<!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 :: datetimepicker-css" />-->
</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" required="required"/>-->
                            <input type="text" style="width:160px" class="form-control" id="beginTime" placeholder="开始时间">

                            <span>-</span>
                            <input type="text" style="width:160px" class="form-control" id="endTime" placeholder="结束时间">

<!--                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime" required="required"/>-->
                        </li>
                        <li>
                            <label>	工位代码：</label>
                            <select name="substation.TableName" id="stationCode" required>
                                <option th:each="ls : ${list}" th:text="${ls.StationCode}" th:value="${ls.StationID}"></option>
                            </select>
                        </li>
                        <li>
                            <label>	产品码：</label>
                            <input type="text" class="text-input" id="semiBarcode" name="semiBarcode"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searc()"><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="expro()" ><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>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-export-js" />
<!--<th:block th:include="include :: datetimepicker-js" />-->
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('nanjing:WorkTrayHistoryInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('nanjing:WorkTrayHistoryInfo:remove')}]];
    var datas = [[${@dict.getType('proState')}]];
    var prefix = ctx + "nanjing/selectStationPara";
    function searc() {
        var formData = new FormData();
        formData.append("stationCode",$("#stationCode").val());
        formData.append("beginTime",$("#beginTime").val());
        formData.append("endTime",$("#endTime").val());
        formData.append("semiBarcode",$("#semiBarcode").val());
        $.ajax({
            type: "post",
            url: prefix + "/list",
            data: formData,
            // contentType: "application/json;charset=utf-8",
            dataType: "json",
            json: 'callback',
            processData: false,
            contentType: false,
            modalName: "工位参数查询",
            showExport: true,//工具栏上显示导出按钮
            success: function (json) {
                console.log(json);
                var columnsArray1 = [];
                //
                columnsArray1.push({field : "序号",title : "序号",colspan: 1,rowspan: 1});
                columnsArray1.push({field : "产品码",title : "产品码",colspan: 1,rowspan: 1});
                columnsArray1.push({field : "状态",title : "状态",colspan: 1,rowspan: 1});
                columnsArray1.push({field : "记录时间",title : "记录时间",colspan: 1,rowspan: 1});
                columnsArray1.push({field : "工位名称",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];
                        if(property!='产品码'&&property!='记录时间'&&property!='序号'&&property!='状态'&&property!='工位名称') {
                            columnsArray1.push({
                                "title": property,
                                "field": property,
                                switchable: true
                            });
                        }
                    }
                }
                // console.log(json);
                // var arrlength=[];
                // json.rows.forEach(function (value) {
                //     var mapsize=Object.keys(value).length;
                //     arrlength.push(mapsize);
                // })
                // console.log(arrlength)
                // var bigValue=arrlength[0];
                // for (var i in  arrlength){
                //     if (arrlength[i]>bigValue){
                //         bigValue=i;
                //     }
                // }
                // console.log(bigValue)
                // console.log(json.rows[bigValue])
                //
                // var columnsArray1 = [];
                // for (var p in json.rows[bigValue])
                // {
                //     columnsArray1.push({field : "p",title : p,colspan: 1,rowspan: 1});
                // }

                // json.rows[bigValue].forEach(function (item,index,arr) {
                //     console.log(item,index,arr)
                // })
                // for(var i = 0; i < json.rows.length; i++)
                // {
                //     // columnsArray1.push({field : x,title : x,colspan: 1,rowspan: 1});
                //     for (x in json.rows[i]) {
                //         // columnsArray1.push({field : x,title : x,colspan: 1,rowspan: 1});
                //         // console.log(x + "=" + json.rows[i][x]);
                //     }
                // }

                // if (json.rows.length>0){
                //     for (var i=0;i<=json.rows.length;i++){
                //         console.log(json.rows[i]);
                //     }
                // }




                // var columnsArray1 = [];
                // columnsArray1.push({field : "系统条码",title : "系统条码",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "semiBarcode" ,title : "产品码",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "机种类型",title : "机种类型",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "返修Y/N",title : "返修Y/N",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "合格状态",title : "合格状态",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "完成状态",title : "完成状态",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "当前工位",title : "当前工位",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "NG工位",title : "NG工位",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "标签Y/N",title : "标签Y/N",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "开始时间",title : "开始时间",colspan: 1,rowspan: 1});
                // columnsArray1.push({field : "结束时间",title : "结束时间",colspan: 1,rowspan: 1});

                $('#bootstrap-table').bootstrapTable('destroy').bootstrapTable({
                    id: "bootstrap-table",
                    data:json.rows,
                    toolbar: "#toolbar",
                    singleSelect: false,
                    clickToSelect: true,
                    sortName: "序号",
                    sortOrder: "desc",
                    pageSize: 50,
                    pageNumber: 1,
                    pageList: "[10, 15,25, 50, All]",
                    showToggle: true,
                    showRefresh: true,
                    showColumns: true,
                    search: false,
                    pagination: true,
                    showExport: true,//工具栏上显示导出按钮
                    exportOptions: {
                        ignoreColumn: false  //忽略第一列和最后一列
                    },
                    columns: columnsArray1
                });

            },
            error: function () {
                alert("查询失败!");
            }
        });
    }
    function expro() {
        $.modal.confirm("确定导出所有" + "工位参数" + "吗？", function() {
            $.modal.loading("正在导出数据，请稍后...");
            $.post(prefix+"/export", function(result) {

            })
        })
    }
    $(function(){
        <!-- laydate示例 -->
        layui.use('laydate', function(){
            var laydate = layui.laydate;


            laydate.render({
                elem: '#beginTime',
                type: 'datetime',
                trigger: 'click'
            });
            laydate.render({
                elem: '#endTime',
                type: 'datetime',
                trigger: 'click'
            });

        });
    });

</script>
</body>
</html>