<?php

namespace App\Admin\Controllers\WeChatProgram\UserManagement;

use App\Models\Notice;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class NoticeUserController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '公告->用户';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Notice());
        $grid->model()->where('type','1')->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('title', __('标题'));
        $grid->column('content', __('内容'))->limit(20,'');
        $grid->column('url', __('小程序链接'));
        $status = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $grid->column('status', __('状态'))->switch($status);
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        return $grid;
    }
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Notice());

        $form->text('title', __('标题'))->rules('required|min:3|max:255',['required'=>'请填写标题','min'=>'标题字符不能少于3个','max'=>'标题长度过长']);
        $form->editor('content', __('内容'))->rules('required' ,['required'=>'请填写内容！']);
        $form->text('url', __('小程序链接'))->rules('required',['required'=>'请填写链接']);
        $form->hidden('type', __('分类'))->default('1');
        $status = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $form->switch('status', __('状态'))->states($status);
        return $form;
    }
}
