手持机平库入 新增,修改,删除库存记录

This commit is contained in:
liuhanqing
2026-01-20 13:32:45 +08:00
parent 149a036f82
commit f4d5e2c714
20 changed files with 500 additions and 237 deletions

View File

@@ -2,89 +2,76 @@
<view class="container">
<view class="form card">
<view class="field">
<text class="label">托盘条码</text>
<uni-easyinput ref="trayInput" v-model="trayCode" @input="onTrayInput" placeholder="请输入托盘条码" :disabled="loadingTray" :clearable="true" >
<template #right>
<text class="scan-icon" @click="handleScanTray">📷</text>
</template>
</uni-easyinput>
<text class="input-label">仓库</text>
<uni-data-select
v-model="warehouseId"
:localdata="warehouseList"
:clear="false"
placeholder="请选择仓库"
/>
</view>
<view class="field">
<text class="label">物料条码</text>
<uni-easyinput v-model="materialCode" @input="onMaterialInput" placeholder="请输入物料条码" :clearable="true">
<text class="label">入库子单</text>
<uni-easyinput v-model="materialCode" @input="onMaterialInput" placeholder="请输入入库子单编码"
:clearable="true">
<template #right>
<text class="scan-icon" @click="handleScanMaterial">📷</text>
</template>
</uni-easyinput>
</view>
<view class="field">
<text class="input-label">仓库</text>
<uni-data-select
v-model="warehouseId"
:localdata="warehouseList"
:clear="false"
placeholder="请选择仓库"
/>
</view>
</view>
<view class="tray-info card" v-if="trayMaterials.length">
<text class="section-title">托盘已绑定物料</text>
<view class="list">
<view class="item" v-for="(m, idx) in trayMaterials" :key="idx">
<view class="item-header">
<text class="name">{{ m.productName || '未知物料' }}</text>
<text class="qty-tag">× {{ m.quantity }}</text>
</view>
<!-- <text class="meta">编码:{{ m.productId}}</text> -->
</view>
</view>
</view>
<view class="tray-info card" v-else>
<text class="section-title">托盘已绑定物料</text>
<view class="empty">暂无数据</view>
</view>
<uni-popup ref="detailPopup" type="bottom">
<uni-popup ref="detailPopup" type="bottom">
<view class="popup">
<text class="popup-title">物料详情</text>
<view v-if="materialDetail">
<view class="row"><text class="row-label">物料名称</text><text class="row-value">{{ materialDetail.productName }}</text></view>
<view class="row"><text class="row-label">物料编码</text><text class="row-value">{{ materialDetail.productId }}</text></view>
<view class="row"><text class="row-label">可用数量</text><text class="row-value">{{ materialDetail.quantity }}</text></view>
<view class="row">
<text class="row-label">绑定数量</text>
<uni-easyinput v-model="bindQty" type="number" placeholder="输入数量" />
<text class="row-label">物料名称</text>
<text class="row-value">{{ materialDetail.productName }}</text>
</view>
<view class="row">
<text class="row-label">物料编码</text>
<text class="row-value">{{ materialDetail.productId }}</text>
</view>
<view class="row">
<text class="row-label">可用数量</text>
<text class="row-value">{{ materialDetail.quantityX }}</text>
</view>
<view class="row">
<text class="row-label">入库数量</text>
<uni-easyinput v-model="bindQty" type="number" placeholder="输入数量"/>
</view>
<view class="actions">
<button class="btn primary" @click="handleBindTray" :disabled="isBinding">绑定托盘</button>
<button class="btn primary" @click="handleConfirmIn" :disabled="isBinding">确认入库</button>
<button class="btn secondary" @click="closePopup">取消</button>
</view>
</view>
</view>
</uni-popup>
<!-- 页脚操作区:确认入库 -->
<view class="footer-actions">
<button class="confirm-btn" @click="handleConfirmIn" :disabled="!trayCode || isConfirming">
{{ isConfirming ? '入库中...' : '确认入库' }}
</button>
</view>
<!-- <view class="footer-actions">-->
<!-- <button class="confirm-btn" @click="handleConfirmIn" :disabled="!trayCode || isConfirming">-->
<!-- {{ isConfirming ? '入库中...' : '确认入库' }}-->
<!-- </button>-->
<!-- </view>-->
</view>
</template>
<script>
import { getTrayInfo, bindTray, getOrderGoods, addInJobpk } from '@/api/in/order.js'
import { getBasWarehouList } from '@/api/bas/bas.js'
import {addInJobpk, bindTray, getOrderGoods, getTrayInfo} from '@/api/in/order.js'
import {getBasWarehouList} from '@/api/bas/bas.js'
export default {
data() {
return {
trayCode: '',
materialCode: '',
warehouseId:'',
warehouseList: [],
warehouseId: '',
warehouseList: [],
trayMaterials: [],
loadingTray: false,
materialDetail: null,
@@ -97,87 +84,90 @@ export default {
},
onReady() {
// 获取仓库列表
this.getWarehouseList()
// 获取仓库列表
this.getWarehouseList()
},
methods: {
// 获取仓库列表
async getWarehouseList() {
try {
const response = await getBasWarehouList({
pageNum:1,
pageSize:100,
warehouseType:2
})
if (response.code === 200) {
this.warehouseList = response.rows.map(item => ({
value: item.warehouseId,
text: item.warehouseName
// type: item.warehouseType
}))
}
} catch (error) {
console.error('获取仓库列表失败:', error)
uni.showToast({
title: '获取仓库列表失败',
icon: 'none'
})
}
},
// 获取仓库列表
async getWarehouseList() {
try {
const response = await getBasWarehouList({
pageNum: 1,
pageSize: 100,
warehouseType: 2
})
if (response.code === 200) {
this.warehouseList = response.rows.map(item => ({
value: item.warehouseId,
text: item.warehouseName
// type: item.warehouseType
}))
}
} catch (error) {
console.error('获取仓库列表失败:', error)
uni.showToast({
title: '获取仓库列表失败',
icon: 'none'
})
}
},
mapTrayMaterials(res) {
const list = Array.isArray(res.data) ? res.data : (Array.isArray(res.rows) ? res.rows : (res.data.rows || []))
return list.map(item => ({
productId: item.productId ,
materialDesc: item.productName ,
productId: item.productId,
materialDesc: item.productName,
quantity: item.quantity,
}))
},
async onTrayInput(val) {
this.trayCode = String(val || '').trim()
if (!this.trayCode) { this.trayMaterials = []; return }
if (!this.trayCode) {
this.trayMaterials = [];
return
}
try {
this.loadingTray = true
const res = await getTrayInfo(this.trayCode)
this.trayMaterials = res.data
} catch (e) {
console.error('getTrayInfo error', e)
uni.showToast({ title: '查询托盘失败', icon: 'none' })
uni.showToast({title: '查询托盘失败', icon: 'none'})
} finally {
this.loadingTray = false
}
}
},
// 确认入库
async handleConfirmIn() {
if (!this.trayCode) {
uni.showToast({ title: '请先输入托盘条码', icon: 'none' })
if (!this.warehouseId) {
uni.showToast({title: '请先选择仓库', icon: 'none'})
return
}
if (!this.warehouseId) {
uni.showToast({ title: '请先选择仓库', icon: 'none' })
return
}
try {
this.isConfirming = true
const payload = {
trayCode: this.trayCode,
warehouseId: this.warehouseId,
stockinDetailId: this.materialCode,
inQuantity: this.bindQty
}
const resp = await addInJobpk(payload)
if (resp && resp.code === 200) {
uni.showToast({ title: '入库成功', icon: 'success' })
uni.showToast({title: '入库成功', icon: 'success'})
// 清空托盘与列表,便于下一次操作
this.trayCode = ''
this.trayMaterials = []
} else {
uni.showToast({ title: (resp && resp.msg) || '入库失败', icon: 'none' })
uni.showToast({title: (resp && resp.msg) || '入库失败', icon: 'none'})
}
} catch (e) {
console.error('addInJob error', e)
uni.showToast({ title: '入库失败', icon: 'none' })
uni.showToast({title: '入库失败', icon: 'none'})
} finally {
this.isConfirming = false
this.isBinding = false
}
},
extractMaterialDetail(res) {
@@ -201,43 +191,23 @@ export default {
this.materialCode = String(val || '').trim()
if (!this.materialCode) return
try {
const res = await getOrderGoods({ stockinDetailId: this.materialCode })
const res = await getOrderGoods({stockinDetailId: this.materialCode})
const detail = res.data
if (!detail) {
uni.showToast({ title: '未找到物料信息', icon: 'none' })
uni.showToast({title: '未找到物料信息', icon: 'none'})
return
}
this.materialDetail = detail
this.bindQty = detail.quantity
this.bindQty = detail.quantityX
this.$refs.detailPopup.open()
} catch (e) {
console.error('get material detail error', e)
uni.showToast({ title: '查询物料失败', icon: 'none' })
uni.showToast({title: '查询物料失败', icon: 'none'})
}
},
async handleBindTray() {
if (!this.trayCode) { uni.showToast({ title: '请先输入托盘条码', icon: 'none' }); return }
if (!this.materialDetail?.stockinDetailId) { uni.showToast({ title: '物料信息缺失', icon: 'none' }); return }
try {
this.isBinding = true
const payload = { trayCode: this.trayCode, stockinDetailId: this.materialCode, inQuantity: this.bindQty }
const resp = await bindTray(payload)
if (resp.code === 200) {
uni.showToast({ title: '绑定成功', icon: 'success' })
this.$refs.detailPopup.close()
this.materialCode = ''
await this.onTrayInput(this.trayCode)
} else {
uni.showToast({ title: resp.msg || '绑定失败', icon: 'none' })
}
} catch (e) {
console.error('bindTray error', e)
uni.showToast({ title: resp.msg, icon: 'none' })
} finally {
this.isBinding = false
}
closePopup() {
this.$refs.detailPopup.close()
},
closePopup() { this.$refs.detailPopup.close() },
handleScanTray() {
uni.scanCode({
success: (res) => {
@@ -256,33 +226,163 @@ export default {
}
}
}
</script>
</script>
<style>
.container { padding: 12px; background: #f6f7fb; min-height: 100vh; }
.card { background: #fff; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.06); padding: 12px; margin-bottom: 12px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { color: #666; font-size: 12px; }
.scan-icon { font-size: 16px; padding: 0 8px; color: #2979ff; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.list { margin-top: 4px; display: flex; flex-direction: column; gap: 10px; }
.item { padding: 10px; border: 1px solid #eee; border-radius: 8px; }
.item-header { display: flex; justify-content: space-between; align-items: center; }
.name { font-size: 14px; color: #333; }
.qty-tag { background: #eef3ff; color: #2979ff; padding: 2px 6px; border-radius: 12px; font-size: 12px; }
.meta { color: #888; font-size: 12px; margin-top: 6px; }
.empty { color: #999; font-size: 12px; padding: 12px; text-align: center; }
.popup { padding: 16px; background: #fff; border-top-left-radius: 12px; border-top-right-radius: 12px; }
.popup-title { font-weight: 600; font-size: 16px; margin-bottom: 10px; }
.row { margin: 8px 0; display: flex; justify-content: space-between; }
.row-label { color: #666; }
.row-value { color: #333; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.btn { flex: 1; padding: 10px; border-radius: 8px; }
.primary { background: #2979ff; color: #fff; }
.secondary { background: #f1f1f1; color: #333; }
/* 页脚操作区 */
.footer-actions { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px; background: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.06); }
.confirm-btn { width: 100%; padding: 12px; border-radius: 8px; background: #07c160; color: #fff; font-size: 16px; }
.container {
padding: 12px;
background: #f6f7fb;
min-height: 100vh;
}
.card {
background: #fff;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
padding: 12px;
margin-bottom: 12px;
}
.form {
display: flex;
flex-direction: column;
gap: 12px;
}
.field {
display: flex;
flex-direction: column;
gap: 6px;
}
.label {
color: #666;
font-size: 12px;
}
.scan-icon {
font-size: 16px;
padding: 0 8px;
color: #2979ff;
}
.section-title {
font-size: 14px;
font-weight: 600;
margin-bottom: 8px;
}
.list {
margin-top: 4px;
display: flex;
flex-direction: column;
gap: 10px;
}
.item {
padding: 10px;
border: 1px solid #eee;
border-radius: 8px;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.name {
font-size: 14px;
color: #333;
}
.qty-tag {
background: #eef3ff;
color: #2979ff;
padding: 2px 6px;
border-radius: 12px;
font-size: 12px;
}
.meta {
color: #888;
font-size: 12px;
margin-top: 6px;
}
.empty {
color: #999;
font-size: 12px;
padding: 12px;
text-align: center;
}
.popup {
padding: 16px;
background: #fff;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
.popup-title {
font-weight: 600;
font-size: 16px;
margin-bottom: 10px;
}
.row {
margin: 8px 0;
display: flex;
justify-content: space-between;
}
.row-label {
color: #666;
}
.row-value {
color: #333;
}
.actions {
display: flex;
gap: 10px;
margin-top: 12px;
}
.btn {
flex: 1;
padding: 10px;
border-radius: 8px;
}
.primary {
background: #2979ff;
color: #fff;
}
.secondary {
background: #f1f1f1;
color: #333;
}
/* 页脚操作区 */
.footer-actions {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 10px 12px;
background: #fff;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
}
.confirm-btn {
width: 100%;
padding: 12px;
border-radius: 8px;
background: #07c160;
color: #fff;
font-size: 16px;
}
</style>