WMS_PDA/pages/work/product/itemMaint.vue
zm2000 8318b3a688 feat: 新增商品信息维护页及作业要求(打包/拣货/复核)字段
- 新增 pages/work/product/itemMaint 维护页并在 pages.json 注册
- 商品查询页新增「维护信息」入口,扫码带出商品后跳转
- edit/detail 页新增拣货、复核要求字段,支持要求合并/拆分切换
- 首页与快捷操作拦截「商品信息维护」,仅限商品查询页使用
2026-10-02 17:59:25 +08:00

793 lines
20 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="item-maint-page">
<view class="normar_container">
<page-nav title="商品信息维护">
<template #right>
<u-button
class="nav-save-btn"
size="mini"
type="primary"
text="保存"
:loading="saving"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', color: '#ffffff' }"
@click="handleSave"
>
<text class="nav-save-btn__text">保存</text>
</u-button>
</template>
</page-nav>
<scroll-view class="form-content" scroll-y>
<view v-if="!loaded && !loading" class="empty-state">
<u-icon name="scan" size="88" color="#c0c4cc"></u-icon>
<text class="empty-text">请扫描商品条码</text>
<text class="empty-hint">扫描后自动带出商品信息</text>
</view>
<view v-else class="form-card">
<!-- 商品名称 -->
<view class="form-section form-section--name">
<view class="goods-name-display">{{ formData.NAME || '--' }}</view>
</view>
<!-- 商品图片 -->
<view class="form-section">
<view class="section-title">商品图片</view>
<uploadImgCos
ref="imageUploadRef"
business_type="stock"
:value="formData.images"
:business_id="stockId"
:maxCount="6"
:multiple="true"
:disabled="!stockId"
@change="handleImagesChange"
></uploadImgCos>
<text class="section-tip">最多上传6张,支持多选、删除</text>
</view>
<!-- 商品重量 -->
<view class="form-section">
<view class="field-line">
<text class="field-label">商品重量(g)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.WEIGHT" type="digit" placeholder="请输入重量" />
</view>
</view>
</view>
<!-- 商品有效天数 -->
<view class="form-section">
<view class="field-line">
<text class="field-label">商品有效天数(天)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.YXQ" type="number" placeholder="请输入有效天数" />
</view>
</view>
<view class="quick-buttons">
<view
class="quick-btn"
v-for="option in yxqOptions"
:key="option.days"
@click="setYxq(option.days)"
>
<text class="quick-btn__text">{{ option.label }}</text>
</view>
</view>
</view>
<!-- 箱规 -->
<view class="form-section">
<view class="section-title">箱规</view>
<view class="field-line">
<text class="field-label">每箱数量</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.quantity_per_box" type="number" placeholder="请输入每箱数量" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱毛重(g)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_gross_weight" type="digit" placeholder="请输入箱毛重" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱净重(g)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_net_weight" type="digit" placeholder="请输入箱净重" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱长(cm)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_length" type="digit" placeholder="请输入箱长" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱宽(cm)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_width" type="digit" placeholder="请输入箱宽" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱高(cm)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_height" type="digit" placeholder="请输入箱高" />
</view>
</view>
<view class="field-line">
<text class="field-label">箱体积(m³)</text>
<view class="field-input-box">
<input class="field-input" v-model="formData.box_volume" type="digit" placeholder="请输入箱体积" />
</view>
</view>
</view>
<view class="safe-padding-bottom"></view>
</view>
</scroll-view>
</view>
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
</view>
</template>
<script>
export default {
data() {
return {
barcode: '',
rawItem: null,
loading: false,
saving: false,
loaded: false,
stockId: 0,
querySeq: 0,
imgs: [],
formData: {
NAME: '',
WEIGHT: '',
YXQ: '',
images: [],
quantity_per_box: '',
box_gross_weight: '',
box_net_weight: '',
box_length: '',
box_width: '',
box_height: '',
box_volume: ''
},
yxqOptions: [
{ label: '3个月', days: 90 },
{ label: '6个月', days: 180 },
{ label: '12个月', days: 365 },
{ label: '18个月', days: 540 },
{ label: '2年', days: 730 },
{ label: '2年半', days: 912 },
{ label: '3年', days: 1095 }
]
};
},
onLoad(options) {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
// 从商品查询页跳转时带 barcode,自动带出商品信息
const routeBarcode = this.normalizeKeyword(
(options && (options.barcode || options.code || options.keyword)) || ''
);
if (routeBarcode) {
this.barcode = routeBarcode;
this.queryByBarcode();
}
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[ItemMaint] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[ItemMaint] broadcast/${action} 调用异常:`, error);
}
},
normalizeKeyword(value) {
return String(value || '').replace(/\s+/g, '');
},
normalizePositiveId(value) {
if (value === null || value === undefined || value === '') {
return null;
}
const numeric = Number(value);
if (Number.isFinite(numeric) && numeric > 0) {
return numeric;
}
return null;
},
resolveStoreId(item) {
if (!item || typeof item !== 'object') {
return null;
}
const candidates = [
item.store_id,
item.owner_id,
item.store && item.store.id,
item.store_stock && item.store_stock.store_id
];
for (let i = 0; i < candidates.length; i++) {
const normalized = this.normalizePositiveId(candidates[i]);
if (normalized) {
return normalized;
}
}
return null;
},
resolveWarehouseStockId(item) {
if (!item || typeof item !== 'object') {
return null;
}
const candidates = [
item.stock_id,
item.warehouse_stock_id,
item.storage_id,
item.id
];
for (let i = 0; i < candidates.length; i++) {
const normalized = this.normalizePositiveId(candidates[i]);
if (normalized) {
return normalized;
}
}
return null;
},
normalizeScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return this.normalizeKeyword(scanResult);
}
if (typeof scanResult.result === 'string') {
return this.normalizeKeyword(scanResult.result);
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return this.normalizeKeyword(firstResult);
}
if (firstResult && typeof firstResult.data === 'string') {
return this.normalizeKeyword(firstResult.data);
}
}
if (typeof scanResult.data === 'string') {
return this.normalizeKeyword(scanResult.data);
}
return '';
},
handleBroadcastResult(result) {
const code = this.normalizeScanResult(result);
if (!code) {
return;
}
this.barcode = code;
this.queryByBarcode();
},
toInputValue(value) {
return value === null || value === undefined || value === '' ? '' : String(value);
},
extractListFromResponse(response) {
if (!response || typeof response !== 'object') {
return [];
}
if (Array.isArray(response.list)) {
return response.list;
}
if (Array.isArray(response.rows)) {
return response.rows;
}
const responseData = response.data;
if (Array.isArray(responseData)) {
return responseData;
}
if (responseData && Array.isArray(responseData.list)) {
return responseData.list;
}
if (responseData && Array.isArray(responseData.rows)) {
return responseData.rows;
}
if (responseData && Array.isArray(responseData.data)) {
return responseData.data;
}
return [];
},
getItemName(item) {
return String((item && (item.item_name || item.product_name || item.name)) || '').trim();
},
extractBarcodes(item) {
if (!item || typeof item !== 'object') {
return [];
}
let values = [];
if (Array.isArray(item.barcodes)) {
values = values.concat(item.barcodes);
} else if (typeof item.barcodes === 'string' && item.barcodes.trim()) {
values = values.concat(item.barcodes.split(/[;,,\s]+/));
}
values = values.concat([item.barcode, item.code, item.item_barcode, item.bar_code]);
return [...new Set(values
.map(code => this.normalizeKeyword(code))
.filter(Boolean)
)];
},
normalizeImageList(item) {
const urls = [];
const pushImage = (img) => {
if (!img) {
return;
}
if (typeof img === 'string') {
urls.push(img);
} else if (typeof img === 'object') {
const url = img.url || img.path || img.successUrl || img.fileUrl || img.image_url || '';
if (url) {
urls.push(url);
}
}
};
if (item && Array.isArray(item.images) && item.images.length) {
item.images.forEach(pushImage);
}
if (!urls.length && item && (item.image || item.image_url)) {
urls.push(item.image || item.image_url);
}
return [...new Set(urls.filter(Boolean))].map(url => ({ url }));
},
async queryByBarcode() {
const code = this.normalizeKeyword(this.barcode);
if (!code) {
uni.showToast({
title: '请输入商品条码',
icon: 'none'
});
return;
}
const querySeq = ++this.querySeq;
this.loading = true;
try {
const [searchRes, listRes] = await Promise.all([
this.$http('stock.warehouse.search', {
keyword: code,
with_stock: true
}),
this.$http('stock.warehouse.list', {
with_stock: true,
where: {
barcode: {
operator: 'eq',
value: code,
type: 'string'
}
},
pagination: {
page: 1,
pageSize: 1
}
})
]);
if (querySeq !== this.querySeq) {
return;
}
const searchOk = searchRes && Number(searchRes.code) === 200;
const listOk = listRes && Number(listRes.code) === 200;
const searchList = searchOk ? this.extractListFromResponse(searchRes) : [];
const listList = listOk ? this.extractListFromResponse(listRes) : [];
const exactMatch = list =>
(list || []).find(item => this.extractBarcodes(item).includes(code));
const item = exactMatch(listList) || (listList && listList[0]) || exactMatch(searchList) || (searchList && searchList[0]);
if (!item) {
this.loaded = false;
uni.showToast({
title: '未查询到该商品',
icon: 'none'
});
return;
}
this.applyProduct(item);
} catch (error) {
if (querySeq !== this.querySeq) {
return;
}
console.error('[ItemMaint] 查询异常:', error);
uni.showToast({
title: (error && error.message) || '查询失败',
icon: 'none'
});
} finally {
if (querySeq === this.querySeq) {
this.loading = false;
}
}
},
applyProduct(item) {
this.rawItem = item && typeof item === 'object' ? item : {};
this.stockId = this.resolveWarehouseStockId(item) || 0;
this.formData.NAME = this.getItemName(item);
this.formData.WEIGHT = this.toInputValue(item.gross_weight !== undefined ? item.gross_weight : item.weight);
this.formData.YXQ = this.toInputValue(
item.shelf_life_days !== undefined
? item.shelf_life_days
: (item.validity_days !== undefined ? item.validity_days : item.yxq)
);
this.formData.quantity_per_box = this.toInputValue(item.quantity_per_box);
this.formData.box_gross_weight = this.toInputValue(item.box_gross_weight);
this.formData.box_net_weight = this.toInputValue(item.box_net_weight);
this.formData.box_length = this.toInputValue(item.box_length);
this.formData.box_width = this.toInputValue(item.box_width);
this.formData.box_height = this.toInputValue(item.box_height);
this.formData.box_volume = this.toInputValue(item.box_volume);
this.formData.images = this.normalizeImageList(item);
this.imgs = [];
this.loaded = true;
},
setYxq(days) {
this.formData.YXQ = String(days);
},
handleImagesChange(fileList) {
this.formData.images = Array.isArray(fileList) ? fileList : [];
this.imgs = this.formData.images
.map(file => (file && (file.successUrl || file.url || file.path)) || '')
.filter(Boolean);
},
async handleSave() {
if (this.saving) {
return;
}
if (!this.stockId) {
uni.showToast({
title: '请先扫描商品',
icon: 'none'
});
return;
}
const raw = this.rawItem || {};
const itemCode = String(raw.item_code || raw.goods_code || '').trim();
if (!itemCode) {
uni.showToast({
title: '缺少商品编码,无法保存',
icon: 'none'
});
return;
}
const storeId = this.resolveStoreId(raw);
if (!storeId) {
uni.showToast({
title: '未获取到货主ID',
icon: 'none'
});
return;
}
const itemName = String(this.formData.NAME || '').trim();
if (!itemName) {
uni.showToast({
title: '商品名称为空',
icon: 'none'
});
return;
}
const toNumber = (value) => {
const numeric = Number(value);
return Number.isFinite(numeric) ? numeric : 0;
};
const yxq = toNumber(this.formData.YXQ);
const quantityPerBox = toNumber(this.formData.quantity_per_box);
const payload = {
id: this.stockId,
item_code: itemCode,
store_id: Number(storeId),
store_name: String(raw.store_name || '').trim(),
barcode: String(raw.barcode || raw.bar_code || '').trim(),
item_name: itemName,
sku_property: String(raw.sku_property || '').trim(),
stock_unit: String(raw.stock_unit || '').trim(),
packing_requirements: String(raw.packing_requirements || '').trim(),
pick_requirements: String(raw.pick_requirements || '').trim(),
recheck_requirements: String(raw.recheck_requirements || '').trim(),
length: toNumber(raw.length),
width: toNumber(raw.width),
height: toNumber(raw.height),
volume: toNumber(raw.volume),
gross_weight: toNumber(this.formData.WEIGHT),
net_weight: toNumber(raw.net_weight),
tag_price: toNumber(raw.tag_price),
retail_price: toNumber(raw.retail_price),
is_sn_mgmt: raw.is_sn_mgmt !== undefined ? raw.is_sn_mgmt : 'N',
is_shelf_life_mgmt: yxq > 0 ? 'Y' : 'N',
shelf_life_days: yxq,
is_batch_mgmt: raw.is_batch_mgmt !== undefined ? raw.is_batch_mgmt : 'N',
inbound_min_days: toNumber(raw.inbound_min_days),
outbound_min_days: toNumber(raw.outbound_min_days),
remaining_threshold_days: toNumber(raw.remaining_threshold_days),
brand_name: String(raw.brand_name || '').trim(),
managementFlags: [],
enable_box_spec: quantityPerBox > 0,
quantity_per_box: quantityPerBox,
box_gross_weight: toNumber(this.formData.box_gross_weight),
box_net_weight: toNumber(this.formData.box_net_weight),
box_length: toNumber(this.formData.box_length),
box_width: toNumber(this.formData.box_width),
box_height: toNumber(this.formData.box_height),
box_volume: toNumber(this.formData.box_volume),
box_unit: String(raw.box_unit || ''),
goods_code: String(raw.goods_code || itemCode).trim()
};
this.saving = true;
try {
const res = await this.$http('stock.warehouse.saveWarehouseStock', payload);
if (!res || Number(res.code) !== 200) {
throw new Error((res && res.message) || '保存失败');
}
uni.showToast({
title: '保存成功',
icon: 'success'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 600);
} catch (error) {
console.error('[ItemMaint] 保存异常:', error);
uni.showToast({
title: (error && error.message) || '保存失败',
icon: 'none'
});
} finally {
this.saving = false;
}
}
}
};
</script>
<style lang="scss" scoped>
.item-maint-page {
width: 100%;
min-height: 100vh;
background: #f5f6f7;
}
.normar_container {
display: flex;
flex-direction: column;
height: 100vh;
}
::v-deep .nav-save-btn {
min-width: 144rpx !important;
padding: 0 32rpx !important;
height: 72rpx !important;
line-height: 72rpx !important;
margin-right: 18rpx !important;
border-radius: 12rpx !important;
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.22);
}
::v-deep .nav-save-btn .u-button {
background-color: #2979ff !important;
border-color: #2979ff !important;
color: #ffffff !important;
border-radius: 12rpx !important;
}
.nav-save-btn__text {
font-size: 32rpx;
font-weight: 600;
color: #ffffff;
}
::v-deep .nav-save-btn .u-button__text {
font-size: 32rpx !important;
font-weight: 600 !important;
}
.form-content {
flex: 1;
overflow: hidden;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 160rpx;
}
.empty-text {
margin-top: 24rpx;
color: #909399;
font-size: 36rpx;
}
.empty-hint {
margin-top: 12rpx;
color: #c0c4cc;
font-size: 30rpx;
}
.form-card {
margin: 20rpx 24rpx;
background: #ffffff;
border-radius: 16rpx;
overflow: hidden;
}
.form-section {
padding: 28rpx 24rpx;
border-bottom: 2rpx solid #f0f1f3;
}
.section-title {
color: #303133;
font-size: 36rpx;
font-weight: 600;
margin-bottom: 20rpx;
}
.section-value {
color: #606266;
font-size: 28rpx;
}
.goods-name-display {
color: #303133;
font-size: 44rpx;
font-weight: 600;
line-height: 1.4;
word-break: break-all;
}
.section-tip {
display: block;
margin-top: 12rpx;
color: #c0c4cc;
font-size: 28rpx;
}
.field-row {
display: flex;
flex-direction: row;
align-items: center;
height: 80rpx;
padding: 0 20rpx;
border: 2rpx solid #e4e7ed;
border-radius: 12rpx;
}
.field-line {
display: flex;
flex-direction: row;
align-items: center;
}
.field-line + .field-line {
margin-top: 24rpx;
}
.field-input-box {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
height: 88rpx;
padding: 0 20rpx;
border: 2rpx solid #e4e7ed;
border-radius: 12rpx;
}
.field-label {
width: 330rpx;
flex-shrink: 0;
margin-right: 16rpx;
color: #303133;
font-size: 36rpx;
font-weight: 600;
}
.field-input {
flex: 1;
height: 88rpx;
font-size: 36rpx;
color: #303133;
}
.quick-buttons {
display: flex;
flex-wrap: wrap;
margin-top: 16rpx;
// 老机型 WebView 不支持 flex gap,改用按钮外边距实现实际间隔
margin-bottom: -30rpx;
}
.quick-btn {
padding: 14rpx 32rpx;
border: 1rpx solid #d9e4f5;
border-radius: 10rpx;
background: #f5f8ff;
font-size: 34rpx;
color: #2979ff;
margin-right: 30rpx;
margin-bottom: 30rpx;
}
.quick-btn:active {
opacity: 0.7;
}
.quick-btn__text {
color: #2979ff;
font-size: 34rpx;
}
.safe-padding-bottom {
height: 40rpx;
}
</style>