@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<div class="topdiv">
    <div class="ibox-content">
        <table class="table table-bordered table-striped table-hover">
            <tr>
                <td style="text-align: right;">职员：</td>
                <td>
                    <select id="user">
                        <option value=""></option>
                    </select>
                </td>
                <td style="text-align: right;">签到日期：</td>
                <td>
                    <input type="text" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmStartDate" value="@ViewBag.pmStartDate" />
                </td>
                <td>
                    <input type="text" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmEndDate" value="@ViewBag.pmEndDate" />
                </td>
                <td>
                    <button onclick="Search()" class="btn btn-default"><i class="glyphicon glyphicon-zoom-in"></i>查询</button>
                    <button id="btnExcel" class="btn btn-default"><i class="glyphicon glyphicon-download-alt"></i>导出</button>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="centerdiv">
    <div class="wrapper wrapper-content">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <table id="businessTable"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function bind() {
        $('#businessTable').bootstrapTable({
            url: '../DataQuery/GetUserKaoQin',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            height: $(".centerdiv").height()-10,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "btypeid",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            undefinedText: "",
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    aStrDate: $("#pmStartDate").val(),
                    aEndDate: $("#pmEndDate").val(),
                };
            },//传递参数（*）
            columns: [
                {
                    field: "index", title: "序号", align: "center", width: 50, edit: false, formatter: function (value, row, index) {
                        return row.index = index + 1; //返回行号
                    }
                },
                { field: 'FullName', title: '姓名' },
                { field: 'QDate', title: '日期' },
                { field: 'SignInTimer', title: '签到日期' },
                {
                    field: 'SignInState', title: '签到状态', formatter: function (value, row, index) {
                        if (row["SignIn"] ==null || row["SignIn"] == "")
                        { return " 未签到" }
                        else if (value == "1") {
                            return " 迟到"
                        } else if (value == "0") {
                            return " 正常"
                        } else if (value == "2") {
                            return " 旷工半天"
                        } else if (value == "3") {
                            return " 旷工一天"
                        }
                    }
                },
                { field: 'QInAddress', title: '签到地点' },
                { field: 'SignInSay', title: '签到说明' },
                {
                    field: 'SignInImg', title: '签到照片', align: "center", formatter: function (value, row, index) {
                        return "<button class='btn glyphicon glyphicon-picture'></button>";
                    }
                },
                { field: 'SignOutTimer', title: '签退时间' },
                {
                    field: 'SignOutState', title: '签退状态', formatter: function (value, row, index) {
                        if (row["SignOut"] == null || row["SignOut"] == "")
                        { return " 未签到" }
                        if (value == "1") {
                            return " 早退"
                        } else if (value == "0") {
                            return " 正常"
                        } else if (value == "2") {
                            return " 旷工半天"
                        } else if (value == "3") {
                            return " 旷工一天"
                        }
                    }
                },
                { field: 'QOutAddress', title: '签退地点' },
                { field: 'SignOutSay', title: '签退说明' },
                {
                    field: 'leveal', title: '签退照片', align: "center", formatter: function (value, row, index) {
                        return "<button class='btn glyphicon glyphicon-picture'></button>";
                    }
                }
            ], onClickCell: function (field, value, row, e) {

                var aFlag = "1";
                if (field == "SignInImg") {
                    aFlag = "1";
                    InOutImg(row["LoginID"], row["QDate"], aFlag);
                } else if (field == "leveal") {
                    aFlag = "2";
                    InOutImg(row["LoginID"], row["QDate"], aFlag);
                }
            }
        });
        $(window).resize(function () {
            $('#businessTable').bootstrapTable('resetView');
        });
    };
    $(function () {
        $.ajax({
            url: "../DataQuery/DdlUser",
            type: "post",
            datatype: "text",
            success: function (data) {
                $("#user").append(data);
            }
        })
        bind();
    });
    function Search() {
        var loginid = $("#user").val();
        var aStrDate = $("#pmStartDate").val();
        var aEndDate = $("#pmEndDate").val();
        $('#businessTable').bootstrapTable('refresh', {
            url: '../DataQuery/GetUserKaoQin?loginid=' + loginid + "&aStrDate=" + aStrDate + "&aEndDate=" + aEndDate
        });
    }
    //Excel导出
    $("#btnExcel").on("click", function () {
        var loginid = $("#user").val();
        var aStrDate = $("#pmStartDate").val();
        var aEndDate = $("#pmEndDate").val();
        window.location.href = '../DataQuery/GetExcelUserKaoQin?loginid=' + loginid + "&aStrDate=" + aStrDate + "&aEndDate=" + aEndDate + "&pageSize=1&page=1"

    });
    function InOutImg(loginID, aQDate, aFlag) {
        $.ajax({
            url: "../DataQuery/InOutImg",
            dataType: "json",
            data: {
                loginID: loginID,
                aQDate: aQDate,
                aFlag: aFlag
            },
            type: "post",
            success: function (data) {
                layer.photos({
                    photos: data,
                    shift: 0,
                });
            },
            error: function (data) {
                layer.msg(data, { icon: 5, time: 2000 });
            },
        })
    }
</script>
