Commit a841ad99 by 汪伟伟

地区多选

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