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

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_house/index' + '/ids/' + Config.ids + location.search,
                    table: 'user_house',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                commonSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
						{field: 'user.nickname', title: __('用户昵称'), operate:false},
						{field: 'user.id', title: __('用户ID'), operate:false},
                        {field: 'name', title: __('电话名称'), operate:false},
                        {field: 'phone', title: __('电话')},
						{field: 'status', title: __('绑定状态'), searchList: {'1':'申请中','2':'已绑定','3':'已拒绝'}, formatter: Table.api.formatter.normal},
						{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:
						    [
						        {
									name: '同意',
									text: function (row) {
										if(row.status == 2){
											return '已同意';
										}else{
											return '同意申请';
										}
									},
									title: function (row) {
										if(row.status == 2){
											return '已同意';
										}else{
											return '同意申请';
										}
									},
									classname: 'btn btn-xs btn-success btn-magic btn-ajax',
									icon: 'fa fa-magic',
									url: 'user_house/agree',
									confirm: '确认发送',
									success: function (data, ret) {
										Layer.alert(ret.msg);
										//如果需要阻止成功提示,则必须使用return false;
										//return false;
									},
									error: function (data, ret) {
										Layer.alert(ret.msg);
										return false;
									},
									disable: function (row) {
										//返回true时按钮显示,返回false隐藏
										if(row.status == 2){
											return true;
										}
									}
								},
						    ], 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;
});