WMS_PDA/pages/work/product/detail.vue

471 lines
11 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"></page-nav>
<scroll-view class="detail-content" scroll-y>
<view class="detail-card" v-if="item">
<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="90rpx"
height="90rpx"
>
<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="44rpx"
height="44rpx"
>
<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.goods_code || item.item_code || '--' }}</text>
</view>
<view class="compact-row">
<text class="compact-label">条码:</text>
<text class="compact-value">{{ getBarcodeText(item) }}</text>
</view>
</view>
</view>
</view>
<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">毛重:</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">
<text v-if="item.tag_price !== null && item.tag_price !== undefined && item.tag_price !== ''">¥</text>{{ item.tag_price || '--' }}
</text>
</view>
<view class="info-row">
<text class="label">零售价:</text>
<text class="value">
<text v-if="item.retail_price !== null && item.retail_price !== undefined && item.retail_price !== ''">¥</text>{{ 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">创建时间:</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: ''
};
},
onLoad(options) {
this.cacheKey = (options && options.cacheKey) || '';
if (!this.cacheKey) {
return;
}
const cached = uni.getStorageSync(this.cacheKey);
if (cached && typeof cached === 'object') {
this.item = cached;
}
},
onUnload() {
if (this.cacheKey) {
uni.removeStorageSync(this.cacheKey);
}
},
methods: {
getValueOrDash(value) {
return value === null || value === undefined || value === '' ? '--' : value;
},
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) {
return String(item.images[0]);
}
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(url => String(url)).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;
}
.detail-content {
flex: 1;
min-height: 0;
}
.detail-card {
background: #fff;
margin: 20rpx;
border-radius: 12rpx;
padding: 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: 30rpx;
font-weight: 600;
color: #303133;
}
.item-main-row {
display: flex;
align-items: center;
}
.item-thumb {
width: 90rpx;
margin-right: 20rpx;
flex-shrink: 0;
}
.goods-image {
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
}
.goods-image-grid {
width: 90rpx;
height: 90rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
.grid-cell {
position: relative;
width: 44rpx;
height: 44rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
}
.grid-image {
border-radius: 8rpx;
overflow: hidden;
}
.image-placeholder {
width: 90rpx;
height: 90rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.image-placeholder-small {
width: 44rpx;
height: 44rpx;
}
.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: 18rpx;
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: 24rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
}
.compact-value {
flex: 1;
font-size: 24rpx;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.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: 24rpx;
color: #909399;
flex-shrink: 0;
}
.value {
flex: 1;
font-size: 24rpx;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.empty-state {
padding: 160rpx 0 100rpx;
display: flex;
justify-content: center;
}
.empty-text {
font-size: 28rpx;
color: #909399;
}
</style>