226 lines
11 KiB
Plaintext
226 lines
11 KiB
Plaintext
@model HHWMS.Web.AgvTaskListVM
|
||
@inject IStringLocalizer<Program> Localizer;
|
||
|
||
@* AGV 平库任务列表:原生 HTML 表格渲染,完全避开 WTM grid / layui table 渲染链路的异常问题
|
||
查询、分页、行内 下发/取消/重试完成 均由本页 JS 直调后端接口实现 *@
|
||
<div style="padding:10px;">
|
||
<!-- 查询区 -->
|
||
<div style="background:#fff; border-radius:4px; padding:12px 12px 2px; margin-bottom:10px; box-shadow:0 1px 2px rgba(0,0,0,.06);">
|
||
<div style="display:flex; flex-wrap:wrap; gap:8px 18px; align-items:center;">
|
||
<div><label style="margin-right:4px;">任务号</label><input id="q_taskNo" placeholder="模糊查询" class="agv-q-input" /></div>
|
||
<div><label style="margin-right:4px;">起点</label><input id="q_from" placeholder="模糊查询" class="agv-q-input" /></div>
|
||
<div><label style="margin-right:4px;">终点</label><input id="q_to" placeholder="模糊查询" class="agv-q-input" /></div>
|
||
<div><label style="margin-right:4px;">容器号</label><input id="q_container" placeholder="模糊查询" class="agv-q-input" /></div>
|
||
<div><label style="margin-right:4px;">来源系统</label><select id="q_source" class="agv-q-input"><option value="">全部</option></select></div>
|
||
<div><label style="margin-right:4px;">状态</label><select id="q_status" class="agv-q-input"><option value="">全部</option></select></div>
|
||
<div style="margin-bottom:10px;">
|
||
<button type="button" class="layui-btn layui-btn-sm" onclick="agvSearch(1)"><i class="layui-icon"></i> 查询</button>
|
||
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="agvReset()">重置</button>
|
||
<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" style="margin-left:10px;" onclick="agvOpenCreate()"><i class="layui-icon"></i> 下发任务</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 数据表格(原生 table,行内操作由 JS 直接生成,显示稳定可控) -->
|
||
<table class="layui-table" style="margin:0;">
|
||
<thead>
|
||
<tr>
|
||
<th style="width:170px;">任务号</th>
|
||
<th style="width:110px;">任务场景</th>
|
||
<th style="width:90px;">状态</th>
|
||
<th style="width:110px;">起点</th>
|
||
<th style="width:110px;">终点</th>
|
||
<th style="width:150px;">容器号</th>
|
||
<th style="width:90px;">来源系统</th>
|
||
<th style="width:180px;">错误信息</th>
|
||
<th style="width:150px;">创建时间</th>
|
||
<th style="width:120px;">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="agvTbody"><tr><td colspan="10" style="text-align:center; color:#999;">加载中...</td></tr></tbody>
|
||
</table>
|
||
|
||
<!-- 分页 -->
|
||
<div style="display:flex; justify-content:flex-end; align-items:center; gap:10px; padding:10px 2px; color:#666;">
|
||
<span id="agvTotal">共 0 条</span>
|
||
<span>每页</span>
|
||
<select id="q_size" style="height:26px; padding:0 4px; border:1px solid #e5e6eb; border-radius:4px; outline:none;" onchange="agvSizeChange()">
|
||
<option value="10" selected>10 条</option>
|
||
<option value="20">20 条</option>
|
||
<option value="50">50 条</option>
|
||
<option value="100">100 条</option>
|
||
</select>
|
||
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary" onclick="agvPageTurn(-1)">上一页</button>
|
||
<span id="agvPageNo">第 1 页</span>
|
||
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary" onclick="agvPageTurn(1)">下一页</button>
|
||
</div>
|
||
</div>
|
||
|
||
<style>
|
||
.agv-q-input {
|
||
height: 30px;
|
||
padding: 0 8px;
|
||
border: 1px solid #e5e6eb;
|
||
border-radius: 4px;
|
||
outline: none;
|
||
font-size: 13px;
|
||
width: 130px;
|
||
box-sizing: border-box;
|
||
}
|
||
.agv-q-input:focus { border-color: #16b777; }
|
||
/* 操作列文字链接:纯文字可点击,间隔 5px */
|
||
#agvTbody a { color: #01AAED; margin-right: 5px; }
|
||
#agvTbody td { font-size: 13px; }
|
||
</style>
|
||
|
||
<script>
|
||
// 状态映射(与 AgvTaskStatusEnum 一致:成员名即中文)
|
||
var agvStatusMap = { 0: "新建", 5: "已下发", 10: "执行中", 90: "异常", 95: "取消", 99: "完成联动失败", 100: "完成" };
|
||
var agvPage = 1, agvSize = 10, agvTotal = 0;
|
||
|
||
// HTML 转义,防止数据中的特殊字符破坏表格结构
|
||
function agvEsc(v) {
|
||
return v == null ? "" : String(v).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||
}
|
||
|
||
// 加载任务列表(多条件 + 分页)
|
||
function loadTasks() {
|
||
var body = {
|
||
TaskNo: $("#q_taskNo").val(), FromLocation: $("#q_from").val(), ToLocation: $("#q_to").val(),
|
||
ContainerCode: $("#q_container").val(), SourceSystem: $("#q_source").val(),
|
||
AgvStatus: $("#q_status").val() === "" ? null : parseInt($("#q_status").val()),
|
||
Page: agvPage, Size: agvSize
|
||
};
|
||
$.ajax({
|
||
type: "post", url: "/agv/AgvTask/GetTasks", dataType: "json",
|
||
contentType: "application/json", data: JSON.stringify(body),
|
||
success: function (json) {
|
||
var data = json.Data || {};
|
||
agvTotal = data.Total || 0;
|
||
var list = data.List || [];
|
||
if (list.length === 0) {
|
||
$("#agvTbody").html('<tr><td colspan="10" style="text-align:center; color:#999;">暂无数据</td></tr>');
|
||
} else {
|
||
var rows = "";
|
||
for (var i = 0; i < list.length; i++) {
|
||
var t = list[i];
|
||
rows += "<tr>"
|
||
+ "<td>" + agvEsc(t.TaskNo) + "</td>"
|
||
+ "<td>" + agvEsc(t.SceneName) + "</td>"
|
||
+ "<td>" + agvEsc(t.AgvStatusName || agvStatusMap[t.AgvStatus] || "-") + "</td>"
|
||
+ "<td>" + agvEsc(t.FromLocation) + "</td>"
|
||
+ "<td>" + agvEsc(t.ToLocation) + "</td>"
|
||
+ "<td>" + agvEsc(t.ContainerCode) + "</td>"
|
||
+ "<td>" + agvEsc(t.SourceSystem) + "</td>"
|
||
+ "<td>" + agvEsc(t.ErrorMsg) + "</td>"
|
||
+ "<td>" + agvEsc((t.CreateTime || "").replace("T", " ").substring(0, 19)) + "</td>"
|
||
+ "<td>" + agvOps(t.AgvStatus, t.TaskNo) + "</td>"
|
||
+ "</tr>";
|
||
}
|
||
$("#agvTbody").html(rows);
|
||
}
|
||
$("#agvTotal").text("共 " + agvTotal + " 条");
|
||
var maxPage = Math.max(1, Math.ceil(agvTotal / agvSize));
|
||
$("#agvPageNo").text("第 " + agvPage + " / " + maxPage + " 页");
|
||
},
|
||
error: function () {
|
||
$("#agvTbody").html('<tr><td colspan="10" style="text-align:center; color:#999;">请求失败,请检查服务是否正常</td></tr>');
|
||
}
|
||
});
|
||
}
|
||
|
||
// 行内操作链接:新建/异常→下发;新建/已下发/执行中→取消;完成联动失败→重试完成
|
||
function agvOps(st, taskNo) {
|
||
var html = "";
|
||
if (st == 0 || st == 90) {
|
||
html += "<a href='javascript:void(0)' onclick=\"agvDispatch('" + agvEsc(taskNo) + "')\">下发</a>";
|
||
}
|
||
if (st == 0 || st == 5 || st == 10) {
|
||
html += "<a href='javascript:void(0)' onclick=\"agvCancel('" + agvEsc(taskNo) + "')\">取消</a>";
|
||
}
|
||
if (st == 99) {
|
||
html += "<a href='javascript:void(0)' onclick=\"agvRetryFinish('" + agvEsc(taskNo) + "')\">重试完成</a>";
|
||
}
|
||
return html == "" ? "-" : html;
|
||
}
|
||
|
||
// 通用行操作:确认后 POST 指定接口,成功后刷新列表
|
||
function agvPost(url, taskNo, confirmText, successMsg) {
|
||
layer.confirm(confirmText + " [" + taskNo + "]?", { icon: 3, title: "提示" }, function (index) {
|
||
layer.close(index);
|
||
$.ajax({
|
||
type: "post", dataType: "json", contentType: "application/json",
|
||
data: JSON.stringify({ TaskNo: taskNo }), url: url,
|
||
success: function (json) {
|
||
if (json.Code == 200) {
|
||
layer.msg(json.Msg || successMsg);
|
||
loadTasks();
|
||
} else {
|
||
layer.alert(json.Msg || "操作失败");
|
||
}
|
||
},
|
||
error: function () { layer.alert("请求失败,请检查服务是否正常"); }
|
||
});
|
||
});
|
||
}
|
||
|
||
// 下发(仅新建/异常行显示,后端仍做状态校验兜底)
|
||
function agvDispatch(taskNo) { agvPost("/agv/AgvTask/Dispatch", taskNo, "确定下发任务", "下发成功"); }
|
||
// 取消(仅新建/已下发/执行中行显示)
|
||
function agvCancel(taskNo) { agvPost("/agv/AgvTask/Cancel", taskNo, "确定取消任务", "取消成功"); }
|
||
// 重试完成联动(仅完成联动失败行显示)
|
||
function agvRetryFinish(taskNo) { agvPost("/agv/AgvTask/RetryFinish", taskNo, "确定重试完成联动", "重试成功"); }
|
||
|
||
// 查询(重置回第 1 页)
|
||
function agvSearch(page) { agvPage = page || 1; loadTasks(); }
|
||
// 切换每页条数:回到第 1 页重新加载
|
||
function agvSizeChange() {
|
||
agvSize = parseInt($("#q_size").val()) || 10;
|
||
agvSearch(1);
|
||
}
|
||
// 翻页
|
||
function agvPageTurn(step) {
|
||
var maxPage = Math.max(1, Math.ceil(agvTotal / agvSize));
|
||
var target = agvPage + step;
|
||
if (target < 1 || target > maxPage) return;
|
||
agvPage = target; loadTasks();
|
||
}
|
||
// 重置查询条件
|
||
function agvReset() {
|
||
$("#q_taskNo,#q_from,#q_to,#q_container").val("");
|
||
$("#q_source,#q_status").val("");
|
||
agvSearch(1);
|
||
}
|
||
|
||
// 打开「下发任务」弹窗:与 WTM 弹窗机制一致(ajax 取 HTML 注入当前文档 type:1),
|
||
// 当前文档已加载 Vue/ArcoVue/CSS,避免 iframe 内无脚本导致表单模板原样显示
|
||
var agvCreateLayerIndex = 0;
|
||
function agvOpenCreate() {
|
||
$.ajax({
|
||
type: "get", url: "/agv/AgvTask/Create", dataType: "html",
|
||
success: function (html) {
|
||
agvCreateLayerIndex = layer.open({
|
||
type: 1, title: "下发任务", area: ["800px", "90%"], content: html
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
// 供 Create 弹窗关闭后刷新列表
|
||
function reloadAgvTask() { loadTasks(); }
|
||
|
||
// 初始化:填充状态下拉 + 来源系统下拉 + 首次加载
|
||
$(function () {
|
||
var statusSel = $("#q_status");
|
||
for (var k in agvStatusMap) { statusSel.append('<option value="' + k + '">' + agvStatusMap[k] + "</option>"); }
|
||
$.ajax({
|
||
type: "post", url: "/agv/AgvTask/GetSourceSystems", dataType: "json", contentType: "application/json", data: "{}",
|
||
success: function (json) {
|
||
var list = json.Data || [];
|
||
for (var i = 0; i < list.length; i++) { $("#q_source").append('<option value="' + agvEsc(list[i]) + '">' + agvEsc(list[i]) + "</option>"); }
|
||
}
|
||
});
|
||
loadTasks();
|
||
});
|
||
</script>
|