(function () { function createSearchForm() { return { loc_no: "", barcode: "", row1: "", bay1: "", lev1: "", loc_type: "", qr_code_value: "" }; } function createForm() { return { staNo: "", taskPri: 100 }; } function createBatchNo() { var now = new Date(); var pad = function (value) { return value < 10 ? "0" + value : String(value); }; return "MANUAL_OUT_" + now.getFullYear() + pad(now.getMonth() + 1) + pad(now.getDate()) + pad(now.getHours()) + pad(now.getMinutes()) + pad(now.getSeconds()); } function listSelectedLocNos(selectedLocMap, selectedLocOrder) { return selectedLocOrder.filter(function (locNo) { return !!selectedLocMap[locNo]; }); } function buildOutStationsFromDevps(records) { var stationMap = {}; var stationList = []; (records || []).forEach(function (record) { var outStations = record["outStationList$"] || []; outStations.forEach(function (station) { var stationId = station && station.stationId; if (!stationId || stationMap[stationId]) { return; } stationMap[stationId] = true; stationList.push({ stationId: stationId, deviceNo: station.deviceNo, stationLev: station.stationLev }); }); }); stationList.sort(function (left, right) { return Number(left.stationId) - Number(right.stationId); }); return stationList; } new Vue({ el: "#app", data: function () { return { loading: false, stationLoading: false, submitting: false, advancedVisible: false, tableData: [], outStationOptions: [], searchForm: createSearchForm(), form: createForm(), page: { curr: 1, limit: 30, total: 0 }, selectedLocMap: {}, selectedLocOrder: [], restoringSelection: false, layoutTimer: null }; }, computed: { selectedLocNos: function () { return listSelectedLocNos(this.selectedLocMap, this.selectedLocOrder); }, selectedCount: function () { return this.selectedLocNos.length; }, selectedPreviewLocNos: function () { return this.selectedLocNos.slice(0, 18); }, selectedPreviewOverflow: function () { return Math.max(0, this.selectedCount - this.selectedPreviewLocNos.length); }, tableHeight: function () { return this.advancedVisible ? "calc(100vh - 410px)" : "calc(100vh - 350px)"; } }, created: function () { this.loadOutStations(); this.loadTable(); }, beforeDestroy: function () { if (this.layoutTimer) { clearTimeout(this.layoutTimer); this.layoutTimer = null; } }, methods: { requestTableLayout: function (delay) { var vm = this; if (vm.layoutTimer) { clearTimeout(vm.layoutTimer); } vm.$nextTick(function () { vm.layoutTimer = setTimeout(function () { if (vm.$refs.dataTable && typeof vm.$refs.dataTable.doLayout === "function") { vm.$refs.dataTable.doLayout(); } vm.restoreTableSelection(); }, delay || 40); }); }, buildQueryParams: function () { var params = { curr: this.page.curr, limit: this.page.limit, status: 1, loc_sts: "F", orderByField: "locNo", orderByType: "asc" }; var key; for (key in this.searchForm) { if (Object.prototype.hasOwnProperty.call(this.searchForm, key) && this.searchForm[key] !== "" && this.searchForm[key] !== null) { params[key] = this.searchForm[key]; } } return params; }, loadTable: function () { var vm = this; vm.loading = true; $.ajax({ url: baseUrl + "/locMast/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.page.total = (res.data && res.data.total) || 0; vm.requestTableLayout(80); 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; } }); }, loadOutStations: function () { var vm = this; vm.stationLoading = true; $.ajax({ url: baseUrl + "/basDevp/list/auth", headers: { token: localStorage.getItem("token") }, method: "GET", data: { curr: 1, limit: 200, status: 1, orderByField: "devpNo", orderByType: "asc" }, success: function (res) { if (res.code === 200) { vm.outStationOptions = buildOutStationsFromDevps((res.data && res.data.records) || []); return; } if (res.code === 403) { top.location.href = baseUrl + "/"; return; } vm.$message.error(res.msg || "出库站点加载失败"); }, error: function () { vm.$message.error("出库站点加载失败"); }, complete: function () { vm.stationLoading = false; } }); }, formatStationOptionLabel: function (station) { var parts = []; if (!station) { return ""; } if (station.stationId !== null && station.stationId !== undefined && station.stationId !== "") { parts.push("站点" + station.stationId); } if (station.deviceNo !== null && station.deviceNo !== undefined) { parts.push("设备" + station.deviceNo); } if (station.stationLev !== null && station.stationLev !== undefined) { parts.push(station.stationLev + "层"); } return parts.join(" / "); }, toggleAdvanced: function () { this.advancedVisible = !this.advancedVisible; this.requestTableLayout(180); }, handleSearch: function () { this.page.curr = 1; this.loadTable(); }, handleReset: function () { this.searchForm = createSearchForm(); this.advancedVisible = false; this.page.curr = 1; this.loadTable(); }, handleCurrentChange: function (curr) { this.page.curr = curr; this.loadTable(); }, handleSizeChange: function (limit) { this.page.limit = limit; this.page.curr = 1; this.loadTable(); }, handleSelectionChange: function (rows) { var vm = this; var selectedOnPage = {}; if (vm.restoringSelection) { return; } (rows || []).forEach(function (row) { selectedOnPage[row.locNo] = row; }); vm.tableData.forEach(function (row) { if (!row || !row.locNo) { return; } if (selectedOnPage[row.locNo]) { vm.selectedLocMap[row.locNo] = row; if (vm.selectedLocOrder.indexOf(row.locNo) === -1) { vm.selectedLocOrder.push(row.locNo); } } else if (vm.selectedLocMap[row.locNo]) { vm.$delete(vm.selectedLocMap, row.locNo); } }); vm.selectedLocOrder = vm.selectedLocOrder.filter(function (locNo) { return !!vm.selectedLocMap[locNo]; }); }, restoreTableSelection: function () { var vm = this; if (!vm.$refs.dataTable) { return; } vm.restoringSelection = true; vm.$refs.dataTable.clearSelection(); vm.tableData.forEach(function (row) { if (row && row.locNo && vm.selectedLocMap[row.locNo]) { vm.$refs.dataTable.toggleRowSelection(row, true); } }); vm.restoringSelection = false; }, clearSelectedLocs: function () { this.selectedLocMap = {}; this.selectedLocOrder = []; if (this.$refs.dataTable) { this.$refs.dataTable.clearSelection(); } }, removeSelectedLoc: function (locNo) { if (!locNo || !this.selectedLocMap[locNo]) { return; } this.$delete(this.selectedLocMap, locNo); this.selectedLocOrder = this.selectedLocOrder.filter(function (item) { return item !== locNo; }); this.restoreTableSelection(); }, submitBatchOutTask: function () { var vm = this; var batchNo; var taskList; var locNos = vm.selectedLocNos; if (!vm.form.staNo) { vm.$message.warning("请选择目标站点"); return; } if (!locNos.length) { vm.$message.warning("请先勾选至少一个库位"); return; } batchNo = createBatchNo(); taskList = locNos.map(function (locNo, index) { return { locNo: locNo, staNo: Number(vm.form.staNo), taskPri: vm.form.taskPri, batch: batchNo, batchSeq: index + 1 }; }); vm.submitting = true; $.ajax({ url: baseUrl + "/wrkBatchOut/create/auth", contentType: "application/json", headers: { token: localStorage.getItem("token") }, data: JSON.stringify({ taskList: taskList }), method: "POST", success: function (res) { if (res.code === 200) { vm.$message.success("已生成" + locNos.length + "条出库任务"); vm.clearSelectedLocs(); vm.loadTable(); return; } if (res.code === 403) { top.location.href = baseUrl + "/"; return; } vm.$message.error(res.msg || "批量生成出库任务失败"); }, error: function (xhr) { var message = "批量生成出库任务失败"; if (xhr && xhr.responseJSON && xhr.responseJSON.msg) { message = xhr.responseJSON.msg; } vm.$message.error(message); }, complete: function () { vm.submitting = false; } }); } } }); })();