<?php

namespace App\Admin\Controllers\Order;

use App\Models\UserRechargeRecord;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserRechargeRecordController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(UserRechargeRecord::with(['user','combo']), function (Grid $grid) {
            $grid->model()->where('status',1);
            $grid->column('id')->sortable();
            $grid->column('user_id')->display(function () {
                $str  = "";
                $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
                $str .= '<img data-action="preview-img" src="' . $this->user->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
                $str .= '<div>';
                $str .= '<p style="margin-bottom: 5px">' . $this->user->nickname . '</p>';
                $str .= '<p style="margin-bottom: 0px">' . $this->user->mobile . '</p>';
                $str .= "</div>";
                $str .= "</div>";
                return $str;
            });
            $grid->column('pay_id','订单号');
            $grid->column('combo.name','充值套餐');
            $grid->column('price')->label('danger');
            $grid->column('gold')->label('info');
            $grid->column('gift')->label('primary');
            //$grid->column('pay_id');
            $grid->column('created_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('user_id','用户ID')->width(3);
                $filter->like('user.nickname','用户昵称')->width(3);
                $filter->equal('user.mobile','手机号')->width(3);
                $filter->between('price')->width(3);
                $filter->between('created_at')->date()->width(4);
            });

            $grid->disableCreateButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserRechargeRecord(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('combo_id');
            $show->field('price');
            $show->field('gift');
            $show->field('pay_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserRechargeRecord(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('combo_id');
            $form->text('price');
            $form->text('gift');
            $form->text('pay_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
