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

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

            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.mobile', title: __('账号')},
                        {field: 'name', title: __('Name')},
                        {field: 'address', title: __('Address')},
                        {field: 'license', title: __('License'), events: Table.api.events.image, formatter: Table.api.formatter.images, searchable: false},
                        {field: 'legal_person', title: __('Legal_person')},
                        {field: 'invite_code', title: __('Invite_code')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'examine',
                                    text: '通过',
                                    title: '通过',
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.examine_url+'/status/1',
                                    confirm: '是否确认通过审核?',
                                    visible:function (row) {
                                        if(row.status == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'examine',
                                    text: '拒绝',
                                    title: '拒绝',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    icon: '',
                                    url: $.fn.bootstrapTable.defaults.extend.examine_url+'/status/2',
                                    confirm: '是否确认拒绝审核?',
                                    visible:function (row) {
                                        if(row.status == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'user',
                                    text: '员工名单',
                                    title: '员工名单',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: '',
                                    url: 'mobile/company_user?company_id={id}',
                                    visible:function (row) {
                                        if(row.status == '1'){
                                            return true;
                                        }
                                    },
                                },
                                {
                                    name: 'userlog',
                                    text: '员工记录',
                                    title: '员工记录',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: '',
                                    url: 'mobile/company_user_log?company_id={id}',
                                    visible:function (row) {
                                        if(row.status == '1'){
                                            return true;
                                        }
                                    },
                                },
                                {
                                    name: 'setuser',
                                    text: '设为普通用户',
                                    title: '设为普通用户',
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    icon: '',
                                    url: 'mobile/company/setgroup?group_id=0',
                                    confirm: '是否确认拒绝审核?',
                                    visible:function (row) {
                                        if(row.user.group_id == 1){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                // {
                                //     name: 'setuser',
                                //     text: '设为企业管理员',
                                //     title: '设为企业管理员',
                                //     classname: 'btn btn-xs btn-primary btn-ajax',
                                //     icon: '',
                                //     url: 'mobile/company/setgroup?group_id=1',
                                //     confirm: '是否确认拒绝审核?',
                                //     visible:function (row) {
                                //         if(row.user.group_id == 0){
                                //             return true;
                                //         }
                                //     },
                                //     success: function (data) {
                                //         table.bootstrapTable('refresh');
                                //     }
                                // }
                            ], formatter: Table.api.formatter.operate,
						}
                    ]
                ]
            });

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