添加:物流管理 - 添加前台默认展示国家

This commit is contained in:
wuhui_zzw 2023-08-25 14:16:09 +08:00
parent 4032cfaaa1
commit 3c96766442
7 changed files with 195 additions and 123 deletions

View File

@ -15,6 +15,7 @@ use Beike\Repositories\CategoryRepo;
use Beike\Repositories\CountryRepo;
use Beike\Repositories\LanguageRepo;
use Beike\Repositories\LogisticsRepo;
use Beike\Repositories\SettingRepo;
use Illuminate\Http\Request;
class LogisticsController extends Controller
@ -31,10 +32,14 @@ class LogisticsController extends Controller
$logistics = LogisticsResource::collection($logisticsList);
$logisticsFormat = $logistics->jsonSerialize();
$countries = LogisticsRepo::getDefaultCountries();
$data = [
'logistics_format' => $logisticsFormat,
'logistics' => $logistics,
'type' => 'logistics',
'default_countries' => $countries,
'default_countries_name' => is_array($countries) ? array_values($countries)[0]['name'] : ''
];
$data = hook_filter('admin.logistics.index.data', $data);
@ -166,7 +171,6 @@ class LogisticsController extends Controller
// 获取
$countryIds = (array)explode(',',$logistics->country_ids);
$logistics->country_ids = CountryRepo::getInList($countryIds);
$data = [
'logistics' => $logistics,
'types' => $types,
@ -227,4 +231,22 @@ class LogisticsController extends Controller
{
LogisticsRepo::forceDeleteTrashed();
}
/**
* Common: 设置默认物流国家
* Author: wu-hui
* Time: 2023/08/25 13:48
* @return array
* @throws \Throwable
*/
public function defaultCountries(){
$country = request()->post('country');
SettingRepo::storeValue('default_country', $country,'logistics','plugin');
return json_success(trans('common.updated_success'), []);
}
}

View File

@ -227,6 +227,7 @@ Route::prefix($adminName)
Route::middleware('can:logistics_show')->get('logistics/{logistics}/edit', [Controllers\LogisticsController::class, 'edit'])->name('logistics.edit');
Route::middleware('can:logistics_update')->put('logistics/{logistics}', [Controllers\LogisticsController::class, 'update'])->name('logistics.update');
Route::middleware('can:logistics_delete')->delete('logistics/{logistics}', [Controllers\LogisticsController::class, 'destroy'])->name('logistics.destroy');
Route::middleware('can:logistics_default_countries')->post('logistics/default_countries', [Controllers\LogisticsController::class, 'defaultCountries'])->name('logistics.default_countries');
// 区域组
Route::middleware('can:regions_index')->get('regions', [Controllers\RegionController::class, 'index'])->name('regions.index');

View File

@ -373,4 +373,18 @@ class LogisticsRepo
$products->forceDelete();
}
/**
* Common: 获取默认国家
* Author: wu-hui
* Time: 2023/08/25 13:50
* @param false $isGetInfo
* @return array|mixed
*/
public static function getDefaultCountries($isGetInfo = false){
$set = plugin_setting('logistics.default_country');
if($set && !$isGetInfo) $set = array_column([$set],null,'id');
return $set ?? [];
}
}

View File

