michealwoo 2 rokov pred
rodič
commit
fc15cd4191

+ 34 - 0
app/Admin/Actions/Form/ToothLog.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Admin\Actions\Form;
+
+use Dcat\Admin\Form\AbstractTool;
+use Dcat\Admin\Widgets\Modal;
+
+class ToothLog extends AbstractTool
+{
+    /**
+     * @return string
+     */
+    protected $title = '长牙记录';
+
+    protected $model;
+
+    public function __construct(string $model = null, $id = 0)
+    {
+        $this->model = $model;
+        $this->title = $this->title;
+        $this->id = $id;
+    }
+
+    public function render()
+    {
+        $form = ToothLogForm::make()->payload(['id' => $this->id]);
+        return Modal::make()
+            ->lg()
+            ->title($this->title)
+            ->body($form)
+            ->button($this->title);
+    }
+
+}

+ 46 - 0
app/Admin/Actions/Form/ToothLogForm.php

xqd
@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Admin\Actions\Form;
+
+
+use Dcat\Admin\Contracts\LazyRenderable;
+use Dcat\Admin\Traits\LazyWidget;
+use Dcat\Admin\Widgets\Form;
+use Illuminate\Support\Facades\DB;
+use App\Models\DrawCode;
+
+class ToothLogForm extends Form implements LazyRenderable
+{
+    use LazyWidget;
+
+    //弹窗表单
+    public function form()
+    {
+        $id = isset($this->payload['id']) ? $this->payload['id'] : 0;
+        $this->hidden('id')->value($id);
+        $this->radio('status', '是否解除')->options([1=>'是', 0=>'否'])->default(1);
+        
+    }
+
+    //点击表单处理
+    public function handle(array $input)
+    {
+        $status = $input['status'];
+        DB::beginTransaction();
+        try {
+            if($status==1){
+              $code = DrawCode::query()->where('id',$input['id'])->first();
+              $code->usable_status = 1;//可用
+              $code->save();
+            }
+            DB::commit();
+        } catch (\Exception $exception) {
+            DB::rollBack();
+            return $this->response()->error($exception->getMessage());
+        }
+        
+        return $this->response()->success(admin_trans_field('操作成功'))->refresh();
+    }
+
+
+}

+ 159 - 0
app/Admin/Controllers/AdminController.php

