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

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/index' + location.search,
                    // add_url: 'goods/add',
                    edit_url: 'goods/edit',
                    del_url: 'goods/del',
                    multi_url: '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'), visible:false},
                        {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: '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_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.label},
                        {field: 'admin_is_up', title: __('管理端上架状态'), searchList: {"1":__('已上架'),"0":__('已下架')}, formatter: Table.api.formatter.label},
                        // {field: 'user_deletetime', title: __('商户端删除时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {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,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('通过'),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: false,
                                    url: 'goods/status/ids/{id}/status/2',
                                    hidden: function(row){
                                        if(row.status != 1){
                                            return true;
                                        }
                                    },
                                    success: function (data, ret) {
                                        // Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
                                        $(".btn-refresh").trigger('click');
                                        //如果需要阻止成功提示,则必须使用return false;
                                        //return false;

                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    refresh: true
                                },
                                {
                                    name: 'ajax',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    icon: false,
                                    url: 'goods/status/ids/{id}/status/3',
                                    hidden: function(row){
                                        if(row.status != 1){
                                            return true;
                                        }
                                    },
                                    success: function (data, ret) {
                                        // Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
                                        $(".btn-refresh").trigger('click');
                                        //如果需要阻止成功提示,则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    refresh: true
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: 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();
        },
        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]"));
            }
        }
    };
    return Controller;
});