后台优化
This commit is contained in:
@@ -27,6 +27,9 @@ class Vehicle extends Model
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
//批量赋值黑名单
|
||||
protected $guarded = ['created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Get the location that owns the vehicle.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,12 @@ class LocationController extends Crud
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var string[]
|
||||
*/
|
||||
protected $noNeedAuth = ['getAll'];
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @return void
|
||||
@@ -241,6 +247,11 @@ class LocationController extends Crud
|
||||
]);
|
||||
}
|
||||
|
||||
// public function updateLogistics(Request $request): Response
|
||||
// {
|
||||
// return $this->update($request);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取下拉选项接口
|
||||
*/
|
||||
|
||||
@@ -145,6 +145,10 @@ class RuleController extends Crud
|
||||
$permissions[] = $code;
|
||||
}
|
||||
// $permissions = ["app.admin.vehicle.select","app.admin.vehicle.detail"];
|
||||
// $permissions[] = "app.admin.vehicle.select";
|
||||
// $permissions[] = "app.admin.vehicle.detail";
|
||||
// $permissions[] = "app.admin.vehicle.logistics";
|
||||
// $permissions[] = "app.admin.vehicle.updateLogistics";
|
||||
return $this->json(0, 'ok', $permissions);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class VehicleController extends Crud
|
||||
* 不需要鉴权的方法
|
||||
* @var string[]
|
||||
*/
|
||||
protected $noNeedAuth = ['detail', 'status'];
|
||||
protected $noNeedAuth = ['detail', 'status', 'updateLogistics'];
|
||||
|
||||
protected $status = [
|
||||
'zh-cn' => ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出'],
|
||||
@@ -125,6 +125,66 @@ class VehicleController extends Crud
|
||||
'translations' => $translations
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 浏览
|
||||
* @return Response
|
||||
*/
|
||||
public function logistics(): Response
|
||||
{
|
||||
$lang = session('lang', 'zh-cn');
|
||||
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
|
||||
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
|
||||
$translations = array_merge($common, $translations); // 确保 common.php 的翻译优先
|
||||
|
||||
// 添加默认翻译,确保所有语言都有基本翻译
|
||||
$required_translations = [
|
||||
'title' => $lang === 'zh-cn' ? '车辆管理' : 'Vehicle Management', // 确保title翻译存在
|
||||
'brand' => $lang === 'zh-cn' ? '车辆品牌' : 'Vehicle Brand',
|
||||
'brand_placeholder' => $lang === 'zh-cn' ? '请输入车辆品牌' : 'Please enter vehicle brand',
|
||||
'model' => $lang === 'zh-cn' ? '车辆型号' : 'Vehicle Model',
|
||||
'model_placeholder' => $lang === 'zh-cn' ? '请输入车辆型号' : 'Please enter vehicle model',
|
||||
'vin' => 'VIN',
|
||||
'vin_placeholder' => $lang === 'zh-cn' ? '请输入车架号' : 'Please enter VIN',
|
||||
'status' => $lang === 'zh-cn' ? '车辆状态' : 'Status',
|
||||
'status_placeholder' => $lang === 'zh-cn' ? '请选择状态' : 'Please select status',
|
||||
'purchase_location' => $lang === 'zh-cn' ? '买车地点' : 'Purchase Location',
|
||||
'purchase_location_placeholder' => $lang === 'zh-cn' ? '请输入买车地点' : 'Please enter purchase location',
|
||||
'procedure_location' => $lang === 'zh-cn' ? '手续办理地' : 'Procedure Location',
|
||||
'procedure_location_placeholder' => $lang === 'zh-cn' ? '请输入手续办理地' : 'Please enter procedure location',
|
||||
'fbo_location' => 'FBO Location',
|
||||
'fbo_location_placeholder' => $lang === 'zh-cn' ? '请选择FBO目的地' : 'Please select FBO location',
|
||||
'current_location' => $lang === 'zh-cn' ? '车辆所在地' : 'Current Location',
|
||||
'current_location_placeholder' => $lang === 'zh-cn' ? '请选择车辆所在地' : 'Please select current location',
|
||||
'final_location' => $lang === 'zh-cn' ? '最终目的地' : 'Final Location',
|
||||
'final_location_placeholder' => $lang === 'zh-cn' ? '请选择最终目的地' : 'Please select final location',
|
||||
'departure_time' => $lang === 'zh-cn' ? 'FBO发车时间' : 'FBO Departure Time',
|
||||
'departure_time_placeholder' => $lang === 'zh-cn' ? '请选择发车时间' : 'Please select departure time',
|
||||
'arrival_time' => $lang === 'zh-cn' ? 'FBO到达时间' : 'FBO Arrival Time',
|
||||
'arrival_time_placeholder' => $lang === 'zh-cn' ? '请选择到达时间' : 'Please select arrival time',
|
||||
'shipping_cycle' => $lang === 'zh-cn' ? '运输周期' : 'Shipping Cycle',
|
||||
'shipping_cycle_placeholder' => $lang === 'zh-cn' ? '请输入运输周期' : 'Please enter shipping cycle',
|
||||
'img_url' => $lang === 'zh-cn' ? '图片' : 'Image',
|
||||
'img_url_placeholder' => $lang === 'zh-cn' ? '请输入图片URL' : 'Please enter image URL',
|
||||
'operation' => $lang === 'zh-cn' ? '操作' : 'Operation',
|
||||
'refresh' => $lang === 'zh-cn' ? '刷新' : 'Refresh',
|
||||
'filter' => $lang === 'zh-cn' ? '筛选' : 'Filter',
|
||||
'print' => $lang === 'zh-cn' ? '打印' : 'Print',
|
||||
'export' => $lang === 'zh-cn' ? '导出' : 'Export',
|
||||
'id' => 'ID',
|
||||
'created_at' => $lang === 'zh-cn' ? '创建时间' : 'Created At',
|
||||
'updated_at' => $lang === 'zh-cn' ? '更新时间' : 'Updated At'
|
||||
];
|
||||
|
||||
// 合并翻译,确保语言文件中的翻译优先
|
||||
$translations = array_merge($required_translations, $translations);
|
||||
|
||||
|
||||
|
||||
return view('vehicle/logistics', [
|
||||
'lang' => $lang,
|
||||
'translations' => $translations
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入
|
||||
@@ -314,6 +374,69 @@ class VehicleController extends Crud
|
||||
'lang' => $lang,
|
||||
'translations' => $translations
|
||||
]);
|
||||
} /**
|
||||
* 更新
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function updateLogistics(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id');
|
||||
$lang = session('lang', 'zh-cn');
|
||||
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
|
||||
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
|
||||
$translations = array_merge($translations, $common);
|
||||
|
||||
// 只在中文时使用默认翻译
|
||||
if ($lang === 'zh-cn') {
|
||||
$required_translations = [
|
||||
'brand' => '车辆品牌',
|
||||
'brand_placeholder' => '请输入车辆品牌',
|
||||
'model' => '车辆型号',
|
||||
'model_placeholder' => '请输入车辆型号',
|
||||
'vin' => '车架号',
|
||||
'vin_placeholder' => '请输入车架号',
|
||||
'status' => '车辆状态',
|
||||
'status_placeholder' => '请选择状态',
|
||||
'purchase_location' => '买车地点',
|
||||
'purchase_location_placeholder' => '请输入买车地点',
|
||||
'procedure_location' => '手续办理地',
|
||||
'procedure_location_placeholder' => '请输入手续办理地',
|
||||
'fbo_location' => 'FBO目的地',
|
||||
'fbo_location_placeholder' => '请选择FBO目的地',
|
||||
'current_location' => '车辆所在地',
|
||||
'current_location_placeholder' => '请选择车辆所在地',
|
||||
'final_location' => '最终目的地',
|
||||
'final_location_placeholder' => '请选择最终目的地',
|
||||
'departure_time' => 'FBO发车时间',
|
||||
'departure_time_placeholder' => '请选择发车时间',
|
||||
'arrival_time' => 'FBO到达时间',
|
||||
'arrival_time_placeholder' => '请选择到达时间',
|
||||
'shipping_cycle' => '运输周期',
|
||||
'shipping_cycle_placeholder' => '请输入运输周期',
|
||||
'img_url' => '图片',
|
||||
'img_url_placeholder' => '请输入图片URL'
|
||||
];
|
||||
$translations = array_merge($required_translations, $translations);
|
||||
}
|
||||
|
||||
// 如果是 POST 请求,处理数据保存和翻译
|
||||
if ($request->method() === 'POST') {
|
||||
$this->save($request);
|
||||
}
|
||||
|
||||
$data = Vehicle::where('id', $id)->first();
|
||||
if (!$data) {
|
||||
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
|
||||
}
|
||||
|
||||
return view('vehicle/updateLogistics', [
|
||||
'id' => $id,
|
||||
'data' => $data,
|
||||
'lang' => $lang,
|
||||
'translations' => $translations
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.vehicle.update"><?= $translations['edit'] ?? '编辑' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.vehicle.delete"><?= $translations['delete'] ?? '删除' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="detail" permission="app.admin.vehicle.detail"><?= $translations['detail'] ?? '详情' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="updateLogistics" permission="app.admin.vehicle.updatelogistics"><?= $translations['updateLogistics'] ?? '物流修改' ?></button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js"></script>
|
||||
@@ -56,7 +57,8 @@
|
||||
const INSERT_URL = "/app/admin/vehicle/insert";
|
||||
const UPDATE_URL = "/app/admin/vehicle/update";
|
||||
const DETAIL_URL = "/app/admin/vehicle/detail";
|
||||
|
||||
const LOGISTICS_URL = "/app/admin/vehicle/updateLogistics";
|
||||
|
||||
// 翻译文本
|
||||
const translations = <?= json_encode($translations) ?>;
|
||||
|
||||
@@ -176,6 +178,8 @@
|
||||
edit(obj);
|
||||
} else if (obj.event === "detail") {
|
||||
detail(obj);
|
||||
} else if (obj.event === "updateLogistics") {
|
||||
updateLogistics(obj);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -325,6 +329,19 @@
|
||||
content: DETAIL_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
|
||||
// 查看数据
|
||||
let updateLogistics = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.edit,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: LOGISTICS_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= $lang ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?= $translations['title'] ?? '车辆管理' ?></title>
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
<?php if ($lang === 'ar'): ?>
|
||||
<style>
|
||||
body {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
.layui-table-cell {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<!-- 数据表格 -->
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table id="data-table" lay-filter="data-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<script type="text/html" id="table-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.vehicle.insert">
|
||||
<i class="layui-icon layui-icon-add-1"></i><?= $translations['add'] ?? '新增' ?>
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.vehicle.delete">
|
||||
<i class="layui-icon layui-icon-delete"></i><?= $translations['delete'] ?? '删除' ?>
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.vehicle.update"><?= $translations['edit'] ?? '编辑' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.vehicle.delete"><?= $translations['delete'] ?? '删除' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="detail" permission="app.admin.vehicle.detail"><?= $translations['detail'] ?? '详情' ?></button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="updateLogistics" permission="app.admin.vehicle.updateLogistics"><?= $translations['updateLogistics'] ?? '物流修改' ?></button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script src="/app/admin/admin/js/permission.js"></script>
|
||||
<script src="/app/admin/admin/js/common.js"></script>
|
||||
|
||||
<script>
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
const SELECT_API = "/app/admin/vehicle/select";
|
||||
const UPDATE_API = "/app/admin/vehicle/update";
|
||||
const DELETE_API = "/app/admin/vehicle/delete";
|
||||
const INSERT_URL = "/app/admin/vehicle/insert";
|
||||
const UPDATE_URL = "/app/admin/vehicle/update";
|
||||
const DETAIL_URL = "/app/admin/vehicle/detail";
|
||||
const LOGISTICS_URL = "/app/admin/vehicle/updateLogistics";
|
||||
|
||||
// 翻译文本
|
||||
const translations = <?= json_encode($translations) ?>;
|
||||
|
||||
// 初始化layui
|
||||
layui.use(["table", "form", "common", "popup", "util"], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.$;
|
||||
let common = layui.common;
|
||||
let util = layui.util;
|
||||
|
||||
console.log('Layui initialized');
|
||||
|
||||
// 监听语言更新消息
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.data && event.data.type === 'language_changed') {
|
||||
// 重新获取翻译
|
||||
$.get('/app/admin/vehicle/getTranslations', function(translations) {
|
||||
// 更新标签页标题
|
||||
if (window.parent && window.parent.layui) {
|
||||
window.parent.layui.use(['tab'], function() {
|
||||
let tab = window.parent.layui.tab;
|
||||
if (tab && typeof tab.changeTitle === 'function') {
|
||||
let currentTab = window.parent.document.querySelector('.layui-tab-title .layui-this');
|
||||
if (currentTab) {
|
||||
tab.changeTitle(currentTab.getAttribute('lay-id'), translations.title);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// 重新加载表格
|
||||
table.reload('data-table');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 表头参数
|
||||
let cols = [[
|
||||
{type: "checkbox", align: "center"},
|
||||
{title: translations.id, align: "center", field: "id"},
|
||||
{title: translations.vin, align: "center", field: "vin"},
|
||||
{title: translations.status, align: "center", field: "status_txt"},
|
||||
{title: translations.current_location, align: "center", field: "location_name"},
|
||||
{title: translations.final_location, align: "center", field: "final_location_name"},
|
||||
{title: translations.fbo_location, align: "center", field: "fbo_location_name"},
|
||||
{title: translations.created_at, align: "center", field: "created_at"},
|
||||
{title: translations.updated_at, align: "center", field: "updated_at"},
|
||||
{title: translations.operation, toolbar: "#table-bar", align: "center", fixed: "right", width: 150}
|
||||
]];
|
||||
|
||||
// 渲染表格
|
||||
table.render({
|
||||
elem: "#data-table",
|
||||
url: SELECT_API,
|
||||
page: {
|
||||
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
|
||||
groups: 5,
|
||||
theme: '#FF5722',
|
||||
text: {
|
||||
count: translations.pagination_total,
|
||||
limit: translations.pagination_limit,
|
||||
page: translations.pagination_page,
|
||||
prev: translations.pagination_prev,
|
||||
next: translations.pagination_next,
|
||||
jump: translations.pagination_jump,
|
||||
go: translations.pagination_go
|
||||
}
|
||||
},
|
||||
cols: cols,
|
||||
skin: "line",
|
||||
size: "lg",
|
||||
toolbar: "#table-toolbar",
|
||||
autoSort: false,
|
||||
defaultToolbar: [{
|
||||
title: translations.refresh,
|
||||
layEvent: "refresh",
|
||||
icon: "layui-icon-refresh",
|
||||
}, translations.filter, translations.print, translations.export],
|
||||
text: {
|
||||
none: translations.data_not_found
|
||||
},
|
||||
done: function () {
|
||||
// 更新分页文本
|
||||
$('.layui-laypage a').each(function() {
|
||||
let text = $(this).text();
|
||||
if (text === '上一页') {
|
||||
$(this).text(translations.pagination_prev);
|
||||
} else if (text === '下一页') {
|
||||
$(this).text(translations.pagination_next);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新分页信息
|
||||
let pageInfo = $('.layui-laypage-count').text();
|
||||
let total = pageInfo.match(/\d+/)[0];
|
||||
$('.layui-laypage-count').text(translations.pagination_total.replace('{total}', total));
|
||||
|
||||
// 更新每页条数
|
||||
$('.layui-laypage-limits option').each(function() {
|
||||
let value = $(this).val();
|
||||
$(this).text(translations.pagination_limit.replace('{limit}', value));
|
||||
});
|
||||
|
||||
// 更新跳转文本
|
||||
$('.layui-laypage-skip').prev().text(translations.pagination_jump);
|
||||
$('.layui-laypage-btn').text(translations.pagination_go);
|
||||
|
||||
layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
|
||||
}
|
||||
});
|
||||
|
||||
// 编辑或删除行事件
|
||||
table.on("tool(data-table)", function(obj) {
|
||||
if (obj.event === "remove") {
|
||||
remove(obj);
|
||||
} else if (obj.event === "edit") {
|
||||
edit(obj);
|
||||
} else if (obj.event === "detail") {
|
||||
detail(obj);
|
||||
} else if (obj.event === "updateLogistics") {
|
||||
updateLogistics(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// 表格顶部工具栏事件
|
||||
table.on("toolbar(data-table)", function(obj) {
|
||||
if (obj.event === "add") {
|
||||
add();
|
||||
} else if (obj.event === "refresh") {
|
||||
refreshTable();
|
||||
} else if (obj.event === "batchRemove") {
|
||||
batchRemove(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// 表格顶部搜索事件
|
||||
form.on("submit(table-query)", function(data) {
|
||||
table.reload("data-table", {
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: data.field
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
// 表格顶部搜索重置事件
|
||||
form.on("submit(table-reset)", function(data) {
|
||||
table.reload("data-table", {
|
||||
where: []
|
||||
})
|
||||
});
|
||||
|
||||
// 字段允许为空
|
||||
form.verify({
|
||||
phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
|
||||
email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
|
||||
url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
|
||||
number: [/(^$)|^\d+$/,'只能填写数字'],
|
||||
date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
|
||||
identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
|
||||
});
|
||||
|
||||
// 表格排序事件
|
||||
table.on("sort(data-table)", function(obj){
|
||||
table.reload("data-table", {
|
||||
initSort: obj,
|
||||
scrollPos: "fixed",
|
||||
where: {
|
||||
field: obj.field,
|
||||
order: obj.type
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 表格新增数据
|
||||
let add = function() {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.add,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: INSERT_URL
|
||||
});
|
||||
}
|
||||
|
||||
// 表格编辑数据
|
||||
let edit = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.edit,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
|
||||
// 删除一行
|
||||
let remove = function(obj) {
|
||||
return doRemove(obj.data[PRIMARY_KEY]);
|
||||
}
|
||||
|
||||
// 删除多行
|
||||
let batchRemove = function(obj) {
|
||||
let checkIds = common.checkField(obj, PRIMARY_KEY);
|
||||
if (checkIds === "") {
|
||||
layui.popup.warning(translations.no_data_selected);
|
||||
return false;
|
||||
}
|
||||
doRemove(checkIds.split(","));
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
let doRemove = function (ids) {
|
||||
let data = {};
|
||||
data[PRIMARY_KEY] = ids;
|
||||
layer.confirm(translations.confirm_delete, {
|
||||
icon: 3,
|
||||
title: translations.title
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: DELETE_API,
|
||||
data: data,
|
||||
dataType: "json",
|
||||
type: "post",
|
||||
success: function(res) {
|
||||
layer.close(loading);
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success(translations.operation_success, refreshTable);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新表格数据
|
||||
window.refreshTable = function() {
|
||||
table.reloadData("data-table", {
|
||||
scrollPos: "fixed",
|
||||
done: function (res, curr) {
|
||||
if (curr > 1 && res.data && !res.data.length) {
|
||||
curr = curr - 1;
|
||||
table.reloadData("data-table", {
|
||||
page: {
|
||||
curr: curr
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 查看数据
|
||||
let detail = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.detail,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: DETAIL_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
|
||||
// 查看数据
|
||||
let updateLogistics = function(obj) {
|
||||
let value = obj.data[PRIMARY_KEY];
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: translations.edit,
|
||||
shade: 0.1,
|
||||
maxmin: true,
|
||||
area: [common.isModile()?"100%":"800px", common.isModile()?"100%":"600px"],
|
||||
content: LOGISTICS_URL + "?" + PRIMARY_KEY + "=" + value
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,350 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>更新页面</title>
|
||||
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
|
||||
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
||||
<style>
|
||||
.readonly-input {
|
||||
background-color: #f5f5f5 !important;
|
||||
color: #999 !important;
|
||||
cursor: not-allowed !important;
|
||||
border-color: #e6e6e6 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form class="layui-form">
|
||||
|
||||
<div class="mainBox">
|
||||
<div class="main-container mr-5">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['vin'] ?? '车架号(17位国际标准)' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="vin" readonly value="" required lay-verify="required" class="layui-input readonly-input" placeholder="<?= $translations['vin_placeholder'] ?? '请输入车架号' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['classify'] ?? '分类' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<select name="classify" lay-filter="category" readonly id="classify" required class="readonly-input">
|
||||
<option value=""><?= $translations['classify_placeholder'] ?? '请选择分类' ?></option>
|
||||
<option value="1"><?= $translations['self_owned'] ?? '自主' ?></option>
|
||||
<option value="2"><?= $translations['agent'] ?? '代理' ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['brand'] ?? '车辆品牌' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="brand" value="" readonly required lay-verify="required" class="layui-input readonly-input" placeholder="<?= $translations['brand_placeholder'] ?? '请输入车辆品牌' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['model'] ?? '车辆型号' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="model" value="" readonly required lay-verify="required" class="layui-input readonly-input" placeholder="<?= $translations['model_placeholder'] ?? '请输入车辆型号' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['status'] ?? '状态' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<select name="status" lay-filter="category" required lay-verify="required" id="status" required>
|
||||
<option value=""><?= $translations['please_select'] ?? '请选择状态' ?></option>
|
||||
<!-- <option value="1"><?= $translations['status_pending'] ?? '待发车' ?></option>-->
|
||||
<!-- <option value="2"><?= $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)' ?></option>-->
|
||||
<!-- <option value="3"><?= $translations['status_arrived_fbo'] ?? '抵达发货港口' ?></option>-->
|
||||
<!-- <option value="4"><?= $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)' ?></option>-->
|
||||
<!-- <option value="5"><?= $translations['status_arrived_warehouse'] ?? '抵达目的地' ?></option>-->
|
||||
<!-- <option value="6"><?= $translations['status_sold'] ?? '售出' ?></option>-->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['purchase_location'] ?? '买车地点' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="purchase_location" readonly value="" class="layui-input readonly-input" placeholder="<?= $translations['purchase_location_placeholder'] ?? '请输入买车地点' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['procedure_location'] ?? '手续办理地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="procedure_location" readonly value="" class="layui-input readonly-input" placeholder="<?= $translations['procedure_location_placeholder'] ?? '请输入手续办理地' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['fbo_location'] ?? 'fbo目的地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<select name="fbo_locations_id" lay-filter="category" id="fbo_locations_id" required>
|
||||
<option value=""><?= $translations['please_select'] ?? '请选择分类' ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['current_location'] ?? '车辆所在地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<select name="locations_id" lay-filter="category" id="locations_id" required>
|
||||
<option value=""><?= $translations['please_select'] ?? '请选择分类' ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['final_location'] ?? '最终目的地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<select name="final_locations_id" lay-filter="category" required lay-verify="required" id="final_locations_id" required>
|
||||
<option value=""><?= $translations['please_select'] ?? '请选择分类' ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['departure_time'] ?? 'FBO发车时间' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="departure_time" id="departure_time" value="" class="layui-input" placeholder="<?= $translations['departure_time_placeholder'] ?? '请选择发车时间' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['arrival_time'] ?? 'FBO到达时间' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="arrival_time" id="arrival_time" value="" class="layui-input" placeholder="<?= $translations['arrival_time_placeholder'] ?? '请选择到达时间' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['shipping_cycle'] ?? '运输周期(天)' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="shipping_cycle" value="" class="layui-input" placeholder="<?= $translations['shipping_cycle_placeholder'] ?? '请输入运输周期' ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required"><?= $translations['img_url'] ?? '图片' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<img class="img-3" src=""/>
|
||||
<input type="text" style="display:none" name="img_url" value="" />
|
||||
<button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="img_url">
|
||||
<i class="layui-icon layui-icon-upload"></i><?= $translations['upload_image'] ?? '上传图片' ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bottom">
|
||||
<div class="button-container">
|
||||
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="save">
|
||||
提交
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md">
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
|
||||
<script src="/app/admin/admin/js/permission.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
// 相关接口
|
||||
const PRIMARY_KEY = "id";
|
||||
const SELECT_API = "/app/admin/vehicle/select" + location.search;
|
||||
const UPDATE_API = "/app/admin/vehicle/updateLogistics";
|
||||
|
||||
// 加载选项数据
|
||||
function loadOptions($, form, layer, callback) {
|
||||
$.ajax({
|
||||
url: '/app/admin/location/getAll',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.code !== 0) {
|
||||
layer.msg(res.msg || '加载失败');
|
||||
return;
|
||||
}
|
||||
|
||||
const select = $('#fbo_locations_id');
|
||||
const locations_id = $('#locations_id');
|
||||
const final_locations_id = $('#final_locations_id');
|
||||
select.empty().append('<option value="">请选择分类</option>');
|
||||
locations_id.empty().append('<option value="">请选择分类</option>');
|
||||
final_locations_id.empty().append('<option value="">请选择分类</option>');
|
||||
|
||||
$.each(res.data, function(index, item){
|
||||
select.append(`<option value="${item.id}">${item.name}</option>`);
|
||||
locations_id.append(`<option value="${item.id}">${item.name}</option>`);
|
||||
final_locations_id.append(`<option value="${item.id}">${item.name}</option>`);
|
||||
});
|
||||
|
||||
// 重新渲染下拉框
|
||||
form.render('select');
|
||||
|
||||
// 如果有回调函数,执行回调
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
layer.msg('请求失败: ' + xhr.status);
|
||||
}
|
||||
});
|
||||
|
||||
//车辆状态
|
||||
$.ajax({
|
||||
url: '/app/admin/vehicle/status',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.code !== 0) {
|
||||
layer.msg(res.msg || '加载失败');
|
||||
return;
|
||||
}
|
||||
|
||||
const select = $('#status');
|
||||
// select.empty().append('<option value="">请选择状态</option>');
|
||||
|
||||
$.each(res.data, function(index, item){
|
||||
if(index != 0){
|
||||
select.append(`<option value="${index}">${item}</option>`);
|
||||
}
|
||||
});
|
||||
|
||||
// 重新渲染下拉框
|
||||
form.render('select');
|
||||
},
|
||||
error: function(xhr) {
|
||||
layer.msg('请求失败: ' + xhr.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取数据库记录
|
||||
layui.use(["form", "util", "popup", "jquery", "layer"], function () {
|
||||
let $ = layui.$;
|
||||
let form = layui.form;
|
||||
let layer = layui.layer;
|
||||
|
||||
// 先加载选项数据,然后在回调中加载记录数据
|
||||
loadOptions($, form, layer, function() {
|
||||
$.ajax({
|
||||
url: SELECT_API,
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
|
||||
// 给表单初始化数据
|
||||
let data = res.data[0];
|
||||
console.log('加载的数据:', data); // 调试用
|
||||
|
||||
// 遍历所有表单字段
|
||||
$('form .layui-form-item').each(function() {
|
||||
let input = $(this).find('input:not([type="file"]), select, textarea');
|
||||
if (input.length === 0) return;
|
||||
|
||||
let name = input.attr('name');
|
||||
if (!name || !data[name]) return;
|
||||
|
||||
console.log('设置字段:', name, data[name]); // 调试用
|
||||
|
||||
// 设置字段值
|
||||
if (input.is('select')) {
|
||||
input.val(data[name]);
|
||||
console.log('设置下拉框值:', name, data[name], input.val()); // 调试用
|
||||
} else if (input.is('textarea')) {
|
||||
input.val(data[name]);
|
||||
} else {
|
||||
input.val(data[name]);
|
||||
}
|
||||
|
||||
// 处理图片显示
|
||||
if (name === 'img_url' && data[name]) {
|
||||
$('.img-3').attr('src', data[name]);
|
||||
}
|
||||
});
|
||||
|
||||
// 重新渲染表单
|
||||
form.render();
|
||||
|
||||
// 再次检查下拉框的值
|
||||
console.log('fbo_locations_id:', $('#fbo_locations_id').val());
|
||||
console.log('locations_id:', $('#locations_id').val());
|
||||
console.log('final_locations_id:', $('#final_locations_id').val());
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//提交事件
|
||||
layui.use(["form", "popup"], function () {
|
||||
// 字段验证允许为空
|
||||
layui.form.verify({
|
||||
phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
|
||||
email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
|
||||
url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
|
||||
number: [/(^$)|^\d+$/,'只能填写数字'],
|
||||
date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
|
||||
identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
|
||||
});
|
||||
layui.form.on("submit(save)", function (data) {
|
||||
data.field[PRIMARY_KEY] = layui.url().search[PRIMARY_KEY];
|
||||
layui.$.ajax({
|
||||
url: UPDATE_API,
|
||||
type: "POST",
|
||||
dateType: "json",
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success("操作成功", function () {
|
||||
parent.refreshTable();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
// 图片上传
|
||||
layui.use(["upload", "layer"], function() {
|
||||
let input = layui.$("#img_url").prev();
|
||||
input.prev().attr("src", input.val());
|
||||
layui.upload.render({
|
||||
elem: "#img_url",
|
||||
url: "/app/admin/upload/uploadImage",
|
||||
acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
|
||||
field: "__file__",
|
||||
done: function (res) {
|
||||
if (res.code > 0) return layui.layer.msg(res.msg);
|
||||
this.item.prev().val(res.data.path).prev().attr("src", res.data.image_url);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user