xqd
@@ -0,0 +1,159 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use Dcat\Admin\Layout\Content;
+use Illuminate\Routing\Controller;
+
+class AdminController extends Controller
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title;
+
+    /**
+     * Set description for following 4 action pages.
+     *
+     * @var array
+     */
+    protected $description = [
+        //        'index'  => 'Index',
+        //        'show'   => 'Show',
+        //        'edit'   => 'Edit',
+        //        'create' => 'Create',
+    ];
+
+    /**
+     * Set translation path.
+     *
+     * @var string
+     */
+    protected $translation;
+
+    /**
+     * Get content title.
+     *
+     * @return string
+     */
+    protected function title()
+    {
+        return $this->title ?: admin_trans_label();
+    }
+
+    /**
+     * Get description for following 4 action pages.
+     *
+     * @return array
+     */
+    protected function description()
+    {
+        return $this->description;
+    }
+
+    /**
+     * Get translation path.
+     *
+     * @return string
+     */
+    protected function translation()
+    {
+        return $this->translation;
+    }
+
+    /**
+     * Index interface.
+     *
+     * @param  Content  $content
+     * @return Content
+     */
+    public function index($parent, Content $content)
+    {
+        return $content
+            ->translation($this->translation())
+            ->title($this->title())
+            ->description($this->description()['index'] ?? trans('admin.list'))
+            ->body($this->grid($parent));
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param  mixed  $id
+     * @param  Content  $content
+     * @return Content
+     */
+    public function show($parent, $id, Content $content)
+    {
+        return $content
+            ->translation($this->translation())
+            ->title($this->title())
+            ->description($this->description()['show'] ?? trans('admin.show'))
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param  mixed  $id
+     * @param  Content  $content
+     * @return Content
+     */
+    public function edit($parent, $id, Content $content)
+    {
+        return $content
+            ->translation($this->translation())
+            ->title($this->title())
+            ->description($this->description()['edit'] ?? trans('admin.edit'))
+            ->body($this->form($parent)->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param  Content  $content
+     * @return Content
+     */
+    public function create($parent, Content $content)
+    {
+        return $content
+            ->translation($this->translation())
+            ->title($this->title())
+            ->description($this->description()['create'] ?? trans('admin.create'))
+            ->body($this->form($parent));
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update($parent, $id)
+    {
+        return $this->form($parent)->update($id);
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @return mixed
+     */
+    public function store($parent)
+    {
+        return $this->form($parent)->store();
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy($parent, $id)
+    {
+        return $this->form($parent)->destroy($id);
+    }
+}

+ 3 - 1
app/Admin/Controllers/StudentController.php

xqd xqd
@@ -7,6 +7,7 @@ use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
 use Dcat\Admin\Http\Controllers\AdminController;
+use App\Admin\Actions\Form\ToothLog;
 
 class StudentController extends AdminController
 {
@@ -32,7 +33,8 @@ class StudentController extends AdminController
               $actions->append('疫苗接种记录');
               $actions->append('考勤登记');
               $actions->append('相册');
-              $actions->append('长牙记录');
+              //$actions->append(new ToothLog(Student::class,$actions->row->id));
+              $actions->append('<a href="' . admin_url('toothlog/' . $actions->row->id.'/index') . '">长牙记录</i></a>');
             });
             $grid->filter(function (Grid\Filter $filter) {
                 $filter->panel();

+ 92 - 0
app/Admin/Controllers/ToothLogController.php

xqd
@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Models\Student;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Show;
+use App\Admin\Controllers\AdminController;
+
+use Dcat\Admin\Layout\Content;
+use App\Models\ToothLog;
+
+class ToothLogController extends AdminController
+{
+    public function index($parent, Content $content)
+    {
+        $title = '长牙记录';
+        return $content
+            ->title($title)
+            ->description('列表')
+            // 添加面包屑导航
+            ->breadcrumb([
+                    'text' => '返回列表',
+                    'url' => admin_url('/student'),
+                    'icon' => 'fa fa-step-backward'
+                ],['text' => $title]
+            )
+            ->body($this->grid($parent));
+    }
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid($id)
+    {
+        return Grid::make(new ToothLog(), function (Grid $grid) use($id) {
+            //$grid->column('student_id');
+            $grid->column('student_id','学生信息')->display(function () {
+                $str  = "";
+                $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
+                $str .= '<img data-action="preview-img" src="' . $this->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
+                $str .= '<div>';
+                $str .= '<p style="margin-bottom: 5px">' . $this->username . '</p>';
+                $str .= '<p style="margin-bottom: 0px">' . $this->mobile . '</p>';
+                $str .= "</div>";
+                $str .= "</div>";
+                return $str;
+            });
+            $grid->column('log_time');
+            $grid->column('desc')->limit(50);
+            $grid->column('photos')->display(function ($photo_urls){
+                return json_decode($photo_urls, true);
+            })->image('', '60', '60');;
+            $grid->disableActions();
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->panel();
+                $filter->like('student_id')->width(4);
+            });
+        });
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     *
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        return Show::make($id, new ToothLog(), function (Show $show) {
+            $show->field('id');
+           
+        });
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form($id)
+    {
+        return Form::make(new ToothLog(), function (Form $form) use($id) {
+          $form->width(6)->datetime('time')->required()->placeholder('时间');
+          $form->width(6)->textarea('desc')->placeholder('长牙描述');
+          $form->width(6)->multipleImage('photos')->placeholder('上传照片')->saveAsJson();
+        });
+    }
+}

+ 2 - 0
app/Admin/routes.php

xqd
@@ -28,5 +28,7 @@ Route::group([
     $router->resource('/medication_entrustment', 'MedicationEntrustmentController');//用药委托
     $router->resource('/takeback_entrustment', 'TakebackEntrustmentController');//接回委托
     $router->resource('/leave_message', 'LeaveMessageController');//留言列表
+
+    $router->resource('/toothlog/{id}/index', 'ToothLogController');//长牙记录
     
 });

+ 16 - 0
app/Models/ToothLog.php

xqd
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Eloquent\Model;
+
+class ToothLog extends Model
+{
+	use HasDateTimeFormatter;
+    use SoftDeletes;
+
+    protected $table = 'tooth_log';
+    
+}

+ 18 - 0
resources/lang/zh-CN/tooth-log.php

xqd
@@ -0,0 +1,18 @@
+<?php 
+return [
+    'labels' => [
+        'ToothLog' => '长牙记录',
+        'tooth-log' => '长牙记录',
+        'tooth_log' => '长牙记录',
+        'index' => '记录',
+        'toothlog'=>'长牙记录'
+    ],
+    'fields' => [
+        'student_id'=>'学生姓名',
+        'log_time'=>'记录时间',
+        'desc'=>'长牙描述',
+        'photos'=>'照片'
+    ],
+    'options' => [
+    ],
+];

+ 22 - 0
resources/views/admin/toothlog/index.blade.php

xqd
@@ -0,0 +1,22 @@
+<div class="card">
+  <div class="card-header">
+    <h3 class="card-title">默认卡片示例</h3>
+    <div class="card-tools">
+      <!-- 按钮,标签和其他东西都可以放在这里! -->
+      <!-- 例如,这里是个标签 -->
+      <span class="badge badge-primary">新增长牙记录</span>
+    </div>
+    <!-- /.card-tools -->
+  </div>
+  <!-- /.card-header -->
+  <div class="card-body">
+    这里是卡片内容
+    asdasdsdda
+  </div>
+  <!-- /.card-body -->
+  <div class="card-footer">
+    这里是卡片底部
+  </div>
+  <!-- /.card-footer -->
+</div>
+<!-- /.card -->