美文网首页fastadmin
fastadmin 添加或编辑页面增加按钮操作,从table页面

fastadmin 添加或编辑页面增加按钮操作,从table页面

作者: 原来是红灯啊 | 来源:发表于2021-04-15 16:34 被阅读0次
    <div class="col-xs-12 col-sm-8">
                {eq name="isSave" value="1"}
                    <button type="wancheng" class="btn btn-default btn-embossed disabled" >此项目已完成</button>
                {else/}
                    <button type="submit" class="btn btn-success " id="reports" data-id="{$row.id}" >{:__('永久保存')}</button>
                    <button type="submit" class="btn btn-default btn-embossed disabled" >{:__('保存')}</button>
                {/eq}
    </div>
    

    模板文件给按钮增加一个id和data_id 属性,方便js获取数据

    edit: function () {
                $("#reports").on("click",function(e){
                    e.preventDefault();
                    var form=$("form[role=form]");
                    var ids = $(this).attr('data-id');
                    Fast.api.ajax({
                        url: '/pic/add/ids/'+ids,
                        data: form.serialize()
                    }, function (data) {
                        Fast.api.close();
                        parent.Toastr.success('操作成功');
                        parent.$(".btn-refresh").trigger("click");
                    });
                });
                Controller.api.bindevent();
     },
    

    对应的js里面方法是这样的

    以下是编辑或添加页面弹出form表单并接受数据

    模板文件同上面的一样,js需要修改下

     $(document).on('click', '#noPass', function (e) {
                    var ids = $(this).attr('data-id');
                    Fast.api.open("audit_review/noPass/ids/"+ids, "驳回信息", {
                        callback:function(value){
                            Fast.api.close();
                            parent.Toastr.success('操作成功');
                            parent.$(".btn-refresh").trigger("click");
                        }
                    });
                    return false;
        });
    

    callback里面就是返回的数据


    image.png

    对应的nopass方法需要如图所示处理下。nopass模板同下

    <form id="backhtml-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="audit_review/noPass">
    
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">驳回原因:</label>
            <div class="col-xs-12 col-sm-8">
                <textarea id="c-content" data-rule="required" class="form-control " rows="5" name="row[content]" cols="50"></textarea>
                <input  class="form-control"  name="row[pid]" type="hidden" value="{$ids}">
            </div>
        </div>
    
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 col-sm-8">
                <button type="submit" class="btn btn-success btn-embossed">提交</button>
            </div>
        </div>
    </form>
    

    table弹出列表页

    {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: 'examine/detail',
                                    }],formatter: function (value, row, index) {
                                        var that = $.extend({}, this);
                                        var table = $(that.table).clone(true);
                                        if (row.status != 0)
                                            $(table).data("operate-del", null);
                                        that.table = table;
                                        return Table.api.formatter.operate.call(that, value, row, index);
                                    }}
    
    

    js里面按钮

    edit: function () {
                $("#reports").on("click",function(e){
                    e.preventDefault();
                    var form=$("form[role=form]");
                    Fast.api.ajax({
                        url: '/examine/submit',
                        data: form.serialize()
                    }, function (data) {
                        Fast.api.close();
                        parent.Toastr.success('操作成功');
                        parent.$(".btn-refresh").trigger("click");
                    });
                });
                Controller.api.bindevent();
            },
            report: function () {
                Controller.api.bindevent();
            },
            detail: function (id) {
                Table.api.init({
                    extend: {
                        'dragsort_url': ''
                    }
                });
                var table = $("#table");
                // 初始化表格
                table.bootstrapTable({
                    url: 'examine/detail/id/'+table.attr('data-id') + location.search,
                    pk: 'id',
                    sortName: 'id',
                    showToggle: false,
                    search:false,
                    commonSearch: false,
                    showColumns: false,
                    showExport: false,
                    columns: [
                        [
                            {field: 'username', title: __('审核人')},
                            {field: 'status', title: __('是否通过')},
                            {field: 'content', title: __('备注')},
                            {field: 'type', title: __('审核类型')},
                            {field: 'times', title: __('审核时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        ]
                    ]
                });
    
                // 为表格绑定事件
                Table.api.bindevent(table);
            },
    

    默认js里面detail方法,列表

    <div class="panel panel-default panel-intro">
    
        {:build_heading()}
    
        <div class="panel-body">
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade active in" id="one">
                    <div class="widget-body no-padding">
    
                        <table id="table" data-id="{$ids}" class="table table-striped table-bordered table-hover table-nowrap" width="100%">
    
                        </table>
    
                    </div>
                </div>
    
            </div>
        </div>
    </div>
    

    detail模板代码

    相关文章

      网友评论

        本文标题:fastadmin 添加或编辑页面增加按钮操作,从table页面

        本文链接:https://www.haomeiwen.com/subject/igadlltx.html