diff --git a/pages/cart.vue b/pages/cart.vue
index f6f0ba8..571eb40 100644
--- a/pages/cart.vue
+++ b/pages/cart.vue
@@ -399,21 +399,23 @@ export default {
},
created() {
this.getCart()
- },
- onLoad() {
this.getAddress()
},
onShow() {
this.isEdit = false
- uni.$on('chooseAddress', (res) => {
- console.log(res, '地址修改了!!!!!!!!!!!!!!!!!!!!');
- this.getAddress(res)
- })
if (!this.isLoad) {
return
}
this.closeAttr()
this.getCart()
+ // 选择地址
+ const cartChooseAddress = uni.getStorageSync('cartChooseAddress') || {}
+ if (cartChooseAddress.id) {
+ this.addressInfo = cartChooseAddress
+ uni.setStorageSync('cartChooseAddress', {})
+ return
+ }
+ this.getAddress()
},
onHide() {
this.pageToHideHandle()
@@ -434,7 +436,7 @@ export default {
this.$yrouter.push({
path: "/pages/user/address/AddressManagement/index",
query: {
- choosMode: 1
+ choosMode: 2
}
});
},
@@ -442,22 +444,28 @@ export default {
this.$yrouter.push({
path: "/pages/user/address/AddAddress/index",
query: {
- choosMode: 1
+ choosMode: 2
}
});
},
- getAddress(details) {
- if(details) {
- this.addressInfo = details;
- this.$forceUpdate()
- }
- if(!details) {
- getAddressList({page: 1, limit: 9999}).then(res => {
- this.addressList = res.data
- this.addressInfo = res.data.find(e => e.isDefault == 1) || res.data[0] && res.data[0] || null
- });
- }
-
+ getAddress() {
+ getAddressList({page: 1, limit: 9999}).then(res => {
+ const { data = [] } = res
+ this.addressList = data
+ if (!this.addressInfo.id) {
+ this.addressInfo = data.find(e => e.isDefault == 1) || (data && data[0]) || null
+ } else {
+ let isExist = false
+ data.map(item => {
+ if (item.id === this.addressInfo.id) {
+ isExist = true
+ }
+ })
+ if (!isExist) {
+ this.addressInfo = data.find(e => e.isDefault == 1) || (data && data[0]) || null
+ }
+ }
+ })
},
clearCart() {
const ids = this.list.map(l => {
diff --git a/pages/order/MyOrder/index.vue b/pages/order/MyOrder/index.vue
index 1f2e0af..920fed8 100644
--- a/pages/order/MyOrder/index.vue
+++ b/pages/order/MyOrder/index.vue
@@ -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: {
diff --git a/pages/order/OrderDetails/index.vue b/pages/order/OrderDetails/index.vue
index 17a6ceb..9731395 100644
--- a/pages/order/OrderDetails/index.vue
+++ b/pages/order/OrderDetails/index.vue
@@ -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"],
diff --git a/pages/order/OrderSubmission/index.vue b/pages/order/OrderSubmission/index.vue
index d98f44c..96086eb 100644
--- a/pages/order/OrderSubmission/index.vue
+++ b/pages/order/OrderSubmission/index.vue
@@ -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,
diff --git a/pages/user/address/AddAddress/index.vue b/pages/user/address/AddAddress/index.vue
index f16b738..836f168 100644
--- a/pages/user/address/AddAddress/index.vue
+++ b/pages/user/address/AddAddress/index.vue
@@ -91,6 +91,8 @@ export default {
return {
district: [],
id: 0,
+ // 是否选择地址模式:0-不是,1-来源订单创建页面,2-来源购物车
+ choosMode: 0,
userAddress: {
realName: '',
phone: '',
@@ -104,6 +106,15 @@ export default {
addressInput: ''
};
},
+ onLoad(e) {
+ // 是否选择模式
+ const choosMode = this.$yroute.query.choosMode || 0
+ if (choosMode) {
+ this.choosMode = parseInt(choosMode)
+ } else {
+ this.choosMode = 0
+ }
+ },
mounted: function () {
const id = this.$yroute.query.id
this.id = id
@@ -382,7 +393,7 @@ export default {
duration: 2000
});
}
- if(that.$yroute.query.choosMode == 1) {
+ if (that.choosMode) {
const item = {
id: res.data.id,
realName: name,
@@ -394,7 +405,12 @@ export default {
is_default: isDefault ? true : false,
post_code: ""
}
- uni.$emit('chooseAddress', item)
+ if(that.choosMode === 1) {
+ uni.setStorageSync('chooseAddress', item)
+ }
+ if(that.choosMode === 2) {
+ uni.setStorageSync('cartChooseAddress', item)
+ }
}
that.$yrouter.back();
});
diff --git a/pages/user/address/AddressManagement/index.vue b/pages/user/address/AddressManagement/index.vue
index ed388f2..4b60f48 100644
--- a/pages/user/address/AddressManagement/index.vue
+++ b/pages/user/address/AddressManagement/index.vue
@@ -1,9 +1,8 @@
@@ -25,7 +24,7 @@
}}{{ item.detail }}
-
+
@@ -65,22 +64,13 @@
添加新地址
-
-
-
-
-