<%@ page contentType="text/html;charset=UTF-8" %>
<script>
/**
 * 项目经理组织交底页面
 * */
$(document).ready(function () {
    window.operateEvents = {
        'click #editEngAmount': function (e, value, row, index) {
            jp.openSaveDialog('修改土建工程量', "${ctx}/managementcenter/activiti/editEngAmount?id="+row.id , '1000px', '800px');
        },
        'click #delEngAmount': function (e, value, row, index) {
            jp.confirm('确认要删除该工程量吗？', function(){
                jp.loading();
                jp.get("${ctx}/managementcenter/activiti/delEngAmount?id=" + row.id, function(data){
                    if(data.success){
                        $('#engineeringTable').bootstrapTable('refresh');
                        jp.success(data.msg);
                    }else{
                        jp.error(data.msg);
                    }
                })
            })
        },
        'click #editOtherAmount': function (e, value, row, index) {
            jp.openSaveDialog('修改其它工程量', "${ctx}/managementcenter/activiti/editOther?id="+row.id , '1000px', '800px');
        },
        'click #delOtherAmount': function (e, value, row, index) {
            jp.confirm('确认要删除该工程量吗？', function(){
                jp.loading();
                jp.get("${ctx}/managementcenter/activiti/delOtherAmount?id=" + row.id, function(data){
                    if(data.success){
                        $('#otherTable').bootstrapTable('refresh');
                        jp.success(data.msg);
                    }else{
                        jp.error(data.msg);
                    }
                })
            })
        }
    };
    $('#engineeringTable').bootstrapTable({
        //请求方法
        method: 'post',
        //类型json
        dataType: "json",
        contentType: "application/x-www-form-urlencoded",
        //显示检索按钮
        showSearch: false,
        //显示刷新按钮
        showRefresh: false,
        //显示切换手机试图按钮
        showToggle: false,
        //显示 内容列下拉框
        showColumns: false,
        //显示到处按钮
        showExport: false,
        //显示切换分页按钮
        showPaginationSwitch: false,
        //最低显示2行
        minimumCountColumns: 2,
        //是否显示行间隔色
        striped: true,
        //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        cache: false,
        //是否显示分页（*）
        pagination: true,
        //排序方式
        sortOrder: "asc",
        //初始化加载第一页，默认第一页
        pageNumber:1,
        //每页的记录行数（*）
        pageSize: 5,
        //可供选择的每页的行数（*）
        pageList: [10, 25, 50, 100],
        //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
        url: "${ctx}/managementcenter/activiti/engineeringTable?reserveProjectName=${construction.reserveProjectName}",
        //默认值为 '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){
        },
        onClickRow: function(row, $el){
        },
        onShowSearch: function () {
            $("#search-collapse").slideToggle();
        },
        columns: [{
            field: 'civilWorks',
            title: '形式',
        },{
            field: 'civilMaterials',
            title: '物料',
        },{
            field: 'civilUnit',
            title: '数量',
        },{
            field: 'operate',
            title: '操作',
            width: '160px',
            events: operateEvents,
            formatter: function operateFormatter(value, row, index) {
                return [
                    '<input id="editEngAmount" type="button" value="修改" class="btn btn-default">',
                    '<input id="delEngAmount" type="button" value="删除" class="btn btn-default">',
                ].join('');
            }
        }]
    });


    $('#otherTable').bootstrapTable({
        //请求方法
        method: 'post',
        //类型json
        dataType: "json",
        contentType: "application/x-www-form-urlencoded",
        //显示检索按钮
        showSearch: false,
        //显示刷新按钮
        showRefresh: false,
        //显示切换手机试图按钮
        showToggle: false,
        //显示 内容列下拉框
        showColumns: false,
        //显示到处按钮
        showExport: false,
        //显示切换分页按钮
        showPaginationSwitch: false,
        //最低显示2行
        minimumCountColumns: 2,
        //是否显示行间隔色
        striped: true,
        //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        cache: false,
        //是否显示分页（*）
        pagination: true,
        //排序方式
        sortOrder: "asc",
        //初始化加载第一页，默认第一页
        pageNumber:1,
        //每页的记录行数（*）
        pageSize: 5,
        //可供选择的每页的行数（*）
        pageList: [10, 25, 50, 100],
        //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
        url: "${ctx}/managementcenter/activiti/otherTable?reserveProjectName=${construction.reserveProjectName}",
        //默认值为 '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){
        },
        onClickRow: function(row, $el){
        },
        onShowSearch: function () {
            $("#search-collapse").slideToggle();
        },
        columns: [{
            field: 'otherWorks',
            title: '形式',
        },{
            field: 'otherMaterials',
            title: '物料',
        },{
            field: 'otherUnit',
            title: '数量',
        },{
            field: 'operate',
            title: '操作',
            width: '160px',
            events: operateEvents,
            formatter: function operateFormatter(value, row, index) {
                return [
                    '<input id="editOtherAmount" type="button" value="修改" class="btn btn-default">',
                    '<input id="delOtherAmount" type="button" value="删除" class="btn btn-default">',
                ].join('');
            }
        }]
    });
    jp.ajaxForm("#inputForm", function (data) {
        if (data.success) {
            jp.success(data.msg);
            jp.go("${ctx}/managementcenter/divide");
        } else {
            jp.error(data.msg);
            $("#inputForm").find("button:submit").button("reset");
        }
    });


    $('#startTime').datetimepicker({
        format: "YYYY-MM-DD HH:mm:ss"
    });
    $('#endTime').datetimepicker({
        format: "YYYY-MM-DD HH:mm:ss"
    });
    //富文本初始化
    $('#reason').summernote({
        height: 300,
        lang: 'zh-CN',
        readonly: true,
        callbacks: {
            onChange: function (contents, $editable) {
                $("input[name='reason']").val($('#reason').summernote('code'));//取富文本的值
            }
        }
    });

    /**
     * 导入交底结论
     * */
    $("#btnEng").click(function () {
        jp.open({
            type: 2,
            area: [500, 200],
            auto: true,
            title: "导入交底结论",
            content: "${ctx}/tag/importExcel",
            btn: ['下载模板', '确定', '关闭'],
            btn1: function () {
                jp.downloadFile("${ctx}/managementcenter/activiti/excelQuantity");
            },
            btn2: function (index, layero) {
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.contentWindow.importExcel('${ctx}/managementcenter/activiti/importQuantity', function (data) {
                    if (data.success) {
                        jp.confirm(data.msg, function () {
                            jp.close(index);
                            window.location.reload();
                        }, function () {
                            jp.close(index);
                            window.location.reload();
                        });
                    } else {
                        jp.alert(data.msg);
                    }
                });//调用保存事件
                return false;
            },
            btn3: function (index) {
                jp.close(index);
            }
        });
    });
    $("#edit").click(function () {
        var val = $("#id").val();
        jp.openSaveDialog('修改工程量', "${ctx}/managementcenter/activiti/editEng?id=" + val, '1000px', '800px');
    });

    $("#addEng").click(function () {
        var val = $("#id").val();
        jp.openSaveDialog('修改工程量', "${ctx}/managementcenter/activiti/editEngAmount?reserveProjectName=${construction.reserveProjectName}", '1000px', '800px');
    });

    $("#addOther").click(function () {
        var val = $("#id").val();
        jp.openSaveDialog('修改工程量', "${ctx}/managementcenter/activiti/editOther?reserveProjectName=${construction.reserveProjectName}", '1000px', '800px');
    });

    $("#agree").click(function () {
        jp.prompt(" 审批意见", function (message) {
            jp.post("${ctx}/act/task/engineering",
                {
                    "taskId": "${construction.act.taskId}",
                    "taskName": "${construction.act.taskName}",
                    "taskDefKey": "${construction.act.taskDefKey}",
                    "procInsId": "${construction.act.procInsId}",
                    "procDefId": "${construction.act.procDefId}",
                    "id":"${construction.id}",
                    "flag": "yes",
                    "comment": window.encodeURI(message)
                },
                function (data) {
                    if (data.success) {
                        jp.success(data.msg);
                        jp.go("${ctx}/act/task/todo");
                    } else {
                        jp.error(data.msg);
                    }
                }
            )
        });
    });

    $("#no").click(function () {
        jp.prompt(" 审批意见", function (message) {
            jp.post("${ctx}/act/task/engineering",
                {
                    "taskId": "${construction.act.taskId}",
                    "taskName": "${construction.act.taskName}",
                    "taskDefKey": "${construction.act.taskDefKey}",
                    "procInsId": "${construction.act.procInsId}",
                    "procDefId": "${construction.act.procDefId}",
                    "id":"${construction.id}",
                    "flag": "no",
                    "comment": window.encodeURI(message)
                },
                function (data) {
                    if (data.success) {
                        jp.success(data.msg);
                        jp.go("${ctx}/act/task/todo");
                    } else {
                        jp.error(data.msg);
                    }
                }
            )
        });
    });
})

//刷新列表
function refresh() {
    location.reload();
}
</script>
