李红攀:V2.6.970,扫码枪入库
This commit is contained in:
@@ -20,3 +20,23 @@ export interface ProductSimple {
|
||||
export function getProductSimpleList() {
|
||||
return http.get<ProductSimple[]>('/erp/product/simple-list')
|
||||
}
|
||||
|
||||
/** 通过产品条码获得产品(响应 VO) */
|
||||
export interface ProductByBarCode {
|
||||
id?: number
|
||||
name?: string
|
||||
barCode?: string
|
||||
standard?: string
|
||||
unitId?: number
|
||||
unitName?: string
|
||||
categoryId?: number
|
||||
categoryName?: string
|
||||
purchasePrice?: number
|
||||
salePrice?: number
|
||||
minPrice?: number
|
||||
}
|
||||
|
||||
/** 通过产品条码获得产品 */
|
||||
export function getProductByBarCode(barCode: string) {
|
||||
return http.get<ProductByBarCode>(`/erp/product/get-by-bar-code?barCode=${encodeURIComponent(barCode)}`)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,24 @@ export function deleteWarehouse(id: number) {
|
||||
return http.delete<boolean>(`/erp/warehouse/delete?id=${id}`)
|
||||
}
|
||||
|
||||
/** 仓库精简信息 */
|
||||
export interface WarehouseSimple {
|
||||
id?: number
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** 获取仓库精简列表 */
|
||||
export function getWarehouseSimpleList() {
|
||||
return http.get<Warehouse[]>('/erp/warehouse/simple-list')
|
||||
}
|
||||
|
||||
/** 仓库条码信息 */
|
||||
export interface WarehouseByBarCode {
|
||||
id?: number
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** 通过仓库条码获取仓库 */
|
||||
export function getWarehouseByBarCode(barCode: string) {
|
||||
return http.get<WarehouseByBarCode>(`/erp/warehouse/get-by-bar-code?barCode=${encodeURIComponent(barCode)}`)
|
||||
}
|
||||
|
||||
145
src/pages-erp/stock-in/scan/components/recent-scan-list.vue
Normal file
145
src/pages-erp/stock-in/scan/components/recent-scan-list.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<view class="recent-scan-list">
|
||||
<view
|
||||
v-for="(record, index) in records"
|
||||
:key="record.id"
|
||||
class="recent-scan-list__item"
|
||||
:class="{ 'recent-scan-list__item--new': index === latestIndex }"
|
||||
>
|
||||
<view class="recent-scan-list__info">
|
||||
<view class="recent-scan-list__name">{{ record.productName }}</view>
|
||||
<view class="recent-scan-list__meta">
|
||||
<text>{{ record.warehouseName }}</text>
|
||||
<text v-if="record.locationCode"> · {{ record.locationCode }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="recent-scan-list__actions">
|
||||
<view class="recent-scan-list__count">
|
||||
<text class="count-btn" @tap="$emit('decrease', index)">-</text>
|
||||
<text class="count-num">{{ record.scanCount }}</text>
|
||||
<text class="count-btn" @tap="$emit('increase', index)">+</text>
|
||||
</view>
|
||||
<view class="recent-scan-list__delete" @tap="$emit('delete', index)">
|
||||
<wd-icon name="delete" size="32rpx" color="#ff4d4f" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="records.length === 0" class="recent-scan-list__empty">
|
||||
<text>暂无扫码记录</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
records: {
|
||||
id?: number
|
||||
productName?: string
|
||||
warehouseName?: string
|
||||
locationCode?: string
|
||||
scanCount: number
|
||||
}[]
|
||||
latestIndex?: number
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
delete: [index: number]
|
||||
increase: [index: number]
|
||||
decrease: [index: number]
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.recent-scan-list {
|
||||
max-height: 400rpx;
|
||||
overflow-y: auto;
|
||||
|
||||
&__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&--new {
|
||||
background: #e6f4ff;
|
||||
border-radius: 8rpx;
|
||||
padding: 16rpx;
|
||||
margin: 8rpx 0;
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__name {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #1f2329;
|
||||
margin-bottom: 4rpx;
|
||||
}
|
||||
|
||||
&__meta {
|
||||
font-size: 22rpx;
|
||||
color: #86909c;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
&__count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
|
||||
.count-btn {
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
line-height: 48rpx;
|
||||
text-align: center;
|
||||
background: #f7f8fa;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #1677ff;
|
||||
|
||||
&:active {
|
||||
background: #e6f4ff;
|
||||
}
|
||||
}
|
||||
|
||||
.count-num {
|
||||
min-width: 60rpx;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #1f2329;
|
||||
}
|
||||
}
|
||||
|
||||
&__delete {
|
||||
padding: 8rpx;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
&__empty {
|
||||
padding: 40rpx;
|
||||
text-align: center;
|
||||
color: #86909c;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
66
src/pages-erp/stock-in/scan/components/scan-context-bar.vue
Normal file
66
src/pages-erp/stock-in/scan/components/scan-context-bar.vue
Normal file
@@ -0,0 +1,66 @@
|
||||
<template>
|
||||
<view class="scan-context-bar">
|
||||
<view class="scan-context-bar__item">
|
||||
<text class="scan-context-bar__label">仓库</text>
|
||||
<text class="scan-context-bar__value">{{ warehouseName || '未选择' }}</text>
|
||||
</view>
|
||||
<view class="scan-context-bar__divider" />
|
||||
<view class="scan-context-bar__item">
|
||||
<text class="scan-context-bar__label">已扫</text>
|
||||
<text class="scan-context-bar__value scan-context-bar__value--highlight">{{ scannedCount }}</text>
|
||||
</view>
|
||||
<view class="scan-context-bar__divider" />
|
||||
<view class="scan-context-bar__item">
|
||||
<text class="scan-context-bar__label">记录</text>
|
||||
<text class="scan-context-bar__value scan-context-bar__value--highlight">{{ recordCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
warehouseName?: string
|
||||
scannedCount: number
|
||||
recordCount: number
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.scan-context-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
padding: 20rpx 24rpx;
|
||||
background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 16rpx;
|
||||
|
||||
&__item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4rpx;
|
||||
}
|
||||
|
||||
&__label {
|
||||
font-size: 22rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
&__value {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
|
||||
&--highlight {
|
||||
font-size: 36rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&__divider {
|
||||
width: 2rpx;
|
||||
height: 40rpx;
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
41
src/pages-erp/stock-in/scan/components/scan-feedback-bar.vue
Normal file
41
src/pages-erp/stock-in/scan/components/scan-feedback-bar.vue
Normal file
@@ -0,0 +1,41 @@
|
||||
<template>
|
||||
<view v-if="tone !== 'idle'" class="scan-feedback-bar" :class="`scan-feedback-bar--${tone}`">
|
||||
<text class="scan-feedback-bar__text">{{ message }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
tone: 'success' | 'error' | 'idle'
|
||||
message: string
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.scan-feedback-bar {
|
||||
padding: 16rpx 20rpx;
|
||||
border-radius: 12rpx;
|
||||
margin-top: 16rpx;
|
||||
|
||||
&--success {
|
||||
background: #f6ffed;
|
||||
border: 2rpx solid #b7eb8f;
|
||||
.scan-feedback-bar__text {
|
||||
color: #52c41a;
|
||||
}
|
||||
}
|
||||
|
||||
&--error {
|
||||
background: #fff2f0;
|
||||
border: 2rpx solid #ffccc7;
|
||||
.scan-feedback-bar__text {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
}
|
||||
|
||||
&__text {
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
835
src/pages-erp/stock-in/scan/index.vue
Normal file
835
src/pages-erp/stock-in/scan/index.vue
Normal file
@@ -0,0 +1,835 @@
|
||||
<template>
|
||||
<view class="yd-page-container scan-page">
|
||||
<wd-navbar
|
||||
title="扫码入库"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view class="scan-page__content">
|
||||
<!-- 顶部上下文条 -->
|
||||
<ScanContextBar
|
||||
:warehouse-name="currentWarehouse?.name"
|
||||
:scanned-count="scannedTotalCount"
|
||||
:record-count="records.length"
|
||||
/>
|
||||
|
||||
<!-- 扫码工作台 -->
|
||||
<view class="scan-workbench">
|
||||
<!-- 扫码面板 -->
|
||||
<view class="scan-panel">
|
||||
<!-- 步骤指示器 -->
|
||||
<view class="scan-step-indicator">
|
||||
<view class="scan-step-indicator__item" :class="{ 'active': step === 'idle', 'done': step !== 'idle' }">
|
||||
<view class="scan-step-indicator__dot">1</view>
|
||||
<text>扫仓库</text>
|
||||
</view>
|
||||
<view class="scan-step-indicator__line" :class="{ 'done': step !== 'idle' }" />
|
||||
<view class="scan-step-indicator__item" :class="{ 'active': step === 'warehouse-scanned' }">
|
||||
<view class="scan-step-indicator__dot">2</view>
|
||||
<text>扫产品</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 当前作业提示 -->
|
||||
<view class="scan-current-hint">
|
||||
<text v-if="step === 'idle'">请扫描仓库条码</text>
|
||||
<text v-else>产品已入库,请继续扫码</text>
|
||||
</view>
|
||||
|
||||
<!-- 仓库扫码区 -->
|
||||
<view class="scan-row" :class="{ 'scan-row--dim': step !== 'idle' }">
|
||||
<input
|
||||
v-model="warehouseBarCode"
|
||||
class="scan-field"
|
||||
:class="{ 'scan-field--active': step === 'idle' }"
|
||||
placeholder="扫描仓库条码"
|
||||
confirm-type="next"
|
||||
:focus="warehouseInputFocus"
|
||||
:cursor-spacing="20"
|
||||
:adjust-position="true"
|
||||
:hold-keyboard="true"
|
||||
@blur="handleWarehouseBlur"
|
||||
@confirm="(e) => handleWarehouseScan(e.detail.value)"
|
||||
>
|
||||
<button class="scan-camera-btn" :disabled="scanLoading" @tap="handleCameraScan('warehouse')">
|
||||
拍
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 仓库预览 -->
|
||||
<view class="scan-location-preview" v-if="currentWarehouse">
|
||||
<view class="scan-location-preview__row">
|
||||
<text class="scan-location-preview__label">仓库</text>
|
||||
<text class="scan-location-preview__value scan-location-preview__value--code">
|
||||
{{ currentWarehouse.name }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 产品扫码区 -->
|
||||
<view class="scan-row" :class="{ 'scan-row--dim': step === 'idle' }">
|
||||
<input
|
||||
v-model="productBarCode"
|
||||
class="scan-field"
|
||||
:class="{ 'scan-field--active': step !== 'idle' }"
|
||||
placeholder="扫描产品条码"
|
||||
confirm-type="done"
|
||||
:focus="productInputFocus"
|
||||
:cursor-spacing="20"
|
||||
:adjust-position="true"
|
||||
:hold-keyboard="true"
|
||||
@blur="handleProductBlur"
|
||||
@confirm="(e) => handleProductScan(e.detail.value)"
|
||||
>
|
||||
<button class="scan-camera-btn" :disabled="scanLoading || step === 'idle'" @tap="handleCameraScan('product')">
|
||||
拍
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 产品预览 -->
|
||||
<view class="scan-product-preview" v-if="productPreview">
|
||||
<view class="scan-product-preview__row">
|
||||
<text class="scan-product-preview__label">产品</text>
|
||||
<text class="scan-product-preview__value scan-product-preview__value--name">
|
||||
{{ productPreview.name }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="scan-product-preview__row">
|
||||
<text class="scan-product-preview__label">规格</text>
|
||||
<text class="scan-product-preview__value">{{ productPreview.standard || '-' }}</text>
|
||||
</view>
|
||||
<view class="scan-product-preview__row">
|
||||
<text class="scan-product-preview__label">条码</text>
|
||||
<text class="scan-product-preview__value">{{ productPreview.barCode || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<ScanFeedbackBar :tone="feedbackTone" :message="feedbackMessage" />
|
||||
</view>
|
||||
|
||||
<!-- 扫码记录列表 -->
|
||||
<view class="scan-panel scan-panel--list">
|
||||
<view class="scan-panel__header">
|
||||
<view class="scan-panel__title">扫码记录</view>
|
||||
<view class="scan-panel__meta">共 {{ records.length }} 条</view>
|
||||
</view>
|
||||
<RecentScanList
|
||||
:records="records"
|
||||
:latest-index="latestRecordIndex"
|
||||
@delete="handleDeleteRecord"
|
||||
@increase="handleIncreaseCount"
|
||||
@decrease="handleDecreaseCount"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 提交栏 -->
|
||||
<view class="scan-footer">
|
||||
<button class="scan-footer__clear" @tap="handleClearAll">清空记录</button>
|
||||
<button class="scan-footer__submit" :loading="submitting" @tap="handleSubmit">提交入库</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { getWarehouseByBarCode } from '@/api/erp/warehouse'
|
||||
import { getProductByBarCode, type ProductByBarCode } from '@/api/erp/product'
|
||||
import { createStockIn } from '@/api/erp/stock-in'
|
||||
import ScanFeedbackBar from '@/pages-erp/stock-in/scan/components/scan-feedback-bar.vue'
|
||||
import RecentScanList from '@/pages-erp/stock-in/scan/components/recent-scan-list.vue'
|
||||
import ScanContextBar from '@/pages-erp/stock-in/scan/components/scan-context-bar.vue'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
/** 扫码入库记录 */
|
||||
export interface ScanRecord {
|
||||
id?: number
|
||||
productId?: number
|
||||
productName?: string
|
||||
productSpec?: string
|
||||
productBarCode?: string
|
||||
productUnit?: string
|
||||
productPrice?: number
|
||||
warehouseId?: number
|
||||
warehouseName?: string
|
||||
scanCount: number
|
||||
scanTime?: string
|
||||
}
|
||||
|
||||
type Step = 'idle' | 'warehouse-scanned'
|
||||
|
||||
const toast = useToast()
|
||||
|
||||
// 扫码步骤
|
||||
const step = ref<Step>('idle')
|
||||
|
||||
// 扫码数据
|
||||
const warehouseBarCode = ref('')
|
||||
const currentWarehouse = ref<{ id: number; name: string } | null>(null)
|
||||
const productBarCode = ref('')
|
||||
const productPreview = ref<ProductByBarCode | null>(null)
|
||||
|
||||
// 状态
|
||||
const scanLoading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const records = ref<ScanRecord[]>([])
|
||||
const feedbackTone = ref<'success' | 'error' | 'idle'>('idle')
|
||||
const feedbackMessage = ref('')
|
||||
|
||||
// 输入框焦点控制
|
||||
const warehouseInputFocus = ref(false)
|
||||
const productInputFocus = ref(false)
|
||||
|
||||
// 计算属性
|
||||
const scannedTotalCount = computed(() =>
|
||||
records.value.reduce((sum, r) => sum + Number(r.scanCount || 0), 0),
|
||||
)
|
||||
|
||||
const latestRecordIndex = computed(() => {
|
||||
if (records.value.length === 0) return undefined
|
||||
return records.value.length - 1
|
||||
})
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
if (records.value.length > 0) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出吗?未保存的数据将丢失',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
navigateBackPlus('/pages-erp/stock-in/index')
|
||||
}
|
||||
},
|
||||
})
|
||||
} else {
|
||||
navigateBackPlus('/pages-erp/stock-in/index')
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化页面 */
|
||||
onMounted(async () => {
|
||||
await nextTick()
|
||||
setTimeout(() => {
|
||||
focusWarehouseInput()
|
||||
}, 300)
|
||||
})
|
||||
|
||||
const ERROR_DISPLAY_MS = 2000
|
||||
|
||||
/** 聚焦仓库码输入框 */
|
||||
function focusWarehouseInput() {
|
||||
productInputFocus.value = false
|
||||
warehouseInputFocus.value = false
|
||||
nextTick(() => {
|
||||
warehouseInputFocus.value = true
|
||||
})
|
||||
}
|
||||
|
||||
/** 仓库输入框失焦处理 */
|
||||
function handleWarehouseBlur() {
|
||||
if (step.value === 'idle' && !scanLoading.value) {
|
||||
setTimeout(() => {
|
||||
if (step.value === 'idle') {
|
||||
focusWarehouseInput()
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
/** 产品输入框失焦处理 */
|
||||
function handleProductBlur() {
|
||||
if (step.value === 'warehouse-scanned' && !scanLoading.value) {
|
||||
setTimeout(() => {
|
||||
if (step.value === 'warehouse-scanned') {
|
||||
focusProductInput()
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
/** 扫仓库码(相机扫码调用) */
|
||||
async function handleWarehouseScan(rawValue?: string) {
|
||||
const code = normalizeScanCode(rawValue || warehouseBarCode.value)
|
||||
if (!code) {
|
||||
setErrorFeedback('请先扫描仓库条码')
|
||||
return
|
||||
}
|
||||
|
||||
scanLoading.value = true
|
||||
try {
|
||||
try {
|
||||
const warehouse = await getWarehouseByBarCode(code)
|
||||
currentWarehouse.value = warehouse
|
||||
} catch {
|
||||
setErrorFeedback(`仓库码 ${code} 不存在`)
|
||||
resetToIdle()
|
||||
return
|
||||
}
|
||||
|
||||
if (!currentWarehouse.value?.id) {
|
||||
setErrorFeedback(`仓库码 ${code} 未找到对应仓库`)
|
||||
resetToIdle()
|
||||
return
|
||||
}
|
||||
|
||||
warehouseBarCode.value = code
|
||||
step.value = 'warehouse-scanned'
|
||||
productBarCode.value = ''
|
||||
productPreview.value = null
|
||||
clearFeedback()
|
||||
|
||||
focusProductInput()
|
||||
} finally {
|
||||
scanLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 聚焦产品码输入框 */
|
||||
function focusProductInput() {
|
||||
warehouseInputFocus.value = false
|
||||
productInputFocus.value = false
|
||||
nextTick(() => {
|
||||
productInputFocus.value = true
|
||||
})
|
||||
}
|
||||
|
||||
/** 扫产品码(相机扫码调用) */
|
||||
async function handleProductScan(rawValue?: string) {
|
||||
const code = normalizeScanCode(rawValue || productBarCode.value)
|
||||
if (!code) {
|
||||
setErrorFeedback('请先扫描产品条码')
|
||||
return
|
||||
}
|
||||
|
||||
if (!currentWarehouse.value) {
|
||||
setErrorFeedback('请先扫描仓库条码')
|
||||
step.value = 'idle'
|
||||
return
|
||||
}
|
||||
|
||||
scanLoading.value = true
|
||||
try {
|
||||
try {
|
||||
productPreview.value = await getProductByBarCode(code)
|
||||
} catch {
|
||||
setErrorFeedback(`条码 ${code} 未匹配到产品`)
|
||||
resetToProductScan()
|
||||
return
|
||||
}
|
||||
|
||||
if (!productPreview.value?.id) {
|
||||
setErrorFeedback(`条码 ${code} 未匹配到产品`)
|
||||
resetToProductScan()
|
||||
return
|
||||
}
|
||||
|
||||
productBarCode.value = code
|
||||
clearFeedback()
|
||||
|
||||
// 自动确认入库
|
||||
nextTick(() => handleConfirm())
|
||||
} finally {
|
||||
scanLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 确认入库 */
|
||||
async function handleConfirm() {
|
||||
if (!currentWarehouse.value || !productPreview.value) return
|
||||
|
||||
// 检查是否已存在相同记录
|
||||
const existingIndex = records.value.findIndex(r =>
|
||||
r.warehouseId === currentWarehouse.value!.id &&
|
||||
r.productId === productPreview.value!.id
|
||||
)
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
records.value[existingIndex].scanCount += 1
|
||||
} else {
|
||||
const record: ScanRecord = {
|
||||
id: Date.now(),
|
||||
productId: productPreview.value!.id,
|
||||
productName: productPreview.value!.name,
|
||||
productSpec: productPreview.value!.standard,
|
||||
productBarCode: productPreview.value!.barCode,
|
||||
productUnit: productPreview.value!.unitName,
|
||||
productPrice: Number(productPreview.value!.minPrice || 0),
|
||||
warehouseId: currentWarehouse.value!.id,
|
||||
warehouseName: currentWarehouse.value!.name,
|
||||
scanCount: 1,
|
||||
scanTime: new Date().toISOString(),
|
||||
}
|
||||
records.value.push(record)
|
||||
}
|
||||
|
||||
const productName = productPreview.value!.name
|
||||
clearScanInputs()
|
||||
setSuccessFeedback(`${productName} → ${currentWarehouse.value!.name} 入库成功`)
|
||||
|
||||
await nextTick()
|
||||
focusProductInput()
|
||||
}
|
||||
|
||||
/** 重置到初始状态 */
|
||||
function resetToIdle() {
|
||||
clearScanInputs()
|
||||
currentWarehouse.value = null
|
||||
productPreview.value = null
|
||||
step.value = 'idle'
|
||||
setTimeout(() => {
|
||||
clearFeedback()
|
||||
focusWarehouseInput()
|
||||
}, ERROR_DISPLAY_MS)
|
||||
}
|
||||
|
||||
/** 重置到产品扫码阶段 */
|
||||
function resetToProductScan() {
|
||||
productBarCode.value = ''
|
||||
productPreview.value = null
|
||||
setTimeout(() => {
|
||||
clearFeedback()
|
||||
focusProductInput()
|
||||
}, ERROR_DISPLAY_MS)
|
||||
}
|
||||
|
||||
/** 相机扫码 */
|
||||
function handleCameraScan(target: 'warehouse' | 'product') {
|
||||
if (scanLoading.value) return
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
plus.android.requestPermissions(
|
||||
['android.permission.CAMERA'],
|
||||
function(result) {
|
||||
const granted = result.granted
|
||||
if (granted && granted.length > 0) {
|
||||
doScan(target)
|
||||
} else {
|
||||
toast.error('请在设置中开启相机权限')
|
||||
uni.openSetting()
|
||||
}
|
||||
},
|
||||
function() {
|
||||
toast.error('相机权限获取失败')
|
||||
},
|
||||
)
|
||||
// #endif
|
||||
|
||||
// #ifndef APP-PLUS
|
||||
doScan(target)
|
||||
// #endif
|
||||
}
|
||||
|
||||
function doScan(target: 'warehouse' | 'product') {
|
||||
uni.scanCode({
|
||||
onlyFromCamera: true,
|
||||
success: async (result) => {
|
||||
const code = normalizeScanResult(result)
|
||||
if (!code) return
|
||||
|
||||
if (target === 'warehouse') {
|
||||
warehouseBarCode.value = code
|
||||
await handleWarehouseScan()
|
||||
} else {
|
||||
productBarCode.value = code
|
||||
await handleProductScan()
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
if (String(error?.errMsg || '').includes('cancel')) return
|
||||
toast.error('相机扫码失败,请重试')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除单条记录 */
|
||||
function handleDeleteRecord(index: number) {
|
||||
records.value.splice(index, 1)
|
||||
}
|
||||
|
||||
/** 增加数量 */
|
||||
function handleIncreaseCount(index: number) {
|
||||
if (records.value[index]) {
|
||||
records.value[index].scanCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
/** 减少数量 */
|
||||
function handleDecreaseCount(index: number) {
|
||||
if (records.value[index] && records.value[index].scanCount > 1) {
|
||||
records.value[index].scanCount -= 1
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空所有记录 */
|
||||
function handleClearAll() {
|
||||
if (records.value.length === 0) return
|
||||
uni.showModal({
|
||||
title: '确认清空',
|
||||
content: '确定要清空所有扫码记录吗?',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return
|
||||
records.value = []
|
||||
clearFeedback()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 提交入库单 */
|
||||
async function handleSubmit() {
|
||||
if (records.value.length === 0) {
|
||||
toast.warning('暂无扫码记录')
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const items = records.value.map(r => ({
|
||||
warehouseId: r.warehouseId,
|
||||
productId: r.productId,
|
||||
productPrice: r.productPrice,
|
||||
count: r.scanCount,
|
||||
supplierId: 1,
|
||||
}))
|
||||
|
||||
await createStockIn({
|
||||
inTime: new Date().toISOString(),
|
||||
items,
|
||||
})
|
||||
|
||||
toast.success(`已提交 ${records.value.length} 条入库记录`)
|
||||
records.value = []
|
||||
clearFeedback()
|
||||
resetToIdle()
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空本次扫码输入 */
|
||||
function clearScanInputs() {
|
||||
warehouseBarCode.value = ''
|
||||
productBarCode.value = ''
|
||||
productPreview.value = null
|
||||
}
|
||||
|
||||
function setSuccessFeedback(message: string) {
|
||||
feedbackTone.value = 'success'
|
||||
feedbackMessage.value = message
|
||||
}
|
||||
|
||||
function setErrorFeedback(message: string) {
|
||||
feedbackTone.value = 'error'
|
||||
feedbackMessage.value = message
|
||||
}
|
||||
|
||||
function clearFeedback() {
|
||||
feedbackTone.value = 'idle'
|
||||
feedbackMessage.value = ''
|
||||
}
|
||||
|
||||
/** 规范化扫码结果 */
|
||||
function normalizeScanCode(value: string): string {
|
||||
if (!value) return ''
|
||||
let result = value.trim()
|
||||
const prefixes = ['CODE128:', 'CODE39:', 'EAN13:', 'QR:', 'DATA:', 'MECARD:', 'VCARD:']
|
||||
for (const prefix of prefixes) {
|
||||
if (result.startsWith(prefix)) {
|
||||
result = result.substring(prefix.length)
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** 规范化相机扫码结果 */
|
||||
function normalizeScanResult(result: UniApp.ScanCodeSuccessRes): string {
|
||||
if (!result) return ''
|
||||
const value = result.result || result.code || ''
|
||||
return normalizeScanCode(value)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.scan-page {
|
||||
background: #f4f6f8;
|
||||
min-height: 100vh;
|
||||
|
||||
&__content {
|
||||
padding: 24rpx;
|
||||
padding-top: calc(24rpx + env(safe-area-inset-top) + 88rpx);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
.scan-workbench {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.scan-panel {
|
||||
padding: 24rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #fff;
|
||||
|
||||
&--list {
|
||||
padding-bottom: 8rpx;
|
||||
}
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
&__title {
|
||||
color: #1f2329;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&__meta {
|
||||
color: #86909c;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
}
|
||||
|
||||
// 步骤指示器
|
||||
.scan-step-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24rpx;
|
||||
|
||||
&__item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
|
||||
text {
|
||||
font-size: 22rpx;
|
||||
color: #86909c;
|
||||
}
|
||||
|
||||
&.active text {
|
||||
color: #1677ff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.done text {
|
||||
color: #52c41a;
|
||||
}
|
||||
}
|
||||
|
||||
&__dot {
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
line-height: 48rpx;
|
||||
border-radius: 50%;
|
||||
background: #f2f3f5;
|
||||
color: #86909c;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&__item.active &__dot {
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&__item.done &__dot {
|
||||
background: #52c41a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&__line {
|
||||
flex: 1;
|
||||
height: 2rpx;
|
||||
background: #e5e6eb;
|
||||
margin: 0 12rpx;
|
||||
margin-bottom: 28rpx;
|
||||
max-width: 80rpx;
|
||||
|
||||
&.done {
|
||||
background: #52c41a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当前作业提示
|
||||
.scan-current-hint {
|
||||
text-align: center;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #1f2329;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
// 输入行
|
||||
.scan-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
margin-bottom: 16rpx;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
&--dim {
|
||||
opacity: 0.4;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.scan-field {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
padding: 0 24rpx;
|
||||
line-height: 88rpx;
|
||||
border: 2rpx solid #e5e6eb;
|
||||
border-radius: 14rpx;
|
||||
background: #f7f8fa;
|
||||
color: #1f2329;
|
||||
box-sizing: border-box;
|
||||
font-size: 28rpx;
|
||||
|
||||
&--active {
|
||||
border-color: #1677ff;
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 4rpx rgba(22, 119, 255, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.scan-camera-btn {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
padding: 0;
|
||||
border: none;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:active { opacity: 0.85; }
|
||||
&[disabled] { background: #d9d9d9; }
|
||||
}
|
||||
|
||||
// 仓库预览
|
||||
.scan-location-preview {
|
||||
margin-bottom: 16rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #f6fff0;
|
||||
border: 2rpx solid #b7eb8f;
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 6rpx 0;
|
||||
}
|
||||
|
||||
&__label {
|
||||
color: #4e5969;
|
||||
font-size: 24rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__value {
|
||||
color: #1f2329;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
margin-right: 12rpx;
|
||||
|
||||
&--code {
|
||||
color: #52c41a;
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 产品预览
|
||||
.scan-product-preview {
|
||||
margin-bottom: 16rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #f0f5ff;
|
||||
border: 2rpx solid #adc6ff;
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 6rpx 0;
|
||||
}
|
||||
|
||||
&__label {
|
||||
color: #4e5969;
|
||||
font-size: 24rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__value {
|
||||
color: #1f2329;
|
||||
font-size: 24rpx;
|
||||
text-align: right;
|
||||
|
||||
&--name {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 底部栏
|
||||
.scan-footer {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
padding: 20rpx 0 calc(20rpx + env(safe-area-inset-bottom));
|
||||
background: #f4f6f8;
|
||||
|
||||
&__clear {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #fff;
|
||||
color: #4e5969;
|
||||
font-size: 28rpx;
|
||||
border: 2rpx solid #e5e6eb;
|
||||
}
|
||||
|
||||
&__submit {
|
||||
flex: 2;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -146,6 +146,14 @@ const menuGroupsData: MenuGroup[] = [
|
||||
iconColor: '#13c2c2',
|
||||
permission: 'erp:stock-in:query',
|
||||
},
|
||||
{
|
||||
key: 'stockScan',
|
||||
name: '扫码入库',
|
||||
icon: 'scan',
|
||||
url: '/pages-erp/stock-in/scan/index',
|
||||
iconColor: '#1890ff',
|
||||
permission: 'erp:stock-in:create',
|
||||
},
|
||||
{
|
||||
key: 'stockOut',
|
||||
name: '其他出库',
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user