check and uncheck goods then ajax refresh cart
Showing
12 changed files
with
578 additions
and
420 deletions
@@ -13,62 +13,16 @@ exports.index = (req, res) => { | @@ -13,62 +13,16 @@ exports.index = (req, res) => { | ||
13 | const shoppingKey = req.cookies._SPK || null; | 13 | const shoppingKey = req.cookies._SPK || null; |
14 | const uid = req.cookies.uid || null; | 14 | const uid = req.cookies.uid || null; |
15 | 15 | ||
16 | - // 预售商品 | ||
17 | - let advancedGoods = [], | ||
18 | - advancedCartData; | ||
19 | - | ||
20 | - // 普通商品 | ||
21 | - let ordinaryGoods = [], | ||
22 | - ordinaryCartData; | ||
23 | - | ||
24 | - // skn=0或者已下架的商品,定义为失效商品 | ||
25 | - let invalidGoods = []; | ||
26 | - | ||
27 | - // 库存不足商品 | ||
28 | - let soldOutGoods = []; | ||
29 | - | ||
30 | - // 返回值 | ||
31 | - let resData = {}; | ||
32 | - | ||
33 | cartModel.getCartData(shoppingKey, uid).then((result) => { | 16 | cartModel.getCartData(shoppingKey, uid).then((result) => { |
34 | console.log('get cart data:', result); | 17 | console.log('get cart data:', result); |
35 | if (result.code === 200) { | 18 | if (result.code === 200) { |
36 | - | ||
37 | - if (result.data && result.data.advance_cart_data) { | ||
38 | - // 预售商品 | ||
39 | - advancedCartData = result.data.advance_cart_data; | ||
40 | - advancedGoods = _.concat(advancedGoods, advancedCartData.goods_list); | ||
41 | - invalidGoods = _.concat(invalidGoods, advancedCartData.off_shelves_goods_list); | ||
42 | - soldOutGoods = _.concat(soldOutGoods, advancedCartData.sold_out_goods_list); | ||
43 | - } | ||
44 | - | ||
45 | - if (result.data && result.data.ordinary_cart_data) { | ||
46 | - // 普通商品 | ||
47 | - ordinaryCartData = result.data.ordinary_cart_data; | ||
48 | - ordinaryGoods = _.concat(ordinaryGoods, ordinaryCartData.goods_list); | ||
49 | - invalidGoods = _.concat(invalidGoods, ordinaryCartData.off_shelves_goods_list); | ||
50 | - soldOutGoods = _.concat(soldOutGoods, ordinaryCartData.sold_out_goods_list); | ||
51 | - } | ||
52 | - | ||
53 | - console.log('ordinaryGoods:', ordinaryGoods); | ||
54 | - | ||
55 | - | ||
56 | - _.merge(resData, { | ||
57 | - hasGoods: advancedGoods.length || ordinaryGoods.length || invalidGoods.length, | ||
58 | - preSalePros: advancedGoods.length ? _.groupBy(advancedGoods, 'brand_id') : [], | ||
59 | - commonPros: ordinaryGoods.length ? _.groupBy(ordinaryGoods, 'brand_id') : [], | ||
60 | - invalidPros: invalidGoods | ||
61 | - }); | ||
62 | - | ||
63 | - console.log('resData:', resData); | ||
64 | - | ||
65 | res.display('cart', _.merge({ | 19 | res.display('cart', _.merge({ |
66 | module: 'shopping', | 20 | module: 'shopping', |
67 | - page: 'cart' | 21 | + page: 'cart', |
22 | + bcNavFocus: 1 | ||
68 | }, { | 23 | }, { |
69 | helpers: require('../helpers') | 24 | helpers: require('../helpers') |
70 | - }, resData)); | ||
71 | - | 25 | + }, cartModel.filterCartData(result, uid))); |
72 | } else { | 26 | } else { |
73 | // code 500 | 27 | // code 500 |
74 | res.send(result); | 28 | res.send(result); |
@@ -142,9 +96,25 @@ exports.changeProductNum = (req, res) => { | @@ -142,9 +96,25 @@ exports.changeProductNum = (req, res) => { | ||
142 | 96 | ||
143 | // 删除商品 | 97 | // 删除商品 |
144 | exports.removeProduct = (req, res) => { | 98 | exports.removeProduct = (req, res) => { |
145 | - // TODO | ||
146 | - res.json({ | ||
147 | - code: '0' | 99 | + const params = {}; |
100 | + const uid = req.cookies.uid; | ||
101 | + const shoppingKey = req.cookies._SPK; | ||
102 | + const productSkuList = req.body.skuList; | ||
103 | + | ||
104 | + if (uid) { | ||
105 | + _.merge(params, {uid}); | ||
106 | + } | ||
107 | + | ||
108 | + if (shoppingKey) { | ||
109 | + _.merge(params, {shopping_key: shoppingKey}); | ||
110 | + } | ||
111 | + | ||
112 | + if (productSkuList) { | ||
113 | + _.merge(params, {product_sku_list: productSkuList}); | ||
114 | + } | ||
115 | + | ||
116 | + cartModel.removeGoods(params).then(result => { | ||
117 | + res.send(result); | ||
148 | }); | 118 | }); |
149 | }; | 119 | }; |
150 | 120 | ||
@@ -190,3 +160,35 @@ exports.addToCart = (req, res) => { | @@ -190,3 +160,35 @@ exports.addToCart = (req, res) => { | ||
190 | res.json(result); | 160 | res.json(result); |
191 | }); | 161 | }); |
192 | }; | 162 | }; |
163 | + | ||
164 | +// 购物车商品选择与取消选择 | ||
165 | +exports.toggleSelectGoods = (req, res) => { | ||
166 | + const params = {}; | ||
167 | + const uid = req.cookies.uid; | ||
168 | + const shoppingKey = req.cookies._SPK; | ||
169 | + | ||
170 | + // 商品sku列表 | ||
171 | + // skuList: | ||
172 | + // [{"goods_type":"advance","buy_number":1,"selected":"Y","product_sku":"1006277","promotion_id":0}, {...}] | ||
173 | + // [{"goods_type":"ordinary","buy_number":1,"selected":"Y","product_sku":"1006277","promotion_id":0}, {...}] | ||
174 | + const productSkuList = req.body.skuList; | ||
175 | + | ||
176 | + if (uid) { | ||
177 | + _.merge(params, {uid}); | ||
178 | + } | ||
179 | + | ||
180 | + if (shoppingKey) { | ||
181 | + _.merge(params, {shopping_key: shoppingKey}); | ||
182 | + } | ||
183 | + | ||
184 | + if (productSkuList) { | ||
185 | + _.merge(params, {product_sku_list: productSkuList}); | ||
186 | + } | ||
187 | + | ||
188 | + cartModel.toggleSelectGoods(params).then(result => { | ||
189 | + res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code})); | ||
190 | + }); | ||
191 | +}; | ||
192 | + | ||
193 | + | ||
194 | + |
@@ -5,267 +5,10 @@ | @@ -5,267 +5,10 @@ | ||
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | 7 | ||
8 | -var Promise = require('bluebird'); | ||
9 | var _ = require('lodash'); | 8 | var _ = require('lodash'); |
10 | 9 | ||
11 | const api = global.yoho.API; | 10 | const api = global.yoho.API; |
12 | 11 | ||
13 | -// const ServiceAPI = require(`${global.library}/api`).ServiceAPI; | ||
14 | -// const sign = require(`${global.library}/sign`); | ||
15 | -// const logger = require(`${global.library}/logger`); | ||
16 | -// const headerModel = require('../../../doraemon/models/header'); | ||
17 | - | ||
18 | -// var api = new ServiceAPI(); | ||
19 | - | ||
20 | -// 获取预售商品 | ||
21 | -const getPreSaleProducts = () => { | ||
22 | - return Promise.resolve({ | ||
23 | - preSalePros: [{ | ||
24 | - gender: '1', | ||
25 | - tags: '[Object]', | ||
26 | - status: 1, | ||
27 | - smallSortId: 115, | ||
28 | - vip1Price: 379.04999999999995, | ||
29 | - isGlobal: 'N', | ||
30 | - vip3Price: 351.12, | ||
31 | - isOutlets: 2, | ||
32 | - isDiscount: 'Y', | ||
33 | - brandDomain: 'allenove', | ||
34 | - isSpecial: 'N', | ||
35 | - goodsList: '[Object]', | ||
36 | - isAdvance: 'N', | ||
37 | - productId: 286135, | ||
38 | - vipDiscountType: 1, | ||
39 | - salesNum: 0, | ||
40 | - cnAlphabet: 'ALLENOVE95S11GeBenHaGen', | ||
41 | - productSkn: 51160998, | ||
42 | - shelveTime: 1455616165, | ||
43 | - vip2Price: 359.1, | ||
44 | - editTime: 1455616165, | ||
45 | - isNew: 'N', | ||
46 | - isLimited: 'N', | ||
47 | - brandName: 'Alle nove', | ||
48 | - maxSortId: 1, | ||
49 | - productName: 'Alle nove 小方领长袖衬衫【哥本哈根】', | ||
50 | - brandId: 1007, | ||
51 | - defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
52 | - stockNumber: 29, | ||
53 | - storageNum: 29, | ||
54 | - isSoonSoldOut: false, | ||
55 | - middleSortId: 12, | ||
56 | - salesPrice: 399, | ||
57 | - isPromotion: 101, | ||
58 | - marketPrice: 1299, | ||
59 | - vipPrice: 0, | ||
60 | - id: 51160998, | ||
61 | - thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
62 | - url: 'http://www.yohobuy.com/product/pro_286135_367985/ALLENOVE95S11GeBenHaGen.html', | ||
63 | - brandUrl: '//allenove.yohobuy.com', | ||
64 | - orderNum: 1, // 购买数量 | ||
65 | - numIsValid: true, // 库存是否正常 | ||
66 | - isValid: true // 是否没有实效 | ||
67 | - }] | ||
68 | - }); | ||
69 | -}; | ||
70 | - | ||
71 | -// 获取普通商品 | ||
72 | -const getNormalProducts = () => { | ||
73 | - return Promise.resolve({ | ||
74 | - commonPros: [{ gender: '1', | ||
75 | - tags: '[Object]', | ||
76 | - status: 1, | ||
77 | - smallSortId: 115, | ||
78 | - vip1Price: 284.05, | ||
79 | - isGlobal: 'N', | ||
80 | - vip3Price: 263.12, | ||
81 | - isOutlets: 2, | ||
82 | - isDiscount: 'Y', | ||
83 | - brandDomain: 'allenove', | ||
84 | - isSpecial: 'N', | ||
85 | - goodsList: [Object], | ||
86 | - isAdvance: 'N', | ||
87 | - productId: 286141, | ||
88 | - vipDiscountType: 1, | ||
89 | - salesNum: 0, | ||
90 | - cnAlphabet: 'ALLENOVE95S14WeiYeNa', | ||
91 | - productSkn: 51161001, | ||
92 | - shelveTime: 1455616165, | ||
93 | - vip2Price: 269.1, | ||
94 | - editTime: 1455616165, | ||
95 | - isNew: 'N', | ||
96 | - isLimited: 'N', | ||
97 | - brandName: 'Alle nove', | ||
98 | - maxSortId: 1, | ||
99 | - productName: 'Alle nove 翼型领长袖衬衫【维也纳】', | ||
100 | - brandId: 1007, | ||
101 | - defaultImages: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
102 | - stockNumber: 21, | ||
103 | - storageNum: 21, | ||
104 | - isSoonSoldOut: false, | ||
105 | - middleSortId: 12, | ||
106 | - salesPrice: 299, | ||
107 | - isPromotion: 101, | ||
108 | - marketPrice: 1299, | ||
109 | - vipPrice: 0, | ||
110 | - id: 51161001, | ||
111 | - thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
112 | - url: 'http://www.yohobuy.com/product/pro_286141_367991/ALLENOVE95S14WeiYeNa.html', | ||
113 | - brandUrl: '//allenove.yohobuy.com', | ||
114 | - orderNum: 2, // 购买数量 | ||
115 | - numIsValid: true, // 库存是否正常 | ||
116 | - isValid: true, // 是否没有实效 | ||
117 | - selectColor: '蓝', | ||
118 | - selectSize: 'M' | ||
119 | - }, { gender: '1', | ||
120 | - tags: '[Object]', | ||
121 | - status: 1, | ||
122 | - smallSortId: 115, | ||
123 | - vip1Price: 379.04999999999995, | ||
124 | - isGlobal: 'N', | ||
125 | - vip3Price: 351.12, | ||
126 | - isOutlets: 2, | ||
127 | - isDiscount: 'Y', | ||
128 | - brandDomain: 'allenove', | ||
129 | - isSpecial: 'N', | ||
130 | - goodsList: '[Object]', | ||
131 | - isAdvance: 'N', | ||
132 | - productId: 286143, | ||
133 | - vipDiscountType: 1, | ||
134 | - salesNum: 0, | ||
135 | - cnAlphabet: 'ALLENOVE95S20BaSaiLuoNa', | ||
136 | - productSkn: 51161002, | ||
137 | - shelveTime: 1455616165, | ||
138 | - vip2Price: 359.1, | ||
139 | - editTime: 1455616165, | ||
140 | - isNew: 'N', | ||
141 | - isLimited: 'N', | ||
142 | - brandName: 'Foobar', | ||
143 | - maxSortId: 1, | ||
144 | - productName: 'Foobar 纽扣领绅士长袖衬衫【巴塞罗那】', | ||
145 | - brandId: 1007, | ||
146 | - defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
147 | - stockNumber: 25, | ||
148 | - storageNum: 25, | ||
149 | - isSoonSoldOut: false, | ||
150 | - middleSortId: 12, | ||
151 | - salesPrice: 399, | ||
152 | - isPromotion: 101, | ||
153 | - marketPrice: 1299, | ||
154 | - vipPrice: 0, | ||
155 | - id: 51161002, | ||
156 | - thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
157 | - url: 'http://www.yohobuy.com/product/pro_286143_367993/ALLENOVE95S20BaSaiLuoNa.html', | ||
158 | - brandUrl: '//allenove.yohobuy.com', | ||
159 | - orderNum: 1, // 购买数量 | ||
160 | - numIsValid: false, // 库存是否正常 | ||
161 | - isValid: true // 是否没有实效 | ||
162 | - }, | ||
163 | - { gender: '1', | ||
164 | - tags: [Object], | ||
165 | - status: 1, | ||
166 | - smallSortId: 115, | ||
167 | - vip1Price: 379.04999999999995, | ||
168 | - isGlobal: 'N', | ||
169 | - vip3Price: 351.12, | ||
170 | - isOutlets: 2, | ||
171 | - isDiscount: 'Y', | ||
172 | - brandDomain: 'allenove', | ||
173 | - isSpecial: 'N', | ||
174 | - goodsList: [Object], | ||
175 | - isAdvance: 'N', | ||
176 | - productId: 286169, | ||
177 | - vipDiscountType: 1, | ||
178 | - salesNum: 0, | ||
179 | - cnAlphabet: 'ALLENOVE95S09BiSa', | ||
180 | - productSkn: 51161015, | ||
181 | - shelveTime: 1455616145, | ||
182 | - vip2Price: 359.1, | ||
183 | - editTime: 1455616145, | ||
184 | - isNew: 'N', | ||
185 | - isLimited: 'N', | ||
186 | - brandName: 'Alle nove', | ||
187 | - maxSortId: 1, | ||
188 | - productName: 'Alle nove 高支牛津休闲长袖衬衫【比萨】', | ||
189 | - brandId: 1007, | ||
190 | - defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
191 | - stockNumber: 27, | ||
192 | - storageNum: 27, | ||
193 | - isSoonSoldOut: false, | ||
194 | - middleSortId: 12, | ||
195 | - salesPrice: 399, | ||
196 | - isPromotion: 101, | ||
197 | - marketPrice: 1299, | ||
198 | - vipPrice: 0, | ||
199 | - id: 51161015, | ||
200 | - thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
201 | - url: 'http://www.yohobuy.com/product/pro_286169_368019/ALLENOVE95S09BiSa.html', | ||
202 | - brandUrl: '//allenove.yohobuy.com', | ||
203 | - orderNum: 2, // 购买数量 | ||
204 | - numIsValid: true, // 库存是否正常 | ||
205 | - isValid: true // 是否没有实效 | ||
206 | - }] | ||
207 | - }); | ||
208 | -}; | ||
209 | - | ||
210 | -// 获取失效商品 | ||
211 | -const getInvalidProducts = () => { | ||
212 | - return Promise.resolve({ | ||
213 | - invalidPros: [{ gender: '1', | ||
214 | - tags: ['Object'], | ||
215 | - status: 1, | ||
216 | - smallSortId: 115, | ||
217 | - vip1Price: 379.04999999999995, | ||
218 | - isGlobal: 'N', | ||
219 | - vip3Price: 351.12, | ||
220 | - isOutlets: 2, | ||
221 | - isDiscount: 'Y', | ||
222 | - brandDomain: 'allenove', | ||
223 | - isSpecial: 'N', | ||
224 | - goodsList: ['Object'], | ||
225 | - isAdvance: 'N', | ||
226 | - productId: 286139, | ||
227 | - vipDiscountType: 1, | ||
228 | - salesNum: 0, | ||
229 | - cnAlphabet: 'ALLENOVE95S13PuLuoWangSi', | ||
230 | - productSkn: 51161000, | ||
231 | - shelveTime: 1455616165, | ||
232 | - vip2Price: 359.1, | ||
233 | - editTime: 1455616165, | ||
234 | - isNew: 'N', | ||
235 | - isLimited: 'N', | ||
236 | - brandName: 'Alle nove', | ||
237 | - maxSortId: 1, | ||
238 | - productName: 'Alle nove 复古圆领长袖衬衫【普罗旺斯】', | ||
239 | - brandId: 1007, | ||
240 | - defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
241 | - stockNumber: 12, | ||
242 | - storageNum: 12, | ||
243 | - isSoonSoldOut: false, | ||
244 | - middleSortId: 12, | ||
245 | - salesPrice: 399, | ||
246 | - isPromotion: 101, | ||
247 | - marketPrice: 1299, | ||
248 | - vipPrice: 0, | ||
249 | - id: 51161000, | ||
250 | - thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80', | ||
251 | - url: 'http://www.yohobuy.com/product/pro_286139_367989/ALLENOVE95S13PuLuoWangSi.html', | ||
252 | - brandUrl: '//allenove.yohobuy.com', | ||
253 | - orderNum: 1, // 购买数量 | ||
254 | - numIsValid: true, // 库存是否正常 | ||
255 | - isValid: false // 是否没有实效 | ||
256 | - }] | ||
257 | - }); | ||
258 | -}; | ||
259 | - | ||
260 | -// 获取购物车信息 | ||
261 | -const getCartInfo = () => { | ||
262 | - return Promise.all([ | ||
263 | - getPreSaleProducts(), | ||
264 | - getNormalProducts(), | ||
265 | - getInvalidProducts() | ||
266 | - ]); | ||
267 | -}; | ||
268 | - | ||
269 | /* | 12 | /* |
270 | * 加入购物车 | 13 | * 加入购物车 |
271 | * @function addToCart | 14 | * @function addToCart |
@@ -382,9 +125,143 @@ const transferToFavorite = (uid, sku, hasPromotion) => { | @@ -382,9 +125,143 @@ const transferToFavorite = (uid, sku, hasPromotion) => { | ||
382 | return api.get('', params); | 125 | return api.get('', params); |
383 | }; | 126 | }; |
384 | 127 | ||
128 | +/* | ||
129 | + * 商品选择与取消选择 | ||
130 | + * @function toggleSelectGoods | ||
131 | + * @param { Number } uid 用户UID | ||
132 | + * @param { String } sku 商品sku列表 | ||
133 | + * @param { String } shoppingKey 未登录用户唯一识别码,可以不传 | ||
134 | + * @return { Array } | ||
135 | + */ | ||
136 | +const toggleSelectGoods = (params) => { | ||
137 | + // BLK 没有促销, 新接口 | ||
138 | + let method = 'app.Shopping.selectedAndCart'; | ||
139 | + | ||
140 | + _.merge(params, {method}); | ||
141 | + return api.get('', params); | ||
142 | +}; | ||
143 | + | ||
144 | +/* | ||
145 | + * 商品选择与取消选择 | ||
146 | + * @function toggleSelectGoods | ||
147 | + * @param { Number } uid 用户UID | ||
148 | + * @param { String } sku 商品sku列表 | ||
149 | + * @param { String } shoppingKey 未登录用户唯一识别码,可以不传 | ||
150 | + * @return { Array } | ||
151 | + */ | ||
152 | +const removeGoods = (params) => { | ||
153 | + // BLK 没有促销, 新接口 | ||
154 | + let method = 'app.Shopping.removeAndCart'; | ||
155 | + | ||
156 | + _.merge(params, {method}); | ||
157 | + return api.get('', params); | ||
158 | +}; | ||
159 | + | ||
160 | +/* | ||
161 | + * 每次操作处理购物车数据 | ||
162 | + * @function toggleSelectGoods | ||
163 | + * @param { Object } result 购物车数据 | ||
164 | + * { | ||
165 | + * advance_cart_data: { // 预售商品 | ||
166 | + * gift_list: [], // 赠品 | ||
167 | + * goods_list: [] // 商品列表 | ||
168 | + * off_shelves_goods_list: [], // 下架商品, 失效商品 | ||
169 | + * price_gift: [], // 加价购商品 | ||
170 | + * promotion_info: [], // 促销信息 | ||
171 | + * shopping_cart_data: [], // 商品价格计算相关信息 | ||
172 | + * sold_out_goods_list: [] // 售罄商品 | ||
173 | + * }, | ||
174 | + * ordinary_cart_data: { // 普通商品 | ||
175 | + * gift_list: [], | ||
176 | + * goods_list: [], | ||
177 | + * off_shelves_goods_list: [], | ||
178 | + * price_gift: [], | ||
179 | + * promotion_info: [], | ||
180 | + * shopping_cart_data: [], | ||
181 | + * sold_out_goods_list: [] | ||
182 | + * }, | ||
183 | + * md5: '...', | ||
184 | + * message: '...' | ||
185 | + * } | ||
186 | + */ | ||
187 | +const filterCartData = (result, uid) => { | ||
188 | + // 预售商品 | ||
189 | + let advancedGoods = [], | ||
190 | + selectedAdvanceNum = 0, | ||
191 | + advancedCartData; | ||
192 | + | ||
193 | + // 普通商品 | ||
194 | + let ordinaryGoods = [], | ||
195 | + selectedOrdinaryNum = 0, | ||
196 | + ordinaryCartData; | ||
197 | + | ||
198 | + // skn=0或者已下架的商品,定义为失效商品 | ||
199 | + let invalidGoods = []; | ||
200 | + | ||
201 | + // 库存不足商品 | ||
202 | + let soldOutGoods = []; | ||
203 | + | ||
204 | + // 商品总数量 | ||
205 | + let buyNumber; | ||
206 | + let totalNum = 0; | ||
207 | + | ||
208 | + // 返回值 | ||
209 | + let resData = { | ||
210 | + loggedIn: uid | ||
211 | + }; | ||
212 | + | ||
213 | + if (result.data && result.data.advance_cart_data) { | ||
214 | + // 预售商品 | ||
215 | + advancedCartData = result.data.advance_cart_data; | ||
216 | + console.log('---------------advance------:', advancedCartData.goods_list.length); | ||
217 | + advancedGoods = _.concat(advancedGoods, advancedCartData.goods_list); | ||
218 | + invalidGoods = _.concat(invalidGoods, advancedCartData.off_shelves_goods_list); | ||
219 | + soldOutGoods = _.concat(soldOutGoods, advancedCartData.sold_out_goods_list); | ||
220 | + | ||
221 | + _.forEach(advancedGoods, function(good){ | ||
222 | + buyNumber = parseInt(good.buy_number, 10); | ||
223 | + totalNum += buyNumber; | ||
224 | + if (good.selected === 'Y') { | ||
225 | + selectedAdvanceNum += buyNumber; | ||
226 | + } | ||
227 | + }); | ||
228 | + } | ||
229 | + | ||
230 | + if (result.data && result.data.ordinary_cart_data) { | ||
231 | + // 普通商品 | ||
232 | + ordinaryCartData = result.data.ordinary_cart_data; | ||
233 | + console.log('---------------ordinary------:', ordinaryCartData.goods_list.length); | ||
234 | + ordinaryGoods = _.concat(ordinaryGoods, ordinaryCartData.goods_list); | ||
235 | + invalidGoods = _.concat(invalidGoods, ordinaryCartData.off_shelves_goods_list); | ||
236 | + soldOutGoods = _.concat(soldOutGoods, ordinaryCartData.sold_out_goods_list); | ||
237 | + | ||
238 | + _.forEach(ordinaryGoods, function(good){ | ||
239 | + buyNumber = parseInt(good.buy_number, 10); | ||
240 | + totalNum += buyNumber; | ||
241 | + if (good.selected === 'Y') { | ||
242 | + selectedOrdinaryNum += buyNumber; | ||
243 | + } | ||
244 | + }); | ||
245 | + } | ||
246 | + | ||
247 | + // console.log('ordinaryGoods:', ordinaryGoods); | ||
248 | + | ||
249 | + | ||
250 | + return _.merge(resData, { | ||
251 | + hasGoods: advancedGoods.length || ordinaryGoods.length || invalidGoods.length, | ||
252 | + preSalePros: advancedGoods.length ? _.groupBy(advancedGoods, 'brand_id') : [], | ||
253 | + commonPros: ordinaryGoods.length ? _.groupBy(ordinaryGoods, 'brand_id') : [], | ||
254 | + invalidPros: invalidGoods, | ||
255 | + selectedNum: selectedAdvanceNum + selectedOrdinaryNum, | ||
256 | + checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum) | ||
257 | + }); | ||
258 | +}; | ||
259 | + | ||
385 | module.exports = { | 260 | module.exports = { |
386 | addToCart, | 261 | addToCart, |
387 | getCartData, | 262 | getCartData, |
388 | - getCartInfo, | ||
389 | - transferToFavorite | 263 | + transferToFavorite, |
264 | + toggleSelectGoods, | ||
265 | + removeGoods, | ||
266 | + filterCartData | ||
390 | }; | 267 | }; |
@@ -20,6 +20,7 @@ router.delete('/cart/product/:productId', cartCtrl.removeProduct); | @@ -20,6 +20,7 @@ router.delete('/cart/product/:productId', cartCtrl.removeProduct); | ||
20 | router.post('/cart/product/:productId/send_to_favorite', cartCtrl.sendToFavorite); | 20 | router.post('/cart/product/:productId/send_to_favorite', cartCtrl.sendToFavorite); |
21 | router.get('/cart/product/:productId/edit', cartCtrl.editProduct); | 21 | router.get('/cart/product/:productId/edit', cartCtrl.editProduct); |
22 | router.post('/cart/add', cartCtrl.addToCart); | 22 | router.post('/cart/add', cartCtrl.addToCart); |
23 | +router.post('/cart/toggleSelectGoods', cartCtrl.toggleSelectGoods); | ||
23 | 24 | ||
24 | // 结算 | 25 | // 结算 |
25 | router.get('/order', order.index); | 26 | router.get('/order', order.index); |
1 | -{{> common/cart-list-header}} | ||
2 | -{{> common/cart-list-body}} | ||
3 | -{{> common/statement}} | ||
1 | +<div id="cart_content"> | ||
2 | + {{> common/cart-list-header}} | ||
3 | + {{> common/cart-list-body}} | ||
4 | + {{> common/statement}} | ||
5 | +</div> | ||
6 | + | ||
7 | +<script id="cart-content-tpl" type="text/html"> | ||
8 | + <div class="cart-header"> | ||
9 | + <div class="titles"> | ||
10 | + <div class="item"> | ||
11 | + <label id="toggle_check" class="toggle-chk chk-all \{{#if checkAll}}chk-group\{{/if}}"> | ||
12 | + <span class="iconfont checkbox not-checked"></span> | ||
13 | + <span class="iconfont checkbox checked"></span> | ||
14 | + 全选 | ||
15 | + </label> | ||
16 | + </div> | ||
17 | + <div class="item product">货品</div> | ||
18 | + <div class="item price">价格</div> | ||
19 | + <div class="item num">数量</div> | ||
20 | + <div class="item pro-total-price">总价</div> | ||
21 | + <div class="item actions">操作</div> | ||
22 | + </div> | ||
23 | + </div> | ||
24 | + \{{# if preSalePros}} | ||
25 | + <div class="cart-pro-list pre-pros"> | ||
26 | + <div class="title"> | ||
27 | + <span class="main">预售商品</span> | ||
28 | + <span class="note">不同上市期的商品我们将为您先到先发</span> | ||
29 | + </div> | ||
30 | + <div class="pro-list"> | ||
31 | + \{{#each preSalePros}} | ||
32 | + <div class="pros-group"> | ||
33 | + \{{# each this}} | ||
34 | + <ul> | ||
35 | + <li class="chk" data-product_info='{"goods_type": "advance", "buy_number": \{{buy_number}}, "selected": "\{{selected}}", "product_sku": "\{{product_sku}}", "promotion_id": 0}'> | ||
36 | + <label class="toggle-chk-item \{{#isEqual selected 'Y'}}chk-group\{{/isEqual}}"> | ||
37 | + <span class="iconfont checkbox not-checked"></span> | ||
38 | + <span class="iconfont checkbox checked"></span> | ||
39 | + </label> | ||
40 | + <input type="hidden" name="product_ids[]"/> | ||
41 | + </li> | ||
42 | + <li> | ||
43 | + <img src="\{{image goods_images 100 134}}" alt="\{{product_name}}"> | ||
44 | + </li> | ||
45 | + <li class="pro-info"> | ||
46 | + \{{!-- <div class="brand-name">\{{brand_name}}</div> --}} | ||
47 | + <div class="pro-name">\{{product_name}}</div> | ||
48 | + <div class="size"> | ||
49 | + \{{#if size_name}} | ||
50 | + <span>尺寸: \{{size_name}}</span> | ||
51 | + \{{/if}} | ||
52 | + </div> | ||
53 | + \{{#expect_arrival_time}} | ||
54 | + <div class="published-at">上市期: \{{expect_arrival_time}}</div> | ||
55 | + \{{/expect_arrival_time}} | ||
56 | + </li> | ||
57 | + <li class="price-num"> | ||
58 | + <span class="price sale-price">¥\{{sales_price}}</span> | ||
59 | + <div class="stepper" data-productId=\{{productId}}> | ||
60 | + <div class="minus action"> | ||
61 | + <span class="iconfont"></span> | ||
62 | + </div> | ||
63 | + <div class="num"> | ||
64 | + <input type="text" class="input" value=\{{buy_number}} /> | ||
65 | + </div> | ||
66 | + <div class="plus action"> | ||
67 | + <span class="iconfont"></span> | ||
68 | + </div> | ||
69 | + </div> | ||
70 | + </li> | ||
71 | + <li class="total-price-action"> | ||
72 | + <span class="price item-total-price">¥\{{multiple sales_price buy_number}}</span> | ||
73 | + <div class="actions"> | ||
74 | + <div class="remove-item action" data-product_id=\{{product_id}}><span class="iconfont"></span> 删 除</div> | ||
75 | + <div class="send-to-favorite action" data-product_id=\{{product_id}}>移入收藏夹</div> | ||
76 | + </div> | ||
77 | + </li> | ||
78 | + </ul> | ||
79 | + \{{/each}} | ||
80 | + </div> | ||
81 | + \{{/each}} | ||
82 | + </div> | ||
83 | + </div> | ||
84 | + \{{/ if}} | ||
85 | + | ||
86 | + \{{# if commonPros }} | ||
87 | + <div class="cart-pro-list common-pros"> | ||
88 | + <div class="title"> | ||
89 | + <span class="main">普通商品</span> | ||
90 | + </div> | ||
91 | + <div class="pro-list"> | ||
92 | + \{{#each commonPros}} | ||
93 | + <div class="pros-group"> | ||
94 | + \{{# each this}} | ||
95 | + <ul> | ||
96 | + <li class="chk" data-product_info='{"goods_type": "ordinary", "buy_number": \{{buy_number}}, "selected": "\{{selected}}", "product_sku": "\{{product_sku}}", "promotion_id": 0}'> | ||
97 | + <label class="toggle-chk-item \{{#isEqual selected 'Y'}}chk-group\{{/isEqual}}"> | ||
98 | + <span class="iconfont checkbox not-checked"></span> | ||
99 | + <span class="iconfont checkbox checked"></span> | ||
100 | + </label> | ||
101 | + <input type="hidden" name="product_ids[]"/> | ||
102 | + </li> | ||
103 | + <li> | ||
104 | + <img src="\{{image goods_images 100 134}}" alt="\{{product_name}}"> | ||
105 | + </li> | ||
106 | + <li class="pro-info"> | ||
107 | + \{{!-- <div class="brand-name">\{{brandName}}</div> --}} | ||
108 | + <div class="pro-name">\{{product_name}}</div> | ||
109 | + <div class="color-size editable" data-product_id=\{{product_id}} id="edit_\{{product_id}}"> | ||
110 | + \{{#if color_name}} | ||
111 | + <span class="mr20">颜色: \{{color_name}}</span> | ||
112 | + \{{/if}} | ||
113 | + \{{#if size_name}} | ||
114 | + <span>尺寸: \{{size_name}}</span> | ||
115 | + \{{/if}} | ||
116 | + <span class="iconfont"></span> | ||
117 | + </div> | ||
118 | + </li> | ||
119 | + <li class="price-num"> | ||
120 | + <span class="price sale-price">¥\{{sales_price}}</span> | ||
121 | + <div class="stepper" data-productId=\{{productId}}> | ||
122 | + <div class="minus action"> | ||
123 | + <span class="iconfont"></span> | ||
124 | + </div> | ||
125 | + <div class="num"> | ||
126 | + <input type="text" class="input" value=\{{buy_number}} /> | ||
127 | + </div> | ||
128 | + <div class="plus action"> | ||
129 | + <span class="iconfont"></span> | ||
130 | + </div> | ||
131 | + </div> | ||
132 | + </li> | ||
133 | + <li class="total-price-action"> | ||
134 | + <span class="price item-total-price">¥\{{multiple sales_price buy_number}}</span> | ||
135 | + <div class="actions"> | ||
136 | + <div class="remove-item action" data-product_id=\{{product_id}}><span class="iconfont"></span> 删 除</div> | ||
137 | + <div class="send-to-favorite action" data-product_id=\{{product_id}}>移入收藏夹</div> | ||
138 | + </div> | ||
139 | + </li> | ||
140 | + </ul> | ||
141 | + \{{/each}} | ||
142 | + </div> | ||
143 | + \{{/each}} | ||
144 | + </div> | ||
145 | + </div> | ||
146 | + \{{/ if}} | ||
147 | + | ||
148 | + \{{# if invalidPros}} | ||
149 | + <div class="cart-pro-list invalid-pros"> | ||
150 | + <div class="pro-list"> | ||
151 | + \{{#each invalidPros}} | ||
152 | + <ul> | ||
153 | + <li class="chk"> | ||
154 | + <span class="iconfont warning"></span> | ||
155 | + </li> | ||
156 | + <li> | ||
157 | + <img src="\{{image defaultImages 100 134}}" alt="\{{productName}}"> | ||
158 | + </li> | ||
159 | + <li class="pro-info"> | ||
160 | + <div class="brand-name">\{{brandName}}</div> | ||
161 | + <div class="pro-name">\{{productName}}</div> | ||
162 | + <div class="size">尺寸: USB</div> | ||
163 | + <div class="published-at">上市期: 2016年8月</div> | ||
164 | + </li> | ||
165 | + <li class="price-num"> | ||
166 | + <span class="price sale-price">¥\{{salesPrice}}</span> | ||
167 | + <div class="stepper" data-productId=\{{productId}}> | ||
168 | + <div class="minus action"> | ||
169 | + <span class="iconfont"></span> | ||
170 | + </div> | ||
171 | + <div class="num"> | ||
172 | + <input type="text" class="input" value=\{{buy_number}} /> | ||
173 | + </div> | ||
174 | + <div class="plus action"> | ||
175 | + <span class="iconfont"></span> | ||
176 | + </div> | ||
177 | + </div> | ||
178 | + </li> | ||
179 | + <li class="total-price-action"> | ||
180 | + <span class="price item-total-price">¥1289.00</span> | ||
181 | + <div class="actions"> | ||
182 | + <div class="remove-item action" data-product_id=\{{product_id}}><span class="iconfont"></span> 删 除</div> | ||
183 | + <div class="send-to-favorite action" data-product_id=\{{product_id}}>移入收藏夹</div> | ||
184 | + </div> | ||
185 | + </li> | ||
186 | + </ul> | ||
187 | + \{{/each}} | ||
188 | + </div> | ||
189 | + </div> | ||
190 | + \{{/ if}} | ||
191 | + | ||
192 | + <div class="cart-statement"> | ||
193 | + <div class="actions"> | ||
194 | + <div class="action"> | ||
195 | + <label id="toggle_check" class="toggle-chk chk-all \{{#if checkAll}}chk-group\{{/if}}"> | ||
196 | + <span class="iconfont checkbox not-checked"></span> | ||
197 | + <span class="iconfont checkbox checked"></span> | ||
198 | + <span>全选</span> | ||
199 | + </label> | ||
200 | + </div> | ||
201 | + <div id="remove_selected" class="action hoverable">删除选中的商品</div> | ||
202 | + <div id="send_favorite" class="action hoverable">移入收藏夹</div> | ||
203 | + <div id="clear_invalid" class="action hoverable">清除实效商品</div> | ||
204 | + <div class="selected-num">已选<span>\{{selectedNum}}</span>件</div> | ||
205 | + <div class="checkout-total"> | ||
206 | + <div class="total-title">商品金额:</div> | ||
207 | + <div class="total-money">¥<span>58999.00</span></div> | ||
208 | + </div> | ||
209 | + </div> | ||
210 | + <div class="calculate"> | ||
211 | + <div class="checkout-total pay-total"> | ||
212 | + <div class="pay-title">应付金额(不含运费):</div> | ||
213 | + <div class="total-money">¥<span>58999.00</span></div> | ||
214 | + </div> | ||
215 | + </div> | ||
216 | + <div class="checkout"> | ||
217 | + <a href="/" class="go-to-checkout"> | ||
218 | + <span class="btn disable" id="checkout_btn">去结算</span> | ||
219 | + </a> | ||
220 | + </div> | ||
221 | + </div> | ||
222 | +</script> |
@@ -9,12 +9,12 @@ | @@ -9,12 +9,12 @@ | ||
9 | <div class="pros-group"> | 9 | <div class="pros-group"> |
10 | {{# each this}} | 10 | {{# each this}} |
11 | <ul> | 11 | <ul> |
12 | - <li class="chk" data-productId={{productId}}> | ||
13 | - <label class="toggle-chk-item {{#if numIsValid}}chk-group{{/if}}"> | 12 | + <li class="chk" data-product_info='{"goods_type": "advance", "buy_number": {{buy_number}}, "selected": "{{selected}}", "product_sku": "{{product_sku}}", "promotion_id": 0}'> |
13 | + <label class="toggle-chk-item {{#isEqual selected 'Y'}}chk-group{{/isEqual}}"> | ||
14 | <span class="iconfont checkbox not-checked"></span> | 14 | <span class="iconfont checkbox not-checked"></span> |
15 | <span class="iconfont checkbox checked"></span> | 15 | <span class="iconfont checkbox checked"></span> |
16 | </label> | 16 | </label> |
17 | - <input type="hidden" name="productIds[]"/> | 17 | + <input type="hidden" name="product_ids[]"/> |
18 | </li> | 18 | </li> |
19 | <li> | 19 | <li> |
20 | <img src="{{image goods_images 100 134}}" alt="{{product_name}}"> | 20 | <img src="{{image goods_images 100 134}}" alt="{{product_name}}"> |
@@ -27,7 +27,9 @@ | @@ -27,7 +27,9 @@ | ||
27 | <span>尺寸: {{size_name}}</span> | 27 | <span>尺寸: {{size_name}}</span> |
28 | {{/if}} | 28 | {{/if}} |
29 | </div> | 29 | </div> |
30 | - <div class="published-at">上市期: 2016年8月1日</div> | 30 | + {{#expect_arrival_time}} |
31 | + <div class="published-at">上市期: {{expect_arrival_time}}</div> | ||
32 | + {{/expect_arrival_time}} | ||
31 | </li> | 33 | </li> |
32 | <li class="price-num"> | 34 | <li class="price-num"> |
33 | <span class="price sale-price">¥{{sales_price}}</span> | 35 | <span class="price sale-price">¥{{sales_price}}</span> |
@@ -36,8 +38,8 @@ | @@ -36,8 +38,8 @@ | ||
36 | <li class="total-price-action"> | 38 | <li class="total-price-action"> |
37 | <span class="price item-total-price">¥{{multiple sales_price buy_number}}</span> | 39 | <span class="price item-total-price">¥{{multiple sales_price buy_number}}</span> |
38 | <div class="actions"> | 40 | <div class="actions"> |
39 | - <div class="remove-item action" data-productId={{productId}}><span class="iconfont"></span> 删 除</div> | ||
40 | - <div class="send-to-favorite action" data-productId={{productId}}>移入收藏夹</div> | 41 | + <div class="remove-item action" data-product_id={{product_id}}><span class="iconfont"></span> 删 除</div> |
42 | + <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div> | ||
41 | </div> | 43 | </div> |
42 | </li> | 44 | </li> |
43 | </ul> | 45 | </ul> |
@@ -58,12 +60,12 @@ | @@ -58,12 +60,12 @@ | ||
58 | <div class="pros-group"> | 60 | <div class="pros-group"> |
59 | {{# each this}} | 61 | {{# each this}} |
60 | <ul> | 62 | <ul> |
61 | - <li class="chk" data-productId={{productId}}> | ||
62 | - <label class="toggle-chk-item {{#if numIsValid}}chk-group{{/if}}"> | 63 | + <li class="chk" data-product_info='{"goods_type": "ordinary", "buy_number": {{buy_number}}, "selected": "{{selected}}", "product_sku": "{{product_sku}}", "promotion_id": 0}'> |
64 | + <label class="toggle-chk-item {{#isEqual selected 'Y'}}chk-group{{/isEqual}}"> | ||
63 | <span class="iconfont checkbox not-checked"></span> | 65 | <span class="iconfont checkbox not-checked"></span> |
64 | <span class="iconfont checkbox checked"></span> | 66 | <span class="iconfont checkbox checked"></span> |
65 | </label> | 67 | </label> |
66 | - <input type="hidden" name="productIds[]"/> | 68 | + <input type="hidden" name="product_ids[]"/> |
67 | </li> | 69 | </li> |
68 | <li> | 70 | <li> |
69 | <img src="{{image goods_images 100 134}}" alt="{{product_name}}"> | 71 | <img src="{{image goods_images 100 134}}" alt="{{product_name}}"> |
@@ -71,7 +73,7 @@ | @@ -71,7 +73,7 @@ | ||
71 | <li class="pro-info"> | 73 | <li class="pro-info"> |
72 | {{!-- <div class="brand-name">{{brandName}}</div> --}} | 74 | {{!-- <div class="brand-name">{{brandName}}</div> --}} |
73 | <div class="pro-name">{{product_name}}</div> | 75 | <div class="pro-name">{{product_name}}</div> |
74 | - <div class="color-size editable" data-productId={{productId}} id="edit_{{productId}}"> | 76 | + <div class="color-size editable" data-product_id={{product_id}} id="edit_{{product_id}}"> |
75 | {{#if color_name}} | 77 | {{#if color_name}} |
76 | <span class="mr20">颜色: {{color_name}}</span> | 78 | <span class="mr20">颜色: {{color_name}}</span> |
77 | {{/if}} | 79 | {{/if}} |
@@ -88,8 +90,8 @@ | @@ -88,8 +90,8 @@ | ||
88 | <li class="total-price-action"> | 90 | <li class="total-price-action"> |
89 | <span class="price item-total-price">¥{{multiple sales_price buy_number}}</span> | 91 | <span class="price item-total-price">¥{{multiple sales_price buy_number}}</span> |
90 | <div class="actions"> | 92 | <div class="actions"> |
91 | - <div class="remove-item action" data-productId={{productId}}><span class="iconfont"></span> 删 除</div> | ||
92 | - <div class="send-to-favorite action" data-productId={{productId}}>移入收藏夹</div> | 93 | + <div class="remove-item action" data-product_id={{product_id}}><span class="iconfont"></span> 删 除</div> |
94 | + <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div> | ||
93 | </div> | 95 | </div> |
94 | </li> | 96 | </li> |
95 | </ul> | 97 | </ul> |
@@ -124,8 +126,8 @@ | @@ -124,8 +126,8 @@ | ||
124 | <li class="total-price-action"> | 126 | <li class="total-price-action"> |
125 | <span class="price item-total-price">¥1289.00</span> | 127 | <span class="price item-total-price">¥1289.00</span> |
126 | <div class="actions"> | 128 | <div class="actions"> |
127 | - <div class="remove-item action" data-productId={{productId}}><span class="iconfont"></span> 删 除</div> | ||
128 | - <div class="send-to-favorite action" data-productId={{productId}}>移入收藏夹</div> | 129 | + <div class="remove-item action" data-product_id={{product_id}}><span class="iconfont"></span> 删 除</div> |
130 | + <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div> | ||
129 | </div> | 131 | </div> |
130 | </li> | 132 | </li> |
131 | </ul> | 133 | </ul> |
1 | <div class="cart-header"> | 1 | <div class="cart-header"> |
2 | <div class="titles"> | 2 | <div class="titles"> |
3 | <div class="item"> | 3 | <div class="item"> |
4 | - <label id="toggle_check" class="toggle-chk chk-all chk-group"> | 4 | + <label id="toggle_check" class="toggle-chk chk-all {{#if checkAll}}chk-group{{/if}}"> |
5 | <span class="iconfont checkbox not-checked"></span> | 5 | <span class="iconfont checkbox not-checked"></span> |
6 | <span class="iconfont checkbox checked"></span> | 6 | <span class="iconfont checkbox checked"></span> |
7 | 全选 | 7 | 全选 |
1 | <div class="cart-statement"> | 1 | <div class="cart-statement"> |
2 | <div class="actions"> | 2 | <div class="actions"> |
3 | <div class="action"> | 3 | <div class="action"> |
4 | - <label id="toggle_check" class="toggle-chk chk-all chk-group"> | 4 | + <label id="toggle_check" class="toggle-chk chk-all {{#if checkAll}}chk-group{{/if}}"> |
5 | <span class="iconfont checkbox not-checked"></span> | 5 | <span class="iconfont checkbox not-checked"></span> |
6 | <span class="iconfont checkbox checked"></span> | 6 | <span class="iconfont checkbox checked"></span> |
7 | <span>全选</span> | 7 | <span>全选</span> |
@@ -10,10 +10,10 @@ | @@ -10,10 +10,10 @@ | ||
10 | <div id="remove_selected" class="action hoverable">删除选中的商品</div> | 10 | <div id="remove_selected" class="action hoverable">删除选中的商品</div> |
11 | <div id="send_favorite" class="action hoverable">移入收藏夹</div> | 11 | <div id="send_favorite" class="action hoverable">移入收藏夹</div> |
12 | <div id="clear_invalid" class="action hoverable">清除实效商品</div> | 12 | <div id="clear_invalid" class="action hoverable">清除实效商品</div> |
13 | - <div class="selected-num">已选<span>4</span>件</div> | 13 | + <div class="selected-num">已选<span>{{selectedNum}}</span>件</div> |
14 | <div class="checkout-total"> | 14 | <div class="checkout-total"> |
15 | <div class="total-title">商品金额:</div> | 15 | <div class="total-title">商品金额:</div> |
16 | - <div class="total-money">¥<span>58999.00</span></div> | 16 | + <div class="total-money">¥<span></span></div> |
17 | </div> | 17 | </div> |
18 | </div> | 18 | </div> |
19 | <div class="calculate"> | 19 | <div class="calculate"> |
@@ -104,6 +104,7 @@ | @@ -104,6 +104,7 @@ | ||
104 | "yoho-jquery-nanoscroller": "0.0.1", | 104 | "yoho-jquery-nanoscroller": "0.0.1", |
105 | "yoho-jquery-placeholder": "^2.3.1", | 105 | "yoho-jquery-placeholder": "^2.3.1", |
106 | "yoho-jquery-qrcode": "0.0.3", | 106 | "yoho-jquery-qrcode": "0.0.3", |
107 | + "yoho-json2": "^1.0.0", | ||
107 | "yoho-slider": "0.0.2" | 108 | "yoho-slider": "0.0.2" |
108 | } | 109 | } |
109 | } | 110 | } |
1 | var $ = require('yoho-jquery'); | 1 | var $ = require('yoho-jquery'); |
2 | -var Cart = require('./cart'); | ||
3 | -var Stepper = require('./stepper'); | 2 | +var Cart = require('./cart/cart'); |
3 | +var Stepper = require('./cart/stepper'); | ||
4 | 4 | ||
5 | $(function() { | 5 | $(function() { |
6 | 6 | ||
@@ -9,105 +9,54 @@ $(function() { | @@ -9,105 +9,54 @@ $(function() { | ||
9 | $('.info-bar').hide(); | 9 | $('.info-bar').hide(); |
10 | }); | 10 | }); |
11 | 11 | ||
12 | - // 全选和单选 | ||
13 | - $('.toggle-chk, .toggle-chk-item').on('click', function() { | ||
14 | - var $this = $(this), | ||
15 | - $checkoutBtn = $('#checkout_btn'), | ||
16 | - checkAll = $this.hasClass('chk-all'), | ||
17 | - checkProId = []; | ||
18 | - | ||
19 | - var data; | ||
20 | - | ||
21 | - if ($this.hasClass('chk-group')) { | ||
22 | - // 取消选择 | ||
23 | - $this.removeClass('chk-group'); | ||
24 | - $checkoutBtn.addClass('disable'); | ||
25 | - | ||
26 | - if (checkAll) { | ||
27 | - Cart.unCheckAllPros(); | ||
28 | - } else { | ||
29 | - Cart.resetCheckAllStyle(); | ||
30 | - $this.next().val(''); | ||
31 | - } | ||
32 | - } else { | ||
33 | - if (checkAll) { | ||
34 | - data = { productId: 'ALL' }; | ||
35 | - } else { | ||
36 | - checkProId = $this.parent().attr('data-productId'); | ||
37 | - data = { productId: checkProId}; | ||
38 | - } | ||
39 | - | ||
40 | - // 检查库存 | ||
41 | - $.ajax({ | ||
42 | - type: 'GET', | ||
43 | - url: '/shopping/cart/product/check_inventory', | ||
44 | - data: data, | ||
45 | - dataType: 'json' | ||
46 | - }).done(function(res) { | ||
47 | - if (res.valid) { | ||
48 | - $this.addClass('chk-group'); | ||
49 | - $checkoutBtn.removeClass('disable'); | ||
50 | - | ||
51 | - if (checkAll) { | ||
52 | - Cart.checkAllPros(res.invalidProIds); | ||
53 | - } else { | ||
54 | - $this.next().val(checkProId); | ||
55 | - | ||
56 | - // 判断是否需要全选 | ||
57 | - Cart.toggleCheckAll(); | ||
58 | - } | ||
59 | - } else { | ||
60 | - if (checkAll) { | ||
61 | - // 全选商品中存在库存不足 | ||
62 | - // 如果有有效商品 | ||
63 | - if ($('.toggle-chk-item').length) { | ||
64 | - $this.addClass('chk-group'); | ||
65 | - Cart.checkAllPros(res.invalidProIds); | ||
66 | - } | ||
67 | - Cart.toggleNotEnough($this, 'ALL'); | ||
68 | - } else { | ||
69 | - // 单选商品库存不足 | ||
70 | - Cart.toggleNotEnough($this); | ||
71 | - | ||
72 | - } | ||
73 | - } | ||
74 | - }).fail(function() { | ||
75 | - // 通用处理错误 | ||
76 | - // TODO | ||
77 | - }); | ||
78 | - | ||
79 | - } | 12 | + $('#cart_content').delegate('.toggle-chk, .toggle-chk-item', 'click', function() { |
13 | + // 全选和单选 | ||
14 | + Cart.toggleCheck.call(Cart, this); | ||
15 | + }).delegate('.remove-item', 'click', function() { | ||
16 | + // 删除商品 | ||
17 | + Cart.removePro($(this).attr('data-productId')); | ||
18 | + }).delegate('.send-to-favorite', 'click', function() { | ||
19 | + // 移入收藏夹 | ||
20 | + Cart.sendToFavorite($(this).attr('data-productId')); | ||
21 | + }).delegate('.editable', 'click', function() { | ||
22 | + // 编辑商品颜色和属性 | ||
23 | + Cart.editColorOrSize($(this).attr('data-productId')); | ||
80 | }); | 24 | }); |
81 | 25 | ||
26 | + // // 全选和单选 | ||
27 | + // $('.toggle-chk, .toggle-chk-item').on('click', function() { | ||
28 | + // Cart.toggleCheck.call(Cart, this); | ||
29 | + // }); | ||
30 | + | ||
82 | // 变动商品数量 | 31 | // 变动商品数量 |
83 | Stepper.init(); | 32 | Stepper.init(); |
84 | 33 | ||
85 | - // 删除商品 | ||
86 | - $('.remove-item').on('click', function() { | ||
87 | - Cart.removePro($(this).attr('data-productId')); | ||
88 | - }); | 34 | + // // 删除商品 |
35 | + // $('.remove-item').on('click', function() { | ||
36 | + // Cart.removePro($(this).attr('data-productId')); | ||
37 | + // }); | ||
89 | 38 | ||
90 | - // 移入收藏夹 | ||
91 | - $('.send-to-favorite').on('click', function() { | ||
92 | - Cart.sendToFavorite($(this).attr('data-productId')); | ||
93 | - }); | 39 | + // // 移入收藏夹 |
40 | + // $('.send-to-favorite').on('click', function() { | ||
41 | + // Cart.sendToFavorite($(this).attr('data-productId')); | ||
42 | + // }); | ||
94 | 43 | ||
95 | - // 编辑商品颜色和属性 | ||
96 | - $('.editable').on('click', function() { | ||
97 | - Cart.editColorOrSize($(this).attr('data-productId')); | ||
98 | - }); | 44 | + // // 编辑商品颜色和属性 |
45 | + // $('.editable').on('click', function() { | ||
46 | + // Cart.editColorOrSize($(this).attr('data-productId')); | ||
47 | + // }); | ||
99 | 48 | ||
100 | // TODO=> | 49 | // TODO=> |
101 | $('#add_to_cart1').on('click', function() { | 50 | $('#add_to_cart1').on('click', function() { |
102 | Cart.addToCart({ | 51 | Cart.addToCart({ |
103 | - productSku: '980874', | 52 | + productSku: '870896', |
104 | buyNumber: 1 | 53 | buyNumber: 1 |
105 | }); | 54 | }); |
106 | }); | 55 | }); |
107 | 56 | ||
108 | $('#add_to_cart2').on('click', function() { | 57 | $('#add_to_cart2').on('click', function() { |
109 | Cart.addToCart({ | 58 | Cart.addToCart({ |
110 | - productSku: '980870', | 59 | + productSku: '972201', |
111 | buyNumber: 2 | 60 | buyNumber: 2 |
112 | }); | 61 | }); |
113 | }); | 62 | }); |
@@ -5,12 +5,14 @@ | @@ -5,12 +5,14 @@ | ||
5 | * @module shopping/cart | 5 | * @module shopping/cart |
6 | */ | 6 | */ |
7 | 7 | ||
8 | -var Dialog = require('../plugins/dialog'); | 8 | +var Dialog = require('../../plugins/dialog'); |
9 | +var JSON = require('yoho-json2'); | ||
9 | var _confirm = Dialog.Confirm; | 10 | var _confirm = Dialog.Confirm; |
10 | var _alert = Dialog.Alert; | 11 | var _alert = Dialog.Alert; |
11 | var Util = require('./util'); | 12 | var Util = require('./util'); |
12 | var hbs = require('yoho-handlebars'); | 13 | var hbs = require('yoho-handlebars'); |
13 | -var common = require('../common'); | 14 | +var common = require('../../common'); |
15 | +var Stepper = require('./cart/stepper'); | ||
14 | 16 | ||
15 | var Cart = { | 17 | var Cart = { |
16 | /* | 18 | /* |
@@ -21,6 +23,8 @@ var Cart = { | @@ -21,6 +23,8 @@ var Cart = { | ||
21 | * @params { Function } callback 购买结果回调 | 23 | * @params { Function } callback 购买结果回调 |
22 | */ | 24 | */ |
23 | addToCart: function(params, callback) { | 25 | addToCart: function(params, callback) { |
26 | + // TODO | ||
27 | + common.setCookie('uid', '20000058'); | ||
24 | Util.ajax({ | 28 | Util.ajax({ |
25 | url: '/shopping/cart/add', | 29 | url: '/shopping/cart/add', |
26 | type: 'POST', | 30 | type: 'POST', |
@@ -108,11 +112,114 @@ var Cart = { | @@ -108,11 +112,114 @@ var Cart = { | ||
108 | }, | 112 | }, |
109 | 113 | ||
110 | /* | 114 | /* |
115 | + * 根据服务端JSON,刷新购物车信息 | ||
116 | + * @function [refreshCart] | ||
117 | + */ | ||
118 | + refreshCart: function(data) { | ||
119 | + var template; | ||
120 | + | ||
121 | + hbs.registerHelper('multiple', function(num1, num2) { | ||
122 | + num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10); | ||
123 | + num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10); | ||
124 | + | ||
125 | + if (num1 && num2) { | ||
126 | + return num1 * num2; | ||
127 | + } else { | ||
128 | + console.error('multiplication needs two number parameters'); | ||
129 | + } | ||
130 | + }); | ||
131 | + | ||
132 | + hbs.registerHelper('isEqual', function(v1, v2, options) { | ||
133 | + if (v1 === v2) { | ||
134 | + return options.fn(this); | ||
135 | + } | ||
136 | + return options.inverse(this); | ||
137 | + }); | ||
138 | + | ||
139 | + hbs.registerHelper('image', function(url, width, height, mode) { | ||
140 | + mode = parseInt(mode, 10) ? mode : 2; | ||
141 | + url = url || ''; | ||
142 | + return url.replace(/{width}/g, width).replace(/{height}/g, height).replace(/{mode}/g, mode); | ||
143 | + }); | ||
144 | + | ||
145 | + template = hbs.compile($('#cart-content-tpl').html()); | ||
146 | + $('#cart_content').html(template(data)); | ||
147 | + | ||
148 | + Stepper.init(); | ||
149 | + }, | ||
150 | + | ||
151 | + /* | ||
152 | + * 选择与取消选择 | ||
153 | + * @function [toggleSelectGoods] | ||
154 | + */ | ||
155 | + toggleSelectGoods: function(data) { | ||
156 | + $.ajax({ | ||
157 | + type: 'POST', | ||
158 | + url: '/shopping/cart/toggleSelectGoods', | ||
159 | + data: {skuList: JSON.stringify(data)}, | ||
160 | + dataType: 'json' | ||
161 | + }).done(function(res) { | ||
162 | + if (res.code === 200) { | ||
163 | + Cart.refreshCart(res); | ||
164 | + } else { | ||
165 | + _alert(res.message); | ||
166 | + } | ||
167 | + }).fail(function() { | ||
168 | + | ||
169 | + }); | ||
170 | + }, | ||
171 | + | ||
172 | + /* | ||
111 | * 单选每一个商品判断是否需要全选 | 173 | * 单选每一个商品判断是否需要全选 |
112 | * @function [toggleCheckAll] | 174 | * @function [toggleCheckAll] |
113 | */ | 175 | */ |
114 | - toggleCheckAll: function() { | 176 | + toggleCheck: function(target) { |
177 | + var $this = $(target), | ||
178 | + $checkoutBtn = $('#checkout_btn'), | ||
179 | + checkAll = $this.hasClass('chk-all'); | ||
180 | + | ||
181 | + var goodInfo; | ||
182 | + var data = []; | ||
183 | + | ||
184 | + if ($this.hasClass('chk-group')) { | ||
185 | + // 取消选择 | ||
186 | + $this.removeClass('chk-group'); | ||
187 | + $checkoutBtn.addClass('disable'); | ||
188 | + | ||
189 | + if (checkAll) { | ||
190 | + Cart.unCheckAllPros(); | ||
191 | + | ||
192 | + // TODO | ||
193 | + } else { | ||
194 | + // TODO | ||
195 | + Cart.resetCheckAllStyle(); | ||
196 | + | ||
197 | + // $this.next().val(''); | ||
198 | + // data.push($this.parent().attr('data-product_info')); | ||
199 | + console.log($this.parent().attr('data-product_info')); | ||
200 | + | ||
201 | + // console.log($.parseJSON($this.parent().attr('data-product_info'))) | ||
202 | + goodInfo = $.parseJSON($this.parent().attr('data-product_info')); | ||
203 | + goodInfo.selected = 'N'; | ||
204 | + data.push(goodInfo); | ||
205 | + Cart.toggleSelectGoods(data); | ||
206 | + } | ||
207 | + } else { | ||
208 | + // 选择 | ||
209 | + if (checkAll) { | ||
210 | + data = { productId: 'ALL' }; | ||
115 | 211 | ||
212 | + // TODO | ||
213 | + } else { | ||
214 | + console.log($this.parent().attr('data-product_info')); | ||
215 | + | ||
216 | + // console.log($.parseJSON($this.parent().attr('data-product_info'))) | ||
217 | + goodInfo = $.parseJSON($this.parent().attr('data-product_info')); | ||
218 | + goodInfo.selected = 'Y'; | ||
219 | + data.push(goodInfo); | ||
220 | + Cart.toggleSelectGoods(data); | ||
221 | + } | ||
222 | + } | ||
116 | }, | 223 | }, |
117 | 224 | ||
118 | /* | 225 | /* |
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | * @date: 2016/07/11 | 4 | * @date: 2016/07/11 |
5 | * @module shopping/util | 5 | * @module shopping/util |
6 | */ | 6 | */ |
7 | -var dialog = require('../plugins/dialog'); | 7 | +var dialog = require('../../plugins/dialog'); |
8 | var _alert = dialog.Alert; | 8 | var _alert = dialog.Alert; |
9 | 9 | ||
10 | var Util = { | 10 | var Util = { |
-
Please register or login to post a comment