This commit is contained in:
2025-09-29 21:38:32 +08:00
parent ed26244cdb
commit 19117de6c8
182 changed files with 11590 additions and 2156 deletions

View File

@@ -0,0 +1,142 @@
<template>
<scroll-view scroll-y class="page" v-if="detail">
<view class="header">
<text class="model">{{ detail.model }}</text>
<text v-if="detail.deleted" class="status deleted">已删除</text>
</view>
<view class="section">
<view class="row"><text class="label">名称</text><text class="value">{{ detail.name || '-' }}</text></view>
<view class="row"><text class="label">品牌</text><text class="value">{{ detail.brand || '-' }}</text></view>
<view class="row"><text class="label">型号</text><text class="value">{{ detail.model || '-' }}</text></view>
<view class="row"><text class="label">条码</text><text class="value">{{ detail.barcode || '-' }}</text></view>
<view class="row"><text class="label">类别</text><text class="value">{{ categoryName }}</text></view>
<view class="row"><text class="label">模板</text><text class="value">{{ templateName }}</text></view>
<view class="row" v-if="detail.externalCode"><text class="label">编号</text><text class="value">{{ detail.externalCode }}</text></view>
</view>
<view class="section">
<view class="block-title">参数</view>
<view v-if="labeledPairs.length" class="params">
<view class="param" v-for="item in labeledPairs" :key="item.key">
<text class="param-key">{{ item.label }}<text v-if="item.unit">{{ item.unit }}</text></text>
<text class="param-val">{{ item.value }}</text>
</view>
</view>
<view v-else class="placeholder">未填写参数</view>
</view>
<view class="section">
<view class="block-title">图片</view>
<view v-if="detail.images && detail.images.length" class="images">
<image v-for="(img, idx) in detail.images" :key="idx" :src="img.url || img" class="image" mode="aspectFill" @click="preview(idx)" />
</view>
<view v-else class="placeholder">未上传图片</view>
</view>
<view class="section">
<view class="block-title">备注</view>
<view class="placeholder">{{ detail.remark || '无' }}</view>
</view>
<view class="footer">
<button size="mini" @click="back">返回</button>
<button size="mini" type="warn" @click="remove">删除</button>
</view>
</scroll-view>
<view v-else class="loading">加载中...</view>
</template>
<script>
import { get, del } from '../../common/http.js'
export default {
data() {
return { id: '', detail: null, categoryName: '-', templateName: '-' }
},
async onLoad(query) {
this.id = query?.id || ''
if (!this.id) { uni.showToast({ title: '参数缺失', icon: 'none' }); return }
await this.preloadDictionaries()
await this.loadDetail()
},
methods: {
async preloadDictionaries() {
try {
const needCats = !Array.isArray(uni.getStorageSync('CACHE_CATEGORIES'))
const needTpls = !Array.isArray(uni.getStorageSync('CACHE_TEMPLATES'))
if (!needCats && !needTpls) return
const reqs = []
if (needCats) reqs.push(get('/api/product-categories'))
if (needTpls) reqs.push(get('/api/product-templates'))
const res = await Promise.all(reqs)
let idx = 0
if (needCats) { const r = res[idx++]; const list = Array.isArray(r?.list)?r.list:(Array.isArray(r)?r:[]); uni.setStorageSync('CACHE_CATEGORIES', list) }
if (needTpls) { const r = res[idx++]; const list = Array.isArray(r?.list)?r.list:(Array.isArray(r)?r:[]); uni.setStorageSync('CACHE_TEMPLATES', list) }
} catch (_) {}
},
async loadDetail() {
try {
const data = await get('/api/products/' + this.id)
this.detail = data
this.categoryName = this.categoryLookup(data.categoryId)
this.templateName = this.templateLookup(data.templateId)
} catch (e) { uni.showToast({ title: e?.message || '加载失败', icon: 'none' }) }
},
preview(idx) {
try { const list = (this.detail?.images||[]).map(i => i.url || i); uni.previewImage({ urls: list, current: idx }) } catch (_) {}
},
categoryLookup(id) {
try { const list = uni.getStorageSync('CACHE_CATEGORIES') || []; const f = list.find(x => String(x.id)===String(id)); return f?f.name:'-'} catch(_){return'-'}
},
templateLookup(id) {
try { const list = uni.getStorageSync('CACHE_TEMPLATES') || []; const f = list.find(x => String(x.id)===String(id)); return f?f.name:'-'} catch(_){return'-'}
},
async remove() {
try {
const r = await new Promise(resolve => { uni.showModal({ content: '确认删除该货品?删除后可在后台恢复', success: resolve }) })
if (!r || !r.confirm) return
await del('/api/products/' + this.id)
uni.showToast({ title: '已删除', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) { uni.showToast({ title: '删除失败', icon: 'none' }) }
},
back(){ uni.navigateBack({ delta: 1 }) }
},
computed: {
labeledPairs() {
const params = this.detail?.parameters
if (!params || typeof params !== 'object') return []
let labelMap = {}, unitMap = {}
try {
const templates = uni.getStorageSync('CACHE_TEMPLATES') || []
const tpl = templates.find(t => String(t.id) === String(this.detail?.templateId))
if (tpl && Array.isArray(tpl.params)) for (const p of tpl.params) { labelMap[p.fieldKey] = p.fieldLabel; unitMap[p.fieldKey] = p.unit }
} catch (_) {}
return Object.keys(params).map(k => ({ key: k, label: labelMap[k] || k, unit: unitMap[k] || '', value: params[k] }))
}
}
}
</script>
<style lang="scss">
.page { padding: 24rpx 24rpx 160rpx; background: #f6f7fb; }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20rpx; }
.model { font-size: 36rpx; font-weight: 700; color: #2d3a4a; }
.status.deleted { font-size: 24rpx; padding: 6rpx 18rpx; border-radius: 999rpx; background: #c0c4cc; color: #fff; }
.section { background: #fff; border-radius: 16rpx; padding: 20rpx 22rpx; margin-bottom: 24rpx; box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.04); }
.row { display: flex; justify-content: space-between; padding: 12rpx 0; border-bottom: 1rpx solid #f1f2f5; }
.row:last-child { border-bottom: none; }
.label { width: 160rpx; font-size: 26rpx; color: #7a8899; }
.value { flex: 1; text-align: right; font-size: 26rpx; color: #2d3a4a; word-break: break-all; }
.block-title { font-size: 28rpx; font-weight: 600; color: #2d3a4a; margin-bottom: 12rpx; }
.placeholder { font-size: 26rpx; color: #7a8899; }
.params { display: flex; flex-direction: column; gap: 12rpx; }
.param { display: flex; justify-content: space-between; font-size: 26rpx; color: #2d3a4a; }
.param-key { color: #7a8899; }
.images { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12rpx; }
.image { width: 100%; height: 200rpx; border-radius: 16rpx; background: #f0f2f5; }
.footer { display: flex; justify-content: flex-end; gap: 20rpx; }
.loading { height: 100vh; display: flex; align-items: center; justify-content: center; color: #7a8899; }
</style>