WMS_PDA/pages/work/product/detail.vue

620 lines
14 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.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>
</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="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;
}
},
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}`
});
},
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) {
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: 35rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
}
.compact-value {
flex: 1;
font-size: 35rpx;
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: 35rpx;
color: #909399;
flex-shrink: 0;
}
.value {
flex: 1;
font-size: 35rpx;
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>