feat:仓储管理-物料入库模块

master
zhongwenkai 5 days ago
parent 872c0b58e1
commit e13f3796f3

@ -0,0 +1,45 @@
import request from '@/utils/request'
// 物料入库单创建
export function createMaterialInbound(data) {
return request({
url: '/admin-api/erp/stock-in/create',
method: 'post',
data: { ...data, inType: '物料入库' }
})
}
// 物料入库单分页查询(待入库/待审核)
export function getMaterialInboundPage(params = {}) {
return request({
url: '/admin-api/erp/stock-in/page',
method: 'get',
params: { ...params, inType: '物料入库' }
})
}
// 物料入库单提交审核(提交后变为待审核状态)
export function submitMaterialInbound(data) {
return request({
url: '/admin-api/erp/stock-in/submit',
method: 'put',
data
})
}
// 物料入库单审核status: 20=通过, 1=驳回)
export function auditMaterialInbound(data) {
return request({
url: '/admin-api/erp/stock-in/audit',
method: 'put',
data
})
}
// 物料入库单删除
export function deleteMaterialInbound(id) {
return request({
url: '/admin-api/erp/stock-in/delete',
method: 'delete',
params: { ids: String(id) }
})
}

@ -13,6 +13,28 @@ export function getSparepartSimpleList(pageNo = 1) {
})
}
// 物料列表(分页查询,后端按 categoryType=2 过滤物料)
export function getMaterialSimpleList(pageNo = 1) {
return request({
url: '/admin-api/erp/product/page',
method: 'get',
params: {
pageNo,
pageSize: 100,
categoryType: 2
}
})
}
// 产品详情(含供应商、图片等完整信息,备件/物料通用)
export function getProductDetail(id) {
return request({
url: '/admin-api/erp/product/get',
method: 'get',
params: { id }
})
}
// 备件详情(含供应商、图片等完整信息)
export function getSparepartDetail(id) {
return request({

@ -430,6 +430,34 @@
"navigationStyle": "custom"
}
},
{
"path": "materialInbound/index",
"style": {
"navigationBarTitleText": "物料入库",
"navigationStyle": "custom"
}
},
{
"path": "materialInbound/create",
"style": {
"navigationBarTitleText": "新增物料入库",
"navigationStyle": "custom"
}
},
{
"path": "materialInbound/materialSelect",
"style": {
"navigationBarTitleText": "选择物料",
"navigationStyle": "custom"
}
},
{
"path": "materialInbound/materialConfirm",
"style": {
"navigationBarTitleText": "确认物料入库",
"navigationStyle": "custom"
}
},
{
"path": "keypart/index",

@ -0,0 +1,576 @@
<template>
<view class="page-container">
<NavBar :title="'新增物料入库'" />
<!-- 操作按钮区 -->
<view class="action-row">
<view class="scan-input-row">
<input
id="material-inbound-scan-input"
class="scan-input"
v-model="scanCodeInput"
placeholder="红外扫码或输入物料码"
confirm-type="done"
@confirm="onScanInputConfirm"
/>
</view>
<view class="action-btn select-btn" @click="handleSelectMaterial">
<text class="btn-text">选择物料</text>
</view>
</view>
<!-- 入库信息 -->
<view class="form-section">
<!-- 入库时间 -->
<view class="section-title-bar">
<view class="section-bar-line"></view>
<text class="section-title"><text class="required">*</text>入库时间</text>
</view>
<picker mode="date" :value="inboundDate" @change="handleDateChange">
<view class="form-row-card">
<text :class="{ placeholder: !inboundDate }">{{ inboundDate || '请选择入库时间' }}</text>
<text class="form-row-arrow"></text>
</view>
</picker>
<!-- 经办人 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title"><text class="required">*</text>经办人</text>
</view>
<view class="form-row-card" @click="goSelectOperator">
<text :class="{ placeholder: !selectedOperatorName }">
{{ selectedOperatorName || '请选择经办人' }}
</text>
<text class="form-row-arrow"></text>
</view>
<!-- 备注 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title">备注</text>
</view>
<view class="form-row-card remark-card">
<textarea
v-model="remark"
class="remark-textarea"
placeholder="请输入备注信息"
placeholder-class="remark-placeholder"
:maxlength="500"
auto-height
/>
</view>
<!-- 附件 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title">附件</text>
</view>
<view class="attachment-area">
<view class="attachment-list">
<view v-for="(file, idx) in attachmentList" :key="idx" class="attachment-file-item">
<view class="file-icon">
<text class="file-icon-text">{{ getFileIcon(file.name) }}</text>
</view>
<view class="file-info">
<text class="file-name" :title="file.name">{{ file.name }}</text>
<text class="file-size">{{ formatFileSize(file.size) }}</text>
</view>
<view class="file-delete" @click="removeAttachment(idx)">
<text class="delete-icon-sm"></text>
</view>
</view>
<view class="attachment-add-file" @click="handleAddAttachment">
<text class="add-text">选取文件</text>
</view>
</view>
</view>
</view>
<!-- 已选物料列表 -->
<view class="material-section">
<view class="section-title-bar">
<view class="section-bar-line"></view>
<text class="section-title">入库清单{{ itemList.length }}</text>
</view>
<view v-if="itemList.length" class="item-list">
<view v-for="(item, idx) in itemList" :key="idx" class="item-card">
<view class="item-delete-top" @click="removeItem(idx)"><text class="delete-icon"></text></view>
<view class="item-left">
<view class="item-image-wrap">
<image
v-if="item._material && getItemImage(item._material)"
:src="getItemImage(item._material)"
class="item-image"
mode="aspectFill"
/>
<text v-else class="item-image-empty">📦</text>
</view>
<view class="item-info">
<text class="item-name">{{ item.productName }}</text>
<text class="item-spec">{{ item.productBarCode || '-' }}</text>
</view>
</view>
<view class="item-right">
<view class="item-qty-row">
<text class="item-qty-label">入库数量</text>
<text class="item-qty-value">{{ item.inputCount }}{{ item.purchaseUnitName }}</text>
</view>
</view>
</view>
</view>
<view v-else class="empty-wrap">
<text class="empty-text">请扫码或选择物料</text>
</view>
</view>
<!-- 底部操作栏 -->
<view class="bottom-actions">
<view class="bottom-btn cancel-btn" @click="handleCancel"></view>
<view class="bottom-btn confirm-btn" @click="handleSubmit"></view>
</view>
<sv-focus-no-keyboard ref="focusNoKeyboardRef"></sv-focus-no-keyboard>
</view>
</template>
<script setup>
import { ref, nextTick } from 'vue'
import { onReady, onShow, onHide } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { createMaterialInbound } from '@/api/mes/materialInbound'
import { getProductDetail } from '@/api/mes/sparepart'
const itemList = ref([])
const scanCodeInput = ref('')
//
const focusNoKeyboardRef = ref(null)
const keywordInputSelector = '#material-inbound-scan-input input, input#material-inbound-scan-input'
function focusKeywordNoKeyboard() {
nextTick(() => {
setTimeout(() => {
focusNoKeyboardRef.value?.focus(keywordInputSelector)
}, 80)
})
}
//
function onScanInputConfirm() {
const code = scanCodeInput.value.trim()
if (!code) return
handleScanCode(code)
}
async function handleScanCode(code) {
let materialId = null
if (code.toUpperCase().startsWith('MATERIAL-')) {
materialId = code.replace(/MATERIAL-/i, '')
} else {
const idMatch = code.match(/(\d+)$/)
if (idMatch) materialId = idMatch[1]
}
if (!materialId) {
uni.showToast({ title: '无法识别物料码', icon: 'none' })
return
}
try {
const apiRes = await getSparepartDetail(materialId)
const detail = apiRes?.data || apiRes
if (detail && detail.id) {
getApp().globalData._materialFromScan = true
getApp().globalData._materialBeforeConfirm = detail
uni.navigateTo({
url: '/pages_function/pages/materialInbound/materialConfirm'
})
} else {
uni.showToast({ title: '未找到物料: ' + materialId, icon: 'none' })
}
} catch (e) {
console.error('[物料入库] 扫码查询物料失败:', e)
uni.showToast({ title: '扫码失败', icon: 'none' })
}
}
//
const inboundDate = ref(formatDate(new Date()))
//
const selectedOperatorId = ref(null)
const selectedOperatorName = ref('')
//
const remark = ref('')
//
const attachmentList = ref([])
function formatDate(date) {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${d}`
}
function handleDateChange(e) {
inboundDate.value = e.detail.value
}
function getItemImage(material) {
const images = material.images
if (!images) return ''
if (Array.isArray(images)) return String(images[0] || '')
return String(images).split(',')[0]?.trim() || ''
}
function handleCancel() {
getApp().globalData._materialInboundItems = []
uni.navigateBack()
}
function handleSelectMaterial() {
getApp().globalData._materialSelectFrom = 'inbound'
uni.navigateTo({
url: '/pages_function/pages/materialInbound/materialSelect'
})
}
function handleScan() {
uni.scanCode({
onlyFromCamera: false,
scanType: ['barCode', 'qrCode'],
success: (res) => {
const code = (res.result || '').trim()
if (!code) return
scanCodeInput.value = code
handleScanCode(code)
},
fail: () => {
uni.showToast({ title: '扫码失败', icon: 'none' })
}
})
}
function removeItem(idx) {
itemList.value.splice(idx, 1)
getApp().globalData._materialInboundItems = [...itemList.value]
}
//
function goSelectOperator() {
getApp().globalData._materialInboundUserFrom = 'materialInbound'
uni.navigateTo({
url: '/pages_function/pages/moldRepair/userSelect?field=operator&from=materialInbound'
})
}
//
function getFileIcon(fileName) {
const ext = (fileName || '').split('.').pop()?.toLowerCase()
const iconMap = {
pdf: '📄', doc: '📝', docx: '📝', xls: '📊', xlsx: '📊',
ppt: '📽', pptx: '📽', txt: '📃', zip: '📦', rar: '📦',
jpg: '🖼', jpeg: '🖼', png: '🖼', gif: '🖼', webp: '🖼'
}
return iconMap[ext] || '📎'
}
function formatFileSize(bytes) {
if (!bytes) return '0 B'
if (bytes < 1024) return bytes + ' B'
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'
return (bytes / (1024 * 1024)).toFixed(1) + ' MB'
}
function handleAddAttachment() {
// #ifdef APP-PLUS
plus.gallery.pick(
(res) => {
const files = (res?.files || []).map(f => ({
name: f.name || 'unknown',
size: f.size || 0,
path: f
}))
attachmentList.value.push(...files)
},
(e) => {
console.log('选择文件失败:', e)
},
{ filter: 'all', multiple: true, maximum: 9 - attachmentList.value.length }
)
// #endif
// #ifndef APP-PLUS
uni.chooseImage({
count: 9 - attachmentList.value.length,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
res.tempFilePaths.forEach(path => {
const parts = path.split('/')
const name = parts[parts.length - 1] || 'image.jpg'
attachmentList.value.push({ name, size: 0, path })
})
}
})
// #endif
}
function removeAttachment(idx) {
attachmentList.value.splice(idx, 1)
}
async function handleSubmit() {
if (!itemList.value.length) {
uni.showToast({ title: '请先添加物料', icon: 'none' })
return
}
if (!inboundDate.value) {
uni.showToast({ title: '请选择入库时间', icon: 'none' })
return
}
if (!selectedOperatorId.value) {
uni.showToast({ title: '请选择经办人', icon: 'none' })
return
}
let totalCount = 0
const items = itemList.value.map(item => {
totalCount += item.count || 0
return {
warehouseId: item.warehouseId,
areaId: item.areaId,
productId: item.productId,
productName: item.productName,
productBarCode: item.productBarCode,
productUnitName: item.productUnitName,
purchaseUnitName: item.purchaseUnitName,
purchaseUnitConvertQuantity: item.purchaseUnitConvertQuantity,
inputCount: item.inputCount,
count: item.count
}
})
const now = new Date()
const [y, m, d] = inboundDate.value.split('-').map(Number)
const inTime = new Date(y, m - 1, d, now.getHours(), now.getMinutes(), now.getSeconds()).getTime()
const submitData = {
isCode: true,
inTime: inTime,
stockUserId: String(selectedOperatorId.value),
supplierId: itemList.value[0]?.supplierId,
status: 0,
totalCount: totalCount,
totalPrice: 0,
remark: remark.value,
items: items
}
if (attachmentList.value.length) {
submitData.attachments = attachmentList.value.map(f => f.path || f)
}
console.log('提交数据:', JSON.stringify(submitData))
uni.showLoading({ title: '提交中...', mask: true })
try {
await createMaterialInbound(submitData)
uni.hideLoading()
getApp().globalData._materialInboundItems = []
uni.showToast({ title: '入库成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack()
}, 1500)
} catch (e) {
uni.hideLoading()
const msg = e?.message || e?.data?.msg || e?.response?.data?.msg || '保存失败'
console.error('入库提交失败:', e)
uni.showToast({ title: String(msg).substring(0, 50), icon: 'none' })
}
}
onReady(() => {
focusKeywordNoKeyboard()
})
onShow(() => {
const items = getApp().globalData?._materialInboundItems
if (Array.isArray(items)) {
itemList.value = [...items]
}
//
const userResult = getApp().globalData?._materialInboundUserSelectResult
if (userResult) {
selectedOperatorId.value = userResult.user.id
selectedOperatorName.value = userResult.user.nickname || userResult.user.userName || userResult.user.name || ''
getApp().globalData._materialInboundUserSelectResult = null
}
})
onHide(() => {})
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f5f6f8;
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
}
/* 操作按钮区 */
.action-row {
display: flex;
align-items: center;
gap: 16rpx;
padding: 20rpx 24rpx;
}
.scan-input-row {
flex: 1;
display: flex;
align-items: center;
height: 72rpx;
border-radius: 10rpx;
overflow: hidden;
}
.scan-input {
flex: 1;
height: 72rpx;
padding: 0 20rpx;
font-size: 26rpx;
color: #333;
background: #fff;
border: 1rpx solid #d0d5dd;
border-radius: 10rpx;
}
.action-btn {
display: flex;
align-items: center;
justify-content: center;
height: 72rpx;
padding: 0 24rpx;
border-radius: 10rpx;
background: #1f4b79;
color: #fff;
font-size: 26rpx;
font-weight: 600;
white-space: nowrap;
.btn-text { font-size: 26rpx; font-weight: 600; color: #fff; }
}
/* 物料列表 */
.material-section { padding: 0; }
.section-title-bar {
display: flex; align-items: center; gap: 10rpx;
padding: 24rpx 24rpx 18rpx;
}
.section-bar-line {
width: 6rpx; height: 32rpx; border-radius: 3rpx;
background: #2563eb; flex-shrink: 0;
}
.section-title { font-size: 30rpx; font-weight: 700; color: #1a1a1a; }
.required { color: #ef4444; margin-right: 2rpx; }
.item-list { padding: 0 24rpx; }
.item-card {
position: relative; display: flex; align-items: center; justify-content: space-between;
background: #fff; border-radius: 14rpx; padding: 20rpx; margin-bottom: 16rpx;
box-shadow: 0 2rpx 12rpx rgba(15, 23, 42, 0.04);
}
.item-delete-top { position: absolute; top: 10rpx; right: 10rpx; width: 40rpx; height: 40rpx; border-radius: 20rpx; background: #fee2e2; display: flex; align-items: center; justify-content: center; z-index: 1; .delete-icon { font-size: 20rpx; color: #dc2626; } }
.item-left { display: flex; align-items: center; flex: 1; min-width: 0; padding-right: 36rpx; }
.item-image-wrap {
width: 80rpx; height: 80rpx; border-radius: 10rpx; overflow: hidden;
background: #f8fafc; border: 1rpx solid #f0f0f0; flex-shrink: 0;
display: flex; align-items: center; justify-content: center;
}
.item-image { width: 100%; height: 100%; }
.item-image-empty { font-size: 36rpx; opacity: 0.3; }
.item-info { margin-left: 16rpx; flex: 1; min-width: 0; }
.item-name {
font-size: 28rpx; font-weight: 600; color: #1a1a1a; display: block;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-spec { font-size: 24rpx; color: #9ca3af; margin-top: 6rpx; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-right { display: flex; flex-direction: column; align-items: flex-end; margin-left: 16rpx; flex-shrink: 0; padding-right: 50rpx; }
.item-qty-row { display: flex; flex-direction: column; align-items: flex-end; }
.item-qty-label { font-size: 22rpx; color: #9ca3af; }
.item-qty-value { font-size: 28rpx; font-weight: 700; color: #2563eb; margin-top: 4rpx; }
.empty-wrap { padding: 160rpx 0; text-align: center; }
.empty-text { font-size: 28rpx; color: #94a3b8; }
/* 入库信息区 */
.form-section { padding-bottom: 16rpx; }
.form-row-card {
position: relative;
display: flex; align-items: center; justify-content: space-between;
background: #fff; border-radius: 16rpx; padding: 26rpx 24rpx; margin: 0 24rpx 16rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.04);
font-size: 28rpx; color: #374151;
.placeholder { color: #9ca3af; }
}
.form-row-arrow { font-size: 20rpx; color: #999; flex-shrink: 0; }
/* 备注 */
.remark-card { padding: 20rpx 24rpx; }
.remark-textarea { width: 100%; min-height: 120rpx; font-size: 27rpx; color: #374151; line-height: 1.6; box-sizing: border-box; }
.remark-placeholder { color: #bbb; }
/* 附件 */
.attachment-area { padding: 0 24rpx 16rpx; }
.attachment-list { display: flex; flex-direction: column; gap: 12rpx; }
.attachment-file-item {
display: flex; align-items: center; gap: 16rpx;
background: #fff; border-radius: 12rpx; padding: 18rpx 20rpx;
box-shadow: 0 2rpx 8rpx rgba(15, 23, 42, 0.03);
}
.file-icon {
width: 72rpx; height: 72rpx; border-radius: 10rpx;
background: #f1f5f9; display: flex; align-items: center; justify-content: center;
flex-shrink: 0;
}
.file-icon-text { font-size: 36rpx; }
.file-info { flex: 1; min-width: 0; }
.file-name {
font-size: 26rpx; color: #1f2937; display: block;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-size { font-size: 22rpx; color: #9ca3af; margin-top: 4rpx; display: block; }
.file-delete {
width: 48rpx; height: 48rpx; border-radius: 24rpx;
background: #fee2e2; display: flex; align-items: center; justify-content: center;
flex-shrink: 0;
}
.delete-icon-sm { font-size: 22rpx; color: #dc2626; }
.attachment-add-file {
display: flex; align-items: center; justify-content: center; gap: 10rpx;
height: 88rpx; background: #fff; border: 2rpx dashed #cbd5e1;
border-radius: 12rpx;
}
.add-text { font-size: 26rpx; color: #6b7280; }
/* 底部操作栏 */
.bottom-actions {
position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 18rpx;
padding: 18rpx 24rpx calc(18rpx + env(safe-area-inset-bottom));
background: #ffffff; box-shadow: 0 -8rpx 24rpx rgba(15, 23, 42, 0.06); z-index: 99;
}
.bottom-btn { flex: 1; height: 84rpx; line-height: 84rpx; text-align: center; border-radius: 16rpx; font-size: 30rpx; font-weight: 600;
&:active { opacity: 0.85; }
}
.cancel-btn { background: #eef2f7; color: #475569; }
.confirm-btn { background: #1f4b79; color: #ffffff; }
</style>

@ -0,0 +1,764 @@
<template>
<view class="page-container">
<NavBar :title="'物料入库'" />
<!-- 搜索栏 -->
<view class="filter-bar">
<view class="keyword-box">
<input
v-model="searchKeyword"
class="keyword-input"
placeholder="搜索单号"
confirm-type="search"
@input="handleKeywordInput"
@confirm="handleSearch"
/>
</view>
<picker mode="selector" :range="statusLabels" :value="statusIndex" @change="onStatusChange">
<view class="status-box">
<text class="status-box-text">{{ currentStatusLabel }}</text>
<uni-icons type="bottom" size="14" color="#9ca3af"></uni-icons>
</view>
</picker>
<view class="reset-filter-btn" @click="resetFilters"></view>
</view>
<!-- 列表 -->
<scroll-view
scroll-y
class="list-scroll"
:scroll-top="scrollTop"
@scroll="onScroll"
@scrolltolower="loadMore"
:lower-threshold="80"
>
<view class="list-wrap">
<view
v-for="item in list"
:key="item.id"
class="task-card"
@click="openDetail(item)"
>
<view class="card-header">
<view class="header-main">
<view class="header-left">
<text class="task-no">{{ textValue(item.no) }}</text>
</view>
<view class="header-tags">
<text :class="['record-tag', statusClass(item.status)]">{{ statusText(item.status) }}</text>
</view>
</view>
</view>
<view class="card-body">
<view class="row">
<text class="label">物料信息</text>
<text class="value">{{ textValue(item.productNames) }}</text>
</view>
<view class="row">
<text class="label">入库时间</text>
<text class="value">{{ formatDateTime(item.inTime || item.createTime) }}</text>
</view>
<view class="row">
<text class="label">创建人</text>
<text class="value">{{ textValue(item.creatorName || item.creator) }}</text>
</view>
<view class="row">
<text class="label">数量</text>
<text class="value highlight">{{ textValue(item.totalCount) }}</text>
</view>
<view class="row">
<text class="label">审核人</text>
<text class="value">{{ textValue(item.auditUserName) }}</text>
</view>
</view>
<!-- 待入库提交审核 -->
<view v-if="Number(item.status) === 0" class="card-actions">
<view class="action-btn submit-btn" @click.stop="openSubmitAudit(item)">提交审核</view>
</view>
<!-- 待审核通过 / 驳回 -->
<view v-if="Number(item.status) === 10" class="card-actions">
<view class="action-btn approve-btn" @click.stop="handleApprove(item)">审核通过</view>
<view class="action-btn reject-btn" @click.stop="handleReject(item)">审核驳回</view>
</view>
</view>
<view v-if="loading && pageNo === 1" class="hint">...</view>
<view v-else-if="!list.length" class="hint">暂无数据</view>
<view v-else-if="loadingMore" class="hint">加载更多...</view>
<view v-else-if="finished" class="hint">没有更多了</view>
</view>
</scroll-view>
<!-- 回顶部 -->
<view v-if="showGoTop" class="go-top-btn" @click="goTop">
<uni-icons type="arrow-up" size="20" color="#1f4b79"></uni-icons>
</view>
<!-- 新增按钮 -->
<view class="add-btn" @click="goAdd">
<text class="add-icon">+</text>
</view>
<!-- 提交审核弹框 -->
<view v-if="showAuditModal" class="modal-overlay" @click="closeAuditModal">
<view class="modal-card" @click.stop>
<view class="modal-header">
<text class="modal-title">提交审核</text>
<text class="modal-close" @click="closeAuditModal"></text>
</view>
<view class="modal-body">
<!-- 审核人 -->
<view class="modal-field">
<text class="modal-label"><text class="required">*</text>审核人</text>
<view class="modal-dropdown" @click="toggleAuditorDropdown">
<text :class="{ placeholder: !selectedAuditor }">{{ selectedAuditor ? selectedAuditor.label : '请选择' }}</text>
<text class="dropdown-arrow"></text>
<view v-if="showAuditorDropdown" class="dropdown-panel">
<scroll-view scroll-y class="dropdown-scroll">
<view v-for="u in auditorOptions" :key="u.value" class="dropdown-item" :class="{ active: selectedAuditor?.value === u.value }" @click.stop="selectAuditor(u)">
<text class="dropdown-item-text">{{ u.label }}</text>
<text v-if="selectedAuditor?.value === u.value" class="dropdown-check"></text>
</view>
</scroll-view>
</view>
</view>
</view>
<!-- 备注 -->
<view class="modal-field">
<text class="modal-label">备注</text>
<textarea v-model="auditRemark" class="modal-textarea" placeholder="请输入备注" placeholder-class="textarea-placeholder" :maxlength="200" />
</view>
</view>
<view class="modal-footer">
<view class="modal-btn cancel-btn" @click="closeAuditModal"></view>
<view class="modal-btn confirm-btn" @click="confirmSubmitAudit"></view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { computed, ref } from 'vue'
import { onShow, onUnload } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { getMaterialInboundPage, auditMaterialInbound, submitMaterialInbound } from '@/api/mes/materialInbound'
import { getSimpleUserList } from '@/api/mes/moldget'
const selectedStatus = ref('')
const searchKeyword = ref('')
const statusOptions = computed(() => [
{ label: '全部', value: '' },
{ label: '待入库', value: '0' },
{ label: '待审核', value: '10' },
{ label: '已入库', value: '20' }
])
const statusLabels = computed(() => statusOptions.value.map((item) => item.label))
const statusIndex = computed(() => {
const index = statusOptions.value.findIndex((item) => item.value === selectedStatus.value)
return index >= 0 ? index : 0
})
const currentStatusLabel = computed(() => {
const current = statusOptions.value.find((item) => item.value === selectedStatus.value)
return current ? current.label : '全部'
})
const list = ref([])
const loading = ref(false)
const loadingMore = ref(false)
const finished = ref(false)
const pageNo = ref(1)
const pageSize = ref(10)
const scrollTop = ref(0)
const showGoTop = ref(false)
let searchTimer = null
function textValue(v) {
if (v === 0) return '0'
if (v == null) return '-'
const s = String(v).trim()
return s || '-'
}
function formatDateTime(value) {
if (!value) return '-'
if (Array.isArray(value) && value.length >= 3) {
const [year, month, day] = value
const pad = (n) => String(n).padStart(2, '0')
return `${year}-${pad(month)}-${pad(day)}`
}
const date = new Date(Number(value))
if (Number.isNaN(date.getTime())) return String(value)
const pad = (n) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
}
const STATUS_MAP = { 0: '待入库', 10: '待审核', 20: '已入库', 1: '已驳回' }
function statusText(s) {
const num = Number(s)
return STATUS_MAP[num] || textValue(num)
}
function statusClass(s) {
const num = Number(s)
if (num === 0) return 'text-primary'
if (num === 10) return 'text-warning'
if (num === 20) return 'text-success'
if (num === 1) return 'text-danger'
return ''
}
function normalizePageData(res) {
const root = res && res.data !== undefined ? res.data : res
const candidateList = root?.list || root?.rows || root?.records || root?.data?.list || root?.data?.rows || []
const candidateTotal = root?.total ?? root?.data?.total ?? (Array.isArray(candidateList) ? candidateList.length : 0)
return {
list: Array.isArray(candidateList) ? candidateList : [],
total: Number(candidateTotal || 0)
}
}
async function fetchList(reset) {
if (reset) {
pageNo.value = 1
finished.value = false
}
if (pageNo.value === 1) {
loading.value = true
} else {
loadingMore.value = true
}
try {
const params = {
pageNo: pageNo.value,
pageSize: pageSize.value,
no: searchKeyword.value.trim() || undefined,
status: selectedStatus.value || undefined
}
const res = await getMaterialInboundPage(params)
const page = normalizePageData(res)
list.value = reset ? page.list : [...list.value, ...page.list]
finished.value = list.value.length >= page.total || page.list.length < pageSize.value
} catch (e) {
if (!reset) pageNo.value = Math.max(1, pageNo.value - 1)
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
loadingMore.value = false
}
}
function onStatusChange(event) {
const index = Number(event?.detail?.value || 0)
selectedStatus.value = statusOptions.value[index]?.value ?? ''
fetchList(true)
}
function handleSearch() {
clearSearchTimer()
uni.hideKeyboard()
fetchList(true)
}
function handleKeywordInput() {
clearSearchTimer()
searchTimer = setTimeout(() => {
fetchList(true)
}, 300)
}
function resetFilters() {
clearSearchTimer()
searchKeyword.value = ''
selectedStatus.value = ''
fetchList(true)
}
async function loadMore() {
if (loading.value || loadingMore.value || finished.value) return
pageNo.value += 1
await fetchList(false)
}
function openDetail(item) {
if (!item?.id) {
uni.showToast({ title: '无法查看详情', icon: 'none' })
return
}
//
uni.navigateTo({
url: `/pages_function/pages/sparepartInbound/detail?id=${encodeURIComponent(String(item.id))}`
})
}
async function handleApprove(item) {
if (!item?.id) return
uni.showModal({
title: '确认',
content: '确认审核通过?',
confirmColor: '#16a34a',
success: async (res) => {
if (res.confirm) {
try {
await auditMaterialInbound({ id: item.id, status: 20 })
uni.showToast({ title: '审核通过', icon: 'success' })
fetchList(true)
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
}
})
}
async function handleReject(item) {
if (!item?.id) return
uni.showModal({
title: '确认',
content: '确认审核驳回?',
confirmColor: '#dc2626',
success: async (res) => {
if (res.confirm) {
try {
await auditMaterialInbound({ id: item.id, status: 1 })
uni.showToast({ title: '已驳回', icon: 'success' })
fetchList(true)
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
}
})
}
//
const showAuditModal = ref(false)
const currentAuditItem = ref(null)
const auditorOptions = ref([])
const selectedAuditor = ref(null)
const showAuditorDropdown = ref(false)
const auditRemark = ref('')
function openSubmitAudit(item) {
currentAuditItem.value = item
selectedAuditor.value = null
auditRemark.value = ''
showAuditModal.value = true
loadAuditorOptions()
}
function closeAuditModal() {
showAuditModal.value = false
currentAuditItem.value = null
showAuditorDropdown.value = false
}
function toggleAuditorDropdown() {
showAuditorDropdown.value = !showAuditorDropdown.value
}
function selectAuditor(u) {
selectedAuditor.value = u
showAuditorDropdown.value = false
}
async function loadAuditorOptions() {
if (auditorOptions.value.length) return
try {
const res = await getSimpleUserList()
const data = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : [])
auditorOptions.value = data.map((u) => ({
value: u.id || u.userId,
label: u.nickname || u.userName || u.name || String(u.id || '')
}))
} catch (e) {
console.error('loadAuditorOptions error', e)
}
}
async function confirmSubmitAudit() {
if (!selectedAuditor.value) {
uni.showToast({ title: '请选择审核人', icon: 'none' })
return
}
if (!currentAuditItem.value?.id) return
try {
uni.showLoading({ title: '提交中...', mask: true })
await submitMaterialInbound({
id: currentAuditItem.value.id,
auditUserId: selectedAuditor.value.value,
remark: auditRemark.value || undefined
})
uni.hideLoading()
uni.showToast({ title: '提交审核成功', icon: 'success' })
closeAuditModal()
fetchList(true)
} catch (e) {
uni.hideLoading()
uni.showToast({ title: '提交失败', icon: 'none' })
}
}
function onScroll(event) {
showGoTop.value = (event?.detail?.scrollTop || 0) > 600
}
function goTop() {
scrollTop.value = 0
}
function goAdd() {
uni.navigateTo({
url: '/pages_function/pages/materialInbound/create'
})
}
function clearSearchTimer() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
}
onShow(() => {
fetchList(true)
})
onUnload(() => {
clearSearchTimer()
})
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f4f5f7;
}
/* ====== 搜索栏 ====== */
.filter-bar {
display: flex;
align-items: center;
gap: 12rpx;
padding: 18rpx 24rpx;
background: #fff;
}
.keyword-box {
flex: 1;
min-width: 0;
height: 66rpx;
padding: 0 28rpx;
background: #f4f5f7;
border: 1rpx solid #e5e7eb;
border-radius: 12rpx;
display: flex;
align-items: center;
}
.keyword-input {
width: 100%;
font-size: 24rpx;
color: #374151;
}
.status-box {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: space-between;
height: 66rpx;
padding: 0 28rpx;
min-width: 160rpx;
background: #fff;
border: 1rpx solid #e5e7eb;
border-radius: 12rpx;
}
.status-box-text {
font-size: 24rpx;
color: #374151;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.reset-filter-btn {
height: 66rpx;
line-height: 66rpx;
padding: 0 28rpx;
font-size: 24rpx;
color: #4b5563;
background: #fff;
border: 1rpx solid #e5e7eb;
border-radius: 12rpx;
flex-shrink: 0;
}
/* ====== 列表 ====== */
.list-scroll {
height: calc(100vh - 194rpx);
}
.list-wrap {
padding: 0 24rpx 60rpx;
}
.task-card {
position: relative;
margin-top: 20rpx;
padding: 28rpx;
background: #fff;
border-radius: 22rpx;
box-shadow: 0 8rpx 28rpx rgba(15, 23, 42, 0.06);
}
.card-header {
margin-bottom: 18rpx;
}
.header-main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.header-left {
min-width: 0;
flex: 1;
}
.task-no {
font-size: 32rpx;
font-weight: 700;
color: #0f172a;
}
.header-tags {
display: flex;
align-items: center;
gap: 12rpx;
flex-shrink: 0;
}
.record-tag {
padding: 8rpx 18rpx;
border-radius: 999rpx;
font-size: 22rpx;
line-height: 1;
background: #e2e8f0;
color: #64748b;
}
.card-body .row {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 20rpx;
margin-top: 12rpx;
&:first-child {
margin-top: 0;
}
}
.label {
width: 140rpx;
font-size: 25rpx;
color: #94a3b8;
flex-shrink: 0;
}
.value {
flex: 1;
text-align: right;
font-size: 27rpx;
color: #334155;
line-height: 1.5;
&.highlight {
color: #1f4b79;
font-weight: 600;
}
}
/* ====== 操作按钮 ====== */
.card-actions {
display: flex;
gap: 16rpx;
margin-top: 20rpx;
padding-top: 20rpx;
border-top: 1rpx solid #f0f0f0;
}
.action-btn {
flex: 1;
height: 64rpx;
line-height: 64rpx;
text-align: center;
border-radius: 10rpx;
font-size: 26rpx;
font-weight: 500;
&.approve-btn {
background: #dcfce7;
color: #16a34a;
}
&.reject-btn {
background: #fee2e2;
color: #dc2626;
}
&.submit-btn {
background: #dbeafe;
color: #1d4ed8;
}
&:active {
opacity: 0.8;
}
}
/* ====== 状态标签颜色 ====== */
.text-success {
color: #16a34a;
}
.text-danger {
color: #dc2626;
}
.text-warning {
color: #d97706;
}
.text-primary {
color: #2563eb;
}
.record-tag.text-success {
color: #15803d;
background: #dcfce7;
}
.record-tag.text-danger {
color: #dc2626;
background: #fee2e2;
}
.record-tag.text-warning {
color: #d97706;
background: #fef3c7;
}
.record-tag.text-primary {
color: #1d4ed8;
background: #dbeafe;
}
/* ====== 提示 ====== */
.hint {
padding: 36rpx 0;
text-align: center;
color: #94a3b8;
font-size: 26rpx;
}
/* ====== 回顶部 ====== */
.go-top-btn {
position: fixed;
right: 28rpx;
bottom: calc(140rpx + env(safe-area-inset-bottom));
width: 92rpx;
height: 92rpx;
border-radius: 46rpx;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 8rpx 24rpx rgba(15, 23, 42, 0.12);
display: flex;
align-items: center;
justify-content: center;
}
/* ====== 新增按钮 ====== */
.add-btn {
position: fixed;
right: 28rpx;
bottom: calc(56rpx + env(safe-area-inset-bottom));
width: 92rpx;
height: 92rpx;
border-radius: 46rpx;
background: #1f4b79;
box-shadow: 0 14rpx 30rpx rgba(24, 63, 108, 0.24);
display: flex;
align-items: center;
justify-content: center;
}
.add-icon {
color: #ffffff;
font-size: 64rpx;
line-height: 1;
margin-top: -4rpx;
}
/* ====== 提交审核弹框 ====== */
.modal-overlay {
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.45); z-index: 999;
display: flex; align-items: center; justify-content: center;
}
.modal-card {
width: 640rpx; background: #fff; border-radius: 20rpx;
box-shadow: 0 16rpx 48rpx rgba(0,0,0,0.15);
}
.modal-header {
display: flex; align-items: center; justify-content: space-between;
padding: 32rpx 32rpx 20rpx; border-bottom: 1rpx solid #f0f0f0;
}
.modal-title { font-size: 32rpx; font-weight: 700; color: #1a1a1a; }
.modal-close { font-size: 32rpx; color: #999; padding: 8rpx; }
.modal-body { padding: 28rpx 32rpx; }
.modal-field { margin-bottom: 28rpx;
&:last-child { margin-bottom: 0; }
}
.modal-label { font-size: 28rpx; color: #374151; font-weight: 500; margin-bottom: 14rpx; display: block; }
.modal-label .required { color: #ef4444; }
.modal-dropdown {
position: relative; display: flex; align-items: center; justify-content: space-between;
height: 80rpx; padding: 0 24rpx;
background: #f8fafc; border: 1rpx solid #e0e0e0; border-radius: 12rpx;
font-size: 28rpx; color: #374151;
.placeholder { color: #bbb; }
.dropdown-arrow { font-size: 20rpx; color: #999; }
}
.modal-textarea {
width: 100%; min-height: 140rpx; padding: 20rpx;
background: #f8fafc; border: 1rpx solid #e0e0e0;
border-radius: 12rpx; font-size: 27rpx; color: #374151;
box-sizing: border-box;
}
.textarea-placeholder { color: #bbb; }
.dropdown-panel {
position: absolute; top: 100%; left: 0; right: 0; z-index: 200; margin-top: 4rpx;
background: #fff; border: 1rpx solid #e0e0e0; border-radius: 12rpx;
box-shadow: 0 8rpx 30rpx rgba(0,0,0,0.1); overflow: hidden;
}
.dropdown-scroll { height: 300rpx; }
.dropdown-item { display: flex; align-items: center; justify-content: space-between; padding: 20rpx 24rpx; border-bottom: 1rpx solid #f0f0f0;
&:last-child { border-bottom: 0; }
&.active { background: #f0f5ff; }
}
.dropdown-item-text { font-size: 27rpx; color: #333; }
.dropdown-check { font-size: 28rpx; color: #2563eb; font-weight: 700; }
.modal-footer { display: flex; gap: 18rpx; padding: 24rpx 32rpx; border-top: 1rpx solid #f0f0f0; }
.modal-btn { flex: 1; height: 80rpx; line-height: 80rpx; text-align: center; border-radius: 14rpx; font-size: 30rpx; font-weight: 600;
&:active { opacity: 0.85; }
&.cancel-btn { background: #f0f0f0; color: #6b7280; }
&.confirm-btn { background: #1f4b79; color: #fff; }
}
</style>

@ -0,0 +1,469 @@
<template>
<view class="page-container">
<NavBar :title="'确认物料入库'" />
<!-- 已选物料 -->
<view class="material-section">
<view class="section-title-bar">
<view class="section-bar-line"></view>
<text class="section-title">已选物料</text>
</view>
<view class="material-card">
<view class="card-top">
<view class="card-image-wrap">
<image
v-if="materialImage"
:src="materialImage"
class="card-image"
mode="aspectFill"
/>
<view v-else class="card-image-empty">
<text class="empty-img-icon">📦</text>
</view>
</view>
<view class="card-info-right">
<view class="info-item">
<text class="info-label">物料名称</text>
<text class="info-name">{{ textValue(material.name) }}</text>
</view>
<view class="info-item">
<text class="info-label">规格</text>
<text class="info-value">{{ textValue(material.standard || material.deviceSpec) }}</text>
</view>
<view class="info-item">
<text class="info-label">当前总库存</text>
<text class="info-value stock-highlight">{{ material.count != null ? material.count : 0 }}{{ textUnit(material.unitName || material.minStockUnitName || '个') }}</text>
</view>
</view>
</view>
<view class="card-bottom">
<view class="detail-row two-col">
<view class="detail-col">
<text class="detail-label">采购单位</text>
<text class="detail-value">{{ textValue(material.purchaseUnitName) }}</text>
</view>
<view class="detail-col">
<text class="detail-label">库存单位</text>
<text class="detail-value">{{ textValue(material.unitName || material.minStockUnitName || '个') }}</text>
</view>
</view>
<view class="detail-row">
<text class="detail-label">换算关系</text>
<text class="detail-value">1{{ textValue(material.purchaseUnitName) }}={{ textValue(material.purchaseUnitConvertQuantity) }}{{ stockUnitLabel(material) }}</text>
</view>
</view>
</view>
<!-- 仓库/库区 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title">仓库/库区</text>
</view>
<view class="select-row-card warehouse-area-card">
<view class="warehouse-area-rows">
<view class="warehouse-area-row">
<text class="warehouse-area-label">仓库</text>
<view class="warehouse-area-dropdown" @click="toggleWarehouseDropdown">
<view class="dropdown-input">
<text :class="['dropdown-value', { placeholder: !selectedWarehouse }]">
{{ selectedWarehouse ? selectedWarehouse.label : '请选择' }}
</text>
<text class="dropdown-arrow"></text>
</view>
<view v-if="showWarehouseDropdown" class="dropdown-panel">
<view class="dropdown-scroll">
<view
v-for="item in warehouseOptions"
:key="item.value"
class="dropdown-item"
:class="{ active: selectedWarehouse?.value === item.value }"
@click.stop="handleSelectWarehouse(item)"
>
<text class="dropdown-item-text">{{ item.label }}</text>
<text v-if="selectedWarehouse?.value === item.value" class="dropdown-check"></text>
</view>
<view v-if="!warehouseOptions.length" class="dropdown-empty"></view>
</view>
</view>
</view>
</view>
<view class="warehouse-area-row">
<text class="warehouse-area-label">库区</text>
<view class="warehouse-area-dropdown" @click="toggleAreaDropdown">
<view class="dropdown-input">
<text :class="['dropdown-value', { placeholder: !selectedArea }]">
{{ selectedArea ? selectedArea.label : (loadingAreas ? '加载中...' : '请选择') }}
</text>
<text class="dropdown-arrow"></text>
</view>
<view v-if="showAreaDropdown" class="dropdown-panel">
<view class="dropdown-scroll">
<view
v-for="item in areaOptions"
:key="item.value"
class="dropdown-item"
:class="{ active: selectedArea?.value === item.value }"
@click.stop="handleSelectArea(item)"
>
<text class="dropdown-item-text">{{ item.label }}</text>
<text v-if="selectedArea?.value === item.value" class="dropdown-check"></text>
</view>
<view v-if="!areaOptions.length" class="dropdown-empty"></view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 入库数量 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title">入库数量</text>
</view>
<view class="qty-input-card">
<view class="form-field">
<text class="form-label">入库数量</text>
<input
v-model="inboundQty"
class="form-input"
placeholder="请输入"
confirm-type="done"
/>
<text class="form-suffix-text">单位{{ textValue(material.purchaseUnitName) }}</text>
</view>
<view class="convert-row">
<text class="convert-label-inline">折算后库存数量</text>
<text class="convert-value-inline">{{ calculatedStock }}</text>
<text class="convert-unit-inline">{{ stockUnitLabel(material) }}</text>
</view>
<view class="convert-formula-inline">
{{ inboundQty || 0 }}{{ textValue(material.purchaseUnitName) }} × {{ textValue(material.purchaseUnitConvertQuantity) }}{{ stockUnitLabel(material) }} = {{ calculatedStock }}{{ stockUnitLabel(material) }}
</view>
</view>
<!-- 供应商 -->
<view class="section-title-bar" style="padding-top: 24rpx;">
<view class="section-bar-line"></view>
<text class="section-title">供应商</text>
</view>
<view class="select-row-card">
<view class="full-dropdown">
<text :class="{ placeholder: !defaultSupplierName }">
{{ defaultSupplierName || '未配置默认供应商' }}
</text>
</view>
</view>
</view>
<!-- 底部确认按钮 -->
<view class="bottom-actions">
<view class="bottom-btn cancel-btn" @click="handleCancel"></view>
<view class="bottom-btn confirm-btn" @click="handleConfirm"></view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { onShow, onHide } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { getWarehouseSimpleList, getWarehouseAreaSimpleList } from '@/api/mes/moldget'
import { getProductDetail, getSparepartStockCount } from '@/api/mes/sparepart'
const material = ref({})
const inboundQty = ref(null)
//
const warehouseOptions = ref([])
const selectedWarehouse = ref(null)
const showWarehouseDropdown = ref(false)
//
const areaOptions = ref([])
const selectedArea = ref(null)
const showAreaDropdown = ref(false)
const loadingAreas = ref(false)
const materialImage = computed(() => {
const images = material.value.images
if (!images) return ''
if (Array.isArray(images)) return String(images[0] || '')
return String(images).split(',')[0]?.trim() || ''
})
const calculatedStock = computed(() => {
const qty = Number(inboundQty.value) || 0
const ratio = Number(material.value.purchaseUnitConvertQuantity) || 0
return qty * ratio
})
const defaultSupplierName = computed(() => {
const suppliers = material.value.suppliers
const defaultId = material.value.defaultSupplierId
if (!suppliers || !suppliers.length) return ''
if (defaultId) {
const found = suppliers.find(s => s.supplierId === defaultId || s.id === defaultId)
if (found) return found.supplierName || ''
}
const firstDefault = suppliers.find(s => s.defaultStatus === 1)
return firstDefault?.supplierName || ''
})
function textValue(v) {
if (v === 0) return '0'
if (v == null) return '-'
const s = String(v).trim()
return s || '-'
}
function textUnit(v) {
if (v === 0) return '0'
if (v == null) return ''
return String(v).trim()
}
function stockUnitLabel(item) {
return item.unitName || item.minStockUnitName || '个'
}
function handleCancel() {
uni.navigateBack()
}
function handleConfirm() {
if (!inboundQty.value || Number(inboundQty.value) <= 0) {
uni.showToast({ title: '请输入入库数量', icon: 'none' })
return
}
if (!selectedWarehouse.value) {
uni.showToast({ title: '请选择仓库', icon: 'none' })
return
}
if (!selectedArea.value) {
uni.showToast({ title: '请选择库区', icon: 'none' })
return
}
const item = {
productId: material.value.id,
productName: material.value.name || '',
productBarCode: material.value.barCode || '',
productUnitName: material.value.unitName || material.value.minStockUnitName || '',
purchaseUnitName: material.value.purchaseUnitName || '',
purchaseUnitConvertQuantity: Number(material.value.purchaseUnitConvertQuantity) || 1,
inputCount: Number(inboundQty.value),
count: Number(inboundQty.value) * (Number(material.value.purchaseUnitConvertQuantity) || 1),
supplierId: material.value.defaultSupplierId,
supplierName: defaultSupplierName.value,
warehouseId: selectedWarehouse.value.value,
warehouseName: selectedWarehouse.value.label,
areaId: selectedArea.value.value,
areaName: selectedArea.value.label,
_material: { ...material.value }
}
if (!getApp().globalData._materialInboundItems) {
getApp().globalData._materialInboundItems = []
}
getApp().globalData._materialInboundItems.push(item)
uni.showToast({ title: '已添加: ' + (material.value.name || ''), icon: 'success', duration: 1200 })
setTimeout(() => {
const fromScan = getApp().globalData._materialFromScan
getApp().globalData._materialFromScan = false
uni.navigateBack({ delta: fromScan ? 1 : 2 })
}, 800)
}
//
function toggleWarehouseDropdown() {
showWarehouseDropdown.value = !showWarehouseDropdown.value
}
function handleSelectWarehouse(item) {
selectedWarehouse.value = item
showWarehouseDropdown.value = false
selectedArea.value = null
areaOptions.value = []
loadAreas(item.value)
}
async function loadWarehouses() {
try {
const res = await getWarehouseSimpleList()
const data = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : [])
warehouseOptions.value = data.map((w) => ({
value: w.id,
label: w.name || String(w.id || '')
}))
} catch (e) {
console.error('loadWarehouses error', e)
}
}
//
function toggleAreaDropdown() {
if (!selectedWarehouse.value) {
uni.showToast({ title: '请先选择仓库', icon: 'none' })
return
}
showAreaDropdown.value = !showAreaDropdown.value
}
function handleSelectArea(item) {
selectedArea.value = item
showAreaDropdown.value = false
}
async function loadAreas(warehouseId) {
if (!warehouseId) return
loadingAreas.value = true
areaOptions.value = []
try {
const res = await getWarehouseAreaSimpleList(warehouseId)
const data = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : [])
areaOptions.value = data.map((a) => ({
value: a.id,
label: a.name || a.areaName || String(a.id || '')
}))
} catch (e) {
console.error('loadAreas error', e)
} finally {
loadingAreas.value = false
}
}
onShow(async () => {
const selectResult = getApp().globalData?._materialBeforeConfirm
if (selectResult) {
material.value = selectResult
inboundQty.value = null
getApp().globalData._materialBeforeConfirm = null
if (selectResult.id) {
try {
const res = await getSparepartDetail(selectResult.id)
const detail = res?.data || res
if (detail) {
material.value = { ...material.value, ...detail }
loadStockCount()
}
} catch (e) {
console.error('获取物料详情失败:', e)
}
}
}
loadWarehouses()
})
async function loadStockCount() {
const id = material.value.id
if (!id) return
try {
const res = await getSparepartStockCount(id)
material.value.count = (res?.data ?? res) != null ? Number(res?.data ?? res) : 0
} catch (e) {
console.error('获取库存失败:', e)
material.value.count = 0
}
}
onHide(() => {
showWarehouseDropdown.value = false
showAreaDropdown.value = false
})
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f5f6f8;
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
}
.material-section { padding: 0; }
.section-title-bar { display: flex; align-items: center; gap: 10rpx; padding: 24rpx 24rpx 18rpx; }
.section-bar-line { width: 6rpx; height: 32rpx; border-radius: 3rpx; background: #2563eb; flex-shrink: 0; }
.section-title { font-size: 30rpx; font-weight: 700; color: #1a1a1a; }
.material-card {
background: #fff; border-radius: 16rpx; padding: 24rpx; margin: 0 24rpx 20rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.04);
}
.card-top { display: flex; position: relative; }
.card-image-wrap {
width: 160rpx; height: 160rpx; border-radius: 12rpx; overflow: hidden;
background: #f8fafc; border: 1rpx solid #f0f0f0; flex-shrink: 0; margin-right: 20rpx;
}
.card-image { width: 100%; height: 100%; }
.card-image-empty { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: #f8fafc; }
.empty-img-icon { font-size: 56rpx; opacity: 0.3; }
.card-info-right { flex: 1; min-width: 0; }
.info-item { display: flex; align-items: center; margin-bottom: 8rpx; }
.info-label { font-size: 26rpx; color: #6b7280; flex-shrink: 0; }
.info-name { font-size: 30rpx; font-weight: 700; color: #0f172a; }
.info-value { font-size: 26rpx; color: #374151; }
.stock-highlight { font-size: 30rpx; font-weight: 700; color: #1f2937; }
.card-bottom { margin-top: 20rpx; padding-top: 20rpx; border-top: 1rpx solid #f0f0f0; }
.detail-row { display: flex; align-items: center; margin-bottom: 14rpx;
&:last-child { margin-bottom: 0; }
&.two-col { justify-content: space-between; }
}
.detail-col { display: flex; align-items: center; flex: 1; }
.detail-label { font-size: 24rpx; color: #9ca3af; flex-shrink: 0; }
.detail-value { font-size: 24rpx; color: #4b5563; }
.qty-input-card {
background: #fff; border-radius: 16rpx; padding: 24rpx; margin: 0 24rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.04);
}
.form-field { display: flex; flex-direction: column; gap: 12rpx; }
.form-label { font-size: 26rpx; color: #4b5563; font-weight: 500; }
.form-input { width: 100%; height: 88rpx; padding: 0 24rpx; font-size: 28rpx; color: #374151; background: #f8fafc; border-radius: 14rpx; box-sizing: border-box; }
.form-suffix-text { display: block; margin-top: 10rpx; font-size: 24rpx; color: #9ca3af; }
.convert-row { margin-top: 20rpx; padding-top: 20rpx; border-top: 1rpx solid #f0f0f0; display: flex; align-items: center; }
.convert-label-inline { font-size: 26rpx; color: #6b7280; }
.convert-value-inline { font-size: 36rpx; font-weight: 700; color: #1f2937; margin-left: auto; }
.convert-unit-inline { font-size: 24rpx; color: #64748b; margin-left: 8rpx; }
.convert-formula-inline { margin-top: 10rpx; font-size: 22rpx; color: #9ca3af; }
.select-row-card {
position: relative; display: flex; align-items: center; justify-content: space-between;
background: #fff; border-radius: 16rpx; padding: 24rpx; margin: 0 24rpx 20rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.04);
}
.full-dropdown { display: flex; align-items: center; justify-content: space-between; width: 100%; font-size: 28rpx; color: #374151;
.placeholder { color: #9ca3af; }
}
.warehouse-area-card { align-items: flex-start; }
.warehouse-area-rows { width: 100%; display: flex; flex-direction: column; gap: 16rpx; }
.warehouse-area-row { display: flex; align-items: center; }
.warehouse-area-label { width: 80rpx; font-size: 26rpx; color: #6b7280; flex-shrink: 0; }
.warehouse-area-dropdown { flex: 1; min-width: 0; position: relative; }
.dropdown-input { display: flex; align-items: center; height: 64rpx; padding: 0 20rpx; border: 1rpx solid #e0e0e0; border-radius: 10rpx; background: #f9fafb; }
.dropdown-value { flex: 1; font-size: 27rpx; color: #333; &.placeholder { color: #bbb; } }
.dropdown-arrow { font-size: 20rpx; color: #999; flex-shrink: 0; }
.dropdown-panel { position: absolute; top: 68rpx; left: 0; right: 0; z-index: 200; background: #fff; border: 1rpx solid #e0e0e0; border-radius: 12rpx; box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1); overflow: hidden; }
.dropdown-scroll { max-height: 360rpx; overflow-y: auto; }
.dropdown-item { display: flex; align-items: center; justify-content: space-between; padding: 20rpx 24rpx; border-bottom: 1rpx solid #f0f0f0;
&:last-child { border-bottom: 0; }
&.active { background: #f0f5ff; }
}
.dropdown-item-text { font-size: 27rpx; color: #333; }
.dropdown-check { font-size: 28rpx; color: #2563eb; font-weight: 700; }
.dropdown-empty { padding: 32rpx; text-align: center; color: #999; font-size: 26rpx; }
.bottom-actions {
position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 18rpx;
padding: 18rpx 24rpx calc(18rpx + env(safe-area-inset-bottom));
background: #ffffff; box-shadow: 0 -8rpx 24rpx rgba(15, 23, 42, 0.06); z-index: 99;
}
.bottom-btn { flex: 1; height: 84rpx; line-height: 84rpx; text-align: center; border-radius: 16rpx; font-size: 30rpx; font-weight: 600;
&:active { opacity: 0.85; }
}
.cancel-btn { background: #eef2f7; color: #475569; }
.confirm-btn { background: #1f4b79; color: #ffffff; }
</style>

@ -0,0 +1,294 @@
<template>
<view class="page-container">
<NavBar :title="'选择物料'" />
<!-- 搜索区 -->
<view class="search-bar">
<view class="search-input-wrap">
<text class="search-icon iconfont icon-search"></text>
<input class="search-input" v-model="searchText" placeholder="搜索物料名称/条码/规格" @input="onSearch" placeholder-class="search-placeholder" />
<text v-if="searchText" class="search-clear" @click="clearSearch"></text>
</view>
</view>
<!-- 物料列表 -->
<scroll-view scroll-y class="material-list" v-if="filteredList.length > 0">
<view
v-for="item in filteredList"
:key="item.id"
class="material-card"
:class="{ active: selectedId === item.id }"
@click="selectedId = item.id"
>
<view class="material-card-header">
<text class="material-name">{{ textValue(item.name) }}</text>
</view>
<view class="material-card-body">
<view class="material-info-row">
<text class="info-label">物料编码</text>
<text class="info-value">{{ textValue(item.barCode) }}</text>
</view>
<view class="material-info-row">
<text class="info-label">规格</text>
<text class="info-value">{{ textValue(item.standard || item.deviceSpec) }}</text>
</view>
<view class="material-info-row">
<text class="info-label">分类</text>
<text class="info-value">{{ textValue(item.categoryName) }}</text>
</view>
<view class="material-info-row">
<text class="info-label">单位</text>
<text class="info-value">{{ textValue(item.unitName) }}</text>
</view>
<view class="material-info-row">
<text class="info-label">采购单位</text>
<text class="info-value">{{ textValue(item.purchaseUnitName) }}</text>
</view>
<view class="material-info-row">
<text class="info-label">换算关系</text>
<text class="info-value">1{{ textValue(item.purchaseUnitName) }}={{ textValue(item.purchaseUnitConvertQuantity) }}{{ textValue(item.unitName) }}</text>
</view>
</view>
</view>
</scroll-view>
<!-- 空状态 -->
<view v-else class="empty-wrap">
<text v-if="loading" class="empty-text">...</text>
<text v-else class="empty-text">暂无物料数据</text>
</view>
<!-- 底部确认按钮 -->
<view class="bottom-actions">
<view class="bottom-btn confirm-btn" @click="handleConfirm">
确认
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { getMaterialSimpleList } from '@/api/mes/sparepart'
const materialList = ref([])
const selectedId = ref(null)
const searchText = ref('')
const loading = ref(false)
function textValue(v) {
if (v === 0) return '0'
if (v == null) return '-'
const s = String(v).trim()
return s || '-'
}
const filteredList = computed(() => {
let list = materialList.value
const keyword = searchText.value.trim().toLowerCase()
if (keyword) {
list = list.filter(item => {
return (item.name || '').toLowerCase().includes(keyword) ||
(item.barCode || '').toLowerCase().includes(keyword) ||
(item.standard || '').toLowerCase().includes(keyword)
})
}
return list
})
function onSearch() {}
function clearSearch() {
searchText.value = ''
}
async function loadMaterials() {
loading.value = true
try {
const raw = []
let page = 1
const maxPages = 5
while (page <= maxPages) {
const res = await getMaterialSimpleList(page)
let root = res && res.data !== undefined ? res.data : res
let pageList = Array.isArray(root)
? root
: Array.isArray(root?.list) ? root.list
: Array.isArray(root?.rows) ? root.rows
: []
if (!pageList.length) break
raw.push(...pageList)
if (pageList.length < 100) break
page++
}
// API categoryType=2
materialList.value = raw
console.log('[materialSelect] 加载全部物料:', raw.length)
} catch (e) {
console.error('loadMaterials error', e)
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function handleConfirm() {
if (!selectedId.value) {
uni.showToast({ title: '请选择物料', icon: 'none' })
return
}
const item = materialList.value.find((d) => d.id === selectedId.value)
if (!item) return
getApp().globalData._materialBeforeConfirm = item
uni.navigateTo({
url: '/pages_function/pages/materialInbound/materialConfirm'
})
}
onShow(async () => {
await loadMaterials()
})
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f5f6f8;
padding-bottom: 140rpx;
}
/* 搜索栏 */
.search-bar {
padding: 16rpx 24rpx;
background: #fff;
}
.search-input-wrap {
display: flex;
align-items: center;
height: 72rpx;
padding: 0 16rpx;
background: #f5f6f8;
border-radius: 36rpx;
}
.search-icon {
font-size: 32rpx;
color: #999;
margin-right: 12rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.search-placeholder {
color: #bbb;
}
.search-clear {
font-size: 28rpx;
color: #999;
padding: 8rpx;
}
/* 物料列表 */
.material-list {
padding: 16rpx 24rpx;
}
.material-card {
background: #fff;
border-radius: 14rpx;
padding: 24rpx;
margin-bottom: 16rpx;
border: 2rpx solid transparent;
&.active {
border-color: #2563eb;
background: #f0f5ff;
}
}
.material-card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16rpx;
}
.material-name {
font-size: 30rpx;
font-weight: 700;
color: #1a1a1a;
}
.material-card-body {
border-top: 1rpx solid #f0f0f0;
padding-top: 16rpx;
}
.material-info-row {
display: flex;
align-items: center;
margin-bottom: 10rpx;
&:last-child {
margin-bottom: 0;
}
}
.info-label {
width: 140rpx;
font-size: 24rpx;
color: #999;
flex-shrink: 0;
}
.info-value {
font-size: 26rpx;
color: #333;
}
/* 空状态 */
.empty-wrap {
padding: 120rpx 0;
text-align: center;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
/* 底部确认按钮 */
.bottom-actions {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 18rpx 24rpx calc(18rpx + env(safe-area-inset-bottom));
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.06);
z-index: 99;
}
.bottom-btn {
width: 100%;
height: 84rpx;
line-height: 84rpx;
text-align: center;
border-radius: 16rpx;
font-size: 30rpx;
font-weight: 600;
}
.confirm-btn {
background: #1f4b79;
color: #fff;
}
</style>

@ -63,7 +63,7 @@ const selectedId = ref('')
const searchText = ref('')
const userList = ref([])
const loading = ref(false)
const fromSource = ref('moldRepair') // moldRepair | sparepartInbound | sparepartOutbound
const fromSource = ref('moldRepair') // moldRepair | sparepartInbound | sparepartOutbound | materialInbound
let searchTimer = null
const pageTitle = computed(() => {
@ -124,7 +124,7 @@ function handleConfirm() {
return
}
// 使 globalData key
const keyMap = { sparepartInbound: '_sparepartInboundUserSelectResult', sparepartOutbound: '_sparepartOutboundUserSelectResult' }
const keyMap = { sparepartInbound: '_sparepartInboundUserSelectResult', sparepartOutbound: '_sparepartOutboundUserSelectResult', materialInbound: '_materialInboundUserSelectResult' }
const key = keyMap[fromSource.value] || '_moldRepairUserSelectResult'
getApp().globalData[key] = {
field: field.value === 'confirmBy' ? 'confirmBy' : 'acceptedBy',

@ -94,6 +94,9 @@ const MENU_ROUTE_MAP = {
sparepartinbound: '/pages_function/pages/sparepartInbound/index',
sparepartIn: '/pages_function/pages/sparepartInbound/index',
'备件入库': '/pages_function/pages/sparepartInbound/index',
materialInbound: '/pages_function/pages/materialInbound/index',
materialinbound: '/pages_function/pages/materialInbound/index',
'物料入库': '/pages_function/pages/materialInbound/index',
sparepartinventory: '/pages_function/pages/sparepartInventory/index',
'备件库存查询': '/pages_function/pages/sparepartInventory/index',
keypart: '/pages_function/pages/keypart/index',

Loading…
Cancel
Save