This commit is contained in:
hero920103 committed 2026-10-19 01:13:17 +08:00
1 parent 5718a00e31
commit 1850ac640e
226 files changed
+37772 -12071

No files matched your search

+391
View File
@@ -0,0 +1,391 @@
<template>
<view class="page">
<view v-if="loading && !product" class="state-box">
<text class="state-text">加载中...</text>
</view>
<block v-else-if="product">
<view class="hero">
<view class="hero-top">
<text class="hero-name">{{ product.product_name }}</text>
<u-tag v-if="!isOnSale" text="停用/草稿" type="info" size="mini" />
</view>
<text class="hero-code">{{ product.product_code || '无编码' }}</text>
<view class="hero-grid">
<view class="hero-cell">
<text class="cell-label">总库存</text>
<text class="cell-value">{{ qtyText(product.total_stock) }} {{ product.base_unit || '' }}</text>
</view>
<view class="hero-cell">
<text class="cell-label">库存状态</text>
<text class="cell-value">{{ safetyStateLabel(product.safety_state) }}</text>
</view>
<view class="hero-cell">
<text class="cell-label">售价</text>
<text class="cell-value">¥{{ moneyText(product.sale_price) }}</text>
</view>
</view>
</view>
<view class="card">
<view class="block-head">
<text class="block-title">商品资料</text>
</view>
<view class="line">
<text class="line-label">分类</text>
<text class="line-value">{{ product.category_name || '未分类' }}</text>
</view>
<view class="line">
<text class="line-label">品牌 / 规格</text>
<text class="line-value">{{ join([product.brand, product.spec]) }}</text>
</view>
<view class="line">
<text class="line-label">型号</text>
<text class="line-value">{{ dash(product.model) }}</text>
</view>
<view class="line">
<text class="line-label">单位</text>
<text class="line-value">
{{ dash(product.base_unit) }}
<text v-if="product.aux_unit"> / 辅 {{ product.aux_unit }} × {{ qtyText(product.aux_ratio || 1) }}</text>
</text>
</view>
<view class="line">
<text class="line-label">条码</text>
<text class="line-value">{{ dash(product.barcode) }}</text>
</view>
<view v-if="product.remark" class="remark">
<text>{{ product.remark }}</text>
</view>
</view>
<view class="card">
<view class="block-head">
<text class="block-title">价格与管控</text>
<text class="block-tip">手机端只读</text>
</view>
<view class="grid3">
<view v-for="p in priceCells" :key="p.label" class="g-cell">
<text class="cell-label">{{ p.label }}</text>
<text class="cell-value">{{ p.value }}</text>
</view>
</view>
</view>
<view class="card">
<view class="block-head">
<text class="block-title">分仓库存({{ stocks.length }} 行)</text>
<text class="block-tip">货值 ¥{{ moneyText(stockAmount) }}</text>
</view>
<view v-if="!stocks.length" class="empty-line">
<text>暂无在库库存</text>
</view>
<view v-for="(s, i) in stocks" :key="i" class="line">
<view class="line-label grow">
<text>{{ s.warehouse_name || `仓库#${s.warehouse_id}` }}</text>
<text v-if="s.batch_no" class="sub">批次 {{ s.batch_no }}</text>
</view>
<text class="line-value">{{ qtyText(s.quantity) }} · ¥{{ moneyText(s.cost_price) }}</text>
</view>
</view>
<view class="footer-space"></view>
<view class="actions">
<view class="act" @tap="go('/pages/erp/stock/ledger')">
<text>出入库流水</text>
</view>
<view class="act" @tap="go('/pages/erp/stock/batch')">
<text>批次台账</text>
</view>
<view class="act primary" @tap="go('/pages/erp/document/index')">
<text>相关单据</text>
</view>
</view>
</block>
</view>
</template>
<script setup>
/**
* 商品详情(只读):资料 / 价格 / 库存管控 / 分仓结存。
* 建档与改价一律回 Web 端,这里把「这个货现在有多少、成本多少、卖多少」讲清楚,
* 现场接单或盘库时一眼能判断能不能发。
*/
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getProduct,
moneyText,
qtyText,
safetyStateLabel
} from '@/api/erp.js'
const product = ref(null)
const loading = ref(false)
const productId = ref(0)
const stocks = computed(() => product.value?.stocks || [])
const stockAmount = computed(() => stocks.value.reduce((sum, s) => sum + Number(s.amount || 0), 0))
const isOnSale = computed(() => Number(product.value?.status) === 1 && Number(product.value?.is_draft) !== 1)
const priceCells = computed(() => {
const p = product.value || {}
return [
{ label: '采购价', value: `¥${moneyText(p.purchase_price)}` },
{ label: '销售价', value: `¥${moneyText(p.sale_price)}` },
{ label: '批发价', value: `¥${moneyText(p.wholesale_price)}` },
{ label: '会员价', value: `¥${moneyText(p.member_price)}` },
{ label: '最低售价', value: `¥${moneyText(p.min_price)}` },
{ label: '税率', value: `${Number(p.tax_rate || 0)}%` },
{ label: '安全库存', value: qtyText(p.safety_qty) },
{ label: '最高库存', value: qtyText(p.max_qty) },
{ label: '保质期', value: Number(p.shelf_life_days) > 0 ? `${p.shelf_life_days} 天` : '不管理' },
{ label: '批次管理', value: Number(p.enable_batch) === 1 ? '启用' : '关闭' }
]
})
onLoad((query = {}) => {
productId.value = Number(query.id) || 0
load()
})
async function load() {
if (!productId.value) {
uni.showToast({ title: '缺少商品 ID', icon: 'none' })
return
}
loading.value = true
try {
product.value = await getProduct(productId.value)
if (product.value?.product_name) uni.setNavigationBarTitle({ title: product.value.product_name })
} catch (e) {
uni.showToast({ title: '商品加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function go(base) {
uni.navigateTo({ url: `${base}?product_id=${productId.value}` })
}
function dash(v) {
const s = String(v ?? '').trim()
return s || '—'
}
function join(arr) {
const s = (arr || []).filter(Boolean).join(' / ')
return s || '—'
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding-top: 20rpx;
}
.hero {
margin: 0 $page-padding-x 24rpx;
padding: 32rpx;
border-radius: $radius-lg;
background: $hero-gradient;
color: #ffffff;
box-shadow: $shadow-float;
}
.hero-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16rpx;
}
.hero-name {
flex: 1;
font-size: 36rpx;
font-weight: 600;
line-height: 1.4;
}
.hero-code {
display: block;
margin-top: 8rpx;
font-size: 24rpx;
opacity: 0.85;
}
.hero-grid {
display: flex;
margin-top: 28rpx;
padding-top: 22rpx;
border-top: 1rpx solid rgba(255, 255, 255, 0.22);
}
.hero-cell {
flex: 1;
.cell-label {
display: block;
font-size: 22rpx;
opacity: 0.8;
}
.cell-value {
display: block;
margin-top: 6rpx;
font-size: 28rpx;
font-weight: 500;
}
}
.card {
@include card;
margin: 0 $page-padding-x 24rpx;
padding: 24rpx 28rpx;
}
.block-head {
@include block-head;
}
.block-title {
@include section-title;
}
.block-tip {
font-size: 22rpx;
color: $color-text-muted;
}
.line {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
padding: 14rpx 0;
border-bottom: 1rpx solid $color-divider;
font-size: 26rpx;
&:last-child {
border-bottom: none;
}
}
.line-label {
color: $color-text-secondary;
flex-shrink: 0;
&.grow {
flex: 1;
min-width: 0;
}
}
.sub {
display: block;
margin-top: 4rpx;
font-size: 22rpx;
color: $color-text-muted;
}
.line-value {
flex: 1;
text-align: right;
color: $color-text;
word-break: break-all;
}
.grid3 {
display: flex;
flex-wrap: wrap;
}
.g-cell {
width: 33.33%;
padding: 12rpx 0;
.cell-label {
display: block;
font-size: 22rpx;
color: $color-text-muted;
}
.cell-value {
display: block;
margin-top: 4rpx;
font-size: 26rpx;
color: $color-text;
}
}
.remark {
margin-top: 12rpx;
padding: 16rpx 20rpx;
background: $color-bg-page;
border-radius: $radius-sm;
font-size: 24rpx;
line-height: 1.6;
color: $color-text-secondary;
}
.empty-line {
padding: 40rpx 0;
text-align: center;
font-size: 25rpx;
color: $color-text-muted;
}
.footer-space {
height: calc(150rpx + env(safe-area-inset-bottom));
}
.actions {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 16rpx;
padding: 18rpx $page-padding-x calc(18rpx + env(safe-area-inset-bottom));
background: $color-card;
box-shadow: 0 -4rpx 16rpx rgba(15, 23, 42, 0.06);
@include dialog-responsive;
}
.act {
flex: 1;
height: 76rpx;
line-height: 76rpx;
text-align: center;
border-radius: $radius-full;
background: $color-bg-page;
font-size: 26rpx;
color: $color-text-secondary;
&.primary {
background: #2563eb;
color: #ffffff;
}
&:active {
opacity: 0.85;
}
}
.state-box {
display: flex;
justify-content: center;
padding: 140rpx 0;
}
.state-text {
font-size: 28rpx;
color: $color-text-muted;
}
</style>
+368
View File
@@ -0,0 +1,368 @@
<template>
<view class="page">
<view class="filter-bar">
<view class="search-box">
<FaIcon name="magnifying-glass" color="#94a3b8" :size="16" />
<input
v-model="keyword"
class="search-input"
placeholder="搜索商品名称 / 编码 / 条码"
confirm-type="search"
@confirm="refresh"
/>
<text v-if="keyword" class="search-clear" @tap="clearKeyword">清空</text>
</view>
<view class="chip-row">
<view class="chip" :class="{ active: filterKey === 'category' }" @tap="openPicker('category')">
<text>{{ categoryName || '全部分类' }}</text>
<FaIcon name="chevron-right" color="#94a3b8" :size="12" />
</view>
<view class="chip" :class="{ active: onlyEnabled }" @tap="toggleEnabled">
<text>仅在售</text>
</view>
<view class="chip count">
<text>共 {{ total }} 个</text>
</view>
</view>
</view>
<view v-if="loading && !list.length" class="state-box">
<text class="state-text">加载中...</text>
</view>
<view v-else-if="!list.length" class="state-box">
<u-empty mode="search" text="没有匹配的商品" />
<text class="state-tip">商品建档请在 Web 后台「进销存 - 商品档案」完成</text>
</view>
<template v-else>
<view v-for="row in list" :key="row.id" class="p-card" @tap="openDetail(row)">
<view class="p-top">
<text class="p-name">{{ row.product_name }}</text>
<u-tag
v-if="row.safety_state !== 'normal'"
:text="safetyStateLabel(row.safety_state)"
:type="row.safety_state === 'low' ? 'warning' : 'primary'"
size="mini"
/>
<u-tag v-else-if="!isOnSale(row)" text="停用" type="info" size="mini" />
</view>
<text class="p-sub">{{ [row.product_code, row.spec, row.category_name].filter(Boolean).join(' · ') || '—' }}</text>
<view class="p-grid">
<view class="p-cell">
<text class="cell-label">库存</text>
<text class="cell-value">{{ qtyText(row.total_stock) }} {{ row.base_unit || '' }}</text>
</view>
<view class="p-cell">
<text class="cell-label">售价</text>
<text class="cell-value">¥{{ moneyText(row.sale_price) }}</text>
</view>
<view class="p-cell">
<text class="cell-label">采购价</text>
<text class="cell-value">¥{{ moneyText(row.purchase_price) }}</text>
</view>
</view>
</view>
<view v-if="finished" class="load-done">
<text>{{ list.length ? '没有更多了' : '' }}</text>
</view>
</template>
<ErpPicker
:show="picker.show"
title="选择分类"
placeholder="搜索分类"
:options="categoryOptions"
:model-value="categoryId"
@update:show="picker.show = false"
@select="onCategory"
/>
</view>
</template>
<script setup>
/**
* 商品档案(移动端只读)。
* 建档、改价、启停都在 Web 后台做,手机端只负责「查得到、看得清、点得进」,
* 库存与价格取的正是 Web 端同一批接口字段,两端不会出现两套数。
*/
import { computed, ref } from 'vue'
import { onReachBottom, onShow } from '@dcloudio/uni-app'
import FaIcon from '@/components/FaIcon.vue'
import ErpPicker from '@/components/erp/ErpPicker.vue'
import {
fetchCategories,
fetchProducts,
moneyText,
qtyText,
safetyStateLabel
} from '@/api/erp.js'
const PAGE_SIZE = 20
const list = ref([])
const total = ref(0)
const page = ref(1)
const loading = ref(false)
const finished = ref(false)
const keyword = ref('')
const categoryId = ref('')
const onlyEnabled = ref(false)
const categories = ref([])
const picker = ref({ show: false })
const filterKey = ref('')
const categoryName = computed(() => {
const hit = categories.value.find((c) => String(c.id) === String(categoryId.value))
return hit ? hit.name : ''
})
const categoryOptions = computed(() =>
categories.value.map((c) => ({
value: c.id,
label: c.name,
sub: c.level_text || '',
extra: `${c.product_count || 0} 个`
}))
)
onShow(() => {
refresh()
loadCategories()
})
onReachBottom(() => {
if (finished.value || loading.value) return
loadMore()
})
async function loadCategories() {
if (categories.value.length) return
try {
const { list: rows } = await fetchCategories()
const nameOf = {}
rows.forEach((c) => {
nameOf[c.id] = c.category_name
})
categories.value = rows.map((c) => ({
id: c.id,
name: c.category_name,
level_text: c.parent_id && nameOf[c.parent_id] ? `上级:${nameOf[c.parent_id]}` : '',
product_count: c.product_count || 0
}))
} catch (e) {
// 分类拉不到不影响商品列表,只是筛选栏少一项
}
}
async function refresh() {
page.value = 1
finished.value = false
list.value = []
await loadPage()
}
async function loadMore() {
page.value += 1
await loadPage()
}
async function loadPage() {
loading.value = true
try {
const data = await fetchProducts({
page: page.value,
pageSize: PAGE_SIZE,
keyword: keyword.value.trim(),
categoryId: categoryId.value,
onlyEnabled: onlyEnabled.value
})
const rows = data.list || []
list.value = page.value === 1 ? rows : [...list.value, ...rows]
total.value = data.total || 0
finished.value = list.value.length >= total.value
} catch (e) {
if (page.value > 1) page.value -= 1
} finally {
loading.value = false
}
}
function clearKeyword() {
keyword.value = ''
refresh()
}
function toggleEnabled() {
onlyEnabled.value = !onlyEnabled.value
refresh()
}
function openPicker(key) {
filterKey.value = key
picker.value.show = true
}
function onCategory(opt) {
categoryId.value = String(opt.value) === String(categoryId.value) ? '' : opt.value
refresh()
}
function isOnSale(row) {
return Number(row.status) === 1 && Number(row.is_draft) !== 1
}
function openDetail(row) {
uni.navigateTo({ url: `/pages/erp/basic/product-detail?id=${row.id}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding-bottom: 40rpx;
}
.filter-bar {
position: sticky;
top: 0;
z-index: 10;
background: $color-bg-page;
padding: 20rpx $page-padding-x 8rpx;
}
.search-box {
display: flex;
align-items: center;
gap: 12rpx;
height: 72rpx;
padding: 0 24rpx;
background: $color-card;
border-radius: $radius-full;
box-shadow: $shadow-card;
.search-input {
flex: 1;
font-size: 26rpx;
color: $color-text;
}
.search-clear {
font-size: 24rpx;
color: $color-text-muted;
}
}
.chip-row {
display: flex;
align-items: center;
gap: 16rpx;
margin-top: 18rpx;
}
.chip {
display: inline-flex;
align-items: center;
gap: 6rpx;
padding: 10rpx 22rpx;
border-radius: $radius-full;
background: $color-card;
font-size: 24rpx;
color: $color-text-secondary;
box-shadow: $shadow-card;
&.active {
background: #2563eb;
color: #ffffff;
}
&.count {
margin-left: auto;
background: transparent;
box-shadow: none;
color: $color-text-muted;
}
}
.p-card {
@include card;
margin: 0 $page-padding-x 20rpx;
padding: 24rpx 28rpx;
&:active {
opacity: 0.85;
}
}
.p-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
}
.p-name {
flex: 1;
font-size: 29rpx;
font-weight: 500;
color: $color-text;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.p-sub {
display: block;
margin-top: 8rpx;
font-size: 23rpx;
color: $color-text-muted;
}
.p-grid {
display: flex;
margin-top: 18rpx;
padding-top: 16rpx;
border-top: 1rpx solid $color-divider;
}
.p-cell {
flex: 1;
.cell-label {
display: block;
font-size: 22rpx;
color: $color-text-muted;
}
.cell-value {
display: block;
margin-top: 6rpx;
font-size: 27rpx;
color: $color-text;
}
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
padding: 120rpx 40rpx;
}
.state-text,
.state-tip {
font-size: 26rpx;
color: $color-text-muted;
margin-top: 16rpx;
}
.load-done {
display: flex;
justify-content: center;
padding: 8rpx 0 24rpx;
font-size: 24rpx;
color: $color-text-muted;
}
</style>
+235
View File
@@ -0,0 +1,235 @@
<template>
<view class="page">
<view class="filter-bar">
<view class="search-box">
<FaIcon name="magnifying-glass" color="#94a3b8" :size="16" />
<input
v-model="keyword"
class="search-input"
placeholder="搜索仓库名称"
confirm-type="search"
@confirm="load"
/>
</view>
<view class="sum-row">
<text class="sum-item">仓库 {{ list.length }} 个</text>
<text class="sum-item">在库货值 ¥{{ moneyText(totalValue) }}</text>
</view>
</view>
<view v-if="loading && !list.length" class="state-box">
<text class="state-text">加载中...</text>
</view>
<view v-else-if="!list.length" class="state-box">
<u-empty mode="list" text="没有仓库" />
<text class="state-tip">先在 Web 后台「进销存 - 仓库档案」建仓库</text>
</view>
<template v-else>
<view v-for="row in list" :key="row.id" class="w-card" @tap="openStock(row)">
<view class="w-top">
<view class="w-icon">
<FaIcon name="warehouse" color="#2563eb" :size="18" />
</view>
<view class="w-main">
<view class="w-name-row">
<text class="w-name">{{ row.warehouse_name }}</text>
<u-tag v-if="Number(row.is_default) === 1" text="默认" type="primary" size="mini" />
<u-tag v-if="Number(row.status) !== 1" text="停用" type="info" size="mini" />
</view>
<text class="w-sub">{{ [row.warehouse_code, row.manager, row.phone].filter(Boolean).join(' · ') || '—' }}</text>
</view>
<FaIcon name="chevron-right" color="#cbd5e1" :size="15" />
</view>
<view class="w-grid">
<view class="w-cell">
<text class="cell-label">在库品种</text>
<text class="cell-value">{{ row.stock_kinds || 0 }}</text>
</view>
<view class="w-cell">
<text class="cell-label">货值</text>
<text class="cell-value">¥{{ moneyText(row.stock_value) }}</text>
</view>
<view class="w-cell">
<text class="cell-label">地址</text>
<text class="cell-value ellipsis">{{ row.address || '—' }}</text>
</view>
</view>
</view>
</template>
</view>
</template>
<script setup>
/**
* 仓库档案(移动端只读):一屏看清每个仓压了多少货,点进去直接查该仓库存。
*/
import { computed, ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import FaIcon from '@/components/FaIcon.vue'
import { fetchWarehouses, moneyText } from '@/api/erp.js'
const list = ref([])
const keyword = ref('')
const loading = ref(false)
const totalValue = computed(() => list.value.reduce((sum, w) => sum + Number(w.stock_value || 0), 0))
onShow(() => {
load()
})
async function load() {
loading.value = true
try {
list.value = await fetchWarehouses({ keyword: keyword.value.trim() })
} catch (e) {
uni.showToast({ title: '仓库加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function openStock(row) {
uni.navigateTo({ url: `/pages/erp/stock/index?warehouse_id=${row.id}&warehouse_name=${encodeURIComponent(row.warehouse_name || '')}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding-bottom: 40rpx;
}
.filter-bar {
position: sticky;
top: 0;
z-index: 10;
background: $color-bg-page;
padding: 20rpx $page-padding-x 12rpx;
}
.search-box {
display: flex;
align-items: center;
gap: 12rpx;
height: 72rpx;
padding: 0 24rpx;
background: $color-card;
border-radius: $radius-full;
box-shadow: $shadow-card;
.search-input {
flex: 1;
font-size: 26rpx;
color: $color-text;
}
}
.sum-row {
display: flex;
gap: 28rpx;
padding: 16rpx 8rpx 4rpx;
}
.sum-item {
font-size: 24rpx;
color: $color-text-muted;
}
.w-card {
@include card;
margin: 0 $page-padding-x 20rpx;
padding: 24rpx 28rpx;
&:active {
opacity: 0.85;
}
}
.w-top {
display: flex;
align-items: center;
gap: 18rpx;
}
.w-icon {
@include icon-box(64rpx);
}
.w-main {
flex: 1;
min-width: 0;
}
.w-name-row {
display: flex;
align-items: center;
gap: 12rpx;
}
.w-name {
font-size: 29rpx;
font-weight: 500;
color: $color-text;
}
.w-sub {
display: block;
margin-top: 6rpx;
font-size: 23rpx;
color: $color-text-muted;
}
.w-grid {
display: flex;
margin-top: 20rpx;
padding-top: 16rpx;
border-top: 1rpx solid $color-divider;
}
.w-cell {
flex: 1;
min-width: 0;
&:nth-child(3) {
flex: 1.4;
padding-left: 20rpx;
}
.cell-label {
display: block;
font-size: 22rpx;
color: $color-text-muted;
}
.cell-value {
display: block;
margin-top: 6rpx;
font-size: 26rpx;
color: $color-text;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
padding: 120rpx 40rpx;
}
.state-text,
.state-tip {
font-size: 26rpx;
color: $color-text-muted;
margin-top: 16rpx;
}
</style>