Laravel-admin grid 自定義按鈕並彈出模態框再次進行確認(基礎使用)

Wen1109發表於2019-08-14
  • 建立新的按鈕並彈出模態框再次進行確認;
  • 文章寫法有些麻煩,大佬有好的實現方法,不要忘記評論奧;
  • 附程式碼
/**
* 建立按鈕
*/
$grid->actions(function (Grid\Displayers\Actions  $actions) {
        $actions->append("<a class='btn btn-xs action-btn btn-danger grid-row-refuse' data-id='{$actions->getKey()}'><i class='fa fa-close' title='拒絕退款'>拒絕</i></a>&nbsp;&nbsp;");
        $actions->append("<a class='btn btn-xs action-btn btn-success grid-row-pass' data-id='{$actions->getKey()}'><i class='fa fa-check' title='同意退款'>同意</i></a>");
});

/**
* 建立模態框
*/
$this->script = <<<EOT
        $('.grid-row-pass').unbind('click').click(function() {
            var id = $(this).data('id');
            swal({
                title: "確認同意該使用者的退款申請嗎?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "確認",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    $.ajax({
                        method: 'get',
                        url: '/admin/refund/' + id, 
                        success: function (data) {
                            console.log(data);
                            $.pjax.reload('#pjax-container');
                            if(data.code){
                                swal(data.msg, '', 'success');
                            }else{
                                swal(data.msg, '', 'error');
                            }
                        }
                    });
                }
            });
        });

        $('.grid-row-refuse').unbind('click').click(function() {
            var id = $(this).data('id');
            swal({
                title: "確認拒絕該使用者的退款申請嗎?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "確認",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    $.ajax({
                        method: 'get',
                        url: '/admin/refuse/' + id,
                        success: function (data) {
                            console.log(data);
                            $.pjax.reload('#pjax-container');
                            if(data.code){
                                swal(data.msg, '', 'success');
                            }else{
                                swal(data.msg, '', 'error');
                            }
                        }
                    });
                }
            });
        });
EOT;
        Admin::script($this->script);

Laravel-admin grid 自定義按鈕(基礎使用)

Laravel-admin grid 自定義按鈕並彈出模態框再次進行確認(基礎使用)

Laravel-admin grid 自定義按鈕並彈出模態框再次進行確認(基礎使用)

相關文章