快乐的昕的电脑
2025-10-13 661d1a63f7de63dc86b9e3b22f0267acc57cd484
components/mold.vue
@@ -117,10 +117,7 @@
            searchKey: '',
            filteredTools: [],
            useLimitInput: '',
            toolRecords: [
               // 示例数据,实际应从后端接口获取
               { id: 1, no: 'T22050338', name: 'm1.5合金长刀', upTime: '7-13 9:00', upCount: 15, downTime: '7-13 19:00', downCount: 3115, useCount: 3100, useLimit: 8888, lifePercent: '34.88%', lifeWarn: '90%', warnStatus: '正常' }
            ]
            toolRecords: []
         };
      },
      computed: {
@@ -261,27 +258,57 @@
            this.toolModel = '';
         },
            async fetchFormData() {
                const payload = new URLSearchParams();
                payload.append('workOrderNo', this.workOrderNo);
                payload.append('machineNo', this.machineNo);
                const res = await this.$post({
                    url: '/MesCutterLedger/GetFormData',
                    data: payload.toString(),
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                });
                if (res.status === 0) {
                    this.toolRecords = res.data; // 假设后端直接返回表格数组
                } else {
                    this.$showMessage(res.message || '获取表单数据失败');
                if (!this.workOrderNo || !this.machineNo) {
                    console.warn('工单号或机台号为空,跳过获取表单数据');
                    return;
                }
                const payload = {
                    workOrderNo: this.workOrderNo.trim(),
                    machineNo: this.machineNo.trim()
                };
                try {
                    console.log('请求参数:', payload); // 添加调试日志
                    const res = await this.$post({
                        url: '/MesCutterLedger/GetFormData',
                        data: JSON.stringify(payload),
                        headers: { 'Content-Type': 'application/json' }
                    });
                    if (res.status === 0) {
                        console.log('获取数据成功:', res.data);
                        // ... 处理数据
                    } else {
                        this.$showMessage(res.message || '获取表单数据失败');
                    }
                } catch (error) {
                    console.error('获取表单数据错误:', error);
                    this.$showMessage('获取数据失败,请检查网络连接');
                }
            }
            //// 添加辅助方法
            //formatDateTime(dateTimeStr) {
            //    if (!dateTimeStr) return '';
            //    // 根据后端返回的时间格式进行调整
            //    const date = new Date(dateTimeStr);
            //    return `${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes().toString().padStart(2, '0')}`;
            //}
      },
        mounted() {
            this.fetchTools('');
            this.machineNo = uni.getStorageSync('machineNo') || '';
            this.workOrderNo = uni.getStorageSync('daa001') || '';
            // 添加调试信息
            console.log('机台号:', this.machineNo);
            console.log('工单号:', this.workOrderNo);
            if (this.machineNo && this.workOrderNo) {
                this.fetchFormData();
            } else {
                console.warn('机台号或工单号为空,无法获取表单数据');
            }
        }
   };