baseCRUD() ->tableLayout('fixed') ->headerToolbar([ $this->createButton(), ...$this->baseHeaderToolBar(), ]) ->bulkActions([]) ->filter($this->baseFilter()->body([ amis()->GroupControl()->mode('horizontal')->body([ amisMake()->TextControl()->name('search')->label(__('admin.keyword'))->placeholder(__('workflow.key').'/'.__('workflow.name'))->columnRatio(3)->clearable(), ]), ])) ->columns([ amisMake()->TableColumn()->name('id')->label(__('workflow.id')), amisMake()->TableColumn()->name('key')->label(__('workflow.key')), amisMake()->TableColumn()->name('name')->label(__('workflow.name')), $this->rowActions([ $this->rowShowButton(), $this->rowEditButton(), $this->rowDeleteButton(), ]), ]); return $this->baseList($crud); } public function form($edit): Form { return $this->baseForm()->title('')->body([ amisMake()->TextControl()->name('key')->label(__('workflow.key'))->required(), amisMake()->TextControl()->name('name')->label(__('workflow.name'))->required(), amisMake()->ArrayControl()->name('config')->label(__('workflow.config'))->items(amisMake()->ComboControl()->items([ amisMake()->SelectControl()->options(CheckType::options())->name('type')->label(__('workflow.type')), amisMake()->SelectControl() ->options($this->getJobOptions()) ->labelField('name') ->valueField('key') ->name('job') // ->visibleOn('${config.type == '.CheckType::Job->value.'}') ->label(CheckType::Job->text()), amisMake()->SelectControl() ->options($this->getEmployeeOptions()) ->labelField('name') ->valueField('id') ->searchable() ->name('user') // ->visibleOn('${config.type == '.CheckType::User->value.'}') ->label(CheckType::User->text()), ])), ]); } public function detail(): Form { $detail = amisMake()->Property()->items([ ['label' => __('workflow.key'), 'content' => '${key}'], ['label' => __('workflow.name'), 'content' => '${name}'], ['label' => __('workflow.config'), 'content' => amisMake()->Steps()->labelPlacement('horizontal')->source('${config}'), 'span' => 3], ]); return $this->baseDetail()->title('')->body($detail); } public function apply(Request $request) { $model = WorkflowCheck::findOrFail($request->input('id')); $employee = $request->whenFilled('user', function ($id) { if ($employee = Employee::find($id)) { return $employee; } admin_abort('员工未找到'); }, function () { if ($employee = Employee::where('admin_user_id', Admin::user()->id)->first()) { return $employee; } admin_abort('当前登录账户未关联员工'); }); try { DB::beginTransaction(); if (! $this->service->apply($model, $employee)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function cancel(Request $request) { $model = WorkflowCheck::findOrFail($request->input('id')); try { DB::beginTransaction(); if (! $this->service->cancel($model)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function success(Request $request) { $user = Admin::user(); $employee = Employee::where('admin_user_id', $user->id)->first(); if (! $employee) { return $this->response()->fail('当前登录账户未关联员工'); } $log = WorkflowLog::findOrFail($request->input('id')); try { DB::beginTransaction(); if (! $this->service->check($employee, $log, true)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function fail(Request $request) { if (! $request->input('remarks')) { return $this->response()->fail('请填写未通过原因'); } $user = Admin::user(); $employee = Employee::where('admin_user_id', $user->id)->first(); if (! $employee) { return $this->response()->fail('当前登录账户未关联员工'); } $log = WorkflowLog::findOrFail($request->input('id')); try { DB::beginTransaction(); if (! $this->service->check($employee, $log, false, ['remarks' => $request->input('remarks')])) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function logs(Request $request) { $list = WorkflowLog::with(['checkUser'])->where('check_id', $request->input('id'))->sort()->get(); return $this->response()->success($list); } public function getJobOptions() { if (! $this->jobOptions) { $this->jobOptions = Keyword::where('parent_key', 'job')->get(); } return $this->jobOptions; } public function getEmployeeOptions() { if (! $this->employeeOptions) { $this->employeeOptions = Employee::enable()->get(); } return $this->employeeOptions; } }