快乐的昕的电脑
2025-10-13 749b366b2af987479d3e13a3dd1a478781211bb7
components/mold.vue
@@ -175,7 +175,28 @@
         confirmTool() {
            this.showToolDialog = false;
         },
            async handleUpTool() {
         async handleUpTool() {
                if (!this.workOrderNo) {
                    this.$showMessage('工单号不能为空');
                    return;
                }
                if (!this.machineNo) {
                    this.$showMessage('机台号不能为空');
                    return;
                }
                if (!this.selectedToolNo) {
                    this.$showMessage('刀具编号不能为空');
                    return;
                }
                if (!this.useLimitInput) {
                    this.$showMessage('使用上限不能为空');
                    return;
            }
                const useLimit = Number(this.useLimitInput);
                if (isNaN(useLimit) || useLimit <= 0) {
                    this.$showMessage('请输入有效的使用上限');
                    return;
                }
                const payload = {
                    workOrderNo: this.workOrderNo,   // 工单号
                    machineNo: this.machineNo,       // 机台编号
@@ -194,7 +215,28 @@
                    this.$showMessage(res.message || '上刀提交失败');
                }
            },
            async handleDownTool() {
         async handleDownTool() {
                if (!this.workOrderNo) {
                    this.$showMessage('工单号不能为空');
                    return;
                }
                if (!this.machineNo) {
                    this.$showMessage('机台号不能为空');
                    return;
                }
                if (!this.selectedToolNo) {
                    this.$showMessage('刀具编号不能为空');
                    return;
                }
                if (!this.useLimitInput) {
                    this.$showMessage('使用上限不能为空');
                    return;
            }
                const useLimit = Number(this.useLimitInput);
                if (isNaN(useLimit) || useLimit <= 0) {
                    this.$showMessage('请输入有效的使用上限');
                    return;
                }
                const payload = {
                    workOrderNo: this.workOrderNo,
                    machineNo: this.machineNo,
@@ -218,17 +260,29 @@
            this.toolName = '';
            this.toolModel = '';
         },
         setUseLimit() {
            // 保存使用上限逻辑,实际应调用后端接口
            this.$showMessage('使用上限已保存(示例)');
         }
            async fetchFormData() {
                const payload = {
                    workOrderNo: this.workOrderNo && this.workOrderNo.trim() !== '' ? this.workOrderNo : null,
                    machineNo: this.machineNo && this.machineNo.trim() !== '' ? this.machineNo : null,
                };
                const res = await this.$post({
                    url: '/api/MesCutterLedger/GetFormData', // 加上 /api 前缀
                    data: JSON.stringify(payload),
                    headers: { 'Content-Type': 'application/json' }
                });
                if (res.status === 0) {
                    this.toolRecords = res.data;
                } else {
                    this.$showMessage(res.message || '获取表单数据失败');
                }
            }
      },
      mounted() {
         // 页面加载时拉取全部刀具
         this.fetchTools('');
            this.machineNo = uni.getStorageSync('machineNo') || '';// 读取本地缓存的机台编号
            this.workOrderNo = uni.getStorageSync('workOrderNo') || '';// 读取本地缓存的工单编号
      }
        mounted() {
            this.fetchTools('');
            this.machineNo = uni.getStorageSync('machineNo') || '';
            this.workOrderNo = uni.getStorageSync('daa001') || '';
            if (this.machineNo && this.workOrderNo) {this.fetchFormData();}
        }
   };
</script>