提交 8d6db061 编写于 作者: C cangdu 提交者: GitHub

Merge pull request #46 from clarkdo/master

[加入购物车]代码分支简化
...@@ -64,52 +64,20 @@ export default { ...@@ -64,52 +64,20 @@ export default {
let cart = state.cartList; let cart = state.cartList;
if (cart[shopid] && cart[shopid][category_id] && cart[shopid][category_id][item_id] && cart[shopid][category_id][item_id][food_id]) { if (cart[shopid] && cart[shopid][category_id] && cart[shopid][category_id][item_id] && cart[shopid][category_id][item_id][food_id]) {
cart[shopid][category_id][item_id][food_id]['num']++; cart[shopid][category_id][item_id][food_id]['num']++;
} else if (cart[shopid] && cart[shopid][category_id] && cart[shopid][category_id][item_id]) {
cart[shopid][category_id][item_id][food_id] = {};
cart[shopid][category_id][item_id][food_id]['num'] = 1;
cart[shopid][category_id][item_id][food_id]['id'] = food_id;
cart[shopid][category_id][item_id][food_id]['name'] = name;
cart[shopid][category_id][item_id][food_id]['price'] = price;
cart[shopid][category_id][item_id][food_id]['specs'] = specs;
cart[shopid][category_id][item_id][food_id]['packing_fee'] = packing_fee;
cart[shopid][category_id][item_id][food_id]['sku_id'] = sku_id;
cart[shopid][category_id][item_id][food_id]['stock'] = stock;
} else if (cart[shopid] && cart[shopid][category_id]) {
cart[shopid][category_id][item_id] = {};
cart[shopid][category_id][item_id][food_id] = {};
cart[shopid][category_id][item_id][food_id]['num'] = 1;
cart[shopid][category_id][item_id][food_id]['id'] = food_id;
cart[shopid][category_id][item_id][food_id]['name'] = name;
cart[shopid][category_id][item_id][food_id]['price'] = price;
cart[shopid][category_id][item_id][food_id]['specs'] = specs;
cart[shopid][category_id][item_id][food_id]['packing_fee'] = packing_fee;
cart[shopid][category_id][item_id][food_id]['sku_id'] = sku_id;
cart[shopid][category_id][item_id][food_id]['stock'] = stock;
} else if (cart[shopid]) {
cart[shopid][category_id] = {};
cart[shopid][category_id][item_id] = {};
cart[shopid][category_id][item_id][food_id] = {};
cart[shopid][category_id][item_id][food_id]['num'] = 1;
cart[shopid][category_id][item_id][food_id]['id'] = food_id;
cart[shopid][category_id][item_id][food_id]['name'] = name;
cart[shopid][category_id][item_id][food_id]['price'] = price;
cart[shopid][category_id][item_id][food_id]['specs'] = specs;
cart[shopid][category_id][item_id][food_id]['packing_fee'] = packing_fee;
cart[shopid][category_id][item_id][food_id]['sku_id'] = sku_id;
cart[shopid][category_id][item_id][food_id]['stock'] = stock;
} else { } else {
cart[shopid] = {}; cart[shopid] = (cart[shopid] || {});
cart[shopid][category_id] = {}; cart[shopid][category_id] = (cart[shopid][category_id] || {});
cart[shopid][category_id][item_id] = {}; cart[shopid][category_id][item_id] = (cart[shopid][category_id][item_id] || {});
cart[shopid][category_id][item_id][food_id] = {}; cart[shopid][category_id][item_id][food_id] = {
cart[shopid][category_id][item_id][food_id]['num'] = 1; "num" : 1,
cart[shopid][category_id][item_id][food_id]['id'] = food_id; "id" : food_id,
cart[shopid][category_id][item_id][food_id]['name'] = name; "name" : name,
cart[shopid][category_id][item_id][food_id]['price'] = price; "price" : price,
cart[shopid][category_id][item_id][food_id]['specs'] = specs; "specs" : specs,
cart[shopid][category_id][item_id][food_id]['packing_fee'] = packing_fee; "packing_fee" : packing_fee,
cart[shopid][category_id][item_id][food_id]['sku_id'] = sku_id; "sku_id" : sku_id,
cart[shopid][category_id][item_id][food_id]['stock'] = stock; "stock" : stock
};
} }
state.cartList = {...cart}; state.cartList = {...cart};
//存入localStorage //存入localStorage
...@@ -280,4 +248,4 @@ export default { ...@@ -280,4 +248,4 @@ export default {
state.cartPrice = price; state.cartPrice = price;
}, },
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册