@ -41,6 +41,21 @@
.fcm-content .fcm-footer .title{
margin-right: 10px;
}
.default-countries{
margin-left: 30px!important;
display: inline-flex;
align-items: flex-end;
justify-content: flex-start;
font-size: 15px;
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE 10+ */
user-select: none; /* 标准语法 */
}
.countries-select-btn{
color: #409eff;
cursor: pointer;
}
</style>
@if ($errors->has('error'))
<x-admin-alert type="danger" msg="{{ $errors->first('error') }}" class="mt-4" />
@ -54,11 +69,17 @@
<div class="card h-min-600">
<div class="card-body">
<div class="d-flex justify-content-between my-4">
<div class="d-flex my-4">
@if ($type != 'trashed')
<a href="{{ admin_route('logistics.create') }}" class="me-1 nowrap">
<button class="btn btn-primary">{{ __('admin/logistics.logistics_create') }}</button>
</a>
<div class="default-countries">
{{ __('admin/logistics.default_countries') }}
<span class="countries-select-btn" @click="$refs['select-countries'].showSelectCountries()">
@{{ showCurrentCountry() }}
</span>
</div>
@else
@if ($logistics->total())
<button class="btn btn-primary" @click="clearRestore">{{ __('admin/logistics.clear_restore') }}</button>
@ -161,12 +182,15 @@
@endif
</div>
</div>
<select-countries ref="select-countries" :country_list="country_list" @change-info="changeCountry" :is_single="true"></select-countries>
</div>
@hook('admin.product.list.content.footer')
@endsection
@push('footer')
@include('shared.select-countries')
<script>
let app = new Vue({
el: '#product-app',
@ -183,8 +207,9 @@
},
selectedIds: [],
productIds: @json($logistics->pluck('id')),
country_list: @json($default_countries ?? []),
default_countries_name: "{{ $default_countries_name ?? ''}}",
},
computed: {
allSelected: {
get(e) {
@ -195,11 +220,9 @@
}
}
},
created() {
bk.addFilterCondition(this);
},
methods: {
turnOnOff() {
let id = event.currentTarget.getAttribute("data-id");
@ -211,7 +234,6 @@
location.reload();
})
},
batchDelete() {
this.$confirm('{{ __('admin/product.confirm_batch_product') }}', '{{ __('common.text_hint') }}', {
confirmButtonText: '{{ __('common.confirm') }}',
@ -224,7 +246,6 @@
})
}).catch(()=>{});
},
batchActive(type) {
this.$confirm('{{ __('admin/product.confirm_batch_status') }}', '{{ __('common.text_hint') }}', {
confirmButtonText: '{{ __('common.confirm') }}',
@ -237,22 +258,18 @@
})
}).catch(()=>{});
},
search() {
this.filter.page = '';
location = bk.objectToUrlParams(this.filter, this.url)
},
checkedOrderBy(orderBy) {
this.filter.order_by = orderBy;
location = bk.objectToUrlParams(this.filter, this.url)
},
resetSearch() {
this.filter = bk.clearObjectValue(this.filter)
location = bk.objectToUrlParams(this.filter, this.url)
},
copyProduct(index) {
const id = this.productIds[index];
@ -277,7 +294,6 @@
})
}).catch(()=>{});
},
restoreProduct(index) {
const id = this.productIds[index];
@ -289,7 +305,6 @@
})
}).catch(()=>{});;
},
clearRestore() {
this.$confirm('{{ __('admin/product.confirm_delete_restore') }}', '{{ __('common.text_hint') }}', {
type: 'warning'
@ -298,7 +313,25 @@
location.reload();
})
}).catch(()=>{});;
},
// 默认国家信息改变
changeCountry(info){
let _this = this;
_this.country_list = info;
let singleInfo = Object.values(info)[0];
$http.post('logistics/default_countries',{ country: singleInfo }).then((res) => {
_this.default_countries_name = singleInfo.name;
})
},
// 当前选择国家文字显示
showCurrentCountry(){
let name = this.default_countries_name;
if(!name) name = "{{ __('admin/customer.choose_country') }}";
return name;
}
}
});
</script>

View File

@ -1,14 +1,12 @@
<?php
/**
* order.php
*
* @copyright 2022 beikeshop.com - All Rights Reserved
* @link https://beikeshop.com
* @author Edward Yang <yangjin@guangda.work>
* @created 2022-08-02 14:22:41
* @modified 2022-08-02 14:22:41
*/
return [
'logistics_index' => 'Index',
'logistics_name' => 'Logistics Name',
@ -22,11 +20,9 @@ return [
'clear_restore' => 'Empty Recycle Bin',
'logistics_filter_index' => 'View Filters',
'logistics_filter_update' => 'Modify Filters',
'batch_delete' => 'Batch Delete',
'batch_active' => 'Batch Active',
'batch_inactive' => 'Batch Inactive',
'basic_information' => 'Basic Information',
'product_details' => 'Product details',
'product_relations' => 'Related Logistics',
@ -50,14 +46,12 @@ return [
'width' => 'Width',
'height' => 'Height',
'weight_class' => 'weight unit',
'confirm_batch_product' => 'Are you sure you want to delete the selected logistics in batches? ',
'confirm_batch_status' => 'Confirm to modify the status of the selected logistics in batches? ',
'confirm_batch_restore' => 'Confirm to restore the selected product? ',
'confirm_delete_restore' => 'Are you sure you want to empty the recycle bin? ',
'warehouse_name' => 'Warehouse name',
'type' => 'Type',
'first_weight' => 'First weight',
'first_weight_fee' => 'First weight fee',
'continuation_weight_max' => 'Continuation weight max',
@ -79,4 +73,5 @@ return [
'freight_calculation_method' => 'Freight calculation method',
'logistics_duration' => 'Delivery within :day working days after shipment',
'unit' => 'unit:unit',
'default_countries' => 'Default display country for the front desk',
];

View File

@ -78,4 +78,5 @@ return [
'freight_calculation_method' => '运费计算方式',
'logistics_duration' => '发货后:day个工作日内交货',
'unit' => '单位::unit',
'default_countries' => '前台默认展示国家',
];

View File

@ -159,6 +159,10 @@
default: {},
type: [Object,Array]
},
is_single: {
default: false,
type: Boolean
}
},
data: function () {
return {
@ -213,7 +217,9 @@
// 点击当前国家
clickCountries(item){
let _this = this;
let countryIds = Object.assign({}, _this.country_list);
// 判断:单选 || 多选
let countryIds = {};// 单选
if(!_this.is_single) countryIds = Object.assign({}, _this.country_list);// 多选
// 判断:根据是否已经存在进行对应的存在 不存在-添加;存在-删除
if(_this.isSelected(item)) delete countryIds[item.id];// 存在-删除
else countryIds[item.id] = item;// 不存在 添加