绿满眶商城微信小程序-uniapp
peng
2025-09-10 cd4fa2cfed76c15143511a40783abf3a75eb3146
扫码修改地址
1个文件已修改
98 ■■■■ 已修改文件
pages/order/editOrderAddress/editOrderAddress.vue 98 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/order/editOrderAddress/editOrderAddress.vue
@@ -117,6 +117,20 @@
            }
        },
        methods: {
            // 安全的toast方法,适配小程序环境
            safeShowToast(options) {
                // 确保loading和之前的toast已关闭
                uni.hideLoading();
                uni.hideToast();
                // 使用nextTick确保在下一个事件循环中执行
                this.$nextTick(() => {
                    uni.showToast({
                        ...options,
                        duration: options.duration || 2000
                    });
                });
            },
            // 解析URL参数
            parseUrlParams(url) {
                const params = {};
@@ -136,29 +150,66 @@
            },
            // 加载订单详情
            async loadOrderDetail() {
                if (!this.orderSn) {
                    console.log('订单号为空,无法加载订单详情');
                    this.safeShowToast({
                        title: '订单号不能为空',
                        icon: 'none'
                    });
                    return;
                }
                let loadingShown = false;
                try {
                    uni.showLoading({
                        title: '加载中...'
                    })
                    const res = await getOrderDetailEdit(this.orderSn)
                    console.log('----------获取订单返回结果------------->',res)
                    if (res.data.success) {
                        this.orderDetail = res.data.result
                        console.log('----------------------->订单数据', JSON.stringify(this.orderDetail))
                    });
                    loadingShown = true;
                    console.log('开始请求订单详情,订单号:', this.orderSn);
                    const res = await getOrderDetailEdit(this.orderSn);
                    console.log('----------获取订单返回结果------------->',res);
                    // 检查响应状态
                    if (res && res.data) {
                        if (res.data.success) {
                            this.orderDetail = res.data.result;
                            console.log('----------------------->订单数据', JSON.stringify(this.orderDetail));
                        } else {
                            console.log('API返回失败:', res.data.message);
                            // 先关闭loading再显示toast
                            uni.hideLoading();
                            loadingShown = false;
                            this.safeShowToast({
                                title: res.data.message || '获取订单信息失败',
                                icon: 'none'
                            });
                        }
                    } else {
                        uni.showToast({
                            title: res.data.message || '获取订单信息失败',
                        console.log('服务器响应异常:', res);
                        uni.hideLoading();
                        loadingShown = false;
                        this.safeShowToast({
                            title: '服务器响应异常',
                            icon: 'none'
                        })
                        });
                    }
                } catch (error) {
                    console.error('获取订单详情失败:', error)
                    uni.showToast({
                        title: '获取订单信息失败',
                    console.error('获取订单详情失败:', error);
                    // 网络异常或其他错误
                    if (loadingShown) {
                        uni.hideLoading();
                        loadingShown = false;
                    }
                    this.safeShowToast({
                        title: '网络异常,请稍后重试',
                        icon: 'none'
                    })
                    });
                } finally {
                    uni.hideLoading()
                    // 确保loading被关闭
                    if (loadingShown) {
                        uni.hideLoading();
                    }
                }
            },
@@ -317,17 +368,18 @@
                        needToken: true,
                        data: this.addressForm
                    })
                    console.log("地址保存")
                    if (res.data.success) {
                        uni.showToast({
                            title: '地址保存成功',
                            icon: 'success'
                        // uni.showToast({
                        //     title: '地址保存成功',
                        //     icon: 'success'
                        // })
                        uni.redirectTo({
                            url:'/pages/tabbar/index/home',
                            fail(e) {
                                console.log("跳转失败原因",e)
                            }
                        })
                        setTimeout(() => {
                            uni.switchTab({
                                url:'/pages/tabbar/index/home'
                            })
                        }, 1500)
                    } else {
                        uni.showToast({
                            title: res.data.message || '保存失败',