baseCRUD() ->filterTogglable(false) ->columnsTogglable(false) ->headerToolbar([ $this->createButton(), $this->exportAction(), ]) ->filter($this->baseFilter()->actions()->body([ amisMake()->SelectControl()->options($this->getTypeOptions())->name('type_id')->label(__('patient.type_id'))->size('md')->clearable(), amisMake()->TextControl()->name('keyword')->label(__('patient.keyword'))->placeholder(__('patient.name') . '/' . __('patient.phone'))->size('md')->clearable(), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('doctor_id')->label(__('patient.doctor_id'))->size('md')->clearable(), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('inviter_id')->label(__('patient.inviter_id'))->size('md')->clearable(), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('saler_id')->label(__('patient.saler_id'))->size('md')->clearable(), // amisMake()->Button()->label(__('admin.reset'))->actionType('clear-and-submit'), amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'), ])) ->columns([ amisMake()->TableColumn()->name('id')->label(__('patient.id')), amisMake()->TableColumn()->name('type.name')->label(__('patient.type_id')), amisMake()->TableColumn()->name('name')->label(__('patient.name')), amisMake()->TableColumn()->name('sex_text')->label(__('patient.sex')), amisMake()->TableColumn()->name('phone')->label(__('patient.phone')), amisMake()->TableColumn()->name('age')->label(__('patient.age')), amisMake()->TableColumn()->name('treat_format')->label(__('patient.treat_at')), amisMake()->TableColumn()->name('doctor.name')->label(__('patient.doctor_id')), amisMake()->TableColumn()->name('inviter.name')->label(__('patient.inviter_id')), amisMake()->TableColumn()->name('saler.name')->label(__('patient.saler_id')), $this->rowActions(), ]) ->alwaysShowPagination(); return $this->baseList($crud); } public function form(): Form { return $this->baseForm()->body([ amisMake()->SelectControl()->options($this->getTypeOptions())->name('type_id')->label(__('patient.type_id'))->required(), amisMake()->SelectControl()->source(admin_url('/api/user/list'))->name('user_id')->label(__('patient.user_id'))->clearable()->onEvent([ 'change' => [ 'actions' => [ ['actionType' => 'setValue', 'componentId' => 'patient_name', 'args' => ['value' => '${event.data.selectedItems.name}']], ['actionType' => 'setValue', 'componentId' => 'patient_sex', 'args' => ['value' => '${event.data.selectedItems.sex}']], ['actionType' => 'setValue', 'componentId' => 'patient_phone', 'args' => ['value' => '${event.data.selectedItems.phone}']], ['actionType' => 'setValue', 'componentId' => 'patient_address', 'args' => ['value' => '${event.data.selectedItems.address}']], ['actionType' => 'setValue', 'componentId' => 'patient_birthday', 'args' => ['value' => '${event.data.selectedItems.birthday}']], ] ] ]), amisMake()->TextControl()->name('name')->label(__('patient.name'))->id('patient_name')->required(true), amisMake()->SelectControl()->options(Gender::options())->name('sex')->label(__('patient.sex'))->id('patient_sex'), amisMake()->TextControl()->name('phone')->label(__('patient.phone'))->id('patient_phone'), amisMake()->TextControl()->name('address')->label(__('patient.address'))->id('patient_address'), amisMake()->DateControl()->name('birthday')->label(__('patient.birthday'))->id('patient_birthday'), amisMake()->DateControl()->name('treat_at')->label(__('patient.treat_at')), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('doctor_id')->label(__('patient.doctor_id')), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('inviter_id')->label(__('patient.inviter_id')), amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('saler_id')->label(__('patient.saler_id')), amisMake()->ImageControl()->multiple()->receiver(admin_url('upload_image') . '?full-url=1')->name('images')->label(__('patient.images')), // Components::make()->fuEditorControl()->name('illness')->label(__('patient.illness')), amisMake()->TextareaControl()->name('illness')->label(__('patient.illness')), ]); } public function show($id) { if ($this->actionOfGetData()) { return $this->response()->success($this->service->getDetail($id)); } $record = new PatientRecordController(); $detail = amisMake() ->Card() ->className('base-form') ->header(['title' => __('admin.detail')]) ->body($this->detail($id)) ->toolbar([ amisMake()->Button()->label('修改基础信息') ->level('primary') ->className('mr-1') ->actionType('dialog') ->dialog(amisMake()->Dialog()->size('lg')->title('修改基础信息')->body( $this->form(true)->api($this->getUpdatePath())->initApi($this->getEditGetDataPath())->onEvent([ 'submitSucc' => [ 'actions' => [ ['actionType' => 'custom', 'script' => 'window.$owl.refreshAmisPage()',] ] ] ]) )), amisMake()->Button()->label('添加病历记录') ->level('warning') ->className('mr-1') ->actionType('dialog') ->dialog(amisMake()->Dialog()->size('lg')->title('添加病历记录')->body( $record->form(false, $id)->api('post:' . admin_url('/record'))->onEvent([ 'submitSucc' => [ 'actions' => [ ['actionType' => 'custom', 'script' => 'window.$owl.refreshAmisPage()',] ] ] ]) )), $this->backButton() ]); $page = $this->basePage()->body($detail); return $this->response()->success($page); } public function detail($id) { return $this->baseDetail()->body(amisMake()->Tabs()->tabs([ amisMake()->Tab()->title('基础信息')->body([ amisMake()->TextControl()->name('name')->label(__('patient.name'))->static(), amisMake()->SelectControl()->options(Gender::options())->name('sex')->label(__('patient.sex'))->static(), amisMake()->TextControl()->name('phone')->label(__('patient.phone'))->static(), amisMake()->TextControl()->name('address')->label(__('patient.address'))->static(), amisMake()->DateControl()->name('birthday')->label(__('patient.birthday'))->static(), amisMake()->DateControl()->name('treat_format')->label(__('patient.treat_at'))->static(), amisMake()->TextControl()->name('images')->label(__('patient.images'))->static()->staticSchema(amisMake()->Images()), amisMake()->TextControl()->name('doctor.name')->label(__('patient.doctor_id'))->static(), amisMake()->TextControl()->name('inviter.name')->label(__('patient.inviter_id'))->static(), amisMake()->TextControl()->name('saler.name')->label(__('patient.saler_id'))->static(), // Components::make()->fuEditorControl()->name('illness')->label(__('patient.illness'))->static(), amisMake()->TextareaControl()->name('illness')->label(__('patient.illness'))->static(), amisMake()->TextControl()->name('created_at')->label(__('patient.created_at'))->static(), ]), amisMake()->Tab()->title('病历记录')->body(amisMake()->Service() ->api(admin_url('/record?_action=getData&page=1&patient_id='.$id.'&perPage=20')) ->body(amisMake()->Table()->columns([ amisMake()->TableColumn()->name('id')->label(__('patient-record.id')), amisMake()->Mapping()->map($this->getTypeOptions()->pluck('label', 'value'))->name('type_id')->label(__('patient-record.type_id')), amisMake()->TableColumn()->name('treat_at')->label(__('patient-record.treat_at')), amisMake()->TableColumn()->name('next_treat_at')->label(__('patient-record.next_treat_at')), amisMake()->TableColumn()->name('doctor.name')->label(__('patient-record.doctor_id')), ])->affixRow([ amisMake()->Button()->level('link')->label('查看更多')->colSpan(5)->actionType('link')->link(admin_url('/record?patient_id=' . $id)), ]) ) ) ])); } public function getTypeOptions() { if (!$this->typeOptions) { $this->typeOptions = Keyword::where('type_key', 'treat_type')->select(['id as value', 'name as label'])->get(); } return $this->typeOptions; } public function getSelectOptions(Request $request) { $list = Patient::filter($request->all())->select(['id as value', 'name as label'])->sort()->get(); return $this->response()->success([ 'items' => $list->items() ]); } public function getAdminUserOptions() { if (!$this->adminUserOptions) { $this->adminUserOptions = AdminUserService::make()->query()->select(['id as value', 'name as label'])->get(); } return $this->adminUserOptions; } protected function exportAction($disableSelectedItem = false) { $event = fn($script) => ['click' => ['actions' => [['actionType' => 'custom', 'script' => $script]]]]; $downloadPath = '/' . admin_url('_download_export', true); $exportPath = $this->getExportPath(); $doAction = <<set('icon', 'fa-solid fa-download') ->align('right') ->onEvent($event( <<exportFileName(), date('YmdHis')); // 导出本页和导出选中项都是通过 _ids 查询 $ids = request()->input('_ids'); // listQuery() 为列表查询条件,与获取列表数据一致 $query = $this->service->listQuery() ->when($ids, fn($query) => $query->whereIn($this->service->primaryKey(), explode(',', $ids))); // 此处使用 laravel-excel 导出,可自行修改 AdminExport::make($query) ->setHeadings($this->exportHeadings()) ->setMap(fn($row) => $this->exportColumns($row)) ->store($path); return $this->response()->success(compact('path')); } protected function exportHeadings() { return [ __('patient.id'), __('patient.type_id'), __('patient.name'), __('patient.sex'), __('patient.phone'), __('patient.address'), __('patient.birthday'), __('patient.age'), __('patient.treat_at'), __('patient.doctor_id'), __('patient.inviter_id'), __('patient.saler_id'), __('patient.created_at'), ]; } protected function exportColumns($row) { return [ $row->id, $row->type?->name, $row->name, $row->sex->text(), $row->phone, $row->address, $row->birthday_format, $row->age, $row->treat_format, $row->doctor?->name, $row->inviter?->name, $row->saler?->name, $row->created_at, ]; } }