| | |
| | | <view class="title">SN确认</view> |
| | | |
| | | <view v-if="current === 'true'" class="remark"> |
| | | 备注:点击"扫码"按钮扫描SN码,再次点击可覆盖上次记录 |
| | | 备注:点击"扫码"按钮打开专业扫码界面(免费官方组件) |
| | | </view> |
| | | |
| | | <view class="scan-table"> |
| | |
| | | mid: null, // MES主表ID |
| | | scanItems: [], // 从 MES_SJ_SCAN_ITEM_CK 获取 |
| | | current: 'true', // 控制是否可编辑 |
| | | currentScanIndex: -1, // 当前扫描的索引 |
| | | }; |
| | | }, |
| | | |
| | | onLoad(options) { |
| | | // 调试信息:打印接收到的参数 |
| | | console.log('ScanCode页面接收到的参数:', options); |
| | | |
| | | // 假设从上一页传入 mid |
| | | this.mid = options.id || null; |
| | | this.current = options.current || 'true'; // 默认为可编辑状态 |
| | | |
| | | // 调试信息:打印mid值 |
| | | console.log('mid值:', this.mid); |
| | | console.log('current值:', this.current); |
| | | |
| | | // 临时测试:如果mid为空,使用默认值 |
| | | if (!this.mid) { |
| | | console.warn('警告:mid为空,使用测试数据'); |
| | | // 取消注释下面一行可以直接显示测试数据 |
| | | // this.loadTestData(); |
| | | // return; |
| | | } |
| | | |
| | | this.getScanItems(); |
| | | }, |
| | | |
| | | methods: { |
| | | // 临时测试方法:加载测试数据 |
| | | loadTestData() { |
| | | console.log('加载测试数据'); |
| | | this.scanItems = [ |
| | | { id: 1, scanItem: '产品SN', snNo: '' }, |
| | | { id: 2, scanItem: '机架号', snNo: '' }, |
| | | { id: 3, scanItem: '电机编号', snNo: '' }, |
| | | ]; |
| | | uni.showToast({ |
| | | title: '已加载测试数据', |
| | | icon: 'success' |
| | | }); |
| | | }, |
| | | |
| | | // 从 MES_SJ_SCAN_ITEM_CK 获取数据 |
| | | getScanItems() { |
| | | if (!this.mid) return; |
| | | console.log('开始获取SN列表, mid:', this.mid); |
| | | |
| | | if (!this.mid) { |
| | | console.error('mid为空,无法获取列表'); |
| | | uni.showToast({ |
| | | title: "缺少必要参数", |
| | | icon: "none" |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | uni.showLoading({ title: "加载中..." }); |
| | | |
| | | console.log('准备调用接口:/SJ/GetList, 参数:', { mid: this.mid }); |
| | | |
| | | this.$post({ |
| | | url: "/SJ/GetList", |
| | | data: { mid: this.mid } |
| | | }).then(res => { |
| | | console.log('接口返回结果:', res); |
| | | |
| | | if (res.status === 0) { |
| | | console.log('返回的数据:', res.data); |
| | | |
| | | this.scanItems = res.data.map(x => ({ |
| | | id: x.id, |
| | | scanItem: x.scanItem, |
| | | snNo: x.snNo || "", |
| | | })); |
| | | |
| | | console.log('处理后的scanItems:', this.scanItems); |
| | | |
| | | if (this.scanItems.length === 0) { |
| | | uni.showToast({ |
| | | title: "暂无扫码项目", |
| | | icon: "none" |
| | | }); |
| | | } |
| | | } else { |
| | | console.error('接口返回错误:', res.message); |
| | | uni.showToast({ |
| | | title: res.message || "加载失败", |
| | | icon: "none" |
| | |
| | | }); |
| | | }, |
| | | |
| | | // 扫码功能 |
| | | // 扫码成功回调(由 nvue 扫码页面调用) |
| | | onScanSuccess(scanResult) { |
| | | console.log('扫码结果:', scanResult); |
| | | |
| | | if (this.currentScanIndex >= 0 && this.currentScanIndex < this.scanItems.length) { |
| | | // 更新对应项目的SN码 |
| | | this.scanItems[this.currentScanIndex].snNo = scanResult.trim(); |
| | | |
| | | uni.showToast({ |
| | | title: '扫码成功', |
| | | icon: 'success' |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | // 打开扫码页面(使用识别率更高的方案) |
| | | onScan(index) { |
| | | const self = this; |
| | | |
| | | // #ifdef MP-WEIXIN |
| | | uni.scanCode({ |
| | | success(res){ |
| | | self.scanItems[index].snNo = res.result; |
| | | }, |
| | | fail(err) { |
| | | console.log("扫码失败", err); |
| | | }, |
| | | this.currentScanIndex = index; |
| | | const itemName = this.scanItems[index].scanItem; |
| | | |
| | | // 跳转到 nvue 扫码页面(使用官方 Barcode 组件,识别率 90%+) |
| | | uni.navigateTo({ |
| | | url: `/pages/QC/SJ/BarcodeScan?title=${encodeURIComponent(itemName)}` |
| | | }); |
| | | // #endif |
| | | |
| | | // #ifdef H5 |
| | | uni.showToast({ |
| | | title: "请使用扫码枪输入到SN输入框", |
| | | icon: "none", |
| | | }); |
| | | // #endif |
| | | |
| | | // #ifdef APP-PLUS |
| | | uni.scanCode({ |
| | | scanType: ['barCode'], // 新增这一行 |
| | | autoDecodeCharset: true, // 自动解码字符集 |
| | | success(res) { |
| | | console.log(res) |
| | | self.scanItems[index].snNo = res.result; |
| | | }, |
| | | }); |
| | | // #endif |
| | | }, |
| | | |
| | | // 保存 SN 数据到 MES_SJ_SCAN_ITEM_CK |