<%@ 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/moduleForm",
        //默认值为 '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,
                    rowspan:2,
                }
               ,{
                    field: 'projectReserveId',
                    width:150,
                    title: '项目储备编号',
                    rowspan:2,
                    formatter:function(value, row , index){
                        if(value == null || value ==""){
                            value = "-";
                        }
                    <c:choose>
                        <c:when test="${fns:hasPermission('sg:managementcenter:reserveManagement:jlEdit')}">
                        return "<a href='javascript:jlEdit(\""+row.id+"\")'>"+value+"</a>";
                    </c:when>
                        <c:otherwise>
                        return value;
                    </c:otherwise>
                        </c:choose>

                    }
                },{
                field: 'projectName',
                width:100,
                title: '项目名称',
                rowspan:2,
                },
/*方案交底组织*/
                {
                    field: 'disclosureToCoordinate',
                    width:100,
                    title: '交底牵头</br>部门',
                    rowspan:2,
                },{
                    field: 'disclosureParticipate',
                    width:100,
                    title: '交底参与</br>部门',
                    rowspan:2,
                },{
                    field: 'whetherFinishDisclosure',
                    width:60,
                    title: '是否</br>完成</br>交底',
                    rowspan:2,
                },{
                    field: 'projectManagementPeople',
                    width:80,
                    title: '项目</br>管理中心</br>人员',
                    rowspan:2,
                },{
                    field: 'designingInstitutePeople',
                    width:70,
                    title: '设计院</br>人员',
                    rowspan:2,
                },{
                    field: 'ifoPeople',
                    width:70,
                    title: '经研所</br>人员',
                    rowspan:2,
                },{
                    field: 'regionalCenterPeople',
                    width:70,
                    title: '区域</br>中心</br>人员',
                    rowspan:2,
                },{
                    field: 'uninterruptedOperationPeople',
                    width:80,
                    title: '不停电</br>作业</br>中心人员',
                    rowspan:2,
                },{
                    field: 'workMode',
                    width:100,
                    title: '作业方式',
                    rowspan:2,
                },{
                    field: 'disclosureFinishDate',
                    width:100,
                    title: '交底完成</br>日期',
                    rowspan:2,
                    //——修改——获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    },
                },{
                    field: 'disclosureRemarks',
                    width:200,
                    title: '备注',
                    rowspan:2,
                },
/*方案交底结论*/
                {
                    title: "交底结论",
                    width:400,
                    colspan:4,
                },{
                    title: "成本资本划分",
                    width:200,
                    colspan:2,
                },{
                    title: "现场是否实施",
                    width:200,
                    colspan:2,
                },{
                    title: "实施必要性",
                    width:200,
                    colspan:2,
                },{
                    title: "施工前置条件检查",
                    width:200,
                    colspan:2,
                },{
                    title: "施工方案可行性检查",
                    width:200,
                    colspan:2,
                },{
                    title: "方案安全性检查",
                    width:200,
                    colspan:2,
                },{
                    title: "物资交底",
                    width:300,
                    colspan:3,
                },{
                    title: "作业方式",
                    width:200,
                    colspan:2,
                },{
                    title: "工作量描述",
                    width:300,
                    colspan:3,
                },{
                    title: "政处交底",
                    width:900,
                    colspan:9,
                }
            ],[
                {
                    field: 'projectDescription',
                    width:100,
                    title: '立项说明',
                },
                {
                    field: 'doNotPossessProjectDescription',
                    width:100,
                    title: '不具备立项</br>条件说明',
                },
                {
                    field: 'changedProgramsExplain',
                    width:100,
                    title: '方案变更</br>说明',
                },
                {
                    field: 'initialDifficulty',
                    width:100,
                    title: '政处</br>难度初判',
                },
                {
                    field: 'capitalEquipment',
                    width:770,
                    title: '是否有</br>资本</br>设备',
                },
                {
                    field: 'substationNewLine',
                    width:70,
                    title: '是否有</br>变电站</br>新出线',
                },
                {
                    field: 'whetherImplement',
                    width:70,
                    title: '是否</br>已实施',
                },
                {
                    field: 'fieldDescription',
                    width:100,
                    title: '现场情况</br>描述',
                },
                {
                    field: 'necessaryOfImplementation',
                    width:70,
                    title: '是否有</br>实施</br>必要性',
                },
                {
                    field: 'unnecessaryDescription',
                    width:100,
                    title: '实施无必要</br>描述',
                },
                {
                    field: 'precondition',
                    width:80,
                    title: '是否</br>存在</br>前置条件',
                },
                {
                    field: 'conditionsDescribed',
                    width:100,
                    title: '前置条件</br>描述',
                },
                {
                    field: 'constructionSchemeProblem',
                    width:80,
                    title: '是否</br>存在</br>施工方案</br>问题',
                },
                {
                    field: 'problemDescriptionOfConstructionScheme',
                    width:100,
                    title: '施工方案</br>问题描述',
                },
                {
                    field: 'existingSecurityThreat',
                    width:100,
                    title: '现场</br>是否存在</br>安全隐患',
                },
                {
                    field: 'safetyHazardDescription',
                    width:100,
                    title: '安全隐患</br>描述',
                },
                {
                    field: 'customizedMaterials',
                    width:80,
                    title: '是否</br>需要</br>定制物资',
                },
                {
                    field: 'materialDescription',
                    width:100,
                    title: '定制物资</br>描述',
                },
                {
                    field: 'dismantlingTheOldMaterial',
                    width:80,
                    title: '是否有</br>拆旧物资',
                },
                {
                    field: 'operatingType',
                    width:100,
                    title: '作业方式',
                },
                {
                    field: 'problemDescription',
                    width:100,
                    title: '停电问题</br>描述',
                },
                {
                    field: 'civilWork',
                    width:70,
                    title: '是否有</br>土建</br>工作量',
                },
                {
                    field: 'verticalRodWorkload',
                    width:70,
                    title: '是否有</br>立杆</br>工作量',
                },
                {
                    field: 'totalWorkloadDescription',
                    width:100,
                    title: '总工作量</br>描述',
                },
                {
                    field: 'regionalCenter',
                    width:80,
                    title: '区域</br>中心',
                },
                {
                    field: 'powerSupplyArea',
                    width:80,
                    title: '供电所</br>辖区',
                },
                {
                    field: 'zhengLocation',
                    width:80,
                    title: '政处</br>地点',
                },
                {
                    field: 'zhengType',
                    width:80,
                    title: '政处</br>类型',
                },
                {
                    field: 'zhengObject',
                    width:80,
                    title: '政处</br>对象',
                },
                {
                    field: 'zhengDescribe',
                    width:100,
                    title: '政处描述',
                },
                {
                    field: 'projectApproval',
                    width:80,
                    title: '是否需</br>规划报批',
                },
                {
                    field: 'courseEvaluationProcedures',
                    width:80,
                    title: '是否需</br>办理</br>安评航评</br>手续',
                },
                {
                    field: 'zhengDifficultyWarn',
                    width:100,
                    title: '政处难点</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);
    });


    $("#jlImport").click(function () {
        jp.open({
            type: 2,
            area: [500, 200],
            auto: true,
            title: "导入数据",
            content: "${ctx}/tag/importExcel",
            btn: ['确定', '关闭'],
/*            btn1: function (index) {
                jp.downloadFile('${ctx}/sg/managementCenter/reserveManagement/schemeTemplate');
            },*/
            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/jlExport?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 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>