(function () {
|
var COLUMN_STORAGE_KEY = "wrk-mast-visible-columns";
|
|
var DEFAULT_COLUMNS = [
|
{ key: "wrkNo", prop: "wrkNo", label: "工作号", width: 110, sortable: true, align: "center" },
|
{ key: "wmsWrkNo", prop: "wmsWrkNo", label: "WMS任务号", minWidth: 160, sortable: true },
|
{ key: "wrkSts$", prop: "wrkSts$", label: "工作状态", minWidth: 120, sortable: true },
|
{ key: "ioType$", prop: "ioType$", label: "任务类型", minWidth: 120, sortable: true },
|
{ key: "ioPri", prop: "ioPri", label: "优先级", width: 90, sortable: true, align: "center" },
|
{ key: "sourceStaNo", prop: "sourceStaNo", label: "源站", width: 90, sortable: true, align: "center" },
|
{ key: "staNo", prop: "staNo", label: "目标站", width: 90, sortable: true, align: "center" },
|
{ key: "sourceLocNo", prop: "sourceLocNo", label: "源库位", minWidth: 140, sortable: true },
|
{ key: "locNo", prop: "locNo", label: "目标库位", minWidth: 140, sortable: true },
|
{ key: "modiTime$", prop: "modiTime$", label: "修改时间", minWidth: 168, sortable: true },
|
{ key: "barcode", prop: "barcode", label: "托盘码", minWidth: 150, sortable: true },
|
{ key: "crnNo", prop: "crnNo", label: "堆垛机", width: 90, sortable: true, align: "center" },
|
{ key: "dualCrnNo", prop: "dualCrnNo", label: "双工位堆垛机", minWidth: 120, sortable: true, align: "center" },
|
{ key: "batch", prop: "batch", label: "批次", minWidth: 120, sortable: true },
|
{ key: "batchSeq", prop: "batchSeq", label: "批次序列", width: 100, sortable: true, align: "center" },
|
{ key: "sendFailCount", prop: "sendFailCount", label: "失败次数", width: 96, sortable: true, align: "center" },
|
{ key: "errorTime$", prop: "errorTime$", label: "失败时间", minWidth: 168, sortable: true },
|
{ key: "errorMemo", prop: "errorMemo", label: "失败原因", minWidth: 220, sortable: false, showOverflow: false },
|
{ key: "systemMsg", prop: "systemMsg", label: "系统消息", minWidth: 220, sortable: false, showOverflow: false }
|
];
|
|
var MANUAL_ROLLBACK_STATUSES = [6, 106, 506];
|
|
function cloneSearchForm() {
|
return {
|
condition: "",
|
wrk_no: "",
|
wms_wrk_no: "",
|
loc_no: "",
|
source_loc_no: "",
|
crn_no: "",
|
dual_crn_no: ""
|
};
|
}
|
|
function loadStoredColumns() {
|
try {
|
var raw = localStorage.getItem(COLUMN_STORAGE_KEY);
|
var parsed = raw ? JSON.parse(raw) : null;
|
if (!parsed || !parsed.length) {
|
return DEFAULT_COLUMNS.map(function (column) { return column.key; });
|
}
|
return DEFAULT_COLUMNS.map(function (column) { return column.key; }).filter(function (key) {
|
return parsed.indexOf(key) > -1;
|
});
|
} catch (e) {
|
return DEFAULT_COLUMNS.map(function (column) { return column.key; });
|
}
|
}
|
|
function saveVisibleColumns(keys) {
|
localStorage.setItem(COLUMN_STORAGE_KEY, JSON.stringify(keys));
|
}
|
|
new Vue({
|
el: "#app",
|
data: function () {
|
return {
|
loading: false,
|
advancedVisible: false,
|
columnPopoverVisible: false,
|
tableData: [],
|
currentPage: 1,
|
pageSize: 30,
|
pageSizes: [16, 30, 50, 100, 150, 200],
|
pageTotal: 0,
|
tableHeight: 520,
|
searchForm: cloneSearchForm(),
|
sortState: {
|
prop: "",
|
order: ""
|
},
|
columnDefs: DEFAULT_COLUMNS,
|
visibleColumnKeys: loadStoredColumns(),
|
layoutTimer: null
|
};
|
},
|
computed: {
|
visibleColumns: function () {
|
var keys = this.visibleColumnKeys;
|
return this.columnDefs.filter(function (column) {
|
return keys.indexOf(column.key) > -1;
|
});
|
},
|
tableRenderKey: function () {
|
return this.visibleColumnKeys.join("|");
|
}
|
},
|
created: function () {
|
this.loadList();
|
},
|
mounted: function () {
|
this.updateTableHeight();
|
window.addEventListener("resize", this.handleResize);
|
},
|
beforeDestroy: function () {
|
window.removeEventListener("resize", this.handleResize);
|
if (this.layoutTimer) {
|
clearTimeout(this.layoutTimer);
|
this.layoutTimer = null;
|
}
|
},
|
methods: {
|
displayCellValue: function (row, column) {
|
var value;
|
if (!row || !column) {
|
return "";
|
}
|
value = row[column.prop];
|
return value === null || value === undefined || value === "" ? "" : value;
|
},
|
buildQueryParams: function () {
|
var data = {
|
curr: this.currentPage,
|
limit: this.pageSize
|
};
|
var key;
|
for (key in this.searchForm) {
|
if (Object.prototype.hasOwnProperty.call(this.searchForm, key) && this.searchForm[key] !== "" && this.searchForm[key] !== null) {
|
data[key] = this.searchForm[key];
|
}
|
}
|
if (this.sortState.prop && this.sortState.order) {
|
data.orderByField = this.sortState.prop;
|
data.orderByType = this.sortState.order === "ascending" ? "asc" : "desc";
|
}
|
return data;
|
},
|
loadList: function () {
|
var vm = this;
|
vm.loading = true;
|
$.ajax({
|
url: baseUrl + "/wrkMast/list/auth",
|
headers: { token: localStorage.getItem("token") },
|
method: "GET",
|
data: vm.buildQueryParams(),
|
success: function (res) {
|
if (res.code === 200) {
|
vm.tableData = (res.data && res.data.records) || [];
|
vm.pageTotal = (res.data && res.data.total) || 0;
|
vm.scheduleTableLayout();
|
return;
|
}
|
if (res.code === 403) {
|
top.location.href = baseUrl + "/";
|
return;
|
}
|
vm.$message.error(res.msg || "任务列表加载失败");
|
},
|
error: function () {
|
vm.$message.error("任务列表加载失败");
|
},
|
complete: function () {
|
vm.loading = false;
|
}
|
});
|
},
|
handleSearch: function () {
|
this.currentPage = 1;
|
this.loadList();
|
},
|
handleReset: function () {
|
this.searchForm = cloneSearchForm();
|
this.currentPage = 1;
|
this.sortState = {
|
prop: "",
|
order: ""
|
};
|
this.loadList();
|
this.scheduleTableLayout();
|
},
|
toggleAdvanced: function () {
|
this.advancedVisible = !this.advancedVisible;
|
this.updateTableHeight();
|
this.scheduleTableLayout();
|
},
|
handleSizeChange: function (size) {
|
this.pageSize = size;
|
this.currentPage = 1;
|
this.loadList();
|
},
|
handleCurrentChange: function (page) {
|
this.currentPage = page;
|
this.loadList();
|
},
|
handleSortChange: function (sort) {
|
this.sortState = {
|
prop: sort.prop || "",
|
order: sort.order || ""
|
};
|
this.currentPage = 1;
|
this.loadList();
|
},
|
isColumnVisible: function (key) {
|
return this.visibleColumnKeys.indexOf(key) > -1;
|
},
|
toggleColumn: function (key, checked) {
|
var next = this.visibleColumnKeys.slice();
|
var index = next.indexOf(key);
|
|
if (checked && index === -1) {
|
next.push(key);
|
}
|
if (!checked && index > -1) {
|
if (next.length === 1) {
|
this.$message.warning("至少保留一列");
|
return;
|
}
|
next.splice(index, 1);
|
}
|
|
this.visibleColumnKeys = this.columnDefs.map(function (column) {
|
return column.key;
|
}).filter(function (columnKey) {
|
return next.indexOf(columnKey) > -1;
|
});
|
saveVisibleColumns(this.visibleColumnKeys);
|
this.scheduleTableLayout();
|
},
|
showAllColumns: function () {
|
this.visibleColumnKeys = this.columnDefs.map(function (column) {
|
return column.key;
|
});
|
saveVisibleColumns(this.visibleColumnKeys);
|
this.scheduleTableLayout();
|
},
|
resetColumns: function () {
|
this.visibleColumnKeys = DEFAULT_COLUMNS.map(function (column) {
|
return column.key;
|
});
|
saveVisibleColumns(this.visibleColumnKeys);
|
this.scheduleTableLayout();
|
},
|
handleRowCommand: function (command, row) {
|
if (command === "complete") {
|
this.completeTask(row);
|
return;
|
}
|
if (command === "cancel") {
|
this.cancelTask(row);
|
return;
|
}
|
if (command === "manualRollback") {
|
this.manualRollbackTask(row);
|
}
|
},
|
canManualRollback: function (row) {
|
return !!row && MANUAL_ROLLBACK_STATUSES.indexOf(Number(row.wrkSts)) > -1;
|
},
|
completeTask: function (row) {
|
var vm = this;
|
vm.$confirm("确定完成该任务吗?", "提示", {
|
type: "warning",
|
confirmButtonText: "确定",
|
cancelButtonText: "取消"
|
}).then(function () {
|
$.ajax({
|
url: baseUrl + "/openapi/completeTask",
|
contentType: "application/json",
|
headers: { token: localStorage.getItem("token") },
|
data: JSON.stringify({ wrkNo: row.wrkNo }),
|
method: "POST",
|
success: function (res) {
|
if (res.code === 200) {
|
vm.$message.success("完成成功");
|
vm.loadList();
|
return;
|
}
|
if (res.code === 403) {
|
top.location.href = baseUrl + "/";
|
return;
|
}
|
vm.$message.error(res.msg || "完成失败");
|
},
|
error: function () {
|
vm.$message.error("完成失败");
|
}
|
});
|
}).catch(function () {});
|
},
|
cancelTask: function (row) {
|
var vm = this;
|
vm.$confirm("确定取消该任务吗?", "提示", {
|
type: "warning",
|
confirmButtonText: "确定",
|
cancelButtonText: "取消"
|
}).then(function () {
|
$.ajax({
|
url: baseUrl + "/openapi/cancelTask",
|
contentType: "application/json",
|
headers: { token: localStorage.getItem("token") },
|
data: JSON.stringify({ wrkNo: row.wrkNo }),
|
method: "POST",
|
success: function (res) {
|
if (res.code === 200) {
|
vm.$message.success("取消成功");
|
vm.loadList();
|
return;
|
}
|
if (res.code === 403) {
|
top.location.href = baseUrl + "/";
|
return;
|
}
|
vm.$message.error(res.msg || "取消失败");
|
},
|
error: function () {
|
vm.$message.error("取消失败");
|
}
|
});
|
}).catch(function () {});
|
},
|
manualRollbackTask: function (row) {
|
var vm = this;
|
if (!vm.canManualRollback(row)) {
|
vm.$message.warning("当前任务不处于待人工回滚状态");
|
return;
|
}
|
vm.$confirm("确定手动回滚该任务吗?回滚后任务会恢复为待执行状态。", "提示", {
|
type: "warning",
|
confirmButtonText: "确定",
|
cancelButtonText: "取消"
|
}).then(function () {
|
$.ajax({
|
url: baseUrl + "/openapi/manualRollbackTask",
|
contentType: "application/json",
|
headers: { token: localStorage.getItem("token") },
|
data: JSON.stringify({ wrkNo: row.wrkNo }),
|
method: "POST",
|
success: function (res) {
|
if (res.code === 200) {
|
vm.$message.success("人工回滚成功");
|
vm.loadList();
|
return;
|
}
|
if (res.code === 403) {
|
top.location.href = baseUrl + "/";
|
return;
|
}
|
vm.$message.error(res.msg || "人工回滚失败");
|
},
|
error: function () {
|
vm.$message.error("人工回滚失败");
|
}
|
});
|
}).catch(function () {});
|
},
|
updateTableHeight: function () {
|
var viewport = window.innerHeight || document.documentElement.clientHeight || 860;
|
this.tableHeight = Math.max(340, viewport - (this.advancedVisible ? 276 : 222));
|
},
|
scheduleTableLayout: function () {
|
var vm = this;
|
vm.updateTableHeight();
|
vm.$nextTick(function () {
|
if (vm.layoutTimer) {
|
clearTimeout(vm.layoutTimer);
|
}
|
vm.layoutTimer = setTimeout(function () {
|
if (vm.$refs.dataTable && typeof vm.$refs.dataTable.doLayout === "function") {
|
vm.$refs.dataTable.doLayout();
|
}
|
}, 50);
|
});
|
},
|
handleResize: function () {
|
this.scheduleTableLayout();
|
}
|
}
|
});
|
})();
|