285 lines
6.1 KiB
Vue
285 lines
6.1 KiB
Vue
<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="image-section">
|
||
<u-image
|
||
class="main-image"
|
||
:src="getImageUrl(item)"
|
||
mode="aspectFit"
|
||
width="100%"
|
||
height="360rpx"
|
||
@click="previewProductImage(item)"
|
||
>
|
||
<template #error>
|
||
<view class="image-placeholder">
|
||
<u-icon name="photo" size="42" color="#c0c4cc"></u-icon>
|
||
</view>
|
||
</template>
|
||
</u-image>
|
||
</view>
|
||
|
||
<view class="info-section">
|
||
<view class="name-row">
|
||
<text class="goods-name">{{ 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.goods_code || item.item_code || '--' }}</text>
|
||
</view>
|
||
<view class="info-row">
|
||
<text class="label">条码:</text>
|
||
<text class="value">{{ getBarcodeText(item) }}</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">{{ item.stock_unit || '--' }}</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>
|
||
</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] : [];
|
||
},
|
||
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;
|
||
}
|
||
|
||
.image-section {
|
||
margin-bottom: 16rpx;
|
||
}
|
||
|
||
.main-image {
|
||
border-radius: 10rpx;
|
||
overflow: hidden;
|
||
background: #f5f7fa;
|
||
}
|
||
|
||
.image-placeholder {
|
||
width: 100%;
|
||
height: 360rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f5f7fa;
|
||
}
|
||
|
||
.name-row {
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.goods-name {
|
||
font-size: 30rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.info-row {
|
||
display: flex;
|
||
align-items: center;
|
||
line-height: 1.6;
|
||
margin-bottom: 6rpx;
|
||
}
|
||
|
||
.info-row:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.label {
|
||
width: 120rpx;
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.value {
|
||
flex: 1;
|
||
font-size: 24rpx;
|
||
color: #606266;
|
||
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>
|