goods.js 10.1 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: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'category_one_id', title: __('Category_one_id'),visible:false, operate:false},
                        {field: 'category_two_id', title: __('Category_two_id'),visible:false, operate:false},
                        {field: 'category_three_id', title: __('Category_three_id'),visible:false, operate:false},
                        {field: 'category_group_ids', title: __('Category_group_ids'),visible:false, operate:false},
                        {field: 'country_id', title: __('Country_id'),visible:false},
                        {field: 'brand_id', title: __('Brand_id'),visible:false, operate:false},
                        {field: 'level_id', title: __('Level_id'),visible:false, operate:false},
                        {field: 'part_id', title: __('Part_id'),visible:false, operate:false},
                        {field: 'category2_id', title: __('Category2_id'),visible:false, operate:false},
                        {field: 'depot_id', title: __('Depot_id'),visible:false, operate:false},
                        {field: 'ch_name', title: __('Ch_name')},
                        {field: 'en_name', title: __('En_name')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false},
                        {field: 'images', title: __('Images'),visible:false, events: Table.api.events.image, formatter: Table.api.formatter.images, operate:false},
                        {field: 'goods_no', title: __('Goods_no')},
                        {field: 'ch_specification', title: __('Ch_specification'),visible:false, operate:false},
                        {field: 'en_specification', title: __('En_specification'),visible:false, operate:false},
                        {field: 'ch_save_where', title: __('Ch_save_where'),visible:false, operate:false},
                        {field: 'en_save_where', title: __('En_save_where'),visible:false, operate:false},
                        {field: 'ch_period', title: __('Ch_period'),visible:false, operate:false},
                        {field: 'en_period', title: __('En_period'),visible:false, operate:false},
                        {field: 'stock_num', title: __('Stock_num'), operate:false},
                        {field: 'sales_initial', title: __('Sales_initial'), operate:false},
                        {field: 'sales_actual', title: __('Sales_actual'), operate:false},
                        {field: 'is_group', title: __('Is_group'), searchList: {"1":__('Is_group 1'),"2":__('Is_group 2')}, formatter: Table.api.formatter.normal,visible:false},
                        {field: 'group_num', title: __('Group_num'),visible:false, operate:false},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'vip_price', title: __('Vip_price'), operate:'BETWEEN',visible:false},
                        {field: 'is_vip_price', title: __('Is_vip_price'), searchList: {"1":__('Is_vip_price 1'),"2":__('Is_vip_price 2')}, formatter: Table.api.formatter.normal,visible:false},
                        // {field: 'is_recommend', title: __('Is_recommend'), searchList: {"1":__('Is_recommend 1'),"2":__('Is_recommend 2')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.toggle,yes:1,no:2},
                        {field: 'weigh', title: __('Weigh'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'country.ch_name', title: __('Country.ch_name'), formatter: Table.api.formatter.label},
                        // {field: 'category.name', title: __('Category.name'), formatter: Table.api.formatter.label},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'depot', title: '仓库信息', icon: 'fa fa-bars',
                                    classname: 'btn btn-xs btn-warning  btn-dialog',
                                    url: 'depot/index/goods_id/{id}/type/1',
                                    extend: "data-area='[\"65%\",\"80%\"]'"
                                },
                                {
                                    name: 'evaluate', title: '评价信息', icon: 'fa fa-bars',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    url: 'evaluate/index/goods_id/{id}/type/1',
                                    extend: "data-area='[\"65%\",\"80%\"]'",
                                }
                            ]
                        }
                    ]
                ]
            });

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

        },
        add: function () {
            Controller.api.bindevent();
            $('#c-is_group').change(function () {
                var val = $('#c-is_group').val();
                if(val == 1){
                    $('.group').show();
                }else {
                    $('.group').hide();
                }
            });
            $('#c-is_vip_price').change(function () {
                var val = $('#c-is_vip_price').val();
                if(val == 1){
                    $('.vip_price').show();
                }else {
                    $('.vip_price').hide();
                }
            });
            // $("#c-category_two_id").data("params", function (obj) {
            //     var id = $("#c-category_one_id").val()?$("#c-category_one_id").val():-1;
            //     return {wherein: {pid: id}};
            // });
            // $("#c-category_one_id").on('change',function(){
            //     $("#c-category_two_id").val('');
            //     $("#c-category_two_id_text").val('');
            //     $("#c-category_three_id").val('');
            //     $("#c-category_three_id_text").val('');
            //     $(".category_two .selected_tag").remove();
            //     $(".category_three .selected_tag").remove();
            // });
            // $("#c-category_three_id").data("params", function (obj) {
            //     var id = $("#c-category_two_id").val()?$("#c-category_two_id").val():-1;
            //     return {wherein: {pid: id}};
            // });
            // $("#c-category_two_id").on('change',function(){
            //     $("#c-category_three_id").val('');
            //     $("#c-category_three_id_text").val('');
            //     $(".category_three .selected_tag").remove();
            // });
        },
        edit: function () {
            Controller.api.bindevent();
            var val = $('#c-is_group').val();
            if(val == 1){
                $('.group').show();
            }
            var val1 = $('#c-is_vip_price').val();
            if(val1 == 1){
                $('.vip_price').show();
            }
            $('#c-is_group').change(function () {
                var val = $('#c-is_group').val();
                if(val == 1){
                    $('.group').show();
                }else {
                    $('.group').hide();
                }
            });

            $('#c-is_vip_price').change(function () {
                var val = $('#c-is_vip_price').val();
                if(val == 1){
                    $('.vip_price').show();
                }else {
                    $('.vip_price').hide();
                }
            });

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                // $("#c-category_one_id").on('change',function(){
                //     $("#c-category_two_id").val('');
                //     $("#c-category_two_id_text").val('');
                //     $("#c-category_three_id").val('');
                //     $("#c-category_three_id_text").val('');
                //     $(".category_two .selected_tag").remove();
                //     $(".category_three .selected_tag").remove();
                //     console.log(123);
                // });
                //
                // $("#c-category_two_id").on('change',function(){
                //     $("#c-category_three_id").val('');
                //     $("#c-category_three_id_text").val('');
                //     $(".category_three .selected_tag").remove();
                // });
                $("#c-category_two_id").data("params", function (obj) {
                    var id = $("#c-category_one_id").val()?$("#c-category_one_id").val():-1;
                    return {wherein: {pid: id}};
                });
                $("#c-category_three_id").data("params", function (obj) {
                    var id = $("#c-category_two_id").val()?$("#c-category_two_id").val():-1;
                    return {wherein: {pid: id}};
                });
            }
        }
    };
    return Controller;
});