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

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_detail/index' + location.search,
                    del_url: 'order_detail/del',
                    detail_url: 'order_detail/detail',
                    send_url: 'order_detail/send',
                    refund_url: 'order_detail/refund',
                    apply_invoice_url: 'order_detail/apply_invoice',
                    table: 'order_detail',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'store.name', title: __('Store.name')},
                        {field: 'num', title: __('Num')},
                        {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Pay_type 1'),"2":__('Pay_type 2'),"3":__('Pay_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'express', title: __('Express'), searchList: {"1":__('Express 1'),"2":__('Express 2'),"3":__('Express 3')}, formatter: Table.api.formatter.normal},
                        {field: 'total', title: __('Total'), operate:'BETWEEN'},
                        {field: 'goods_total', title: __('Goods_total'), operate:'BETWEEN'},
                        {field: 'postage_total', title: __('Postage_total'), operate:'BETWEEN'},
                        {field: 'name', title: __('Name')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'province_name', title: __('Province_name')},
                        {field: 'city_name', title: __('City_name')},
                        {field: 'county_name', title: __('County_name')},
                        {field: 'address', title: __('Address')},
                        {field: 'logistic_code', title: __('运单号')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7'),"8":__('Status 8'),"9":__('Status 9'),"10":__('Status 10'),"11":__('Status 11')}, formatter: Table.api.formatter.status},
                        {field: 'invoice_status', title: __('Invoice_status'), searchList: {"1":__('Invoice_status 1'),"2":__('Invoice_status 2'),"3":__('Invoice_status 3')},
                            formatter: function(value,row,index){
                                if(value=='0'){
                                    return "-";
                                }else{
                                    return Table.api.formatter.status(__('Invoice_status '+value), row, index);
                                }
                            }
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('详情'),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.detail_url,
                                    extend:"data-area='[\"50%\",\"80%\"]'",
                                },
                                {
                                    name: 'send',
                                    text: __('发货'),
                                    title: __('发货'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.send_url,
                                    confirm: '是否确认通过已发货?',
                                    hidden:function(row){
                                        if(row.status != 2){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'refund',
                                    text: __('已退款'),
                                    title: __('已退款'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.refund_url + '/status/9',
                                    confirm: '是否确认通过已退款?',
                                    hidden:function(row){
                                        if(row.status != 8){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'refund',
                                    text: __('未退款'),
                                    title: __('未退款'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.refund_url + '/status/11',
                                    confirm: '是否确认通过未退款?',
                                    hidden:function(row){
                                        if(row.status != 8){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'del',
                                    text: __(''),
                                    title: __('删除'),
                                    classname: 'btn btn-xs btn-danger btn-delone',
                                    icon: 'fa fa-trash',
                                    url: $.fn.bootstrapTable.defaults.extend.refund_url,
                                    hidden:function(row){
                                        if(row.status != 7 && row.status != 10){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'apply_invoice',
                                    text: __('申请发票'),
                                    title: __('申请发票'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: '',
                                    hidden:function(row){
                                        if(row.status != 1 && row.invoice_status == 0){
                                            return false;
                                        }
                                        return true;
                                    },
                                    url: $.fn.bootstrapTable.defaults.extend.apply_invoice_url,
                                    extend:"data-area='[\"50%\",\"80%\"]'",
                                },
                            ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        detail: function () {
            Controller.api.bindevent();
        },
        apply_invoice: function () {
            Controller.api.bindevent();
            Form.api.bindevent($("form[role=form]"));
            function init(){
                var type = $('#c-type').val();
                if(type == 1){
                    //企业单位
                    $('.duty_number_html').show();
                }else if(type == 2){
                    //个人/非企业单位
                    $('.duty_number_html').hide();
                }
            }
            init();
            $('#c-type').change(function(){
                init();
            })
        },
        send:function(){
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});