<?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();
    }


}
