feat: 新增备件入库详细页

master
zhongwenkai 3 days ago
parent 16a0af8bd3
commit e358345cf1

@ -43,3 +43,12 @@ export function deleteSparepartInbound(id) {
params: { ids: String(id) }
})
}
// 备件入库单详情
export function getSparepartInboundDetail(id) {
return request({
url: '/admin-api/erp/stock-in/get',
method: 'get',
params: { id }
})
}

@ -379,6 +379,13 @@
"navigationStyle": "custom"
}
},
{
"path": "sparepartInbound/detail",
"style": {
"navigationBarTitleText": "备件入库详情",
"navigationStyle": "custom"
}
},
{

@ -2,8 +2,8 @@
<view class="page-container">
<NavBar :title="t('sparepartInbound.createTitle')" />
<!-- 操作按钮区 -->
<view class="action-row">
<!-- 扫码/选择备件 - 固定在页面最上方 -->
<view class="top-action-bar">
<view class="scan-input-row">
<input
id="sparepart-inbound-scan-input"
@ -14,123 +14,124 @@
@confirm="onScanInputConfirm"
/>
</view>
<view class="action-btn select-btn" @click="handleSelectSparepart">
<view class="scan-btn" @click="handleSelectSparepart">
<text class="btn-text">{{ t('sparepartInbound.selectSparepart') }}</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>
<scroll-view scroll-y class="detail-scroll">
<view class="content-section">
<!-- 入库信息卡片 -->
<view class="section-card">
<view class="section-header">
<view class="section-icon">
<uni-icons type="compose" size="24" color="#1f7cff"></uni-icons>
</view>
<text class="section-title">{{ t('productInbound.inboundInfo') }}</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="attachment-area">
<view v-if="attachmentFileName" class="attachment-file-item">
<view class="file-icon">
<text class="file-icon-text">{{ getFileIcon(attachmentFileName) }}</text>
<view class="form-field">
<text class="form-label">入库时间<text class="required-star">*</text></text>
<picker mode="date" :value="inboundDate" @change="handleDateChange">
<view class="select-field">
<text :class="['select-text', inboundDate ? '' : 'placeholder']">{{ inboundDate || '请选择入库时间' }}</text>
<uni-icons type="calendar" size="18" color="#9ca3af"></uni-icons>
</view>
</picker>
</view>
<view class="file-info">
<text class="file-name" :title="attachmentFileName">{{ attachmentFileName }}</text>
<text v-if="attachmentFileSize" class="file-size">{{ formatFileSize(attachmentFileSize) }}</text>
<view class="form-field">
<text class="form-label">经办人<text class="required-star">*</text></text>
<view class="select-field" @click="goSelectOperator">
<text :class="['select-text', selectedOperatorName ? '' : 'placeholder']">{{ selectedOperatorName || '请选择经办人' }}</text>
<uni-icons type="right" size="18" color="#9ca3af"></uni-icons>
</view>
</view>
<view v-if="uploadLoading" class="file-uploading">
<text class="uploading-text">上传中...</text>
<view class="form-field">
<text class="form-label">备注</text>
<textarea v-model="remark" class="form-textarea" placeholder="请输入备注信息" placeholder-class="placeholder-text" maxlength="500" />
</view>
<view v-else class="file-delete" @click="removeAttachment">
<text class="delete-icon-sm"></text>
<view class="form-field">
<text class="form-label">附件</text>
<view class="attachment-upload" @click="handleAddAttachment">
<uni-icons type="paperclip" size="20" color="#1f7cff"></uni-icons>
<text>选取文件</text>
</view>
<view v-if="attachmentList.length" class="attachment-list">
<view v-for="(file, idx) in attachmentList" :key="idx" class="attachment-item">
<view class="attachment-main">
<uni-icons type="paperclip" size="16" color="#64748b"></uni-icons>
<text class="attachment-name">{{ file.name }}</text>
</view>
<view class="attachment-delete" @click="removeAttachment(idx)">
<uni-icons type="closeempty" size="18" color="#ef4444"></uni-icons>
</view>
</view>
</view>
</view>
</view>
<view class="attachment-add-file" @click="handleAddAttachment" v-if="!attachmentFileName">
<text class="add-text">选取文件</text>
</view>
</view>
</view>
<!-- 已选备件列表 -->
<view class="sparepart-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._sparepart && getItemImage(item._sparepart)"
:src="getItemImage(item._sparepart)"
class="item-image"
mode="aspectFill"
/>
<text v-else class="item-image-empty">📦</text>
<!-- 入库清单卡片 -->
<view class="section-card">
<view class="section-header list-header">
<view class="section-title-wrap">
<view class="section-icon">
<uni-icons type="list" size="24" color="#1f7cff"></uni-icons>
</view>
<text class="section-title">入库清单{{ itemList.length }}</text>
</view>
<view class="item-info">
<text class="item-name">{{ item.productName }}</text>
<text class="item-spec">{{ item.productBarCode || '-' }}</text>
<view class="add-product-btn" @click="handleSelectSparepart">
<uni-icons type="plusempty" size="16" color="#1f7cff"></uni-icons>
<text>添加备件</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 v-if="itemList.length" class="item-list">
<view v-for="(item, idx) in itemList" :key="idx" class="item-card">
<view class="image-box">
<image
v-if="item._sparepart && getItemImage(item._sparepart)"
:src="getItemImage(item._sparepart)"
class="item-image"
mode="aspectFill"
/>
<uni-icons v-else type="image" size="34" color="#cbd5e1"></uni-icons>
</view>
<view class="item-info">
<view class="item-header">
<text class="item-name">{{ textValue(item.productName) }}</text>
<view class="delete-btn" @click="removeItem(idx)">
<uni-icons type="trash" size="18" color="#ef4444"></uni-icons>
</view>
</view>
<view class="info-grid">
<view class="info-cell">
<text class="info-label">编码</text>
<text class="info-value">{{ item.productBarCode || '-' }}</text>
</view>
<view class="info-cell">
<text class="info-label">入库数量</text>
<text class="info-value">{{ item.inputCount }}{{ item.purchaseUnitName }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view v-else class="empty-wrap">
<text class="empty-text">请扫码或选择备件</text>
<view v-else class="empty-card" @click="handleSelectSparepart">
<uni-icons type="plusempty" size="30" color="#94a3b8"></uni-icons>
<text>请扫码或选择备件</text>
</view>
</view>
</view>
</view>
</scroll-view>
<!-- 底部操作栏 -->
<view class="bottom-actions">
<view class="bottom-btn cancel-btn" @click="handleCancel"></view>
<view class="bottom-btn confirm-btn" @click="handleSubmit"></view>
<view class="action-bar">
<view class="action-btn back-btn" @click="handleCancel"></view>
<view class="action-btn submit-btn" @click="handleSubmit"></view>
</view>
<sv-focus-no-keyboard ref="focusNoKeyboardRef"></sv-focus-no-keyboard>
@ -144,8 +145,6 @@ import { useI18n } from 'vue-i18n'
import NavBar from '@/components/common/NavBar.vue'
import { createSparepartInbound } from '@/api/mes/sparepartInbound'
import { getSparepartDetail } from '@/api/mes/sparepart'
import { getBaseUrl } from '@/utils/request'
import { getToken } from '@/utils/auth'
const { t } = useI18n()
@ -211,11 +210,8 @@ const selectedOperatorName = ref('')
//
const remark = ref('')
// web limit=1
const fileUrl = ref('') // JSON: {"fileName":"xxx.pdf","fileUrl":"https://..."}
const attachmentFileName = ref('') //
const attachmentFileSize = ref(0) //
const uploadLoading = ref(false) //
//
const attachmentList = ref([])
function formatDate(date) {
const y = date.getFullYear()
@ -228,6 +224,13 @@ function handleDateChange(e) {
inboundDate.value = e.detail.value
}
function textValue(v) {
if (v === 0) return '0'
if (v == null) return '-'
const s = String(v).trim()
return s || '-'
}
function getItemImage(sparepart) {
const images = sparepart.images
if (!images) return ''
@ -277,147 +280,38 @@ function goSelectOperator() {
}
//
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'
}
const ALLOWED_EXTS = ['png', 'jpg', 'jpeg', 'doc', 'xls', 'ppt', 'txt', 'pdf']
const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB
function handleAddAttachment() {
// #ifdef APP-PLUS
// APP plus.gallery
plus.gallery.pick(
(res) => {
const file = res?.files?.[0]
if (!file) return
const ext = (file.name || '').split('.').pop()?.toLowerCase()
if (!ALLOWED_EXTS.includes(ext)) {
uni.showToast({ title: '不支持的文件类型:.' + (ext || '未知'), icon: 'none' })
return
}
if (file.size > MAX_FILE_SIZE) {
uni.showToast({ title: '文件大小不能超过100MB', icon: 'none' })
return
}
uploadFile(file)
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: false }
() => {},
{ filter: 'all', multiple: true, maximum: 9 - attachmentList.value.length }
)
// #endif
// #ifndef APP-PLUS
// APP uni.chooseFile
uni.chooseFile({
count: 1,
type: 'all',
uni.chooseImage({
count: 9 - attachmentList.value.length,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
const tempFile = res.tempFiles?.[0]
if (!tempFile) return
const ext = (tempFile.name || '').split('.').pop()?.toLowerCase()
if (!ALLOWED_EXTS.includes(ext)) {
uni.showToast({ title: '不支持的文件类型:.' + (ext || '未知'), icon: 'none' })
return
}
if (tempFile.size > MAX_FILE_SIZE) {
uni.showToast({ title: '文件大小不能超过100MB', icon: 'none' })
return
}
uploadFile(tempFile)
},
fail: () => {
// chooseFile chooseImage
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (imgRes) => {
const path = imgRes.tempFilePaths?.[0]
if (!path) return
const parts = path.split('/')
const name = parts[parts.length - 1] || 'image.jpg'
uploadFile({ path, name, size: 0 })
}
res.tempFilePaths.forEach((path) => {
const parts = path.split('/')
attachmentList.value.push({ name: parts[parts.length - 1] || 'image.jpg', size: 0, path })
})
}
})
// #endif
}
async function uploadFile(file) {
uploadLoading.value = true
attachmentFileName.value = file.name || 'unknown'
attachmentFileSize.value = file.size || 0
// form-data
const formData = {
file: file.path // uni.uploadFile files
}
try {
const res = await new Promise((resolve, reject) => {
uni.uploadFile({
url: getBaseUrl() + '/admin-api/infra/file/upload',
filePath: file.path,
name: 'file',
header: {
'Authorization': 'Bearer ' + (getToken() || ''),
'tenantId': '1'
},
success: (uploadRes) => {
if (uploadRes.statusCode === 200) {
try {
const data = JSON.parse(uploadRes.data)
resolve(data)
} catch (e) {
reject(new Error('解析上传结果失败'))
}
} else {
reject(new Error('上传失败,状态码:' + uploadRes.statusCode))
}
},
fail: (err) => {
reject(err)
}
})
})
if (res.code === 0 && res.data) {
const { fileName, fileUrl: url } = res.data
fileUrl.value = JSON.stringify({ fileName: fileName || file.name, fileUrl: url })
attachmentFileName.value = fileName || file.name
uni.showToast({ title: '上传成功', icon: 'success' })
} else {
throw new Error(res.msg || '上传失败')
}
} catch (e) {
attachmentFileName.value = ''
attachmentFileSize.value = 0
fileUrl.value = ''
const msg = e?.message || '上传失败'
uni.showToast({ title: String(msg).substring(0, 50), icon: 'none' })
} finally {
uploadLoading.value = false
}
}
function removeAttachment() {
attachmentFileName.value = ''
attachmentFileSize.value = 0
fileUrl.value = ''
function removeAttachment(idx) {
attachmentList.value.splice(idx, 1)
}
async function handleSubmit() {
@ -467,9 +361,9 @@ async function handleSubmit() {
items: items
}
// web JSON
if (fileUrl.value) {
submitData.fileUrl = fileUrl.value
//
if (attachmentList.value.length) {
submitData.attachments = attachmentList.value.map((f) => f.path || f)
}
console.log('提交数据:', JSON.stringify(submitData))
@ -513,172 +407,53 @@ 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;
min-height: 72rpx !important;
height: 72rpx !important;
border-radius: 10rpx;
overflow: hidden;
}
.scan-input {
flex: 1;
min-height: 72rpx !important;
height: 72rpx !important;
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-icon-wrap { width: 44rpx; height: 44rpx; display: flex; align-items: center; justify-content: center; }
.btn-icon { font-size: 36rpx; color: #fff; }
.btn-text { font-size: 26rpx; font-weight: 600; color: #fff; }
}
/* 备件列表 */
.sparepart-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;
}
.page-container { min-height: 100vh; background: #f5f7fb; }
.top-action-bar { display: flex; align-items: center; gap: 16rpx; padding: 20rpx 24rpx; background: #ffffff; border-bottom: 1rpx solid #eef2f7; }
.detail-scroll { height: calc(100vh - 172rpx - 116rpx); }
.content-section { padding: 20rpx 24rpx 28rpx; }
.section-card { background: #ffffff; border-radius: 20rpx; padding: 24rpx; margin-bottom: 20rpx; border: 1rpx solid #eef2f7; box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04); }
.section-header { display: flex; align-items: center; gap: 12rpx; margin-bottom: 22rpx; padding-bottom: 18rpx; border-bottom: 1rpx solid #f1f5f9; }
.section-icon { width: 40rpx; height: 40rpx; border-radius: 10rpx; background: #eff6ff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.section-title { font-size: 32rpx; font-weight: 600; color: #1f2937; }
.section-title-wrap { display: flex; align-items: center; gap: 12rpx; min-width: 0; }
.list-header { justify-content: space-between; gap: 16rpx; }
.form-field { display: flex; flex-direction: column; gap: 12rpx; }
.form-field + .form-field { margin-top: 24rpx; }
.form-label { font-size: 26rpx; color: #4b5563; font-weight: 500; }
.required-star { color: #ef4444; font-size: 28rpx; margin-left: 4rpx; }
.select-field { display: flex; align-items: center; justify-content: space-between; padding: 0 24rpx; height: 76rpx; background: #f8fafc; border: 1rpx solid #e5e7eb; border-radius: 14rpx; box-sizing: border-box; }
.select-text { flex: 1; min-width: 0; font-size: 28rpx; color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.placeholder, .placeholder-text { color: #9ca3af; }
.form-textarea { width: 100%; min-height: 120rpx; background: #f8fafc; border-radius: 14rpx; padding: 18rpx 24rpx; font-size: 28rpx; color: #374151; box-sizing: border-box; }
.attachment-upload { height: 76rpx; border-radius: 14rpx; border: 1rpx dashed #bfdbfe; background: #eff6ff; color: #1f7cff; display: flex; align-items: center; justify-content: center; gap: 10rpx; font-size: 26rpx; font-weight: 600; }
.attachment-list { margin-top: 12rpx; display: flex; flex-direction: column; gap: 10rpx; }
.attachment-item { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; padding: 16rpx 18rpx; background: #f8fafc; border-radius: 12rpx; }
.attachment-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10rpx; }
.attachment-name { flex: 1; min-width: 0; font-size: 24rpx; color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-delete { width: 44rpx; height: 44rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.uploading-text { font-size: 22rpx; color: #2563eb; flex-shrink: 0; }
.add-product-btn { height: 60rpx; padding: 0 18rpx; border-radius: 999rpx; border: 1rpx solid #bfdbfe; background: #eff6ff; color: #1f7cff; font-size: 24rpx; font-weight: 600; display: flex; align-items: center; gap: 8rpx; flex-shrink: 0; }
.scan-input-row { flex: 1; }
.scan-input { width: 100%; height: 76rpx; padding: 0 20rpx; font-size: 26rpx; color: #333; background: #f8fafc; border: 1rpx solid #e5e7eb; border-radius: 14rpx; box-sizing: border-box; }
.scan-btn { display: flex; align-items: center; justify-content: center; height: 76rpx; padding: 0 24rpx; border-radius: 14rpx; background: #1f4b79; white-space: nowrap; flex-shrink: 0; }
.btn-text { font-size: 26rpx; font-weight: 600; color: #fff; }
.item-list { display: flex; flex-direction: column; gap: 18rpx; }
.item-card { display: flex; gap: 18rpx; padding: 20rpx; background: #ffffff; border: 1rpx solid #eef2f7; border-radius: 18rpx; box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04); }
.image-box { width: 128rpx; height: 128rpx; border-radius: 16rpx; background: #f8fafc; border: 1rpx solid #e5e7eb; display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden; }
.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; }
.file-uploading {
flex-shrink: 0;
.uploading-text { font-size: 22rpx; color: #2563eb; }
}
.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-icon { font-size: 32rpx; }
.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; }
.item-info { flex: 1; min-width: 0; }
.item-header { display: flex; align-items: center; gap: 12rpx; margin-bottom: 14rpx; }
.item-name { flex: 1; min-width: 0; font-size: 30rpx; font-weight: 600; color: #1f2937; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delete-btn { width: 48rpx; height: 48rpx; border-radius: 24rpx; background: #fef2f2; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12rpx; }
.info-cell { min-width: 0; display: flex; flex-direction: column; gap: 4rpx; }
.info-label { font-size: 22rpx; color: #9ca3af; }
.info-value { font-size: 26rpx; color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-card { min-height: 220rpx; border: 2rpx dashed #d7dde8; border-radius: 18rpx; background: #f8fafc; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14rpx; color: #94a3b8; font-size: 27rpx; }
.action-bar { 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; }
.action-btn { flex: 1; height: 84rpx; border-radius: 16rpx; display: flex; align-items: center; justify-content: center; font-size: 30rpx; font-weight: 600; }
.back-btn { background: #eef2f7; color: #475569; }
.submit-btn { background: #1f4b79; color: #ffffff; }
</style>

@ -0,0 +1,277 @@
<template>
<view class="page-container">
<NavBar :title="'备件入库详情'" />
<scroll-view scroll-y class="detail-scroll">
<view class="content-section">
<!-- 入库信息卡片 -->
<view class="section-card">
<view class="section-header">
<view class="section-icon">
<uni-icons type="compose" size="24" color="#1f7cff"></uni-icons>
</view>
<text class="section-title">入库信息</text>
<text :class="['status-tag', statusClass(detail.status)]">{{ statusText(detail.status) }}</text>
</view>
<view v-if="loading" class="loading-card">...</view>
<template v-else>
<view class="readonly-grid">
<view class="readonly-item">
<text class="readonly-label">单据号</text>
<text class="readonly-value">{{ textValue(detail.no) }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">入库类型</text>
<text class="readonly-value">{{ textValue(detail.inType) }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">入库时间</text>
<text class="readonly-value">{{ formatDateTime(detail.inTime || detail.createTime) }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">经办人</text>
<text class="readonly-value">{{ textValue(detail.stockUserName) }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">入库数量</text>
<text class="readonly-value highlight">{{ textValue(detail.totalCount) }}{{ detail.totalCount != null ? ' 个' : '' }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">审核人</text>
<text class="readonly-value">{{ textValue(detail.auditUserName) }}</text>
</view>
</view>
<view class="form-field">
<text class="form-label">备注</text>
<view class="readonly-box">{{ textValue(detail.remark) }}</view>
</view>
<view v-if="attachmentList.length" class="form-field">
<text class="form-label">附件</text>
<view class="attachment-list">
<view v-for="(file, idx) in attachmentList" :key="idx" class="attachment-item">
<uni-icons type="paperclip" size="16" color="#64748b"></uni-icons>
<text class="attachment-name">{{ textValue(getAttachmentName(file, idx)) }}</text>
</view>
</view>
</view>
</template>
</view>
<!-- 入库清单卡片 -->
<view class="section-card">
<view class="section-header list-header">
<view class="section-title-wrap">
<view class="section-icon">
<uni-icons type="list" size="24" color="#1f7cff"></uni-icons>
</view>
<text class="section-title">入库清单</text>
</view>
<text class="count-badge">{{ itemList.length }} </text>
</view>
<view v-if="itemList.length" class="summary-strip">
<view class="summary-item">
<text class="summary-value">{{ itemList.length }}</text>
<text class="summary-label">备件</text>
</view>
<view class="summary-item">
<text class="summary-value">{{ totalPieceCount }} </text>
<text class="summary-label">总数量</text>
</view>
</view>
<view v-if="itemList.length" class="item-list">
<view v-for="(item, idx) in itemList" :key="item.id || idx" class="item-card">
<view class="item-header">
<text class="item-name">{{ textValue(item.productName) }}</text>
<text class="item-code">{{ textValue(item.productBarCode) }}</text>
</view>
<view class="info-grid">
<view class="info-cell">
<text class="info-label">仓库</text>
<text class="info-value">{{ textValue(item.warehouseName) }}</text>
</view>
<view class="info-cell">
<text class="info-label">库区</text>
<text class="info-value">{{ textValue(item.areaName) }}</text>
</view>
<view class="info-cell">
<text class="info-label">数量</text>
<text class="info-value">{{ textValue(item.count) }}{{ getSparepartUnitData(item).unitName && ' ' + getSparepartUnitData(item).unitName }}</text>
</view>
<view class="info-cell">
<text class="info-label">换算关系</text>
<text class="info-value">{{ textValue(getSparepartUnitData(item).packagingRule) }}</text>
</view>
</view>
</view>
</view>
<view v-else class="empty-card">{{ loading ? '加载中...' : '暂无入库清单' }}</view>
</view>
</view>
</scroll-view>
<view class="action-bar">
<view class="action-btn back-btn" @click="handleBack"></view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { getSparepartInboundDetail } from '@/api/mes/sparepartInbound'
import { getSparepartDetail } from '@/api/mes/sparepart'
const detailId = ref(null)
const detail = ref({})
const loading = ref(false)
const sparepartMap = ref({}) // productId sparepart detail
const itemList = computed(() => {
const list = detail.value?.items || detail.value?.itemList || detail.value?.stockInItems || []
return Array.isArray(list) ? list : []
})
const attachmentList = computed(() => {
const raw = detail.value?.fileUrl || detail.value?.attachments || detail.value?.attachmentList
if (!raw) return []
if (Array.isArray(raw)) return raw
return typeof raw === 'object' ? [raw] : String(raw).split(',').map(s => s.trim()).filter(Boolean)
})
const totalPieceCount = computed(() => itemList.value.reduce((sum, item) => sum + (Number(item.count) || 0), 0))
function getSparepartUnitData(item) {
const sp = sparepartMap.value[item.productId]
const puName = sp?.purchaseUnitName || item.purchaseUnitName || ''
const puQty = sp?.purchaseUnitConvertQuantity || item.purchaseUnitConvertQuantity
const unitName = sp?.unitName || sp?.productUnitName || item.unitName || item.productUnitName || '个'
// packagingRule
let packagingRule = sp?.packagingRule || item.packagingRule || ''
if (!packagingRule && puName && puQty) {
packagingRule = `1${puName}=${puQty}${unitName}`
}
return {
packagingRule: packagingRule || '-',
unitName: unitName
}
}
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 '-'
const raw = typeof value === 'string' && /^\d+$/.test(value) ? Number(value) : value
const date = new Date(raw)
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())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
}
function statusText(s) {
const map = { 0: '待入库', 10: '待审核', 20: '已入库', 1: '已驳回' }
return map[Number(s)] || textValue(s)
}
function statusClass(s) {
const map = { 0: 'text-primary', 10: 'text-warning', 20: 'text-success', 1: 'text-danger' }
return map[Number(s)] || ''
}
function getAttachmentName(file, index) {
if (file?.name) return file.name
if (file?.fileName) return file.fileName
const text = String(file?.url || file?.fileUrl || file || '')
const name = text.split('/').pop()
return name || `附件${index + 1}`
}
async function loadDetail() {
if (!detailId.value) return
loading.value = true
try {
const res = await getSparepartInboundDetail(detailId.value)
detail.value = res?.data !== undefined ? res.data : res
//
const items = itemList.value
if (items.length) {
const ids = [...new Set(items.map(i => i.productId).filter(Boolean))]
const map = {}
await Promise.all(ids.map(async (id) => {
try {
const r = await getSparepartDetail(id)
const d = r?.data || r
if (d) map[id] = d
} catch (e) {}
}))
sparepartMap.value = map
}
} catch (e) {
uni.showToast({ title: '加载详情失败', icon: 'none' })
} finally {
loading.value = false
}
}
function handleBack() {
uni.navigateBack()
}
onLoad((options) => {
detailId.value = options?.id || null
loadDetail()
})
</script>
<style lang="scss" scoped>
.page-container { min-height: 100vh; background: #f5f7fb; }
.detail-scroll { height: calc(100vh - 172rpx); }
.content-section { padding: 20rpx 24rpx 28rpx; }
.section-card { background: #ffffff; border-radius: 20rpx; padding: 24rpx; margin-bottom: 20rpx; border: 1rpx solid #eef2f7; box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04); }
.section-header { display: flex; align-items: center; gap: 12rpx; margin-bottom: 22rpx; padding-bottom: 18rpx; border-bottom: 1rpx solid #f1f5f9; }
.section-icon { width: 40rpx; height: 40rpx; border-radius: 10rpx; background: #eff6ff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.section-title { font-size: 32rpx; font-weight: 600; color: #1f2937; }
.section-title-wrap { display: flex; align-items: center; gap: 12rpx; min-width: 0; }
.list-header { justify-content: space-between; gap: 16rpx; }
.count-badge { flex-shrink: 0; padding: 6rpx 16rpx; border-radius: 999rpx; background: #eff6ff; color: #1f7cff; font-size: 22rpx; font-weight: 600; }
.status-tag { margin-left: auto; flex-shrink: 0; padding: 8rpx 18rpx; border-radius: 999rpx; font-size: 22rpx; line-height: 1; background: #e2e8f0; color: #64748b; }
.status-tag.text-success { color: #15803d; background: #dcfce7; }
.status-tag.text-danger { color: #dc2626; background: #fee2e2; }
.status-tag.text-warning { color: #d97706; background: #fef3c7; }
.status-tag.text-primary { color: #1d4ed8; background: #dbeafe; }
.loading-card, .empty-card { min-height: 180rpx; border: 2rpx dashed #d7dde8; border-radius: 18rpx; background: #f8fafc; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 27rpx; }
.readonly-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; background: #ffffff; border: 1rpx solid #eef2f7; border-radius: 14rpx; overflow: hidden; }
.readonly-item { min-width: 0; display: flex; flex-direction: column; gap: 8rpx; padding: 18rpx 20rpx; border-right: 1rpx solid #f1f5f9; border-bottom: 1rpx solid #f1f5f9; }
.readonly-item:nth-child(2n) { border-right: 0; }
.readonly-label { font-size: 23rpx; color: #8a94a6; }
.readonly-value { font-size: 27rpx; color: #334155; line-height: 1.35; word-break: break-all; }
.readonly-value.highlight { color: #1f4b79; font-weight: 700; }
.form-field { display: flex; flex-direction: column; gap: 12rpx; margin-top: 24rpx; }
.form-label { font-size: 26rpx; color: #4b5563; font-weight: 500; }
.readonly-box { min-height: 70rpx; padding: 18rpx 24rpx; background: #f8fafc; border: 1rpx solid #e5e7eb; border-radius: 14rpx; box-sizing: border-box; font-size: 28rpx; color: #374151; line-height: 1.45; }
.attachment-list { display: flex; flex-direction: column; gap: 10rpx; }
.attachment-item { display: flex; align-items: center; gap: 10rpx; padding: 16rpx 18rpx; background: #f8fafc; border-radius: 12rpx; }
.attachment-name { flex: 1; min-width: 0; font-size: 24rpx; color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-strip { display: grid; grid-template-columns: repeat(2, 1fr); background: #f8fafc; border: 1rpx solid #e8eef6; border-radius: 16rpx; overflow: hidden; margin-bottom: 18rpx; }
.summary-item { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6rpx; padding: 16rpx 8rpx; border-right: 1rpx solid #eef2f7; }
.summary-item:last-child { border-right: 0; }
.summary-value { max-width: 100%; font-size: 30rpx; font-weight: 700; color: #1f4b79; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-label { font-size: 22rpx; color: #8a94a6; }
.item-list { display: flex; flex-direction: column; gap: 18rpx; }
.item-card { padding: 20rpx; background: #ffffff; border: 1rpx solid #eef2f7; border-radius: 18rpx; box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04); }
.item-header { display: flex; align-items: center; gap: 12rpx; margin-bottom: 14rpx; }
.item-name { flex: 1; min-width: 0; font-size: 30rpx; font-weight: 600; color: #1f2937; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-code { flex-shrink: 0; max-width: 240rpx; font-size: 24rpx; color: #8a94a6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12rpx; }
.info-cell { min-width: 0; display: flex; flex-direction: column; gap: 4rpx; }
.info-label { font-size: 22rpx; color: #9ca3af; }
.info-value { font-size: 26rpx; color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-bar { 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; }
.action-btn { flex: 1; height: 84rpx; border-radius: 16rpx; display: flex; align-items: center; justify-content: center; font-size: 30rpx; font-weight: 600; }
.back-btn { background: #1f4b79; color: #ffffff; }
</style>
Loading…
Cancel
Save