management.js 18.2 KB
define(['jquery', 'bootstrap', 'backend', 'form', 'table', '../project_common/project-api'], function ($, undefined, Backend, Form, Table, projectApi) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { // 为tab按钮绑定事件
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    Controller.table[panel.attr('id')].call(this, panel.index() + 1, panel.attr('id'));
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });
            // 批量通过
            $(document).on('click', '.btn-multiPass', function () {
                $("#mome_text").val('');
                // 下一个评审阶段编号
                var status = this.dataset.check_stage;
                if (('undefined' === typeof status) || ('' === status)) { throw new Error('审核进度参数不能为空') }
                layer.open({
                    type: 1,
                    title:['审核意见', 'background-color:#2C3E50;color:#fff;'],
                    skin: 'demo-class', //样式类名
                    closeBtn: 0, //不显示关闭按钮
                    anim: 2,
                    shadeClose: true, //开启遮罩关闭
                    area:["70%","70%"],
                    content: $("#memo"),
                    btn: ['确定通过', '取消'],
                    yes:function(val,row){
                        var memo = $("#mome_text").val();
                        var table = $( ('#table' + ($('.nav-tabs .active').index() + 1)) )
                        var ids = Table.api.selectedids(table);
                        if ('array' !== typeof ids) {
                            ids = (''+ids).split(',');
                        }
                        if (!ids.length) {
                            throw new Error('id不能为空');
                        }
                        var data = {list:JSON.stringify(ids.map(function (id) {
                                var editItem = {id: id, status: status,memo:memo,verify_stage:1};
                                // 学校审核完,进入下一个评审阶段(项目结题除外)
                                if (3 === Number(status) && (2 != Config.review_stage)) {
                                    editItem.review_stage = Number(Config.review_stage) + 1;
                                    // editItem.project_approval_status = 3;
                                }
                                return editItem;
                            }))};
                        $.ajax({
                            url: '/school/project_common/management/editProject',
                            method: 'POST',
                            data: data,
                            success: function (res) {
                                if (1 === res.code) {
                                    Toastr.success('操作成功')
                                    layer.close(val);
                                    table.bootstrapTable("refresh");
                                } else {
                                    Toastr.error(res.msg);
                                }
                            }
                        });
                    },
                });
                // confirm('确定通过选中的项目吗?', function () {
                //     var table = $( ('#table' + ($('.nav-tabs .active').index() + 1)) )
                //     var ids = Table.api.selectedids(table)
                //     Controller.api.passProject(ids, table, status)
                // })
            })
            // 批量淘汰
            $(document).on('click', '.btn-multiOut', function () {
                $("#mome_text").val('');
                layer.open({
                    type: 1,
                    title:['审核意见', 'background-color:#2C3E50;color:#fff;'],
                    skin: 'demo-class', //样式类名
                    closeBtn: 0, //不显示关闭按钮
                    anim: 2,
                    shadeClose: true, //开启遮罩关闭
                    area:["70%","70%"],
                    content: $("#memo"),
                    btn: ['确定淘汰', '取消'],
                    yes:function(val,row){
                        var memo = $("#mome_text").val();
                        var table = $( ('#table' + ($('.nav-tabs .active').index() + 1)) )
                        var ids = Table.api.selectedids(table);
                        if ('array' !== typeof ids) {
                            ids = (''+ids).split(',');
                        }
                        if (!ids.length) {
                            throw new Error('id不能为空');
                        }
                        var data = {list:JSON.stringify(ids.map(function (id) {return { id: id, project_status: 1,memo:memo,verify_stage:1}}))};
                        $.ajax({
                            url: '/school/project_common/management/editProject',
                            method: 'POST',
                            data: data,
                            success: function (res) {
                                if (1 === res.code) {
                                    Toastr.success('操作成功')
                                    layer.close(val);
                                    table.bootstrapTable("refresh");
                                } else {
                                    Toastr.error(res.msg);
                                }
                            }
                        });
                        // var res = Controller.api.outProject(ids, table,memo,val);
                    },
                });
                // confirm('确定淘汰选中的项目吗?', function () {
                //     var table = $( ('#table' + ($('.nav-tabs .active').index() + 1)) )
                //     var ids = Table.api.selectedids(table)
                //     Controller.api.outProject(ids, table)
                // })
            })

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            // 项目管理
            all: function (index, id) {
                // 表格1
                var option = {
                    index: index,
                    url: '/school/project_mid_check/management/' + id,
                    column: Controller.api.getReviewColumns(),
                    operateButtons: [

                    ]
                }
                var table = Controller.api.initTable(option)
            },
            // 学校未审核
            schoolNoAudit: function (index, id) {
                console.log(Config.login_type);
                // 表格2
                if(Config.login_type ===0 ){
                    var option = {
                        index: index,
                        url: '/school/project_mid_check/management/' + id,

                        operateButtons: [
                            // {
                            //     name: 'btn1',
                            //     text: '通过',
                            //     title: '通过',
                            //     classname: 'btn btn-xs btn-success btn-click',
                            //     click: function (val, row) {
                            //         confirm('确定通过这个项目吗?', function () {
                            //             Controller.api.passProject(row.id, table, 3)
                            //         });
                            //     }
                            // },
                            // {
                            //     name: 'btn2',
                            //     text: '淘汰',
                            //     title: '淘汰',
                            //     classname: 'btn btn-xs btn-danger btn-click',
                            //     click: function (val, row) {
                            //         confirm('确定淘汰这个项目吗?', function () {
                            //             Controller.api.outProject(row.id, table)
                            //         })
                            //     }
                            // }
                        ]
                    }
                }else{
                    var option = {
                        index: index,
                        url: '/school/project_mid_check/management/' + id,

                        operateButtons: []
                    }
                }

                var table = Controller.api.initTable(option)
            },
            // 学院未审核
            collegeNoAudit: function (index, id) {
                var option = {
                    index: index,
                    url: '/school/project_mid_check/management/' + id,
                    operateButtons: [
                        // {
                        //     name: 'btn1',
                        //     text: '通过',
                        //     title: '通过',
                        //     classname: 'btn btn-xs btn-success btn-click',
                        //     click: function (val, row) {
                        //         confirm('确定通过这个项目吗?', function () {
                        //             Controller.api.passProject(row.id, table, 2)
                        //         })
                        //     }
                        // },
                        // {
                        //     name: 'btn2',
                        //     text: '淘汰',
                        //     title: '淘汰',
                        //     classname: 'btn btn-xs btn-danger btn-click',
                        //     click: function (val, row) {
                        //         confirm('确定淘汰这个项目吗?', function () {
                        //             Controller.api.outProject(row.id, table)
                        //         })
                        //     }
                        // }
                    ]
                }
                var table = Controller.api.initTable(option)
            },
            // 学生填报不完整
            incomplete: function (index, id) {
                var option = {
                    index: index,
                    url: '/school/project_mid_check/management/' + id,
                }
                var table = Controller.api.initTable(option)
            },
            // 淘汰项目
            out: function (index, id) {
                var option = {
                    index: index,
                    url: '/school/project_mid_check/management/' + id,
                    operateButtons: [
                        {
                            name: 'btn1',
                            text: '撤销',
                            title: '撤销',
                            classname: 'btn btn-xs btn-success btn-click',
                            click: function (val, row) {
                                confirm('确定恢复这个项目吗?', function () {
                                    Controller.api.editProject({
                                        list: JSON.stringify([
                                            { id: row.id, project_status: 0,verify_stage:1,revoke:1}
                                        ])
                                    }, table)
                                })
                            }
                        }
                    ]
                }
                var table = Controller.api.initTable(option)
            }
        },
        api: $.extend(projectApi, {
            /**
             * 初始化table
             * @param {Number} option.index 显示表格对应的下标(table和toolbar的id命名都以下标结尾)
             * @param {Array} option.operateButtons 操作栏按钮
             */
            initTable: function (option) {
                var table = $('#table' + option.index);
                option.column = option.column || []
                table.bootstrapTable({
                    url: option.url,
                    toolbar: '#toolbar' + option.index, // toolbar属性用于绑定table自己的工具栏,避免一个页面出现多个工具栏
                    // 是否显示快速搜索(搜索框)
                    search: false,
                    // 是否显示切换视图按钮
                    showToggle: false,
                    searchFormVisible: true,
                    searchFormTemplate: 'search_tpl',
                    columns: [
                        [
                            {checkbox: true},
                            { field: 'id', title: '序号', operate: false },
                            // { field: 'id', title: '完整度', operate: false },
                            {
                                field: 'project_info', title: '项目名称及编号', operate: false, align: 'left', formatter: function (val, row) {
                                    return row.project_name + '<br/>' +  (row.project_no ? row.project_no  : '暂无');
                                }
                            },
                            { field: 'memberCount', title: '团队人数', operate: false },
                            { field: 'project_type_name', title: '项目分类', operate: false },
                            { field: 'college_name', title: '项目所属学院', operate: false },
                            {
                                field: 'user_info', title: '负责人姓名/学号', align: 'left', operate: false, formatter: function (val, row) {
                                    return row.nickname + '<br/>' + (row.student_no || '-')
                                }
                            },
                            {
                                field: 'user_from', title: '负责人学院/专业', align: 'left', operate: false, formatter: function (val, row) {
                                    return row.college_name + '<br>' + (row.major_name || '-')
                                }
                            },
                            // { field: 'teacher_info', title: '指导教师', operate: false },
                            { field: 'project_teachers', title: '指导教师', formatter: function (val) {
                                    var teachersName = '';
                                    for (var p in val) {
                                        teachersName += (val[p].username + '<br>')
                                    }
                                    return teachersName;
                                }
                            },
                            {
                                field: 'teacher_info', title: '提交情况', formatter: function (val, row) {
                                    return (!row.mid_attachment) ?
                                        '<span class="text-danger">未提交</span>' :
                                        '<span class="text-success">已提交</span>'
                                }, operate: false
                            },
                            {field: 'project_metaphase_status', title: '审核状态', operate: false, formatter: function(index,row){
                                    var project_metaphase_status = parseInt(row.project_metaphase_status);
                                    switch (project_metaphase_status) {
                                        case 3:
                                            return '已审核';
                                        default :
                                            return '审核中';
                                    }
                                }
                            },
                        ].concat(option.column).concat([
                            {
                                field: 'operate', title: __('Operate'), operate: false, table: table,
                                class: 'nowrap',
                                formatter: Table.api.formatter.buttons,
                                buttons: [
                                    {
                                        name: '_btn1',
                                        text: '查看中期项目',
                                        title: '查看中期项目',
                                        classname: 'btn btn-xs btn-info btn-addtabs',
                                        url: function (val) {
                                            return '/school/project_common/project_view/index?review_stage=1&ids=' + val.id
                                        }
                                    },
                                    {
                                        name: '_btn2',
                                        text: '查看审核信息',
                                        title: '查看审核信息',
                                        classname: 'btn btn-xs btn-info btn-addtabs',
                                        url: function (val) {
                                            return '/school/project_common/judge/verify_list?review_stage=1&register_id=' + val.id
                                        }
                                    }
                                ].concat(option.operateButtons || [])
                            }
                        ])
                    ]
                });

                // 为表格1绑定事件
                Table.api.bindevent(table);
                return table
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        })
    }

    /**
     * 询问弹窗
     * @param {string} msg 询问文字
     * @param {function} callback 确认回调
     */
    function confirm(msg, callback) {
        layer.confirm(msg, {
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            callback && callback()
            layer.close(index)
        });
    }


    return Controller
})