WMS_PDA/pages/work/product/detail.vue
2026-09-16 15:58:27 +08:00

823 lines
21 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="goods-detail-page">
<view class="normar_container">
<page-nav :title="title">
<template #right>
<u-button
class="nav-edit-btn"
size="mini"
type="info"
text="修改"
:customStyle="{ backgroundColor: '#3c9cff', borderColor: '#3c9cff', color: '#ffffff' }"
@click="openEditPage"
>
<text class="nav-edit-btn__text">修改</text>
</u-button>
</template>
</page-nav>
<view v-if="item" class="detail-fixed-header">
<view class="detail-card detail-card--header">
<view class="detail-header">
<view class="item-title-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="item-main-row">
<view class="item-thumb" @click="previewProductImage(item)">
<u-image
v-if="getImageList(item).length <= 1"
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
width="140rpx"
height="140rpx"
>
<template #error>
<view class="image-placeholder">
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-else class="goods-image-grid">
<view
class="grid-cell"
v-for="(img, imgIndex) in getImageThumbList(item)"
:key="img + '-' + imgIndex"
>
<u-image
class="grid-image"
:src="img"
mode="aspectFill"
width="68rpx"
height="68rpx"
>
<template #error>
<view class="image-placeholder image-placeholder-small">
<u-icon name="photo" size="18" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-if="imgIndex === 3 && getExtraImageCount(item) > 0" class="more-mask">
<text class="more-text">+{{ getExtraImageCount(item) }}</text>
</view>
</view>
</view>
</view>
<view class="item-info">
<view class="compact-row">
<text class="compact-label">商品编码:</text>
<text class="compact-value">{{ item.item_code || item.goods_code || '--' }}</text>
</view>
<view class="compact-row">
<text class="compact-label">条码:</text>
<text class="compact-value">{{ getBarcodeText(item) }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
<view v-if="item" class="detail-fixed-placeholder"></view>
<scroll-view class="detail-content" scroll-y>
<view class="detail-card detail-card--body" v-if="item">
<view class="info-section">
<view class="info-row">
<text class="label">名称:</text>
<text class="value">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="info-row">
<text class="label">货主:</text>
<text class="value">{{ getStoreOwnerText(item) }}</text>
</view>
<view class="info-row">
<text class="label">毛重(g):</text>
<text class="value">{{ item.gross_weight || '--' }}</text>
</view>
<view class="info-row">
<text class="label">品牌:</text>
<text class="value">{{ item.brand_name || '--' }}</text>
</view>
<view class="info-row">
<text class="label">违禁品类型:</text>
<text class="value">{{ (item.prohibited && item.prohibited.type_name) || '--' }}</text>
</view>
<view class="info-row">
<text class="label">SKU规格:</text>
<text class="value">{{ item.sku_property || '--' }}</text>
</view>
<view class="info-row">
<text class="label">库存数量:</text>
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
</view>
<view class="info-row">
<text class="label">锁定量:</text>
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
</view>
<view class="info-row">
<text class="label">可用库存:</text>
<text class="value">{{ item.available_quantity || '--' }}</text>
</view>
<view class="info-row">
<text class="label">锁定率:</text>
<text class="value">{{ item.lock_rate_display || '--' }}</text>
</view>
<view class="info-row">
<text class="label">库存单位:</text>
<text class="value">{{ item.stock_unit || '--' }}</text>
</view>
<view class="info-row">
<text class="label">标价(¥):</text>
<text class="value">{{ item.tag_price || '--' }}</text>
</view>
<view class="info-row">
<text class="label">零售价(¥):</text>
<text class="value">{{ item.retail_price || '--' }}</text>
</view>
<view class="info-row">
<text class="label">ABC分类:</text>
<text class="value">{{ item.level || '--' }}</text>
</view>
<view class="info-row">
<text class="label">体积:</text>
<text class="value">{{ item.box_volume || '--' }}</text>
</view>
<view class="info-row">
<text class="label">净重(g):</text>
<text class="value">{{ item.net_weight || '--' }}</text>
</view>
<!-- 管理标识 -->
<view class="detail-section-title">管理标识</view>
<view class="info-row">
<text class="label">序列号管理:</text>
<text class="value">{{ getFlagValue(item, ['is_sn_mgmt', 'is_serial_management', 'serial_management', 'is_serial', 'manage_serial']) }}</text>
</view>
<view class="info-row">
<text class="label">保质期管理:</text>
<text class="value">{{ getFlagValue(item, ['is_shelf_life_mgmt', 'is_expiry_management', 'expiry_management', 'is_expiry', 'manage_expiry']) }}</text>
</view>
<template v-if="isShelfLifeMgmtEnabled(item)">
<view class="shelf-life-block">
<view class="info-row">
<text class="label">保质期天数:</text>
<text class="value">{{ getValue(item, ['shelf_life_days', 'validity_days']) }}</text>
</view>
<view class="info-row">
<text class="label">入库最小天数:</text>
<text class="value">{{ getValue(item, ['inbound_min_days', 'min_inbound_days']) }}</text>
</view>
<view class="info-row">
<text class="label">出库最小天数:</text>
<text class="value">{{ getValue(item, ['outbound_min_days', 'min_outbound_days']) }}</text>
</view>
<view class="info-row">
<text class="label">剩余有效期:</text>
<text class="value">{{ getValue(item, ['remaining_threshold_days', 'remaining_validity_days']) }}</text>
</view>
</view>
</template>
<view class="info-row">
<text class="label">批次管理:</text>
<text class="value">{{ getFlagValue(item, ['is_batch_mgmt', 'is_batch_management', 'batch_management', 'is_batch', 'manage_batch']) }}</text>
</view>
<!-- 尺寸信息 -->
<view class="detail-section-title">尺寸信息</view>
<view class="info-row">
<text class="label">长度(cm):</text>
<text class="value">{{ getValue(item, ['length', 'item_length', 'box_length']) }}</text>
</view>
<view class="info-row">
<text class="label">宽度(cm):</text>
<text class="value">{{ getValue(item, ['width', 'item_width', 'box_width']) }}</text>
</view>
<view class="info-row">
<text class="label">高度(cm):</text>
<text class="value">{{ getValue(item, ['height', 'item_height', 'box_height']) }}</text>
</view>
<view class="info-row">
<text class="label">体积(cm³):</text>
<text class="value">{{ getValue(item, ['volume', 'item_volume', 'box_volume']) }}</text>
</view>
<!-- 箱规信息 -->
<view class="detail-section-title">箱规信息</view>
<view class="info-row">
<text class="label">启用箱规:</text>
<text class="value">{{ getFlagValue(item, ['enable_box_spec', 'enable_box_rule', 'is_box_rule', 'box_rule_enabled', 'use_box_rule', 'enabled_box_rule']) }}</text>
</view>
<template v-if="isBoxSpecEnabled(item)">
<view class="box-spec-block">
<view class="info-row">
<text class="label">每箱数量:</text>
<text class="value">{{ getValue(item, ['quantity_per_box']) }}</text>
</view>
<view class="info-row">
<text class="label">箱毛重(g):</text>
<text class="value">{{ getValue(item, ['box_gross_weight']) }}</text>
</view>
<view class="info-row">
<text class="label">箱净重(g):</text>
<text class="value">{{ getValue(item, ['box_net_weight']) }}</text>
</view>
<view class="info-row">
<text class="label">箱长(cm):</text>
<text class="value">{{ getValue(item, ['box_length']) }}</text>
</view>
<view class="info-row">
<text class="label">箱宽(cm):</text>
<text class="value">{{ getValue(item, ['box_width']) }}</text>
</view>
<view class="info-row">
<text class="label">箱高(cm):</text>
<text class="value">{{ getValue(item, ['box_height']) }}</text>
</view>
<view class="info-row">
<text class="label">箱体积(m³):</text>
<text class="value">{{ getValue(item, ['box_volume']) }}</text>
</view>
</view>
</template>
<!-- 打包要求 -->
<view class="info-row info-row--multiline">
<text class="label">打包要求:</text>
<text class="value value--multiline">{{ getValue(item, ['packing_requirements', 'package_requirement', 'packing_requirement', 'package_requirements']) }}</text>
</view>
<view class="info-row">
<text class="label">创建时间:</text>
<text class="value">{{ item.create_at_display || '--' }}</text>
</view>
<view class="info-row">
<text class="label">更新时间:</text>
<text class="value">{{ item.update_at_display || '--' }}</text>
</view>
</view>
</view>
<view v-else class="empty-state">
<text class="empty-text">暂无商品详情</text>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '商品详情',
item: null,
cacheKey: '',
onProductUpdated: null
};
},
onLoad(options) {
this.cacheKey = (options && options.cacheKey) || '';
this.onProductUpdated = payload => {
const nextItem = payload && payload.item;
if (!nextItem || typeof nextItem !== 'object') {
return;
}
this.item = {
...(this.item || {}),
...nextItem
};
if (this.cacheKey) {
uni.setStorageSync(this.cacheKey, this.item);
}
};
uni.$on('product:detail:updated', this.onProductUpdated);
if (!this.cacheKey) {
return;
}
const cached = uni.getStorageSync(this.cacheKey);
if (cached && typeof cached === 'object') {
this.item = cached;
}
},
onShow() {
// 从编辑页返回时,重新读取缓存,确保展示最新数据(含商品条码)
if (this.cacheKey) {
const cached = uni.getStorageSync(this.cacheKey);
if (cached && typeof cached === 'object') {
this.item = {
...(this.item || {}),
...cached
};
}
}
},
onUnload() {
if (this.onProductUpdated) {
uni.$off('product:detail:updated', this.onProductUpdated);
this.onProductUpdated = null;
}
if (this.cacheKey) {
uni.removeStorageSync(this.cacheKey);
}
},
methods: {
openEditPage() {
if (!this.item || typeof this.item !== 'object') {
uni.showToast({
title: '暂无可修改商品',
icon: 'none'
});
return;
}
const editCacheKey = `product_edit_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
uni.setStorageSync(editCacheKey, this.item);
uni.navigateTo({
url: `/pages/work/product/edit?cacheKey=${editCacheKey}&detailCacheKey=${encodeURIComponent(this.cacheKey || '')}`
});
},
getValueOrDash(value) {
return value === null || value === undefined || value === '' ? '--' : value;
},
isBoxSpecEnabled(item) {
if (!item || typeof item !== 'object') {
return false;
}
const val = item.enable_box_spec ?? item.enable_box_rule ?? item.is_box_rule ?? item.box_rule_enabled ?? item.use_box_rule ?? item.enabled_box_rule;
if (val === true || val === 1 || val === '1' || val === 'Y' || val === 'y' || val === '是' || String(val).toLowerCase() === 'true') {
return true;
}
return false;
},
isShelfLifeMgmtEnabled(item) {
if (!item || typeof item !== 'object') {
return false;
}
const val = item.is_shelf_life_mgmt ?? item.is_expiry_management ?? item.expiry_management ?? item.is_expiry ?? item.manage_expiry;
if (val === true || val === 1 || val === '1' || val === 'Y' || val === 'y' || val === '是' || String(val).toLowerCase() === 'true') {
return true;
}
return false;
},
getValue(item, fieldKeys) {
if (!item || typeof item !== 'object' || !Array.isArray(fieldKeys)) {
return '--';
}
for (const key of fieldKeys) {
const val = item[key];
if (val !== null && val !== undefined && val !== '') {
return val;
}
}
return '--';
},
getFlagValue(item, fieldKeys) {
const val = this.getValue(item, fieldKeys);
if (val === '--') {
return '--';
}
return this.toYesNoText(val);
},
toYesNoText(val) {
const str = String(val).trim().toLowerCase();
if (val === true || val === 1 || str === 'true' || str === 'yes' || str === 'y' || str === '是' || str === '启用' || str === '开启') {
return '是';
}
if (val === false || val === 0 || str === 'false' || str === 'no' || str === 'n' || str === '否' || str === '禁用' || str === '关闭') {
return '否';
}
return String(val);
},
getBarcodeText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
const barcodes = item.barcodes;
if (Array.isArray(barcodes) && barcodes.length > 0) {
return barcodes.filter(code => code !== null && code !== undefined && code !== '').join(';');
}
if (typeof barcodes === 'string' && barcodes.trim()) {
return barcodes;
}
return item.barcode || item.code || '--';
},
getImageUrl(item) {
if (!item || typeof item !== 'object') {
return '';
}
const candidate = item.image || item.image_url || item.img || item.pic || item.photo || item.cover || item.cover_url;
if (candidate) {
return String(candidate);
}
if (Array.isArray(item.images) && item.images.length > 0) {
const firstImage = item.images[0];
if (!firstImage) {
return '';
}
if (typeof firstImage === 'string') {
return firstImage;
}
if (typeof firstImage === 'object') {
return String(firstImage.url || firstImage.path || firstImage.successUrl || firstImage.fileUrl || firstImage.image_url || '');
}
return '';
}
if (Array.isArray(item.pics) && item.pics.length > 0) {
return String(item.pics[0]);
}
return '';
},
getImageList(item) {
if (!item || typeof item !== 'object') {
return [];
}
if (Array.isArray(item.images) && item.images.length > 0) {
return item.images
.map(image => {
if (!image) {
return '';
}
if (typeof image === 'string') {
return image;
}
if (typeof image === 'object') {
return image.url || image.path || image.successUrl || image.fileUrl || image.image_url || '';
}
return '';
})
.filter(Boolean);
}
if (Array.isArray(item.pics) && item.pics.length > 0) {
return item.pics.map(url => String(url)).filter(Boolean);
}
const single = this.getImageUrl(item);
return single ? [single] : [];
},
getImageThumbList(item) {
return this.getImageList(item).slice(0, 4);
},
getExtraImageCount(item) {
const total = this.getImageList(item).length;
return total > 4 ? total - 4 : 0;
},
previewProductImage(item) {
const urls = this.getImageList(item);
if (!urls.length) {
uni.showToast({
title: '暂无可预览图片',
icon: 'none'
});
return;
}
uni.previewImage({
current: urls[0],
urls
});
},
getStoreOwnerText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
const directValue = item['store.store_remask'] || item['store_stock.store_remask'] || item.store_remask;
if (directValue !== null && directValue !== undefined && directValue !== '') {
return directValue;
}
if (item.store_stock && typeof item.store_stock === 'object' && item.store_stock.store_remask) {
return item.store_stock.store_remask;
}
if (item.store && typeof item.store === 'object' && item.store.store_remask) {
return item.store.store_remask;
}
return '--';
}
}
};
</script>
<style lang="scss" scoped>
.goods-detail-page {
background: #f7f8fa;
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.normar_container {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
overflow: hidden;
}
::v-deep .nav-title .right {
width: auto;
min-width: 120rpx;
display: flex;
justify-content: flex-end;
align-items: center;
}
::v-deep .nav-edit-btn {
min-width: 132rpx !important;
padding: 0 26rpx !important;
height: 64rpx !important;
line-height: 64rpx !important;
margin-right: 18rpx !important;
border-radius: 12rpx !important;
box-shadow: 0 4rpx 12rpx rgba(60, 156, 255, 0.22);
}
::v-deep .nav-edit-btn .u-button {
background-color: #3c9cff !important;
border-color: #3c9cff !important;
color: #ffffff !important;
border-radius: 12rpx !important;
}
.nav-edit-btn__text {
font-size: 26rpx;
font-weight: 600;
color: #ffffff;
}
::v-deep .nav-edit-btn .u-button__text {
font-size: 26rpx !important;
font-weight: 600 !important;
}
.detail-fixed-header {
flex-shrink: 0;
position: fixed;
left: 0;
right: 0;
top: calc(var(--status-bar-height) + 110rpx);
z-index: 30;
background: #f7f8fa;
padding: 0 20rpx 0;
box-shadow: 0 2rpx 10rpx rgba(15, 23, 42, 0.04);
}
.detail-fixed-placeholder {
flex-shrink: 0;
height: 290rpx;
}
.detail-content {
flex: 1;
min-height: 0;
position: relative;
z-index: 0;
}
.detail-card {
background: #fff;
margin: 20rpx;
border-radius: 12rpx;
padding: 20rpx;
}
.detail-card--header {
margin: 0;
padding: 20rpx;
border-radius: 0 0 12rpx 12rpx;
}
.detail-card--body {
margin-top: 20rpx;
}
.detail-header {
padding-bottom: 18rpx;
border-bottom: 2rpx solid #e5e7eb;
}
.info-section {
padding-top: 16rpx;
}
.item-title-row {
margin-bottom: 10rpx;
}
.goods-name {
font-size: 42rpx;
font-weight: 600;
color: #303133;
}
.item-main-row {
display: flex;
align-items: center;
}
.item-thumb {
width: 140rpx;
margin-right: 20rpx;
flex-shrink: 0;
}
.goods-image {
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
}
.goods-image-grid {
width: 140rpx;
height: 140rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
.grid-cell {
position: relative;
width: 68rpx;
height: 68rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
}
.grid-image {
border-radius: 8rpx;
overflow: hidden;
}
.image-placeholder {
width: 140rpx;
height: 140rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.image-placeholder-small {
width: 68rpx;
height: 68rpx;
}
.more-mask {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.45);
display: flex;
align-items: center;
justify-content: center;
}
.more-text {
font-size: 22rpx;
color: #fff;
font-weight: 600;
}
.item-info {
flex: 1;
min-width: 0;
}
.compact-row {
display: flex;
align-items: center;
line-height: 1.4;
margin-bottom: 2rpx;
}
.compact-row:last-child {
margin-bottom: 0;
}
.compact-label {
width: auto;
margin-right: 6rpx;
font-size: 40rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
}
.compact-value {
flex: 1;
font-size: 40rpx;
color: #000;
word-break: break-all;
}
.detail-section-title {
padding: 24rpx 0 12rpx;
font-size: 35rpx;
font-weight: bold;
color: #303133;
}
.shelf-life-block {
margin: 12rpx 0 16rpx;
padding: 20rpx;
border: 2rpx solid #dcdfe6;
border-radius: 12rpx;
background: #f8fafc;
}
.box-spec-block {
margin: 12rpx 0 16rpx;
padding: 20rpx;
border: 2rpx solid #dcdfe6;
border-radius: 12rpx;
background: #f8fafc;
}
.info-row {
display: flex;
align-items: center;
line-height: 1.6;
margin-bottom: 6rpx;
}
.info-row:last-child {
margin-bottom: 0;
}
.label {
width: auto;
margin-right: 6rpx;
font-size: 40rpx;
color: #909399;
flex-shrink: 0;
}
.info-row--multiline {
align-items: flex-start;
}
.value {
flex: 1;
font-size: 40rpx;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.value--multiline {
white-space: pre-wrap;
overflow: visible;
text-overflow: clip;
word-break: break-all;
line-height: 1.6;
}
/* 底部安全区:适配真机底部 home 指示条,避免最后一行被遮挡 */
.safe-area-bottom {
height: 20rpx;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
.empty-state {
padding: 160rpx 0 100rpx;
display: flex;
justify-content: center;
}
.empty-text {
font-size: 28rpx;
color: #909399;
}
</style>