class MaintainFromCreateFrom extends Form
{
use LazyWidget;
public function handle(array $input)
{
// dump($input);
//处理表单提交逻辑.
// return $this->response()->error('Your error message.');
$bg_asset_number = $input['bg_asset_number'] ?? null;
// 获取故障说明,来自表单传参
$bg_description = $input['bg_description'] ?? null;
// 获取故障时间,来自表单传参
$bg_time = $input['bg_time'] ?? null;
// 如果没有资产编号、故障说明、故障时间则返回错误
if (/\*!$bg_asset_number || \*/!$bg_description || !$bg_time) {
return $this->response()
->error(trans('main.parameter_missing'));
}
// 创建新的配件追踪
$maintenance_record = new MaintenanceRecord();
$maintenance_record->asset_number = $bg_asset_number;
$maintenance_record->ng_description = $bg_description;
$maintenance_record->ng_time = $bg_time;
$maintenance_record->status = 0;
$maintenance_record->save();
return $this->response()
->success(trans('main.success'))
->refresh();
}
public function form()
{
return Form::make( function (Form $form) {
$form = $this->selectTable('bg_asset_number','资产编号')
->title('弹窗标题')
->dialogWidth('50%') // 弹窗宽度,默认 800px
->from(DeviceTable::make(['bg_asset_number' => $form->getKey()])) // 设置渲染类实例,并传递自定义参数
->model(DeviceRecord::class, 'bg_asset_number', 'asset_number')
#>payload($from = 'bg_asset_number' )
;
$from = $this->text('bg_description', trans('main.bg_description'))->required();
$from = $this->datetime('bg_time', trans('main.bg_time'))->required();
}
);
}