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: {
+35 -41
View File
@@ -465,7 +465,6 @@ export default {
mixins: [pageListenMixins],
data: function () {
return {
addressId: null,
showExtend: false,
delayId: '',
showMore: false,
@@ -498,47 +497,42 @@ export default {
...mapGetters(["userInfo"])
},
onShow() {
this.id = this.$yroute.query.id;
this.getDetail();
uni.$on('chooseAddress', (res) => {
this.addressId = res.id
})
},
watch: {
addressId(val) {
if(val) {
const params = {
addressId: this.addressId,
orderId: this.orderInfo.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: '修改成功!'
})
this.getDetail();
}).finally(() => {
uni.hideLoading()
})
}
},
complete:(complete)=>{
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.orderInfo.orderId
}).then(res => {
uni.showToast({
icon: 'success',
title: '修改成功!'
})
_this.getDetail()
}).finally(() => {
uni.hideLoading()
this.addressId = ''
},
})
}, 1000)
}
})
}
},
complete:(complete)=>{
uni.hideLoading()
}
})
} else {
_this.id = _this.$yroute.query.id;
_this.getDetail();
}
},
// inject: ["app"],
+31 -34
View File
@@ -388,49 +388,46 @@ export default {
this.computedPrice('couponId')
}
},
onLoad: function () {
let that = this;
uni.$on('chooseAddress', (res) => {
console.log('监听到选择收货地址:' + JSON.stringify(res));
setTimeout(() => {
uni.showModal({
title:'确定修改地址吗?',
content: '',
showCancel: true,
cancelText: '取消',
confirmText: '确认',
success:(success)=>{
if(success.confirm) {
that.addressInfo = res;
//地址切换也要重新计算一下
that.computedPrice('onLoad chooseAddress');
}
},
complete:(complete)=>{
uni.hideLoading()
},
})
})
},1000)
onLoad() {
const that = this
if (that.$yroute.query.pinkid !== undefined) {
that.pinkId = that.$yroute.query.pinkid;
that.pinkId = that.$yroute.query.pinkid
}
if (that.$yroute.query.id !== undefined) {
that.cartid = that.$yroute.query.id;
that.cartid = that.$yroute.query.id
console.log(that.cartid)
}
if (that.$yroute.query.lotteryRecordId !== undefined) {
that.lotteryRecordId = that.$yroute.query.lotteryRecordId;
that.lotteryRecordId = that.$yroute.query.lotteryRecordId
}
that.getCartInfo();
that.getCartInfo()
},
onUnload: function () {
console.log('关闭监听选择收货地址');
uni.$off('chooseAddress');
},
onShow: function () {
onShow() {
const _this = this
//获取用户信息
this.$store.dispatch("getUser", true);
_this.$store.dispatch("getUser", true)
const chooseAddress = uni.getStorageSync('chooseAddress') || {}
// 监听到选择收货地址
if (chooseAddress.id) {
uni.showModal({
title:'确定修改地址吗?',
content: '',
showCancel: true,
cancelText: '取消',
confirmText: '确认',
success: (res) => {
if(res.confirm) {
_this.addressInfo = chooseAddress
// 地址切换也要重新计算一下
_this.computedPrice('onLoad chooseAddress')
}
},
complete: () => {
uni.hideLoading()
uni.setStorageSync('chooseAddress', {})
}
})
}
},
methods: {
isNullOrEmpty,