Commit a841ad99 by 汪伟伟

地区多选

parent 8bc1dbc5
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:wHGDcJa6sO4Z52I01OWMrNUaWDcDd4iqjs5LrlssMmM=
APP_DEBUG=true
APP_DEBUG=false
APP_URL=http://localhost
LOG_LEVEL=debug
......
......@@ -12,6 +12,7 @@ use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
......@@ -62,10 +63,10 @@ class TaskController extends AdminController
});
$grid->actions(function (Grid\Displayers\Actions $actions)use ($user){
if ($user->is_admin == 0){
if ($this->num > 0 && !TasksReceive::query()->where('task_id',$this->id)->where('user_id',$user->id)->exists()){
$actions->append( new ReceiveAction());//领取按钮
$grid->actions(function (Grid\Displayers\Actions $actions) use ($user) {
if ($user->is_admin == 0) {
if ($this->num > 0 && !TasksReceive::query()->where('task_id', $this->id)->where('user_id', $user->id)->exists()) {
$actions->append(new ReceiveAction());//领取按钮
}
}
......@@ -73,7 +74,7 @@ class TaskController extends AdminController
$grid->disableEditButton()->disableDeleteButton()->disableCreateButton();
$grid->disableBatchDelete();
$grid->tools(function (Grid\Tools $tools) use ($user){
$grid->tools(function (Grid\Tools $tools) use ($user) {
if ($user->is_admin == 0) {
$tools->append(new BatchReceiveAction());//新增批量领取按钮
}
......@@ -89,7 +90,7 @@ class TaskController extends AdminController
*/
protected function receiveDetail($id)
{
return Show::make($id, new Task(), function (Show $show)use ($id) {
return Show::make($id, new Task(), function (Show $show) use ($id) {
$show->field('id');
$show->field('name');
$show->field('level');
......@@ -159,7 +160,7 @@ class TaskController extends AdminController
*/
protected function detail($id)
{
return Show::make($id, new Task(), function (Show $show)use ($id) {
return Show::make($id, new Task(), function (Show $show) use ($id) {
$show->field('id');
$show->field('name');
$show->field('level');
......@@ -176,6 +177,27 @@ class TaskController extends AdminController
}
public function getCity(Request $request)
{
// $provinceId = $request->get('q');
$data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true);
$city = [];
foreach ($data['100000'] as $key=>$value) {
if (isset($data[$key])) {
foreach ($data[$key] as $k => $val) {
$city[] = [
'id' => $k,
'text' => $val
];
}
}
}
return $city;
}
/**
* Make a form builder.
......@@ -185,23 +207,19 @@ class TaskController extends AdminController
protected function form()
{
// $data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true);
// foreach ($data as $key=>$datum) {
// if (array_key_exists($key, $data['100000'])) {
// foreach ($datum as $k => $d) {
// $arr[$k] = $d;
// }
// }
// }
// $arr = $data['100000'];
return Form::make(new Task(), function (Form $form) {
$form->display('id');
$form->text('name')->required();
$form->select('level')->options([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5])->required();
// $form->multipleSelect('area', '选择地区')->options($arr)->value('110000')->required();
$form->distpicker([
'province_id' => '省',
'city_id' => '市',
], '选择地区')->required();
// $form->timeRange('year','year','选择时间');
// $form->select('province_id', '省')->options($arr)->loads('city_id', '/getCity');
$form->multipleSelect('city_id', '选择地区')->options('/getCity')->required();
// $form->distpicker([
// 'province_id' => '省',
// 'city_id' => '市',
// ], '选择地区')->required();
$form->multipleSelect('year', '选择时间')->options(function () {
$year = (int)date('Y');
......@@ -210,7 +228,7 @@ class TaskController extends AdminController
}
return $years;
})->value(2024)->required();
$form->url('refer', '参考信源')->required();
$form->text('refer', '参考信源')->required();
$form->editor('guide', '收集指南')->required();
// $form->text('status');
......@@ -257,14 +275,17 @@ class TaskController extends AdminController
// dd($request->input());
$param = $request->input();
$query = \App\Models\Task::query();
foreach ($param['city_id'] as $city) {
if ($city) {
foreach ($param['year'] as $y) {
if ($y) {
$insertData = [
'name' => $param['name'],
'level' => $param['level'],
'province_id' => $param['province_id'],
'city_id' => $param['city_id'],
'province_id' => '',
'city_id' => $city,
'year' => [$y],
'refer' => $param['refer'],
'guide' => $param['guide'],
......@@ -272,7 +293,8 @@ class TaskController extends AdminController
$query->create($insertData);
}
}
}
}
$form = Form::make();
return $form->response()->success('操作成功')->redirect('tasks');
......
......@@ -159,9 +159,5 @@ class TasksApproveController extends AdminController
// ->body($this->form());
// }
public function update($id)
{
dd($id);
return $this->res;
}
}
......@@ -14,9 +14,12 @@ Route::group([
$router->get('/dashboard', 'HomeController@index');
$router->resource('tasks', 'TaskController');
$router->get('receive', 'TaskController@receiveIndex');
$router->get('getCity', 'TaskController@getCity');
$router->get('receive/{id}', 'TaskController@receiveDetail');
......
......@@ -24,8 +24,8 @@ class Task extends Model
protected $fillable = [
'name',
'level',
'province_id',
'city_id',
'province_id',
'year',
'refer',
'guide',
......@@ -55,6 +55,11 @@ class Task extends Model
$this->attributes['year'] = implode(',', $value);
}
public function setCityIdAttribute($value)
{
$this->attributes['city_id'] = implode(',', $value);
}
public function approves()
{
return $this->hasMany(TasksApprove::class,'task_id');
......
......@@ -36,7 +36,7 @@
"820000": "澳门特别行政区"
},
"110000": {
"110100": "北京城区"
"110100": "北京"
},
"110100": {
"110101": "东城区",
......@@ -57,7 +57,7 @@
"110119": "延庆区"
},
"120000": {
"120100": "天津城区"
"120100": "天津"
},
"120100": {
"120101": "和平区",
......@@ -970,7 +970,7 @@
"232722": "塔河县"
},
"310000": {
"310100": "上海城区"
"310100": "上海"
},
"310100": {
"310101": "黄浦区",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment