200 lines
10 KiB
PHP
200 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use App\Admin\Components;
|
|
use App\Models\Region;
|
|
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
|
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
|
use Slowlyo\OwlAdmin\Renderers\Image;
|
|
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
|
|
|
class CustomRegionController extends AdminController
|
|
{
|
|
protected string $queryPath = 'custom-region';
|
|
|
|
public function regionIndex($type)
|
|
{
|
|
switch($type){
|
|
case 'yuyang':
|
|
// $this->pageTitle = '育秧列表';
|
|
$categoryId = 1;
|
|
break;
|
|
case 'daotian':
|
|
// $this->pageTitle = '稻田列表';
|
|
$categoryId = 2;
|
|
break;
|
|
}
|
|
|
|
$page = $this->basePage()->body([
|
|
\amisMake()->GridNav()->options(
|
|
$this->regionList($categoryId)
|
|
)
|
|
]);
|
|
|
|
return $this->response()->success($page);
|
|
}
|
|
|
|
private function regionList($categoryId)
|
|
{
|
|
$regionList = Region::with('monitorModes')->where('category_id', $categoryId)->get();
|
|
$resList = [];
|
|
foreach($regionList as $region){
|
|
$tabs = Region::regionTabConfig($region);
|
|
$resList[] = [
|
|
"icon"=> $region->cover ?: url('default.svg'),
|
|
"text"=> $region->name,
|
|
'clickAction' => DialogAction::make()->dialog(
|
|
Dialog::make()->title($region['name'])->body([
|
|
\amisMake()->Tabs()->tabsMode('simple')->tabs($tabs),
|
|
])->size('full')->actions([])
|
|
),
|
|
];
|
|
}
|
|
return $resList;
|
|
}
|
|
|
|
public function getRegionTabs(Request $request){
|
|
$region = Region::find($request->id);
|
|
$tabs = Region::regionTabConfig($region);
|
|
$page = \amisMake()->Tabs()->tabsMode('simple')->tabs($tabs);
|
|
|
|
return $this->response()->success($page);
|
|
}
|
|
|
|
public function regionDetail(Request $request)
|
|
{
|
|
$id = $request->id;
|
|
$region = Region::find($id);
|
|
$page = $this->basePage()->body([
|
|
amisMake()->Grid()->columns([
|
|
amisMake()->Wrapper()->sm(4)->body([
|
|
amisMake()->Panel()->title('基础详情')
|
|
->subFormMode('horizontal')
|
|
->labelWidth(100)
|
|
->body([
|
|
\amisMake()->TextControl()->static(true)->name('name')->label('名称')->value($region?->name),
|
|
TextControl::make()->name('cover')->label(__('region.cover'))->static(true)->staticSchema(Image::make()->src($region?->cover)),
|
|
\amisMake()->TextControl()->static(true)->name('director')->label('负责人')->value($region->director),
|
|
\amisMake()->TextControl()->static(true)->name('category_name')->label('分类')->value($region->category?->name ?? ''),
|
|
\amisMake()->TextControl()->static(true)->name('area')->label('面积m²')->value($region?->area ?? ''),
|
|
\amisMake()->TextControl()->static(true)->name('sort')->label('排序')->value($region?->sort ?? '0'),
|
|
\amisMake()->SwitchControl()->static(true)->label('显示')->value(!!$region->is_enable),
|
|
]),
|
|
amisMake()->Panel()->title('基础介绍')
|
|
->body([
|
|
amisMake()->Wrapper()->className('overflow-x-auto')->size('none')->body(
|
|
Components::make()->fuEditorControl('content', '')->value($region?->description)->static(true)
|
|
),
|
|
])
|
|
]),
|
|
amisMake()->Wrapper()->sm(8)->body([
|
|
amisMake()->Panel()->title('种植记录')
|
|
->body([
|
|
DialogAction::make()->className('absolute top-1 right-4')->label(__('admin.create'))->dialog(
|
|
Dialog::make()->title('新增种植记录')->body($this->plantCreateForm($region))
|
|
),
|
|
\amisMake()->CRUDTable()->affixHeader(false)
|
|
->title('')
|
|
->api(admin_url('crop-plants').'?_action=getData®ion_id='.$region->id)
|
|
->columns([
|
|
amisMake()->TableColumn()->name('plant_name')->label('名称'),
|
|
amisMake()->TableColumn()->name('director')->label('负责人'),
|
|
amisMake()->TableColumn()->name('area')->label('种植面积m²'),
|
|
amisMake()->TableColumn()->name('start_at')->label('种植时间'),
|
|
amisMake()->TableColumn()->name('plant_state')->type('status')->source([
|
|
1 => ['label' => '种植中','icon' => 'fa fa-warning','color' => '#ff9326'],
|
|
2 => ['label' => '已结束','icon' => 'fa fa-check-circle','color' => '#ffb6b3']
|
|
])->label('种植状态'),
|
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
|
amisMake()
|
|
->DialogAction()
|
|
->label('编辑')
|
|
->level('link')
|
|
->dialog(Dialog::make()->title('编辑种植记录')->body($this->plantEditForm())),
|
|
amisMake()->AjaxAction()->label('删除')->level('link')
|
|
->actionType('ajax')
|
|
->confirmText(__('admin.confirm_delete'))
|
|
->api([
|
|
'method' => 'delete',
|
|
'url' => admin_url('crop-plants/${id}')
|
|
])
|
|
]),
|
|
])
|
|
->itemAction([
|
|
'type'=>'button',
|
|
'actionType'=>'dialog',
|
|
'dialog'=> \amisMake()->Dialog()->title('${plant_name}')
|
|
->size('full')->actions([])->body([
|
|
\amisMake()->Tabs()->tabsMode('simple')->name('detailTab')->tabs([
|
|
[
|
|
'title' => '种植详情',
|
|
'value' => 'detail',
|
|
'tab'=>\amisMake()->Service()->name('plant_detail')->schemaApi(admin_url('crop-plant-detail?id=${id}')),//传id
|
|
'unmountOnExit' => true//每次切换tab都要销毁
|
|
],
|
|
// [
|
|
// 'title' => '报警记录',
|
|
// 'value' => 'warning',
|
|
// // 'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?id='.$region['id'])),
|
|
// 'unmountOnExit' => true//每次切换tab都要销毁
|
|
// ],
|
|
[
|
|
'title' => '虫情记录',
|
|
'value' => 'warning',
|
|
// 'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?id='.$region['id'])),
|
|
'unmountOnExit' => true//每次切换tab都要销毁
|
|
],
|
|
])
|
|
])
|
|
])
|
|
])
|
|
]),
|
|
])
|
|
]);
|
|
|
|
return $this->response()->success($page);
|
|
}
|
|
|
|
private function plantCreateForm(Region $region = null){
|
|
return amisMake()->Form()
|
|
->api([
|
|
'method'=>'post',
|
|
'url'=>admin_url('crop-plants'),
|
|
"data" => [
|
|
'region_id'=>'${region_id}',
|
|
'plant_name'=>'${plant_name}',
|
|
'director'=>'${plant_director}',
|
|
'area'=>'${plant_area}',
|
|
'start_at'=>'${start_at}',
|
|
],
|
|
])
|
|
->body([
|
|
\amisMake()->TextControl()->name('region_id')->label('区域ID')->hidden(true)->value($region?->id ?? 0),
|
|
\amisMake()->TextControl()->name('plant_name')->label('作物名称')->required(true),
|
|
\amisMake()->TextControl()->name('plant_director')->label('负责人')->required(true),
|
|
Components::make()->decimalControl('plant_area','种植面积')->required(true),
|
|
\amisMake()->DateControl()->name('start_at')->format('YYYY-MM-DD')->label('种植时间')->required(true),
|
|
]);
|
|
}
|
|
|
|
private function plantEditForm(){
|
|
return amisMake()->Form()
|
|
->api([
|
|
'method'=>'put',
|
|
'url'=>admin_url('crop-plants/${id}'),
|
|
])->initApi(admin_url('crop-plants/${id}/edit').'?_action=getData')
|
|
->body([
|
|
\amisMake()->TextControl()->name('id')->hidden(true),
|
|
\amisMake()->TextControl()->name('region_id')->label('区域ID')->hidden(true),
|
|
\amisMake()->TextControl()->name('plant_name')->label('作物名称')->required(true),
|
|
\amisMake()->TextControl()->name('director')->label('负责人')->required(true),
|
|
Components::make()->decimalControl('area','种植面积')->required(true),
|
|
\amisMake()->DateControl()->name('start_at')->format('YYYY-MM-DD')->label('种植时间')->required(true),
|
|
\amisMake()->DateControl()->name('end_at')->format('YYYY-MM-DD')->label('结束时间'),
|
|
]);
|
|
}
|
|
}
|