功能:新增下一阶段运营能力和生产部署

This commit is contained in:
xiaowang
2026-05-24 18:09:11 +08:00
parent 8116abc9b5
commit 1d077d4089
157 changed files with 9206 additions and 74 deletions
@@ -0,0 +1,204 @@
const inventoryApi = require('../../api/inventory')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
Page({
data: {
loading: false,
list: [],
total: 0,
canManage: false,
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
},
onShow() {
if (!navigation.ensureLogin('进入库存管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canManage: permission.hasPermission(permissionCodes, 'inventory:manage')
})
this.loadItems()
},
onPullDownRefresh() {
this.loadItems().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadItems() {
this.setData({ loading: true })
try {
const response = await inventoryApi.listItems({
page: 1,
size: 30
})
this.setData({
list: safeList(response).map(item => this.formatItem(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '库存加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatItem(item) {
return {
...item,
displayStock: format.formatPrice(item.stockQuantity),
displayWarning: format.formatPrice(item.warningThreshold),
statusText: Number(item.status) === 0 ? '停用' : '启用'
}
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
async handleSaveItem() {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存维护权限',
icon: 'none'
})
return
}
const form = this.data.form
if (!String(form.itemName || '').trim()) {
wx.showToast({
title: '请填写物料名称',
icon: 'none'
})
return
}
try {
await inventoryApi.saveItem({
itemName: String(form.itemName || '').trim(),
category: String(form.category || '').trim(),
unit: String(form.unit || '').trim() || '件',
stockQuantity: Number(form.stockQuantity) || 0,
warningThreshold: Number(form.warningThreshold) || 0,
status: 1
})
markDirty('admin-workbench')
wx.showToast({
title: '物料已保存',
icon: 'none'
})
this.setData({
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '物料保存失败',
icon: 'none'
})
}
},
promptAdjust(item) {
return new Promise(resolve => {
wx.showModal({
title: `调整 ${item.itemName}`,
content: '填写正数入库,负数出库。',
editable: true,
placeholderText: '例如 5 或 -2',
confirmText: '调整',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
},
async handleAdjust(event) {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存调整权限',
icon: 'none'
})
return
}
const item = event.currentTarget.dataset.item
if (!item) {
return
}
const value = await this.promptAdjust(item)
if (value === null) {
return
}
const quantity = Number(value)
if (!isFinite(quantity) || quantity === 0) {
wx.showToast({
title: '请输入非 0 数量',
icon: 'none'
})
return
}
try {
await inventoryApi.adjustStock(item.id, {
changeType: quantity > 0 ? 'IN' : 'OUT',
changeQuantity: quantity,
remark: '管理端小程序调整'
})
markDirty('admin-workbench')
wx.showToast({
title: '库存已调整',
icon: 'none'
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '库存调整失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,58 @@
<navigation-bar title="库存管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Inventory</text>
<text class="hero-title">耗材库存</text>
<text class="hero-desc">查看库存和预警项,支持手机端快速新增物料与正负数调整库存。</text>
</view>
<view wx:if="{{canManage}}" class="surface-card">
<text class="section-title">新增物料</text>
<view class="form-grid">
<input class="field-input" placeholder="物料名称" placeholder-class="placeholder" value="{{form.itemName}}" data-field="itemName" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="分类" placeholder-class="placeholder" value="{{form.category}}" data-field="category" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="单位" placeholder-class="placeholder" value="{{form.unit}}" data-field="unit" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="初始库存" placeholder-class="placeholder" value="{{form.stockQuantity}}" data-field="stockQuantity" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="预警阈值" placeholder-class="placeholder" value="{{form.warningThreshold}}" data-field="warningThreshold" bindinput="handleFormInput"></input>
</view>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveItem">保存物料</button>
</view>
<view class="surface-card">
<text class="section-title">库存列表</text>
<text class="section-desc">共 {{total}} 个物料,低于阈值会标记为预警。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.itemName}}</text>
<text class="list-subtitle">{{item.category || '未分类'}} · {{item.statusText}}</text>
</view>
<text class="{{item.warning ? 'danger-badge' : 'success-badge'}}">{{item.warning ? '库存预警' : '正常'}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">当前库存</text>
<text class="meta-value">{{item.displayStock}} {{item.unit || ''}}</text>
</view>
<view class="meta-item">
<text class="meta-label">预警阈值</text>
<text class="meta-value">{{item.displayWarning}} {{item.unit || ''}}</text>
</view>
</view>
<view wx:if="{{canManage}}" class="list-actions">
<view class="mini-btn primary" data-item="{{item}}" bindtap="handleAdjust">调整库存</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无库存物料</text>
<text class="empty-desc">当前店铺还没有录入耗材库存。</text>
</view>
</view>
</view>
@@ -0,0 +1,14 @@
.page-shell {
background: transparent;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 18rpx;
}
.compact-btn {
margin-top: 18rpx;
}