优化:国家选择器 - 添加区域分组筛选
This commit is contained in:
parent
df8cff8869
commit
5a83342538
|
|
@ -12,6 +12,7 @@
|
|||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Admin\Repositories\RegionRepo;
|
||||
use Beike\Models\Region;
|
||||
use Beike\Repositories\CountryRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
|
@ -52,4 +53,19 @@ class RegionController
|
|||
|
||||
return json_success(trans('common.deleted_success'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 获取全部的区域分组
|
||||
* Author: wu-hui
|
||||
* Time: 2023/08/31 9:25
|
||||
* @return array
|
||||
*/
|
||||
public function regionsAll(){
|
||||
$list = Region::query()->select(['id','name'])->get();
|
||||
|
||||
return json_success(trans('common.get_success'), $list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,6 +234,8 @@ Route::prefix($adminName)
|
|||
Route::middleware('can:regions_create')->post('regions', [Controllers\RegionController::class, 'store'])->name('regions.store');
|
||||
Route::middleware('can:regions_update')->put('regions/{id}', [Controllers\RegionController::class, 'update'])->name('regions.update');
|
||||
Route::middleware('can:regions_delete')->delete('regions/{id}', [Controllers\RegionController::class, 'destroy'])->name('regions.destroy');
|
||||
Route::middleware('can:regions_all')->get('regions/get_all', [Controllers\RegionController::class, 'regionsAll'])->name('regions.regions_all');
|
||||
|
||||
|
||||
// RMA
|
||||
Route::middleware('can:rmas_update')->post('rmas/history/{id}', [Controllers\RmaController::class, 'addHistory'])->name('rmas.add_history');
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Country;
|
||||
use Beike\Models\RegionZone;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
|
@ -134,9 +135,18 @@ class CountryRepo
|
|||
public static function autocomplete($name, $onlyActive = 1){
|
||||
// 参数获取
|
||||
$pageSize = request()->input('page_size',10);
|
||||
$regionsId = (int)request()->input('regions_id');
|
||||
// 列表获取
|
||||
$builder = Country::query()
|
||||
->where('name', 'like', "$name%")
|
||||
->when($regionsId > 0,function($query) use ($regionsId){
|
||||
$ids = RegionZone::query()
|
||||
->where('region_id',$regionsId)
|
||||
->where('zone_id',0)
|
||||
->pluck('country_id');
|
||||
$ids = $ids ? $ids->toArray() : [];
|
||||
if(is_array($ids) && count($ids) > 0) $query->whereIn('id',$ids);
|
||||
})
|
||||
->select('id', 'name', 'icon', 'status', 'code')
|
||||
->orderBy('sort_order','ASC')
|
||||
->orderBy('id','ASC');
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<div class="swiper-slide">
|
||||
<a href="{{ $image['link']['link'] ?: 'javascript:void(0)' }}" class="d-flex justify-content-center">
|
||||
@if(in_array(pathinfo($image['image'])['extension'],['mp4']))
|
||||
<video src="{{ $image['image'] }}" class="img-fluid" controls autoplay loop muted>
|
||||
<video src="{{ $image['image'] }}" class="img-fluid" controls autoplay muted>
|
||||
@else
|
||||
<img src="{{ $image['image'] }}" class="img-fluid">
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -137,7 +137,13 @@
|
|||
align-items: flex-end;
|
||||
}
|
||||
|
||||
|
||||
.regions-list{
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
.regions-list button{
|
||||
margin: 0 5px 5px 0;
|
||||
}
|
||||
</style>
|
||||
<template id="select-countries">
|
||||
<el-dialog custom-class="mobileWidth" title="{{ __('admin/customer.choose_country') }}" :visible.sync="is_show" width="80%" @close="closeSelectCountries">
|
||||
|
|
@ -151,6 +157,17 @@
|
|||
{{--搜索输入框--}}
|
||||
<input type="text" v-model="countries_name" class="form-control" placeholder="{{ __('admin/customer.search_placeholder') }}"/>
|
||||
</div>
|
||||
{{--区域分组--}}
|
||||
<div class="regions-list">
|
||||
所属地区:
|
||||
<button
|
||||
v-for="(item,index) in regions_list"
|
||||
:key="index"
|
||||
type="button"
|
||||
:class="['btn',item.id == regions_id ? 'btn-success' : 'btn-light']"
|
||||
@click="regions_id = item.id"
|
||||
>@{{ item.name }}</button>
|
||||
</div>
|
||||
{{--国家列表--}}
|
||||
<div class="countries-list" v-if="Object.keys(countries_list).length > 0">
|
||||
<div :class="['list-box',{'list-box-active':isSelected(item)}]" v-for="(item,index) in countries_list" :title="item.name" @click="clickCountries(item)">
|
||||
|
|
@ -182,17 +199,23 @@
|
|||
is_show: false,
|
||||
countries_name: '',
|
||||
countries_list: {},
|
||||
regions_list: {},
|
||||
regions_id: 0,
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
countries_name(){
|
||||
this.getCountriesList();
|
||||
},
|
||||
regions_id(){
|
||||
this.getCountriesList();
|
||||
}
|
||||
},
|
||||
computed: {},
|
||||
beforeMount() {},
|
||||
mounted(){
|
||||
this.getCountriesList()
|
||||
this.getCountriesList();
|
||||
this.getRegionsList();
|
||||
},
|
||||
methods: {
|
||||
// 显示国家选择器
|
||||
|
|
@ -210,6 +233,7 @@
|
|||
let params = {
|
||||
name: _this.countries_name,
|
||||
page_size: 'all',
|
||||
regions_id: _this.regions_id
|
||||
};
|
||||
// 发起请求
|
||||
$http.get(url, params, {hload: true}).then((res) => {
|
||||
|
|
@ -218,6 +242,23 @@
|
|||
}
|
||||
})
|
||||
},
|
||||
// 区域分组列表
|
||||
getRegionsList(){
|
||||
let _this = this;
|
||||
let url = `regions/get_all`;
|
||||
let params = {};
|
||||
// 发起请求
|
||||
$http.get(url, params, {hload: true}).then((res) => {
|
||||
if(res.status === 'success'){
|
||||
let regionsList = [
|
||||
{id:0,name:'全部'}
|
||||
];
|
||||
let data = res.data || [];
|
||||
|
||||
_this.regions_list = regionsList.concat(data);
|
||||
}
|
||||
})
|
||||
},
|
||||
// 判断:当前国家是否已经被选中
|
||||
isSelected(item){
|
||||
let isHas = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue