将每一步的钢卷二维码进行保存,新步骤采用新码

This commit is contained in:
2025-10-30 17:07:02 +08:00
parent 7ea75aef84
commit 20481d28a6
3 changed files with 509 additions and 166 deletions

View File

@@ -33,17 +33,9 @@
</view>
</view>
<!-- 历史码提示 -->
<view class="warning-card" v-if="form.coilId && qrcodeStatus === 0">
<view class="warning-icon"></view>
<view class="warning-content">
<text class="warning-title">历史二维码</text>
<text class="warning-desc">此二维码已失效不允许进行分卷操作</text>
</view>
</view>
<!-- 分卷列表 -->
<view class="form-card" v-if="form.coilId && qrcodeStatus === 1" @click="closeWarehouseList">
<view class="form-card" v-if="form.coilId" @click="closeWarehouseList">
<view class="card-title">
<text class="title-dot"></text>
<text class="title-text">分卷配置</text>
@@ -110,6 +102,21 @@
<text class="picker-arrow"></text>
</view>
</view>
<!-- 产品选择仅当该分卷选择了成品库区时显示 -->
<view class="split-field" v-if="item.itemType === 'product'">
<text class="field-label-optional">选择产品</text>
<view
class="picker-input"
@click="showProductPickerForItem(index)"
>
<text class="picker-text" :class="{ 'picker-placeholder': !item.productName }">
{{ item.productName || '请选择产品' }}
</text>
<text class="picker-arrow"></text>
</view>
</view>
<view class="split-field">
<text class="field-label-optional">毛重 (kg)</text>
<input
@@ -178,6 +185,38 @@
</scroll-view>
</view>
</uni-popup>
<!-- 产品选择弹窗 -->
<uni-popup ref="productPopup" type="bottom">
<view class="warehouse-popup">
<view class="popup-header">
<text class="popup-title">选择产品</text>
<text class="popup-close" @click="closeProductPickerForItem"></text>
</view>
<view class="popup-search">
<input
v-model="productSearchKeyword"
@input="filterProductsInPicker"
placeholder="搜索产品名称"
class="search-input"
/>
</view>
<scroll-view class="popup-body" scroll-y>
<view
class="warehouse-item"
v-for="product in filteredProductsInPicker"
:key="product.productId"
@click="selectProductFromPicker(product)"
>
<text class="warehouse-name">{{ product.productName }}</text>
<text class="warehouse-check" v-if="currentPickerItemIndex !== -1 && splitCoils[currentPickerItemIndex].itemId === product.productId"></text>
</view>
<view class="empty-tip" v-if="!filteredProductsInPicker || filteredProductsInPicker.length === 0">
<text>未找到匹配的产品</text>
</view>
</scroll-view>
</view>
</uni-popup>
</view>
</template>
@@ -185,6 +224,7 @@
import { getGenerateRecord } from '@/api/wms/code.js'
import { updateMaterialCoil, getMaterialCoil, getMaterialCoilTrace } from '@/api/wms/coil.js'
import { listWarehouse } from '@/api/wms/warehouse.js'
import { listProduct } from '@/api/wms/product.js'
export default {
data() {
@@ -223,9 +263,11 @@ export default {
warehouses: [],
warehouseSearchKeyword: '',
filteredWarehousesInPicker: [],
products: [], // 产品列表
productSearchKeyword: '',
filteredProductsInPicker: [],
currentPickerItemIndex: -1,
loading: false,
qrcodeStatus: 1 // 二维码状态0=历史码1=当前有效码
loading: false
}
},
@@ -266,6 +308,111 @@ export default {
}
},
// 加载产品列表
async loadProducts() {
console.log('开始加载产品列表...');
try {
const res = await listProduct({ pageNum: 1, pageSize: 1000 });
console.log("产品返回值", res);
if (res.code === 200) {
this.products = res.rows || res.data || [];
this.filteredProductsInPicker = this.products;
console.log('产品加载成功,数量:', this.products.length);
} else {
console.error('产品加载失败:', res.msg);
}
} catch (err) {
console.error('加载产品异常:', err);
}
},
// 过滤库区(在选择器中)
filterWarehousesInPicker() {
const keyword = this.warehouseSearchKeyword.trim().toLowerCase();
if (!keyword) {
this.filteredWarehousesInPicker = [...this.warehouses];
} else {
this.filteredWarehousesInPicker = this.warehouses.filter(warehouse => {
const name = (warehouse.warehouseName || '').toLowerCase();
return name.includes(keyword);
});
}
},
// 从选择器中选择库区
async selectWarehouseFromPicker(warehouse) {
if (this.currentPickerItemIndex === -1) return;
const item = this.splitCoils[this.currentPickerItemIndex];
item.warehouseId = warehouse.warehouseId;
item.warehouseName = warehouse.warehouseName;
this.closeWarehousePickerForItem();
// 检查是否选择了成品库区
if (warehouse.warehouseName && warehouse.warehouseName.includes('成品')) {
// 加载产品列表
await this.loadProducts();
// 弹出产品选择框
this.showProductPickerForItem(this.currentPickerItemIndex);
}
},
// 显示库区选择器(为特定分卷)
showWarehousePickerForItem(index) {
this.currentPickerItemIndex = index;
this.warehouseSearchKeyword = '';
this.filteredWarehousesInPicker = [...this.warehouses];
this.$refs.warehousePopup.open();
},
// 关闭库区选择器
closeWarehousePickerForItem() {
this.$refs.warehousePopup.close();
this.currentPickerItemIndex = -1;
},
// 显示产品选择器(为特定分卷)
showProductPickerForItem(index) {
this.currentPickerItemIndex = index;
this.productSearchKeyword = '';
this.filteredProductsInPicker = [...this.products];
this.$refs.productPopup.open();
},
// 关闭产品选择器
closeProductPickerForItem() {
this.$refs.productPopup.close();
this.currentPickerItemIndex = -1;
},
// 过滤产品(在选择器中)
filterProductsInPicker() {
const keyword = this.productSearchKeyword.trim().toLowerCase();
if (!keyword) {
this.filteredProductsInPicker = [...this.products];
} else {
this.filteredProductsInPicker = this.products.filter(product => {
const name = (product.productName || '').toLowerCase();
return name.includes(keyword);
});
}
},
// 从选择器中选择产品
selectProductFromPicker(product) {
if (this.currentPickerItemIndex === -1) return;
const item = this.splitCoils[this.currentPickerItemIndex];
item.itemId = product.productId;
item.itemType = 'product';
item.productName = product.productName; // 保存产品名称用于显示
uni.showToast({
title: `分卷 ${this.currentPickerItemIndex + 1} 已选择产品:${product.productName}`,
icon: 'success'
});
this.closeProductPickerForItem();
},
// 过滤库区(为特定分卷)
filterWarehousesForItem(index) {
console.log(`分卷页面过滤库区,分卷${index + 1},关键词:`, this.splitCoils[index].warehouseKeyword);
@@ -352,56 +499,56 @@ export default {
throw new Error('未找到二维码记录');
}
// 2. 解析content获取enter_coil_nocurrent_coil_no
// 2. 解析content获取enter_coil_nocurrent_coil_no和coil_id
const qrcodeRecord = qrcodeRes.data;
const content = JSON.parse(qrcodeRecord.content);
const enterCoilNo = content.enter_coil_no;
const currentCoilNo = content.current_coil_no;
// 保存二维码状态
this.qrcodeStatus = qrcodeRecord.status || 1;
// 如果是历史码,直接拒绝
if (this.qrcodeStatus === 0) {
uni.showModal({
title: '历史二维码',
content: '此二维码已失效,不允许进行分卷操作,请使用最新二维码',
showCancel: false
});
return;
}
const coilId = content.coil_id && content.coil_id !== 'null' ? content.coil_id : null;
if (!enterCoilNo) {
throw new Error('二维码中未包含有效的入场钢卷号');
}
// 3. 通过追溯接口获取准确的钢卷信息
// 3. 通过追溯接口获取钢卷信息
const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo);
if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records.length === 0) {
throw new Error('未找到钢卷信息');
}
// 4. 找到当前数据
// 4. 根据二维码内容匹配对应的钢卷数据
let coilData = null;
for (const record of traceRes.data.records) {
if (record.dataType === 1 && record.currentCoilNo === currentCoilNo) {
coilData = record;
break;
}
const records = traceRes.data.records;
// 优先使用coil_id精确匹配
if (coilId) {
coilData = records.find(record => String(record.coilId) === String(coilId));
}
// 如果没找到使用currentCoilNo匹配
if (!coilData && currentCoilNo) {
coilData = records.find(record => record.currentCoilNo === currentCoilNo);
}
// 如果还是没找到,取第一条记录
if (!coilData && records.length > 0) {
coilData = records[0];
}
if (!coilData) {
for (const record of traceRes.data.records) {
if (record.dataType === 1) {
coilData = record;
break;
}
}
throw new Error('未找到对应的钢卷数据');
}
if (!coilData) {
coilData = traceRes.data.records[0];
// 5. 检查是否为历史数据
if (coilData.dataType === 0) {
uni.showModal({
title: '历史数据',
content: '此为历史记录,不允许进行分卷操作',
showCancel: false
});
return;
}
this.coilDetail = coilData;
this.form.coilId = coilData.coilId;
@@ -501,11 +648,11 @@ export default {
// 提交分卷
handleConfirm() {
// 历史二维码不允许分卷
if (this.qrcodeStatus === 0) {
// 历史数据不允许分卷
if (this.coilDetail.dataType === 0) {
uni.showModal({
title: '历史二维码',
content: '此二维码已失效,不允许进行分卷操作,请使用最新二维码',
title: '历史数据',
content: '此为历史记录,不允许进行分卷操作',
showCancel: false
});
return;
@@ -542,8 +689,8 @@ export default {
currentCoilNo: item.currentCoilNo,
team: item.team,
hasMergeSplit: 1,
itemType: this.coilDetail.itemType,
itemId: this.coilDetail.itemId,
itemType: item.itemType || this.coilDetail.itemType, // 优先使用分卷的itemType
itemId: item.itemId || this.coilDetail.itemId, // 优先使用分卷的itemId
warehouseId: item.warehouseId || this.coilDetail.warehouseId, // 使用分卷的库区或原库区
grossWeight: item.grossWeight ? Number(item.grossWeight) : null,
netWeight: item.netWeight ? Number(item.netWeight) : null

View File

@@ -11,15 +11,6 @@
</view>
</view>
<!-- 历史码提示 -->
<view class="warning-card" v-if="hasHistoryQrcode">
<view class="warning-icon"></view>
<view class="warning-content">
<text class="warning-title">包含历史二维码</text>
<text class="warning-desc">列表中包含已失效的二维码不允许进行合卷操作请移除后重试</text>
</view>
</view>
<!-- 已扫描的钢卷列表 -->
<view class="coil-list" v-if="scannedCoils.length > 0">
<view class="card-title">
@@ -29,12 +20,11 @@
<view class="coil-item" v-for="(coil, index) in scannedCoils" :key="index">
<view class="coil-content">
<view class="coil-index" :class="{ 'index-history': coil.qrcodeStatus === 0 }">{{ index + 1 }}</view>
<view class="coil-index">{{ index + 1 }}</view>
<view class="coil-info">
<view class="coil-row">
<text class="coil-label">入场钢卷号</text>
<text class="coil-value">{{ coil.enterCoilNo }}</text>
<text class="history-tag" v-if="coil.qrcodeStatus === 0">历史码</text>
</view>
<view class="coil-row">
<text class="coil-label">当前钢卷号</text>
@@ -93,6 +83,20 @@
</view>
</view>
<!-- 产品选择仅当选择了成品库区时显示 -->
<view class="form-item form-item-optional" v-if="itemType === 'product'">
<text class="form-label-optional">选择产品</text>
<view
class="picker-input"
@click="showProductPicker()"
>
<text class="picker-text" :class="{ 'picker-placeholder': !selectedProductName }">
{{ selectedProductName || '请选择产品' }}
</text>
<text class="picker-arrow"></text>
</view>
</view>
<!-- 毛重 -->
<view class="form-item form-item-optional">
<text class="form-label-optional">毛重 (kg)</text>
@@ -166,6 +170,38 @@
</scroll-view>
</view>
</uni-popup>
<!-- 产品选择弹窗 -->
<uni-popup ref="productPopup" type="bottom">
<view class="warehouse-popup">
<view class="popup-header">
<text class="popup-title">选择产品</text>
<text class="popup-close" @click="closeProductPicker"></text>
</view>
<view class="popup-search">
<input
v-model="productSearchKeyword"
@input="filterProductsInPicker"
placeholder="搜索产品名称"
class="search-input"
/>
</view>
<scroll-view class="popup-body" scroll-y>
<view
class="warehouse-item"
v-for="product in filteredProductsInPicker"
:key="product.productId"
@click="selectProductFromPicker(product)"
>
<text class="warehouse-name">{{ product.productName }}</text>
<text class="warehouse-check" v-if="itemId === product.productId"></text>
</view>
<view class="empty-tip" v-if="!filteredProductsInPicker || filteredProductsInPicker.length === 0">
<text>未找到匹配的产品</text>
</view>
</scroll-view>
</view>
</uni-popup>
</view>
</template>
@@ -173,6 +209,7 @@
import { getGenerateRecord } from '@/api/wms/code.js'
import { updateMaterialCoil, getMaterialCoil, getMaterialCoilTrace } from '@/api/wms/coil.js'
import { listWarehouse } from '@/api/wms/warehouse.js'
import { listProduct } from '@/api/wms/product.js'
export default {
data() {
@@ -188,18 +225,18 @@ export default {
showWarehouseList: false,
warehouseSearchKeyword: '',
filteredWarehousesInPicker: [],
products: [], // 产品列表
productSearchKeyword: '',
filteredProductsInPicker: [],
itemType: '', // 合卷后的物品类型
itemId: undefined, // 合卷后的物品ID
selectedProductName: '', // 已选择的产品名称
grossWeight: '',
netWeight: '',
loading: false
}
},
computed: {
// 是否包含历史二维码
hasHistoryQrcode() {
return this.scannedCoils.some(coil => coil.qrcodeStatus === 0);
}
},
onLoad() {
this.loadWarehouses();
@@ -234,6 +271,61 @@ export default {
}
},
// 加载产品列表
async loadProducts() {
console.log('开始加载产品列表...');
try {
const res = await listProduct({ pageNum: 1, pageSize: 1000 });
console.log("产品返回值", res);
if (res.code === 200) {
this.products = res.rows || res.data || [];
this.filteredProductsInPicker = this.products;
console.log('产品加载成功,数量:', this.products.length);
} else {
console.error('产品加载失败:', res.msg);
}
} catch (err) {
console.error('加载产品异常:', err);
}
},
// 显示产品选择器
showProductPicker() {
this.productSearchKeyword = '';
this.filteredProductsInPicker = [...this.products];
this.$refs.productPopup.open();
},
// 关闭产品选择器
closeProductPicker() {
this.$refs.productPopup.close();
},
// 过滤产品(在选择器中)
filterProductsInPicker() {
const keyword = this.productSearchKeyword.trim().toLowerCase();
if (!keyword) {
this.filteredProductsInPicker = [...this.products];
} else {
this.filteredProductsInPicker = this.products.filter(product => {
const name = (product.productName || '').toLowerCase();
return name.includes(keyword);
});
}
},
// 从选择器中选择产品
selectProductFromPicker(product) {
this.itemId = product.productId;
this.itemType = 'product';
this.selectedProductName = product.productName;
uni.showToast({
title: `已选择产品:${product.productName}`,
icon: 'success'
});
this.closeProductPicker();
},
// 过滤库区
filterWarehouses() {
console.log('合卷页面过滤库区,关键词:', this.warehouseKeyword);
@@ -290,11 +382,21 @@ export default {
},
// 从选择器中选择库区
selectWarehouseFromPicker(warehouse) {
async selectWarehouseFromPicker(warehouse) {
this.warehouseId = warehouse.warehouseId;
this.warehouseName = warehouse.warehouseName;
this.warehouseKeyword = warehouse.warehouseName;
this.closeWarehousePicker();
// 检查是否选择了成品库区
if (warehouse.warehouseName && warehouse.warehouseName.includes('成品')) {
// 切换为产品类型
this.itemType = 'product';
// 加载产品列表
await this.loadProducts();
// 弹出产品选择框
this.showProductPicker();
}
},
// 扫码
@@ -311,56 +413,57 @@ export default {
throw new Error('未找到二维码记录');
}
// 2. 解析content获取enter_coil_nocurrent_coil_no
// 2. 解析content获取enter_coil_nocurrent_coil_no和coil_id
const qrcodeRecord = qrcodeRes.data;
const content = JSON.parse(qrcodeRecord.content);
const enterCoilNo = content.enter_coil_no;
const currentCoilNo = content.current_coil_no;
const qrcodeStatus = qrcodeRecord.status || 1;
// 如果是历史码,提示用户
if (qrcodeStatus === 0) {
uni.showModal({
title: '历史二维码',
content: '此二维码已失效,不允许进行合卷操作,请使用最新二维码',
showCancel: false
});
return;
}
const coilId = content.coil_id && content.coil_id !== 'null' ? content.coil_id : null;
if (!enterCoilNo) {
throw new Error('二维码中未包含有效的入场钢卷号');
}
// 3. 通过追溯接口获取准确的钢卷信息
// 3. 通过追溯接口获取钢卷信息
const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo);
if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records.length === 0) {
throw new Error('未找到钢卷信息');
}
// 4. 找到当前数据
// 4. 根据二维码内容匹配对应的钢卷数据
let coilData = null;
for (const record of traceRes.data.records) {
if (record.dataType === 1 && record.currentCoilNo === currentCoilNo) {
coilData = record;
break;
}
const records = traceRes.data.records;
// 优先使用coil_id精确匹配
if (coilId) {
coilData = records.find(record => String(record.coilId) === String(coilId));
}
// 如果没找到使用currentCoilNo匹配
if (!coilData && currentCoilNo) {
coilData = records.find(record => record.currentCoilNo === currentCoilNo);
}
// 如果还是没找到,取第一条记录
if (!coilData && records.length > 0) {
coilData = records[0];
}
if (!coilData) {
for (const record of traceRes.data.records) {
if (record.dataType === 1) {
coilData = record;
break;
}
}
throw new Error('未找到对应的钢卷数据');
}
if (!coilData) {
coilData = traceRes.data.records[0];
// 5. 检查是否为历史数据
if (coilData.dataType === 0) {
uni.showModal({
title: '历史数据',
content: '此为历史记录,不允许进行合卷操作',
showCancel: false
});
return;
}
// 5. 检查是否已扫描过
// 6. 检查是否已扫描过
const exists = this.scannedCoils.some(coil => coil.coilId === coilData.coilId);
if (exists) {
uni.showToast({
@@ -370,9 +473,6 @@ export default {
return;
}
// 保存二维码状态到钢卷数据中
coilData.qrcodeStatus = qrcodeStatus;
this.scannedCoils.push(coilData);
console.log('钢卷详情:', coilData);
@@ -425,6 +525,9 @@ export default {
this.warehouseId = undefined;
this.warehouseName = '';
this.warehouseKeyword = '';
this.itemType = '';
this.itemId = undefined;
this.selectedProductName = '';
this.grossWeight = '';
this.netWeight = '';
this.showWarehouseList = false;
@@ -435,11 +538,12 @@ export default {
// 提交合卷
handleConfirm() {
// 检查是否包含历史二维码
if (this.hasHistoryQrcode) {
// 检查是否包含历史数据
const hasHistoryData = this.scannedCoils.some(coil => coil.dataType === 0);
if (hasHistoryData) {
uni.showModal({
title: '包含历史二维码',
content: '列表中包含已失效的二维码,不允许进行合卷操作,请移除后重试',
title: '包含历史数据',
content: '列表中包含历史记录,不允许进行合卷操作,请移除后重试',
showCancel: false
});
return;
@@ -481,8 +585,8 @@ export default {
currentCoilNo: this.mergedCoilNo,
team: this.team,
hasMergeSplit: 2, // 2表示合卷
itemType: this.scannedCoils[0].itemType,
itemId: this.scannedCoils[0].itemId,
itemType: this.itemType || this.scannedCoils[0].itemType, // 优先使用选择的itemType
itemId: this.itemId || this.scannedCoils[0].itemId, // 优先使用选择的itemId
warehouseId: this.warehouseId || this.scannedCoils[0].warehouseId, // 使用选择的库区或第一个钢卷的库区
grossWeight: this.grossWeight ? Number(this.grossWeight) : null,
netWeight: this.netWeight ? Number(this.netWeight) : null,

View File

@@ -44,21 +44,12 @@
</view>
</view>
<!-- 历史码提示 -->
<view class="warning-card" v-if="form.coilId && qrcodeStatus === 0">
<view class="warning-icon"></view>
<view class="warning-content">
<text class="warning-title">历史二维码</text>
<text class="warning-desc">此二维码已失效已为您加载最新物料信息仅可查看无法修改</text>
</view>
</view>
<!-- 历史数据提示 -->
<view class="warning-card" v-if="form.coilId && coilDetail.dataType === 0 && qrcodeStatus !== 0">
<view class="warning-card" v-if="form.coilId && coilDetail.dataType === 0">
<view class="warning-icon"></view>
<view class="warning-content">
<text class="warning-title">历史数据</text>
<text class="warning-desc">钢卷为历史数据查看无法修改</text>
<text class="warning-desc">此为历史记录查看不允许进行修改操作</text>
</view>
</view>
@@ -76,8 +67,8 @@
v-model="form.currentCoilNo"
placeholder="请输入当前钢卷号"
class="form-input"
:disabled="coilDetail.dataType === 0 || qrcodeStatus === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 || qrcodeStatus === 0 }"
:disabled="coilDetail.dataType === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 }"
/>
</view>
@@ -88,8 +79,8 @@
v-model="form.team"
placeholder="请输入班组名称"
class="form-input"
:disabled="coilDetail.dataType === 0 || qrcodeStatus === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 || qrcodeStatus === 0 }"
:disabled="coilDetail.dataType === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 }"
/>
</view>
@@ -98,13 +89,28 @@
<text class="form-label-optional">目标库区</text>
<view
class="picker-input"
@click="(coilDetail.dataType !== 0 && qrcodeStatus !== 0) && showWarehousePicker()"
:class="{ 'picker-input-disabled': coilDetail.dataType === 0 || qrcodeStatus === 0 }"
@click="coilDetail.dataType !== 0 && showWarehousePicker()"
:class="{ 'picker-input-disabled': coilDetail.dataType === 0 }"
>
<text class="picker-text" :class="{ 'picker-placeholder': !currentWarehouseName }">
{{ currentWarehouseName || '请选择目标库区' }}
</text>
<text class="picker-arrow" v-if="coilDetail.dataType !== 0 && qrcodeStatus !== 0"></text>
<text class="picker-arrow" v-if="coilDetail.dataType !== 0"></text>
</view>
</view>
<!-- 产品选择仅当选择了成品库区时显示 -->
<view class="form-item form-item-optional" v-if="form.itemType === 'product'">
<text class="form-label-optional">选择产品</text>
<view
class="picker-input"
@click="coilDetail.dataType !== 0 && showProductPicker()"
:class="{ 'picker-input-disabled': coilDetail.dataType === 0 }"
>
<text class="picker-text" :class="{ 'picker-placeholder': !selectedProductName }">
{{ selectedProductName || '请选择产品' }}
</text>
<text class="picker-arrow" v-if="coilDetail.dataType !== 0"></text>
</view>
</view>
@@ -113,11 +119,11 @@
<text class="form-label-optional">毛重 (kg)</text>
<input
v-model="form.grossWeight"
type="digit"
type="digit"
placeholder="请输入毛重(选填)"
class="form-input"
:disabled="coilDetail.dataType === 0 || qrcodeStatus === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 || qrcodeStatus === 0 }"
:disabled="coilDetail.dataType === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 }"
/>
</view>
@@ -126,11 +132,11 @@
<text class="form-label-optional">净重 (kg)</text>
<input
v-model="form.netWeight"
type="digit"
type="digit"
placeholder="请输入净重(选填)"
class="form-input"
:disabled="coilDetail.dataType === 0 || qrcodeStatus === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 || qrcodeStatus === 0 }"
:disabled="coilDetail.dataType === 0"
:class="{ 'form-input-disabled': coilDetail.dataType === 0 }"
/>
</view>
@@ -144,7 +150,7 @@
<view class="action-buttons">
<button class="btn btn-secondary" @click="handleReset">重新扫码</button>
<button
v-if="coilDetail.dataType === 1 && qrcodeStatus === 1"
v-if="coilDetail.dataType === 1"
class="btn btn-primary"
@click="handleConfirm"
:disabled="loading"
@@ -186,6 +192,38 @@
</view>
</uni-popup>
<!-- 产品选择弹窗 -->
<uni-popup ref="productPopup" type="bottom">
<view class="warehouse-popup">
<view class="popup-header">
<text class="popup-title">选择产品</text>
<text class="popup-close" @click="closeProductPicker"></text>
</view>
<view class="popup-search">
<input
v-model="productSearchKeyword"
@input="filterProductsInPicker"
placeholder="搜索产品名称"
class="search-input"
/>
</view>
<scroll-view scroll-y class="popup-body">
<view
class="warehouse-item"
v-for="product in filteredProductsInPicker"
:key="product.productId"
@click="selectProductFromPicker(product)"
>
<text class="warehouse-name">{{ product.productName }}</text>
<text class="warehouse-check" v-if="form.itemId === product.productId"></text>
</view>
<view class="empty-tip" v-if="!filteredProductsInPicker || filteredProductsInPicker.length === 0">
<text>未找到匹配的产品</text>
</view>
</scroll-view>
</view>
</uni-popup>
<!-- BOM弹窗 -->
<uni-popup ref="bomPopup" type="bottom">
<view class="bom-popup">
@@ -221,6 +259,7 @@
import { updateMaterialCoil, getMaterialCoil, getMaterialCoilTrace } from '@/api/wms/coil.js'
import { listWarehouse } from '@/api/wms/warehouse.js'
import { getRawMaterial } from '@/api/wms/rawMaterial.js'
import { listProduct } from '@/api/wms/product.js'
export default {
data() {
@@ -246,6 +285,10 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
currentWarehouseName: '',
warehouseSearchKeyword: '',
filteredWarehousesInPicker: [],
products: [], // 产品列表
productSearchKeyword: '',
filteredProductsInPicker: [],
selectedProductName: '', // 已选择的产品名称
loading: false,
qrcodeStatus: 1 // 二维码状态0=历史码1=当前有效码
}
@@ -285,6 +328,62 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
}
},
// 加载产品列表
async loadProducts() {
console.log('开始加载产品列表...');
try {
const res = await listProduct({ pageNum: 1, pageSize: 1000 });
console.log("产品返回值", res);
if (res.code === 200) {
this.products = res.rows || res.data || [];
this.filteredProductsInPicker = this.products;
console.log('产品加载成功,数量:', this.products.length);
} else {
console.error('产品加载失败:', res.msg);
}
} catch (err) {
console.error('加载产品异常:', err);
}
},
// 显示产品选择器
showProductPicker() {
this.productSearchKeyword = '';
this.filteredProductsInPicker = [...this.products];
this.$refs.productPopup.open();
},
// 关闭产品选择器
closeProductPicker() {
this.$refs.productPopup.close();
},
// 过滤产品(在选择器中)
filterProductsInPicker() {
console.log('过滤产品,关键词:', this.productSearchKeyword);
const keyword = this.productSearchKeyword.trim().toLowerCase();
if (!keyword) {
this.filteredProductsInPicker = [...this.products];
} else {
this.filteredProductsInPicker = this.products.filter(product => {
const name = (product.productName || '').toLowerCase();
return name.includes(keyword);
});
}
},
// 从选择器中选择产品
selectProductFromPicker(product) {
this.form.itemId = product.productId;
this.form.itemType = 'product';
this.selectedProductName = product.productName;
uni.showToast({
title: `已选择产品:${product.productName}`,
icon: 'success'
});
this.closeProductPicker();
},
// 过滤库区
filterWarehouses() {
console.log('过滤库区,关键词:', this.warehouseKeyword);
@@ -339,11 +438,21 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
},
// 从选择器中选择库区
selectWarehouseFromPicker(warehouse) {
async selectWarehouseFromPicker(warehouse) {
this.form.warehouseId = warehouse.warehouseId;
this.form.warehouseName = warehouse.warehouseName;
this.currentWarehouseName = warehouse.warehouseName;
this.closeWarehousePicker();
// 检查是否选择了成品库区
if (warehouse.warehouseName && warehouse.warehouseName.includes('成品')) {
// 切换为产品类型
this.form.itemType = 'product';
// 加载产品列表
await this.loadProducts();
// 弹出产品选择框
this.showProductPicker();
}
},
// 扫码
@@ -361,11 +470,12 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
throw new Error('未找到二维码记录');
}
// 2. 解析二维码的content获取enter_coil_nocurrent_coil_no
// 2. 解析二维码的content获取enter_coil_nocurrent_coil_no和coil_id
const qrcodeRecord = qrcodeRes.data;
const content = JSON.parse(qrcodeRecord.content);
const enterCoilNo = content.enter_coil_no;
const currentCoilNo = content.current_coil_no;
const coilId = content.coil_id && content.coil_id !== 'null' ? content.coil_id : null;
// 保存二维码状态0=历史码1=当前有效码)
this.qrcodeStatus = qrcodeRecord.status || 1;
@@ -374,55 +484,42 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
throw new Error('二维码中未包含有效的入场钢卷号');
}
// 3. 如果是历史码,提示用户并加载最新数据
// 3. 如果是历史码,提示用户
if (this.qrcodeStatus === 0) {
uni.showToast({
title: '历史二维码,已加载最新信息',
title: '历史二维码,仅供查看',
icon: 'none',
duration: 2000
});
}
// 4. 通过入场钢卷号查询最新的钢卷详情不传currentCoilNo获取所有相关钢卷
// 如果是历史码,查询该入场钢卷号的最新数据
const traceRes = await getMaterialCoilTrace(enterCoilNo, this.qrcodeStatus === 0 ? null : currentCoilNo);
// 4. 通过入场钢卷号查询钢卷追溯信息
const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo);
if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records.length === 0) {
throw new Error('未找到钢卷信息');
}
// 5. 从追溯结果中找到当前数据dataType = 1
// 5. 根据二维码内容匹配对应的钢卷数据
let coilData = null;
if (this.qrcodeStatus === 0) {
// 历史码找到最新的当前数据dataType = 1
for (const record of traceRes.data.records) {
if (record.dataType === 1) {
coilData = record;
break;
}
}
} else {
// 当前码:找到匹配当前钢卷号的记录
for (const record of traceRes.data.records) {
if (record.dataType === 1 && record.currentCoilNo === currentCoilNo) {
coilData = record;
break;
}
}
const records = traceRes.data.records;
// 优先使用coil_id精确匹配
if (coilId) {
coilData = records.find(record => String(record.coilId) === String(coilId));
}
// 如果没找到精确匹配的,取第一个当前数据
if (!coilData) {
for (const record of traceRes.data.records) {
if (record.dataType === 1) {
coilData = record;
break;
}
}
// 如果没找到使用currentCoilNo匹配
if (!coilData && currentCoilNo) {
coilData = records.find(record => record.currentCoilNo === currentCoilNo);
}
// 如果还是没找到,取第一条记录
if (!coilData && records.length > 0) {
coilData = records[0];
}
// 如果还是没有找到,取第一个记录(可能是历史数据)
if (!coilData) {
coilData = traceRes.data.records[0];
throw new Error('未找到对应的钢卷数据');
}
// 保存钢卷详情
@@ -515,6 +612,7 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
this.bomItemList = [];
this.warehouseKeyword = '';
this.currentWarehouseName = '';
this.selectedProductName = '';
this.filteredWarehouses = this.warehouses;
this.qrcodeStatus = 1; // 重置二维码状态
}
@@ -530,12 +628,6 @@ import { getRawMaterial } from '@/api/wms/rawMaterial.js'
return;
}
// 历史二维码不允许修改
if (this.qrcodeStatus === 0) {
uni.showToast({ title: '历史二维码不允许修改', icon: 'none' });
return;
}
// 验证必填项
if (!this.form.currentCoilNo) {
uni.showToast({ title: '请输入当前钢卷号', icon: 'none' });