快乐的昕的电脑
2025-10-31 713091471f5bc416ecaaa7f11852785df2f08c77
components/machine.vue
@@ -157,40 +157,63 @@
         },
         // 保存并生效,将时间等信息提交到后端
         // 变更:返回 Promise;成功后局部刷新(调用 findByOrderId)而不是整页 reload
         save() {
            if (!this.statusForm.id) {
               this.$showMessage("id为空,不允许推送");
               return Promise.resolve();
            }
            return this.$post({
               url: "/MesOrderSta/ChangeMachineTime",
               data: {
                  maStartTime: this.maStartTime,
                  maShoutTime: this.maShoutTime,
                  maEndTime: this.maEndTime,
                  id: this.statusForm.id,
                  orderId: this.orderId,
                  machineNo: this.machineNo,
                  flag: this.flag
               }
            }).then(res => {
               if (res && res.data && res.data.tbBillList) {
                  this.$showMessage("呼叫成功");
                  // 局部刷新:重新拉取当前工单状态并更新当前组件数据
                  this.findByOrderId();
                  // 如果需要在保存后关闭对话框或返回上一级,可在这里处理
               } else {
                  this.$showMessage("呼叫失败");
                  this.cancel();
               }
               return res;
            }).catch(err => {
               // 保持友好的错误提示并将错误抛出以便外部链式处理
               console.error('保存失败:', err);
               this.$showMessage("保存时发生错误");
               throw err;
            });
         },
            save() {
                if (!this.statusForm.id) {
                    this.$showMessage("id为空,不允许推送");
                    return Promise.resolve();
                }
                return this.$post({
                    url: "/MesOrderSta/ChangeMachineTime",
                    data: {
                        maStartTime: this.maStartTime,
                        maShoutTime: this.maShoutTime,
                        maEndTime: this.maEndTime,
                        id: this.statusForm.id,
                        orderId: this.orderId,
                        machineNo: this.machineNo,
                        flag: this.flag
                    }
                }).then(res => {
                    if (res && res.data && res.data.tbBillList) {
                        this.$showMessage("呼叫成功");
                        // 关键修改:清空 flag 的值
                        this.flag = -1; // 或者根据业务需求设置为其他初始值
                        // 方案1:使用uni-app的页面刷新方法
                        // 方法1:触发下拉刷新(如果页面支持)
                        if (uni.startPullDownRefresh) {
                            uni.startPullDownRefresh();
                            // 2秒后停止刷新
                            setTimeout(() => {
                                uni.stopPullDownRefresh();
                            }, 2000);
                        }
                        // 方法2:重新调用页面的onLoad方法(推荐)
                        const pages = getCurrentPages();
                        const currentPage = pages[pages.length - 1];
                        if (currentPage && currentPage.onLoad) {
                            // 保存当前页面参数
                            const pageOptions = currentPage.options || {};
                            // 重新加载页面数据
                            currentPage.onLoad(pageOptions);
                        }
                        // 方法3:同时刷新组件数据
                        this.findByOrderId();
                    } else {
                        this.$showMessage("呼叫失败");
                        this.cancel();
                    }
                    return res;
                }).catch(err => {
                    console.error('保存失败:', err);
                    this.$showMessage("保存时发生错误");
                    throw err;
                });
            },
         // 取消操作,恢复为上次保存的数据
         cancel() {
            this.maShoutTime = this.statusForm.maShoutTime;