取消获取总数,改为本地计算
This commit is contained in:
parent
5ed2f6412d
commit
348fee275f
|
@ -81,10 +81,6 @@ export default {
|
||||||
},
|
},
|
||||||
service: {
|
service: {
|
||||||
cart: {
|
cart: {
|
||||||
count: {
|
|
||||||
url: "/wxapp/order/myshoppingcarcount",
|
|
||||||
auth: true,
|
|
||||||
},
|
|
||||||
toCart: {
|
toCart: {
|
||||||
url: "/wxapp/order/addshoppingcar",
|
url: "/wxapp/order/addshoppingcar",
|
||||||
showLoading: true,
|
showLoading: true,
|
||||||
|
|
|
@ -2,18 +2,6 @@ import Vue from "vue"
|
||||||
let prototype = Vue.prototype;
|
let prototype = Vue.prototype;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
|
||||||
* 获取总数
|
|
||||||
*/
|
|
||||||
count(id, type) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
prototype.$request({
|
|
||||||
api: "service.cart.count",
|
|
||||||
}).then((response) => {
|
|
||||||
return resolve(response.data.count);
|
|
||||||
}).catch(e => { });
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* 添加到购物车
|
* 添加到购物车
|
||||||
*/
|
*/
|
||||||
|
@ -71,18 +59,12 @@ export default {
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
*/
|
*/
|
||||||
list(refresh) {
|
list() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let cacheList = prototype.$storage.get('user_cart');
|
|
||||||
if ((typeof refresh === "undefined" || false === refresh) && cacheList) {
|
|
||||||
return resolve(cacheList);
|
|
||||||
}
|
|
||||||
|
|
||||||
prototype.$request({
|
prototype.$request({
|
||||||
api: "service.cart.list",
|
api: "service.cart.list",
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.code == 1) {
|
if (response.code == 1) {
|
||||||
prototype.$storage.set('user_cart', response.data);
|
|
||||||
return resolve(response.data);
|
return resolve(response.data);
|
||||||
}
|
}
|
||||||
return reject(response.msg);
|
return reject(response.msg);
|
||||||
|
|
|
@ -255,7 +255,7 @@ export default {
|
||||||
desc: this.content,
|
desc: this.content,
|
||||||
})
|
})
|
||||||
.then((id) => {
|
.then((id) => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
this.$store.commit("system/currentOrderTabIndex", 0);
|
this.$store.commit("system/currentOrderTabIndex", 0);
|
||||||
this.$store.commit("system/refreshOrder", true);
|
this.$store.commit("system/refreshOrder", true);
|
||||||
this.$models.order
|
this.$models.order
|
||||||
|
|
|
@ -161,7 +161,7 @@ export default {
|
||||||
let currentItem = this.list[idx.parentIndex].list[idx.itemIndex];
|
let currentItem = this.list[idx.parentIndex].list[idx.itemIndex];
|
||||||
if (currentItem.number != e.value) {
|
if (currentItem.number != e.value) {
|
||||||
this.$models.cart.change(currentItem.id, e.type).then(() => {
|
this.$models.cart.change(currentItem.id, e.type).then(() => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
currentItem.number = e.value;
|
currentItem.number = e.value;
|
||||||
this.updateTotal(idx.parentIndex);
|
this.updateTotal(idx.parentIndex);
|
||||||
});
|
});
|
||||||
|
@ -182,7 +182,7 @@ export default {
|
||||||
let parentItem = that.list[parentIndex];
|
let parentItem = that.list[parentIndex];
|
||||||
let currentItem = parentItem.list[itemIndex];
|
let currentItem = parentItem.list[itemIndex];
|
||||||
that.$models.cart.delete(currentItem.id).then(() => {
|
that.$models.cart.delete(currentItem.id).then(() => {
|
||||||
that.$store.dispatch("cart/updateAll");
|
that.$store.dispatch("cart/update", true);
|
||||||
parentItem.list.splice(itemIndex, 1);
|
parentItem.list.splice(itemIndex, 1);
|
||||||
if (parentItem.list.length > 0) {
|
if (parentItem.list.length > 0) {
|
||||||
that.updateTotal(parentIndex);
|
that.updateTotal(parentIndex);
|
||||||
|
|
|
@ -42,7 +42,6 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
utils: this.$utils,
|
utils: this.$utils,
|
||||||
loadedCartCount: false,
|
|
||||||
position: { x: 300, y: 1000 },
|
position: { x: 300, y: 1000 },
|
||||||
currentId: 0,
|
currentId: 0,
|
||||||
newId: 0,
|
newId: 0,
|
||||||
|
@ -89,9 +88,8 @@ export default {
|
||||||
this.loadCate();
|
this.loadCate();
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
if (this.isLogin && !this.loadedCartCount) {
|
if (this.isLogin) {
|
||||||
this.$store.dispatch("cart/updateCount");
|
this.$store.dispatch("cart/update");
|
||||||
this.loadedCartCount = true;
|
|
||||||
}
|
}
|
||||||
this.newId = this.currentId = this.currentCateId;
|
this.newId = this.currentId = this.currentCateId;
|
||||||
},
|
},
|
||||||
|
|
|
@ -177,7 +177,7 @@ export default {
|
||||||
*/
|
*/
|
||||||
addToCart() {
|
addToCart() {
|
||||||
this.$models.cart.toCart(this.id).then((msg) => {
|
this.$models.cart.toCart(this.id).then((msg) => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
this.$utils.toast(msg);
|
this.$utils.toast(msg);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,7 +74,7 @@ export default {
|
||||||
initPage(e) {
|
initPage(e) {
|
||||||
this.pageConfig = getApp().globalData.pageConfig;
|
this.pageConfig = getApp().globalData.pageConfig;
|
||||||
if (this.isLogin) {
|
if (this.isLogin) {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update");
|
||||||
}
|
}
|
||||||
this.canUse = this.cartCount > 0;
|
this.canUse = this.cartCount > 0;
|
||||||
if (!e.id) {
|
if (!e.id) {
|
||||||
|
@ -128,16 +128,16 @@ export default {
|
||||||
if (e.value > 0) {
|
if (e.value > 0) {
|
||||||
if (e.type == "add" && e.value == 1) {
|
if (e.type == "add" && e.value == 1) {
|
||||||
this.$models.cart.toCart(id).then(() => {
|
this.$models.cart.toCart(id).then(() => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$models.cart.change(id, e.type).then(() => {
|
this.$models.cart.change(id, e.type).then(() => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$models.cart.delete(id).then(() => {
|
this.$models.cart.delete(id).then(() => {
|
||||||
this.$store.dispatch("cart/updateAll");
|
this.$store.dispatch("cart/update", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,6 +5,7 @@ export default {
|
||||||
state: {
|
state: {
|
||||||
count: 0,
|
count: 0,
|
||||||
briefCart: {
|
briefCart: {
|
||||||
|
loaded: false,
|
||||||
ids: [],
|
ids: [],
|
||||||
list: {},
|
list: {},
|
||||||
},
|
},
|
||||||
|
@ -19,31 +20,27 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
updateCount(context) {
|
update(context, refresh) {
|
||||||
cart.count().then(count => {
|
if (!context.state.briefCart.loaded || refresh) {
|
||||||
context.commit('count', count);
|
cart.list().then((list) => {
|
||||||
});
|
let count = 0, data = {
|
||||||
},
|
ids: [],
|
||||||
briefCart(context) {
|
list: {},
|
||||||
cart.list().then((list) => {
|
};
|
||||||
let data = {
|
list.forEach((item) => {
|
||||||
ids: [],
|
item.good.forEach((k) => {
|
||||||
list: {},
|
count += k.number;
|
||||||
};
|
data.list[k.gid] = k.number;
|
||||||
list.forEach((item) => {
|
});
|
||||||
item.good.forEach((k) => {
|
|
||||||
data.list[k.gid] = k.number;
|
|
||||||
});
|
});
|
||||||
|
data.ids = Object.keys(data.list);
|
||||||
|
context.commit('briefCart', {
|
||||||
|
...data,
|
||||||
|
loaded: true,
|
||||||
|
});
|
||||||
|
context.commit('count', count);
|
||||||
});
|
});
|
||||||
data.ids = Object.keys(data.list);
|
}
|
||||||
context.commit('briefCart', data);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
updateAll(context) {
|
|
||||||
cart.list(true).then(() => {
|
|
||||||
context.dispatch('briefCart');
|
|
||||||
context.dispatch('updateCount');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue