Authored by 郭成尧

Merge branch 'feature/cart' of git.yoho.cn:fe/yohobuywap-node into feature/cart

@@ -11,7 +11,10 @@ const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab @@ -11,7 +11,10 @@ const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
11 11
12 const indexModel = require('../models/index'); 12 const indexModel = require('../models/index');
13 13
14 -let index = (req, res, next) => { 14 +/**
  15 + * [购物车首页]
  16 + */
  17 +const index = (req, res, next) => {
15 let isLogin = req.user && req.user.uid, 18 let isLogin = req.user && req.user.uid,
16 pageData = { 19 pageData = {
17 isLogin, 20 isLogin,
@@ -28,24 +31,193 @@ let index = (req, res, next) => { @@ -28,24 +31,193 @@ let index = (req, res, next) => {
28 width750: true, 31 width750: true,
29 pageHeader: headerModel.setNav({ 32 pageHeader: headerModel.setNav({
30 navTitle: '购物车', 33 navTitle: '购物车',
31 - backUrl: '/product/show_.html'  
32 - }),  
33 - pageFooter: true, 34 + navBack: true,
  35 + suggestSub: {
  36 + text: ' '
  37 + },
  38 + navBtn: false
  39 + })
34 })); 40 }));
35 }; 41 };
36 42
37 -let indexData = (req, res, next) => { 43 +/**
  44 + * [购物车数据]
  45 + */
  46 +const indexData = (req, res, next) => {
38 if (!req.xhr) { 47 if (!req.xhr) {
39 return next(); 48 return next();
40 } 49 }
41 let shoppingKey = req.cookies._SPK || '', 50 let shoppingKey = req.cookies._SPK || '',
42 - channel = req.cookies._Channel;  
43 - return indexModel.indexData(8040155, 'dc9d09e2ffd8607f2cfd8b9c95962923', channel).then(data => {  
44 - res.json(data); 51 + channel = req.cookies._Channel,
  52 + uid = req.user && req.user.uid;
  53 +
  54 + uid = 8040155;
  55 + shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
  56 +
  57 + return indexModel.indexData(uid, shoppingKey, channel).then(data => {
  58 + res.json({
  59 + code: 200,
  60 + data
  61 + });
  62 + }).catch(next);
  63 +}
  64 +
  65 +/**
  66 + * [选择或者取消商品]
  67 + */
  68 +const select = (req, res, next) => {
  69 + if (!req.xhr) {
  70 + return next();
  71 + }
  72 + let shoppingKey = req.cookies._SPK || '',
  73 + uid = req.user && req.user.uid;
  74 + let skuList = req.body.skuList;
  75 +
  76 + if (!skuList || !skuList.length) {
  77 + return res.json({
  78 + code: 400,
  79 + message: '参数错误'
  80 + });
  81 + }
  82 +
  83 + uid = 8040155;
  84 + shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
  85 +
  86 + return indexModel.selectGood(uid, skuList, shoppingKey).then(data => {
  87 + res.json({
  88 + code: 200,
  89 + data
  90 + });
  91 + }).catch(next);
  92 +}
  93 +
  94 +/**
  95 + * [移出购物车]
  96 + */
  97 +const del = (req, res, next) => {
  98 + if (!req.xhr) {
  99 + return next();
  100 + }
  101 + let shoppingKey = req.cookies._SPK || '',
  102 + uid = req.user && req.user.uid;
  103 + let skuList = req.body.skuList;
  104 +
  105 + if (!skuList || !skuList.length) {
  106 + return res.json({
  107 + code: 400,
  108 + message: '参数错误'
  109 + });
  110 + }
  111 +
  112 + uid = 8040155;
  113 + shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
  114 +
  115 + return indexModel.removeFromCart(uid, skuList, shoppingKey).then(data => {
  116 + res.json({
  117 + code: 200,
  118 + data
  119 + });
  120 + }).catch(next);
  121 +}
  122 +
  123 +/**
  124 + * [获取购物车数据]
  125 + */
  126 +const goodinfo = (req, res, next) => {
  127 + if (!req.xhr) {
  128 + return next();
  129 + }
  130 + let uid = req.user && req.user.uid,
  131 + buyNum = req.body.buy_num,
  132 + skn = req.body.skn;
  133 +
  134 + if (!buyNum || !skn) {
  135 + return res.json({
  136 + code: 400,
  137 + message: '参数错误'
  138 + });
  139 + }
  140 +
  141 + return indexModel.cartProductData(uid, skn, buyNum).then(data => {
  142 + res.render('good-info', {
  143 + layout: false,
  144 + cartInfo: data
  145 + });
  146 + }).catch(next);
  147 +}
  148 +
  149 +const col = (req, res, next) => {
  150 + if (!req.xhr) {
  151 + return next();
  152 + }
  153 + let uid = req.user && req.user.uid,
  154 + productId = req.body.id;
  155 +
  156 + if (!productId) {
  157 + return res.json({
  158 + code: 400,
  159 + message: '参数错误'
  160 + });
  161 + }
  162 + return indexModel.addToFav(uid, productId).then(data => {
  163 + res.json({
  164 + code: 200,
  165 + data
  166 + });
  167 + }).catch(next);
  168 +
  169 +}
  170 +
  171 +const modifyNum = (req, res, next) => {
  172 + if (!req.xhr) {
  173 + return next();
  174 + }
  175 + let uid = req.user && req.user.uid,
  176 + shoppingKey = req.cookies._SPK || '',
  177 + sku = req.body.sku,
  178 + increaseNum = req.body.increaseNum,
  179 + decreaseNum = req.body.decreaseNum;
  180 +
  181 + if (!sku || (!increaseNum && !decreaseNum)) {
  182 + return res.json({
  183 + code: 400,
  184 + message: '参数错误'
  185 + });
  186 + }
  187 +
  188 + uid = 8040155;
  189 + shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
  190 +
  191 + let promise;
  192 +
  193 + if (increaseNum > 0) {
  194 + promise = indexModel.increaseProductNum(uid, sku, increaseNum, shoppingKey);
  195 + } else if (decreaseNum > 0) {
  196 + promise = indexModel.decreaseProductNum(uid, sku, decreaseNum, shoppingKey);
  197 + }
  198 +
  199 + return promise.then(data => {
  200 + if (data.code === 200 && data.data) {
  201 + res.json({
  202 + code: 200,
  203 + goodsCount: data.data.goods_count
  204 + });
  205 + } else {
  206 + res.json({
  207 + code: 400,
  208 + message: data.message
  209 + });
  210 + }
  211 +
45 }).catch(next); 212 }).catch(next);
46 } 213 }
47 214
48 module.exports = { 215 module.exports = {
49 index, 216 index,
50 - indexData 217 + indexData,
  218 + select,
  219 + del,
  220 + goodinfo,
  221 + col,
  222 + modifyNum
51 }; 223 };
@@ -5,9 +5,8 @@ @@ -5,9 +5,8 @@
5 */ 5 */
6 6
7 'use strict'; 7 'use strict';
8 -const helpers = global.yoho.helpers;  
9 const api = global.yoho.API; 8 const api = global.yoho.API;
10 -const _ = require('lodash'); 9 +const cartProcess = require(global.utils + '/cart-process');
11 10
12 const indexData = (uid, shoppingKey, saleChannel, cartType) => { 11 const indexData = (uid, shoppingKey, saleChannel, cartType) => {
13 return api.get('', { 12 return api.get('', {
@@ -16,185 +15,1030 @@ const indexData = (uid, shoppingKey, saleChannel, cartType) => { @@ -16,185 +15,1030 @@ const indexData = (uid, shoppingKey, saleChannel, cartType) => {
16 shopping_key: shoppingKey, 15 shopping_key: shoppingKey,
17 sale_channel: saleChannel 16 sale_channel: saleChannel
18 }).then((data) => { 17 }).then((data) => {
19 - let cart = data.data;  
20 - let result = {};  
21 - let ordinaryCount = _.get(cart, 'ordinary_cart_data.shopping_cart_data.goods_count', 0);  
22 - let advanceCount = _.get(cart, 'advance_cart_data.shopping_cart_data.goods_count', 0);  
23 - let ordinarySoldOut = _.get(cart, 'ordinary_cart_data.sold_out_goods_list', []);  
24 - let advanceSoldOut = _.get(cart, 'advance_cart_data.sold_out_goods_list', []);  
25 -  
26 - // 普通购物车和预售购物车都为空  
27 - if (ordinaryCount === 0 && advanceCount === 0 && !ordinarySoldOut.length && !advanceSoldOut.length) {  
28 - result.isEmptyCart = true;  
29 - return result;  
30 - }  
31 -  
32 - // 普通购物车空,则显示预售购物车  
33 - if (ordinaryCount === 0 && !ordinarySoldOut.length) {  
34 - result.cartNav = false;  
35 - result.cartType = 'advance';  
36 - } // 预售购物车空,则显示普通购物车  
37 - else if (advanceCount === 0 && !advanceSoldOut.length) {  
38 - result.cartNav = false;  
39 - result.cartType = 'ordinary';  
40 - } // 以上两个购物车中都有数据, 默认显示普通购物车  
41 - else {  
42 - result.cartNav = true;  
43 - result.cartType = cartType || 'ordinary';  
44 - }  
45 -  
46 - /* 普通购物车 */  
47 - result.commonGoodsCount = ordinaryCount;  
48 - result.commonCart = processData(cart.ordinary_cart_data, false);  
49 - /* 预售购物车 */  
50 - result.presellGoodsCount = advanceCount;  
51 - result.preSellCart = processData(cart.advance_cart_data);  
52 - console.log(result)  
53 - return result; 18 +// return new Promise((resolve, reject) => {
  19 +// resolve(cartProcess.processData({
  20 +// "alg": "SALT_MD5",
  21 +// "code": 200,
  22 +// "data": {
  23 +// "advance_cart_data": {
  24 +// "gift_list": [],
  25 +// "goods_list": [],
  26 +// "goods_pool_list": [],
  27 +// "off_shelves_goods_list": [],
  28 +// "price_gift": [],
  29 +// "promotion_info": [],
  30 +// "shopping_cart_data": {
  31 +// "discount_amount": 0,
  32 +// "fast_shopping_cost": 15,
  33 +// "gain_yoho_coin": 0,
  34 +// "goods_count": 0,
  35 +// "has_invalid_goods": 0,
  36 +// "is_multi_package": "N",
  37 +// "last_order_amount": 0,
  38 +// "offline_goods_count": 0,
  39 +// "online_goods_count": 0,
  40 +// "order_amount": 0,
  41 +// "package_list": [],
  42 +// "promotion_formula": "总计¥0.00=商品金额¥0.00",
  43 +// "promotion_formula_list": [
  44 +// {
  45 +// "promotion": "商品金额",
  46 +// "promotion_amount": "¥0.00"
  47 +// }
  48 +// ],
  49 +// "remain_time": 0,
  50 +// "selected_goods_count": 0,
  51 +// "shipping_cost": 10,
  52 +// "str_discount_amount": "¥0.00",
  53 +// "str_order_amount": "¥0.00"
  54 +// },
  55 +// "sold_out_goods_list": []
  56 +// },
  57 +// "ordinary_cart_data": {
  58 +// "gift_list": [],
  59 +// "goods_list": [],
  60 +// "goods_pool_list": [
  61 +// {
  62 +// "goods_list": [
  63 +// {
  64 +// "attribute": "1",
  65 +// "brand_domain": "I LOVE CHOC",
  66 +// "brand_id": "524",
  67 +// "brand_name": "ilovechoc",
  68 +// "buy_limit": 0,
  69 +// "buy_number": "1",
  70 +// "buy_type": 2,
  71 +// "can_cod_pay": "Y",
  72 +// "cn_alphabet": "ILOVECHOC505432039TongZhuangXingXingPinJieLianMaoBangQiuShan",
  73 +// "color_id": "7",
  74 +// "color_name": "蓝色",
  75 +// "delay_notice": "",
  76 +// "discount_tag": "",
  77 +// "expect_arrival_time": "",
  78 +// "factory_goods_name": "蓝色",
  79 +// "fit_promotions": [],
  80 +// "get_yoho_coin": "0",
  81 +// "goods_id": "367065",
  82 +// "goods_images": "http://img10.static.yhbimg.com/goodsimg/2015/11/25/06/01d06aa4c18f6714a04573afeac2ae71d2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  83 +// "goods_type": "ordinary",
  84 +// "is_advance": "N",
  85 +// "is_deposit_advance": "N",
  86 +// "is_jit": "N",
  87 +// "is_limited": "N",
  88 +// "is_outlets": "N",
  89 +// "is_special": "N",
  90 +// "last_price": "280.0",
  91 +// "last_vip_price": 280,
  92 +// "local_buy_number": 0,
  93 +// "market_price": 281,
  94 +// "max_sort_id": "365",
  95 +// "middle_sort_id": "404",
  96 +// "min_buy_number": 1,
  97 +// "off_shelves": 0,
  98 +// "offline_goods_status": 1,
  99 +// "offline_storage_number": 0,
  100 +// "offline_storage_status": 1,
  101 +// "online_storage_number": 0,
  102 +// "product_id": 285265,
  103 +// "product_name": "I LOVE CHOC 童装星星拼接连帽棒球衫",
  104 +// "product_skc": "288132",
  105 +// "product_skn": "51160552",
  106 +// "product_sku": "912752",
  107 +// "promotion_flag": "101",
  108 +// "promotion_id": "0",
  109 +// "real_price": 280,
  110 +// "real_vip_price": 0,
  111 +// "sale_price": 0,
  112 +// "sales_price": 280,
  113 +// "selected": "Y",
  114 +// "shop_id": 0,
  115 +// "shopping_cart_goods_id": "60454",
  116 +// "shopping_cart_id": "118792348",
  117 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  118 +// "size_id": "203",
  119 +// "size_name": "M",
  120 +// "small_sort_id": "405",
  121 +// "storage_number": "1",
  122 +// "store_id": 0,
  123 +// "str_subtotal": "¥280.00",
  124 +// "subtotal": 280,
  125 +// "supplier_id": 0,
  126 +// "tags": [],
  127 +// "uid": "8040155",
  128 +// "vip1_price": "0.00",
  129 +// "vip2_price": "0.00",
  130 +// "vip3_price": "0.00",
  131 +// "vip_discount": 1,
  132 +// "vip_discount_money": 0,
  133 +// "vip_discount_type": "3",
  134 +// "vip_price": 0,
  135 +// "wareHouseId": 0,
  136 +// "yoho_coin_num": "0"
  137 +// }
  138 +// ],
  139 +// "pool_title": "ilovechoc",
  140 +// "pool_type": 1
  141 +// },
  142 +// {
  143 +// "pool_type": 0,
  144 +// "promotion_list": [
  145 +// {
  146 +// "alreadyMatch": true,
  147 +// "condition_unit": 0,
  148 +// "condition_value": 0,
  149 +// "gift_goods_List": [],
  150 +// "gift_price": 0,
  151 +// "promotion_id": 9148,
  152 +// "promotion_title": "全场促销",
  153 +// "promotion_type": "Discount",
  154 +// "status": 10
  155 +// }
  156 +// ],
  157 +// "sub_pool": [
  158 +// {
  159 +// "goods_list": [
  160 +// {
  161 +// "attribute": "1",
  162 +// "brand_domain": "oasso",
  163 +// "brand_id": "210",
  164 +// "brand_name": "oasso",
  165 +// "buy_limit": 0,
  166 +// "buy_number": "2",
  167 +// "buy_type": 2,
  168 +// "can_cod_pay": "Y",
  169 +// "cn_alphabet": "OASSOShouJiChongDianZuo",
  170 +// "color_id": "6",
  171 +// "color_name": "绿色",
  172 +// "delay_notice": "",
  173 +// "discount_tag": "S",
  174 +// "expect_arrival_time": "",
  175 +// "factory_goods_name": "绿色",
  176 +// "fit_promotions": [
  177 +// "9148"
  178 +// ],
  179 +// "get_yoho_coin": "0",
  180 +// "goods_id": "254893",
  181 +// "goods_images": "http://img13.static.yhbimg.com/goodsimg/2016/01/12/05/02d78f2aec2e0206f34e6bed05e463c73d.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  182 +// "goods_type": "ordinary",
  183 +// "is_advance": "N",
  184 +// "is_deposit_advance": "N",
  185 +// "is_jit": "N",
  186 +// "is_limited": "Y",
  187 +// "is_outlets": "N",
  188 +// "is_special": "N",
  189 +// "last_price": "7.92",
  190 +// "last_vip_price": 9.9,
  191 +// "local_buy_number": 0,
  192 +// "market_price": 12,
  193 +// "max_sort_id": "10",
  194 +// "middle_sort_id": "103",
  195 +// "min_buy_number": 1,
  196 +// "off_shelves": 0,
  197 +// "offline_goods_status": 1,
  198 +// "offline_storage_number": 0,
  199 +// "offline_storage_status": 1,
  200 +// "online_storage_number": 0,
  201 +// "product_id": 189413,
  202 +// "product_name": "oasso 手机充电座",
  203 +// "product_skc": "228608",
  204 +// "product_skn": "51109379",
  205 +// "product_sku": "746705",
  206 +// "promotion_flag": "110",
  207 +// "promotion_id": "0",
  208 +// "real_price": 7.92,
  209 +// "real_vip_price": 9.9,
  210 +// "sale_price": 0,
  211 +// "sales_price": 11,
  212 +// "selected": "Y",
  213 +// "shop_id": 0,
  214 +// "shopping_cart_goods_id": "60434",
  215 +// "shopping_cart_id": "118792348",
  216 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  217 +// "size_id": "199",
  218 +// "size_name": "F",
  219 +// "small_sort_id": "212",
  220 +// "storage_number": "12331",
  221 +// "store_id": 0,
  222 +// "str_subtotal": "¥19.80",
  223 +// "subtotal": 19.8,
  224 +// "supplier_id": 0,
  225 +// "tags": [],
  226 +// "uid": "8040155",
  227 +// "vip1_price": "10.45",
  228 +// "vip2_price": "9.90",
  229 +// "vip3_price": "9.68",
  230 +// "vip_discount": 0.9,
  231 +// "vip_discount_money": 1.1,
  232 +// "vip_discount_type": "1",
  233 +// "vip_price": 11,
  234 +// "wareHouseId": 0,
  235 +// "yoho_coin_num": "0"
  236 +// }
  237 +// ],
  238 +// "pool_type": 1
  239 +// }
  240 +// ]
  241 +// },
  242 +// {
  243 +// "goods_list": [
  244 +// {
  245 +// "attribute": "1",
  246 +// "brand_domain": "EBLIS",
  247 +// "brand_id": "37",
  248 +// "brand_name": "eblishungi",
  249 +// "buy_limit": 0,
  250 +// "buy_number": "1",
  251 +// "buy_type": 2,
  252 +// "can_cod_pay": "Y",
  253 +// "cn_alphabet": "EBLISChenShanS223",
  254 +// "color_id": "7",
  255 +// "color_name": "蓝色",
  256 +// "delay_notice": "",
  257 +// "discount_tag": "S",
  258 +// "expect_arrival_time": "1月",
  259 +// "factory_goods_name": "测试数据,测试厂家颜色,蓝色,testtest,测试测试测试测试。。。。测试",
  260 +// "fit_promotions": [],
  261 +// "get_yoho_coin": "0",
  262 +// "goods_id": "443029",
  263 +// "goods_images": "http://img11.static.yhbimg.com/goodsimg/2016/01/12/02/01e1c78084e7ed6739b21a8bccbbf32f1b.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  264 +// "goods_type": "ordinary",
  265 +// "is_advance": "N",
  266 +// "is_deposit_advance": "N",
  267 +// "is_jit": "N",
  268 +// "is_limited": "N",
  269 +// "is_outlets": "N",
  270 +// "is_special": "N",
  271 +// "last_price": "9.9",
  272 +// "last_vip_price": 9.9,
  273 +// "local_buy_number": 0,
  274 +// "market_price": 598,
  275 +// "max_sort_id": "1",
  276 +// "middle_sort_id": "12",
  277 +// "min_buy_number": 1,
  278 +// "off_shelves": 0,
  279 +// "offline_goods_status": 1,
  280 +// "offline_storage_number": 0,
  281 +// "offline_storage_status": 1,
  282 +// "online_storage_number": 0,
  283 +// "product_id": 345753,
  284 +// "product_name": "EBLIS 男款格子衬衫",
  285 +// "product_skc": "329633",
  286 +// "product_skn": "51192557",
  287 +// "product_sku": "1029828",
  288 +// "promotion_flag": "0",
  289 +// "promotion_id": "0",
  290 +// "real_price": 9.9,
  291 +// "real_vip_price": 9.9,
  292 +// "sale_price": 0,
  293 +// "sales_price": 11,
  294 +// "selected": "Y",
  295 +// "shop_id": 0,
  296 +// "shopping_cart_goods_id": "60430",
  297 +// "shopping_cart_id": "118792348",
  298 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  299 +// "size_id": "207",
  300 +// "size_name": "S",
  301 +// "small_sort_id": "115",
  302 +// "storage_number": "499",
  303 +// "store_id": 0,
  304 +// "str_subtotal": "¥9.90",
  305 +// "subtotal": 9.9,
  306 +// "supplier_id": 0,
  307 +// "tags": [],
  308 +// "uid": "8040155",
  309 +// "vip1_price": "10.45",
  310 +// "vip2_price": "9.90",
  311 +// "vip3_price": "9.68",
  312 +// "vip_discount": 0.9,
  313 +// "vip_discount_money": 1.1,
  314 +// "vip_discount_type": "1",
  315 +// "vip_price": 11,
  316 +// "wareHouseId": 0,
  317 +// "yoho_coin_num": "0"
  318 +// }
  319 +// ],
  320 +// "pool_title": "eblishungi",
  321 +// "pool_type": 1
  322 +// },
  323 +// {
  324 +// "pool_type": 0,
  325 +// "promotion_list": [
  326 +// {
  327 +// "alreadyMatch": true,
  328 +// "condition_unit": 0,
  329 +// "condition_value": 0,
  330 +// "gift_goods_List": [],
  331 +// "gift_price": 0,
  332 +// "promotion_id": 9088,
  333 +// "promotion_title": "线下店满3免一勿动",
  334 +// "promotion_type": "Cheapestfree",
  335 +// "status": 10
  336 +// }
  337 +// ],
  338 +// "sub_pool": [
  339 +// {
  340 +// "goods_list": [
  341 +// {
  342 +// "attribute": "1",
  343 +// "brand_domain": "BLACKJACK",
  344 +// "brand_id": "256",
  345 +// "brand_name": "blackjack",
  346 +// "buy_limit": 0,
  347 +// "buy_number": "3",
  348 +// "buy_type": 2,
  349 +// "can_cod_pay": "Y",
  350 +// "cn_alphabet": "PANDAMADEHOTRODP12062",
  351 +// "color_id": "1",
  352 +// "color_name": "白",
  353 +// "delay_notice": "",
  354 +// "discount_tag": "S",
  355 +// "expect_arrival_time": "",
  356 +// "factory_goods_name": "白",
  357 +// "fit_promotions": [
  358 +// "9088"
  359 +// ],
  360 +// "get_yoho_coin": "0",
  361 +// "goods_id": "28492",
  362 +// "goods_images": "http://img10.static.yhbimg.com/goodsimg/2016/09/26/19/01a0040ac739eda88815760dc95017c406.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  363 +// "goods_type": "ordinary",
  364 +// "is_advance": "N",
  365 +// "is_deposit_advance": "N",
  366 +// "is_jit": "N",
  367 +// "is_limited": "N",
  368 +// "is_outlets": "N",
  369 +// "is_special": "N",
  370 +// "last_price": "0.6",
  371 +// "last_vip_price": 0.9,
  372 +// "local_buy_number": 0,
  373 +// "market_price": 289,
  374 +// "max_sort_id": "1",
  375 +// "middle_sort_id": "11",
  376 +// "min_buy_number": 1,
  377 +// "off_shelves": 0,
  378 +// "offline_goods_status": 1,
  379 +// "offline_storage_number": 0,
  380 +// "offline_storage_status": 1,
  381 +// "online_storage_number": 0,
  382 +// "product_id": 19858,
  383 +// "product_name": "BLACKJACK民族风骷髅拉花毛衣",
  384 +// "product_skc": "28492",
  385 +// "product_skn": "50023801",
  386 +// "product_sku": "164165",
  387 +// "promotion_flag": "108",
  388 +// "promotion_id": "0",
  389 +// "real_price": 0.6,
  390 +// "real_vip_price": 0.9,
  391 +// "sale_price": 0,
  392 +// "sales_price": 1,
  393 +// "selected": "Y",
  394 +// "shop_id": 0,
  395 +// "shopping_cart_goods_id": "60428",
  396 +// "shopping_cart_id": "118792348",
  397 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  398 +// "size_id": "201",
  399 +// "size_name": "L",
  400 +// "small_sort_id": "114",
  401 +// "storage_number": "100",
  402 +// "store_id": 0,
  403 +// "str_subtotal": "¥2.70",
  404 +// "subtotal": 2.7,
  405 +// "supplier_id": 0,
  406 +// "tags": [],
  407 +// "uid": "8040155",
  408 +// "vip1_price": "0.95",
  409 +// "vip2_price": "0.90",
  410 +// "vip3_price": "0.88",
  411 +// "vip_discount": 0.9,
  412 +// "vip_discount_money": 0.1,
  413 +// "vip_discount_type": "1",
  414 +// "vip_price": 11,
  415 +// "wareHouseId": 0,
  416 +// "yoho_coin_num": "0"
  417 +// }
  418 +// ],
  419 +// "pool_type": 1
  420 +// }
  421 +// ]
  422 +// },
  423 +// {
  424 +// "goods_list": [
  425 +// {
  426 +// "attribute": "1",
  427 +// "brand_domain": "VANS",
  428 +// "brand_id": "144",
  429 +// "brand_name": "vans",
  430 +// "buy_limit": 0,
  431 +// "buy_number": "1",
  432 +// "buy_type": 2,
  433 +// "can_cod_pay": "Y",
  434 +// "cn_alphabet": "VANSGGIRLFRIENDSKIRTVN01Z1BLK",
  435 +// "color_id": "2",
  436 +// "color_name": "黑色",
  437 +// "delay_notice": "",
  438 +// "discount_tag": "S",
  439 +// "expect_arrival_time": "",
  440 +// "factory_goods_name": "黑色",
  441 +// "fit_promotions": [],
  442 +// "get_yoho_coin": "0",
  443 +// "goods_id": "257295",
  444 +// "goods_images": "http://img11.static.yhbimg.com/goodsimg/2015/05/22/08/01bdaaa0753892690e06ff7ef9bfd39b2b.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  445 +// "goods_type": "ordinary",
  446 +// "is_advance": "N",
  447 +// "is_deposit_advance": "N",
  448 +// "is_jit": "N",
  449 +// "is_limited": "N",
  450 +// "is_outlets": "N",
  451 +// "is_special": "N",
  452 +// "last_price": "9.9",
  453 +// "last_vip_price": 9.9,
  454 +// "local_buy_number": 0,
  455 +// "market_price": 260,
  456 +// "max_sort_id": "4",
  457 +// "middle_sort_id": "32",
  458 +// "min_buy_number": 1,
  459 +// "off_shelves": 0,
  460 +// "offline_goods_status": 1,
  461 +// "offline_storage_number": 0,
  462 +// "offline_storage_status": 1,
  463 +// "online_storage_number": 0,
  464 +// "product_id": 191193,
  465 +// "product_name": "VANS G GIRLFRIEND SKIRT",
  466 +// "product_skc": "230040",
  467 +// "product_skn": "51110511",
  468 +// "product_sku": "751215",
  469 +// "promotion_flag": "101",
  470 +// "promotion_id": "0",
  471 +// "real_price": 9.9,
  472 +// "real_vip_price": 9.9,
  473 +// "sale_price": 0,
  474 +// "sales_price": 11,
  475 +// "selected": "Y",
  476 +// "shop_id": 0,
  477 +// "shopping_cart_goods_id": "60424",
  478 +// "shopping_cart_id": "118792348",
  479 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  480 +// "size_id": "201",
  481 +// "size_name": "L",
  482 +// "small_sort_id": "135",
  483 +// "storage_number": "11999",
  484 +// "store_id": 0,
  485 +// "str_subtotal": "¥9.90",
  486 +// "subtotal": 9.9,
  487 +// "supplier_id": 0,
  488 +// "tags": [],
  489 +// "uid": "8040155",
  490 +// "vip1_price": "10.45",
  491 +// "vip2_price": "9.90",
  492 +// "vip3_price": "9.68",
  493 +// "vip_discount": 0.9,
  494 +// "vip_discount_money": 1.1,
  495 +// "vip_discount_type": "1",
  496 +// "vip_price": 11,
  497 +// "wareHouseId": 0,
  498 +// "yoho_coin_num": "0"
  499 +// }
  500 +// ],
  501 +// "pool_title": "vans",
  502 +// "pool_type": 1
  503 +// },
  504 +// {
  505 +// "pool_type": 0,
  506 +// "promotion_list": [
  507 +// {
  508 +// "alreadyMatch": true,
  509 +// "condition_unit": 0,
  510 +// "condition_value": 0,
  511 +// "gift_goods_List": [],
  512 +// "gift_price": 0,
  513 +// "promotion_id": 9086,
  514 +// "promotion_title": "线下店分件折扣勿动",
  515 +// "promotion_type": "Degressdiscount",
  516 +// "status": 10
  517 +// }
  518 +// ],
  519 +// "sub_pool": [
  520 +// {
  521 +// "goods_list": [
  522 +// {
  523 +// "attribute": "1",
  524 +// "brand_domain": "ZERONE",
  525 +// "brand_id": "199",
  526 +// "brand_name": "zerone",
  527 +// "buy_limit": 0,
  528 +// "buy_number": "1",
  529 +// "buy_type": 2,
  530 +// "can_cod_pay": "Y",
  531 +// "cn_alphabet": "ZERONEDZ100105DZ100107UPC853A",
  532 +// "color_id": "2",
  533 +// "color_name": "黑",
  534 +// "delay_notice": "",
  535 +// "discount_tag": "S",
  536 +// "expect_arrival_time": "",
  537 +// "factory_goods_name": "黑",
  538 +// "fit_promotions": [
  539 +// "9086"
  540 +// ],
  541 +// "get_yoho_coin": "0",
  542 +// "goods_id": "20056",
  543 +// "goods_images": "http://img12.static.yhbimg.com/goodsimg/2012/02/29/11/02f5a2573d16e353b3c36a6404a9aabd7c.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  544 +// "goods_type": "ordinary",
  545 +// "is_advance": "N",
  546 +// "is_deposit_advance": "N",
  547 +// "is_jit": "N",
  548 +// "is_limited": "N",
  549 +// "is_outlets": "N",
  550 +// "is_special": "N",
  551 +// "last_price": "195.93",
  552 +// "last_vip_price": 279.9,
  553 +// "local_buy_number": 0,
  554 +// "market_price": 629,
  555 +// "max_sort_id": "8",
  556 +// "middle_sort_id": "59",
  557 +// "min_buy_number": 1,
  558 +// "off_shelves": 0,
  559 +// "offline_goods_status": 1,
  560 +// "offline_storage_number": 0,
  561 +// "offline_storage_status": 1,
  562 +// "online_storage_number": 0,
  563 +// "product_id": 14293,
  564 +// "product_name": "ZERONE Lolita系列蕾丝手表",
  565 +// "product_skc": "20056",
  566 +// "product_skn": "50018093",
  567 +// "product_sku": "141155",
  568 +// "promotion_flag": "108",
  569 +// "promotion_id": "0",
  570 +// "real_price": 195.93,
  571 +// "real_vip_price": 279.9,
  572 +// "sale_price": 0,
  573 +// "sales_price": 311,
  574 +// "selected": "Y",
  575 +// "shop_id": 0,
  576 +// "shopping_cart_goods_id": "60422",
  577 +// "shopping_cart_id": "118792348",
  578 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  579 +// "size_id": "199",
  580 +// "size_name": "F",
  581 +// "small_sort_id": "162",
  582 +// "storage_number": "100",
  583 +// "store_id": 0,
  584 +// "str_subtotal": "¥279.90",
  585 +// "subtotal": 279.9,
  586 +// "supplier_id": 0,
  587 +// "tags": [],
  588 +// "uid": "8040155",
  589 +// "vip1_price": "295.45",
  590 +// "vip2_price": "279.90",
  591 +// "vip3_price": "273.68",
  592 +// "vip_discount": 0.9,
  593 +// "vip_discount_money": 31.1,
  594 +// "vip_discount_type": "1",
  595 +// "vip_price": 11,
  596 +// "wareHouseId": 0,
  597 +// "yoho_coin_num": "0"
  598 +// },
  599 +// {
  600 +// "attribute": "1",
  601 +// "brand_domain": "ZERONE",
  602 +// "brand_id": "199",
  603 +// "brand_name": "zerone",
  604 +// "buy_limit": 0,
  605 +// "buy_number": "1",
  606 +// "buy_type": 2,
  607 +// "can_cod_pay": "Y",
  608 +// "cn_alphabet": "ZERONEDZ100105DZ100107UPC853A",
  609 +// "color_id": "2",
  610 +// "color_name": "黑",
  611 +// "delay_notice": "",
  612 +// "discount_tag": "S",
  613 +// "expect_arrival_time": "",
  614 +// "factory_goods_name": "黑",
  615 +// "fit_promotions": [
  616 +// "9086"
  617 +// ],
  618 +// "get_yoho_coin": "0",
  619 +// "goods_id": "20056",
  620 +// "goods_images": "http://img12.static.yhbimg.com/goodsimg/2012/02/29/11/02f5a2573d16e353b3c36a6404a9aabd7c.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  621 +// "goods_type": "ordinary",
  622 +// "is_advance": "N",
  623 +// "is_deposit_advance": "N",
  624 +// "is_jit": "N",
  625 +// "is_limited": "N",
  626 +// "is_outlets": "N",
  627 +// "is_special": "N",
  628 +// "last_price": "195.93",
  629 +// "last_vip_price": 279.9,
  630 +// "local_buy_number": 0,
  631 +// "market_price": 629,
  632 +// "max_sort_id": "8",
  633 +// "middle_sort_id": "59",
  634 +// "min_buy_number": 1,
  635 +// "off_shelves": 0,
  636 +// "offline_goods_status": 1,
  637 +// "offline_storage_number": 0,
  638 +// "offline_storage_status": 1,
  639 +// "online_storage_number": 0,
  640 +// "product_id": 14293,
  641 +// "product_name": "ZERONE Lolita系列蕾丝手表",
  642 +// "product_skc": "20056",
  643 +// "product_skn": "50018093",
  644 +// "product_sku": "141155",
  645 +// "promotion_flag": "108",
  646 +// "promotion_id": "0",
  647 +// "real_price": 195.93,
  648 +// "real_vip_price": 279.9,
  649 +// "sale_price": 0,
  650 +// "sales_price": 311,
  651 +// "selected": "Y",
  652 +// "shop_id": 0,
  653 +// "shopping_cart_goods_id": "60422",
  654 +// "shopping_cart_id": "118792348",
  655 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  656 +// "size_id": "199",
  657 +// "size_name": "F",
  658 +// "small_sort_id": "162",
  659 +// "storage_number": "100",
  660 +// "store_id": 0,
  661 +// "str_subtotal": "¥279.90",
  662 +// "subtotal": 279.9,
  663 +// "supplier_id": 0,
  664 +// "tags": [],
  665 +// "uid": "8040155",
  666 +// "vip1_price": "295.45",
  667 +// "vip2_price": "279.90",
  668 +// "vip3_price": "273.68",
  669 +// "vip_discount": 0.9,
  670 +// "vip_discount_money": 31.1,
  671 +// "vip_discount_type": "1",
  672 +// "vip_price": 11,
  673 +// "wareHouseId": 0,
  674 +// "yoho_coin_num": "0"
  675 +// }
  676 +// ],
  677 +// "pool_type": 1
  678 +// }
  679 +// ]
  680 +// },
  681 +// {
  682 +// "goods_list": [
  683 +// {
  684 +// "attribute": "1",
  685 +// "brand_domain": "reemoor",
  686 +// "brand_id": "949",
  687 +// "brand_name": "reemoor",
  688 +// "buy_limit": 0,
  689 +// "buy_number": "1",
  690 +// "buy_type": 2,
  691 +// "can_cod_pay": "Y",
  692 +// "cn_alphabet": "REEMOOR251205ShuangXianHangFengYaZhiFengGeShuJuanXie",
  693 +// "color_id": "7",
  694 +// "color_name": "蓝色",
  695 +// "delay_notice": "",
  696 +// "discount_tag": "S",
  697 +// "expect_arrival_time": "",
  698 +// "factory_goods_name": "蓝色",
  699 +// "fit_promotions": [],
  700 +// "get_yoho_coin": "0",
  701 +// "goods_id": "353397",
  702 +// "goods_images": "http://img10.static.yhbimg.com/goodsimg/2015/10/10/08/01218e9a756a74d2f15e8071fe43b601ab.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  703 +// "goods_type": "ordinary",
  704 +// "is_advance": "N",
  705 +// "is_deposit_advance": "N",
  706 +// "is_jit": "N",
  707 +// "is_limited": "N",
  708 +// "is_outlets": "N",
  709 +// "is_special": "N",
  710 +// "last_price": "9.9",
  711 +// "last_vip_price": 9.9,
  712 +// "local_buy_number": 0,
  713 +// "market_price": 298,
  714 +// "max_sort_id": "6",
  715 +// "middle_sort_id": "48",
  716 +// "min_buy_number": 1,
  717 +// "off_shelves": 0,
  718 +// "offline_goods_status": 1,
  719 +// "offline_storage_number": 0,
  720 +// "offline_storage_status": 1,
  721 +// "online_storage_number": 0,
  722 +// "product_id": 273535,
  723 +// "product_name": "reemoor 双线绗缝雅致风格舒卷鞋",
  724 +// "product_skc": "278773",
  725 +// "product_skn": "51152203",
  726 +// "product_sku": "890538",
  727 +// "promotion_flag": "109",
  728 +// "promotion_id": "0",
  729 +// "real_price": 9.9,
  730 +// "real_vip_price": 9.9,
  731 +// "sale_price": 0,
  732 +// "sales_price": 11,
  733 +// "selected": "Y",
  734 +// "shop_id": 0,
  735 +// "shopping_cart_goods_id": "60416",
  736 +// "shopping_cart_id": "118792348",
  737 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  738 +// "size_id": "116",
  739 +// "size_name": "40码",
  740 +// "small_sort_id": "151",
  741 +// "storage_number": "7",
  742 +// "store_id": 0,
  743 +// "str_subtotal": "¥9.90",
  744 +// "subtotal": 9.9,
  745 +// "supplier_id": 0,
  746 +// "tags": [],
  747 +// "uid": "8040155",
  748 +// "vip1_price": "10.45",
  749 +// "vip2_price": "9.90",
  750 +// "vip3_price": "9.68",
  751 +// "vip_discount": 0.9,
  752 +// "vip_discount_money": 1.1,
  753 +// "vip_discount_type": "1",
  754 +// "vip_price": 11,
  755 +// "wareHouseId": 0,
  756 +// "yoho_coin_num": "0"
  757 +// },
  758 +// {
  759 +// "attribute": "1",
  760 +// "brand_domain": "reemoor",
  761 +// "brand_id": "949",
  762 +// "brand_name": "reemoor",
  763 +// "buy_limit": 0,
  764 +// "buy_number": "1",
  765 +// "buy_type": 2,
  766 +// "can_cod_pay": "Y",
  767 +// "cn_alphabet": "REEMOOR251289LiangMianJianTouHuDieJieZhuangShiShuJuanXie",
  768 +// "color_id": "1",
  769 +// "color_name": "白色",
  770 +// "delay_notice": "",
  771 +// "discount_tag": "S",
  772 +// "expect_arrival_time": "",
  773 +// "factory_goods_name": "白色",
  774 +// "fit_promotions": [],
  775 +// "get_yoho_coin": "0",
  776 +// "goods_id": "353425",
  777 +// "goods_images": "http://img10.static.yhbimg.com/goodsimg/2015/10/10/08/01a9456ed9db84ea945d2163de7144a85f.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
  778 +// "goods_type": "ordinary",
  779 +// "is_advance": "N",
  780 +// "is_deposit_advance": "N",
  781 +// "is_jit": "N",
  782 +// "is_limited": "N",
  783 +// "is_outlets": "N",
  784 +// "is_special": "N",
  785 +// "last_price": "9.9",
  786 +// "last_vip_price": 9.9,
  787 +// "local_buy_number": 0,
  788 +// "market_price": 298,
  789 +// "max_sort_id": "6",
  790 +// "middle_sort_id": "48",
  791 +// "min_buy_number": 1,
  792 +// "off_shelves": 0,
  793 +// "offline_goods_status": 1,
  794 +// "offline_storage_number": 0,
  795 +// "offline_storage_status": 1,
  796 +// "online_storage_number": 0,
  797 +// "product_id": 273543,
  798 +// "product_name": "reemoor 亮面尖头蝴蝶结装饰舒卷鞋",
  799 +// "product_skc": "278787",
  800 +// "product_skn": "51152207",
  801 +// "product_sku": "890621",
  802 +// "promotion_flag": "109",
  803 +// "promotion_id": "0",
  804 +// "real_price": 9.9,
  805 +// "real_vip_price": 9.9,
  806 +// "sale_price": 0,
  807 +// "sales_price": 11,
  808 +// "selected": "Y",
  809 +// "shop_id": 0,
  810 +// "shopping_cart_goods_id": "60426",
  811 +// "shopping_cart_id": "118792348",
  812 +// "shopping_key": "2a7729e3e974cfe476e4472a89c13743",
  813 +// "size_id": "116",
  814 +// "size_name": "40码",
  815 +// "small_sort_id": "151",
  816 +// "storage_number": "6",
  817 +// "store_id": 0,
  818 +// "str_subtotal": "¥9.90",
  819 +// "subtotal": 9.9,
  820 +// "supplier_id": 0,
  821 +// "tags": [],
  822 +// "uid": "8040155",
  823 +// "vip1_price": "10.45",
  824 +// "vip2_price": "9.90",
  825 +// "vip3_price": "9.68",
  826 +// "vip_discount": 0.9,
  827 +// "vip_discount_money": 1.1,
  828 +// "vip_discount_type": "1",
  829 +// "vip_price": 11,
  830 +// "wareHouseId": 0,
  831 +// "yoho_coin_num": "0"
  832 +// }
  833 +// ],
  834 +// "pool_title": "reemoor",
  835 +// "pool_type": 1
  836 +// }
  837 +// ],
  838 +// "off_shelves_goods_list": [],
  839 +// "price_gift": [],
  840 +// "promotion_info": [
  841 +// {
  842 +// "cutdown_amount": 0.9,
  843 +// "promotion_id": 9088,
  844 +// "promotion_title": "线下店满3免一勿动",
  845 +// "promotion_type": "Cheapestfree"
  846 +// },
  847 +// {
  848 +// "cutdown_amount": 3.96,
  849 +// "promotion_id": 9148,
  850 +// "promotion_title": "全场促销",
  851 +// "promotion_type": "Discount"
  852 +// },
  853 +// {
  854 +// "cutdown_amount": 167.94,
  855 +// "promotion_id": 9086,
  856 +// "promotion_title": "线下店分件折扣勿动",
  857 +// "promotion_type": "Degressdiscount"
  858 +// },
  859 +// {
  860 +// "cutdown_amount": 10,
  861 +// "promotion_id": 0,
  862 +// "promotion_title": "满¥399免运费",
  863 +// "promotion_type": "FreeShippingCost"
  864 +// }
  865 +// ],
  866 +// "shopping_cart_data": {
  867 +// "discount_amount": 172.8,
  868 +// "fast_shopping_cost": 5,
  869 +// "gain_yoho_coin": 0,
  870 +// "goods_count": 12,
  871 +// "has_invalid_goods": 0,
  872 +// "is_multi_package": "N",
  873 +// "last_order_amount": 729.1,
  874 +// "offline_goods_count": 0,
  875 +// "online_goods_count": 0,
  876 +// "order_amount": 971,
  877 +// "package_list": [],
  878 +// "promotion_formula": "总计¥729.10=商品金额¥971.00-活动金额¥172.80-学生优惠¥69.10",
  879 +// "promotion_formula_list": [
  880 +// {
  881 +// "promotion": "商品金额",
  882 +// "promotion_amount": "¥971.00"
  883 +// },
  884 +// {
  885 +// "promotion": "活动金额",
  886 +// "promotion_amount": "-¥172.80"
  887 +// },
  888 +// {
  889 +// "promotion": "学生优惠",
  890 +// "promotion_amount": "-¥69.10"
  891 +// }
  892 +// ],
  893 +// "remain_time": 0,
  894 +// "selected_goods_count": 12,
  895 +// "shipping_cost": 0,
  896 +// "str_discount_amount": "¥172.80",
  897 +// "str_order_amount": "¥971.00"
  898 +// },
  899 +// "sold_out_goods_list": []
  900 +// }
  901 +// },
  902 +// "md5": "4fd4cbe259627fea6b1c68a0fb6c217a",
  903 +// "message": "cart goods list."
  904 +// }))
  905 +// })
  906 + return cartProcess.processData(data);
54 }); 907 });
55 }; 908 };
56 909
57 -const processData = (data, isAdvanceCart) => {  
58 - let result = {};  
59 -  
60 - // 购买的可用商品列表  
61 - result.goods = _.get(data, 'goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart); });  
62 - result.promotionPoolList = _.get(data, 'promotion_pool_list', []).map(promotion => {  
63 - return {  
64 - goods: _.get(promotion, 'goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart); }),  
65 - promotions: _.get(promotion, 'promotion_list', []).map(promo => {  
66 - return {  
67 - status: promo.status,  
68 - conditionUnit: promo.condition_unit,  
69 - conditionValue: promo.condition_value,  
70 - giftGoodsList: _.get(promo, 'gift_goods_List', []).map(gift => { return formatAdvanceGoods(gift); }),  
71 - giftPrice: promo.gift_price,  
72 - promotionId: promo.promotion_id,  
73 - promotionTitle: promo.promotion_title,  
74 - promotionType: promo.promotion_type,  
75 - alreadyMatch: promo.alreadyMatch  
76 - };  
77 - })  
78 - }; 910 +/**
  911 + * 购物车商品选择与取消接口
  912 + *
  913 + * @param int $uid 用户ID
  914 + * @param string $sku 商品sku列表
  915 + * @param string $shoppingKey 未登录用户唯一识别码
  916 + * @return array 购物车接口返回的数据
  917 + */
  918 +const selectGood = (uid, sku, shoppingKey) => {
  919 + return api.get('', {
  920 + method: 'app.Shopping.selectedAndQryCart',
  921 + product_sku_list: sku,
  922 + uid: uid,
  923 + shopping_key: shoppingKey
  924 + }).then((data) => {
  925 + return cartProcess.processData(data);
79 }); 926 });
80 -  
81 - // 失效商品列表  
82 - result.notValidGoods = _.get(data, 'sold_out_goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart, false); });  
83 -  
84 - // 下架的商品列表  
85 - result.offShelveGoods = _.get(data, 'off_shelves_goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart, false); });  
86 -  
87 - // 赠品和加价购商品  
88 - if (data.gift_list.length || data.price_gift.length) {  
89 - result.freebieOrAdvanceBuy = true;  
90 -  
91 - // 赠品  
92 - result.freebie = data.gift_list.map(good => { return formatAdvanceGoods(good); });  
93 - result.giftCount = result.freebie.length;  
94 -  
95 - // 加价购  
96 - result.advanceBuy = data.price_gift.map(good => { return formatAdvanceGoods(good); });  
97 - result.advanceBuyCount = result.advanceBuy.length;  
98 - }  
99 -  
100 - // 已参加的活动  
101 - if (data.promotion_info && data.promotion_info.length > 0) {  
102 - result.promotionInfo = data.promotion_info.map(promotion => {  
103 - return {id: promotion.promotion_id, name: promotion.promotion_title};  
104 - });  
105 - }  
106 -  
107 - // 结算数据  
108 - result.formulaPrice = data.shopping_cart_data.promotion_formula;  
109 - result.count = data.shopping_cart_data.selected_goods_count;  
110 - result.isAllSelected = (data.shopping_cart_data.goods_count === data.shopping_cart_data.selected_goods_count) && (data.shopping_cart_data.selected_goods_count > 0);  
111 - result.sumPrice = transPrice(data.shopping_cart_data.last_order_amount);  
112 -  
113 -  
114 - return result;  
115 -}; 927 +}
116 928
117 /** 929 /**
118 - * 格式化加价购和赠品商品 930 + * 移出购物车
119 * 931 *
120 - * @param array $advanceGoods 加价购商品列表  
121 - * @param int $count 计商品件数  
122 - * @return array $arr 处理之后的加价购商品数据 932 + * @param int $uid 用户ID
  933 + * @param string $sku 商品sku列表
  934 + * @param string $shoppingKey 未登录用户唯一识别码
  935 + * @return array 接口返回的数据
123 */ 936 */
124 -const formatAdvanceGoods = (advanceGood, isGift) => {  
125 - let result = {};  
126 -  
127 - result.id = advanceGood.product_skn;  
128 - result.name = advanceGood.product_name;  
129 - result.thumb = advanceGood.goods_images ? helpers.image(advanceGood.goods_images, 120, 160) : '';  
130 - result.price = transPrice(advanceGood.last_price);  
131 - result.marketPrice = isGift ? '0.00' : transPrice(advanceGood.market_price);  
132 - result.count = advanceGood.storage_number;  
133 -  
134 - return result;  
135 -};  
136 - 937 +const removeFromCart = (uid, sku, shoppingKey) => {
  938 + return api.get('', {
  939 + method: 'app.Shopping.removeAndQryCart',
  940 + product_sku_list: sku,
  941 + uid: uid,
  942 + shopping_key: shoppingKey
  943 + }).then((data) => {
  944 + return cartProcess.processData(data);
  945 + });
  946 +}
137 /** 947 /**
138 - * 格式化购物车商品 948 + * 获取购物车商品数据
139 * 949 *
140 - * @param array $cartGoods 购物车商品列表  
141 - * @param boolean $isValid 是否是可用商品(非失效商品),默认是  
142 - * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)  
143 - * @return array 处理之后的购物车商品数据 950 + * @param int $uid 用户ID
  951 + * @param int $skn 商品skn
  952 + * @return array 接口返回的数据
144 */ 953 */
145 -const formatCartGoods = (goodData, isAdvanceCart, isValid) => {  
146 - let result = {};  
147 - result.id = goodData.product_sku;  
148 - result.skn = goodData.product_skn;  
149 - result.name = goodData.product_name;  
150 - result.thumb = goodData.goods_images ? helpers.image(goodData.goods_images, 120, 160) : '';  
151 - result.color = goodData.color_name;  
152 - result.size = goodData.size_name;  
153 - result.checked = goodData.selected === 'Y';  
154 - result.price = transPrice(goodData.last_vip_price);  
155 - result.isVipPrice = goodData.sales_price !== goodData.last_vip_price && goodData.discount_tag === 'V';  
156 - result.isStudents = goodData.sales_price !== goodData.last_vip_price && goodData.discount_tag === 'S';  
157 - result.count = goodData.buy_number;  
158 - result.promotion_id = goodData.promotion_id;  
159 - if (isValid) {  
160 - // 库存不足  
161 - result.lowStocks = (goodData.buy_number > goodData.storage_number);  
162 - } else { // 失效商品  
163 - result.inValid = true;  
164 - }  
165 -  
166 - // gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;  
167 - if (!goodData.goods_type) {  
168 - result.inValid = true;  
169 - }  
170 - else if (goodData.goods_type === 'gift' && !goodData.isAdvanceBuy) {  
171 - result.isGift = true;  
172 - result.salesPrice = transPrice(goodData.sales_price);  
173 - result.price = transPrice(goodData.last_price);  
174 - }  
175 - else if (goodData.goods_type === 'price_gift') {  
176 - result.showCheckbox = true;  
177 - result.isAdvanceBuy = true;  
178 - result.salesPrice = transPrice(goodData.sales_price);  
179 - result.price = transPrice(goodData.last_price);  
180 - }  
181 - else {  
182 - result.showCheckbox = true;  
183 - }  
184 -  
185 - // 上市期  
186 - if (isAdvanceCart && goodData.expect_arrival_time) {  
187 - result.appearDate = goodData.expect_arrival_time;  
188 - } 954 +const cartProductData = (uid, skn) => {
  955 + return api.get('', {
  956 + method: 'app.product.data',
  957 + product_skn: skn,
  958 + uid: uid,
  959 + showcomment: 'N'
  960 + }).then((data) => {
  961 + return cartProcess.procGoodsDetail(data);
  962 + });
  963 +}
189 964
190 - // 商品链接  
191 - result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`);  
192 -}; 965 +/**
  966 + * 修改购物车商品数量-增加
  967 + *
  968 + * @param int $uid 用户ID
  969 + * @param string $sku 商品SKU
  970 + * @param int $increaseNum 增加的数目
  971 + * @param string $shoppingKey 未登录用户唯一识别码
  972 + * @return array 接口返回的数据
  973 + */
  974 +const increaseProductNum = (uid, sku, increaseNum, shoppingKey) => {
  975 + return api.get('', {
  976 + method: 'app.Shopping.increase',
  977 + product_sku: sku,
  978 + increase_number: increaseNum,
  979 + uid: uid,
  980 + shopping_key: shoppingKey
  981 + });
  982 +}
  983 +/**
  984 + * 修改购物车商品数量-减少
  985 + *
  986 + * @param int $uid 用户ID
  987 + * @param string $sku 商品SKU
  988 + * @param int $decreaseNum 减少的数目
  989 + * @param string $shoppingKey 未登录用户唯一识别码
  990 + * @return array 接口返回的数据
  991 + */
  992 +const decreaseProductNum = (uid, sku, decreaseNum, shoppingKey) => {
  993 + return api.get('', {
  994 + method: 'app.Shopping.decrease',
  995 + product_sku: sku,
  996 + decrease_number: decreaseNum,
  997 + uid: uid,
  998 + shopping_key: shoppingKey
  999 + });
  1000 +}
193 1001
194 -const transPrice = (price, isSepcialZero) => {  
195 - return (price || isSepcialZero) ? price.toFixed(2) : 0;  
196 -}; 1002 +/**
  1003 + * 修改购物车商品数据
  1004 + *
  1005 + * @param int $uid 用户ID
  1006 + * @param string $param 要更改的数据
  1007 + * @param string $shoppingKey 未登录用户唯一识别码
  1008 + * @return array 接口返回的数据
  1009 + */
  1010 +const modifyCartProduct = (uid, param, shoppingKey) => {
  1011 + return api.get('', {
  1012 + method: 'app.Shopping.swap',
  1013 + swap_data: param,
  1014 + uid: uid,
  1015 + shopping_key: shoppingKey
  1016 + });
  1017 +}
  1018 +/**
  1019 + * 移入收藏夹
  1020 + *
  1021 + * @param int $uid 用户ID
  1022 + * @param string $sku 商品sku列表
  1023 + * @return array 接口返回的数据
  1024 + */
  1025 +const addToFav = (uid, sku) => {
  1026 + return api.get('', {
  1027 + method: 'app.Shopping.addfavoriteAndQryCart',
  1028 + product_sku_list: sku,
  1029 + uid: uid,
  1030 + shopping_key: shoppingKey
  1031 + }).then((data) => {
  1032 + return cartProcess.processData(data);
  1033 + });
  1034 +}
197 1035
198 module.exports = { 1036 module.exports = {
199 - indexData 1037 + indexData,
  1038 + selectGood,
  1039 + removeFromCart,
  1040 + cartProductData,
  1041 + addToFav,
  1042 + increaseProductNum,
  1043 + decreaseProductNum
200 } 1044 }
@@ -40,6 +40,10 @@ router.get('/index/new/invoiceInfo', authMW, order.invoiceInfo); // 发票信息 @@ -40,6 +40,10 @@ router.get('/index/new/invoiceInfo', authMW, order.invoiceInfo); // 发票信息
40 40
41 router.get('/index/new', indexController.index); // 购物车 41 router.get('/index/new', indexController.index); // 购物车
42 router.post('/index/new/data', indexController.indexData); // 购物车 42 router.post('/index/new/data', indexController.indexData); // 购物车
  43 +router.post('/index/new/select', indexController.select); // 选择取消购物车商品
  44 +router.post('/index/new/del', indexController.del); // 删除购物车商品
  45 +router.post('/index/new/goodinfo', indexController.goodinfo); // 获取购物车商品数据,chosepanel
  46 +router.post('/index/new/modifyNum', indexController.modifyNum); // 获取购物车商品数量
43 47
44 48
45 module.exports = router; 49 module.exports = router;
  1 +{{> cart/chose-panel}}
@@ -1843,88 +1843,79 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { @@ -1843,88 +1843,79 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
1843 let notForSale = origin.attribute === 2; 1843 let notForSale = origin.attribute === 2;
1844 let preSale = (origin.status === 0 && origin.advance_shelve_time > 0); 1844 let preSale = (origin.status === 0 && origin.advance_shelve_time > 0);
1845 1845
1846 - // 悬浮的购物车信息  
1847 - dest.cartInfo = {  
1848 - cartUrl: helpers.urlFormat('/cart/index/index'),  
1849 - numInCart: 0,  
1850 - goodsInstore: origin.storage_sum  
1851 - };  
1852 -  
1853 - // 显示加入购物车链接  
1854 - if (!soldOut && !notForSale && !preSale || origin.isLimitBuy) {  
1855 - _.orderBy(colorGroup);  
1856 - Object.assign(dest.cartInfo, {  
1857 - productId: origin.product_id,  
1858 - thumbs: thumbImageList,  
1859 - name: dest.goodsName || '',  
1860 - price: dest.goodsPrice.previousPrice ? dest.goodsPrice.previousPrice : '',  
1861 - salePrice: dest.goodsPrice.currentPrice ? dest.goodsPrice.currentPrice : '',  
1862 - totalNum: totalStorageNum,  
1863 - colors: _.toArray(colorGroup),  
1864 - sizes: sizeGroup  
1865 - }); 1846 +
  1847 + return new Promise((resolve, reject) => {
  1848 + // 悬浮的购物车信息
  1849 + dest.cartInfo = {
  1850 + cartUrl: helpers.urlFormat('/cart/index/index'),
  1851 + numInCart: 0,
  1852 + goodsInstore: origin.storage_sum
  1853 + };
  1854 + // 显示加入购物车链接
  1855 + if (!soldOut && !notForSale && !preSale || origin.isLimitBuy) {
  1856 + _.orderBy(colorGroup);
  1857 + Object.assign(dest.cartInfo, {
  1858 + productId: origin.product_id,
  1859 + thumbs: thumbImageList,
  1860 + name: dest.goodsName || '',
  1861 + price: dest.goodsPrice.previousPrice ? dest.goodsPrice.previousPrice : '',
  1862 + salePrice: dest.goodsPrice.currentPrice ? dest.goodsPrice.currentPrice : '',
  1863 + totalNum: totalStorageNum,
  1864 + colors: _.toArray(colorGroup),
  1865 + sizes: sizeGroup
  1866 + });
1866 1867
1867 - // 限购商品  
1868 - if (origin.isLimitBuy) {  
1869 - return api.get('', {  
1870 - method: 'app.limitProduct.productStatus',  
1871 - limitProductCode: origin.limitProductCode,  
1872 - uid: uid,  
1873 - product_skn: origin.product_skn  
1874 - }, {  
1875 - code: 200,  
1876 - cache: true  
1877 - }).then((result) => {  
1878 - if (result.data) {  
1879 - if (!result.data.isLimitBuy) { 1868 + // 限购商品
  1869 + if (origin.isLimitBuy) {
  1870 + return api.get('', {
  1871 + method: 'app.limitProduct.productStatus',
  1872 + limitProductCode: origin.limitProductCode,
  1873 + uid: uid,
  1874 + product_skn: origin.product_skn
  1875 + }, {
  1876 + code: 200,
  1877 + cache: true
  1878 + }).then((result) => {
  1879 + if (result.data) {
  1880 + if (!result.data.isLimitBuy) {
  1881 + dest.cartInfo.soldOut = true;
  1882 + return resolve(dest);
  1883 + }
  1884 +
  1885 + // 是否开售
  1886 + let isBeginSale = (result.data.saleStatus === 1);
  1887 +
  1888 + // 限购商品有关的展示状态
  1889 + let showStatus = 1;
  1890 +
  1891 + origin.showStatus && (showStatus = parseInt(result.data.showStatus, 10));
  1892 +
  1893 + // 处理限购商品有关的按钮状态
  1894 + dest = _procShowStatus(dest, showStatus, isBeginSale);
  1895 +
  1896 + dest.cartInfo.limitProductCode = origin.limitProductCode;
  1897 + dest.cartInfo.limitCodeUrl = _getLimitCodeUrl(origin.limitProductCode, origin.product_skn, ua);
  1898 + dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure');
  1899 + return resolve(dest);
  1900 + } else {
1880 dest.cartInfo.soldOut = true; 1901 dest.cartInfo.soldOut = true;
1881 - return callback(); 1902 + return resolve(dest);
1882 } 1903 }
1883 1904
1884 - // 是否开售  
1885 - let isBeginSale = (result.data.saleStatus === 1);  
1886 -  
1887 - // 限购商品有关的展示状态  
1888 - let showStatus = 1;  
1889 -  
1890 - origin.showStatus && (showStatus = parseInt(result.data.showStatus, 10));  
1891 -  
1892 - // 处理限购商品有关的按钮状态  
1893 - dest = _procShowStatus(dest, showStatus, isBeginSale);  
1894 -  
1895 - dest.cartInfo.limitProductCode = origin.limitProductCode;  
1896 - dest.cartInfo.limitCodeUrl = _getLimitCodeUrl(origin.limitProductCode, origin.product_skn, ua);  
1897 - dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure');  
1898 - return callback();  
1899 - } else {  
1900 - dest.cartInfo.soldOut = true;  
1901 - return callback();  
1902 - }  
1903 -  
1904 - });  
1905 - } else {  
1906 - dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.product_id + '_' +  
1907 - origin.goods_id + '.html');  
1908 - return callback(); 1905 + });
  1906 + } else {
  1907 + dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.product_id + '_' +
  1908 + origin.goods_id + '.html');
  1909 + }
  1910 + } else if (notForSale && !preSale) {
  1911 + dest.cartInfo.notForSale = true;
  1912 + } else if (soldOut && !preSale) {
  1913 + dest.cartInfo.soldOut = true;
  1914 + } else if (preSale) {
  1915 + dest.cartInfo.preSale = true;
1909 } 1916 }
1910 - } else if (notForSale && !preSale) {  
1911 - dest.cartInfo.notForSale = true;  
1912 - return callback();  
1913 - } else if (soldOut && !preSale) {  
1914 - dest.cartInfo.soldOut = true;  
1915 - return callback();  
1916 - } else if (preSale) {  
1917 - dest.cartInfo.preSale = true;  
1918 - return callback();  
1919 - }  
1920 -  
1921 - // 是否收藏 使用单独收藏接口获取  
1922 - // dest.isCollect = false;  
1923 - // if (origin.is_collect === 'Y') {  
1924 - // dest.isCollect = true;  
1925 - // dest.cartInfo.isCollect = true;  
1926 - // }  
1927 - function callback() { 1917 + return resolve(dest);
  1918 + }).then(dest => {
1928 // 虚拟商品(门票) 1919 // 虚拟商品(门票)
1929 if (origin.attribute * 1 === 3) { 1920 if (origin.attribute * 1 === 3) {
1930 dest.tickets = true; 1921 dest.tickets = true;
@@ -1954,22 +1945,13 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { @@ -1954,22 +1945,13 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
1954 if (dest.isSecKill === 'Y' && dest.cartInfo.totalNum > 0) { 1945 if (dest.isSecKill === 'Y' && dest.cartInfo.totalNum > 0) {
1955 dest.totalNum = 1; 1946 dest.totalNum = 1;
1956 } 1947 }
1957 - return Promise.resolve(dest);  
1958 - } 1948 + return dest;
  1949 + })
  1950 +};
1959 1951
1960 - return api.get('', {  
1961 - method: 'app.shop.queryShopsByBrandId',  
1962 - brand_id: _.toString(brandId)  
1963 - }, {  
1964 - cache: true  
1965 - }).then(shops => {  
1966 - if (shops && shops.code === 200) {  
1967 - return _processShopsInfo(shops.data);  
1968 - } 1952 +const detailCartDataPkgAsync = (origin) => {
1969 1953
1970 - return [];  
1971 - });  
1972 -}; 1954 +}
1973 1955
1974 1956
1975 /** 1957 /**
  1 +{{#cartInfo}}
  2 +<div class="chose-panel">
  3 + <div class="main">
  4 + <div class="infos {{#if ../tickets}}tickets-info{{/if}}">
  5 + <div class="basic-info" >
  6 + {{#thumbs}}
  7 + <img class="thumb {{#unless @first}}hide{{/unless}}" src={{img}}>
  8 + {{/thumbs}}
  9 + <div class="text-info">
  10 + <p class="name">{{name}}</p>
  11 + <p class="price">
  12 + <span class="sale-price{{^price}} no-price{{/price}}">{{salePrice}}</span>
  13 + {{#if price}}
  14 + <span class="market-price">{{price}}</span>
  15 + {{/if}}
  16 + </p>
  17 + </div>
  18 + </div>
  19 + <div class="chose-items">
  20 + <div class="color-list block-list">
  21 + <span>{{colorName}}</span>
  22 + {{# colors}}
  23 + <ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/unless}}">
  24 + {{# color}}
  25 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}">
  26 + {{name}}
  27 + </li>
  28 + {{/ color}}
  29 + </ul>
  30 + {{/ colors}}
  31 + </div>
  32 + <div class="size-list block-list {{#if ../single}}hide{{/if}}">
  33 + <span>{{sizeName}}</span>
  34 + {{# sizes}}
  35 + <ul class="size-row clearfix {{#unless @first}}hide{{/unless}}">
  36 + {{# size}}
  37 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}" data-skuid="{{skuId}}">
  38 + {{name}}
  39 + </li>
  40 + {{/ size}}
  41 + </ul>
  42 + {{/ sizes}}
  43 + </div>
  44 + <p>
  45 + <div class="num">
  46 + <span>数量</span>
  47 + <div class="clearfix">
  48 + <a class="btn btn-minus" href="javascript:void(0);">
  49 + <span class="iconfont {{#if promotionId}}disabled{{/if}}">&#xe625;</span>
  50 + </a>
  51 + <input id="good-num" class="good-num disabled" type="text" value="1" disabled="true">
  52 + <a class="btn btn-plus" href="javascript:void(0);">
  53 + <span class="iconfont {{#if promotionId}}disabled{{/if}}">&#xe624;</span>
  54 + </a>
  55 + </div>
  56 + <span class="left-num"></span>
  57 + <input id="left-num" type="hidden" value="0">
  58 + <input id="limitNum" type="hidden" value="{{limit}}">
  59 + </div>
  60 + </div>
  61 + </div>
  62 + <div class="btn-wrap">
  63 + <button id="chose-btn-sure" class="btn btn-sure">{{#if ../tickets}}立即购买{{else}}加入购物车{{/if}}</button>
  64 + </div>
  65 + </div>
  66 +</div>
  67 +{{/cartInfo}}
  68 +<input id="promotionId" type="hidden" value="{{promotionId}}">
  69 +<input id="single" type="hidden" value="{{single}}">
@@ -29,7 +29,13 @@ @@ -29,7 +29,13 @@
29 <p class="nav-title">{{.}}</p> 29 <p class="nav-title">{{.}}</p>
30 {{/navTitle}} 30 {{/navTitle}}
31 {{#suggestSub}} 31 {{#suggestSub}}
32 - <span class="nav-btn">提交</span> 32 + <span class="nav-btn">
  33 + {{#if text}}
  34 + {{text}}
  35 + {{^}}
  36 + 提交
  37 + {{/if}}
  38 + </span>
33 {{/suggestSub}} 39 {{/suggestSub}}
34 {{#saleNav}} 40 {{#saleNav}}
35 <span class="sale-nav nav-home"> 41 <span class="sale-nav nav-home">
  1 +<div class="normal-box">
  2 + {{#goodPools}}
  3 + <div class="cart-brand box">
  4 + {{#if isPromotion}}
  5 + <div class="promotion-header {{#if promotionMore}}more-box{{/if}}">
  6 + {{#promotions}}
  7 + <div class="promo-item">
  8 + <div class="info"><i class="iconfont cuxiao"></i>{{promotionTitle}}</div>
  9 + <div class="opt to-gift">
  10 + <a href="javascript:;" data-status="{{status}}">{{optTitle}}</a><i class="iconfont to-arrow"></i>
  11 + </div>
  12 + </div>
  13 + {{/promotions}}
  14 + <div class="down-arrow">
  15 + <i class="iconfont arrow"></i>
  16 + </div>
  17 + </div>
  18 + {{#sub_pool}}
  19 + {{#if isPromotion}}
  20 + <div class="promos {{#if promotionMore}}more-box{{/if}}">
  21 + {{#promotions}}
  22 + <div class="promo-item">
  23 + <div class="info">
  24 + <span class="flag">加价购</span>差1件立享【满¥399减100】
  25 + </div>
  26 + <div class="opt to-gift">
  27 + <a href="#">去凑单</a><i class="iconfont to-arrow"></i>
  28 + </div>
  29 + </div>
  30 + {{/promotions}}
  31 + <div class="down-arrow">
  32 + <i class="iconfont arrow"></i>
  33 + </div>
  34 + </div>
  35 + {{/if}}
  36 + {{#goods}}
  37 + {{> cart-good}}
  38 + {{/goods}}
  39 + {{/sub_pool}}
  40 + {{/if}}
  41 + {{#if isBrand}}
  42 + <div class="good-list">
  43 + {{#goods}}
  44 + {{> cart-good}}
  45 + {{/goods}}
  46 + </div>
  47 + {{/if}}
  48 + </div>
  49 + {{/goodPools}}
  50 + {{#goods}}
  51 + <div class="cart-brand box">
  52 + <div class="good-list">
  53 + {{> cart-good}}
  54 + </div>
  55 + </div>
  56 + {{/goods}}
  57 +</div>
  58 +{{#if freebieOrAdvanceBuy}}
  59 +<div class="all-gift-box box">
  60 + {{#if freebie}}
  61 + <div class="gift-item">
  62 + <div class="flag">
  63 + <i class="iconfont gift"></i>
  64 + </div>
  65 + <div class="content">
  66 + <div class="info">已满足全场加价购</div>
  67 + <div class="opt to-gift">
  68 + <a href="#">去凑单</a><i class="iconfont to-arrow"></i>
  69 + </div>
  70 + </div>
  71 + </div>
  72 + {{/if}}
  73 + {{#if advanceBuy}}
  74 + <div class="gift-item">
  75 + <div class="flag">
  76 + <i class="iconfont price-gift"></i>
  77 + </div>
  78 + <div class="content">
  79 + <div class="info">已满足全场加价购</div>
  80 + <div class="opt to-gift">
  81 + <a href="#">去凑单</a><i class="iconfont to-arrow"></i>
  82 + </div>
  83 + </div>
  84 + </div>
  85 + {{/if}}
  86 +</div>
  87 +{{/if}}
  88 +{{#if hasNoSaleGoods}}
  89 +<div class="disable-box box">
  90 + {{#notValidGoods}}
  91 + {{> cart-good}}
  92 + {{/notValidGoods}}
  93 + {{#offShelveGoods}}
  94 + {{> cart-good}}
  95 + {{/offShelveGoods}}
  96 +
  97 + <div class="remove-all">
  98 + <button class="btn btn-remove">清空失效商品</button>
  99 + </div>
  100 +</div>
  101 +{{/if}}
  102 +<div class="total box">
  103 + {{#if promotionInfo.length}}
  104 + <div class="activity-title">
  105 + <h1>已参与活动</h1>
  106 + </div>
  107 + <div class="activity">
  108 + <ul>
  109 + {{#promotionInfo}}
  110 + <li>{{name}}</li>
  111 + {{/promotionInfo}}
  112 + </ul>
  113 + </div>
  114 + {{/if}}
  115 + <div class="price-compute">
  116 + <p>{{formulaPrice}}</p>
  117 + </div>
  118 +</div>
  119 +<div class="cart-footer">
  120 + <div class="check-all">
  121 + <i class="iconfont chk select {{#if isAllSelected}}checked{{/if}}"></i>
  122 + <i class="iconfont chk edit"></i>
  123 + <p>全选</p>
  124 + </div>
  125 + <div class="opts edit">
  126 + <button class="btn btn-gray btn-fav">移入<br>收藏夹</button>
  127 + <button class="btn btn-red btn-del">删除</button>
  128 + </div>
  129 + <div class="opts bill ">
  130 + <div class="total">
  131 + <p class="price">总计:¥{{sumPrice}}&nbsp;&nbsp;({{count}}件)</p>
  132 + <p class="intro">不含运费</p>
  133 + </div>
  134 + <button class="btn btn-red">结算</button>
  135 + </div>
  136 +</div>
1 -<div class="cart-good edit">  
2 - <div class="promos more-box ">  
3 - <div class="promo-item">  
4 - <div class="info">  
5 - <span class="flag">加价购</span>差1件立享【满¥399减100】  
6 - </div>  
7 - <div class="opt to-gift">  
8 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
9 - </div>  
10 - </div>  
11 - <div class="promo-item">  
12 - <div class="info">  
13 - <span class="flag">加价购</span>差1件立享【满¥399减100】  
14 - </div>  
15 - <div class="opt to-gift">  
16 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
17 - </div>  
18 - </div>  
19 - <div class="promo-item">  
20 - <div class="info">  
21 - <span class="flag">加价购</span>差1件立享【满¥399减100】  
22 - </div>  
23 - <div class="opt to-gift">  
24 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
25 - </div>  
26 - </div>  
27 - <div class="down-arrow">  
28 - <i class="iconfont arrow"></i>  
29 - </div> 1 +<div class="good-item{{#if lowStocks}} low-stocks{{/if}}{{#if isStudents}} is-students{{/if}}{{#if isVipPrice}} is-vip-price{{/if}}" data-promotion="{{promotion_id}}" data-id="{{id}}" data-skn="{{skn}}">
  2 + <div class="opt">
  3 + {{#if showCheckbox}}
  4 + <i class="iconfont chk select {{#if checked}}checked{{/if}}"></i>
  5 + <i class="iconfont chk edit"></i>
  6 + {{/if}}
  7 + {{#inValid}}
  8 + <span class="disable fill-text">失效</span>
  9 + {{/inValid}}
30 </div> 10 </div>
31 - <div class="good-item">  
32 - <div class="opt">  
33 - <i class="iconfont chk "></i>  
34 - {{!-- <span class="disable fill-text">失效</span> --}}  
35 - </div>  
36 - <div class="good-new-info">  
37 - <a href="//m.yohobuy.com/product/show_{{product_skn}}.html" class="img-a">  
38 - <div class="img">  
39 - <img class="thumb lazy" src="//img12.static.yhbimg.com/goodsimg/2016/12/21/17/02a2809c6b69141c032b9978a2f61d9958.jpg?imageMogr2/thumbnail/120x160/extent/120x160/background/d2hpdGU=/position/center/quality/80" alt=""> 11 + <div class="good-new-info">
  12 + <a href="{{link}}" class="img-a">
  13 + <div class="img">
  14 + <img class="thumb lazy" data-original="{{thumb}}" alt="">
  15 + {{#isGift}}
  16 + <div class="flag gift"><div class="text">赠品</div></div>
  17 + {{/isGift}}
  18 + {{#isAdvanceBuy}}
40 <div class="flag price-gift"><div class="text">加价购</div></div> 19 <div class="flag price-gift"><div class="text">加价购</div></div>
41 - </div>  
42 - </a>  
43 - <div class="info">  
44 - <div class="fixed-height">  
45 - <div class="intro intro-name">  
46 - <div class="name-row">  
47 - <div class="name">  
48 - <a href="//m.yohobuy.com/product/show_{{product_skn}}.html">EBLIS时拼色EBLIS时拼色EBLIS时拼色时尚拼色EBLI色EBLIS时拼色EBLIS时拼色时尚拼色EBLI色EBLIS时拼色EBLIS时拼色时尚拼色EBLI色EBLIS时拼色时尚拼色EBLI色</a>  
49 - </div> 20 + {{/isAdvanceBuy}}
  21 + </div>
  22 + </a>
  23 + <div class="info">
  24 + <div class="fixed-height">
  25 + <div class="intro intro-name">
  26 + <div class="name-row">
  27 + <div class="name">
  28 + <a href="{{link}}">{{name}}</a>
50 </div> 29 </div>
51 - <p class="color-size-row"><span class="color">颜色:黑色</span><span class="size">尺码:S</span></p>  
52 </div> 30 </div>
53 - <div class="intro intro-edit">  
54 - <div class="edit-box">  
55 - <div class="num-opt">  
56 - <a href="javascript:;" class="btn btn-minus "><span class="iconfont"></span></a>  
57 - <input type="text" class="good-num" disabled="true" value="1">  
58 - <a href="javascript:;" class="btn btn-plus"><span class="iconfont"></span></a>  
59 - </div>  
60 - <div class="size-info">  
61 - <div class="txt">颜色:黑色 尺码:S</div>  
62 - <div class="down">  
63 - <i class="iconfont"></i>  
64 - </div> 31 + <p class="color-size-row"><span class="color">颜色:{{color}}</span><span class="size">尺码:{{size}}</span></p>
  32 + </div>
  33 + <div class="intro intro-edit">
  34 + <div class="edit-box">
  35 + <div class="num-opt">
  36 + <a href="javascript:;" class="btn btn-opt-minus{{#if minSelectNum}} disabled{{/if}}"><span class="iconfont"></span></a>
  37 + <input type="text" class="good-num" disabled="true" value="{{count}}" data-min="{{minNumber}}" data-max="{{maxNumber}}">
  38 + <a href="javascript:;" class="btn btn-opt-plus"><span class="iconfont"></span></a>
  39 + </div>
  40 + <div class="size-info">
  41 + <div class="txt">颜色:{{color}} 尺码:{{size}}</div>
  42 + <div class="down">
  43 + <i class="iconfont"></i>
65 </div> 44 </div>
66 </div> 45 </div>
67 </div> 46 </div>
68 - <div class="count">x1</div>  
69 - </div>  
70 - <p class="price">  
71 - <span class="market-price">¥1119.66</span>  
72 - <span class="vip fill-text">VIP</span>  
73 - <span class="vip fill-text"></span>  
74 - </p>  
75 - <div class="tags">  
76 - <span class="low-stocks fill-text">库存不足</span>  
77 - <span class="appear-date">上市期:2015年13月</span>  
78 </div> 47 </div>
  48 + <div class="count">x{{count}}</div>
  49 + </div>
  50 + <p class="price">
  51 + <span class="market-price">{{price}}</span>
  52 + {{#if isStudents}}<span class="vip fill-text"></span>{{/if}}
  53 + {{#if isVipPrice}}<span class="vip fill-text">VIP</span>{{/if}}
  54 + </p>
  55 + <div class="tags">
  56 + {{#if lowStocks}}<span class="low-stocks fill-text">库存不足</span>{{/if}}
  57 + {{#appearDate}}<span class="appear-date">上市期:{{appearDate}}</span>{{/appearDate}}
79 </div> 58 </div>
80 </div> 59 </div>
81 </div> 60 </div>
82 -</div>  
  61 +</div>
1 {{#if cartNav}} 1 {{#if cartNav}}
2 <ul class="cart-nav clearfix"> 2 <ul class="cart-nav clearfix">
3 - <li class="active" id="common-cart-nav"> 3 + <li class="active" id="common-cart-nav" data-type="normal-good">
4 <span>普通商品({{commonGoodsCount}})</span> 4 <span>普通商品({{commonGoodsCount}})</span>
5 </li> 5 </li>
6 - <li id="presell-cart-nav"> 6 + <li id="presell-cart-nav" data-type="advance-good">
7 <span >预售商品({{presellGoodsCount}})</span> 7 <span >预售商品({{presellGoodsCount}})</span>
8 <div id="presell-tip" class="presell-tip hide"> 8 <div id="presell-tip" class="presell-tip hide">
9 <div class="triangle"></div> 9 <div class="triangle"></div>
@@ -12,93 +12,17 @@ @@ -12,93 +12,17 @@
12 </li> 12 </li>
13 </ul> 13 </ul>
14 {{/if}} 14 {{/if}}
15 -<div class="cart-content normal-good">  
16 - <div class="normal-box">  
17 - <div class="cart-brand box">  
18 - <div class="promotion-header more-box ">  
19 - <div class="promo-item">  
20 - <div class="info"><i class="iconfont cuxiao"></i>差¥200立享【满¥699减100】</div>  
21 - <div class="opt to-gift">  
22 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
23 - </div>  
24 - </div>  
25 - <div class="promo-item">  
26 - <div class="info"><i class="iconfont cuxiao"></i>差¥200立享【满¥699减100】</div>  
27 - <div class="opt to-gift">  
28 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
29 - </div>  
30 - </div>  
31 - <div class="down-arrow">  
32 - <i class="iconfont arrow"></i>  
33 - </div>  
34 - </div>  
35 - <div class="good-list">  
36 - {{> cart-good}}  
37 - </div>  
38 - </div>  
39 - </div>  
40 - <div class="all-gift-box box">  
41 - <div class="gift-item">  
42 - <div class="flag">  
43 - <i class="iconfont gift"></i>  
44 - </div>  
45 - <div class="content">  
46 - <div class="info">已满足全场加价购</div>  
47 - <div class="opt to-gift">  
48 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
49 - </div>  
50 - </div>  
51 - </div>  
52 - <div class="gift-item">  
53 - <div class="flag">  
54 - <i class="iconfont price-gift"></i>  
55 - </div>  
56 - <div class="content">  
57 - <div class="info">已满足全场加价购</div>  
58 - <div class="opt to-gift">  
59 - <a href="#">去凑单</a><i class="iconfont to-arrow"></i>  
60 - </div>  
61 - </div>  
62 - </div>  
63 - </div>  
64 - <div class="disable-box box">  
65 - {{> cart-good}}  
66 - <div class="remove-all">  
67 - <button class="btn btn-remove">清空失效商品</button>  
68 - </div>  
69 - </div>  
70 - <div class="total box">  
71 - <div class="activity-title">  
72 - <h1>已参与活动</h1>  
73 - </div>  
74 - <div class="activity">  
75 - <ul>  
76 - <li>【大牌盛宴】下单7折</li>  
77 - <li>满¥399免运费</li>  
78 - </ul>  
79 - </div>  
80 - <div class="price-compute">  
81 - <p>总计¥1896.60=商品金额¥1986.00-活动金额¥89.40</p>  
82 - </div>  
83 - </div> 15 +<div class="cart-content normal-good {{#if ordinaryCart}}active{{/if}}">
  16 + {{#commonCart}}
  17 + {{> cart-content}}
  18 + {{/commonCart}}
  19 +</div>
  20 +<div class="cart-content advance-good {{#if advanceCart}}active{{/if}}">
  21 + {{#preSellCart}}
  22 + {{> cart-content}}
  23 + {{/preSellCart}}
84 </div> 24 </div>
85 -<div class="cart-content advance-good hide"></div> 25 +<input id="cartType" type="hidden" value="{{cartType}}">
86 <div class="recommend-for-you box hide"> 26 <div class="recommend-for-you box hide">
87 </div> 27 </div>
88 -<div class="cart-footer">  
89 - <div class="check-all">  
90 - <i class="iconfont chk"></i>  
91 - <p>全选</p>  
92 - </div>  
93 - <div class="opts edit hide">  
94 - <button class="btn btn-gray">移入<br>收藏夹</button>  
95 - <button class="btn btn-red">删除</button>  
96 - </div>  
97 - <div class="opts bill ">  
98 - <div class="total">  
99 - <p class="price">总计:¥0.00&nbsp;&nbsp;(0件)</p>  
100 - <p class="intro">不含运费</p>  
101 - </div>  
102 - <button class="btn btn-red">结算</button>  
103 - </div>  
104 -</div> 28 +
@@ -3,78 +3,38 @@ @@ -3,78 +3,38 @@
3 * @author: feng.chen<feng.chen@yoho.cn> 3 * @author: feng.chen<feng.chen@yoho.cn>
4 * @date: 2016/12/22 4 * @date: 2016/12/22
5 */ 5 */
  6 +'use strict';
6 7
7 require('cart/index.page.css') 8 require('cart/index.page.css')
8 9
9 -let testData = require('./data.json');  
10 -let $ = require('yoho-jquery');  
11 -let hbsTemplate = require('cart/index/index.hbs'); 10 +let testData = require('./data.json'),
  11 + $ = require('yoho-jquery'),
  12 + hbsTemplate = require('cart/index/index.hbs'),
  13 + lazyLoad = require('yoho-jquery-lazyload');
12 14
13 let indexObj = { 15 let indexObj = {
14 - minStock: 1, 16 + editMode: false,
15 init() { 17 init() {
16 let self = this; 18 let self = this;
  19 +
17 $.ajax({ 20 $.ajax({
18 url: '/cart/index/new/data', 21 url: '/cart/index/new/data',
19 type: 'POST', 22 type: 'POST',
20 success: (data) => { 23 success: (data) => {
21 - $('.cart-box').html(hbsTemplate(data)); 24 + self.refreshPage(data.data);
22 } 25 }
23 - })  
24 -  
25 - self.registerEvent();  
26 - self.loadRecommendForYou(); 26 + });
  27 + require('./index/recommend-for-you').init(self);
27 }, 28 },
28 - registerEvent() { 29 + refreshPage(data) {
29 let self = this; 30 let self = this;
30 31
31 - $('.cart-nav').on('click', 'li', function() {  
32 - $('.cart-content').eq($(this).index()).removeClass('hide').siblings('.cart-content').addClass('hide');  
33 - $(this).addClass('active').siblings().removeClass('active')  
34 - });  
35 - $('.more-box>.down-arrow').on('click', function() {  
36 - $(this).parent().toggleClass('down')  
37 - });  
38 - $('.opt>.chk').on('click', function() {  
39 - $(this).toggleClass('checked')  
40 - });  
41 - $('.check-all').on('click', function() {  
42 - $(this).find('.chk').hasClass('checked') ? $('.opt>.chk').removeClass('checked') : $('.opt>.chk').addClass('checked');  
43 - $(this).find('.chk').toggleClass('checked');  
44 - });  
45 - $('.cart-good').on('click', '.num-opt .btn', function(e) {  
46 - let maxStock = 5;  
47 - let minusEl = $(e.delegateTarget).find('.btn-minus');  
48 - let plusEl = $(e.delegateTarget).find('.btn-plus');  
49 - let goodNum = $(e.delegateTarget).find('.good-num').val();  
50 -  
51 - $(this).hasClass('btn-plus') ? goodNum++ : goodNum--;  
52 -  
53 - if (goodNum < self.minStock) {  
54 - console.log('不能小于0')  
55 - return;  
56 - }  
57 - if (goodNum > maxStock) {  
58 - console.log('不能大于5')  
59 - return;  
60 - }  
61 - if (goodNum === self.minStock) {  
62 - $(minusEl).addClass('disabled');  
63 - } else if($(minusEl).hasClass('disabled')) {  
64 - $(minusEl).removeClass('disabled');  
65 - }  
66 - if (goodNum === maxStock) {  
67 - $(plusEl).addClass('disabled');  
68 - } else if($(plusEl).hasClass('disabled')) {  
69 - $(plusEl).removeClass('disabled');  
70 - }  
71 - $(e.delegateTarget).find('.good-num').val(goodNum);  
72 - })  
73 - },  
74 - loadRecommendForYou() {  
75 - if ($('.recommend-for-you').length) {  
76 - require('./recommend-for-you-cart');  
77 - } 32 + $('.main-wrap').removeClass('edit');
  33 + self.editMode = false;
  34 + $('.cart-box').html(hbsTemplate(data));
  35 + require('./index/cart').init(self);
  36 + require('./index/good').init(self);
  37 + lazyLoad($('img.lazy'));
78 } 38 }
79 } 39 }
80 40
  1 +/**
  2 + * 购物车页面操作
  3 + * @author: feng.chen<feng.chen@yoho.cn>
  4 + * @date: 2016/12/29
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +let $ = require('yoho-jquery');
  10 +
  11 +let cartObj = {
  12 + init(handle) {
  13 + let self = this;
  14 + self.handle = handle;
  15 +
  16 + $('.cart-nav').on('click', 'li', function() {
  17 + $(this).addClass('active').siblings().removeClass('active');
  18 + $(`.${$(this).attr('data-type')}`).addClass('active').siblings('.cart-content').removeClass('active');
  19 + });
  20 + $('.more-box>.down-arrow').on('click', function() {
  21 + $(this).parent().toggleClass('down')
  22 + });
  23 +
  24 + $('.nav-btn').on('click', () => {
  25 + $('.main-wrap').toggleClass('edit')
  26 + if ($('.main-wrap').hasClass('edit')) {
  27 + self.handle.editMode = true;
  28 + } else {
  29 + self.handle.editMode = false;
  30 + }
  31 + })
  32 +
  33 + }
  34 +}
  35 +
  36 +module.exports = cartObj;
  1 +/**
  2 + * 购物车商品操作
  3 + * @author: feng.chen<feng.chen@yoho.cn>
  4 + * @date: 2016/12/29
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +let $ = require('yoho-jquery'),
  10 + dialog = require('../../plugin/dialog'),
  11 + tip = require('../../plugin/tip'),
  12 + chosePanel = require('../chose-panel'),
  13 + loading = require('../../plugin/loading');
  14 +
  15 +let goodObj = {
  16 + previousEditSkn: 0,
  17 + init(handle) {
  18 + let self = this;
  19 + self.handle = handle;
  20 +
  21 + $('.good-item').on('click', '.num-opt .btn', function(e) {
  22 + let goodNumEle = $(e.delegateTarget).find('.good-num');
  23 + let minNumber = goodNumEle.data('min');
  24 + let maxNumber = goodNumEle.data('max');
  25 +
  26 + let minusEl = $(e.delegateTarget).find('.btn-opt-minus');
  27 + let plusEl = $(e.delegateTarget).find('.btn-opt-plus');
  28 + let oldGoodNum = $(e.delegateTarget).find('.good-num').val();
  29 + let goodNum = oldGoodNum;
  30 +
  31 + $(this).hasClass('btn-opt-plus') ? goodNum++ : goodNum--;
  32 +
  33 + if (goodNum < minNumber) {
  34 + if (minNumber === 1) {
  35 + tip.show('您选择的数量不能为零~')
  36 + } else if(minNumber > 1) {
  37 + tip.show(`量贩商品,${minNumber}件起购`)
  38 + }
  39 + return;
  40 + }
  41 + if (goodNum > maxNumber) {
  42 + tip.show('您选择的数量超过了最大库存量~')
  43 + return;
  44 + }
  45 + if (goodNum === minNumber) {
  46 + $(minusEl).addClass('disabled');
  47 + } else if($(minusEl).hasClass('disabled')) {
  48 + $(minusEl).removeClass('disabled');
  49 + }
  50 + if (goodNum === maxNumber) {
  51 + $(plusEl).addClass('disabled');
  52 + } else if($(plusEl).hasClass('disabled')) {
  53 + $(plusEl).removeClass('disabled');
  54 + }
  55 + self.modifyNum($(e.delegateTarget).data('id'), oldGoodNum, goodNum);
  56 + $(e.delegateTarget).find('.good-num').val(goodNum);
  57 + });
  58 + $('.good-item').on('click', '.chk.select', function() {
  59 + self.selectGood($(this));
  60 + });
  61 + $('.good-item').on('click', '.chk.edit', function() {
  62 + $(this).toggleClass('checked');
  63 + });
  64 + $('.check-all').on('click', function() {
  65 + if (self.handle.editMode) {
  66 + $(this).find('.chk.edit').toggleClass('checked');
  67 + if ($(this).find('.chk.edit').hasClass('checked')) {
  68 + $('.good-item .chk.edit').addClass('checked');
  69 + } else {
  70 + $('.good-item .chk.edit').removeClass('checked');
  71 + }
  72 + } else {
  73 + $(this).find('.chk.select').toggleClass('checked');
  74 +
  75 + self.selectGood($('.good-item:not(.low-stocks) .chk.select'), $(this).find('.chk.select').hasClass('checked'));
  76 + }
  77 + });
  78 + $('.btn-del').on('click', function() {
  79 + if (!$('.good-item .chk.edit.checked').length) {
  80 + tip.show('请至少选择一件商品');
  81 + return;
  82 + }
  83 + self.delGood($('.good-item .chk.edit.checked'));
  84 + });
  85 + $('.good-item').on('click', '.size-info', function(e) {
  86 + let $this = $(this),
  87 + skn = $(e.delegateTarget).data('skn');
  88 +
  89 + let id,
  90 + count,
  91 + canEditNum;
  92 +
  93 + //如果点击的是上次编辑的商品,直接显示chose-pannel
  94 + if (skn === self.previousEditSkn) {
  95 + chosePanel.show();
  96 + return;
  97 + }
  98 + let isSelected = $(e.delegateTarget).find('.chk.select').hasClass('checked');
  99 + id = $(e.delegateTarget).data('id');
  100 + count = $(e.delegateTarget).find('.good-num').val();
  101 + //加价购或者赠品不能编辑数量
  102 + canEditNum = $(e.delegateTarget).find('.flag.gift').length || $(e.delegateTarget).find('.flag.price-gift').length ? false : true;
  103 + e.stopPropagation();
  104 + loading.showLoadingMask();
  105 + $.ajax({
  106 + url: '/cart/index/new/goodinfo',
  107 + data: {
  108 + skn: skn,
  109 + buy_num: count
  110 + },
  111 + type: "POST",
  112 + success: function(res) {
  113 + self.showEditPannelWithSku(res, id, isSelected, canEditNum);
  114 + self.previousEditSkn = skn;
  115 + },
  116 + error: function() {
  117 + loading.hideLoadingMask();
  118 + tip.show('网络异常');
  119 + },
  120 + complete: function() {
  121 + loading.hideLoadingMask();
  122 + }
  123 + });
  124 + })
  125 + },
  126 + selectGood(eles, selectAll) {
  127 + let self = this;
  128 + let skuData = self.getSelectGoodData(eles, selectAll);
  129 +
  130 + $.ajax({
  131 + type: 'post',
  132 + url: '/cart/index/new/select',
  133 + data: {
  134 + skuList: JSON.stringify(skuData)
  135 + }
  136 + }).then(function(data) {
  137 + if (data.code === 200) {
  138 + self.handle.refreshPage(data.data);
  139 + } else if (data.code === 400) {
  140 + tip.show('网络异常');
  141 + }
  142 + }, function() {
  143 + tip.show('网络异常');
  144 + });
  145 + },
  146 + delGood(eles) {
  147 + let self = this;
  148 + let skuData = self.getSelectGoodData(eles).map(ele => {
  149 + delete ele.goods_type;
  150 + delete ele.selected;
  151 + return ele;
  152 + });
  153 +
  154 + $.ajax({
  155 + type: 'post',
  156 + url: '/cart/index/new/del',
  157 + data: {
  158 + skuList: JSON.stringify(skuData)
  159 + }
  160 + }).then(function(data) {
  161 + if (data.code === 200) {
  162 + self.handle.refreshPage(data.data);
  163 + } else if (data.code === 400) {
  164 + tip.show('网络异常');
  165 + }
  166 + }, function() {
  167 + tip.show('网络异常');
  168 + });
  169 + },
  170 + getSelectGoodData(eles, selectAll) {
  171 + return Array.from(eles.map((i, ele) => {
  172 + let $this = $(ele),
  173 + $good = $this.closest('.good-item'),
  174 + id = $good.data('id'),
  175 + promotion = $good.data('promotion');
  176 + console.log
  177 +
  178 + let goodInfo = {};
  179 +
  180 + if (!$this.hasClass('checked') && $good.find('.low-stocks').length > 0) {
  181 + tip.show('库存不足,无法购买');
  182 + return false;
  183 + }
  184 +
  185 + goodInfo.goods_type = $('#cartType').val();
  186 + if (selectAll != undefined) {
  187 + goodInfo.selected = selectAll ? 'Y' : 'N';
  188 + } else {
  189 + goodInfo.selected = $this.hasClass('checked') ? 'N' : 'Y';
  190 + }
  191 + goodInfo.product_sku = id;
  192 + goodInfo.promotion_id = promotion;
  193 + goodInfo.buy_number = $good.find('.good-num').val();
  194 + return goodInfo;
  195 + }))
  196 +
  197 + },
  198 + showEditPannelWithSku (html, id, isSelected, isEditNum) {
  199 + if (html.length < 2) {
  200 + tip.show('出错啦!');
  201 + return false;
  202 + }
  203 +
  204 + //删掉页面上原有的pannel
  205 + chosePanel.remove();
  206 +
  207 + $(html).appendTo('#mainCart');
  208 +
  209 +
  210 + chosePanel.init();
  211 + chosePanel.setEditModeWithSknId(id, isSelected);
  212 +
  213 + if (!isEditNum) {
  214 + chosePanel.disableNumEdit();
  215 + }
  216 +
  217 + chosePanel.show();
  218 + },
  219 + modifyNum (sku, num, newNum) {
  220 + $.ajax({
  221 + type: 'post',
  222 + url: '/cart/index/new/modifyNum',
  223 + data: {
  224 + sku,
  225 + increaseNum: newNum > num ? newNum - num : 0,
  226 + decreaseNum: num > newNum ? num - newNum : 0,
  227 + }
  228 + }).then(function(data) {
  229 + if (data.code === 200) {
  230 + $(`.good-item[data-id="${sku}"]`).find('.good-num').val(newNum)
  231 + } else if (data.code === 400) {
  232 + tip.show('网络异常');
  233 + }
  234 + }, function() {
  235 + tip.show('网络异常');
  236 + });
  237 + }
  238 +}
  239 +
  240 +module.exports = goodObj;
  1 +/**
  2 + * 为你优选操作
  3 + * @author: feng.chen<feng.chen@yoho.cn>
  4 + * @date: 2016/12/29
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +let $ = require('yoho-jquery');
  10 +
  11 +let recommendObj = {
  12 + init(handle) {
  13 + let self = this;
  14 + self.handle = handle;
  15 +
  16 + if ($('.recommend-for-you').length) {
  17 + setTimeout(() => {
  18 + require('../recommend-for-you-cart');
  19 + }, 0)
  20 + }
  21 + }
  22 +}
  23 +
  24 +module.exports = recommendObj;
@@ -21,7 +21,7 @@ $.get('/product/recommend-for-you/cart').then(function(html) { @@ -21,7 +21,7 @@ $.get('/product/recommend-for-you/cart').then(function(html) {
21 PRDID.push($(this).data('id')); 21 PRDID.push($(this).data('id'));
22 }); 22 });
23 23
24 - window.givePoint({ 24 + window.givePoint && window.givePoint({
25 'REC_POSE': 110003, 25 'REC_POSE': 110003,
26 'PRD_ID': PRDID.join(','), 26 'PRD_ID': PRDID.join(','),
27 'PRD_NUM': $('.recommend-for-you .good-info').length, 27 'PRD_NUM': $('.recommend-for-you .good-info').length,
@@ -32,7 +32,7 @@ $.get('/product/recommend-for-you/cart').then(function(html) { @@ -32,7 +32,7 @@ $.get('/product/recommend-for-you/cart').then(function(html) {
32 $recommendForYou.find('.good-info').on('click', 'a', function() { 32 $recommendForYou.find('.good-info').on('click', 'a', function() {
33 var index = $(this).closest('.good-info').index() + 1; 33 var index = $(this).closest('.good-info').index() + 1;
34 34
35 - window.givePoint({ 35 + window.givePoint && window.givePoint({
36 'REC_POSE': 110003, 36 'REC_POSE': 110003,
37 'PRD_ID': $(this).closest('.good-info').data('id'), 37 'PRD_ID': $(this).closest('.good-info').data('id'),
38 'PRD_NUM': index, 38 'PRD_NUM': index,
1 .good-item { 1 .good-item {
2 display: flex; 2 display: flex;
3 width: 100%; 3 width: 100%;
  4 + min-height: 246px;
4 5
5 &:last-child { 6 &:last-child {
6 .good-new-info { 7 .good-new-info {
@@ -18,6 +19,14 @@ @@ -18,6 +19,14 @@
18 align-items: center; 19 align-items: center;
19 justify-content: center; 20 justify-content: center;
20 21
  22 + .select {
  23 + display: block;
  24 + }
  25 +
  26 + .edit {
  27 + display: none;
  28 + }
  29 +
21 .disable { 30 .disable {
22 background-color: #7f7f7f; 31 background-color: #7f7f7f;
23 } 32 }
@@ -141,7 +150,8 @@ @@ -141,7 +150,8 @@
141 position: relative; 150 position: relative;
142 151
143 .thumb { 152 .thumb {
144 - width: 154px; 153 + width: 152px;
  154 + min-height: 204px;
145 } 155 }
146 156
147 .flag { 157 .flag {
@@ -226,6 +236,7 @@ @@ -226,6 +236,7 @@
226 } 236 }
227 237
228 .appear-date { 238 .appear-date {
  239 + display: none;
229 padding: 4px 0px; 240 padding: 4px 0px;
230 float: left; 241 float: left;
231 font-size: 23px; 242 font-size: 23px;
@@ -246,21 +257,21 @@ @@ -246,21 +257,21 @@
246 } 257 }
247 258
248 .edit-box { 259 .edit-box {
249 - width: 240px; 260 + width: 280px;
250 margin-bottom: 11px; 261 margin-bottom: 11px;
251 262
252 .num-opt { 263 .num-opt {
253 - height: 64px; 264 + height: 74px;
254 border: solid 1PX #dfdfdf; 265 border: solid 1PX #dfdfdf;
255 border-radius: 5px 5px 0px 0px; 266 border-radius: 5px 5px 0px 0px;
256 display: flex; 267 display: flex;
257 268
258 .btn { 269 .btn {
259 - width: 70px; 270 + width: 80px;
260 display: block; 271 display: block;
261 height: 100%; 272 height: 100%;
262 text-align: center; 273 text-align: center;
263 - line-height: 64px; 274 + line-height: 74px;
264 275
265 .iconfont { 276 .iconfont {
266 color: #444444; 277 color: #444444;
@@ -272,7 +283,7 @@ @@ -272,7 +283,7 @@
272 } 283 }
273 } 284 }
274 285
275 - &.btn-minus { 286 + &.btn-opt-minus {
276 border-right: 1PX solid #dfdfdf; 287 border-right: 1PX solid #dfdfdf;
277 288
278 .iconfont:before { 289 .iconfont:before {
@@ -280,7 +291,7 @@ @@ -280,7 +291,7 @@
280 } 291 }
281 } 292 }
282 293
283 - &.btn-plus { 294 + &.btn-opt-plus {
284 border-left: 1px solid #dfdfdf; 295 border-left: 1px solid #dfdfdf;
285 296
286 .iconfont:before { 297 .iconfont:before {
@@ -290,7 +301,7 @@ @@ -290,7 +301,7 @@
290 } 301 }
291 302
292 .good-num { 303 .good-num {
293 - width: 100px; 304 + width: 120px;
294 text-align: center; 305 text-align: center;
295 color: #444444; 306 color: #444444;
296 font-size: 32px; 307 font-size: 32px;
@@ -302,8 +313,8 @@ @@ -302,8 +313,8 @@
302 313
303 .size-info { 314 .size-info {
304 width: 100%; 315 width: 100%;
305 - height: 64px;  
306 - line-height: 64px; 316 + height: 74px;
  317 + line-height: 74px;
307 padding-left: 14px; 318 padding-left: 14px;
308 border: solid 1PX #dfdfdf; 319 border: solid 1PX #dfdfdf;
309 border-top: none; 320 border-top: none;
@@ -321,7 +332,7 @@ @@ -321,7 +332,7 @@
321 332
322 .down { 333 .down {
323 text-align: center; 334 text-align: center;
324 - width: 45px; 335 + width: 55px;
325 336
326 .iconfont { 337 .iconfont {
327 font-size: 30px; 338 font-size: 30px;
@@ -335,18 +346,40 @@ @@ -335,18 +346,40 @@
335 } 346 }
336 } 347 }
337 348
338 -.cart-good {  
339 - &.edit {  
340 - .info {  
341 - padding-top: 0px; 349 +.cart-content {
  350 + &.advance-good {
  351 + .appear-date {
  352 + display: block;
342 } 353 }
  354 + }
  355 +}
343 356
344 - .intro-name {  
345 - display: none;  
346 - } 357 +.main-wrap.edit {
  358 + .cart-content.active {
  359 + .normal-box {
  360 + .good-item {
  361 + .info {
  362 + padding-top: 0px;
  363 + }
347 364
348 - .intro-edit {  
349 - display: block; 365 + .opt {
  366 + .select {
  367 + display: none;
  368 + }
  369 +
  370 + .edit {
  371 + display: block;
  372 + }
  373 + }
  374 +
  375 + .intro-name {
  376 + display: none;
  377 + }
  378 +
  379 + .intro-edit {
  380 + display: block;
  381 + }
  382 + }
350 } 383 }
351 } 384 }
352 -}  
  385 +}
@@ -6,8 +6,21 @@ body { @@ -6,8 +6,21 @@ body {
6 margin-bottom: 120px; 6 margin-bottom: 120px;
7 overflow-x: hidden; 7 overflow-x: hidden;
8 8
  9 + .cart-content {
  10 + display: none;
  11 +
  12 + &.active {
  13 + display: block;
  14 + }
  15 + }
  16 +
9 .box { 17 .box {
10 background-color: #fff; 18 background-color: #fff;
  19 + margin-top: 20px;
  20 +
  21 + &.cart-brand:first-child {
  22 + margin-top: 0px;
  23 + }
11 } 24 }
12 25
13 .cart-nav { 26 .cart-nav {
@@ -244,6 +257,45 @@ body { @@ -244,6 +257,45 @@ body {
244 } 257 }
245 } 258 }
246 259
  260 +.main-wrap {
  261 + .nav-btn {
  262 + &:before {
  263 + content: "编辑";
  264 + }
  265 + }
  266 +}
  267 +.main-wrap.edit {
  268 + .nav-btn {
  269 + &:before {
  270 + content: "完成";
  271 + }
  272 + }
  273 + .cart-content.active {
  274 + .cart-footer {
  275 + .check-all {
  276 + .select {
  277 + display: none;
  278 + }
  279 +
  280 + .edit {
  281 + display: block;
  282 + }
  283 + }
  284 +
  285 + .opts {
  286 + &.edit {
  287 + display: flex;
  288 + }
  289 +
  290 + &.bill {
  291 + display: none;
  292 + }
  293 + }
  294 + }
  295 + }
  296 +}
  297 +
  298 +
247 .cart-footer { 299 .cart-footer {
248 z-index: 99; 300 z-index: 99;
249 background-color: #fff; 301 background-color: #fff;
@@ -259,6 +311,14 @@ body { @@ -259,6 +311,14 @@ body {
259 text-align: center; 311 text-align: center;
260 padding-top: 20px; 312 padding-top: 20px;
261 313
  314 + .select {
  315 + display: block;
  316 + }
  317 +
  318 + .edit {
  319 + display: none;
  320 + }
  321 +
262 p { 322 p {
263 font-size: 26px; 323 font-size: 26px;
264 color: #666; 324 color: #666;
@@ -272,10 +332,14 @@ body { @@ -272,10 +332,14 @@ body {
272 display: flex; 332 display: flex;
273 justify-content: flex-end; 333 justify-content: flex-end;
274 334
275 - &.hide { 335 + &.edit {
276 display: none; 336 display: none;
277 } 337 }
278 338
  339 + &.bill {
  340 + display: flex;
  341 + }
  342 +
279 .btn { 343 .btn {
280 width: 170px; 344 width: 170px;
281 height: 88px; 345 height: 88px;
  1 +/**
  2 + * 购物车处理类
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const helpers = global.yoho.helpers;
  8 +const _ = require('lodash');
  9 +
  10 +const processData = (data) => {
  11 + let cart = data.data;
  12 + let result = {};
  13 + let ordinaryCount = _.get(cart, 'ordinary_cart_data.shopping_cart_data.goods_count', 0);
  14 + let advanceCount = _.get(cart, 'advance_cart_data.shopping_cart_data.goods_count', 0);
  15 + let ordinarySoldOut = _.get(cart, 'ordinary_cart_data.sold_out_goods_list', []);
  16 + let advanceSoldOut = _.get(cart, 'advance_cart_data.sold_out_goods_list', []);
  17 +
  18 + // 普通购物车和预售购物车都为空
  19 + if (ordinaryCount === 0 && advanceCount === 0 && !ordinarySoldOut.length && !advanceSoldOut.length) {
  20 + result.isEmptyCart = true;
  21 + return result;
  22 + }
  23 +
  24 + // 普通购物车空,则显示预售购物车
  25 + if (ordinaryCount === 0 && !ordinarySoldOut.length) {
  26 + result.cartNav = false;
  27 + result.cartType = 'advance';
  28 + } // 预售购物车空,则显示普通购物车
  29 + else if (advanceCount === 0 && !advanceSoldOut.length) {
  30 + result.cartNav = false;
  31 + result.cartType = 'ordinary';
  32 + } // 以上两个购物车中都有数据, 默认显示普通购物车
  33 + else {
  34 + result.cartNav = true;
  35 + result.cartType = cartType || 'ordinary';
  36 + }
  37 + result.ordinaryCart = result.cartType === 'ordinary';
  38 + result.advanceCart = !result.ordinaryCart;
  39 + /* 普通购物车 */
  40 + result.commonGoodsCount = ordinaryCount;
  41 + result.commonCart = processCartData(cart.ordinary_cart_data, false);
  42 + /* 预售购物车 */
  43 + result.presellGoodsCount = advanceCount;
  44 + result.preSellCart = processCartData(cart.advance_cart_data);
  45 + return result;
  46 +}
  47 +
  48 +const processCartData = (data, isAdvanceCart) => {
  49 + let result = {};
  50 + // 购买的可用商品列表
  51 + result.goods = _.get(data, 'goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart); });
  52 + result.goodPools = _.get(data, 'goods_pool_list', []).map(pool => {
  53 + return {
  54 + isBrand: pool.pool_type <= 1,
  55 + isPromotion: pool.pool_type === 2,
  56 + poolTitle: pool.pool_title,
  57 + goods: _.get(pool, 'goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart); }),
  58 + promotions: _.get(pool, 'promotion_list', []).map(promo => { return formatPromotion(promo); }),
  59 + promotionMore: _.get(pool, 'promotion_list', []).length > 1,
  60 + sub_pool: _.get(pool, 'sub_pool', []).map(subPool => {
  61 + return {
  62 + isBrand: subPool.pool_type <= 1,
  63 + isPromotion: subPool.pool_type === 0,
  64 + goods: _.get(subPool, 'goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart); }),
  65 + promotions: _.get(subPool, 'promotion_list', []).map(promo => { return formatPromotion(promo); }),
  66 + promotionMore: _.get(pool, 'promotion_list', []).length > 1
  67 + }
  68 + })
  69 + }
  70 + })
  71 +
  72 + // 失效商品列表
  73 + result.notValidGoods = _.get(data, 'sold_out_goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart, false); });
  74 +
  75 + // 下架的商品列表
  76 + result.offShelveGoods = _.get(data, 'off_shelves_goods_list', []).map(good => { return formatCartGoods(good, isAdvanceCart, false); });
  77 +
  78 + // 赠品和加价购商品
  79 + if (data.gift_list.length || data.price_gift.length) {
  80 + result.freebieOrAdvanceBuy = true;
  81 +
  82 + // 赠品
  83 + result.freebie = data.gift_list.map(good => { return formatAdvanceGoods(good); });
  84 + result.giftCount = result.freebie.length;
  85 +
  86 + // 加价购
  87 + result.advanceBuy = data.price_gift.map(good => { return formatAdvanceGoods(good); });
  88 + result.advanceBuyCount = result.advanceBuy.length;
  89 + }
  90 +
  91 + // 已参加的活动
  92 + if (data.promotion_info && data.promotion_info.length > 0) {
  93 + result.promotionInfo = data.promotion_info.map(promotion => {
  94 + return {id: promotion.promotion_id, name: promotion.promotion_title};
  95 + });
  96 + }
  97 + //计算正常商品且有库存的总数
  98 + let goodCount = _.get(result.goodPools, 'goods', []).filter(good => good.lowStocks === false).length +
  99 + _.sum(result.goodPools.map(pool => _.sum(_.get(pool, 'sub_pool', []).map(sub => _.get(sub, 'goods', []).filter(good => good.lowStocks === false).length))));
  100 +
  101 + // 结算数据
  102 + result.formulaPrice = data.shopping_cart_data.promotion_formula;
  103 + result.count = data.shopping_cart_data.selected_goods_count;
  104 + result.isAllSelected = (goodCount === data.shopping_cart_data.selected_goods_count) && (data.shopping_cart_data.selected_goods_count > 0);
  105 + result.sumPrice = transPrice(data.shopping_cart_data.last_order_amount);
  106 + result.hasNoSaleGoods = result.notValidGoods.length || result.offShelveGoods.length;
  107 +
  108 + return result;
  109 +};
  110 +const formatPromotion = (promo) => {
  111 + return {
  112 + status: promo.status,
  113 + conditionUnit: promo.condition_unit,
  114 + conditionValue: promo.condition_value,
  115 + giftGoodsList: _.get(promo, 'gift_goods_List', []).map(gift => { return formatAdvanceGoods(gift); }),
  116 + giftPrice: promo.gift_price,
  117 + promotionId: promo.promotion_id,
  118 + promotionTitle: promo.promotion_title,
  119 + promotionType: promo.promotion_type,
  120 + alreadyMatch: promo.alreadyMatch,
  121 + optTitle: formatPromotionTitle(promo)
  122 + };
  123 +}
  124 +const formatPromotionTitle = (promo) => {
  125 + if (promo.status === 0) {
  126 + return '去凑单';
  127 + }
  128 + if (promo.status === 10) {
  129 + if (promo.promotion_type === 'Needpaygift') {
  130 + return '去换购';
  131 + }
  132 + if (promo.promotion_type === 'Gift') {
  133 + return '领赠品';
  134 + }
  135 + return ''
  136 + }
  137 + if (promo.status === 20) {
  138 + return '已抢光';
  139 + }
  140 + if (promo.status === 30) {
  141 + return '更换';
  142 + }
  143 +}
  144 +/**
  145 + * 格式化加价购和赠品商品
  146 + *
  147 + * @param array $advanceGoods 加价购商品列表
  148 + * @param int $count 计商品件数
  149 + * @return array $arr 处理之后的加价购商品数据
  150 + */
  151 +const formatAdvanceGoods = (advanceGood, isGift) => {
  152 + let result = {};
  153 +
  154 + result.id = advanceGood.product_skn;
  155 + result.name = advanceGood.product_name;
  156 + result.thumb = advanceGood.goods_images ? helpers.image(advanceGood.goods_images, 120, 160) : '';
  157 + result.price = transPrice(advanceGood.last_price);
  158 + result.marketPrice = isGift ? '0.00' : transPrice(advanceGood.market_price);
  159 + result.count = advanceGood.storage_number;
  160 +
  161 + return result;
  162 +};
  163 +
  164 +/**
  165 + * 格式化购物车商品
  166 + *
  167 + * @param array $cartGoods 购物车商品列表
  168 + * @param boolean $isValid 是否是可用商品(非失效商品),默认是
  169 + * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)
  170 + * @return array 处理之后的购物车商品数据
  171 + */
  172 +const formatCartGoods = (goodData, isAdvanceCart, isValid = true) => {
  173 + console.log(goodData)
  174 + let result = {};
  175 + result.id = goodData.product_sku;
  176 + result.skn = goodData.product_skn;
  177 + result.name = goodData.product_name;
  178 + result.thumb = goodData.goods_images ? helpers.image(goodData.goods_images, 120, 160) : '';
  179 + result.color = goodData.color_name;
  180 + result.size = goodData.size_name;
  181 + result.checked = goodData.selected === 'Y';
  182 + result.price = transPrice(goodData.last_vip_price);
  183 + result.isVipPrice = goodData.sales_price !== goodData.last_vip_price && goodData.discount_tag === 'V';
  184 + result.isStudents = goodData.sales_price !== goodData.last_vip_price && goodData.discount_tag === 'S';
  185 + result.count = goodData.buy_number;
  186 + result.promotion_id = goodData.promotion_id;
  187 + result.minNumber = parseInt(goodData.min_buy_number, 10);
  188 + result.maxNumber = parseInt(goodData.storage_number, 10);
  189 + result.minSelectNum = parseInt(goodData.buy_number, 10) === parseInt(goodData.min_buy_number, 10) || parseInt(goodData.buy_number, 10) === 1;
  190 +
  191 + if (isValid) {
  192 + // 库存不足
  193 + result.lowStocks = (goodData.buy_number > goodData.storage_number);
  194 + } else { // 失效商品
  195 + result.inValid = true;
  196 + }
  197 +
  198 + // gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
  199 + if (!goodData.goods_type) {
  200 + result.inValid = true;
  201 + }
  202 + else if (goodData.goods_type === 'gift' && !goodData.isAdvanceBuy) {
  203 + result.isGift = true;
  204 + result.salesPrice = transPrice(goodData.sales_price);
  205 + result.price = transPrice(goodData.last_price);
  206 + }
  207 + else if (goodData.goods_type === 'price_gift') {
  208 + result.showCheckbox = true;
  209 + result.isAdvanceBuy = true;
  210 + result.salesPrice = transPrice(goodData.sales_price);
  211 + result.price = transPrice(goodData.last_price);
  212 + }
  213 + else {
  214 + result.showCheckbox = true;
  215 + }
  216 +
  217 + // 上市期
  218 + if (isAdvanceCart && goodData.expect_arrival_time) {
  219 + result.appearDate = goodData.expect_arrival_time;
  220 + }
  221 +
  222 + // 商品链接
  223 + result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`);
  224 + return result;
  225 +};
  226 +
  227 +const transPrice = (price, isSepcialZero) => {
  228 + return (price >= 0 || isSepcialZero) ? parseFloat(price).toFixed(2) : 0;
  229 +};
  230 +
  231 +/**
  232 + * 处理购物车商品、加价购商品、赠品详情数据
  233 + *
  234 + * @param array productData 要处理的商品数据
  235 + * @param int num 购买数目
  236 + * @return array data 处理之后的数据
  237 + */
  238 +const procGoodsDetail = (productData, num = undefined) => {
  239 + let data = {};
  240 +
  241 + data.name = productData.product_name;
  242 + if (_.has(productData, 'special_price')) { // 加价购或者赠品的销售价字段
  243 + data.price = productData.format_market_price;
  244 + data.salePrice = productData.format_sales_price;
  245 + }
  246 + else { // 购物车商品的销售价字段
  247 + data.price = productData.market_price > productData.sales_price ? productData.format_market_price : false;
  248 + data.salePrice = '¥' + transPrice(productData.sales_price);
  249 + }
  250 +
  251 +
  252 + if (_.has(productData, 'storage_sum')) {
  253 + data.storage = productData.storage_sum;
  254 + }
  255 + data.num = 1;
  256 + if (num) {
  257 + data.num = num;
  258 + }
  259 +
  260 + // 商品选择
  261 + if (_.has(productData, 'goods_list')) {
  262 + goodsList = productData.goods_list;
  263 +
  264 + let sizeName = '',
  265 + colors = [],
  266 + colorList = [],
  267 + oneColor = [],
  268 + sizes = [],
  269 + oneSize = [],
  270 + sizeList = [],
  271 + allSizeList = [], // 所有尺码列表
  272 + thumbImageList = [],
  273 + colorNum = 0,
  274 + totalStorageNum = 0, // 总库存数
  275 + colorStorageGroup = []; // 颜色分组的库存总数集合, 多个之间用/分隔
  276 +
  277 + productData.goods_list.forEach(good => {
  278 + colorNum = 0;
  279 + sizeName = '';
  280 +
  281 + // 商品的尺码列表
  282 + colorStorageGroup[good.product_skc] = [];
  283 + if (_.has(good, 'size_list')) {
  284 + // 尺码
  285 + good.size_list.forEach(size => {
  286 + sizeName = size.size_name;
  287 + oneSize = [];
  288 +
  289 + oneSize.id = size.size_id;
  290 + oneSize.skuId = size.product_sku;
  291 + oneSize.goodsId = good.goods_id;
  292 + oneSize.colorId = good.color_id;
  293 + oneSize.name = sizeName;
  294 + oneSize.sizeNum = parseInt(size.storage_number, 10);
  295 + sizeList[good.product_skc].push(oneSize);
  296 +
  297 + // 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
  298 + allSizeList[sizeName] = !allSizeList[sizeName].storage ? {storage:size.storage_number, id: size.size_id} : allSizeList[sizeName];
  299 +
  300 + colorNum += parseInt(size.storage_number, 10);
  301 +
  302 + colorStorageGroup[good.product_skc][size.size_name] = parseInt(size.storage_number, 10);
  303 + })
  304 +
  305 + // 颜色分组
  306 + oneColor = [];
  307 + oneColor.id = good.color_id;
  308 + oneColor.skcId = good.product_skc;
  309 + oneColor.name = good.color_name;
  310 + oneColor.goodsName = productData.product_name;
  311 + oneColor.colorNum = colorNum;
  312 + colorList.push(oneColor);
  313 + }
  314 +
  315 + // 缩略图
  316 + thumbImageList.push({
  317 + img: helpers.image(good.color_image, 60, 60)
  318 + });
  319 +
  320 + // 商品库存总数
  321 + totalStorageNum += colorNum;
  322 + })
  323 +
  324 + // 遍历所有尺码,构建颜色显示数据
  325 + i = 1;
  326 + _.forEach(allSizeList, (value, sizeName) => {
  327 + // 默认尺码
  328 + sizes[0].size.push({
  329 + name: sizeName, // 尺码名称
  330 + sizeNum: value.storage, // 是否有库存 (false:表示没有库存,true:表示有库存)
  331 + id: value.id,
  332 + })
  333 +
  334 + // 各个颜色的尺码, 每行显示一个尺码对应的颜色
  335 + colorList.forEach(colorArr => {
  336 + colorArr.colorNum = _.has(colorStorageGroup, `${colorArr.skcId}.${sizeName}`) ? parseInt(colorStorageGroup[colorArr.skcId][sizeName], 10) : 0;
  337 + colors[i].color.push(colorArr);
  338 + })
  339 +
  340 + colors[i].id = value.id;
  341 +
  342 + ++i;
  343 + })
  344 +
  345 + // 遍历所有颜色, 构建尺码显示数据
  346 + i = 1;
  347 + colorList.forEach(value => {
  348 + // 各个尺码的颜色,每行显示一个颜色的对应尺码
  349 + sizes[i].size = sizeList[value.skcId];
  350 + sizes[i].colorId = value.skcId;
  351 + // 默认颜色
  352 + colors[0].color.push(value);
  353 +
  354 + ++i;
  355 + })
  356 + console.log(colors)//TODO
  357 + // ksort(colors, SORT_NUMERIC);
  358 +
  359 + data.thumbs = thumbImageList;
  360 + data.colors = colors;
  361 + data.sizes = sizes;
  362 + data.totalNum = totalStorageNum;
  363 + }
  364 +
  365 + return data;
  366 +}
  367 +
  368 +module.exports = {
  369 + processData,
  370 + procGoodsDetail
  371 +}