You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
5.4 KiB
141 lines
5.4 KiB
<?php |
|
|
|
namespace App\Admin\Controllers; |
|
|
|
use App\Admin\Metrics\Examples\Follow\AllEnrollCollege; |
|
use App\Admin\Metrics\Examples\Follow\AllEnrollSpeciality; |
|
use App\Admin\Metrics\Examples\Follow\AllNewFollowCollege; |
|
use App\Admin\Metrics\Examples\Follow\AllNewFollowSpeciality; |
|
use App\Http\Controllers\Controller; |
|
use App\Models\AdminFollowShow; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\Speciality; |
|
use App\Models\UserFollowStatus; |
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Admin; |
|
use Dcat\Admin\Grid; |
|
use Dcat\Admin\Layout\Column; |
|
use Dcat\Admin\Layout\Content; |
|
use Dcat\Admin\Layout\Row; |
|
use Illuminate\Http\Request; |
|
|
|
|
|
class UserFollowOverviewController extends Controller |
|
{ |
|
public $showInfo; |
|
// 回访状态 |
|
public $followStatusList = []; |
|
// 回访状态选项框默认值 |
|
public $lastElement; |
|
// 学院select选项 |
|
public $secondaryCollegeList = []; |
|
// 专业select选项 |
|
public $specialityList = []; |
|
|
|
|
|
public function index(Content $content): Content |
|
{ |
|
$this->showInfo = AdminFollowShow::query()->where(['user_id' => Admin::user()['id']])->first(); |
|
$this->followStatusList = UserFollowStatus::query()->orderByDesc('id')->pluck('name', 'id')->toArray(); |
|
$this->lastElement = array_slice($this->followStatusList, -1, 1, true); |
|
$this->secondaryCollegeList = SecondaryCollege::query()->whereIn('id', $this->showInfo['secondary_college_id'] ?? [])->pluck("name", "id"); |
|
|
|
$list = Speciality::query()->whereIn("id", $this->showInfo['speciality_id'] ?? [])->get()->toArray(); |
|
foreach ($list as $item) { |
|
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
$this->specialityList[$item["id"]] = $item["speciality_name"] . "({$college->name})"; |
|
} |
|
|
|
return $content |
|
->header('新生数据概览') |
|
->description('各项数据统计详情') |
|
->body(function (Row $row) { |
|
$row->column(12, function (Column $column) { |
|
$getData = [ |
|
'secondary_college_id' => request()->get('secondary_college_id', ''), |
|
'speciality_id' => request()->get('speciality_id', ''), |
|
'follow_id' => request()->get('follow_id', ''), |
|
]; |
|
if (empty($getData['secondary_college_id'])) { |
|
$getData['secondary_college_id'] = $this->showInfo['secondary_college_id'] ?? ""; |
|
} |
|
|
|
$column->row(function (Row $row) use ($getData) { |
|
$row->column(12, $this->table($getData)); |
|
}); |
|
$column->row(function (Row $row) use ($getData) { |
|
$row->column(4, new AllEnrollCollege($getData)); |
|
$row->column(4, new AllNewFollowCollege($getData)); |
|
}); |
|
$column->row(function (Row $row) use ($getData) { |
|
$row->column(4, new AllEnrollSpeciality($getData)); |
|
$row->column(4, new AllNewFollowSpeciality($getData)); |
|
}); |
|
|
|
Admin::script(<<<JS |
|
var table = document.getElementsByClassName("data-table") |
|
for (var i = 0; i < table.length; i++) { |
|
table[i].style.display = "none"; |
|
} |
|
JS |
|
); |
|
}); |
|
}); |
|
} |
|
|
|
|
|
protected function table($getData): Grid |
|
{ |
|
return Grid::make(new UsersMember(), function (Grid $grid) use ($getData) { |
|
// 禁用 |
|
$grid->disableToolbar(); |
|
// 禁用 |
|
$grid->disablePagination(); |
|
// 禁用操作 |
|
$grid->disableActions(); |
|
// 禁用批量操作 |
|
$grid->disableBatchActions(); |
|
// 禁用行选择 |
|
$grid->disableRowSelector(); |
|
// 禁用创建 |
|
$grid->disableCreateButton(); |
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
$filter->panel(); |
|
$filter->expand(); |
|
|
|
$filter->equal('secondary_college_id', '学院') |
|
->select($this->secondaryCollegeList) |
|
->load('speciality_id', '/api/getSpecialityList') |
|
->ignore() |
|
->width(2); |
|
$filter->equal('speciality_id', '专业') |
|
->select($this->specialityList) |
|
->ignore() |
|
->width(3); |
|
$filter->equal('follow_id', '回访状态') |
|
->select($this->followStatusList) |
|
->ignore() |
|
->width(2); |
|
}); |
|
}); |
|
} |
|
|
|
|
|
/** |
|
* @desc 二级联动:学院下面的专业数据 |
|
* @author 何鸠鸠 |
|
*/ |
|
public function getSpecialityList(Request $request): array |
|
{ |
|
$provinceId = $request->get('q'); |
|
|
|
$list = Speciality::query()->where("secondary_college_id", $provinceId)->get()->toArray(); |
|
$select = []; |
|
foreach ($list as $item) { |
|
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
$select[] = ['id' => $item["id"], 'text' => $item["speciality_name"] . "({$college->name})"]; |
|
} |
|
return $select; |
|
} |
|
}
|
|
|