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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'status', title: __('Status'),searchList: {0: __('待付款'), 1: __('已取消'),2: __('待发货'), 3: __('退款申请中'),4: __('已退款'), 5: __('待收货'),6: __('退换货申请中'), 7: __('已退换货'),8: __('已完成'), 9: __('退换货驳回'),10: __('退款驳回')},formatter:Table.api.formatter.label},
                        {field: 'receive_name', title: __('Receive_name')},
                        {field: 'receive_mobile', title: __('Receive_mobile')},
                        {field: 'receive_address', title: __('Receive_address')},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},//支付总金额
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.avatar', title: __('User.avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                            {
                                name: 'detail',
                                text: __('录入单号'),
                                title: __('录入单号'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                url: 'order/code',
                                callback: function (data) {
                                    //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    if(row.status == 2){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            },
                            {
                                name: 'detail',
                                text: __('同意'),
                                title: __('申请退款'),
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'order/adoptPass',
                                confirm: '确认通过?',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                },
                                error: function (data, ret) {
                                    return false;
                                },
                                visible: function (row) {
                                    if(row.status == 3){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            },
                            {
                                name: 'detail',
                                text: __('驳回'),
                                title: __('申请退款'),
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'order/adoptRefund',
                                confirm: '确认驳回?',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                },
                                error: function (data, ret) {
                                    return false;
                                },
                                visible: function (row) {
                                    if(row.status == 3){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            },
                            {
                                name: 'detail',
                                text: __('同意'),
                                title: __('申请退换货'),
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'order/adoptReturn',
                                confirm: '确认通过?',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                },
                                error: function (data, ret) {
                                    return false;
                                },
                                visible: function (row) {
                                    if(row.status == 6){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            },
                            {
                                name: 'detail',
                                text: __('驳回'),
                                title: __('申请退换货'),
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'order/adoptReturnReject',
                                confirm: '确认驳回?',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                },
                                error: function (data, ret) {
                                    return false;
                                },
                                visible: function (row) {
                                    if(row.status == 6){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            }
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

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