store-manage/app/Admin/Controllers/Hr/EmployeeController.php

104 lines
5.6 KiB
PHP

<?php
namespace App\Admin\Controllers\Hr;
use App\Admin\Services\EmployeeService;
use App\Enums\EmployeeStatus;
use App\Models\Employee;
use Illuminate\Http\Request;
use App\Admin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\Page;
class EmployeeController extends AdminController
{
protected string $serviceName = EmployeeService::class;
public function list(): Page
{
$crud = $this->baseCRUD()
->tableLayout('fixed')
->headerToolbar([
$this->createButton(true)->visible(Admin::user()->can('admin.hr.employees.create')),
...$this->baseHeaderToolBar(),
])
->bulkActions([])
->filter($this->baseFilter()->body([
amis()->GroupControl()->mode('horizontal')->body([
amisMake()->TextControl()->name('name')->label(__('employee.name'))->columnRatio(3)->clearable(),
amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->columnRatio(3)->clearable(),
amisMake()->SelectControl()->name('employee_status')->label(__('employee.employee_status'))->columnRatio(3)->clearable()->options(EmployeeStatus::options()),
]),
]))
->columns([
amisMake()->TableColumn()->name('id')->label(__('employee.id')),
amisMake()->TableColumn()->name('name')->label(__('employee.name')),
amisMake()->TableColumn()->name('phone')->label(__('employee.phone')),
amisMake()->TableColumn()->name('employee_status')->label(__('employee.employee_status'))
->type('switch')
->trueValue(EmployeeStatus::Online)
->falseValue(EmployeeStatus::Offline),
amisMake()->TableColumn()->name('created_at')->label(__('employee.created_at')),
$this->rowActions([
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.employees.view')),
$this->rowEditButton(true)->visible(Admin::user()->can('admin.hr.employees.update')),
$this->rowDeleteButton()->visible(Admin::user()->can('admin.hr.employees.delete')),
// amisMake()->AjaxAction()
// ->label(__('employee.leave'))
// ->level('link')
// ->icon('fa fa-sign-out')
// ->confirmText(__('employee.leave_confirm'))
// ->api('post:'.admin_url('hr/employees/${id}/leave'))
// ->visible(Admin::user()->can('admin.hr.employees.leave')),
]),
]);
return $this->baseList($crud);
}
public function form($edit): Form
{
return $this->baseForm()->title('')->body([
amisMake()->TextControl()->name('name')->label(__('employee.name'))->required(),
amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->required(),
amisMake()->SelectControl()->name('employee_status')->label(__('employee.employee_status'))->options(EmployeeStatus::options())->required(),
amisMake()->TagControl()->name('jobs')->label(__('employee.jobs'))
->source(admin_url('api/keywords/tree-list').'?parent_key='.Employee::JOB_KEY)
->labelField('name')
->valueField('key')
->joinValues(),
amisMake()->DateControl()->name('join_at')->label(__('employee.join_at'))->format('YYYY-MM-DD'),
amisMake()->ImageControl()->name('prize_images')->label(__('employee.prize_images'))
->multiple()
->receiver($this->uploadImagePath() . '?full-url=1')
->joinValues(false)
->extractValue(true),
amisMake()->ImageControl()->name('skill_images')->label(__('employee.skill_images'))
->multiple()
->receiver($this->uploadImagePath() . '?full-url=1')
->joinValues(false)
->extractValue(true),
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->visible(! $edit)->required(! $edit),
amisMake()->TextControl()->name('password')->set('type', 'input-password')->label(__('admin.password'))->visible(! $edit)->required(! $edit),
amisMake()->TextControl()->name('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->visible(! $edit)->required(! $edit),
]);
}
public function detail(): Form
{
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
['label' => __('employee.name'), 'content' => '${name}'],
['label' => __('employee.phone'), 'content' => '${phone}'],
['label' => __('employee.jobs'), 'content' => amisMake()->Each()->name('jobs')->items(amisMake()->Tag()->label('${name}'))],
['label' => __('employee.employee_status'), 'content' => amisMake()->Tag()->label('${employee_status_text}')->color('${employee_status_color}')],
['label' => __('employee.join_at'), 'content' => '${join_at}'],
['label' => __('employee.leave_at'), 'content' => '${leave_at}'],
['label' => __('admin.username'), 'content' => '${admin_user.username}', 'span' => 3],
['label' => __('employee.prize_images'), 'content' => amisMake()->Images()->source('${prize_images}')->enlargeAble(), 'span' => 3],
['label' => __('employee.skill_images'), 'content' => amisMake()->Images()->source('${skill_images}')->enlargeAble(), 'span' => 3],
]));
}
}