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

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'merchant_goods/index' + location.search,
                    add_url: 'merchant_goods/add',
                    edit_url: 'merchant_goods/edit',
                    del_url: 'merchant_goods/del',
                    multi_url: 'merchant_goods/multi',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        {field: 'type', title: __('广告类型'), searchList: {"3":__('图文'),"2":__('音频'),"1":__('视频')}, formatter: Table.api.formatter.label},
                        {field: 'goods_name', title: __('Goods_name')},
                        // {field: 'video', title: __('Video')},
                        // {field: 'voice', title: __('Voice')},
                        // {field: 'view_time', title: __('View_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'start_time', title: __('Start_time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY-MM-DD",},
                        {field: 'end_time', title: __('End_time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY-MM-DD",},
                        // {field: 'sex', title: __('Sex'), searchList: {"2":__('Sex 2'),"1":__('Sex 1'),"0":__('Sex 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'min_age', title: __('Min_age')},
                        // {field: 'max_age', title: __('Max_age')},
                        // {field: 'province', title: __('Province')},
                        // {field: 'city', title: __('City')},
                        // {field: 'county', title: __('County')},
                        // {field: 'address', title: __('Address')},
                        // {field: 'longitude', title: __('Longitude')},
                        // {field: 'latitude', title: __('Latitude')},
                        // {field: 'distance', title: __('Distance'), operate:'BETWEEN'},
                        // {field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
                        {field: 'exp', title: __('Exp'), operate:false},
                        // {field: 'view', title: __('View')},
                        // {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'admin_is_up', title: __('Admin_is_up'), searchList: {"1":__('Admin_is_up 1'),"0":__('Admin_is_up 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'user_deletetime', title: __('User_deletetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin_deletetime', title: __('Admin_deletetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'user_is_up', title: __('上架状态'), searchList: {"1":__('已上架'),"0":__('已下架')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('审核状态'), searchList: {"3":__('审核失败'),"2":__('审核通过'),"1":__('审核中')}, formatter: Table.api.formatter.status},
                        /*{field: 'admin.id', title: __('Admin.id')},
                        {field: 'admin.username', title: __('Admin.username')},
                        {field: 'admin.nickname', title: __('Admin.nickname')},
                        {field: 'admin.password', title: __('Admin.password')},
                        {field: 'admin.salt', title: __('Admin.salt')},
                        {field: 'admin.avatar', title: __('Admin.avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'admin.email', title: __('Admin.email')},
                        {field: 'admin.loginfailure', title: __('Admin.loginfailure')},
                        {field: 'admin.logintime', title: __('Admin.logintime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'admin.createtime', title: __('Admin.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'admin.updatetime', title: __('Admin.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'admin.token', title: __('Admin.token')},
                        {field: 'admin.status', title: __('Admin.status'), formatter: Table.api.formatter.status},
                        {field: 'admin.user_id', title: __('Admin.user_id')},
                        {field: 'admin.money', title: __('Admin.money')},
                        {field: 'admin.merchant_title', title: __('Admin.merchant_title')},
                        {field: 'admin.merchant_name', title: __('Admin.merchant_name')},
                        {field: 'admin.merchant_mobile', title: __('Admin.merchant_mobile')},
                        {field: 'admin.area', title: __('Admin.area')},
                        {field: 'admin.brief', title: __('Admin.brief')},
                        {field: 'admin.business_images', title: __('Admin.business_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'admin.other_images', title: __('Admin.other_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            /*// 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'question/index' + location.search,
                    add_url: 'question/add',
                    edit_url: 'question/edit',
                    del_url: 'question/del',
                    multi_url: 'question/multi',
                    table: 'question',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                search:false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                commonSearch: false,
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate:false, visible:false},
                        {field: 'goods_id', title: __('Goods_id'), operate:false, visible:false},
                        {field: 'question_type', title: __('问题类型'), searchList: {"2":__('选择题'),"1":__('填空题')}, formatter: Table.api.formatter.label},
                        {field: 'question_name', title: __('问题')},
                        {field: 'question_answer', title: __('正确答案')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange',visible:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange',visible:false, formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh'), operate: false, visible: false},
                        {field: 'option', title: __('选项'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

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

            type_init();
            $('.type').click(function(){
                type_init();
            });
            function type_init(){
                var val=$('input:radio[name="row[type]"]:checked').val();
                if(val == 1){
                    //视频
                    $('.video').show();
                    $('.voice').hide();
                    $('.content2').hide();
                    $('.view_time').hide();
                }else if(val == 2){
                    //音频
                    $('.video').hide();
                    $('.voice').show();
                    $('.content2').hide();
                    $('.view_time').hide();
                }else if(val == 3){
                    //图文
                    $('.video').hide();
                    $('.voice').hide();
                    $('.content2').show();
                    $('.view_time').show();
                }
            }
            Controller.api.bindevent();
        },
        edit: function () {
            type_init();
            $('.type').click(function(){
                type_init();
            });
            function type_init(){
                var val=$('input:radio[name="row[type]"]:checked').val();
                if(val == 1){
                    //视频
                    $('.video').show();
                    $('.voice').hide();
                    $('.content2').hide();
                    $('.view_time').hide();
                }else if(val == 2){
                    //音频
                    $('.video').hide();
                    $('.voice').show();
                    $('.content2').hide();
                    $('.view_time').hide();
                }else if(val == 3){
                    //图文
                    $('.video').hide();
                    $('.voice').hide();
                    $('.content2').show();
                    $('.view_time').show();
                }
            }
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            add_type_init:function () {
                type_init();
                function type_init(){
                    var val=$('input:radio[name="row[type]"]:checked').val();
                    console.log(val);
                    if(val == 1){
                        //视频
                        $('.video').show();
                        $('.voice').hide();
                        $('.content').hide();
                        $('.view_time').hide();
                    }else if(val == 2){
                        //音频
                        $('.video').hide();
                        $('.voice').show();
                        $('.content').hide();
                        $('.view_time').hide();
                    }else if(val == 3){
                        //图文
                        $('.video').hide();
                        $('.voice').hide();
                        $('.content').show();
                        $('.view_time').hide();
                    }
                }
            }
        }
    };
    return Controller;
});