<?php

namespace App\Admin\Controllers;

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

class TakebackEntrustmentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TakebackEntrustment(), function (Grid $grid) {
            
            $grid->column('student_id')->using(config('map.students'));
            $grid->column('entrust_time');
            $grid->column('take_back_person')->using(config('map.parent_ids'));
            $grid->column('take_back_desc');
            $grid->column('take_back_photos');
            $grid->column('sign');
           
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->date('created_at')->datetime()->width(4);
                $filter->equal('student_id','输入/选择学生')->select(config('map.students'))->width(4);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TakebackEntrustment(), function (Show $show) {
            $show->row(function (Show\Row $show) {
              $show->field('content','接回委托详情')
                  ->width(8)
                  ->unescape()
                  ->as(function () {
                  $html = '';
                  $html .= '<div style="text-align:left">';
                  $html .= '<div style="margin-top:5px">接回对象：' . config('map.students')[$this->student_id] . '</div>';
                  $html .= '<div style="margin-top:5px">接回家长：' . config('map.parent_ids')[$this->take_back_person] . '</div>';
                  $html .= '<div style="margin-top:5px">接回时间：' . $this->entrust_time . '</div>';
                  $html .= '<div style="margin-top:5px">接回说明：' . $this->take_back_desc . '</div>';
                  $html .= '<div style="margin-top:5px">接回照片：</div>';
                  $html .= '<img data-action="preview-img" src="' . $this->photos . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
                  $html .= '<div style="margin-top:5px">签名：' . $this->sign . '</div>';
                  $html .= '</div>';
                  return $html;
              });
          });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TakebackEntrustment(), function (Form $form) {
         
            $form->text('student_id');
            $form->text('entrust_time');
            $form->text('take_back_person');
            $form->text('take_back_desc');
            $form->text('take_back_photos');
            $form->text('sign');

        });
    }
}
