baseCRUD() ->tableLayout('fixed') ->headerToolbar([ $this->createButton()->visible(Admin::user()->can('admin.store.stores.create')), ...$this->baseHeaderToolBar(), ]) ->bulkActions([]) ->filter($this->baseFilter()->body([ amis()->GroupControl()->mode('horizontal')->body([ amisMake()->TextControl()->name('title')->label(__('store.title'))->columnRatio(3)->clearable(), amisMake()->TreeSelectControl()->name('category_id')->label(__('store.category_id'))->columnRatio(3) ->source(admin_url('api/keywords/tree-list?parent_key=store_category')) ->labelField('name') ->valueField('key') ->onlyLeaf(true) ->clearable(), amisMake()->SelectControl()->name('business_id')->label(__('store.business_id'))->columnRatio(3) ->source(admin_url('api/keywords/tree-list?parent_key=store_business')) ->labelField('name') ->valueField('key') ->clearable(), ]), amisMake()->GroupControl()->mode('horizontal')->body([ amisMake()->SelectControl()->name('level_id')->label(__('store.level_id'))->columnRatio(3) ->source(admin_url('api/keywords/tree-list?parent_key=store_level')) ->labelField('name') ->valueField('key') ->clearable(), // amisMake()->InputCityControl()->name('region')->label(__('store.region'))->columnRatio(3) // ->allowDistrict(false) // ->extractValue(false) // ->clearable(), amisMake()->SelectControl()->name('business_status')->label(__('store.business_status'))->options(BusinessStatus::options())->columnRatio(3)->clearable(), ]), ])) ->columns([ amisMake()->TableColumn()->name('id')->label(__('store.id')), amisMake()->TableColumn()->name('title')->label(__('store.title')), amisMake()->TableColumn()->name('category.name')->label(__('store.category_id')), amisMake()->TableColumn()->name('business.name')->label(__('store.business_id')), amisMake()->TableColumn()->name('level.name')->label(__('store.level_id')), amisMake()->TableColumn()->name('region')->label(__('store.region'))->set('type', 'tpl')->set('tpl', '${region.province}-${region.city}'), amisMake()->TableColumn()->name('business_status')->label(__('store.business_status'))->type('switch')->trueValue(BusinessStatus::Open)->falseValue(BusinessStatus::Close), amisMake()->TableColumn()->name('created_at')->label(__('store.created_at')), $this->rowActions([ $this->rowShowButton()->visible(Admin::user()->can('admin.store.stores.view')), $this->rowEditButton()->visible(Admin::user()->can('admin.store.stores.update')), $this->rowDeleteButton()->visible(Admin::user()->can('admin.store.stores.delete')), ]), ]); return $this->baseList($crud); } public function form($edit): Form { return $this->baseForm()->title('')->body([ amisMake()->TextControl()->name('title')->label(__('store.title'))->required(), amisMake()->SelectControl()->name('master_id')->label(__('store.master_id')) ->source(admin_url('hr/employees?_action=getData')) ->labelField('name') ->valueField('id') ->required(), amisMake()->TreeSelectControl()->name('category_id')->label(__('store.category_id')) ->source(admin_url('api/keywords/tree-list?parent_key=store_category')) ->labelField('name') ->valueField('key') ->onlyLeaf(true) ->required(), amisMake()->SelectControl()->name('business_id')->label(__('store.business_id')) ->source(admin_url('api/keywords/tree-list?parent_key=store_business')) ->labelField('name') ->valueField('key') ->required(), amisMake()->SelectControl()->name('level_id')->label(__('store.level_id')) ->source(admin_url('api/keywords/tree-list?parent_key=store_level')) ->labelField('name') ->valueField('key') ->required(), amisMake()->InputCityControl()->name('region')->label(__('store.region'))->allowDistrict(false)->extractValue(false)->required(), amisMake()->LocationControl()->name('location')->label(__('store.location'))->ak('Qa9sxstHlyBIDfb3SjrR3Uli39yRjB6X')->autoSelectCurrentLoc(), ]); } public function detail(): Form { $detail = amisMake()->Property()->items([ ['label' => __('store.title'), 'content' => '${title}'], ['label' => __('store.master_id'), 'content' => '${master.name}'], ['label' => __('store.business_status'), 'content' => amisMake()->Tag()->label('${business_status_text}')->color('${business_status_color}')], ['label' => __('store.category_id'), 'content' => '${category.name}'], ['label' => __('store.business_id'), 'content' => '${business.name}'], ['label' => __('store.level_id'), 'content' => '${level.name}'], ['label' => __('store.region'), 'content' => '${region.province}-${region.city}'], ['label' => __('store.address'), 'content' => '${region.address}', 'span' => 2], ['label' => __('store.profit_ratio'), 'content' => '${profit_ratio}%', 'span' => 3], ]); // 员工列表 $sales = amisMake()->Service()->id('store-employees-table')->api(admin_url('store/stores/${id}/employees'))->initFetch(false)->body(amisMake()->Table()->columns([ amisMake()->TableColumn()->name('name')->label(__('employee.name')), amisMake()->TableColumn()->name('phone')->label(__('employee.phone')), ])->itemActions([ amisMake()->AjaxAction() ->label(__('admin.delete')) ->level('link') ->confirmText(__('admin.confirm_delete')) ->api('delete:'.admin_url('store/stores/${id}/employees').'?employees=${id}') ->reload('store-employees-table') ])); return $this->baseDetail()->title('')->body([$detail, amisMake()->Divider()->title(__('store.employees')), $sales]); } public function show($id) { if ($this->actionOfGetData()) { return $this->response()->success($this->service->getDetail($id)); } $form = amisMake()->Form() ->labelWidth(0) ->api('post:' . admin_url('store/stores/'.$id.'/employees')) ->redirect('') ->onEvent([ 'submitSucc' => [ 'actions' => [ ['actionType' => 'reload','componentId' => 'store-employees-table'] ] ] ]) ->body([ amisMake()->TransferControl()->name('employees') ->source(admin_url('store/stores/employee_options') . '?store_id='.$id) ->selectMode('table') ->resultListModeFollowSelect() ->joinValues(false) ->extractValue(true) ->columns([ amisMake()->Column()->name('label')->label(__('employee.name')), amisMake()->Column()->name('phone')->label(__('employee.phone')), ]), ]); $dialog = amisMake()->Dialog()->size('lg')->title('添加'.__('store.employees'))->body($form); $detail = amis() ->Card() ->className('base-form') ->header(['title' => __('admin.detail')]) ->body($this->detail()) ->toolbar([ amisMake()->DialogAction()->label('添加'. __('store.employees'))->level('primary')->className('mr-1')->dialog($dialog), $this->backButton(), ]); $page = $this->basePage()->body($detail); return $this->response()->success($page); } public function employees($id) { $store = Store::findOrFail($id); $list = $store->employees()->wherePivot('role', StoreRole::Employee)->get(); return $this->response()->success($list); } public function employeeAdd($id, Request $request) { $employees = $request->input('employees'); $store = Store::findOrFail($id); $service = $this->service; if ($service->attachEmployee($store, $employees)) { return $this->response()->success(); } return $this->response()->fail($service->getError()); } public function employeeDestroy($id, Request $request) { $employees = $request->input('employees'); $store = Store::findOrFail($id); $service = $this->service; if ($service->destroyEmployee($store, is_array($employees) ? $employees : explode(',', $employees))) { return $this->response()->success(); } return $this->response()->fail($service->getError()); } public function employeeOptions() { $ignore = DB::table('store_employees')->pluck('employee_id'); $list = Employee::select(['name as label', 'id as value', 'phone'])->whereNotIn('id', $ignore)->get(); return $this->response()->success($list); } }