From 86c656b02f308d13db6533f02c59223436535e67 Mon Sep 17 00:00:00 2001 From: hwj Date: Mon, 29 Jun 2026 14:21:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BA=A7=E5=93=81=E5=87=BA?= =?UTF-8?q?=E5=BA=93-=E4=BA=A7=E5=93=81=E6=B7=BB=E5=8A=A0=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E5=BD=95=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/productOutbound/create.vue | 97 ++++++++++--------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/src/pages_function/pages/productOutbound/create.vue b/src/pages_function/pages/productOutbound/create.vue index 0042299..bd91c8a 100644 --- a/src/pages_function/pages/productOutbound/create.vue +++ b/src/pages_function/pages/productOutbound/create.vue @@ -4,14 +4,20 @@ - + + + + + + 选择产品 @@ -160,7 +166,7 @@ import { onReady, onShow } from '@dcloudio/uni-app' import { useI18n } from 'vue-i18n' import NavBar from '@/components/common/NavBar.vue' import { createProductOutbound } from '@/api/mes/productOutbound' -import { getProduct, getProductPage } from '@/api/erp/productInfo' +import { getProduct } from '@/api/erp/productInfo' import { setDefaultOperatorFromCurrentUser } from '@/utils/currentUser' const { t } = useI18n() @@ -173,6 +179,9 @@ const attachmentList = ref([]) const scanCodeInput = ref('') const focusNoKeyboardRef = ref(null) const keywordInputSelector = '#product-outbound-scan-input input, input#product-outbound-scan-input' +const PRODUCT_CATEGORY_TYPE = 1 +const SCAN_AUTO_SEARCH_DELAY = 300 +let productScanTimer = null const totalPalletCount = computed(() => itemList.value.reduce((sum, item) => sum + getPalletCount(item), 0)) const totalPackageCount = computed(() => itemList.value.reduce((sum, item) => sum + (Number(item.packageCount) || 0), 0)) @@ -211,52 +220,46 @@ function goSelectOperator() { getApp().globalData._productOutboundUserFrom = 'outbound' uni.navigateTo({ url: '/pages_function/pages/moldRepair/userSelect?field=operator&from=productOutbound' }) } +function getProductMaterialScanCode(value) { + const text = String(value || '').trim() + const match = text.match(/^PRODUCTMATERIAL[-:]?\s*(.+)$/i) + return match ? match[1].trim() : '' +} +function scheduleProductScanSearch(value) { + if (!getProductMaterialScanCode(value)) return + if (productScanTimer) clearTimeout(productScanTimer) + productScanTimer = setTimeout(() => { + productScanTimer = null + onScanInputConfirm() + }, SCAN_AUTO_SEARCH_DELAY) +} +function onScanInput(e) { + scheduleProductScanSearch(e?.detail?.value ?? scanCodeInput.value) +} function onScanInputConfirm() { - const code = scanCodeInput.value.trim() + if (productScanTimer) { + clearTimeout(productScanTimer) + productScanTimer = null + } + const code = getProductMaterialScanCode(scanCodeInput.value) if (!code) return handleScanCode(code) } -function normalizeProductPageList(res) { - const root = res && res.data !== undefined ? res.data : res - return Array.isArray(root) ? root : (root?.list || root?.rows || root?.records || []) -} async function findProductByScanCode(code) { - const rawCode = String(code || '').trim() - const productId = rawCode.toUpperCase().startsWith('PRODUCT-') - ? rawCode.replace(/PRODUCT-/i, '') - : (/^\d+$/.test(rawCode) ? rawCode : null) - if (productId) { - try { - const res = await getProduct(productId) - const detail = res?.data || res - if (detail?.id) return detail - } catch (e) {} - } - for (let pageNo = 1; pageNo <= 5; pageNo += 1) { - const res = await getProductPage({ pageNo, pageSize: 100, categoryType: 1 }) - const list = normalizeProductPageList(res) - const matched = list.find((item) => - String(item.id || '') === rawCode || - String(item.barCode || '') === rawCode || - String(item.code || '') === rawCode - ) - if (matched) { - try { - const detailRes = await getProduct(matched.id) - return { ...matched, ...(detailRes?.data || detailRes || {}) } - } catch (e) { - return matched - } - } - if (list.length < 100) break - } - return null + const id = String(code || '').trim() + if (!/^\d+$/.test(id)) return null + const res = await getProduct(id) + const detail = res?.data || res + if (!detail?.id) return null + if (detail.categoryType && Number(detail.categoryType) !== PRODUCT_CATEGORY_TYPE) return null + return detail } async function handleScanCode(code) { try { const detail = await findProductByScanCode(code) if (detail?.id) { getApp().globalData._productOutboundProductSelectResult = detail + scanCodeInput.value = '' uni.navigateTo({ url: '/pages_function/pages/productOutbound/productConfirm' }) } else { uni.showToast({ title: '\u672a\u627e\u5230\u4ea7\u54c1: ' + code, icon: 'none' }) @@ -427,8 +430,10 @@ onShow(() => {