From f29f358f589f5b1c2589c07b65845650be7aafef Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期一, 08 十二月 2025 21:21:08 +0800
Subject: [PATCH] 代码优化
---
项目代码/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue | 471 ++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 342 insertions(+), 129 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
index 252da58..7e80215 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
@@ -5,29 +5,78 @@
:lazy="true"
width="65%"
:padding="20"
- title="鏃犲簱瀛樺嚭搴�"
+ title="铏氭嫙鍑哄叆搴�"
class="custom-vol-box"
>
<div>
+ <!-- 鍗曟嵁杈撳叆鍖哄煙锛堟敮鎸佹壂鐮侊級 -->
+ <el-form
+ :inline="true"
+ :model="orderForm"
+ style="margin-bottom: 20px; align-items: flex-end;"
+ @submit.prevent
+ >
+ <el-form-item label="鍑哄簱鍗曟嵁:" name="outboundOrderNo">
+ <el-input
+ v-model="orderForm.outboundOrderNo"
+ placeholder="璇疯緭鍏ユ垨鎵弿鍑哄簱鍗曟嵁鍙�"
+ clearable
+ style="width: 220px; margin-right: 10px;"
+ @input="handleOutboundInput"
+ @keyup.enter="(e) => {
+ e.stopPropagation(); // 闃绘浜嬩欢鍐掓场
+ e.preventDefault(); // 闃绘榛樿琛屼负
+ focusBarcodeInputDirectly();
+ }"
+ ref="outboundInputRef"
+ ></el-input>
+ </el-form-item>
+ <el-form-item label="閲囪喘鍗曟嵁:" name="purchaseOrderNo">
+ <el-input
+ v-model="orderForm.purchaseOrderNo"
+ placeholder="鎵爜鏉$爜鍚庤嚜鍔ㄥ~鍏�"
+ clearable
+ style="width: 220px; margin-right: 10px;"
+ @input="handlePurchaseInput"
+ readonly
+ ref="purchaseInputRef"
+ ></el-input>
+ </el-form-item>
+ </el-form>
+
<!-- 涓婃柟杈撳叆妗� -->
- <el-form :inline="true" :model="formData" ref="formData" style="margin-bottom: 20px; align-items: flex-end;">
+ <el-form
+ :inline="true"
+ :model="formData"
+ ref="formRef"
+ style="margin-bottom: 20px; align-items: flex-end;"
+ @submit.prevent
+ >
<el-form-item
label="鎵弿鏉$爜:"
style="width: 80%"
- prop="barcode"
+ name="barcode"
+ :rules="[{ required: true, message: '璇锋壂鎻忔垨杈撳叆鏉$爜', trigger: 'blur' }]"
>
<el-input
- ref="barcodeInput"
+ ref="barcodeInputRef"
v-model="formData.barcode"
placeholder="璇蜂娇鐢ㄦ壂鐮佹灙鎵弿鏉$爜锛屾垨鎵嬪姩杈撳叆"
- @keyup.enter="handleScan"
+ @keydown.enter="debouncedHandleScan"
autofocus
class="custom-input"
+ :disabled="!orderForm.outboundOrderNo || loading"
></el-input>
</el-form-item>
<el-form-item>
- <el-button type="primary" size="small" @click="handleScan" class="custom-button">
- <i class="el-icon-search"></i> 纭鎵弿
+ <el-button
+ type="primary"
+ size="small"
+ @click="handleScan"
+ class="custom-button"
+ :disabled="!orderForm.outboundOrderNo || loading"
+ >
+ <Search /> 纭鎵弿
</el-button>
</el-form-item>
</el-form>
@@ -37,27 +86,23 @@
<el-card shadow="hover" style="margin-bottom: 10px; border: none;" class="custom-card">
<div class="card-header">
<span class="header-title">宸叉壂鎻忔潯鐮佸垪琛紙鍏眥{ scannedBarcodes.length }}鏉★級</span>
- <el-button
- class="clear-all-btn"
- @click="clearAll"
- :disabled="scannedBarcodes.length === 0"
- >娓呯┖鎵�鏈�</el-button>
</div>
<div class="card-body">
<el-scrollbar height="400px" class="custom-scrollbar">
- <!-- 浣跨敤 transition-group 鍖呰9浠ュ疄鐜板姩鐢� -->
<transition-group name="barcode-item-transition">
- <div class="barcode-item" v-for="(barcode, index) in scannedBarcodes" :key="barcode" :data-index="index">
- <span class="barcode-text">{{ index + 1 }}. {{ barcode }}</span>
+ <div class="barcode-item" v-for="(item, index) in scannedBarcodes" :key="item.barcode" :data-index="index">
+ <span class="barcode-text">{{ index + 1 }}. {{ item.barcode }}</span>
<el-button
class="delete-btn"
- @click="removeItem(index)"
- >鍒犻櫎</el-button>
+ @click="removeItem(index, item.barcode)"
+ icon="Delete"
+ circle
+ :disabled="loading"
+ ></el-button>
</div>
</transition-group>
<div class="empty-tip" v-if="scannedBarcodes.length === 0">
- <i class="el-icon-information"></i>
- <span>鏆傛棤鎵弿璁板綍锛岃鎵弿鏉$爜</span>
+ <span>鏆傛棤鎵弿璁板綍锛岃鍏堣緭鍏ュ嚭搴撳崟鎹悗鎵弿鏉$爜</span>
</div>
</el-scrollbar>
</div>
@@ -67,10 +112,26 @@
<template #footer>
<div class="footer-actions">
- <el-button type="primary" size="small" @click="submit" :disabled="scannedBarcodes.length === 0" class="submit-btn">
- <i class="el-icon-check"></i> 鎻愪氦鍑哄簱
+ <el-button
+ type="primary"
+ size="small"
+ @click="submit"
+ :disabled="scannedBarcodes.length === 0 || !orderForm.outboundOrderNo || !orderForm.purchaseOrderNo || loading"
+ class="submit-btn"
+ >
+ <Check /> 鎻愪氦鍑哄簱
</el-button>
- <el-button type="text" size="small" @click="showDetailBox = false" class="cancel-btn">
+ <el-button
+ type="text"
+ size="small"
+ @click="(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ showDetailBox = false;
+ }"
+ class="cancel-btn"
+ :disabled="loading"
+ >
鍙栨秷
</el-button>
</div>
@@ -79,99 +140,261 @@
</div>
</template>
-<script>
+<script setup>
+import { ref, reactive, onMounted, nextTick, watch } from 'vue';
+import { ElMessage } from 'element-plus';
+import { Search, Check } from '@element-plus/icons-vue';
+
import VolBox from "@/components/basic/VolBox.vue";
+import http from '@/api/http';
-export default {
- components: { VolBox },
- data() {
- return {
- showDetailBox: false,
- formData: {
- barcode: "",
- },
- scannedBarcodes: [],
- };
- },
- methods: {
- open() {
- this.showDetailBox = true;
- this.scannedBarcodes = [];
- this.formData.barcode = "";
- this.$nextTick(() => {
- this.$refs.barcodeInput.focus();
- });
- },
+// 鍝嶅簲寮忔暟鎹�
+const showDetailBox = ref(false);
+const orderForm = reactive({
+ outboundOrderNo: "",
+ purchaseOrderNo: ""
+});
+const formData = reactive({
+ barcode: "",
+});
+const scannedBarcodes = ref([]);
+const loading = ref(false);
+// 鏂板锛氬瓨鍌ㄩ娆℃壂鎻忕殑閲囪喘鍗曞彿锛堢敤浜庝竴鑷存�ф牎楠岋級
+const firstPurchaseOrderNo = ref(null);
- handleScan() {
- const barcode = this.formData.barcode.trim();
- if (!barcode) {
- this.$refs.barcodeInput.focus();
- return;
- }
- if (this.scannedBarcodes.includes(barcode)) {
- this.$message.warning(`鏉$爜 ${barcode} 宸叉壂鎻忚繃锛岃鍕块噸澶嶆壂鎻廯);
- this.formData.barcode = "";
- this.$refs.barcodeInput.focus();
- return;
- }
+// 妯℃澘寮曠敤
+const formRef = ref(null);
+const barcodeInputRef = ref(null);
+const outboundInputRef = ref(null);
+const purchaseInputRef = ref(null);
- this.scannedBarcodes.push(barcode);
- this.formData.barcode = "";
+// 缁勪欢鎸傝浇鏃惰仛鐒﹀埌鍑哄簱鍗曡緭鍏ユ
+onMounted(() => {
+ nextTick(() => {
+ outboundInputRef.value?.focus();
+ });
+});
- this.$nextTick(() => {
- this.$refs.barcodeInput.focus();
- });
- },
+// 鐩戝惉鎵弿鍒楄〃锛岃嫢涓虹┖鍒欓噸缃娆¢噰璐崟鍙�
+watch(scannedBarcodes, (newVal) => {
+ if (newVal.length === 0) {
+ firstPurchaseOrderNo.value = null;
+ orderForm.purchaseOrderNo = ""; // 鍚屾娓呯┖閲囪喘鍗曡緭鍏ユ
+ }
+}, { deep: true });
- removeItem(index) {
- this.scannedBarcodes.splice(index, 1);
- },
-
- clearAll() {
- this.$confirm("纭畾瑕佹竻绌烘墍鏈夋壂鎻忚褰曞悧锛�", "鎻愮ず", {
- confirmButtonText: "纭畾",
- cancelButtonText: "鍙栨秷",
- type: "warning",
- }).then(() => {
- this.scannedBarcodes = [];
- }).catch(() => {
- this.$refs.barcodeInput.focus();
- });
- },
-
- submit() {
- if (this.scannedBarcodes.length === 0) {
- this.$message.warning("璇峰厛鎵弿鑷冲皯涓�鏉℃潯鐮�");
- this.$refs.barcodeInput.focus();
- return;
- }
-
- const params = {
- barcodes: this.scannedBarcodes,
- };
-
- this.http
- .post("/api/OutboundOrder/NoStockOut", params, "鏁版嵁澶勭悊涓�...")
- .then((res) => {
- if (!res.status) {
- this.$message.error(res.message);
- this.$refs.barcodeInput.focus();
- return;
- }
- this.$message.success("鍑哄簱鎴愬姛");
- this.showDetailBox = false;
- this.$emit("parentCall", ($vue) => {
- $vue.refresh();
- });
- })
- .catch((err) => {
- this.$message.error(`璇锋眰澶辫触锛�${err.message || "鏈煡閿欒"}`);
- this.$refs.barcodeInput.focus();
- });
- },
- },
+// 绠�鍗曢槻鎶栧嚱鏁帮紙鏃犻渶渚濊禆lodash锛�
+const debounce = (fn, delay = 100) => {
+ let timer = null;
+ return (...args) => {
+ if (timer) clearTimeout(timer);
+ timer = setTimeout(() => {
+ fn.apply(this, args);
+ }, delay);
+ };
};
+
+// 鎵撳紑寮圭獥
+const open = () => {
+ showDetailBox.value = true;
+ scannedBarcodes.value = [];
+ formData.barcode = "";
+ orderForm.outboundOrderNo = "";
+ orderForm.purchaseOrderNo = "";
+ // 閲嶇疆棣栨閲囪喘鍗曞彿
+ firstPurchaseOrderNo.value = null;
+ nextTick(() => {
+ outboundInputRef.value?.focus();
+ });
+};
+
+// 鍑哄簱鍗曡緭鍏ュ鐞嗭紙鎵爜鎴栨墜鍔ㄨ緭鍏ワ級
+const handleOutboundInput = (value) => {
+ if (value && value.trim()) {
+ // 鍑哄簱鍗曞彿鏍煎紡楠岃瘉閫昏緫锛堟寜闇�淇濈暀锛�
+ }
+};
+
+// 閲囪喘鍗曡緭鍏ュ鐞嗭紙鎵爜鎴栨墜鍔ㄨ緭鍏ワ級
+const handlePurchaseInput = (value) => {
+ if (value && value.trim()) {
+ // 閲囪喘鍗曞彿鏍煎紡楠岃瘉閫昏緫锛堟寜闇�淇濈暀锛�
+ }
+};
+
+// 鐩存帴璺宠浆鍒版潯鐮佽緭鍏ユ锛堟棤闇�鍏堝~閲囪喘鍗曪級
+const focusBarcodeInputDirectly = () => {
+ if (orderForm.outboundOrderNo.trim()) {
+ barcodeInputRef.value?.focus();
+ } else {
+ ElMessage.warning("璇峰厛杈撳叆鏈夋晥鐨勫嚭搴撳崟鎹彿");
+ }
+};
+
+/**
+ * 鏍规嵁鏉$爜鏌ヨ閲囪喘鍗曟帴鍙o紙瀹屽叏瀵归綈绀轰緥璇锋眰鏍煎紡锛�
+ * @param {string} barcode 鏉$爜
+ * @returns {Promise<string>} 閲囪喘鍗曞彿
+ */
+const getPurchaseOrderByBarcode = async (barcode) => {
+ // 瀹屽叏鎸夌収绀轰緥鏍煎紡锛歶rl鎷兼帴鍙傛暟 + 绗簩涓弬鏁颁紶鎻愮ず鏂囨湰
+ const res = await http.post(`/api/OutboundPicking/GetPurchaseOrderByBarcode?barCode=${encodeURIComponent(barcode)}`, "鏌ヨ閲囪喘鍗曚腑...");
+
+ if (res.status !== true) {
+ throw new Error(res.message || "鏌ヨ閲囪喘鍗曞け璐�");
+ }
+ if (!res.data?.purchaseOrderNo) {
+ throw new Error("鏈煡璇㈠埌璇ユ潯鐮佸搴旂殑閲囪喘鍗�");
+ }
+ return res.data.purchaseOrderNo;
+};
+
+// 鎵弿鏉$爜鏍稿績閫昏緫
+const handleScan = async () => {
+ if (!formRef.value) return;
+ // 楠岃瘉鏉$爜蹇呭~
+ await formRef.value.validateField('barcode');
+
+ const barcode = formData.barcode.trim();
+ const outboundOrderNo = orderForm.outboundOrderNo.trim();
+
+ // 妫�鏌ユ潯鐮佹槸鍚﹀凡鎵弿
+ if (scannedBarcodes.value.some(item => item.barcode === barcode)) {
+ ElMessage.warning(`鏉$爜 ${barcode} 宸叉壂鎻忚繃锛岃鍕块噸澶嶆壂鎻廯);
+ formData.barcode = "";
+ nextTick(() => barcodeInputRef.value?.focus());
+ return;
+ }
+
+ try {
+ loading.value = true;
+
+ // 姝ラ1锛氫粎浼犳潯鐮佹煡璇㈤噰璐崟锛堜娇鐢ㄧず渚嬫牸寮忕殑璇锋眰锛�
+ const purchaseOrderNo = await getPurchaseOrderByBarcode(barcode);
+
+ // 鏍稿績鏍¢獙锛氶噰璐崟涓�鑷存�ф鏌�
+ if (firstPurchaseOrderNo.value) {
+ // 闈為娆℃壂鎻忥紝鏍¢獙閲囪喘鍗曞彿鏄惁涓�鑷�
+ if (purchaseOrderNo !== firstPurchaseOrderNo.value) {
+ throw new Error(`褰撳墠鏉$爜瀵瑰簲鐨勯噰璐崟銆�${purchaseOrderNo}銆戜笌棣栨鎵弿鐨勯噰璐崟銆�${firstPurchaseOrderNo.value}銆戜笉涓�鑷达紝绂佹鎵弿锛乣);
+ }
+ } else {
+ // 棣栨鎵弿锛岃褰曢噰璐崟鍙�
+ firstPurchaseOrderNo.value = purchaseOrderNo;
+ }
+
+ // 璧嬪�奸噰璐崟鍒拌緭鍏ユ
+ orderForm.purchaseOrderNo = purchaseOrderNo;
+ ElMessage.success(`鎴愬姛鏌ヨ鍒伴噰璐崟锛�${purchaseOrderNo}`);
+
+ // 姝ラ2锛氳皟鐢ㄥ師鏈夋潯鐮侀獙璇佹帴鍙o紙濡傞渶瀵归綈鏍煎紡鍙悓姝ヤ慨鏀癸紝姝ゅ淇濈暀鍘熸湁鏍煎紡锛�
+ const validateRes = await http.post("/api/OutboundPicking/BarcodeValidate", {
+ outOder: outboundOrderNo,
+ inOder: purchaseOrderNo,
+ barCode: barcode
+ });
+
+ if (validateRes.status === true) {
+ scannedBarcodes.value.push({ barcode });
+ ElMessage.success("鎵弿鎴愬姛");
+ formData.barcode = "";
+ } else {
+ ElMessage.error("鎵弿澶辫触锛�" + (validateRes.message || '鏉$爜楠岃瘉澶辫触'));
+ }
+ } catch (error) {
+ // 鎹曡幏閲囪喘鍗曚笉涓�鑷寸瓑閿欒骞舵彁绀�
+ ElMessage.error(error.message);
+ // 娓呯┖褰撳墠杈撳叆妗嗭紝鑱氱劍鏉$爜杈撳叆妗�
+ formData.barcode = "";
+ nextTick(() => barcodeInputRef.value?.focus());
+ } finally {
+ loading.value = false;
+ // 寮哄埗鑱氱劍鏉$爜杈撳叆妗嗭紝閬垮厤鐒︾偣璺冲埌寮圭獥澶�
+ nextTick(() => {
+ if (barcodeInputRef.value) {
+ barcodeInputRef.value.focus();
+ // 娓呯┖杈撳叆妗嗛�変腑鐘舵�侊紙鎵爜鏋彲鑳芥畫鐣欓�変腑锛�
+ if (barcodeInputRef.value.input) {
+ barcodeInputRef.value.input.select = () => {};
+ }
+ }
+ });
+ }
+};
+
+// 甯﹂槻鎶栧拰浜嬩欢鎷︽埅鐨勬壂鎻忓鐞嗭紙閫傞厤鎵爜鏋級
+const debouncedHandleScan = debounce(async (e) => {
+ // 闃绘浜嬩欢鍐掓场鍜岄粯璁よ涓�
+ e.stopPropagation();
+ e.preventDefault();
+ await handleScan();
+}, 100);
+
+// 绉婚櫎鍗曟潯鎵弿璁板綍
+const removeItem = async (index, barcode) => {
+ try {
+ loading.value = true;
+ const res = await http.post("/api/OutboundPicking/DeleteBarcode", {
+ outOder: orderForm.outboundOrderNo,
+ inOder: orderForm.purchaseOrderNo,
+ barCode: barcode
+ });
+
+ if (res.status === true) {
+ scannedBarcodes.value.splice(index, 1);
+ ElMessage.success("鍒犻櫎鎴愬姛");
+ // 鑻ュ垹闄ゅ悗鏃犳潯鐮侊紝鑷姩閲嶇疆棣栨閲囪喘鍗曞彿鍜岄噰璐崟杈撳叆妗�
+ if (scannedBarcodes.value.length === 0) {
+ firstPurchaseOrderNo.value = null;
+ orderForm.purchaseOrderNo = "";
+ }
+ } else {
+ ElMessage.error("鍒犻櫎澶辫触锛�" + (res.message || '鍒犻櫎澶辫触'));
+ }
+ } catch (error) {
+ ElMessage.error("鍒犻櫎鏉$爜寮傚父锛�" + error.message);
+ } finally {
+ loading.value = false;
+ }
+};
+
+// 鎻愪氦鍑哄簱
+const submit = async () => {
+ if (scannedBarcodes.value.length === 0) {
+ ElMessage.warning("璇峰厛鎵弿鑷冲皯涓�鏉℃潯鐮�");
+ return;
+ }
+
+ const barcodes = scannedBarcodes.value.map(item => item.barcode);
+
+ try {
+ loading.value = true;
+ const res = await http.post("/api/OutboundPicking/NoStockOutSubmit", {
+ OutOderSubmit: orderForm.outboundOrderNo,
+ InOderSubmit: orderForm.purchaseOrderNo,
+ BarCodeSubmit: barcodes
+ });
+
+ if (res.status === true) {
+ ElMessage.success("鍑哄簱鎻愪氦鎴愬姛");
+ showDetailBox.value = false;
+ // 鎻愪氦鎴愬姛鍚庨噸缃姸鎬�
+ firstPurchaseOrderNo.value = null;
+ scannedBarcodes.value = [];
+ } else {
+ ElMessage.error("鍑哄簱鎻愪氦澶辫触锛�" + (res.message || '鎻愪氦澶辫触'));
+ }
+ } catch (error) {
+ ElMessage.error("鍑哄簱鎻愪氦寮傚父锛�" + error.message);
+ } finally {
+ loading.value = false;
+ }
+};
+
+// 鏆撮湶缁欑埗缁勪欢鐨勬柟娉�
+defineExpose({
+ open
+});
</script>
<style scoped>
@@ -219,31 +442,22 @@
font-size: 15px;
color: #333;
}
-.clear-all-btn {
- color: #f56c6c;
- font-size: 13px;
- transition: color 0.2s;
-}
-.clear-all-btn:hover {
- color: #e53e3e;
- background: rgba(245, 108, 108, 0.1);
-}
.card-body {
padding: 0;
}
/* 鑷畾涔夋粴鍔ㄦ潯 */
-.custom-scrollbar ::v-deep .el-scrollbar__thumb {
+.custom-scrollbar :deep(.el-scrollbar__thumb) {
background: rgba(0, 0, 0, 0.2);
border-radius: 4px;
width: 4px;
}
-.custom-scrollbar ::v-deep .el-scrollbar__bar:hover .el-scrollbar__thumb {
+.custom-scrollbar :deep(.el-scrollbar__bar:hover .el-scrollbar__thumb) {
background: rgba(0, 0, 0, 0.3);
width: 6px;
}
-.custom-scrollbar ::v-deep .el-scrollbar__wrap {
+.custom-scrollbar :deep(.el-scrollbar__wrap) {
overflow-x: hidden;
}
@@ -260,7 +474,7 @@
}
/* 涓哄鏁拌娣诲姞杞诲井鐨勮儗鏅壊锛屽寮哄彲璇绘�� */
.barcode-item:nth-child(odd) {
- background-color: #e1e1e1;
+ background-color: #f9f9f9;
}
.barcode-text {
flex: 1;
@@ -274,16 +488,15 @@
.delete-btn {
color: #ea1919;
- font-size: 20px;
+ font-size: 16px;
transition: all 0.2s;
- transform: scale(0.8);
+ opacity: 0.7;
}
.barcode-item:hover .delete-btn {
opacity: 1;
- transform: scale(1);
}
.delete-btn:hover {
- color: #f56c6c !important; /* 浣跨敤 !important 瑕嗙洊 Element UI 榛樿鏍峰紡 */
+ color: #f56c6c !important;
background: rgba(245, 108, 108, 0.1);
}
@@ -296,22 +509,22 @@
flex-direction: column;
align-items: center;
justify-content: center;
+ gap: 15px;
}
.empty-tip i {
font-size: 40px;
- margin-bottom: 15px;
color: #dcdfe6;
}
/* 鑷畾涔夎緭鍏ユ */
-.custom-input ::v-deep .el-input__inner {
+.custom-input :deep(.el-input__inner) {
border-radius: 6px;
border-color: #e4e7ed;
transition: all 0.3s;
height: 36px;
line-height: 36px;
}
-.custom-input ::v-deep .el-input__inner:focus {
+.custom-input :deep(.el-input__inner:focus) {
border-color: #409eff;
box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
}
@@ -355,7 +568,7 @@
</style>
<style>
-/* ... (鍏ㄥ眬鏍峰紡閮ㄥ垎淇濇寔涓嶅彉) ... */
+/* 鍏ㄥ眬鏍峰紡閮ㄥ垎淇濇寔涓嶅彉 */
.text-button:hover {
background-color: #f0f9eb !important;
}
--
Gitblit v1.9.3