double.js 4.5 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            var roterUrl = $('#lv2Url').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'Double/getDouble' ,
                    del_url: 'project/del'
                }
            });
            var routerMap = {
                // 项目首页
                main: '/teacher/double_detail/detail/index?ref=addtabs&container_id=',
                // 项目编辑页
                edit: '/teacher/setting/basicinfo/edit?ref=addtabs&container_id=',
                // 项目统计页
                statistical: '/teacher/double_detail/index?ref=addtabs&container_id=',
            }

            var table = $("#table");

            // Template.helper("Moment", Moment);

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                templateView: true,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID', operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ],
                ],
                // 数据加载成功,绑定按钮事件
                onLoadSuccess: function () {
                    // 跳转页面按钮
                    $('.tpl-wrap').on('click', '.btn-router', function () {
                        var url = routerMap[$(this).data('target')] + $(this).parents('.tpl-wrap').data('id')+'&type='+ $(this).data('id');

                        top.location.href = url;
                    })
                    // 删除项目
                    $('.tpl-wrap').on('click', '.btn-del', function () {
                        var that = this;
                        var containerId = $(this).parents('.tpl-wrap').data('id')
                        var top = $(that).offset().top - $(window).scrollTop();
                        var left = $(that).offset().left - $(window).scrollLeft() - 260;
                        if (top + 154 > $(window).height()) {
                            top = top - 154;
                        }
                        if ($(window).width() < 480) {
                            top = left = undefined;
                        }
                        Layer.confirm(
                            __('Are you sure you want to delete this item?'),
                            {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
                            function (index) {
                                var table = $(that).closest('table');
                                var options = table.bootstrapTable('getOptions');
                                Table.api.multi("del", containerId, table, that);
                                Layer.close(index);
                            }
                        );
                    })
                    // 切换项目类型,查看项目报名情况
                    $('.tpl-wrap').on('click', '.tab-item', function () {
                        var index = $(this).index()
                        $(this).addClass('active').siblings().removeClass('active')
                        $('.detail-wrap > div').eq(index).show().siblings().hide()
                    })

                    // 点击各项目容器的第一个项目类型tab(用于显示该类型的报名情况)
                    $('.tpl-wrap').each(function (i, tpl) {
                        $(tpl).find('.tab-item').eq(0).click()
                    })
                },
                // 是否显示快速搜索(搜索框)
                search: false,
                // 是否显示切换视图按钮
                showToggle: false,
                // 是否显示隐藏列按钮
                showColumns: false,
                // 是否显示导出按钮
                showExport: false,
                // 是否开启通用搜索功能(表格右上角的放大镜)
                commonSearch: true,
                // 是否隐藏通用搜索按钮
                showSearch: false,
                //分页大小
                pageSize: 3
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

    };

    return Controller;
});