<%@ page contentType="text/html;charset=UTF-8" %>
    <script>
    $(document).ready(function() {
        $('#dataTable').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: 10,
            //可供选择的每页的行数（*）
            pageList: [10, 25, 50, 100],
            //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
            url: "${ctx}/supply/projectInformation/data",
            //默认值为 '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}/supply/projectInformation/delete?id="+row.id, function(data){
                            if(data.success){
                                $('#dataTable').bootstrapTable('refresh');
                                jp.success(data.msg);
                            }else{
                                jp.error(data.msg);
                            }
                        })

                    });

                }
            },

            onClickRow: function(row, $el){
            },
            onShowSearch: function () {
                $("#search-collapse").slideToggle();
            },
            columns: [{
		        checkbox: true

		    }
			,{
                field: 'projectDefinitionNumber',
                title: '项目定义号',
                    width:120,
                sortName: 'projectDefinitionNumber'
            },{
                    field: 'projectName',
                    title: '项目名称',
                    width:210,
                    sortName: 'projectName'
                }
                ,{
                    field: 'projectType',
                    title: '项目类型',
                    width:150,
                    sortName: 'projectType'
                }
                ,{
                    field: 'voltageLeve',
                    title: '电压等级',
                    width:150,
                    sortName: 'voltageLeve'
                }
                ,{
                    field: 'projectReleaseYear',
                    title: '项目下达年度',
                    width:150,
                    sortName: 'projectReleaseYear'
                }
                ,{
                    field: 'projectBudgetYear',
                    title: '项目预算年度',
                    width:150,
                    sortName: 'projectBudgetYear'
                }
                ,{
                    field: 'totalProjectInvestment',
                    title: '项目总投资',
                    width:150,
                    sortName: 'totalProjectInvestment'
                }
                ,{
                    field: 'approvalReplyNo',
                    title: '可研批复文号',
                    width:150,
                    sortName: 'approvalReplyNo'
                }
                ,{
                    field: 'singleProjectWbsNo',
                    title: '单体工程WBS编号',
                    width:150,
                    sortName: 'singleProjectWbsNo'
                }
                ,{
                    field: 'engineeringNo',
                    title: '工程编号',
                    width:150,
                    sortName: 'engineeringNo'
                }
                ,{
                    field: 'engineeringName',
                    title: '工程名称',
                    width:150,
                    sortName: 'engineeringName'
                }
                ,{
                    field: 'contacts',
                    title: '联系人',
                    width:150,
                    sortName: 'contacts'
                }
                ,{
                    field: 'contactNumber',
                    title: '联系电话',
                    width:150,
                    sortName: 'contactNumber'
                }
                ,{
                    field: 'actualCommencementDate',
                    title: '实际开工日期',
                    width:150,
                    sortName: 'actualCommencementDate'
                }
                ,{
                    field: 'actualCompletionDate',
                    title: '实际竣工日期',
                    width:150,
                    sortName: 'actualCompletionDate'
                }
                ,{
                    field: 'constructionUnit',
                    title: '施工单位',
                    width:150,
                    sortName: 'constructionUnit'
                }
                ,{
                    field: 'contractNo',
                    title: '合同编号',
                    width:150,
                    sortName: 'contractNo'
                }
                ,{
                    field: 'contractAmount',
                    title: '合同金额',
                    width:150,
                    sortName: 'contractAmount'
                }
                ,{
                    field: 'settlementDiscountRate',
                    title: '结算折扣率',
                    width:150,
                    sortName: 'settlementDiscountRate'
                }
                ,{
                    field: 'plannedCommencementDate',
                    title: '计划开工日期',
                    width:150,
                    sortName: 'plannedCommencementDate'
                }
                ,{
                    field: 'plannedCompletionDate',
                    title: '计划竣工日期',
                    width:150,
                    sortName: 'plannedCompletionDate'
                }
                ,{
                    field: 'civilEngineeringAmountSubmittedForApproval',
                    title: '土建送审金额',
                    width:150,
                    sortName: 'civilEngineeringAmountSubmittedForApproval'
                }
                ,{
                    field: 'installAmountSubmittedForApproval',
                    title: '安装送审金额',
                    width:150,
                    sortName: 'installAmountSubmittedForApproval'
                }
                ,{
                    field: 'subtotalOfConstructionCostSubmittedForApproval',
                    title: '送审施工费小计',
                    width:150,
                    sortName: 'subtotalOfConstructionCostSubmittedForApproval'
                }
                ,{
                    field: 'amountOfMaterialsProvidedByPartyAForApproval',
                    title: '甲供材送审金额',
                    width:150,
                    sortName: 'amountOfMaterialsProvidedByPartyAForApproval'
                }
                ,{
                    field: 'commentsOnSubmissionForApproval',
                    title: '送审备注',
                    width:150,
                    sortName: 'commentsOnSubmissionForApproval'
                }
                ,{
                    field: 'firmName',
                    title: '事务所名称',
                    width:150,
                    sortName: 'firmName'
                }
                ,{
                    field: 'auditManagementLevel',
                    title: '审计管理级别',
                    width:150,
                    sortName: 'auditManagementLevel'
                }
                ,{
                    field: 'auditMethod',
                    title: '审计方式',
                    width:150,
                    sortName: 'auditMethod'
                }
                ,{
                    field: 'fullTimeAuditor',
                    title: '审计专职',
                    width:150,
                    sortName: 'fullTimeAuditor'
                }
                ,{
                    field: 'submitter',
                    title: '送审人',
                    width:150,
                    sortName: 'submitter'
                }
                ,{
                    field: 'submissionDepartment',
                    title: '送审部门',
                    width:150,
                    sortName: 'submissionDepartment'
                }
                ,{
                    field: 'secondaryUnit',
                    title: '二级单位',
                    width:150,
                    sortName: 'secondaryUnit'
                }
                ,{
                    field: 'primaryUnit',
                    title: '一级单位',
                    width:150,
                    sortName: 'primaryUnit'
                }
                ,{
                    field: 'submissionStatus',
                    title: '送审状态',
                    width:150,
                    sortName: 'submissionStatus'
                }
                ,{
                    field: 'submissionFormId',
                    title: '送审单id',
                    width:150,
                    sortName: 'submissionFormId'
                }
                ,{
                    field: 'tableBuildingTime',
                    title: '建表时间',
                    width:150,
                    sortName: 'tableBuildingTime'
                }



            ]

        });

        if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端


            $('#dataTable').bootstrapTable("toggleView");
        }

        $('#dataTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
            'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', ! $('#dataTable').bootstrapTable('getSelections').length);
            $('#view,#edit').prop('disabled', $('#dataTable').bootstrapTable('getSelections').length!=1);
        });
        $("#btnImport").click(function(){
            jp.open({
                type: 2,
                area: [500, 200],
                auto: true,
                title:"导入数据",
                content: "${ctx}/tag/importExcel" ,
                btn: [/*'导出模板',*/'确定', '关闭'],
                /*btn1: function () {
                    jp.downloadFile('${ctx}/supply/materialLibrary/templates')  //模板放在哪？
                },*/
                btn1: function(index, layero){
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    iframeWin.contentWindow.importExcel('${ctx}/supply/projectInformation/import', function (data) {
                        if(data.success){
                            var body = data.body;
                            var repeat = body.repeat;
                            var filePath = body.filePath;
                            if(repeat == 3) {
                                jp.confirm('已存在物料数据，是否覆盖？', function () {
                                    jp.loading();
                                    jp.get("${ctx}/supply/projectInformation/importTwo?repeat=1&filePath="+filePath+"", function (data) {
                                        if (data.success) {
                                            $('#reportTable').bootstrapTable('refresh');
                                            jp.success(data.msg);
                                            location.reload();
                                        } else {
                                            jp.error(data.msg);
                                            location.reload();
                                        }

                                    })

                                },function () {
                                    jp.loading();
                                    jp.get("${ctx}/supply/projectInformation/importTwo?repeat=2&filePath="+filePath+"", function (data) {
                                        if (data.success) {
                                            $('#reportTable').bootstrapTable('refresh');
                                            jp.success(data.msg);
                                            location.reload();
                                        } else {
                                            jp.error(data.msg);
                                            location.reload();
                                        }

                                    })
                                })
                            }else {
                                jp.success(data.msg);
                                refresh();
                            }
                        }else{
                            jp.error(data.msg);
                        }
                        jp.close(index);
                    });//调用保存事件
                    return false;
                },
                btn2: function(index){
                    //  jp.close(index);
                }
            });
        });


        //暂时未做
        $("#export").click(function(){//导出Excel文件物料
            var reserveProjectName = $("#reserveProjectName").val();//储备项目暂定名称：
            var projectName = $("#projectName").val();//项目名称
            var reserveCode = $("#reserveCode").val();//储备编码
            var projectCode = $("#projectCode").val();//项目编码
            var projectAttribute = $("#projectAttribute").val();//项目属性
            var projectDefine = $("#projectDefine").val();//项目定义
            var bat = $("#bat").val();//项目批次
            jp.downloadFile('${ctx}/supply/projectInformation/export?reserveProjectName='+reserveProjectName+'&projectName='+projectName+'&reserveCode='+reserveCode+'&projectCode='+projectCode+'&projectAttribute='+projectAttribute+'&projectBatch='+bat+'&projectDefine='+projectDefine);
        });
        $("#exportpro").click(function(){//导出Excel文件
            jp.downloadFile('${ctx}/supply/projectInformation/exportpro');
        });


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

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

        var picker1 = $('#beginDate').datetimepicker({
            format: 'YYYY-MM-DD',
            locale: moment.locale('zh-cn'),
        });
        var picker2 = $('#endDate').datetimepicker({
            format: 'YYYY-MM-DD',
            locale: moment.locale('zh-cn')
        });

    });

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

function deleteAll(){
    jp.confirm('确认要删除该记录信息吗？', function(){
        jp.loading();
        jp.get("${ctx}/supply/projectInformation/deleteAll?ids=" + getIdSelections(), function(data){
            if(data.success){
                $('#dataTable').bootstrapTable('refresh');
                jp.success(data.msg);
            }else{
                jp.error(data.msg);
            }
        })

    })
}

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

function add(){
    jp.openSaveDialog('新增', "${ctx}/supply/projectInformation/form",'800px', '500px');
}



function edit(id){//没有权限时，不显示确定按钮
    if(id == undefined){
        id = getIdSelections();
    }
    jp.openSaveDialog('编辑', "${ctx}/supply/projectInformation/form?id=" + id, '800px', '500px');
}

function view(id){//没有权限时，不显示确定按钮
    if(id == undefined){
        id = getIdSelections();
    }
    jp.openViewDialog('查看', "${ctx}/supply/projectInformation/form?id=" + id, '800px', '500px');
}



</script>
