优化:国家选择器 - 添加区域分组筛选
This commit is contained in:
parent
df8cff8869
commit
5a83342538
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Beike\Admin\Http\Controllers;
|
namespace Beike\Admin\Http\Controllers;
|
||||||
|
|
||||||
use Beike\Admin\Repositories\RegionRepo;
|
use Beike\Admin\Repositories\RegionRepo;
|
||||||
|
use Beike\Models\Region;
|
||||||
use Beike\Repositories\CountryRepo;
|
use Beike\Repositories\CountryRepo;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
|
@ -52,4 +53,19 @@ class RegionController
|
||||||
|
|
||||||
return json_success(trans('common.deleted_success'));
|
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_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_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_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
|
// RMA
|
||||||
Route::middleware('can:rmas_update')->post('rmas/history/{id}', [Controllers\RmaController::class, 'addHistory'])->name('rmas.add_history');
|
Route::middleware('can:rmas_update')->post('rmas/history/{id}', [Controllers\RmaController::class, 'addHistory'])->name('rmas.add_history');
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Beike\Repositories;
|
namespace Beike\Repositories;
|
||||||
|
|
||||||
use Beike\Models\Country;
|
use Beike\Models\Country;
|
||||||
|
use Beike\Models\RegionZone;
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
@ -134,9 +135,18 @@ class CountryRepo
|
||||||
public static function autocomplete($name, $onlyActive = 1){
|
public static function autocomplete($name, $onlyActive = 1){
|
||||||
// 参数获取
|
// 参数获取
|
||||||
$pageSize = request()->input('page_size',10);
|
$pageSize = request()->input('page_size',10);
|
||||||
|
$regionsId = (int)request()->input('regions_id');
|
||||||
// 列表获取
|
// 列表获取
|
||||||
$builder = Country::query()
|
$builder = Country::query()
|
||||||
->where('name', 'like', "$name%")
|
->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')
|
->select('id', 'name', 'icon', 'status', 'code')
|
||||||
->orderBy('sort_order','ASC')
|
->orderBy('sort_order','ASC')
|
||||||
->orderBy('id','ASC');
|
->orderBy('id','ASC');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<div class="swiper-slide">
|
<div class="swiper-slide">
|
||||||
<a href="{{ $image['link']['link'] ?: 'javascript:void(0)' }}" class="d-flex justify-content-center">
|
<a href="{{ $image['link']['link'] ?: 'javascript:void(0)' }}" class="d-flex justify-content-center">
|
||||||
@if(in_array(pathinfo($image['image'])['extension'],['mp4']))
|
@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
|
@else
|
||||||
<img src="{{ $image['image'] }}" class="img-fluid">
|
<img src="{{ $image['image'] }}" class="img-fluid">
|
||||||
@endif
|
@endif
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,13 @@
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.regions-list{
|
||||||
|
margin-top: 10px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.regions-list button{
|
||||||
|
margin: 0 5px 5px 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<template id="select-countries">
|
<template id="select-countries">
|
||||||
<el-dialog custom-class="mobileWidth" title="{{ __('admin/customer.choose_country') }}" :visible.sync="is_show" width="80%" @close="closeSelectCountries">
|
<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') }}"/>
|
<input type="text" v-model="countries_name" class="form-control" placeholder="{{ __('admin/customer.search_placeholder') }}"/>
|
||||||
</div>
|
</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="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)">
|
<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,
|
is_show: false,
|
||||||
countries_name: '',
|
countries_name: '',
|
||||||
countries_list: {},
|
countries_list: {},
|
||||||
|
regions_list: {},
|
||||||
|
regions_id: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch:{
|
watch:{
|
||||||
countries_name(){
|
countries_name(){
|
||||||
this.getCountriesList();
|
this.getCountriesList();
|
||||||
|
},
|
||||||
|
regions_id(){
|
||||||
|
this.getCountriesList();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {},
|
||||||
beforeMount() {},
|
beforeMount() {},
|
||||||
mounted(){
|
mounted(){
|
||||||
this.getCountriesList()
|
this.getCountriesList();
|
||||||
|
this.getRegionsList();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 显示国家选择器
|
// 显示国家选择器
|
||||||
|
|
@ -210,6 +233,7 @@
|
||||||
let params = {
|
let params = {
|
||||||
name: _this.countries_name,
|
name: _this.countries_name,
|
||||||
page_size: 'all',
|
page_size: 'all',
|
||||||
|
regions_id: _this.regions_id
|
||||||
};
|
};
|
||||||
// 发起请求
|
// 发起请求
|
||||||
$http.get(url, params, {hload: true}).then((res) => {
|
$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){
|
isSelected(item){
|
||||||
let isHas = false;
|
let isHas = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue