<%@ page contentType="text/html;charset=UTF-8" %>
<script >
$(document).ready(function () {
    $('#projectTable').bootstrapTable({
        //请求方法
        method: 'post',
        //类型json
        dataType: "json",
        contentType: "application/x-www-form-urlencoded",
        //显示检索按钮
        showSearch: true,
        //显示刷新按钮
        showRefresh: true,
        //显示切换手机试图按钮
        showToggle: true,
        //显示 内容列下拉框
        showColumns: true,
        //显示到处按钮
        showExport: true,
        //显示切换分页按钮
        showPaginationSwitch: true,
        //最低显示2行
        minimumCountColumns: 2,
        //是否显示行间隔色
        striped: true,
        //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        cache: false,
        //是否显示分页（*）
        pagination: true,
        //排序方式
        sortOrder: "asc",
        //初始化加载第一页，默认第一页
        pageNumber: 1,
        //每页的记录行数（*）
        pageSize: 5,
        //可供选择的每页的行数（*）
        pageList: [5, 10, 25, 50, 100],
        //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
        url: "${ctx}/sg/managementCenter/reserveManagement/list",
        //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
        //queryParamsType:'',
        ////查询参数,每次调用是会带上这个参数，可自定义
        queryParams: function (params) {
            var searchParam = $("#searchForm").serializeJSON();
            searchParam.pageNo = params.limit === undefined ? "1" : params.offset / params.limit + 1;
            searchParam.pageSize = params.limit === undefined ? -1 : params.limit;
            searchParam.orderBy = params.sort === undefined ? "" : params.sort + " " + params.order;
            return searchParam;
        },
        //分页方式：client客户端分页，server服务端分页（*）
        sidePagination: "server",
        contextMenuTrigger: "right",//pc端 按右键弹出菜单
        contextMenuTriggerMobile: "press",//手机端 弹出菜单，click：单击， press：长按。
        contextMenu: '#context-menu',
        onContextMenuItem: function (row, $el) {
            if ($el.data("item") == "edit") {
                edit(row.id);
            } else if ($el.data("item") == "view") {
                view(row.id);
            } else if ($el.data("item") == "delete") {
                jp.confirm('确认要删除该表单记录吗？', function () {
                    jp.loading();
                    jp.get("${ctx}/sg/managementcenter/project/delete?id=" + row.id, function (data) {
                        if (data.success) {
                            $('#projectTable').bootstrapTable('refresh');
                            jp.success(data.msg);
                        } else {
                            jp.error(data.msg);
                        }
                    })
                });
            }
        },

        onClickRow: function (row, $el) {
        },
        onShowSearch: function () {
            $("#search-collapse").slideToggle();
        },
        columns:
            [
                {
                    checkbox: true,
                    width:36,
                   
                }
                , {
                    field: 'projectNature',
                    width:65,
                    title: '项目</br>性质',
                   
                },{
                    field: 'demandUnit',
                    width:70,
                    title: '需求</br>单位',
                   
                },{
                    field: 'district',
                    width:60,
                    title: '区域',
                   
                },{
                    field: 'projectGroup',
                    width:70,
                    title: '项目</br>分组',
                   
                },{
                    field: 'reserveBatches',
                    width:70,
                    title: '储备</br>批次',
                   
                },{
                    field: 'blockSupply',
                    width:60,
                    title: '供电</br>区域',
                   
                },{
                    field: 'gridNumber',
                    width:90,
                    title: '网格编号',
                   
                },{
                    field: 'cellNumber',
                    width:100,
                    title: '单元格编号',
                   
                },{
                    field: 'projectReserveId',
                    width:150,
                    title: '项目储备编号',
                   
                    formatter:function(value, row , index){
                        if(value == null || value ==""){
                            value = "-";
                        }
                    <c:choose>
                        <c:when test="${fns:hasPermission('sg:managementcenter:reserveManagement:view')}">
                        return "<a href='javascript:view(\""+row.id+"\")'>"+value+"</a>";
                    </c:when>
                        <c:otherwise>
                        return value;
                    </c:otherwise>
                        </c:choose>

                    }
                },{
                    field: 'powerGridProjectId',
                    width:100,
                    title: '电网项目</br>编号',
                   
                },{
                    field: 'projectName',
                    width:200,
                    title: '项目名称',
                   
                },{
                    field: 'constructionNecessityAndContent',
                    width:400,
                    title: '建设必要性及内容',
                   
                },{
                    field: 'substationName',
                    width:80,
                    title: '变电站</br>名称',
                   
                },{
                    field: 'circuitName',
                    width:100,
                    title: '线路名称',
                   
                },{
                    field: 'netRackProjectDivide',
                    width:80,
                    title: '网架项目</br>划分',
                   
                },{
                    field: 'projectType',
                    width:100,
                    title: '项目类型',
                   
                },{
                    field: 'costEstimate',
                    width:80,
                    title: '费用</br>估算',
                   
                },{
                    field: 'whetherWindwardProject',
                    width:80,
                    title: '是否</br>迎峰度夏</br>项目',
                   
                },{
                    field: 'projectUrgencyDegree',
                    width:80,
                    title: '项目</br>紧急程度',
                   
                },{
                    field: 'implementIssuedYear',
                    width:100,
                    title: '拟实施下达</br>年份',
                   
                },{
                    field: 'implementBatch',
                    width:100,
                    title: '拟实施批次',
                   
                },{
                    field: 'basicRemarks',
                    width:200,
                    title: '备注',
                   
                },
/*设计及评审情况*/
                {
                    field: 'designCondition',
                    width:80,
                    title: '设计</br>状态',
                   
                },{
                    field: 'whetherPassReview',
                    width:80,
                    title: '是否</br>通过</br>省公司</br>评审',
                   
                },{
                    field: 'whetherNeedWiringDiagram',
                    width:60,
                    title: '是否</br>需提交</br>路径图',
                   
                },{
                    field: 'whetherFinishMaterials',
                    width:80,
                    title: '是否</br>完成物资</br>清册编制',
                   
                },{
                    field: 'whetherFinishDrawing',
                    width:60,
                    title: '是否</br>完成</br>图纸</br>移交',
                   
                },
        ]
    });


    if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端
        $('#projectTable').bootstrapTable("toggleView");
    }

    $('#projectTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
        'check-all.bs.table uncheck-all.bs.table', function () {
        $('#remove').prop('disabled', !$('#projectTable').bootstrapTable('getSelections').length);
        $('#view,#edit,#jlEdit').prop('disabled', $('#projectTable').bootstrapTable('getSelections').length != 1);
    });

    $("#btnImport").click(function () {
        jp.open({
            type: 2,
            area: [500, 200],
            auto: true,
            title: "导入数据",
            content: "${ctx}/tag/importExcel",
            btn: ['确定', '关闭'],
            btn1: function (index, layero) {
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.contentWindow.importExcel('${ctx}/sg/managementCenter/reserveManagement/import', function (data) {
                    if (data.success) {
                        jp.success(data.msg);
                        refresh();
                    } else {
                        jp.error(data.msg);
                    }
                    jp.close(index);
                });//调用保存事件
                return false;
            },
            btn2: function (index) {
                //  jp.close(index);
            }
        });
    });

    $("#jlImport").click(function () {
        jp.open({
            type: 2,
            area: [500, 200],
            auto: true,
            title: "导入数据",
            content: "${ctx}/tag/importExcel",
            btn: ['确定', '关闭'],
            btn1: function (index, layero) {
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.contentWindow.importExcel('${ctx}/sg/managementCenter/reserveManagement/jlImport', function (data) {
                    if (data.success) {
                        jp.success(data.msg);
                        refresh();
                    } else {
                        jp.error(data.msg);
                    }
                    jp.close(index);
                });//调用保存事件
                return false;
            },

            btn2: function (index) {
                //  jp.close(index);
            }
        });
    });

    $("#btnExport").click(function () {
        var projectReserveId = $("#projectReserveId").val();
        var projectName = $("#projectName").val();
        jp.downloadFile('${ctx}/sg/managementCenter/reserveManagement/export?projectReserveId=' + projectReserveId + '&projectName=' + projectName);
    });

    $("#search").click("click", function () {// 绑定查询按扭
        $('#projectTable').bootstrapTable('refresh');
    });

    $("#reset").click("click", function () {// 绑定查询按扭
        $("#searchForm  input").val("");
        $("#searchForm  select").val("");
        $("#searchForm  .select-item").html("");
        $('#projectTable').bootstrapTable('refresh');
    });

    $('#beginBeginDate').datetimepicker({
        format: "YYYY-MM-DD HH:mm:ss"
    });
    $('#endBeginDate').datetimepicker({
        format: "YYYY-MM-DD HH:mm:ss"
    });
    $('#endDate').datetimepicker({
        format: "YYYY-MM-DD HH:mm:ss"
    });
});

function getIdSelections() {
    return $.map($("#projectTable").bootstrapTable('getSelections'), function (row) {
        return row.id
    });
}


//刷新列表
function refresh() {
    $('#projectTable').bootstrapTable('refresh');
}

function add() {
    jp.openSaveDialog('新增储备项目基本信息', "${ctx}/sg/managementCenter/reserveManagement/form", '800px', '500px');
}


function edit(id) {//没有权限时，不显示确定按钮
    if (id == undefined) {
        id = getIdSelections();
    }
    jp.openSaveDialog('编辑储备项目基本信息', "${ctx}/sg/managementCenter/reserveManagement/form?id=" + id, '800px', '500px');
}

function jlEdit(id) {//没有权限时，不显示确定按钮
    if (id == undefined) {
        id = getIdSelections();
    }
    jp.openSaveDialog('编辑储备项目基本信息', "${ctx}/sg/managementCenter/reserveManagement/jlEdit?id=" + id, '800px', '500px');
}

function view(id) {//没有权限时，不显示确定按钮
    if (id == undefined) {
        id = getIdSelections();
    }
    jp.openViewDialog('查看储备项目基本信息', "${ctx}/sg/managementCenter/reserveManagement/view?id=" + id, '800px', '500px');
}

function deleteAll(){

    jp.confirm('确认要删除该储备项目基本信息吗？', function(){
        jp.loading();
        jp.get("${ctx}/sg/managementCenter/reserveManagement/deleteAll?ids=" + getIdSelections(), function(data){
            if(data.success){
                $('#projectTable').bootstrapTable('refresh');
                jp.success(data.msg);
            }else{
                jp.error(data.msg);
            }
        })

    })
}
//转换日期格式(时间戳转换为datetime格式)
function changeDateFormat(cellval) {
    var dateVal = cellval + "";
    if (cellval != null) {
        var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

        /*var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();*/

        return date.getFullYear() + "-" + month + "-" + currentDate /*+ " " + hours + ":" + minutes + ":" + seconds*/;
    }
}

</script>