<?php

namespace App\Admin\Controllers;

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

class UsersInfoController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserInfoModel(), function (Grid $grid) {
            $grid->column('user_id')->sortable();
            $grid->column('weixin');
            $grid->column('avatar');
            $grid->column('nickname');
            $grid->column('birthday');
            $grid->column('height');
            $grid->column('weight');
            $grid->column('work');
            $grid->column('info');
            $grid->column('area');
            $grid->column('area_code');
            $grid->column('feeling');
            $grid->column('education');
            $grid->column('income');
            $grid->column('hobby');
            $grid->column('drink');
            $grid->column('smoke');
            $grid->column('photo');
            $grid->column('video');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('user_id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserInfoModel(), function (Show $show) {
            $show->field('user_id');
            $show->field('weixin');
            $show->field('avatar');
            $show->field('nickname');
            $show->field('birthday');
            $show->field('height');
            $show->field('weight');
            $show->field('work');
            $show->field('info');
            $show->field('area');
            $show->field('area_code');
            $show->field('feeling');
            $show->field('education');
            $show->field('income');
            $show->field('hobby');
            $show->field('drink');
            $show->field('smoke');
            $show->field('photo');
            $show->field('video');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserInfoModel(), function (Form $form) {
            $form->display('user_id');
            $form->text('weixin');
            $form->image('avatar')->disk('oss')->uniqueName()->removable(false)->autoUpload()->saveFullUrl();
            $form->text('nickname');
            $form->text('birthday');
            $form->text('height');
            $form->text('weight');
            $form->text('work');
            $form->text('info');
            $form->text('area')->default("成都市");;
//            $form->text('area_code');
            $form->text('feeling');
            $form->text('education');
            $form->text('income');
            $form->text('hobby')->help("多个字段用,隔开，例如：唱歌,跳舞");
            $form->text('drink');
            $form->text('smoke');
            $form->array('photo', function ($form) {
                $form->image('url', '图片上传')->disk("oss")->saveFullUrl()->uniqueName()->removable(false)->autoUpload();
                $form->radio('state', '阅后即焚')->options([0 => "否", 1 => "是"])->default(0);
            })->saveAsJson()->label("图片上传");
            $form->array('video',function ($form){
                $form->file("url","视频上传")->accept('avi,mov,rmvb,rm,flv,mp4,3gp','video/*')->disk('oss')->saveFullUrl()->uniqueName()->removable(false)->autoUpload();
            })->saveAsJson()->label("视频上传");


            $form->tools(function (Form\Tools $tools) {
                $tools->disableView();
                $tools->disableDelete();
                $tools->disableList();
            });

            $form->setCurrentUrl("/users");
        });
    }
}
