Fix(购物车&订单):修复地址选择之后事件分发错误问题

This commit is contained in:
lifizer
2024-12-04 12:03:32 +08:00
parent c0a09ad449
commit c5c9c9146b
6 changed files with 223 additions and 274 deletions
+39 -56
View File
@@ -246,9 +246,7 @@ export default {
delayId: null,
pageKeyId: Object.freeze('userOrderIndex'),
keyword: '',
_orderId: '',
addressId: '',
currentRoute: ''
_orderId: ''
};
},
components: {
@@ -258,60 +256,45 @@ export default {
},
computed: mapGetters(["userInfo"]),
onShow() {
this.type = this.type || parseInt(this.$yroute.query.type) || 0;
this.changeType(this.type);
this.getOrderData();
this.getOrderListReq();
uni.$on('chooseAddress', (res) => {
this.addressId = res.id
})
const pages = getCurrentPages() // 获取栈实例
this.currentRoute = pages[pages.length - 1].route;
},
onHide() {
this.orderList = [];
this.page = 1;
this.limit = 20;
this.loaded = false;
this.loading = false;
},
watch: {
addressId(val) {
const pages = getCurrentPages() // 获取栈实例
let currentRoute = pages[pages.length - 2].route;
if(val && this.currentRoute === currentRoute) {
const params = {
addressId: this.addressId,
orderId: this._orderId
const _this = this
const chooseAddress = uni.getStorageSync('chooseAddress') || {}
const addressId = chooseAddress.id || ''
// 监听到选择收货地址
if (addressId) {
uni.setStorageSync('chooseAddress', {})
uni.showModal({
title:'确定修改地址吗?',
content: '',
showCancel: true,
cancelText: '取消',
confirmText: '确认',
success:(success)=>{
if(success.confirm) {
uni.showLoading()
editAddress({
addressId,
orderId: _this._orderId
}).then(res => {
uni.showToast({
icon: 'success',
title: '修改成功!'
})
_this.changeType()
}).finally(() => {
uni.hideLoading()
})
}
},
cancel: () => {
_this.changeType()
},
complete:(complete)=>{
_this._orderId = ''
}
setTimeout(() => {
uni.showModal({
title:'确定修改地址吗?',
content: '',
showCancel: true,
cancelText: '取消',
confirmText: '确认',
success:(success)=>{
if(success.confirm) {
uni.showLoading()
editAddress(params).then(res => {
uni.showToast({
icon: 'success',
title: '修改成功!'
})
}).finally(() => {
uni.hideLoading()
})
}
},
complete:(complete)=>{
this.addressId = ''
this._orderId = ''
},
})
}, 1000)
}
})
} else {
_this.type = _this.type || parseInt(_this.$yroute.query.type) || 0;
_this.changeType(_this.type);
}
},
methods: {