254 lines
13 KiB
PHP
254 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use App\Admin\Components;
|
|
use App\Models\Region;
|
|
use App\Models\Device;
|
|
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
|
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
|
use Slowlyo\OwlAdmin\Renderers\Service;
|
|
|
|
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('devices')->where('category_id', $categoryId)->get();
|
|
$resList = [];
|
|
foreach($regionList as $region){
|
|
$tabs = [
|
|
[
|
|
'title' => '基地详情',
|
|
'value' => 'detail',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 0,
|
|
],
|
|
];
|
|
if($region->devices){
|
|
foreach($region->devices as $device){
|
|
switch($device->type)
|
|
{
|
|
case Device::TYPE_MONITOR:
|
|
$tabs[] = [//有监控设备才有
|
|
'title' => '监控视频',
|
|
'value' => 'monitor',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-monitor?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 1,
|
|
];
|
|
break;
|
|
case Device::TYPE_SOIL:
|
|
$tabs[] = [//有土壤设备才有
|
|
'title' => '土壤数据',
|
|
'value' => 'turang',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-soil?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 2,
|
|
];
|
|
break;
|
|
case Device::TYPE_WATER_QUALITY:
|
|
$tabs[] = [//有水质设备才有
|
|
'title' => '水质数据',
|
|
'value' => 'shuizi',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-water?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 3,
|
|
];
|
|
break;
|
|
case Device::TYPE_METEOROLOGICAL:
|
|
$tabs[] = [//有气象设备才有
|
|
'title' => '气象数据',
|
|
'value' => 'qixiang',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-meteorological?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 4,
|
|
];
|
|
break;
|
|
case Device::TYPE_AIR:
|
|
$tabs[] = [//有通风设备才有
|
|
'title' => '通风设备',
|
|
'value' => 'air',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-air?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 5,
|
|
];
|
|
break;
|
|
case Device::TYPE_ATOMIZING:
|
|
$tabs[] = [//有喷雾设备才有
|
|
'title' => '喷雾设备',
|
|
'value' => 'wasserstrahl',
|
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-wasserstrahl?id='.$region->id)),
|
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
'sort' => 6,
|
|
];
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
$tabs = array_merge(collect($tabs)->sortBy('sort')->toArray(), []);
|
|
$resList[] = [
|
|
"icon"=> $region->cover ?? '',
|
|
"text"=> $region->name,
|
|
'clickAction' => DialogAction::make()->dialog(
|
|
Dialog::make()->title($region['name'])->body([
|
|
\amisMake()->Tabs()->tabsMode('simple')->name('detailTab')->tabs($tabs),
|
|
])->size('full')
|
|
),
|
|
];
|
|
}
|
|
return $resList;
|
|
}
|
|
|
|
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),
|
|
\amisMake()->TextControl()->static(true)->name('director')->label('负责人')->value($region->director),
|
|
\amisMake()->TextControl()->static(true)->name('category')->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)->name('is_enable')->name('is_enable')->label('显示')->value($region?->is_enable ?? 0),
|
|
]),
|
|
amisMake()->Panel()->title('基础介绍')
|
|
->body([
|
|
amisMake()->Tpl()->tpl($region?->content ?? '')
|
|
])
|
|
]),
|
|
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()
|
|
->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('种植时间'),
|
|
])
|
|
->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()->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都要销毁
|
|
// ],
|
|
])
|
|
])
|
|
])
|
|
->itemActions([
|
|
\amisMake()->DialogAction()->label('编辑')->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}')
|
|
])
|
|
])
|
|
])
|
|
]),
|
|
])
|
|
]);
|
|
|
|
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 HH:mm:ss')->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 HH:mm:ss')->label('种植时间')->required(true),
|
|
]);
|
|
}
|
|
}
|