<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new User(), function (Grid $grid) {
            $grid->column('id')->sortable()->width('80px');
            $grid->column('nickname');
            $grid->column('head_img')->image('',80,80);
            $grid->column('phone_num');
            $grid->column('is_vip')->using([0 => '否', 1 => '是']);
            $grid->column('created_at','注册时间');

            $grid->showQuickEditButton();
            // 禁用删除按钮
            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            // 禁用
            $grid->disableBatchActions();
            // 禁用
            $grid->disableRowSelector();
            /*$grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });*/
            $grid->export();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new User(), function (Show $show) {
            $show->field('id');
            $show->field('nickname');
            $show->field('openid');
            $show->field('heade_img');
            $show->field('parenid');
            $show->field('phone_num');
            $show->field('income');
            $show->field('is_vip');
            $show->field('share_qrcode');
            $show->field('scene_code');
            $show->field('become_vip_at');
            $show->field('become_child_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new User(), function (Form $form) {
            $form->display('id');
            $form->display('nickname');
            $form->display('openid');
            $form->display('heade_img');
            $form->display('parent_id');
            $form->display('phone_num');
            $form->display('income');
            $form->switch('is_vip', '是否会员？')->default(1);
            $form->display('share_qrcode');
            $form->display('scene_code');
            $form->display('become_vip_at');
            $form->display('become_child_at');

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